[git commit] Move "sha256-hash a memory array and produce the digest" helper to libbb
Denys Vlasenko
vda.linux at googlemail.com
Sun Jul 6 08:50:46 UTC 2025
commit: https://git.busybox.net/busybox/commit/?id=62abd47815f0ee2f6c0ea6549fabe6d5c307ef8d
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
include/libbb.h | 1 +
libbb/yescrypt/alg-sha256.c | 26 +++++---------------------
libbb/yescrypt/alg-sha256.h | 6 ------
libbb/yescrypt/alg-yescrypt-kdf.c | 2 +-
4 files changed, 7 insertions(+), 28 deletions(-)
diff --git a/include/libbb.h b/include/libbb.h
index 9a0a2f916..270a9d593 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -2233,6 +2233,7 @@ enum {
SHA512_OUTSIZE = 64,
SHA3_OUTSIZE = 28,
};
+void FAST_FUNC sha256_block(const void *in, size_t len, uint8_t hash[32]);
extern uint32_t *global_crc32_table;
uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
diff --git a/libbb/yescrypt/alg-sha256.c b/libbb/yescrypt/alg-sha256.c
index 038ac0ddb..315c094a2 100644
--- a/libbb/yescrypt/alg-sha256.c
+++ b/libbb/yescrypt/alg-sha256.c
@@ -25,38 +25,22 @@
* SUCH DAMAGE.
*/
-/**
- * SHA256_Buf(in, len, digest):
- * Compute the SHA256 hash of ${len} bytes from ${in} and write it to ${digest}.
- */
-void
-SHA256_Buf(const void * in, size_t len, uint8_t digest[32])
-{
- sha256_ctx_t ctx;
- sha256_begin(&ctx);
- sha256_hash(&ctx, in, len);
- sha256_end(&ctx, digest);
-}
-
/**
* HMAC_SHA256_Init(ctx, K, Klen):
* Initialize the HMAC-SHA256 context ${ctx} with ${Klen} bytes of key from
* ${K}.
*/
static void
-HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen)
+HMAC_SHA256_Init(HMAC_SHA256_CTX *ctx, const void *_K, size_t Klen)
{
uint8_t pad[64];
uint8_t khash[32];
- const uint8_t * K = _K;
+ const uint8_t *K = _K;
size_t i;
/* If Klen > 64, the key is really SHA256(K). */
if (Klen > 64) {
-// SHA256_Init(&ctx->ictx);
-// _SHA256_Update(&ctx->ictx, K, Klen, tmp32);
-// _SHA256_Final(khash, &ctx->ictx, tmp32);
- SHA256_Buf(K, Klen, khash);
+ sha256_block(K, Klen, khash);
K = khash;
Klen = 32;
}
@@ -81,7 +65,7 @@ HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen)
* Input ${len} bytes from ${in} into the HMAC-SHA256 context ${ctx}.
*/
static void
-HMAC_SHA256_Update(HMAC_SHA256_CTX * ctx, const void * in, size_t len)
+HMAC_SHA256_Update(HMAC_SHA256_CTX *ctx, const void *in, size_t len)
{
/* Feed data to the inner SHA256 operation. */
sha256_hash(&ctx->ictx, in, len);
@@ -93,7 +77,7 @@ HMAC_SHA256_Update(HMAC_SHA256_CTX * ctx, const void * in, size_t len)
* buffer ${digest}.
*/
static void
-HMAC_SHA256_Final(uint8_t digest[32], HMAC_SHA256_CTX * ctx)
+HMAC_SHA256_Final(uint8_t digest[32], HMAC_SHA256_CTX *ctx)
{
uint8_t ihash[32];
diff --git a/libbb/yescrypt/alg-sha256.h b/libbb/yescrypt/alg-sha256.h
index 8a4968267..6d2cc0a04 100644
--- a/libbb/yescrypt/alg-sha256.h
+++ b/libbb/yescrypt/alg-sha256.h
@@ -34,12 +34,6 @@
#define HMAC_SHA256_Buf libcperciva_HMAC_SHA256_Buf
#define HMAC_SHA256_CTX libcperciva_HMAC_SHA256_CTX
-/**
- * SHA256_Buf(in, len, digest):
- * Compute the SHA256 hash of ${len} bytes from ${in} and write it to ${digest}.
- */
-extern void SHA256_Buf(const void *, size_t, uint8_t[32]);
-
/* Context structure for HMAC-SHA256 operations. */
typedef struct {
sha256_ctx_t ictx;
diff --git a/libbb/yescrypt/alg-yescrypt-kdf.c b/libbb/yescrypt/alg-yescrypt-kdf.c
index 01a66a6a8..5c1f1006a 100644
--- a/libbb/yescrypt/alg-yescrypt-kdf.c
+++ b/libbb/yescrypt/alg-yescrypt-kdf.c
@@ -945,7 +945,7 @@ static int yescrypt_kdf32_body(
size_t clen = /*buflen:*/32;
if (clen > sizeof(dk))
clen = sizeof(dk);
- SHA256_Buf(sha256, sizeof(sha256), dk);
+ sha256_block(sha256, sizeof(sha256), dk);
memcpy(buf32, dk, clen);
}
}
More information about the busybox-cvs
mailing list