Add support to RC2/RC4 encrypt/decrypt. Update documentation. 99/69099/6
authorDariusz Michaluk <d.michaluk@samsung.com>
Wed, 11 May 2016 09:04:43 +0000 (11:04 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Mon, 16 May 2016 08:32:32 +0000 (10:32 +0200)
Change-Id: I57a54e9581af12ffe73a721c7cae8c3880df94ab

api/yaca/types.h
src/encrypt.c

index 3397e86..7ce9ec9 100644 (file)
@@ -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;
 
 /**
index d185c16..ec2176f 100644 (file)
@@ -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: