The ‘BLOCKSIZE + 72’ business apparently dates back to 30 years ago when the buffer was local (not heap allocated) and was multi-use. That code died long ago, so stop allocating the cargo-cult bytes. * lib/md2-stream.c (md2_stream): * lib/md4-stream.c (md4_stream): * lib/md5-stream.c (md5_stream): * lib/sha1-stream.c (sha1_stream): * lib/sha256-stream.c (shaxxx_stream): * lib/sha3-stream.c (sha3_xxx_stream): * lib/sha512-stream.c (shaxxx_stream): * lib/sm3-stream.c (sm3_stream): Don’t allocate an unnecessary 72 extra bytes. --- ChangeLog | 14 ++++++++++++++ lib/md2-stream.c | 2 +- lib/md4-stream.c | 2 +- lib/md5-stream.c | 2 +- lib/sha1-stream.c | 2 +- lib/sha256-stream.c | 2 +- lib/sha3-stream.c | 2 +- lib/sha512-stream.c | 2 +- lib/sm3-stream.c | 2 +- 9 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog index a3b766a799..39141821aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2026-02-22 Paul Eggert <[email protected]> + crypto: don’t add 72 to malloc size + The ‘BLOCKSIZE + 72’ business apparently dates back to 30 years + ago when the buffer was local (not heap allocated) and was multi-use. + That code died long ago, so stop allocating the cargo-cult bytes. + * lib/md2-stream.c (md2_stream): + * lib/md4-stream.c (md4_stream): + * lib/md5-stream.c (md5_stream): + * lib/sha1-stream.c (sha1_stream): + * lib/sha256-stream.c (shaxxx_stream): + * lib/sha3-stream.c (sha3_xxx_stream): + * lib/sha512-stream.c (shaxxx_stream): + * lib/sm3-stream.c (sm3_stream): + Don’t allocate an unnecessary 72 extra bytes. + crypto: add ‘restrict’ to .h files Use ‘restrict’ on pointer args when appropriate. It suffices to do this in .h files, as .c files inherit it. diff --git a/lib/md2-stream.c b/lib/md2-stream.c index cc6ddf8a27..a2f9b6983c 100644 --- a/lib/md2-stream.c +++ b/lib/md2-stream.c @@ -41,7 +41,7 @@ int md2_stream (FILE *restrict stream, void *restrict resblock) { - char *buffer = malloc (BLOCKSIZE + 72); + char *buffer = malloc (BLOCKSIZE); if (!buffer) return 1; diff --git a/lib/md4-stream.c b/lib/md4-stream.c index 602dffa2a4..b990a0baf9 100644 --- a/lib/md4-stream.c +++ b/lib/md4-stream.c @@ -41,7 +41,7 @@ int md4_stream (FILE *restrict stream, void *restrict resblock) { - char *buffer = malloc (BLOCKSIZE + 72); + char *buffer = malloc (BLOCKSIZE); if (!buffer) return 1; diff --git a/lib/md5-stream.c b/lib/md5-stream.c index 96b92374c1..ffe077f52a 100644 --- a/lib/md5-stream.c +++ b/lib/md5-stream.c @@ -63,7 +63,7 @@ md5_stream (FILE *stream, void *resblock) case -EIO: return 1; } - char *buffer = malloc (BLOCKSIZE + 72); + char *buffer = malloc (BLOCKSIZE); if (!buffer) return 1; diff --git a/lib/sha1-stream.c b/lib/sha1-stream.c index b11464bc10..c6e2c836e9 100644 --- a/lib/sha1-stream.c +++ b/lib/sha1-stream.c @@ -51,7 +51,7 @@ sha1_stream (FILE *restrict stream, void *restrict resblock) case -EIO: return 1; } - char *buffer = malloc (BLOCKSIZE + 72); + char *buffer = malloc (BLOCKSIZE); if (!buffer) return 1; diff --git a/lib/sha256-stream.c b/lib/sha256-stream.c index 66277664da..cde823a597 100644 --- a/lib/sha256-stream.c +++ b/lib/sha256-stream.c @@ -55,7 +55,7 @@ shaxxx_stream (FILE *restrict stream, char const *restrict alg, case -EIO: return 1; } - char *buffer = malloc (BLOCKSIZE + 72); + char *buffer = malloc (BLOCKSIZE); if (!buffer) return 1; diff --git a/lib/sha3-stream.c b/lib/sha3-stream.c index 46ae7df791..7bc3a7d7fe 100644 --- a/lib/sha3-stream.c +++ b/lib/sha3-stream.c @@ -50,7 +50,7 @@ sha3_xxx_stream (FILE *restrict stream, char const *restrict alg, case -EIO: return 1; } - char *buffer = malloc (BLOCKSIZE + 72); + char *buffer = malloc (BLOCKSIZE); if (!buffer) return 1; diff --git a/lib/sha512-stream.c b/lib/sha512-stream.c index a5371b4991..8901eb40aa 100644 --- a/lib/sha512-stream.c +++ b/lib/sha512-stream.c @@ -55,7 +55,7 @@ shaxxx_stream (FILE *restrict stream, char const *restrict alg, case -EIO: return 1; } - char *buffer = malloc (BLOCKSIZE + 72); + char *buffer = malloc (BLOCKSIZE); if (!buffer) return 1; diff --git a/lib/sm3-stream.c b/lib/sm3-stream.c index 0e730e3ccb..412a4a1313 100644 --- a/lib/sm3-stream.c +++ b/lib/sm3-stream.c @@ -45,7 +45,7 @@ int sm3_stream (FILE *restrict stream, void *restrict resblock) { - char *buffer = malloc (BLOCKSIZE + 72); + char *buffer = malloc (BLOCKSIZE); if (!buffer) return 1; -- 2.51.0
