Skip to content

Commit c99d4a2

Browse files
horiagherbertx
authored andcommitted
crypto: caam/qi2 - add support for ChaCha20
Add support for ChaCha20 skcipher algorithm. Signed-off-by: Carmen Iorga <carmen.iorga@nxp.com> Signed-off-by: Horia Geantă <horia.geanta@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent d239b10 commit c99d4a2

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

drivers/crypto/caam/caamalg_desc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,8 @@ static inline void skcipher_append_src_dst(u32 *desc)
12281228
* @desc: pointer to buffer used for descriptor construction
12291229
* @cdata: pointer to block cipher transform definitions
12301230
* Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed
1231-
* with OP_ALG_AAI_CBC or OP_ALG_AAI_CTR_MOD128.
1231+
* with OP_ALG_AAI_CBC or OP_ALG_AAI_CTR_MOD128
1232+
* - OP_ALG_ALGSEL_CHACHA20
12321233
* @ivsize: initialization vector size
12331234
* @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template
12341235
* @ctx1_iv_off: IV offset in CONTEXT1 register
@@ -1293,7 +1294,8 @@ EXPORT_SYMBOL(cnstr_shdsc_skcipher_encap);
12931294
* @desc: pointer to buffer used for descriptor construction
12941295
* @cdata: pointer to block cipher transform definitions
12951296
* Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed
1296-
* with OP_ALG_AAI_CBC or OP_ALG_AAI_CTR_MOD128.
1297+
* with OP_ALG_AAI_CBC or OP_ALG_AAI_CTR_MOD128
1298+
* - OP_ALG_ALGSEL_CHACHA20
12971299
* @ivsize: initialization vector size
12981300
* @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template
12991301
* @ctx1_iv_off: IV offset in CONTEXT1 register

drivers/crypto/caam/caamalg_qi2.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,9 @@ static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
816816
u32 *desc;
817817
u32 ctx1_iv_off = 0;
818818
const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
819-
OP_ALG_AAI_CTR_MOD128);
819+
OP_ALG_AAI_CTR_MOD128) &&
820+
((ctx->cdata.algtype & OP_ALG_ALGSEL_MASK) !=
821+
OP_ALG_ALGSEL_CHACHA20);
820822
const bool is_rfc3686 = alg->caam.rfc3686;
821823

822824
print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
@@ -1494,7 +1496,23 @@ static struct caam_skcipher_alg driver_algs[] = {
14941496
.ivsize = AES_BLOCK_SIZE,
14951497
},
14961498
.caam.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_XTS,
1497-
}
1499+
},
1500+
{
1501+
.skcipher = {
1502+
.base = {
1503+
.cra_name = "chacha20",
1504+
.cra_driver_name = "chacha20-caam-qi2",
1505+
.cra_blocksize = 1,
1506+
},
1507+
.setkey = skcipher_setkey,
1508+
.encrypt = skcipher_encrypt,
1509+
.decrypt = skcipher_decrypt,
1510+
.min_keysize = CHACHA20_KEY_SIZE,
1511+
.max_keysize = CHACHA20_KEY_SIZE,
1512+
.ivsize = CHACHA20_IV_SIZE,
1513+
},
1514+
.caam.class1_alg_type = OP_ALG_ALGSEL_CHACHA20,
1515+
},
14981516
};
14991517

15001518
static struct caam_aead_alg driver_aeads[] = {
@@ -4908,6 +4926,11 @@ static int dpaa2_caam_probe(struct fsl_mc_device *dpseci_dev)
49084926
alg_sel == OP_ALG_ALGSEL_AES)
49094927
continue;
49104928

4929+
/* Skip CHACHA20 algorithms if not supported by device */
4930+
if (alg_sel == OP_ALG_ALGSEL_CHACHA20 &&
4931+
!priv->sec_attr.ccha_acc_num)
4932+
continue;
4933+
49114934
t_alg->caam.dev = dev;
49124935
caam_skcipher_alg_init(t_alg);
49134936

drivers/crypto/caam/compat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <crypto/gcm.h>
3737
#include <crypto/sha.h>
3838
#include <crypto/md5.h>
39+
#include <crypto/chacha20.h>
3940
#include <crypto/internal/aead.h>
4041
#include <crypto/authenc.h>
4142
#include <crypto/akcipher.h>

drivers/crypto/caam/desc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,7 @@
11591159
#define OP_ALG_ALGSEL_KASUMI (0x70 << OP_ALG_ALGSEL_SHIFT)
11601160
#define OP_ALG_ALGSEL_CRC (0x90 << OP_ALG_ALGSEL_SHIFT)
11611161
#define OP_ALG_ALGSEL_SNOW_F9 (0xA0 << OP_ALG_ALGSEL_SHIFT)
1162+
#define OP_ALG_ALGSEL_CHACHA20 (0xD0 << OP_ALG_ALGSEL_SHIFT)
11621163

11631164
#define OP_ALG_AAI_SHIFT 4
11641165
#define OP_ALG_AAI_MASK (0x1ff << OP_ALG_AAI_SHIFT)
@@ -1206,6 +1207,11 @@
12061207
#define OP_ALG_AAI_RNG4_AI (0x80 << OP_ALG_AAI_SHIFT)
12071208
#define OP_ALG_AAI_RNG4_SK (0x100 << OP_ALG_AAI_SHIFT)
12081209

1210+
/* Chacha20 AAI set */
1211+
#define OP_ALG_AAI_AEAD (0x002 << OP_ALG_AAI_SHIFT)
1212+
#define OP_ALG_AAI_KEYSTREAM (0x001 << OP_ALG_AAI_SHIFT)
1213+
#define OP_ALG_AAI_BC8 (0x008 << OP_ALG_AAI_SHIFT)
1214+
12091215
/* hmac/smac AAI set */
12101216
#define OP_ALG_AAI_HASH (0x00 << OP_ALG_AAI_SHIFT)
12111217
#define OP_ALG_AAI_HMAC (0x01 << OP_ALG_AAI_SHIFT)

0 commit comments

Comments
 (0)