Add dedicated getter for the IV size to the crypter_t interface
authorMartin Willi <martin@revosec.ch>
Fri, 13 Aug 2010 09:49:42 +0000 (11:49 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 13 Aug 2010 15:11:53 +0000 (17:11 +0200)
src/libstrongswan/crypto/crypters/crypter.h
src/libstrongswan/plugins/aes/aes_crypter.c
src/libstrongswan/plugins/blowfish/blowfish_crypter.c
src/libstrongswan/plugins/des/des_crypter.c
src/libstrongswan/plugins/gcrypt/gcrypt_crypter.c
src/libstrongswan/plugins/openssl/openssl_crypter.c
src/libstrongswan/plugins/padlock/padlock_aes_crypter.c

index f052a18..70697e2 100644 (file)
@@ -81,8 +81,8 @@ struct crypter_t {
        /**
         * Encrypt a chunk of data and allocate space for the encrypted value.
         *
-        * The length of the iv must equal to get_block_size(), while the length
-        * of data must be a multiple it.
+        * The length of the iv must equal to get_iv_size(), while the length
+        * of data must be a multiple of get_block_size().
         * If encrypted is NULL, the encryption is done in-place (overwriting data).
         *
         * @param data                  data to encrypt
@@ -95,8 +95,8 @@ struct crypter_t {
        /**
         * Decrypt a chunk of data and allocate space for the decrypted value.
         *
-        * The length of the iv must equal to get_block_size(), while the length
-        * of data must be a multiple it.
+        * The length of the iv must equal to get_iv_size(), while the length
+        * of data must be a multiple of get_block_size().
         * If decrpyted is NULL, the encryption is done in-place (overwriting data).
         *
         * @param data                  data to decrypt
@@ -109,14 +109,21 @@ struct crypter_t {
        /**
         * Get the block size of the crypto algorithm.
         *
-        * @return                                      block size in bytes
+        * @return                              block size in bytes
         */
        size_t (*get_block_size) (crypter_t *this);
 
        /**
+        * Get the IV size of the crypto algorithm.
+        *
+        * @return                              initialization vector size in bytes
+        */
+       size_t (*get_iv_size)(crypter_t *this);
+
+       /**
         * Get the key size of the crypto algorithm.
         *
-        * @return                                      key size in bytes
+        * @return                              key size in bytes
         */
        size_t (*get_key_size) (crypter_t *this);
 
@@ -125,7 +132,7 @@ struct crypter_t {
         *
         * The length of the key must match get_key_size().
         *
-        * @param key                           key to set
+        * @param key                   key to set
         */
        void (*set_key) (crypter_t *this, chunk_t key);
 
index 9dcf61c..ee6b532 100644 (file)
@@ -1416,6 +1416,12 @@ METHOD(crypter_t, get_block_size, size_t,
        return AES_BLOCK_SIZE;
 }
 
+METHOD(crypter_t, get_iv_size, size_t,
+       private_aes_crypter_t *this)
+{
+       return AES_BLOCK_SIZE;
+}
+
 METHOD(crypter_t, get_key_size, size_t,
        private_aes_crypter_t *this)
 {
@@ -1545,6 +1551,7 @@ aes_crypter_t *aes_crypter_create(encryption_algorithm_t algo, size_t key_size)
                        .encrypt = _encrypt,
                        .decrypt = _decrypt,
                        .get_block_size = _get_block_size,
+                       .get_iv_size = _get_iv_size,
                        .get_key_size = _get_key_size,
                        .set_key = _set_key,
                        .destroy = _destroy,
index b23a7ba..e37420a 100644 (file)
@@ -139,6 +139,12 @@ METHOD(crypter_t, get_block_size, size_t,
        return BLOWFISH_BLOCK_SIZE;
 }
 
+METHOD(crypter_t, get_iv_size, size_t,
+       private_blowfish_crypter_t *this)
+{
+       return BLOWFISH_BLOCK_SIZE;
+}
+
 METHOD(crypter_t, get_key_size, size_t,
        private_blowfish_crypter_t *this)
 {
@@ -174,6 +180,7 @@ blowfish_crypter_t *blowfish_crypter_create(encryption_algorithm_t algo, size_t
                        .encrypt = _encrypt,
                        .decrypt = _decrypt,
                        .get_block_size = _get_block_size,
+                       .get_iv_size = _get_iv_size,
                        .get_key_size = _get_key_size,
                        .set_key = _set_key,
                        .destroy = _destroy,
index 1b084ac..eae01df 100644 (file)
@@ -1523,6 +1523,12 @@ METHOD(crypter_t, get_block_size, size_t,
        return sizeof(des_cblock);
 }
 
+METHOD(crypter_t, get_iv_size, size_t,
+       private_des_crypter_t *this)
+{
+       return sizeof(des_cblock);
+}
+
 METHOD(crypter_t, get_key_size, size_t,
        private_des_crypter_t *this)
 {
@@ -1559,6 +1565,7 @@ des_crypter_t *des_crypter_create(encryption_algorithm_t algo)
        INIT(this,
                .public.crypter = {
                        .get_block_size = _get_block_size,
+                       .get_iv_size = _get_iv_size,
                        .get_key_size = _get_key_size,
                        .destroy = _destroy,
                },
index 3db5e57..db8bfea 100644 (file)
@@ -83,6 +83,15 @@ METHOD(crypter_t, get_block_size, size_t,
        return len;
 }
 
+METHOD(crypter_t, get_iv_size, size_t,
+       private_gcrypt_crypter_t *this)
+{
+       size_t len = 0;
+
+       gcry_cipher_algo_info(this->alg, GCRYCTL_GET_BLKLEN, NULL, &len);
+       return len;
+}
+
 METHOD(crypter_t, get_key_size, size_t,
        private_gcrypt_crypter_t *this)
 {
@@ -219,6 +228,7 @@ gcrypt_crypter_t *gcrypt_crypter_create(encryption_algorithm_t algo,
                        .encrypt = _encrypt,
                        .decrypt = _decrypt,
                        .get_block_size = _get_block_size,
+                       .get_iv_size = _get_iv_size,
                        .get_key_size = _get_key_size,
                        .set_key = _set_key,
                        .destroy = _destroy,
index 520b232..a410eee 100644 (file)
@@ -162,6 +162,12 @@ METHOD(crypter_t, get_block_size, size_t,
        return this->cipher->block_size;
 }
 
+METHOD(crypter_t, get_iv_size, size_t,
+       private_openssl_crypter_t *this)
+{
+       return this->cipher->block_size;
+}
+
 METHOD(crypter_t, get_key_size, size_t,
        private_openssl_crypter_t *this)
 {
@@ -194,6 +200,7 @@ openssl_crypter_t *openssl_crypter_create(encryption_algorithm_t algo,
                        .encrypt = _encrypt,
                        .decrypt = _decrypt,
                        .get_block_size = _get_block_size,
+                       .get_iv_size = _get_iv_size,
                        .get_key_size = _get_key_size,
                        .set_key = _set_key,
                        .destroy = _destroy,
index f7a521e..11d8ba0 100644 (file)
@@ -125,6 +125,12 @@ METHOD(crypter_t, get_block_size, size_t,
        return AES_BLOCK_SIZE;
 }
 
+METHOD(crypter_t, get_iv_size, size_t,
+       private_padlock_aes_crypter_t *this)
+{
+       return AES_BLOCK_SIZE;
+}
+
 METHOD(crypter_t, get_key_size, size_t,
        private_padlock_aes_crypter_t *this)
 {
@@ -172,6 +178,7 @@ padlock_aes_crypter_t *padlock_aes_crypter_create(encryption_algorithm_t algo,
                        .encrypt = _encrypt,
                        .decrypt = _decrypt,
                        .get_block_size = _get_block_size,
+                       .get_iv_size = _get_iv_size,
                        .get_key_size = _get_key_size,
                        .set_key = _set_key,
                        .destroy = _destroy,