Add dedicated getter for the IV size to the crypter_t interface
This commit is contained in:
@@ -81,8 +81,8 @@ struct crypter_t {
|
|||||||
/**
|
/**
|
||||||
* Encrypt a chunk of data and allocate space for the encrypted value.
|
* 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
|
* The length of the iv must equal to get_iv_size(), while the length
|
||||||
* of data must be a multiple it.
|
* of data must be a multiple of get_block_size().
|
||||||
* If encrypted is NULL, the encryption is done in-place (overwriting data).
|
* If encrypted is NULL, the encryption is done in-place (overwriting data).
|
||||||
*
|
*
|
||||||
* @param data data to encrypt
|
* @param data data to encrypt
|
||||||
@@ -95,8 +95,8 @@ struct crypter_t {
|
|||||||
/**
|
/**
|
||||||
* Decrypt a chunk of data and allocate space for the decrypted value.
|
* 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
|
* The length of the iv must equal to get_iv_size(), while the length
|
||||||
* of data must be a multiple it.
|
* of data must be a multiple of get_block_size().
|
||||||
* If decrpyted is NULL, the encryption is done in-place (overwriting data).
|
* If decrpyted is NULL, the encryption is done in-place (overwriting data).
|
||||||
*
|
*
|
||||||
* @param data data to decrypt
|
* @param data data to decrypt
|
||||||
@@ -109,14 +109,21 @@ struct crypter_t {
|
|||||||
/**
|
/**
|
||||||
* Get the block size of the crypto algorithm.
|
* 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);
|
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.
|
* 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);
|
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().
|
* 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);
|
void (*set_key) (crypter_t *this, chunk_t key);
|
||||||
|
|
||||||
|
|||||||
@@ -1416,6 +1416,12 @@ METHOD(crypter_t, get_block_size, size_t,
|
|||||||
return AES_BLOCK_SIZE;
|
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,
|
METHOD(crypter_t, get_key_size, size_t,
|
||||||
private_aes_crypter_t *this)
|
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,
|
.encrypt = _encrypt,
|
||||||
.decrypt = _decrypt,
|
.decrypt = _decrypt,
|
||||||
.get_block_size = _get_block_size,
|
.get_block_size = _get_block_size,
|
||||||
|
.get_iv_size = _get_iv_size,
|
||||||
.get_key_size = _get_key_size,
|
.get_key_size = _get_key_size,
|
||||||
.set_key = _set_key,
|
.set_key = _set_key,
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
|
|||||||
@@ -139,6 +139,12 @@ METHOD(crypter_t, get_block_size, size_t,
|
|||||||
return BLOWFISH_BLOCK_SIZE;
|
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,
|
METHOD(crypter_t, get_key_size, size_t,
|
||||||
private_blowfish_crypter_t *this)
|
private_blowfish_crypter_t *this)
|
||||||
{
|
{
|
||||||
@@ -174,6 +180,7 @@ blowfish_crypter_t *blowfish_crypter_create(encryption_algorithm_t algo, size_t
|
|||||||
.encrypt = _encrypt,
|
.encrypt = _encrypt,
|
||||||
.decrypt = _decrypt,
|
.decrypt = _decrypt,
|
||||||
.get_block_size = _get_block_size,
|
.get_block_size = _get_block_size,
|
||||||
|
.get_iv_size = _get_iv_size,
|
||||||
.get_key_size = _get_key_size,
|
.get_key_size = _get_key_size,
|
||||||
.set_key = _set_key,
|
.set_key = _set_key,
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
|
|||||||
@@ -1523,6 +1523,12 @@ METHOD(crypter_t, get_block_size, size_t,
|
|||||||
return sizeof(des_cblock);
|
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,
|
METHOD(crypter_t, get_key_size, size_t,
|
||||||
private_des_crypter_t *this)
|
private_des_crypter_t *this)
|
||||||
{
|
{
|
||||||
@@ -1559,6 +1565,7 @@ des_crypter_t *des_crypter_create(encryption_algorithm_t algo)
|
|||||||
INIT(this,
|
INIT(this,
|
||||||
.public.crypter = {
|
.public.crypter = {
|
||||||
.get_block_size = _get_block_size,
|
.get_block_size = _get_block_size,
|
||||||
|
.get_iv_size = _get_iv_size,
|
||||||
.get_key_size = _get_key_size,
|
.get_key_size = _get_key_size,
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -83,6 +83,15 @@ METHOD(crypter_t, get_block_size, size_t,
|
|||||||
return len;
|
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,
|
METHOD(crypter_t, get_key_size, size_t,
|
||||||
private_gcrypt_crypter_t *this)
|
private_gcrypt_crypter_t *this)
|
||||||
{
|
{
|
||||||
@@ -219,6 +228,7 @@ gcrypt_crypter_t *gcrypt_crypter_create(encryption_algorithm_t algo,
|
|||||||
.encrypt = _encrypt,
|
.encrypt = _encrypt,
|
||||||
.decrypt = _decrypt,
|
.decrypt = _decrypt,
|
||||||
.get_block_size = _get_block_size,
|
.get_block_size = _get_block_size,
|
||||||
|
.get_iv_size = _get_iv_size,
|
||||||
.get_key_size = _get_key_size,
|
.get_key_size = _get_key_size,
|
||||||
.set_key = _set_key,
|
.set_key = _set_key,
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
|
|||||||
@@ -162,6 +162,12 @@ METHOD(crypter_t, get_block_size, size_t,
|
|||||||
return this->cipher->block_size;
|
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,
|
METHOD(crypter_t, get_key_size, size_t,
|
||||||
private_openssl_crypter_t *this)
|
private_openssl_crypter_t *this)
|
||||||
{
|
{
|
||||||
@@ -194,6 +200,7 @@ openssl_crypter_t *openssl_crypter_create(encryption_algorithm_t algo,
|
|||||||
.encrypt = _encrypt,
|
.encrypt = _encrypt,
|
||||||
.decrypt = _decrypt,
|
.decrypt = _decrypt,
|
||||||
.get_block_size = _get_block_size,
|
.get_block_size = _get_block_size,
|
||||||
|
.get_iv_size = _get_iv_size,
|
||||||
.get_key_size = _get_key_size,
|
.get_key_size = _get_key_size,
|
||||||
.set_key = _set_key,
|
.set_key = _set_key,
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
|
|||||||
@@ -125,6 +125,12 @@ METHOD(crypter_t, get_block_size, size_t,
|
|||||||
return AES_BLOCK_SIZE;
|
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,
|
METHOD(crypter_t, get_key_size, size_t,
|
||||||
private_padlock_aes_crypter_t *this)
|
private_padlock_aes_crypter_t *this)
|
||||||
{
|
{
|
||||||
@@ -172,6 +178,7 @@ padlock_aes_crypter_t *padlock_aes_crypter_create(encryption_algorithm_t algo,
|
|||||||
.encrypt = _encrypt,
|
.encrypt = _encrypt,
|
||||||
.decrypt = _decrypt,
|
.decrypt = _decrypt,
|
||||||
.get_block_size = _get_block_size,
|
.get_block_size = _get_block_size,
|
||||||
|
.get_iv_size = _get_iv_size,
|
||||||
.get_key_size = _get_key_size,
|
.get_key_size = _get_key_size,
|
||||||
.set_key = _set_key,
|
.set_key = _set_key,
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
|
|||||||
Reference in New Issue
Block a user