From da510a4238399cf0adc27acfce398746a6af65b8 Mon Sep 17 00:00:00 2001 From: ketmar Date: Wed, 10 Nov 2021 15:31:28 +0000 Subject: [PATCH] use iv RIPEMD-160 implementation FossilOrigin-Name: 2e12e6c168ae4d666635d6224dee6c6277b375e2ed08a460e80d69b50cb7f2d6 --- chibackend/sqbase.d | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/chibackend/sqbase.d b/chibackend/sqbase.d index deda9f9..fdfe26f 100644 --- a/chibackend/sqbase.d +++ b/chibackend/sqbase.d @@ -66,9 +66,9 @@ private: // sadly, requires external lib //version = use_zstd; -private import std.digest.ripemd; private import iv.encoding; private import iv.cmdcon; +private import iv.ripemd160; private import iv.strex; private import iv.sq3; private import iv.timer; @@ -1973,7 +1973,9 @@ private void sq3Fn_ChiroRIPEMD160 (sqlite3_context *ctx, int argc, sqlite3_value if (!vs && sz == 0) vs = ""; if (!vs) { sqlite3_result_error(ctx, "cannot get blob data in `ChiroRIPEMD160()`", -1); return; } - ubyte[20] hash = ripemd160Of(vs[0..cast(uint)sz]); + RIPEMD160_Ctx rmd; + ripemd160_put(ref rmd, vs[0..cast(uint)sz]); + ubyte[RIPEMD160_BYTES] hash = ripemd160_finish(ref rmd); sqlite3_result_blob(ctx, cast(const(char)*)hash.ptr, cast(int)hash.length, SQLITE_TRANSIENT); } @@ -3101,12 +3103,11 @@ public bool chiroParseAndInsertOneMessage (uint uid, uint msgtime, int appearanc } // if there is no msgid, create one if (!hasmsgid) { - RIPEMD160 hash; - hash.start(); - hash.put(cast(const(ubyte)[])hdrs); - hash.put(cast(const(ubyte)[])body); - ubyte[20] digest = hash.finish(); - char[20*2+2+16] buf; + RIPEMD160_Ctx rmd; + ripemd160_put(ref rmd, hdrs[]); + ripemd160_put(ref rmd, body[]); + ubyte[RIPEMD160_BYTES] digest = ripemd160_finish(ref rmd); + char[20*2+2+16] buf = 0; import core.stdc.stdio : snprintf; import core.stdc.string : strcat; foreach (immutable idx, ubyte b; digest[]) snprintf(buf.ptr+idx*2, 3, "%02x", b); -- 2.11.4.GIT