Changeset: cb420b9ecb49 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/cb420b9ecb49
Modified Files:
common/utils/ripemd160.c
Branch: Sep2022
Log Message:
Fix Ripemd160 continuation.
Hashing a long string can be done in pieces. The implementation of this
was buggy and could cause buffer overruns. Luckily this doesn't seem to
have happened in the way we use the function, but still, better to fix it.
diffs (28 lines):
diff --git a/common/utils/ripemd160.c b/common/utils/ripemd160.c
--- a/common/utils/ripemd160.c
+++ b/common/utils/ripemd160.c
@@ -27,19 +27,21 @@ RIPEMD160Input(RIPEMD160Context *ctxt, c
ctxt->length += bytecount;
if (ctxt->noverflow > 0) {
+ assert(ctxt->noverflow < 64);
if (ctxt->noverflow + bytecount < 64) {
memcpy(ctxt->overflow + ctxt->noverflow, bytes,
bytecount);
ctxt->noverflow += bytecount;
return;
}
- memcpy(ctxt->overflow + ctxt->noverflow, bytes, bytecount -
ctxt->noverflow);
+ unsigned l = 64 - ctxt->noverflow;
+ memcpy(ctxt->overflow + ctxt->noverflow, bytes, l);
const uint8_t *x = ctxt->overflow;
for (int i = 0; i < 16; i++) {
X[i] = BYTES_TO_DWORD(x);
x += 4;
}
- bytecount -= ctxt->noverflow;
- bytes += ctxt->noverflow;
+ bytecount -= l;
+ bytes += l;
ctxt->noverflow = 0;
MDcompress(ctxt->digest, X);
}
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]