+2024-03-08 Niels Möller <nisse@lysator.liu.se>
+
+ Fix ubsan issues for empty hash updates.
+ * macros.h (MD_UPDATE): Check upfront if length is zero. Avoids
+ calling memcpy(dst, NULL, 0), which is undefined behavior.
+ * sha256.c (sha256_update): Likewise.
+ * sha3.c (_nettle_sha3_update): Likewise.
+ * testsuite/testutils.c (test_hash): Test with message split into
+ two pieces in different ways, and also add an call to update(ctx,
+ 0, NULL) in the middle.
+
2024-02-16 Niels Möller <nisse@lysator.liu.se>
RSA-OAEP support contributed by Nicolas Mora and Daiki Ueno:
ASSERT (digest->length == hash->digest_size);
hash->init(ctx);
- hash->update(ctx, msg->length, msg->data);
- hash->digest(ctx, digest->length, buffer);
-
- if (MEMEQ(digest->length, digest->data, buffer) == 0)
+ for (offset = 0; offset <= msg->length && offset < 40; offset++)
{
- fprintf(stdout, "\nGot:\n");
- print_hex(digest->length, buffer);
- fprintf(stdout, "\nExpected:\n");
- print_hex(digest->length, digest->data);
- abort();
+ hash->update(ctx, offset, msg->data);
+ hash->update(ctx, 0, NULL);
+ hash->update(ctx, msg->length - offset, msg->data + offset);
+
+ hash->digest(ctx, digest->length, buffer);
+
+ if (MEMEQ(digest->length, digest->data, buffer) == 0)
+ {
+ fprintf(stdout, "Offset %u\nGot:\n", offset);
+ print_hex(digest->length, buffer);
+ fprintf(stdout, "\nExpected:\n");
+ print_hex(digest->length, digest->data);
+ abort();
+ }
}
memset(buffer, 0, digest->length);