Commit f26882a3 authored by Pascal van Leeuwen's avatar Pascal van Leeuwen Committed by Herbert Xu

crypto: inside-secure - Use defines instead of some constants (cosmetic)

This patch replaces some hard constants regarding key, IV and nonce sizes
with appropriate defines from the crypto header files.
Signed-off-by: default avatarPascal van Leeuwen <pvanleeuwen@verimatrix.com>
Acked-by: default avatarAntoine Tenart <antoine.tenart@bootlin.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 48f89d2a
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <crypto/aead.h> #include <crypto/aead.h>
#include <crypto/aes.h> #include <crypto/aes.h>
#include <crypto/authenc.h> #include <crypto/authenc.h>
#include <crypto/ctr.h>
#include <crypto/des.h> #include <crypto/des.h>
#include <crypto/sha.h> #include <crypto/sha.h>
#include <crypto/skcipher.h> #include <crypto/skcipher.h>
...@@ -226,19 +227,21 @@ static int safexcel_aead_setkey(struct crypto_aead *ctfm, const u8 *key, ...@@ -226,19 +227,21 @@ static int safexcel_aead_setkey(struct crypto_aead *ctfm, const u8 *key,
goto badkey; goto badkey;
if (ctx->mode == CONTEXT_CONTROL_CRYPTO_MODE_CTR_LOAD) { if (ctx->mode == CONTEXT_CONTROL_CRYPTO_MODE_CTR_LOAD) {
/* 20 is minimum AES key: 16 bytes + 4 bytes nonce */ /* Minimum keysize is minimum AES key size + nonce size */
if (keys.enckeylen < 20) if (keys.enckeylen < (AES_MIN_KEY_SIZE +
CTR_RFC3686_NONCE_SIZE))
goto badkey; goto badkey;
/* last 4 bytes of key are the nonce! */ /* last 4 bytes of key are the nonce! */
ctx->nonce = *(u32 *)(keys.enckey + keys.enckeylen - 4); ctx->nonce = *(u32 *)(keys.enckey + keys.enckeylen -
CTR_RFC3686_NONCE_SIZE);
/* exclude the nonce here */ /* exclude the nonce here */
keys.enckeylen -= 4; keys.enckeylen -= CONTEXT_CONTROL_CRYPTO_MODE_CTR_LOAD;
} }
/* Encryption key */ /* Encryption key */
switch (ctx->alg) { switch (ctx->alg) {
case SAFEXCEL_3DES: case SAFEXCEL_3DES:
if (keys.enckeylen != 24) if (keys.enckeylen != DES3_EDE_KEY_SIZE)
goto badkey; goto badkey;
flags = crypto_aead_get_flags(ctfm); flags = crypto_aead_get_flags(ctfm);
err = __des3_verify_key(&flags, keys.enckey); err = __des3_verify_key(&flags, keys.enckey);
...@@ -1119,9 +1122,9 @@ static int safexcel_skcipher_aesctr_setkey(struct crypto_skcipher *ctfm, ...@@ -1119,9 +1122,9 @@ static int safexcel_skcipher_aesctr_setkey(struct crypto_skcipher *ctfm,
unsigned int keylen; unsigned int keylen;
/* last 4 bytes of key are the nonce! */ /* last 4 bytes of key are the nonce! */
ctx->nonce = *(u32 *)(key + len - 4); ctx->nonce = *(u32 *)(key + len - CTR_RFC3686_NONCE_SIZE);
/* exclude the nonce here */ /* exclude the nonce here */
keylen = len - 4; keylen = len - CTR_RFC3686_NONCE_SIZE;
ret = aes_expandkey(&aes, key, keylen); ret = aes_expandkey(&aes, key, keylen);
if (ret) { if (ret) {
crypto_skcipher_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN); crypto_skcipher_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
...@@ -1152,10 +1155,10 @@ struct safexcel_alg_template safexcel_alg_ctr_aes = { ...@@ -1152,10 +1155,10 @@ struct safexcel_alg_template safexcel_alg_ctr_aes = {
.setkey = safexcel_skcipher_aesctr_setkey, .setkey = safexcel_skcipher_aesctr_setkey,
.encrypt = safexcel_ctr_aes_encrypt, .encrypt = safexcel_ctr_aes_encrypt,
.decrypt = safexcel_ctr_aes_decrypt, .decrypt = safexcel_ctr_aes_decrypt,
/* Add 4 to include the 4 byte nonce! */ /* Add nonce size */
.min_keysize = AES_MIN_KEY_SIZE + 4, .min_keysize = AES_MIN_KEY_SIZE + CTR_RFC3686_NONCE_SIZE,
.max_keysize = AES_MAX_KEY_SIZE + 4, .max_keysize = AES_MAX_KEY_SIZE + CTR_RFC3686_NONCE_SIZE,
.ivsize = 8, .ivsize = CTR_RFC3686_IV_SIZE,
.base = { .base = {
.cra_name = "rfc3686(ctr(aes))", .cra_name = "rfc3686(ctr(aes))",
.cra_driver_name = "safexcel-ctr-aes", .cra_driver_name = "safexcel-ctr-aes",
...@@ -1657,7 +1660,7 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_ctr_aes = { ...@@ -1657,7 +1660,7 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_ctr_aes = {
.setkey = safexcel_aead_setkey, .setkey = safexcel_aead_setkey,
.encrypt = safexcel_aead_encrypt_aes, .encrypt = safexcel_aead_encrypt_aes,
.decrypt = safexcel_aead_decrypt_aes, .decrypt = safexcel_aead_decrypt_aes,
.ivsize = 8, .ivsize = CTR_RFC3686_IV_SIZE,
.maxauthsize = SHA1_DIGEST_SIZE, .maxauthsize = SHA1_DIGEST_SIZE,
.base = { .base = {
.cra_name = "authenc(hmac(sha1),rfc3686(ctr(aes)))", .cra_name = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
...@@ -1690,7 +1693,7 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_ctr_aes = { ...@@ -1690,7 +1693,7 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_ctr_aes = {
.setkey = safexcel_aead_setkey, .setkey = safexcel_aead_setkey,
.encrypt = safexcel_aead_encrypt_aes, .encrypt = safexcel_aead_encrypt_aes,
.decrypt = safexcel_aead_decrypt_aes, .decrypt = safexcel_aead_decrypt_aes,
.ivsize = 8, .ivsize = CTR_RFC3686_IV_SIZE,
.maxauthsize = SHA256_DIGEST_SIZE, .maxauthsize = SHA256_DIGEST_SIZE,
.base = { .base = {
.cra_name = "authenc(hmac(sha256),rfc3686(ctr(aes)))", .cra_name = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
...@@ -1723,7 +1726,7 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_ctr_aes = { ...@@ -1723,7 +1726,7 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_ctr_aes = {
.setkey = safexcel_aead_setkey, .setkey = safexcel_aead_setkey,
.encrypt = safexcel_aead_encrypt_aes, .encrypt = safexcel_aead_encrypt_aes,
.decrypt = safexcel_aead_decrypt_aes, .decrypt = safexcel_aead_decrypt_aes,
.ivsize = 8, .ivsize = CTR_RFC3686_IV_SIZE,
.maxauthsize = SHA224_DIGEST_SIZE, .maxauthsize = SHA224_DIGEST_SIZE,
.base = { .base = {
.cra_name = "authenc(hmac(sha224),rfc3686(ctr(aes)))", .cra_name = "authenc(hmac(sha224),rfc3686(ctr(aes)))",
...@@ -1756,7 +1759,7 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_ctr_aes = { ...@@ -1756,7 +1759,7 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_ctr_aes = {
.setkey = safexcel_aead_setkey, .setkey = safexcel_aead_setkey,
.encrypt = safexcel_aead_encrypt_aes, .encrypt = safexcel_aead_encrypt_aes,
.decrypt = safexcel_aead_decrypt_aes, .decrypt = safexcel_aead_decrypt_aes,
.ivsize = 8, .ivsize = CTR_RFC3686_IV_SIZE,
.maxauthsize = SHA512_DIGEST_SIZE, .maxauthsize = SHA512_DIGEST_SIZE,
.base = { .base = {
.cra_name = "authenc(hmac(sha512),rfc3686(ctr(aes)))", .cra_name = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
...@@ -1789,7 +1792,7 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_ctr_aes = { ...@@ -1789,7 +1792,7 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_ctr_aes = {
.setkey = safexcel_aead_setkey, .setkey = safexcel_aead_setkey,
.encrypt = safexcel_aead_encrypt_aes, .encrypt = safexcel_aead_encrypt_aes,
.decrypt = safexcel_aead_decrypt_aes, .decrypt = safexcel_aead_decrypt_aes,
.ivsize = 8, .ivsize = CTR_RFC3686_IV_SIZE,
.maxauthsize = SHA384_DIGEST_SIZE, .maxauthsize = SHA384_DIGEST_SIZE,
.base = { .base = {
.cra_name = "authenc(hmac(sha384),rfc3686(ctr(aes)))", .cra_name = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment