summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/modes/cts128.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/modes/cts128.c')
-rw-r--r--src/lib/libcrypto/modes/cts128.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/src/lib/libcrypto/modes/cts128.c b/src/lib/libcrypto/modes/cts128.c
index c0e1f3696c..2d583de6f6 100644
--- a/src/lib/libcrypto/modes/cts128.c
+++ b/src/lib/libcrypto/modes/cts128.c
@@ -108,12 +108,8 @@ size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out,
108 (*cbc)(in,out-16,residue,key,ivec,1); 108 (*cbc)(in,out-16,residue,key,ivec,1);
109 memcpy(out,tmp.c,residue); 109 memcpy(out,tmp.c,residue);
110#else 110#else
111 { 111 memset(tmp.c,0,sizeof(tmp));
112 size_t n;
113 for (n=0; n<16; n+=sizeof(size_t))
114 *(size_t *)(tmp.c+n) = 0;
115 memcpy(tmp.c,in,residue); 112 memcpy(tmp.c,in,residue);
116 }
117 memcpy(out,out-16,residue); 113 memcpy(out,out-16,residue);
118 (*cbc)(tmp.c,out-16,16,key,ivec,1); 114 (*cbc)(tmp.c,out-16,16,key,ivec,1);
119#endif 115#endif
@@ -144,12 +140,8 @@ size_t CRYPTO_nistcts128_encrypt(const unsigned char *in, unsigned char *out,
144#if defined(CBC_HANDLES_TRUNCATED_IO) 140#if defined(CBC_HANDLES_TRUNCATED_IO)
145 (*cbc)(in,out-16+residue,residue,key,ivec,1); 141 (*cbc)(in,out-16+residue,residue,key,ivec,1);
146#else 142#else
147 { 143 memset(tmp.c,0,sizeof(tmp));
148 size_t n;
149 for (n=0; n<16; n+=sizeof(size_t))
150 *(size_t *)(tmp.c+n) = 0;
151 memcpy(tmp.c,in,residue); 144 memcpy(tmp.c,in,residue);
152 }
153 (*cbc)(tmp.c,out-16+residue,16,key,ivec,1); 145 (*cbc)(tmp.c,out-16+residue,16,key,ivec,1);
154#endif 146#endif
155 return len+residue; 147 return len+residue;
@@ -177,8 +169,7 @@ size_t CRYPTO_cts128_decrypt_block(const unsigned char *in, unsigned char *out,
177 169
178 (*block)(in,tmp.c+16,key); 170 (*block)(in,tmp.c+16,key);
179 171
180 for (n=0; n<16; n+=sizeof(size_t)) 172 memcpy(tmp.c,tmp.c+16,16);
181 *(size_t *)(tmp.c+n) = *(size_t *)(tmp.c+16+n);
182 memcpy(tmp.c,in+16,residue); 173 memcpy(tmp.c,in+16,residue);
183 (*block)(tmp.c,tmp.c,key); 174 (*block)(tmp.c,tmp.c,key);
184 175
@@ -220,8 +211,7 @@ size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in, unsigned char *o
220 211
221 (*block)(in+residue,tmp.c+16,key); 212 (*block)(in+residue,tmp.c+16,key);
222 213
223 for (n=0; n<16; n+=sizeof(size_t)) 214 memcpy(tmp.c,tmp.c+16,16);
224 *(size_t *)(tmp.c+n) = *(size_t *)(tmp.c+16+n);
225 memcpy(tmp.c,in,residue); 215 memcpy(tmp.c,in,residue);
226 (*block)(tmp.c,tmp.c,key); 216 (*block)(tmp.c,tmp.c,key);
227 217
@@ -240,7 +230,7 @@ size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in, unsigned char *o
240size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out, 230size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
241 size_t len, const void *key, 231 size_t len, const void *key,
242 unsigned char ivec[16], cbc128_f cbc) 232 unsigned char ivec[16], cbc128_f cbc)
243{ size_t residue, n; 233{ size_t residue;
244 union { size_t align; unsigned char c[32]; } tmp; 234 union { size_t align; unsigned char c[32]; } tmp;
245 235
246 assert (in && out && key && ivec); 236 assert (in && out && key && ivec);
@@ -257,8 +247,7 @@ size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
257 out += len; 247 out += len;
258 } 248 }
259 249
260 for (n=16; n<32; n+=sizeof(size_t)) 250 memset(tmp.c,0,sizeof(tmp));
261 *(size_t *)(tmp.c+n) = 0;
262 /* this places in[16] at &tmp.c[16] and decrypted block at &tmp.c[0] */ 251 /* this places in[16] at &tmp.c[16] and decrypted block at &tmp.c[0] */
263 (*cbc)(in,tmp.c,16,key,tmp.c+16,0); 252 (*cbc)(in,tmp.c,16,key,tmp.c+16,0);
264 253
@@ -275,7 +264,7 @@ size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
275size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out, 264size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out,
276 size_t len, const void *key, 265 size_t len, const void *key,
277 unsigned char ivec[16], cbc128_f cbc) 266 unsigned char ivec[16], cbc128_f cbc)
278{ size_t residue, n; 267{ size_t residue;
279 union { size_t align; unsigned char c[32]; } tmp; 268 union { size_t align; unsigned char c[32]; } tmp;
280 269
281 assert (in && out && key && ivec); 270 assert (in && out && key && ivec);
@@ -297,8 +286,7 @@ size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out,
297 out += len; 286 out += len;
298 } 287 }
299 288
300 for (n=16; n<32; n+=sizeof(size_t)) 289 memset(tmp.c,0,sizeof(tmp));
301 *(size_t *)(tmp.c+n) = 0;
302 /* this places in[16] at &tmp.c[16] and decrypted block at &tmp.c[0] */ 290 /* this places in[16] at &tmp.c[16] and decrypted block at &tmp.c[0] */
303 (*cbc)(in+residue,tmp.c,16,key,tmp.c+16,0); 291 (*cbc)(in+residue,tmp.c,16,key,tmp.c+16,0);
304 292