summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2026-05-09 07:14:42 +0000
committerjsing <>2026-05-09 07:14:42 +0000
commit52d8bfcb4d1e70d7ae25fba5e980177afcb56b0b (patch)
treec40d1457f63e76f5debf62de9a18f9f2705258da /src/lib
parent7f13830604735b607b5c5026364a13c0e2536bbc (diff)
downloadopenbsd-52d8bfcb4d1e70d7ae25fba5e980177afcb56b0b.tar.gz
openbsd-52d8bfcb4d1e70d7ae25fba5e980177afcb56b0b.tar.bz2
openbsd-52d8bfcb4d1e70d7ae25fba5e980177afcb56b0b.zip
Use uint32_t instead of SHA_LONG in the SHA-256 code.
This is more readable and we already have a compile time assert that they are the same size. ok tb@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/sha/sha256.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/lib/libcrypto/sha/sha256.c b/src/lib/libcrypto/sha/sha256.c
index 25911246d2..de7904293e 100644
--- a/src/lib/libcrypto/sha/sha256.c
+++ b/src/lib/libcrypto/sha/sha256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha256.c,v 1.37 2026/05/09 07:12:51 jsing Exp $ */ 1/* $OpenBSD: sha256.c,v 1.38 2026/05/09 07:14:42 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -75,7 +75,7 @@ void sha256_block_generic(SHA256_CTX *ctx, const void *_in, size_t num);
75/* 75/*
76 * SHA-256 constants - see FIPS 180-4 section 4.2.2. 76 * SHA-256 constants - see FIPS 180-4 section 4.2.2.
77 */ 77 */
78static const SHA_LONG K256[64] = { 78static const uint32_t K256[64] = {
79 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 79 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
80 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 80 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
81 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL, 81 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL,
@@ -94,55 +94,55 @@ static const SHA_LONG K256[64] = {
94 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL, 94 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL,
95}; 95};
96 96
97static inline SHA_LONG 97static inline uint32_t
98Sigma0(SHA_LONG x) 98Sigma0(uint32_t x)
99{ 99{
100 return crypto_ror_u32(x, 2) ^ crypto_ror_u32(x, 13) ^ 100 return crypto_ror_u32(x, 2) ^ crypto_ror_u32(x, 13) ^
101 crypto_ror_u32(x, 22); 101 crypto_ror_u32(x, 22);
102} 102}
103 103
104static inline SHA_LONG 104static inline uint32_t
105Sigma1(SHA_LONG x) 105Sigma1(uint32_t x)
106{ 106{
107 return crypto_ror_u32(x, 6) ^ crypto_ror_u32(x, 11) ^ 107 return crypto_ror_u32(x, 6) ^ crypto_ror_u32(x, 11) ^
108 crypto_ror_u32(x, 25); 108 crypto_ror_u32(x, 25);
109} 109}
110 110
111static inline SHA_LONG 111static inline uint32_t
112sigma0(SHA_LONG x) 112sigma0(uint32_t x)
113{ 113{
114 return crypto_ror_u32(x, 7) ^ crypto_ror_u32(x, 18) ^ (x >> 3); 114 return crypto_ror_u32(x, 7) ^ crypto_ror_u32(x, 18) ^ (x >> 3);
115} 115}
116 116
117static inline SHA_LONG 117static inline uint32_t
118sigma1(SHA_LONG x) 118sigma1(uint32_t x)
119{ 119{
120 return crypto_ror_u32(x, 17) ^ crypto_ror_u32(x, 19) ^ (x >> 10); 120 return crypto_ror_u32(x, 17) ^ crypto_ror_u32(x, 19) ^ (x >> 10);
121} 121}
122 122
123static inline SHA_LONG 123static inline uint32_t
124Ch(SHA_LONG x, SHA_LONG y, SHA_LONG z) 124Ch(uint32_t x, uint32_t y, uint32_t z)
125{ 125{
126 return (x & y) ^ (~x & z); 126 return (x & y) ^ (~x & z);
127} 127}
128 128
129static inline SHA_LONG 129static inline uint32_t
130Maj(SHA_LONG x, SHA_LONG y, SHA_LONG z) 130Maj(uint32_t x, uint32_t y, uint32_t z)
131{ 131{
132 return (x & y) ^ (x & z) ^ (y & z); 132 return (x & y) ^ (x & z) ^ (y & z);
133} 133}
134 134
135static inline void 135static inline void
136sha256_msg_schedule_update(SHA_LONG *W0, SHA_LONG W1, SHA_LONG W9, SHA_LONG W14) 136sha256_msg_schedule_update(uint32_t *W0, uint32_t W1, uint32_t W9, uint32_t W14)
137{ 137{
138 *W0 = sigma1(W14) + W9 + sigma0(W1) + *W0; 138 *W0 = sigma1(W14) + W9 + sigma0(W1) + *W0;
139} 139}
140 140
141static inline void 141static inline void
142sha256_round(SHA_LONG *a, SHA_LONG *b, SHA_LONG *c, SHA_LONG *d, SHA_LONG *e, 142sha256_round(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e,
143 SHA_LONG *f, SHA_LONG *g, SHA_LONG *h, SHA_LONG Kt, SHA_LONG Wt) 143 uint32_t *f, uint32_t *g, uint32_t *h, uint32_t Kt, uint32_t Wt)
144{ 144{
145 SHA_LONG T1, T2; 145 uint32_t T1, T2;
146 146
147 T1 = *h + Sigma1(*e) + Ch(*e, *f, *g) + Kt + Wt; 147 T1 = *h + Sigma1(*e) + Ch(*e, *f, *g) + Kt + Wt;
148 T2 = Sigma0(*a) + Maj(*a, *b, *c); 148 T2 = Sigma0(*a) + Maj(*a, *b, *c);
@@ -161,9 +161,9 @@ void
161sha256_block_generic(SHA256_CTX *ctx, const void *_in, size_t num) 161sha256_block_generic(SHA256_CTX *ctx, const void *_in, size_t num)
162{ 162{
163 const uint8_t *in = _in; 163 const uint8_t *in = _in;
164 const SHA_LONG *in32; 164 const uint32_t *in32;
165 SHA_LONG a, b, c, d, e, f, g, h; 165 uint32_t a, b, c, d, e, f, g, h;
166 SHA_LONG W[16]; 166 uint32_t W[16];
167 int i; 167 int i;
168 168
169 while (num--) { 169 while (num--) {
@@ -178,7 +178,7 @@ sha256_block_generic(SHA256_CTX *ctx, const void *_in, size_t num)
178 178
179 if ((size_t)in % 4 == 0) { 179 if ((size_t)in % 4 == 0) {
180 /* Input is 32 bit aligned. */ 180 /* Input is 32 bit aligned. */
181 in32 = (const SHA_LONG *)in; 181 in32 = (const uint32_t *)in;
182 W[0] = be32toh(in32[0]); 182 W[0] = be32toh(in32[0]);
183 W[1] = be32toh(in32[1]); 183 W[1] = be32toh(in32[1]);
184 W[2] = be32toh(in32[2]); 184 W[2] = be32toh(in32[2]);