diff options
author | miod <> | 2014-05-07 22:05:48 +0000 |
---|---|---|
committer | miod <> | 2014-05-07 22:05:48 +0000 |
commit | 55b870bc0442258199f29518a1c056569c6cff35 (patch) | |
tree | deb34c5a4686fe5f3219b9c2cc98fdf18af20a2d /src/lib/libcrypto/modes | |
parent | 6e694fdc39d16d30d31406ef82c6b069d9d005d9 (diff) | |
download | openbsd-55b870bc0442258199f29518a1c056569c6cff35.tar.gz openbsd-55b870bc0442258199f29518a1c056569c6cff35.tar.bz2 openbsd-55b870bc0442258199f29518a1c056569c6cff35.zip |
Get __STRICT_ALIGNMENT from <machine/endian.h> and decide upon it, rather
than defining it for not (i386 and amd64 (and sometimes s390)) only.
Compile-time tests remain compile-time tests, and runtime-test remain
runtime-test instead of being converted to compile-time tests, per matthew@'s
explicit demand (rationale: this makes sure the compiler checks your code even
if you won't run it).
No functional change except on s390 (which we don't run on) and vax (which we
run on, but noone cares about)
ok matthew@
Diffstat (limited to 'src/lib/libcrypto/modes')
-rw-r--r-- | src/lib/libcrypto/modes/cbc128.c | 13 | ||||
-rw-r--r-- | src/lib/libcrypto/modes/ccm128.c | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/modes/cfb128.c | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/modes/ctr128.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/modes/gcm128.c | 6 | ||||
-rw-r--r-- | src/lib/libcrypto/modes/modes_lcl.h | 12 | ||||
-rw-r--r-- | src/lib/libcrypto/modes/ofb128.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/modes/xts128.c | 9 |
8 files changed, 25 insertions, 31 deletions
diff --git a/src/lib/libcrypto/modes/cbc128.c b/src/lib/libcrypto/modes/cbc128.c index 0e54f75470..e4920a93ac 100644 --- a/src/lib/libcrypto/modes/cbc128.c +++ b/src/lib/libcrypto/modes/cbc128.c | |||
@@ -59,8 +59,11 @@ | |||
59 | #endif | 59 | #endif |
60 | #include <assert.h> | 60 | #include <assert.h> |
61 | 61 | ||
62 | #ifndef STRICT_ALIGNMENT | 62 | #undef STRICT_ALIGNMENT |
63 | # define STRICT_ALIGNMENT 0 | 63 | #ifdef __STRICT_ALIGNMENT |
64 | #define STRICT_ALIGNMENT 1 | ||
65 | #else | ||
66 | #define STRICT_ALIGNMENT 0 | ||
64 | #endif | 67 | #endif |
65 | 68 | ||
66 | void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out, | 69 | void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out, |
@@ -136,8 +139,7 @@ void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out, | |||
136 | in += 16; | 139 | in += 16; |
137 | out += 16; | 140 | out += 16; |
138 | } | 141 | } |
139 | } | 142 | } else if (16%sizeof(size_t) == 0) { /* always true */ |
140 | else if (16%sizeof(size_t) == 0) { /* always true */ | ||
141 | while (len>=16) { | 143 | while (len>=16) { |
142 | size_t *out_t=(size_t *)out, *iv_t=(size_t *)iv; | 144 | size_t *out_t=(size_t *)out, *iv_t=(size_t *)iv; |
143 | 145 | ||
@@ -166,8 +168,7 @@ void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out, | |||
166 | in += 16; | 168 | in += 16; |
167 | out += 16; | 169 | out += 16; |
168 | } | 170 | } |
169 | } | 171 | } else if (16%sizeof(size_t) == 0) { /* always true */ |
170 | else if (16%sizeof(size_t) == 0) { /* always true */ | ||
171 | while (len>=16) { | 172 | while (len>=16) { |
172 | size_t c, *out_t=(size_t *)out, *ivec_t=(size_t *)ivec; | 173 | size_t c, *out_t=(size_t *)out, *ivec_t=(size_t *)ivec; |
173 | const size_t *in_t=(const size_t *)in; | 174 | const size_t *in_t=(const size_t *)in; |
diff --git a/src/lib/libcrypto/modes/ccm128.c b/src/lib/libcrypto/modes/ccm128.c index 3ce11d0d98..13bc7adf31 100644 --- a/src/lib/libcrypto/modes/ccm128.c +++ b/src/lib/libcrypto/modes/ccm128.c | |||
@@ -197,7 +197,7 @@ int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx, | |||
197 | if (ctx->blocks > (U64(1)<<61)) return -2; /* too much data */ | 197 | if (ctx->blocks > (U64(1)<<61)) return -2; /* too much data */ |
198 | 198 | ||
199 | while (len>=16) { | 199 | while (len>=16) { |
200 | #if defined(STRICT_ALIGNMENT) | 200 | #ifdef __STRICT_ALIGNMENT |
201 | union { u64 u[2]; u8 c[16]; } temp; | 201 | union { u64 u[2]; u8 c[16]; } temp; |
202 | 202 | ||
203 | memcpy (temp.c,inp,16); | 203 | memcpy (temp.c,inp,16); |
@@ -210,7 +210,7 @@ int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx, | |||
210 | (*block)(ctx->cmac.c,ctx->cmac.c,key); | 210 | (*block)(ctx->cmac.c,ctx->cmac.c,key); |
211 | (*block)(ctx->nonce.c,scratch.c,key); | 211 | (*block)(ctx->nonce.c,scratch.c,key); |
212 | ctr64_inc(ctx->nonce.c); | 212 | ctr64_inc(ctx->nonce.c); |
213 | #if defined(STRICT_ALIGNMENT) | 213 | #ifdef __STRICT_ALIGNMENT |
214 | temp.u[0] ^= scratch.u[0]; | 214 | temp.u[0] ^= scratch.u[0]; |
215 | temp.u[1] ^= scratch.u[1]; | 215 | temp.u[1] ^= scratch.u[1]; |
216 | memcpy(out,temp.c,16); | 216 | memcpy(out,temp.c,16); |
@@ -268,12 +268,12 @@ int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx, | |||
268 | if (n!=len) return -1; | 268 | if (n!=len) return -1; |
269 | 269 | ||
270 | while (len>=16) { | 270 | while (len>=16) { |
271 | #if defined(STRICT_ALIGNMENT) | 271 | #ifdef __STRICT_ALIGNMENT |
272 | union { u64 u[2]; u8 c[16]; } temp; | 272 | union { u64 u[2]; u8 c[16]; } temp; |
273 | #endif | 273 | #endif |
274 | (*block)(ctx->nonce.c,scratch.c,key); | 274 | (*block)(ctx->nonce.c,scratch.c,key); |
275 | ctr64_inc(ctx->nonce.c); | 275 | ctr64_inc(ctx->nonce.c); |
276 | #if defined(STRICT_ALIGNMENT) | 276 | #ifdef __STRICT_ALIGNMENT |
277 | memcpy (temp.c,inp,16); | 277 | memcpy (temp.c,inp,16); |
278 | ctx->cmac.u[0] ^= (scratch.u[0] ^= temp.u[0]); | 278 | ctx->cmac.u[0] ^= (scratch.u[0] ^= temp.u[0]); |
279 | ctx->cmac.u[1] ^= (scratch.u[1] ^= temp.u[1]); | 279 | ctx->cmac.u[1] ^= (scratch.u[1] ^= temp.u[1]); |
diff --git a/src/lib/libcrypto/modes/cfb128.c b/src/lib/libcrypto/modes/cfb128.c index 4e6f5d35e1..731cb2864a 100644 --- a/src/lib/libcrypto/modes/cfb128.c +++ b/src/lib/libcrypto/modes/cfb128.c | |||
@@ -83,7 +83,7 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out, | |||
83 | --len; | 83 | --len; |
84 | n = (n+1) % 16; | 84 | n = (n+1) % 16; |
85 | } | 85 | } |
86 | #if defined(STRICT_ALIGNMENT) | 86 | #ifdef __STRICT_ALIGNMENT |
87 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) | 87 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) |
88 | break; | 88 | break; |
89 | #endif | 89 | #endif |
@@ -128,7 +128,7 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out, | |||
128 | --len; | 128 | --len; |
129 | n = (n+1) % 16; | 129 | n = (n+1) % 16; |
130 | } | 130 | } |
131 | #if defined(STRICT_ALIGNMENT) | 131 | #ifdef __STRICT_ALIGNMENT |
132 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) | 132 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) |
133 | break; | 133 | break; |
134 | #endif | 134 | #endif |
diff --git a/src/lib/libcrypto/modes/ctr128.c b/src/lib/libcrypto/modes/ctr128.c index 96af854f8a..ab45e0bd7a 100644 --- a/src/lib/libcrypto/modes/ctr128.c +++ b/src/lib/libcrypto/modes/ctr128.c | |||
@@ -133,7 +133,7 @@ void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out, | |||
133 | n = (n+1) % 16; | 133 | n = (n+1) % 16; |
134 | } | 134 | } |
135 | 135 | ||
136 | #if defined(STRICT_ALIGNMENT) | 136 | #ifdef __STRICT_ALIGNMENT |
137 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) | 137 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) |
138 | break; | 138 | break; |
139 | #endif | 139 | #endif |
diff --git a/src/lib/libcrypto/modes/gcm128.c b/src/lib/libcrypto/modes/gcm128.c index 92b7f4f3c8..f3bcb7dd6e 100644 --- a/src/lib/libcrypto/modes/gcm128.c +++ b/src/lib/libcrypto/modes/gcm128.c | |||
@@ -60,7 +60,7 @@ | |||
60 | #endif | 60 | #endif |
61 | #include <assert.h> | 61 | #include <assert.h> |
62 | 62 | ||
63 | #if defined(BSWAP4) && defined(STRICT_ALIGNMENT) | 63 | #if defined(BSWAP4) && defined(__STRICT_ALIGNMENT) |
64 | /* redefine, because alignment is ensured */ | 64 | /* redefine, because alignment is ensured */ |
65 | #undef GETU32 | 65 | #undef GETU32 |
66 | #define GETU32(p) BSWAP4(*(const u32 *)(p)) | 66 | #define GETU32(p) BSWAP4(*(const u32 *)(p)) |
@@ -935,7 +935,7 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx, | |||
935 | return 0; | 935 | return 0; |
936 | } | 936 | } |
937 | } | 937 | } |
938 | #if defined(STRICT_ALIGNMENT) | 938 | #ifdef __STRICT_ALIGNMENT |
939 | if (((size_t)in|(size_t)out)%sizeof(size_t) != 0) | 939 | if (((size_t)in|(size_t)out)%sizeof(size_t) != 0) |
940 | break; | 940 | break; |
941 | #endif | 941 | #endif |
@@ -1113,7 +1113,7 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, | |||
1113 | return 0; | 1113 | return 0; |
1114 | } | 1114 | } |
1115 | } | 1115 | } |
1116 | #if defined(STRICT_ALIGNMENT) | 1116 | #ifdef __STRICT_ALIGNMENT |
1117 | if (((size_t)in|(size_t)out)%sizeof(size_t) != 0) | 1117 | if (((size_t)in|(size_t)out)%sizeof(size_t) != 0) |
1118 | break; | 1118 | break; |
1119 | #endif | 1119 | #endif |
diff --git a/src/lib/libcrypto/modes/modes_lcl.h b/src/lib/libcrypto/modes/modes_lcl.h index 68c0e355ad..a53333df3d 100644 --- a/src/lib/libcrypto/modes/modes_lcl.h +++ b/src/lib/libcrypto/modes/modes_lcl.h | |||
@@ -22,14 +22,6 @@ typedef unsigned long long u64; | |||
22 | typedef unsigned int u32; | 22 | typedef unsigned int u32; |
23 | typedef unsigned char u8; | 23 | typedef unsigned char u8; |
24 | 24 | ||
25 | #define STRICT_ALIGNMENT 1 | ||
26 | #if defined(__i386) || defined(__i386__) || \ | ||
27 | defined(__x86_64) || defined(__x86_64__) || \ | ||
28 | defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) || \ | ||
29 | defined(__s390__) || defined(__s390x__) | ||
30 | # undef STRICT_ALIGNMENT | ||
31 | #endif | ||
32 | |||
33 | #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) | 25 | #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) |
34 | #if defined(__GNUC__) && __GNUC__>=2 | 26 | #if defined(__GNUC__) && __GNUC__>=2 |
35 | # if defined(__x86_64) || defined(__x86_64__) | 27 | # if defined(__x86_64) || defined(__x86_64__) |
@@ -47,7 +39,7 @@ typedef unsigned char u8; | |||
47 | # define BSWAP4(x) ({ u32 ret=(x); \ | 39 | # define BSWAP4(x) ({ u32 ret=(x); \ |
48 | asm ("bswapl %0" \ | 40 | asm ("bswapl %0" \ |
49 | : "+r"(ret)); ret; }) | 41 | : "+r"(ret)); ret; }) |
50 | # elif (defined(__arm__) || defined(__arm)) && !defined(STRICT_ALIGNMENT) | 42 | # elif (defined(__arm__) || defined(__arm)) && !defined(__STRICT_ALIGNMENT) |
51 | # define BSWAP8(x) ({ u32 lo=(u64)(x)>>32,hi=(x); \ | 43 | # define BSWAP8(x) ({ u32 lo=(u64)(x)>>32,hi=(x); \ |
52 | asm ("rev %0,%0; rev %1,%1" \ | 44 | asm ("rev %0,%0; rev %1,%1" \ |
53 | : "+r"(hi),"+r"(lo)); \ | 45 | : "+r"(hi),"+r"(lo)); \ |
@@ -60,7 +52,7 @@ typedef unsigned char u8; | |||
60 | #endif | 52 | #endif |
61 | #endif | 53 | #endif |
62 | 54 | ||
63 | #if defined(BSWAP4) && !defined(STRICT_ALIGNMENT) | 55 | #if defined(BSWAP4) && !defined(__STRICT_ALIGNMENT) |
64 | #define GETU32(p) BSWAP4(*(const u32 *)(p)) | 56 | #define GETU32(p) BSWAP4(*(const u32 *)(p)) |
65 | #define PUTU32(p,v) *(u32 *)(p) = BSWAP4(v) | 57 | #define PUTU32(p,v) *(u32 *)(p) = BSWAP4(v) |
66 | #else | 58 | #else |
diff --git a/src/lib/libcrypto/modes/ofb128.c b/src/lib/libcrypto/modes/ofb128.c index 01c01702c4..147c80c549 100644 --- a/src/lib/libcrypto/modes/ofb128.c +++ b/src/lib/libcrypto/modes/ofb128.c | |||
@@ -82,7 +82,7 @@ void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out, | |||
82 | --len; | 82 | --len; |
83 | n = (n+1) % 16; | 83 | n = (n+1) % 16; |
84 | } | 84 | } |
85 | #if defined(STRICT_ALIGNMENT) | 85 | #ifdef __STRICT_ALIGNMENT |
86 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) | 86 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) |
87 | break; | 87 | break; |
88 | #endif | 88 | #endif |
diff --git a/src/lib/libcrypto/modes/xts128.c b/src/lib/libcrypto/modes/xts128.c index de23de457d..9dcd16885d 100644 --- a/src/lib/libcrypto/modes/xts128.c +++ b/src/lib/libcrypto/modes/xts128.c | |||
@@ -47,6 +47,7 @@ | |||
47 | * ==================================================================== | 47 | * ==================================================================== |
48 | */ | 48 | */ |
49 | 49 | ||
50 | #include <machine/endian.h> | ||
50 | #include <openssl/crypto.h> | 51 | #include <openssl/crypto.h> |
51 | #include "modes_lcl.h" | 52 | #include "modes_lcl.h" |
52 | #include <string.h> | 53 | #include <string.h> |
@@ -74,7 +75,7 @@ int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16], | |||
74 | if (!enc && (len%16)) len-=16; | 75 | if (!enc && (len%16)) len-=16; |
75 | 76 | ||
76 | while (len>=16) { | 77 | while (len>=16) { |
77 | #if defined(STRICT_ALIGNMENT) | 78 | #ifdef __STRICT_ALIGNMENT |
78 | memcpy(scratch.c,inp,16); | 79 | memcpy(scratch.c,inp,16); |
79 | scratch.u[0] ^= tweak.u[0]; | 80 | scratch.u[0] ^= tweak.u[0]; |
80 | scratch.u[1] ^= tweak.u[1]; | 81 | scratch.u[1] ^= tweak.u[1]; |
@@ -83,7 +84,7 @@ int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16], | |||
83 | scratch.u[1] = ((u64*)inp)[1]^tweak.u[1]; | 84 | scratch.u[1] = ((u64*)inp)[1]^tweak.u[1]; |
84 | #endif | 85 | #endif |
85 | (*ctx->block1)(scratch.c,scratch.c,ctx->key1); | 86 | (*ctx->block1)(scratch.c,scratch.c,ctx->key1); |
86 | #if defined(STRICT_ALIGNMENT) | 87 | #ifdef __STRICT_ALIGNMENT |
87 | scratch.u[0] ^= tweak.u[0]; | 88 | scratch.u[0] ^= tweak.u[0]; |
88 | scratch.u[1] ^= tweak.u[1]; | 89 | scratch.u[1] ^= tweak.u[1]; |
89 | memcpy(out,scratch.c,16); | 90 | memcpy(out,scratch.c,16); |
@@ -152,7 +153,7 @@ int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16], | |||
152 | } | 153 | } |
153 | tweak1.c[0] ^= (u8)(0x87&(0-c)); | 154 | tweak1.c[0] ^= (u8)(0x87&(0-c)); |
154 | } | 155 | } |
155 | #if defined(STRICT_ALIGNMENT) | 156 | #ifdef __STRICT_ALIGNMENT |
156 | memcpy(scratch.c,inp,16); | 157 | memcpy(scratch.c,inp,16); |
157 | scratch.u[0] ^= tweak1.u[0]; | 158 | scratch.u[0] ^= tweak1.u[0]; |
158 | scratch.u[1] ^= tweak1.u[1]; | 159 | scratch.u[1] ^= tweak1.u[1]; |
@@ -172,7 +173,7 @@ int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16], | |||
172 | scratch.u[0] ^= tweak.u[0]; | 173 | scratch.u[0] ^= tweak.u[0]; |
173 | scratch.u[1] ^= tweak.u[1]; | 174 | scratch.u[1] ^= tweak.u[1]; |
174 | (*ctx->block1)(scratch.c,scratch.c,ctx->key1); | 175 | (*ctx->block1)(scratch.c,scratch.c,ctx->key1); |
175 | #if defined(STRICT_ALIGNMENT) | 176 | #ifdef __STRICT_ALIGNMENT |
176 | scratch.u[0] ^= tweak.u[0]; | 177 | scratch.u[0] ^= tweak.u[0]; |
177 | scratch.u[1] ^= tweak.u[1]; | 178 | scratch.u[1] ^= tweak.u[1]; |
178 | memcpy (out,scratch.c,16); | 179 | memcpy (out,scratch.c,16); |