From 9b95537a01ae599ba7616d4bc1c2e81563b9ca1b Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Wed, 26 Dec 2007 19:04:58 +0000 Subject: [PATCH] Fixes to make CFB1 Monte Carlo test work. --- CHANGES | 4 ++++ crypto/evp/evp.h | 3 +++ crypto/evp/evp_locl.h | 2 +- fips/aes/fips_aesavs.c | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index dba53baca8..9b04e3e2fa 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,10 @@ Changes between 0.9.8g and 0.9.8h-fips [xx XXX xxxx] + *) Add flag EVP_CIPH_FLAG_LENGTH_BITS to indicate that input buffer length + is in bits not bytes. The Monte Carlo FIPS140-2 CFB1 tests require this. + [Steve Henson] + *) Add option --with-fipslibdir to specify location of fipscanister.lib and friends. When combined with fips build option fipscanister.lib is not built but linked from the supplied directory. Always link fips diff --git a/crypto/evp/evp.h b/crypto/evp/evp.h index ed4393d8fb..8bf05de1ad 100644 --- a/crypto/evp/evp.h +++ b/crypto/evp/evp.h @@ -378,6 +378,8 @@ struct evp_cipher_st #define EVP_CIPH_FLAG_NON_FIPS_ALLOW 0x800 /* Allow use default ASN1 get/set iv */ #define EVP_CIPH_FLAG_DEFAULT_ASN1 0x1000 +/* Buffer length in bits not bytes: CFB1 mode only */ +#define EVP_CIPH_FLAG_LENGTH_BITS 0x2000 /* ctrl() values */ @@ -470,6 +472,7 @@ typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, #define M_EVP_MD_CTX_type(e) M_EVP_MD_type(M_EVP_MD_CTX_md(e)) #define M_EVP_MD_CTX_md(e) ((e)->digest) +#define M_EVP_CIPHER_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs)) int EVP_MD_type(const EVP_MD *md); #define EVP_MD_nid(e) EVP_MD_type(e) diff --git a/crypto/evp/evp_locl.h b/crypto/evp/evp_locl.h index 6f6ce16c9e..a59c4c1a61 100644 --- a/crypto/evp/evp_locl.h +++ b/crypto/evp/evp_locl.h @@ -92,7 +92,7 @@ static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const uns #define BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \ static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \ {\ - cprefix##_cfb##cbits##_encrypt(in, out, (long)(cbits==1?inl*8:inl), &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num, ctx->encrypt);\ + cprefix##_cfb##cbits##_encrypt(in, out, (long)((cbits==1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ?inl*8:inl), &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num, ctx->encrypt);\ return 1;\ } diff --git a/fips/aes/fips_aesavs.c b/fips/aes/fips_aesavs.c index 0acbdd5e36..a7002e1c1a 100644 --- a/fips/aes/fips_aesavs.c +++ b/fips/aes/fips_aesavs.c @@ -212,6 +212,8 @@ int AESTest(EVP_CIPHER_CTX *ctx, } if (EVP_CipherInit_ex(ctx, cipher, NULL, aKey, iVec, dir) <= 0) return 0; + if(!strcasecmp(amode,"CFB1")) + M_EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS); if (dir) EVP_Cipher(ctx, ciphertext, plaintext, len); else @@ -377,9 +379,11 @@ int do_mct(char *amode, case CFB1: if(j == 0) { +#if 0 /* compensate for wrong endianness of input file */ if(i == 0) ptext[0][0]<<=7; +#endif ret = AESTest(&ctx,amode,akeysz,key[i],iv[i],dir, ptext[j], ctext[j], len); } -- 2.25.1