Fix some bugs with the cfb1 bitsize handling
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Wed, 21 Feb 2018 14:48:02 +0000 (15:48 +0100)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Fri, 23 Feb 2018 13:12:18 +0000 (14:12 +0100)
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5426)

(cherry picked from commit 604e591ed75eff9296c21ee5fe93f3e9ec246094)

crypto/evp/e_aes.c
crypto/evp/e_camellia.c
crypto/include/internal/evp_int.h

index fe52213eab6a9fb6edfd304beb2469fa3d1accd4..b17154dbcc82bbf33251eabad577ed8288dbdf86 100644 (file)
@@ -1229,6 +1229,8 @@ static int aes_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
                                 EVP_CIPHER_CTX_encrypting(ctx), dat->block);
         EVP_CIPHER_CTX_set_num(ctx, num);
         len -= MAXBITCHUNK;
+        out += MAXBITCHUNK;
+        in  += MAXBITCHUNK;
     }
     if (len) {
         int num = EVP_CIPHER_CTX_num(ctx);
index b50fa0b96d6f34a4ffcb17cd16757a281ac39f59..905d7a6f06015f543027306557659eb516b024b7 100644 (file)
@@ -325,8 +325,10 @@ static int camellia_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
         int num = EVP_CIPHER_CTX_num(ctx);
         CRYPTO_cfb128_1_encrypt(in, out, MAXBITCHUNK * 8, &dat->ks,
                                 EVP_CIPHER_CTX_iv_noconst(ctx), &num, EVP_CIPHER_CTX_encrypting(ctx), dat->block);
-        len -= MAXBITCHUNK;
         EVP_CIPHER_CTX_set_num(ctx, num);
+        len -= MAXBITCHUNK;
+        out += MAXBITCHUNK;
+        in  += MAXBITCHUNK;
     }
     if (len) {
         int num = EVP_CIPHER_CTX_num(ctx);
index 6cc2f9255f3cb62973488e75e93f31124460ff51..358d720bfabff0bc399bfe32a48ca7dab11b0b82 100644 (file)
@@ -199,7 +199,7 @@ static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
         cprefix##_cfb##cbits##_encrypt(in, out, (long) \
             ((cbits == 1) \
                 && !EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS) \
-                ? inl*8 : inl), \
+                ? chunk*8 : chunk), \
             &EVP_C_DATA(kstruct, ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx),\
             &num, EVP_CIPHER_CTX_encrypting(ctx));\
         EVP_CIPHER_CTX_set_num(ctx, num);\