summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/modes/xts128.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/modes/xts128.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/modes/xts128.c')
-rw-r--r--src/lib/libcrypto/modes/xts128.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/lib/libcrypto/modes/xts128.c b/src/lib/libcrypto/modes/xts128.c
index 9cf27a25e9..de23de457d 100644
--- a/src/lib/libcrypto/modes/xts128.c
+++ b/src/lib/libcrypto/modes/xts128.c
@@ -62,7 +62,6 @@ int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
62 const unsigned char *inp, unsigned char *out, 62 const unsigned char *inp, unsigned char *out,
63 size_t len, int enc) 63 size_t len, int enc)
64{ 64{
65 const union { long one; char little; } is_endian = {1};
66 union { u64 u[2]; u32 d[4]; u8 c[16]; } tweak, scratch; 65 union { u64 u[2]; u32 d[4]; u8 c[16]; } tweak, scratch;
67 unsigned int i; 66 unsigned int i;
68 67
@@ -98,7 +97,7 @@ int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
98 97
99 if (len==0) return 0; 98 if (len==0) return 0;
100 99
101 if (is_endian.little) { 100 if (_BYTE_ORDER == _LITTLE_ENDIAN) {
102 unsigned int carry,res; 101 unsigned int carry,res;
103 102
104 res = 0x87&(((int)tweak.d[3])>>31); 103 res = 0x87&(((int)tweak.d[3])>>31);
@@ -134,7 +133,7 @@ int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
134 else { 133 else {
135 union { u64 u[2]; u8 c[16]; } tweak1; 134 union { u64 u[2]; u8 c[16]; } tweak1;
136 135
137 if (is_endian.little) { 136 if (_BYTE_ORDER == _LITTLE_ENDIAN) {
138 unsigned int carry,res; 137 unsigned int carry,res;
139 138
140 res = 0x87&(((int)tweak.d[3])>>31); 139 res = 0x87&(((int)tweak.d[3])>>31);