Correct AES counter mode, which incorrectly incremented the counter before
[openssl.git] / crypto / aes / aes_ctr.c
index 8e800481de00fb26b4de1dcc50da38e070796749..aea3db209272189e4e8fcd6638a3e3ed51048e10 100644 (file)
@@ -106,8 +106,8 @@ void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
 
        while (l--) {
                if (n == 0) {
 
        while (l--) {
                if (n == 0) {
-                       AES_ctr128_inc(counter);
                        AES_encrypt(counter, tmp, key);
                        AES_encrypt(counter, tmp, key);
+                       AES_ctr128_inc(counter);
                }
                *(out++) = *(in++) ^ tmp[n];
                n = (n+1) % AES_BLOCK_SIZE;
                }
                *(out++) = *(in++) ^ tmp[n];
                n = (n+1) % AES_BLOCK_SIZE;