summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/sha/sha256.c
diff options
context:
space:
mode:
authormiod <>2014-04-23 18:40:39 +0000
committermiod <>2014-04-23 18:40:39 +0000
commit7f5d17891e05458836147cd2b05889fde1e7be19 (patch)
treee1e4b99a334105ef85f59fe57d8b382b9d71b773 /src/lib/libcrypto/sha/sha256.c
parent909fa81274d3ab37a13fd6a376b38c3652c1ec4f (diff)
downloadopenbsd-7f5d17891e05458836147cd2b05889fde1e7be19.tar.gz
openbsd-7f5d17891e05458836147cd2b05889fde1e7be19.tar.bz2
openbsd-7f5d17891e05458836147cd2b05889fde1e7be19.zip
Figure out endianness at compile-time, using _BYTE_ORDER from
<machine/endian.h>, rather than writing 1 to a 32-bit variable and checking whether the first byte is nonzero. tweaks and ok matthew@; ok beck@ tedu@
Diffstat (limited to 'src/lib/libcrypto/sha/sha256.c')
-rw-r--r--src/lib/libcrypto/sha/sha256.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/lib/libcrypto/sha/sha256.c b/src/lib/libcrypto/sha/sha256.c
index 4eae074849..e767afde5a 100644
--- a/src/lib/libcrypto/sha/sha256.c
+++ b/src/lib/libcrypto/sha/sha256.c
@@ -9,6 +9,7 @@
9 9
10#include <stdlib.h> 10#include <stdlib.h>
11#include <string.h> 11#include <string.h>
12#include <machine/endian.h>
12 13
13#include <openssl/crypto.h> 14#include <openssl/crypto.h>
14#include <openssl/sha.h> 15#include <openssl/sha.h>
@@ -206,14 +207,14 @@ static void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num
206 SHA_LONG X[16]; 207 SHA_LONG X[16];
207 int i; 208 int i;
208 const unsigned char *data=in; 209 const unsigned char *data=in;
209 const union { long one; char little; } is_endian = {1};
210 210
211 while (num--) { 211 while (num--) {
212 212
213 a = ctx->h[0]; b = ctx->h[1]; c = ctx->h[2]; d = ctx->h[3]; 213 a = ctx->h[0]; b = ctx->h[1]; c = ctx->h[2]; d = ctx->h[3];
214 e = ctx->h[4]; f = ctx->h[5]; g = ctx->h[6]; h = ctx->h[7]; 214 e = ctx->h[4]; f = ctx->h[5]; g = ctx->h[6]; h = ctx->h[7];
215 215
216 if (!is_endian.little && sizeof(SHA_LONG)==4 && ((size_t)in%4)==0) 216 if (_BYTE_ORDER != _LITTLE_ENDIAN &&
217 sizeof(SHA_LONG)==4 && ((size_t)in%4)==0)
217 { 218 {
218 const SHA_LONG *W=(const SHA_LONG *)data; 219 const SHA_LONG *W=(const SHA_LONG *)data;
219 220