Skip to content

Commit 30b60a6

Browse files
committed
sha_fixes
1 parent 63a28fa commit 30b60a6

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

sha2.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@
9797

9898
/*** ENDIAN SPECIFIC COPY MACROS **************************************/
9999
#define BE_8_TO_32(dst, cp) do { \
100-
(dst) = (u_int32_t)(cp)[3] | ((u_int32_t)(cp)[2] << 8) | \
101-
((u_int32_t)(cp)[1] << 16) | ((u_int32_t)(cp)[0] << 24); \
100+
(dst) = (uint32_t)(cp)[3] | ((uint32_t)(cp)[2] << 8) | \
101+
((uint32_t)(cp)[1] << 16) | ((uint32_t)(cp)[0] << 24); \
102102
} while(0)
103103

104104
#define BE_8_TO_64(dst, cp) do { \
105-
(dst) = (u_int64_t)(cp)[7] | ((u_int64_t)(cp)[6] << 8) | \
106-
((u_int64_t)(cp)[5] << 16) | ((u_int64_t)(cp)[4] << 24) | \
107-
((u_int64_t)(cp)[3] << 32) | ((u_int64_t)(cp)[2] << 40) | \
108-
((u_int64_t)(cp)[1] << 48) | ((u_int64_t)(cp)[0] << 56); \
105+
(dst) = (uint64_t)(cp)[7] | ((uint64_t)(cp)[6] << 8) | \
106+
((uint64_t)(cp)[5] << 16) | ((uint64_t)(cp)[4] << 24) | \
107+
((uint64_t)(cp)[3] << 32) | ((uint64_t)(cp)[2] << 40) | \
108+
((uint64_t)(cp)[1] << 48) | ((uint64_t)(cp)[0] << 56); \
109109
} while (0)
110110

111111
#define BE_64_TO_8(cp, src) do { \
@@ -132,7 +132,7 @@
132132
* 64-bit words):
133133
*/
134134
#define ADDINC128(w,n) do { \
135-
(w)[0] += (u_int64_t)(n); \
135+
(w)[0] += (uint64_t)(n); \
136136
if ((w)[0] < (n)) { \
137137
(w)[1]++; \
138138
} \
@@ -165,7 +165,7 @@
165165

