From 398c57b0b3bbe9cb304bd06ef0e343972617400b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 23 Jun 2014 12:10:59 +0200 Subject: [PATCH] Blowfish accepts variable key len in cipher layer --- ChangeLog | 1 + library/cipher.c | 5 +++- library/cipher_wrap.c | 8 +++--- tests/suites/test_suite_cipher.blowfish.data | 29 ++++++++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b266d572..c1df10958 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ Features * Support for CCM and CCM_8 ciphersuites * Support for parsing and verifying RSASSA-PSS signatures in the X.509 modules (certificates, CRLs and CSRs). + * Blowfish in the cipher layer now supports variable length keys. Changes * Add LINK_WITH_PTHREAD option in CMake for explicit linking that is diff --git a/library/cipher.c b/library/cipher.c index 01913b5e1..558c4b35b 100644 --- a/library/cipher.c +++ b/library/cipher.c @@ -168,8 +168,11 @@ int cipher_setkey( cipher_context_t *ctx, const unsigned char *key, if( NULL == ctx || NULL == ctx->cipher_info ) return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA ); - if( (int) ctx->cipher_info->key_length != key_length ) + if( ( ctx->cipher_info->flags & POLARSSL_CIPHER_VARIABLE_KEY_LEN ) == 0 && + (int) ctx->cipher_info->key_length != key_length ) + { return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA ); + } ctx->key_length = key_length; ctx->operation = operation; diff --git a/library/cipher_wrap.c b/library/cipher_wrap.c index 34fc9e7e5..f4d39fa26 100644 --- a/library/cipher_wrap.c +++ b/library/cipher_wrap.c @@ -1180,7 +1180,7 @@ const cipher_info_t blowfish_ecb_info = { 128, "BLOWFISH-ECB", 8, - 0, + POLARSSL_CIPHER_VARIABLE_KEY_LEN, 8, &blowfish_info }; @@ -1192,7 +1192,7 @@ const cipher_info_t blowfish_cbc_info = { 128, "BLOWFISH-CBC", 8, - 0, + POLARSSL_CIPHER_VARIABLE_KEY_LEN, 8, &blowfish_info }; @@ -1205,7 +1205,7 @@ const cipher_info_t blowfish_cfb64_info = { 128, "BLOWFISH-CFB64", 8, - 0, + POLARSSL_CIPHER_VARIABLE_KEY_LEN, 8, &blowfish_info }; @@ -1218,7 +1218,7 @@ const cipher_info_t blowfish_ctr_info = { 128, "BLOWFISH-CTR", 8, - 0, + POLARSSL_CIPHER_VARIABLE_KEY_LEN, 8, &blowfish_info }; diff --git a/tests/suites/test_suite_cipher.blowfish.data b/tests/suites/test_suite_cipher.blowfish.data index f9cfd36ec..bd0f890f0 100644 --- a/tests/suites/test_suite_cipher.blowfish.data +++ b/tests/suites/test_suite_cipher.blowfish.data @@ -550,6 +550,18 @@ BLOWFISH Encrypt and decrypt 32 bytes in multiple parts 1 depends_on:POLARSSL_BLOWFISH_C:POLARSSL_CIPHER_MODE_CTR enc_dec_buf_multipart:POLARSSL_CIPHER_BLOWFISH_CTR:128:16:16: +BLOWFISH CBC Encrypt and decrypt 7 bytes, 192-bits key +depends_on:POLARSSL_BLOWFISH_C:POLARSSL_CIPHER_MODE_CBC:POLARSSL_CIPHER_PADDING_PKCS7 +enc_dec_buf:POLARSSL_CIPHER_BLOWFISH_CBC:"BLOWFISH-CBC":192:7:-1 + +BLOWFISH CTR Encrypt and decrypt 7 bytes, 192-bits key +depends_on:POLARSSL_BLOWFISH_C:POLARSSL_CIPHER_MODE_CTR +enc_dec_buf:POLARSSL_CIPHER_BLOWFISH_CTR:"BLOWFISH-CTR":192:7:-1 + +BLOWFISH CFB64 Encrypt and decrypt 7 bytes, 192-bits key +depends_on:POLARSSL_BLOWFISH_C:POLARSSL_CIPHER_MODE_CFB +enc_dec_buf:POLARSSL_CIPHER_BLOWFISH_CFB64:"BLOWFISH-CFB64":192:7:-1 + BLOWFISH ECB Encrypt test vector (SSLeay) #1 depends_on:POLARSSL_BLOWFISH_C test_vec_ecb:POLARSSL_CIPHER_BLOWFISH_ECB:POLARSSL_ENCRYPT:"00000000000000000000000000000000":"0000000000000000":"4ef997456198dd78":0 @@ -562,6 +574,14 @@ BLOWFISH ECB Encrypt test vector (SSLeay) #3 depends_on:POLARSSL_BLOWFISH_C test_vec_ecb:POLARSSL_CIPHER_BLOWFISH_ECB:POLARSSL_ENCRYPT:"fedcba9876543210fedcba9876543210":"0123456789abcdef":"0aceab0fc6a0a28d":0 +BLOWFISH ECB Encrypt test vector (SSLeay) #3, 64-bit key +depends_on:POLARSSL_BLOWFISH_C +test_vec_ecb:POLARSSL_CIPHER_BLOWFISH_ECB:POLARSSL_ENCRYPT:"fedcba9876543210":"0123456789abcdef":"0aceab0fc6a0a28d":0 + +BLOWFISH ECB Encrypt test vector (SSLeay) #3, 192-bit key +depends_on:POLARSSL_BLOWFISH_C +test_vec_ecb:POLARSSL_CIPHER_BLOWFISH_ECB:POLARSSL_ENCRYPT:"fedcba9876543210fedcba9876543210fedcba9876543210":"0123456789abcdef":"0aceab0fc6a0a28d":0 + BLOWFISH ECB Decrypt test vector (SSLeay) #1 depends_on:POLARSSL_BLOWFISH_C test_vec_ecb:POLARSSL_CIPHER_BLOWFISH_ECB:POLARSSL_DECRYPT:"00000000000000000000000000000000":"4ef997456198dd78":"0000000000000000":0 @@ -573,3 +593,12 @@ test_vec_ecb:POLARSSL_CIPHER_BLOWFISH_ECB:POLARSSL_DECRYPT:"ffffffffffffffffffff BLOWFISH ECB Decrypt test vector (SSLeay) #3 depends_on:POLARSSL_BLOWFISH_C test_vec_ecb:POLARSSL_CIPHER_BLOWFISH_ECB:POLARSSL_DECRYPT:"3849674c2602319e3849674c2602319e":"a25e7856cf2651eb":"51454b582ddf440a":0 + +BLOWFISH ECB Decrypt test vector (SSLeay) #3, 64-bit key +depends_on:POLARSSL_BLOWFISH_C +test_vec_ecb:POLARSSL_CIPHER_BLOWFISH_ECB:POLARSSL_DECRYPT:"3849674c2602319e":"a25e7856cf2651eb":"51454b582ddf440a":0 + +BLOWFISH ECB Decrypt test vector (SSLeay) #3, 192-bit key +depends_on:POLARSSL_BLOWFISH_C +test_vec_ecb:POLARSSL_CIPHER_BLOWFISH_ECB:POLARSSL_DECRYPT:"3849674c2602319e3849674c2602319e3849674c2602319e":"a25e7856cf2651eb":"51454b582ddf440a":0 +