crypto/modes: even more strict aliasing fixes [and fix bug in cbc128.c from
[openssl.git] / crypto / modes / cbc128.c
index 34b2a2e..0e54f75 100644 (file)
@@ -137,11 +137,13 @@ void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
                                out += 16;
                        }
                }
-               else {
+               else  if (16%sizeof(size_t) == 0) { /* always true */
                        while (len>=16) {
+                               size_t *out_t=(size_t *)out, *iv_t=(size_t *)iv;
+
                                (*block)(in, out, key);
-                               for(n=0; n<16; n+=sizeof(size_t))
-                                       *(size_t *)(out+n) ^= *(size_t *)(iv+n);
+                               for(n=0; n<16/sizeof(size_t); n++)
+                                       out_t[n] ^= iv_t[n];
                                iv = in;
                                len -= 16;
                                in  += 16;
@@ -166,18 +168,19 @@ void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
                        }
                }
                else if (16%sizeof(size_t) == 0) { /* always true */
-                       size_t c, *out_t=(size_t *)out, *ivec_t=(size_t *)ivec;
-                       const size_t *in_t=(const size_t *)in;
                        while (len>=16) {
-                               (*block)((const unsigned char *)in_t, tmp.c, key);
+                               size_t c, *out_t=(size_t *)out, *ivec_t=(size_t *)ivec;
+                               const size_t *in_t=(const size_t *)in;
+
+                               (*block)(in, tmp.c, key);
                                for(n=0; n<16/sizeof(size_t); n++) {
                                        c = in_t[n];
                                        out_t[n] = tmp.t[n] ^ ivec_t[n];
                                        ivec_t[n] = c;
                                }
                                len -= 16;
-                               in_t  += 16/sizeof(size_t);
-                               out_t += 16/sizeof(size_t);
+                               in  += 16;
+                               out += 16;
                        }
                }
        }