diff options
Diffstat (limited to 'gl/sha256.c')
| -rw-r--r-- | gl/sha256.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/gl/sha256.c b/gl/sha256.c index 9358faff..bada2d07 100644 --- a/gl/sha256.c +++ b/gl/sha256.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* sha256.c - Functions to compute SHA256 and SHA224 message digest of files or | 1 | /* sha256.c - Functions to compute SHA256 and SHA224 message digest of files or |
| 2 | memory blocks according to the NIST specification FIPS-180-2. | 2 | memory blocks according to the NIST specification FIPS-180-2. |
| 3 | 3 | ||
| 4 | Copyright (C) 2005-2006, 2008-2025 Free Software Foundation, Inc. | 4 | Copyright (C) 2005-2006, 2008-2026 Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | This file is free software: you can redistribute it and/or modify | 6 | This file is free software: you can redistribute it and/or modify |
| 7 | it under the terms of the GNU Lesser General Public License as | 7 | it under the terms of the GNU Lesser General Public License as |
| @@ -96,10 +96,9 @@ set_uint32 (char *cp, uint32_t v) | |||
| 96 | void * | 96 | void * |
| 97 | sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf) | 97 | sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf) |
| 98 | { | 98 | { |
| 99 | int i; | ||
| 100 | char *r = resbuf; | 99 | char *r = resbuf; |
| 101 | 100 | ||
| 102 | for (i = 0; i < 8; i++) | 101 | for (int i = 0; i < 8; i++) |
| 103 | set_uint32 (r + i * sizeof ctx->state[0], SWAP (ctx->state[i])); | 102 | set_uint32 (r + i * sizeof ctx->state[0], SWAP (ctx->state[i])); |
| 104 | 103 | ||
| 105 | return resbuf; | 104 | return resbuf; |
| @@ -108,10 +107,9 @@ sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf) | |||
| 108 | void * | 107 | void * |
| 109 | sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf) | 108 | sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf) |
| 110 | { | 109 | { |
| 111 | int i; | ||
| 112 | char *r = resbuf; | 110 | char *r = resbuf; |
| 113 | 111 | ||
| 114 | for (i = 0; i < 7; i++) | 112 | for (int i = 0; i < 7; i++) |
| 115 | set_uint32 (r + i * sizeof ctx->state[0], SWAP (ctx->state[i])); | 113 | set_uint32 (r + i * sizeof ctx->state[0], SWAP (ctx->state[i])); |
| 116 | 114 | ||
| 117 | return resbuf; | 115 | return resbuf; |
| @@ -326,8 +324,8 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) | |||
| 326 | + S0(x[(I-15)&0x0f]) + x[I&0x0f] \ | 324 | + S0(x[(I-15)&0x0f]) + x[I&0x0f] \ |
| 327 | , x[I&0x0f] = tm ) | 325 | , x[I&0x0f] = tm ) |
| 328 | 326 | ||
| 329 | #define R(A,B,C,D,E,F,G,H,K,M) do { t0 = SS0(A) + F2(A,B,C); \ | 327 | #define R(A,B,C,D,E,F,G,H,K,M) do { uint32_t t0 = SS0(A) + F2(A,B,C); \ |
| 330 | t1 = H + SS1(E) \ | 328 | uint32_t t1 = H + SS1(E) \ |
| 331 | + F1(E,F,G) \ | 329 | + F1(E,F,G) \ |
| 332 | + K \ | 330 | + K \ |
| 333 | + M; \ | 331 | + M; \ |
| @@ -336,16 +334,15 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) | |||
| 336 | 334 | ||
| 337 | while (words < endp) | 335 | while (words < endp) |
| 338 | { | 336 | { |
| 339 | uint32_t tm; | ||
| 340 | uint32_t t0, t1; | ||
| 341 | int t; | ||
| 342 | /* FIXME: see sha1.c for a better implementation. */ | 337 | /* FIXME: see sha1.c for a better implementation. */ |
| 343 | for (t = 0; t < 16; t++) | 338 | for (int t = 0; t < 16; t++) |
| 344 | { | 339 | { |
| 345 | x[t] = SWAP (*words); | 340 | x[t] = SWAP (*words); |
| 346 | words++; | 341 | words++; |
| 347 | } | 342 | } |
| 348 | 343 | ||
| 344 | uint32_t tm; | ||
| 345 | |||
| 349 | R( a, b, c, d, e, f, g, h, K( 0), x[ 0] ); | 346 | R( a, b, c, d, e, f, g, h, K( 0), x[ 0] ); |
| 350 | R( h, a, b, c, d, e, f, g, K( 1), x[ 1] ); | 347 | R( h, a, b, c, d, e, f, g, K( 1), x[ 1] ); |
| 351 | R( g, h, a, b, c, d, e, f, K( 2), x[ 2] ); | 348 | R( g, h, a, b, c, d, e, f, K( 2), x[ 2] ); |