166166
/*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/
167167
/* Hash constant words K for SHA-224 and SHA-256: */
168-
static const u_int32_t K256[64] = {
168+
static const uint32_t K256[64] = {
169169
0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
170170
0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
171171
0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL,
@@ -185,7 +185,7 @@ static const u_int32_t K256[64] = {
185185
};
186186

187187
/* Initial hash value H for SHA-256: */
188-
static const u_int32_t sha256_initial_hash_value[8] = {
188+
static const uint32_t sha256_initial_hash_value[8] = {
189189
0x6a09e667UL,
190190
0xbb67ae85UL,
191191
0x3c6ef372UL,
@@ -232,10 +232,10 @@ SHA256Init(SHA2_CTX *context)
232232
} while(0)
233233

234234
void
235-
SHA256Transform(u_int32_t state[8], const u_int8_t data[SHA256_BLOCK_LENGTH])
235+
SHA256Transform(uint32_t state[8], const uint8_t data[SHA256_BLOCK_LENGTH])
236236
{
237-
u_int32_t a, b, c, d, e, f, g, h, s0, s1;
238-
u_int32_t T1, W256[16];
237+
uint32_t a, b, c, d, e, f, g, h, s0, s1;
238+
uint32_t T1, W256[16];
239239
int j;
240240

241241
/* Initialize registers with the prev. intermediate value */
@@ -290,10 +290,10 @@ SHA256Transform(u_int32_t state[8], const u_int8_t data[SHA256_BLOCK_LENGTH])
290290
#else /* SHA2_UNROLL_TRANSFORM */
291291

292292
void
293-
SHA256Transform(u_int32_t state[8], const u_int8_t data[SHA256_BLOCK_LENGTH])
293+
SHA256Transform(uint32_t state[8], const uint8_t data[SHA256_BLOCK_LENGTH])
294294
{
295-
u_int32_t a, b, c, d, e, f, g, h, s0, s1;
296-
u_int32_t T1, T2, W256[16];
295+
uint32_t a, b, c, d, e, f, g, h, s0, s1;
296+
uint32_t T1, T2, W256[16];
297297
int j;
298298

299299
/* Initialize registers with the prev. intermediate value */
@@ -365,9 +365,9 @@ SHA256Transform(u_int32_t state[8], const u_int8_t data[SHA256_BLOCK_LENGTH])
365365
#endif /* SHA2_UNROLL_TRANSFORM */
366366

367367
void
368-
SHA256Update(SHA2_CTX *context, const u_int8_t *data, size_t len)
368+
SHA256Update(SHA2_CTX *context, const uint8_t *data, size_t len)
369369
{
370-
u_int64_t freespace, usedspace;
370+
uint64_t freespace, usedspace;
371371

372372
/* Calling with no data is valid (we do nothing) */
373373
if (len == 0)
@@ -388,7 +388,7 @@ SHA256Update(SHA2_CTX *context, const u_int8_t *data, size_t len)
388388
} else {
389389
/* The buffer is not yet full */
390390
memcpy(&context->buffer[usedspace], data, len);
391-
context->bitcount[0] += (u_int64_t)len << 3;
391+
context->bitcount[0] += (uint64_t)len << 3;
392392
/* Clean up: */
393393
usedspace = freespace = 0;
394394
return;
@@ -454,7 +454,7 @@ SHA256Pad(SHA2_CTX *context)
454454
}
455455

456456
void
457-
SHA256Final(u_int8_t digest[SHA256_DIGEST_LENGTH], SHA2_CTX *context)
457+
SHA256Final(uint8_t digest[SHA256_DIGEST_LENGTH], SHA2_CTX *context)
458458
{
459459
SHA2_CTX *volatile const contextv = context;
460460
SHA256Pad(context);

sha2.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#ifndef __SHA2_H__
3838
#define __SHA2_H__
3939

40+
#include "stdint.h"
41+
4042
/*** SHA-256/384/512 Various Length Definitions ***********************/
4143
#define SHA256_BLOCK_LENGTH 64
4244
#define SHA256_DIGEST_LENGTH 32
@@ -45,18 +47,18 @@
4547
/*** SHA-224/256/384/512 Context Structure *******************************/
4648
typedef struct _SHA2_CTX {
4749
union {
48-
u_int32_t st32[8];
49-
u_int64_t st64[8];
50+
uint32_t st32[8];
51+
uint64_t st64[8];
5052
} state;
51-
u_int64_t bitcount[2];
52-
u_int8_t buffer[SHA256_BLOCK_LENGTH];
53+
uint64_t bitcount[2];
54+
uint8_t buffer[SHA256_BLOCK_LENGTH];
5355
} SHA2_CTX;
5456

5557
void SHA256Init(SHA2_CTX *);
56-
void SHA256Transform(u_int32_t state[8], const u_int8_t [SHA256_BLOCK_LENGTH]);
57-
void SHA256Update(SHA2_CTX *, const u_int8_t *, size_t);
58+
void SHA256Transform(uint32_t state[8], const uint8_t [SHA256_BLOCK_LENGTH]);
59+
void SHA256Update(SHA2_CTX *, const uint8_t *, size_t);
5860
void SHA256Pad(SHA2_CTX *);
59-
void SHA256Final(u_int8_t [SHA256_DIGEST_LENGTH], SHA2_CTX *);
61+
void SHA256Final(uint8_t [SHA256_DIGEST_LENGTH], SHA2_CTX *);
6062
char *SHA256End(SHA2_CTX *, char *);
6163

6264
#endif /* __SHA2_H__ */

0 commit comments

Comments
 (0)