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

crypto: inside-secure - add support for authenc(hmac(sha1),cbc(des3_ede))

Signed-off-by: default avatarPascal van Leeuwen <pvanleeuwen@verimatrix.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 5c9254ad
...@@ -875,6 +875,7 @@ static struct safexcel_alg_template *safexcel_algs[] = { ...@@ -875,6 +875,7 @@ static struct safexcel_alg_template *safexcel_algs[] = {
&safexcel_alg_authenc_hmac_sha256_cbc_aes, &safexcel_alg_authenc_hmac_sha256_cbc_aes,
&safexcel_alg_authenc_hmac_sha384_cbc_aes, &safexcel_alg_authenc_hmac_sha384_cbc_aes,
&safexcel_alg_authenc_hmac_sha512_cbc_aes, &safexcel_alg_authenc_hmac_sha512_cbc_aes,
&safexcel_alg_authenc_hmac_sha1_cbc_des3_ede,
}; };
static int safexcel_register_algorithms(struct safexcel_crypto_priv *priv) static int safexcel_register_algorithms(struct safexcel_crypto_priv *priv)
......
...@@ -735,5 +735,6 @@ extern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_cbc_aes; ...@@ -735,5 +735,6 @@ extern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_cbc_aes;
extern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_cbc_aes; extern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_cbc_aes;
extern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_cbc_aes; extern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_cbc_aes;
extern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_cbc_aes; extern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_cbc_aes;
extern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_cbc_des3_ede;
#endif #endif
...@@ -183,14 +183,16 @@ static int safexcel_skcipher_aes_setkey(struct crypto_skcipher *ctfm, ...@@ -183,14 +183,16 @@ static int safexcel_skcipher_aes_setkey(struct crypto_skcipher *ctfm,
return 0; return 0;
} }
static int safexcel_aead_aes_setkey(struct crypto_aead *ctfm, const u8 *key, static int safexcel_aead_setkey(struct crypto_aead *ctfm, const u8 *key,
unsigned int len) unsigned int len)
{ {
struct crypto_tfm *tfm = crypto_aead_tfm(ctfm); struct crypto_tfm *tfm = crypto_aead_tfm(ctfm);
struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm); struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
struct safexcel_ahash_export_state istate, ostate; struct safexcel_ahash_export_state istate, ostate;
struct safexcel_crypto_priv *priv = ctx->priv; struct safexcel_crypto_priv *priv = ctx->priv;
struct crypto_authenc_keys keys; struct crypto_authenc_keys keys;
u32 flags;
int err;
if (crypto_authenc_extractkeys(&keys, key, len) != 0) if (crypto_authenc_extractkeys(&keys, key, len) != 0)
goto badkey; goto badkey;
...@@ -199,6 +201,15 @@ static int safexcel_aead_aes_setkey(struct crypto_aead *ctfm, const u8 *key, ...@@ -199,6 +201,15 @@ static int safexcel_aead_aes_setkey(struct crypto_aead *ctfm, const u8 *key,
goto badkey; goto badkey;
/* Encryption key */ /* Encryption key */
if (ctx->alg == SAFEXCEL_3DES) {
flags = crypto_aead_get_flags(ctfm);
err = __des3_verify_key(&flags, keys.enckey);
crypto_aead_set_flags(ctfm, flags);
if (unlikely(err))
return err;
}
if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma && if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma &&
memcmp(ctx->key, keys.enckey, keys.enckeylen)) memcmp(ctx->key, keys.enckey, keys.enckeylen))
ctx->base.needs_inv = true; ctx->base.needs_inv = true;
...@@ -1246,7 +1257,7 @@ struct safexcel_alg_template safexcel_alg_ecb_des3_ede = { ...@@ -1246,7 +1257,7 @@ struct safexcel_alg_template safexcel_alg_ecb_des3_ede = {
}, },
}; };
static int safexcel_aead_encrypt(struct aead_request *req) static int safexcel_aead_encrypt_aes(struct aead_request *req)
{ {
struct safexcel_cipher_req *creq = aead_request_ctx(req); struct safexcel_cipher_req *creq = aead_request_ctx(req);
...@@ -1254,7 +1265,7 @@ static int safexcel_aead_encrypt(struct aead_request *req) ...@@ -1254,7 +1265,7 @@ static int safexcel_aead_encrypt(struct aead_request *req)
CONTEXT_CONTROL_CRYPTO_MODE_CBC, SAFEXCEL_AES); CONTEXT_CONTROL_CRYPTO_MODE_CBC, SAFEXCEL_AES);
} }
static int safexcel_aead_decrypt(struct aead_request *req) static int safexcel_aead_decrypt_aes(struct aead_request *req)
{ {
struct safexcel_cipher_req *creq = aead_request_ctx(req); struct safexcel_cipher_req *creq = aead_request_ctx(req);
...@@ -1294,9 +1305,9 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_cbc_aes = { ...@@ -1294,9 +1305,9 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_cbc_aes = {
.type = SAFEXCEL_ALG_TYPE_AEAD, .type = SAFEXCEL_ALG_TYPE_AEAD,
.engines = EIP97IES | EIP197B | EIP197D, .engines = EIP97IES | EIP197B | EIP197D,
.alg.aead = { .alg.aead = {
.setkey = safexcel_aead_aes_setkey, .setkey = safexcel_aead_setkey,
.encrypt = safexcel_aead_encrypt, .encrypt = safexcel_aead_encrypt_aes,
.decrypt = safexcel_aead_decrypt, .decrypt = safexcel_aead_decrypt_aes,
.ivsize = AES_BLOCK_SIZE, .ivsize = AES_BLOCK_SIZE,
.maxauthsize = SHA1_DIGEST_SIZE, .maxauthsize = SHA1_DIGEST_SIZE,
.base = { .base = {
...@@ -1329,9 +1340,9 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_cbc_aes = { ...@@ -1329,9 +1340,9 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_cbc_aes = {
.type = SAFEXCEL_ALG_TYPE_AEAD, .type = SAFEXCEL_ALG_TYPE_AEAD,
.engines = EIP97IES | EIP197B | EIP197D, .engines = EIP97IES | EIP197B | EIP197D,
.alg.aead = { .alg.aead = {
.setkey = safexcel_aead_aes_setkey, .setkey = safexcel_aead_setkey,
.encrypt = safexcel_aead_encrypt, .encrypt = safexcel_aead_encrypt_aes,
.decrypt = safexcel_aead_decrypt, .decrypt = safexcel_aead_decrypt_aes,
.ivsize = AES_BLOCK_SIZE, .ivsize = AES_BLOCK_SIZE,
.maxauthsize = SHA256_DIGEST_SIZE, .maxauthsize = SHA256_DIGEST_SIZE,
.base = { .base = {
...@@ -1364,9 +1375,9 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_cbc_aes = { ...@@ -1364,9 +1375,9 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_cbc_aes = {
.type = SAFEXCEL_ALG_TYPE_AEAD, .type = SAFEXCEL_ALG_TYPE_AEAD,
.engines = EIP97IES | EIP197B | EIP197D, .engines = EIP97IES | EIP197B | EIP197D,
.alg.aead = { .alg.aead = {
.setkey = safexcel_aead_aes_setkey, .setkey = safexcel_aead_setkey,
.encrypt = safexcel_aead_encrypt, .encrypt = safexcel_aead_encrypt_aes,
.decrypt = safexcel_aead_decrypt, .decrypt = safexcel_aead_decrypt_aes,
.ivsize = AES_BLOCK_SIZE, .ivsize = AES_BLOCK_SIZE,
.maxauthsize = SHA224_DIGEST_SIZE, .maxauthsize = SHA224_DIGEST_SIZE,
.base = { .base = {
...@@ -1399,9 +1410,9 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_cbc_aes = { ...@@ -1399,9 +1410,9 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_cbc_aes = {
.type = SAFEXCEL_ALG_TYPE_AEAD, .type = SAFEXCEL_ALG_TYPE_AEAD,
.engines = EIP97IES | EIP197B | EIP197D, .engines = EIP97IES | EIP197B | EIP197D,
.alg.aead = { .alg.aead = {
.setkey = safexcel_aead_aes_setkey, .setkey = safexcel_aead_setkey,
.encrypt = safexcel_aead_encrypt, .encrypt = safexcel_aead_encrypt_aes,
.decrypt = safexcel_aead_decrypt, .decrypt = safexcel_aead_decrypt_aes,
.ivsize = AES_BLOCK_SIZE, .ivsize = AES_BLOCK_SIZE,
.maxauthsize = SHA512_DIGEST_SIZE, .maxauthsize = SHA512_DIGEST_SIZE,
.base = { .base = {
...@@ -1434,9 +1445,9 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_cbc_aes = { ...@@ -1434,9 +1445,9 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_cbc_aes = {
.type = SAFEXCEL_ALG_TYPE_AEAD, .type = SAFEXCEL_ALG_TYPE_AEAD,
.engines = EIP97IES | EIP197B | EIP197D, .engines = EIP97IES | EIP197B | EIP197D,
.alg.aead = { .alg.aead = {
.setkey = safexcel_aead_aes_setkey, .setkey = safexcel_aead_setkey,
.encrypt = safexcel_aead_encrypt, .encrypt = safexcel_aead_encrypt_aes,
.decrypt = safexcel_aead_decrypt, .decrypt = safexcel_aead_decrypt_aes,
.ivsize = AES_BLOCK_SIZE, .ivsize = AES_BLOCK_SIZE,
.maxauthsize = SHA384_DIGEST_SIZE, .maxauthsize = SHA384_DIGEST_SIZE,
.base = { .base = {
...@@ -1454,3 +1465,43 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_cbc_aes = { ...@@ -1454,3 +1465,43 @@ struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_cbc_aes = {
}, },
}, },
}; };
static int safexcel_aead_encrypt_3des(struct aead_request *req)
{
struct safexcel_cipher_req *creq = aead_request_ctx(req);
return safexcel_queue_req(&req->base, creq, SAFEXCEL_ENCRYPT,
CONTEXT_CONTROL_CRYPTO_MODE_CBC, SAFEXCEL_3DES);
}
static int safexcel_aead_decrypt_3des(struct aead_request *req)
{
struct safexcel_cipher_req *creq = aead_request_ctx(req);
return safexcel_queue_req(&req->base, creq, SAFEXCEL_DECRYPT,
CONTEXT_CONTROL_CRYPTO_MODE_CBC, SAFEXCEL_3DES);
}
struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_cbc_des3_ede = {
.type = SAFEXCEL_ALG_TYPE_AEAD,
.alg.aead = {
.setkey = safexcel_aead_setkey,
.encrypt = safexcel_aead_encrypt_3des,
.decrypt = safexcel_aead_decrypt_3des,
.ivsize = DES3_EDE_BLOCK_SIZE,
.maxauthsize = SHA1_DIGEST_SIZE,
.base = {
.cra_name = "authenc(hmac(sha1),cbc(des3_ede))",
.cra_driver_name = "safexcel-authenc-hmac-sha1-cbc-des3_ede",
.cra_priority = 300,
.cra_flags = CRYPTO_ALG_ASYNC |
CRYPTO_ALG_KERN_DRIVER_ONLY,
.cra_blocksize = DES3_EDE_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct safexcel_cipher_ctx),
.cra_alignmask = 0,
.cra_init = safexcel_aead_sha1_cra_init,
.cra_exit = safexcel_aead_cra_exit,
.cra_module = THIS_MODULE,
},
},
};
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