From 0cb7bca2390db4d2d1e3c0be1d15c2842ed276be Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Wed, 11 May 2016 11:04:43 +0200 Subject: [PATCH] Add support to RC2/RC4 encrypt/decrypt. Update documentation. Change-Id: I57a54e9581af12ffe73a721c7cae8c3880df94ab --- api/yaca/types.h | 35 +++++++++++++++++++++++++---------- src/encrypt.c | 9 +++++---- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/api/yaca/types.h b/api/yaca/types.h index 3397e86..7ce9ec9 100644 --- a/api/yaca/types.h +++ b/api/yaca/types.h @@ -100,6 +100,7 @@ typedef enum { YACA_KEY_CURVE_P192 = 192, /**< ECC: P192 curve */ YACA_KEY_CURVE_P256 = 256, /**< ECC: P-256 curve */ YACA_KEY_CURVE_P384 = 384, /**< ECC: SECP-384 curve */ + YACA_KEY_UNSAFE_8BIT = 8, YACA_KEY_UNSAFE_40BIT = 40, YACA_KEY_UNSAFE_64BIT = 64, YACA_KEY_UNSAFE_80BIT = 80, @@ -178,15 +179,23 @@ typedef enum { /** * RC2 encryption. - * - The key length is extracted from the key buffer. + * This is a variable key length cipher. * - Supported key lengths: 8-1024 bits in steps of 8 bits. + * - Additional parameter, effective key bits: #YACA_PARAM_RC2_EFFECTIVE_KEY_BITS, + * by default equals to 128 + * - Supported block cipher modes: + * #YACA_BCM_CBC, + * #YACA_BCM_OFB, + * #YACA_BCM_CFB, + * #YACA_BCM_ECB */ YACA_ENC_UNSAFE_RC2, /** * RC4 encryption. - * - The key length is extracted from the key buffer. + * This is a variable key length cipher. * - Supported key lengths: 40–2048 bits in steps of 8 bits. + * This cipher doesn't support block cipher modes, use #YACA_BCM_NONE instead. */ YACA_ENC_UNSAFE_RC4, @@ -215,6 +224,11 @@ typedef enum { */ typedef enum { /** + * Used when algorithm doesn't support block ciphers modes. + */ + YACA_BCM_NONE, + + /** * ECB block cipher mode. * Encrypts 64 bit at a time. No IV is used. */ @@ -277,17 +291,18 @@ typedef enum { * @brief Non-standard parameters for algorithms */ typedef enum { - YACA_PARAM_PADDING, /**< Padding */ + YACA_PARAM_PADDING, /**< Padding */ - YACA_PARAM_CTR_CNT, /**< CTR Counter bits */ + YACA_PARAM_RC2_EFFECTIVE_KEY_BITS, /**< RC2 effective key bits, 1-1024, 1 bit resolution */ + YACA_PARAM_CTR_CNT, /**< CTR Counter bits */ - YACA_PARAM_GCM_AAD, /**< GCM Additional Authentication Data */ - YACA_PARAM_GCM_TAG, /**< GCM Tag bits */ - YACA_PARAM_GCM_TAG_LEN, /**< GCM Tag length */ + YACA_PARAM_GCM_AAD, /**< GCM Additional Authentication Data */ + YACA_PARAM_GCM_TAG, /**< GCM Tag bits */ + YACA_PARAM_GCM_TAG_LEN, /**< GCM Tag length */ - YACA_PARAM_CCM_AAD, /**< CCM Additional Authentication Data */ - YACA_PARAM_CCM_TAG, /**< CCM Tag bits */ - YACA_PARAM_CCM_TAG_LEN, /**< CCM Tag length */ + YACA_PARAM_CCM_AAD, /**< CCM Additional Authentication Data */ + YACA_PARAM_CCM_TAG, /**< CCM Tag bits */ + YACA_PARAM_CCM_TAG_LEN, /**< CCM Tag length */ } yaca_ex_param_e; /** diff --git a/src/encrypt.c b/src/encrypt.c index d185c16..ec2176f 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -115,6 +115,8 @@ static const char *encrypt_algo_to_str(yaca_enc_algo_e algo) static const char *bcm_to_str(yaca_block_cipher_mode_e bcm) { switch (bcm) { + case YACA_BCM_NONE: + return "none"; case YACA_BCM_ECB: return "ecb"; case YACA_BCM_CBC: @@ -158,6 +160,8 @@ int encrypt_get_algorithm(yaca_enc_algo_e algo, algo_name, key_bits, bcm_name); break; case YACA_ENC_UNSAFE_DES: + case YACA_ENC_UNSAFE_RC2: + case YACA_ENC_CAST5: ret = snprintf(cipher_name, sizeof(cipher_name), "%s-%s", algo_name, bcm_name); break; @@ -169,11 +173,8 @@ int encrypt_get_algorithm(yaca_enc_algo_e algo, ret = snprintf(cipher_name, sizeof(cipher_name), "%s-%s", algo_name, bcm_name); break; - case YACA_ENC_UNSAFE_RC2: case YACA_ENC_UNSAFE_RC4: - case YACA_ENC_CAST5: - ret = snprintf(cipher_name, sizeof(cipher_name), "%s-%s", - algo_name, bcm_name); + ret = snprintf(cipher_name, sizeof(cipher_name), "%s", algo_name); break; case YACA_ENC_UNSAFE_SKIPJACK: default: -- 2.7.4