diff options
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/yescrypt/alg-sha256.c | 26 | ||||
| -rw-r--r-- | libbb/yescrypt/alg-sha256.h | 6 | ||||
| -rw-r--r-- | libbb/yescrypt/alg-yescrypt-kdf.c | 2 |
3 files changed, 6 insertions, 28 deletions
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 | |||
| @@ -26,37 +26,21 @@ | |||
| 26 | */ | 26 | */ |
| 27 | 27 | ||
| 28 | /** | 28 | /** |
| 29 | * SHA256_Buf(in, len, digest): | ||
| 30 | * Compute the SHA256 hash of ${len} bytes from ${in} and write it to ${digest}. | ||
| 31 | */ | ||
| 32 | void | ||
| 33 | SHA256_Buf(const void * in, size_t len, uint8_t digest[32]) | ||
| 34 | { | ||
| 35 | sha256_ctx_t ctx; | ||
| 36 | sha256_begin(&ctx); | ||
| 37 | sha256_hash(&ctx, in, len); | ||
| 38 | sha256_end(&ctx, digest); | ||
| 39 | } | ||
| 40 | |||
| 41 | /** | ||
| 42 | * HMAC_SHA256_Init(ctx, K, Klen): | 29 | * HMAC_SHA256_Init(ctx, K, Klen): |
| 43 | * Initialize the HMAC-SHA256 context ${ctx} with ${Klen} bytes of key from | 30 | * Initialize the HMAC-SHA256 context ${ctx} with ${Klen} bytes of key from |
| 44 | * ${K}. | 31 | * ${K}. |
| 45 | */ | 32 | */ |
| 46 | static void | 33 | static void |
| 47 | HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen) | 34 | HMAC_SHA256_Init(HMAC_SHA256_CTX *ctx, const void *_K, size_t Klen) |
| 48 | { | 35 | { |
| 49 | uint8_t pad[64]; | 36 | uint8_t pad[64]; |
| 50 | uint8_t khash[32]; | 37 | uint8_t khash[32]; |
| 51 | const uint8_t * K = _K; | 38 | const uint8_t *K = _K; |
| 52 | size_t i; | 39 | size_t i; |
| 53 | 40 | ||
| 54 | /* If Klen > 64, the key is really SHA256(K). */ | 41 | /* If Klen > 64, the key is really SHA256(K). */ |
| 55 | if (Klen > 64) { | 42 | if (Klen > 64) { |
| 56 | // SHA256_Init(&ctx->ictx); | 43 | sha256_block(K, Klen, khash); |
| 57 | // _SHA256_Update(&ctx->ictx, K, Klen, tmp32); | ||
| 58 | // _SHA256_Final(khash, &ctx->ictx, tmp32); | ||
| 59 | SHA256_Buf(K, Klen, khash); | ||
| 60 | K = khash; | 44 | K = khash; |
| 61 | Klen = 32; | 45 | Klen = 32; |
| 62 | } | 46 | } |
| @@ -81,7 +65,7 @@ HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen) | |||
| 81 | * Input ${len} bytes from ${in} into the HMAC-SHA256 context ${ctx}. | 65 | * Input ${len} bytes from ${in} into the HMAC-SHA256 context ${ctx}. |
| 82 | */ | 66 | */ |
| 83 | static void | 67 | static void |
| 84 | HMAC_SHA256_Update(HMAC_SHA256_CTX * ctx, const void * in, size_t len) | 68 | HMAC_SHA256_Update(HMAC_SHA256_CTX *ctx, const void *in, size_t len) |
| 85 | { | 69 | { |
| 86 | /* Feed data to the inner SHA256 operation. */ | 70 | /* Feed data to the inner SHA256 operation. */ |
| 87 | sha256_hash(&ctx->ictx, in, len); | 71 | sha256_hash(&ctx->ictx, in, len); |
| @@ -93,7 +77,7 @@ HMAC_SHA256_Update(HMAC_SHA256_CTX * ctx, const void * in, size_t len) | |||
| 93 | * buffer ${digest}. | 77 | * buffer ${digest}. |
| 94 | */ | 78 | */ |
| 95 | static void | 79 | static void |
| 96 | HMAC_SHA256_Final(uint8_t digest[32], HMAC_SHA256_CTX * ctx) | 80 | HMAC_SHA256_Final(uint8_t digest[32], HMAC_SHA256_CTX *ctx) |
| 97 | { | 81 | { |
| 98 | uint8_t ihash[32]; | 82 | uint8_t ihash[32]; |
| 99 | 83 | ||
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 @@ | |||
| 34 | #define HMAC_SHA256_Buf libcperciva_HMAC_SHA256_Buf | 34 | #define HMAC_SHA256_Buf libcperciva_HMAC_SHA256_Buf |
| 35 | #define HMAC_SHA256_CTX libcperciva_HMAC_SHA256_CTX | 35 | #define HMAC_SHA256_CTX libcperciva_HMAC_SHA256_CTX |
| 36 | 36 | ||
| 37 | /** | ||
| 38 | * SHA256_Buf(in, len, digest): | ||
| 39 | * Compute the SHA256 hash of ${len} bytes from ${in} and write it to ${digest}. | ||
| 40 | */ | ||
| 41 | extern void SHA256_Buf(const void *, size_t, uint8_t[32]); | ||
| 42 | |||
| 43 | /* Context structure for HMAC-SHA256 operations. */ | 37 | /* Context structure for HMAC-SHA256 operations. */ |
| 44 | typedef struct { | 38 | typedef struct { |
| 45 | sha256_ctx_t ictx; | 39 | 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( | |||
| 945 | size_t clen = /*buflen:*/32; | 945 | size_t clen = /*buflen:*/32; |
| 946 | if (clen > sizeof(dk)) | 946 | if (clen > sizeof(dk)) |
| 947 | clen = sizeof(dk); | 947 | clen = sizeof(dk); |
| 948 | SHA256_Buf(sha256, sizeof(sha256), dk); | 948 | sha256_block(sha256, sizeof(sha256), dk); |
| 949 | memcpy(buf32, dk, clen); | 949 | memcpy(buf32, dk, clen); |
| 950 | } | 950 | } |
| 951 | } | 951 | } |
