diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/modes/xts128.c | 70 |
1 files changed, 34 insertions, 36 deletions
diff --git a/src/lib/libcrypto/modes/xts128.c b/src/lib/libcrypto/modes/xts128.c index 3e2378379e..0be23d4ea9 100644 --- a/src/lib/libcrypto/modes/xts128.c +++ b/src/lib/libcrypto/modes/xts128.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: xts128.c,v 1.6 2015/02/10 09:46:30 miod Exp $ */ | 1 | /* $OpenBSD: xts128.c,v 1.7 2017/08/13 17:46:24 bcook Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 2011 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2011 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| @@ -98,25 +98,24 @@ int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16], | |||
| 98 | 98 | ||
| 99 | if (len==0) return 0; | 99 | if (len==0) return 0; |
| 100 | 100 | ||
| 101 | if (BYTE_ORDER == LITTLE_ENDIAN) { | 101 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 102 | unsigned int carry,res; | 102 | unsigned int carry,res; |
| 103 | 103 | ||
| 104 | res = 0x87&(((int)tweak.d[3])>>31); | 104 | res = 0x87&(((int)tweak.d[3])>>31); |
| 105 | carry = (unsigned int)(tweak.u[0]>>63); | 105 | carry = (unsigned int)(tweak.u[0]>>63); |
| 106 | tweak.u[0] = (tweak.u[0]<<1)^res; | 106 | tweak.u[0] = (tweak.u[0]<<1)^res; |
| 107 | tweak.u[1] = (tweak.u[1]<<1)|carry; | 107 | tweak.u[1] = (tweak.u[1]<<1)|carry; |
| 108 | } | 108 | #else /* BIG_ENDIAN */ |
| 109 | else { | 109 | size_t c; |
| 110 | size_t c; | 110 | |
| 111 | 111 | for (c=0,i=0;i<16;++i) { | |
| 112 | for (c=0,i=0;i<16;++i) { | 112 | /*+ substitutes for |, because c is 1 bit */ |
| 113 | /*+ substitutes for |, because c is 1 bit */ | 113 | c += ((size_t)tweak.c[i])<<1; |
| 114 | c += ((size_t)tweak.c[i])<<1; | 114 | tweak.c[i] = (u8)c; |
| 115 | tweak.c[i] = (u8)c; | 115 | c = c>>8; |
| 116 | c = c>>8; | ||
| 117 | } | ||
| 118 | tweak.c[0] ^= (u8)(0x87&(0-c)); | ||
| 119 | } | 116 | } |
| 117 | tweak.c[0] ^= (u8)(0x87&(0-c)); | ||
| 118 | #endif | ||
| 120 | } | 119 | } |
| 121 | if (enc) { | 120 | if (enc) { |
| 122 | for (i=0;i<len;++i) { | 121 | for (i=0;i<len;++i) { |
| @@ -134,25 +133,24 @@ 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 (BYTE_ORDER == LITTLE_ENDIAN) { | 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); |
| 141 | carry = (unsigned int)(tweak.u[0]>>63); | 140 | carry = (unsigned int)(tweak.u[0]>>63); |
| 142 | tweak1.u[0] = (tweak.u[0]<<1)^res; | 141 | tweak1.u[0] = (tweak.u[0]<<1)^res; |
| 143 | tweak1.u[1] = (tweak.u[1]<<1)|carry; | 142 | tweak1.u[1] = (tweak.u[1]<<1)|carry; |
| 144 | } | 143 | #else |
| 145 | else { | 144 | size_t c; |
| 146 | size_t c; | 145 | |
| 147 | 146 | for (c=0,i=0;i<16;++i) { | |
| 148 | for (c=0,i=0;i<16;++i) { | 147 | /*+ substitutes for |, because c is 1 bit */ |
| 149 | /*+ substitutes for |, because c is 1 bit */ | 148 | c += ((size_t)tweak.c[i])<<1; |
| 150 | c += ((size_t)tweak.c[i])<<1; | 149 | tweak1.c[i] = (u8)c; |
| 151 | tweak1.c[i] = (u8)c; | 150 | c = c>>8; |
| 152 | c = c>>8; | ||
| 153 | } | ||
| 154 | tweak1.c[0] ^= (u8)(0x87&(0-c)); | ||
| 155 | } | 151 | } |
| 152 | tweak1.c[0] ^= (u8)(0x87&(0-c)); | ||
| 153 | #endif | ||
| 156 | #ifdef __STRICT_ALIGNMENT | 154 | #ifdef __STRICT_ALIGNMENT |
| 157 | memcpy(scratch.c,inp,16); | 155 | memcpy(scratch.c,inp,16); |
| 158 | scratch.u[0] ^= tweak1.u[0]; | 156 | scratch.u[0] ^= tweak1.u[0]; |
