crypto: k3: Add sa2ul driver
cover crypto: k3: Add sa2ul driver
The series adds Crypto hardware accelerator support for SA2UL. SA2UL stands for security accelerator ultra lite.
The Security Accelerator (SA2_UL) subsystem provides hardware cryptographic acceleration for the following use cases:
• Encryption and authentication for secure boot
• Encryption and authentication of content in applications requiring DRM (digital rights management) and content/asset protection
The device includes one instantiation of SA2_UL named SA2_UL0
SA2UL needs on tx channel and a pair of rx dma channels.
This series has dependency on UDMA series. Hence is based on top of:
https://patchwork.kernel.org/project/linux-dmaengine/list/?series=114105
The above series adds couple of dmaengine APIs that are used by the sa2ul driver. Hence there is a hard dependency on the above series.
Resending with linux-crypto list in Cc.
Keerthy (10):
dt-bindings: crypto: k3: Add sa2ul bindings documentation
crypto: sa2ul: Add crypto driver
crypto: sa2ul: Add AES ECB Mode support
crypto: sa2ul: Add aead support for hmac(sha1)cbc(aes) algorithm
crypto: sha256_generic: Export the Transform function
crypto: sa2ul: Add hmac(sha256)cbc(aes) AEAD Algo support
crypto: sa2ul: Add hmac(sha1) HMAC algorithm support
crypto: sa2ul: Add hmac(sha256) HMAC algorithm support
sa2ul: Add 3DES ECB & CBC Mode support
arm64: dts: k3-am6: Add crypto accelarator node
.../devicetree/bindings/crypto/sa2ul.txt | 47 + arch/arm64/boot/dts/ti/k3-am65-main.dtsi | 33 + crypto/sha256_generic.c | 3 +- drivers/crypto/Kconfig | 17 + drivers/crypto/Makefile | 1 + drivers/crypto/sa2ul.c | 2232 +++++++++++++++++ drivers/crypto/sa2ul.h | 384 +++ include/crypto/sha.h | 1 + 8 files changed, 2717 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/crypto/sa2ul.txt create mode 100644 drivers/crypto/sa2ul.c create mode 100644 drivers/crypto/sa2ul.h
Signature · 1 line
2.17.1
PATCH RESEND 1/10 dt-bindings: crypto: k3: Add sa2ul bindings documentation
The series adds Crypto hardware accelerator support for SA2UL. SA2UL stands for security accelerator ultra lite.
The Security Accelerator (SA2_UL) subsystem provides hardware cryptographic acceleration for the following use cases:
• Encryption and authentication for secure boot
• Encryption and authentication of content in applications requiring DRM (digital rights management) and content/asset protection
The device includes one instantiation of SA2_UL named SA2_UL0
SA2UL needs on tx channel and a pair of rx dma channels.
--- .../devicetree/bindings/crypto/sa2ul.txt | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/sa2ul.txt
Documentation/devicetree/bindings/crypto/sa2ul.txt new file +47 -0
@@ -0,0 +1,47 @@ +K3 SoC SA2UL crypto module + +Required properties: + +- compatible : Should be: + - "ti,sa2ul-crypto" +- reg : Offset and length of the register set for the module + +- dmas: DMA specifiers for tx and rx dma. sa2ul needs one tx channel + and 2 rx channels. First rx channel for < 256 bytes and + the other one for >=256 bytes. See the DMA client binding, + Documentation/devicetree/bindings/dma/dma.txt +- dma-names: DMA request names has to have one tx and 2 rx names + corresponding to dmas abive. +- ti,psil-config* - UDMA PSIL native Peripheral using packet mode. + SA2UL must have EPIB(Extended protocal information block) + and PSDATA(protocol specific data) properties. + +Example AM654 SA2UL: +crypto: crypto@4E00000 { + compatible = "ti,sa2ul-crypto"; + reg = <0x0 0x4E00000 0x0 0x1200>; + ti,psil-base = <0x4000>; + + dmas = <&main_udmap &crypto 0 UDMA_DIR_TX>, + <&main_udmap &crypto 0 UDMA_DIR_RX>, + <&main_udmap &crypto 1 UDMA_DIR_RX>; + dma-names = "tx", "rx1", "rx2"; + + ti,psil-config0 { + linux,udma-mode = <UDMA_PKT_MODE>; + ti,needs-epib; + ti,psd-size = <64>; + }; + + ti,psil-config1 { + linux,udma-mode = <UDMA_PKT_MODE>; + ti,needs-epib; + ti,psd-size = <64>; + }; + + ti,psil-config2 { + linux,udma-mode = <UDMA_PKT_MODE>; + ti,needs-epib; + ti,psd-size = <64>; + }; +};
Signature · 1 line
2.17.1
PATCH RESEND 2/10 crypto: sa2ul: Add crypto driver
In reply to KeerthyThe Security Accelerator (SA2_UL) subsystem provides hardware cryptographic acceleration for the following use cases:
• Encryption and authentication for secure boot
• Encryption and authentication of content in applications requiring DRM (digital rights management) and content/asset protection
The device includes one instantiation of SA2_UL named SA2_UL0
SA2_UL supports the following cryptographic industry standards to enable data authentication, data integrity and data confidentiality.
Crypto function library for software acceleration
o AES operation
o 3DES operation
o SHA1 operation
o MD5 operation
o SHA2 – 224, 256, 384, 512 operation
Authentication supported via following hardware cores
o SHA1
o MD5
o SHA2 -224
o SHA2-256
o SHA2-384
o SHA2-512
Patch adds a basic crypto driver and currently supports AES in cbc mode for both encryption and decryption.
--- drivers/crypto/Kconfig | 17 + drivers/crypto/Makefile | 1 + drivers/crypto/sa2ul.c | 1151 +++++++++++++++++++++++++++++++++++++++ drivers/crypto/sa2ul.h | 384 +++++++++++++ 4 files changed, 1553 insertions(+) create mode 100644 drivers/crypto/sa2ul.c create mode 100644 drivers/crypto/sa2ul.h
drivers/crypto/Kconfig +17 -0
@@ -785,4 +785,21 @@ config CRYPTO_DEV_CCREE source "drivers/crypto/hisilicon/Kconfig" +config CRYPTO_DEV_SA2UL + tristate "Support for TI security accelerator" + depends on ARCH_K3 || COMPILE_TEST + select ARM64_CRYPTO + select CRYPTO_AES + select CRYPTO_AES_ARM64 + select CRYPTO_SHA1 + select CRYPTO_MD5 + select CRYPTO_ALGAPI + select CRYPTO_AUTHENC + select HW_RANDOM + default m if ARCH_K3 + help + Keystone devices include a security accelerator engine that may be + used for crypto offload. Select this if you want to use hardware + acceleration for cryptographic algorithms on these devices. + endif # CRYPTO_HW
drivers/crypto/Makefile +1 -0
@@ -47,4 +47,5 @@ obj-$(CONFIG_CRYPTO_DEV_VMX) += vmx/ obj-$(CONFIG_CRYPTO_DEV_BCM_SPU) += bcm/ obj-$(CONFIG_CRYPTO_DEV_SAFEXCEL) += inside-secure/ obj-$(CONFIG_CRYPTO_DEV_ARTPEC6) += axis/ +obj-$(CONFIG_CRYPTO_DEV_SA2UL) += sa2ul.o obj-y += hisilicon/
drivers/crypto/sa2ul.c new file +1151 -0
1,151 lines not on this page · raw message
drivers/crypto/sa2ul.h new file +384 -0
384 lines not on this page · raw message
Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH RESEND 3/10 crypto: sa2ul: Add AES ECB Mode support
In reply to KeerthyAdd support for AES algorithm in ECB Mode. Data encryption modes are supported via MCE engine (programmable mode control engine). ECB (Electronic code book) is a mode of operation for a block cipher, with the characteristic that each possible block of plaintext has a defined corresponding ciphertext value and vice versa. In other words, the same plaintext value will always result in the same ciphertext value.
--- drivers/crypto/sa2ul.c | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)
drivers/crypto/sa2ul.c +76 -0
@@ -178,6 +178,38 @@ static u8 mci_cbc_dec_array[3][MODE_CONTROL_BYTES] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, }; +/* +* Mode Control Instructions for various Key lengths 128, 192, 256 +* For ECB (Electronic Code Book) mode for encryption +*/ +static u8 mci_ecb_enc_array[3 ][27 ] = { + {0x21 ,0x00 ,0x00 ,0x80 ,0x8a ,0x04 ,0xb7 ,0x90 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 }, + {0x21 ,0x00 ,0x00 ,0x84 ,0x8a ,0x04 ,0xb7 ,0x90 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 }, + {0x21 ,0x00 ,0x00 ,0x88 ,0x8a ,0x04 ,0xb7 ,0x90 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 }, +}; + +/* +* Mode Control Instructions for various Key lengths 128, 192, 256 +* For ECB (Electronic Code Book) mode for decryption +*/ +static u8 mci_ecb_dec_array[3 ][27 ] = { + {0x31 ,0x00 ,0x00 ,0x80 ,0x8a ,0x04 ,0xb7 ,0x90 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 }, + {0x31 ,0x00 ,0x00 ,0x84 ,0x8a ,0x04 ,0xb7 ,0x90 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 }, + {0x31 ,0x00 ,0x00 ,0x88 ,0x8a ,0x04 ,0xb7 ,0x90 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 }, +}; +/* * Perform 16 byte or 128 bit swizzling * The SA2UL Expects the security context to
@@ -746,6 +778,26 @@ static int sa_aes_cbc_setkey(struct crypto_ablkcipher *tfm, const u8 *key,return sa_aes_setkey (tfm, key, keylen, ad); } +static int sa_aes_ecb_setkey (struct crypto_ablkcipher *tfm,const u8 *key, +unsigned int keylen) +{ +struct algo_data *ad =kzalloc (sizeof (*ad),GFP_KERNEL ); +/* Convert the key size (16/24/32) to the key size index (0/1/2) */ +int key_idx = (keylen >>3 ) -2 ; + + ad->enc_eng.eng_id =SA_ENG_ID_EM1 ; + ad->enc_eng.sc_size =SA_CTX_ENC_TYPE1_SZ ; + ad->auth_eng.eng_id =SA_ENG_ID_NONE ; + ad->auth_eng.sc_size =0 ; + ad->mci_enc = mci_ecb_enc_array[key_idx]; + ad->mci_dec = mci_ecb_dec_array[key_idx]; + ad->inv_key = true; + ad->ealg_id =SA_EALG_ID_AES_ECB ; + ad->aalg_id =SA_AALG_ID_NONE ; + +return sa_aes_setkey (tfm, key, keylen, ad); +} +static void sa_aes_dma_in_callback (void *data) {struct sa_rx_data *rxd = (struct sa_rx_data *)data;
@@ -940,6 +992,30 @@ static struct sa_alg_tmpl sa_algs[] = { } } }, + { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, + .alg.crypto = { + .cra_name = "ecb(aes)", + .cra_driver_name = "ecb-aes-sa2ul", + .cra_priority = 30000, + .cra_flags =CRYPTO_ALG_TYPE_ABLKCIPHER | +CRYPTO_ALG_KERN_DRIVER_ONLY | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK, + .cra_blocksize = AES_BLOCK_SIZE, + .cra_ctxsize = sizeof(struct sa_tfm_ctx), + .cra_alignmask = 0, + .cra_type = &crypto_ablkcipher_type, + .cra_module = THIS_MODULE, + .cra_init = sa_aes_cra_init, + .cra_exit = sa_aes_cra_exit, + .cra_u.ablkcipher = { + .min_keysize = AES_MIN_KEY_SIZE, + .max_keysize = AES_MAX_KEY_SIZE, + .setkey = sa_aes_ecb_setkey, + .encrypt = sa_aes_cbc_encrypt, + .decrypt = sa_aes_cbc_decrypt, + } + } + }, };/* Register the algorithms in crypto framework */
Signature · 1 line
2.17.1
PATCH RESEND 4/10 crypto: sa2ul: Add aead support for hmac(sha1)cbc(aes) algorithm
In reply to KeerthyAdd aead support for hmac(sha1)cbc(aes) algorithm. Authenticated encryption (AE) and authenticated encryption with associated data (AEAD) is a form of encryption which simultaneously provides confidentiality, integrity, and authenticity assurances on the data.
hmac(sha1) has a digest size of 20 bytes is used for authetication and AES in CBC mode is used in conjunction for encryption/decryption.
--- drivers/crypto/sa2ul.c | 402 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 402 insertions(+)
drivers/crypto/sa2ul.c +402 -0
@@ -228,6 +228,49 @@ static void sa_swiz_128(u8 *in, u16 len) } } +/* Prepare the ipad and opad from key as per SHA algorithm step 1*/ +static void prepare_kiopad (u8 *k_ipad,u8 *k_opad,const u8 *key,u16 key_sz) +{ +int i; + +for (i =0 ; i < key_sz; i++) { + k_ipad[i] = key[i] ^0x36 ; + k_opad[i] = key[i] ^0x5c ; + } + +/* Instead of XOR with 0 */ +for (; i <SHA_MESSAGE_BYTES ; i++) { + k_ipad[i] =0x36 ; + k_opad[i] =0x5c ; + } +} + +/* Generate HMAC-SHA1 intermediate Hash */ +static +void sa_hmac_sha1_get_pad (const u8 *key,u16 key_sz,u32 *ipad,u32 *opad) +{ +u32 ws[SHA_WORKSPACE_WORDS ]; +u8 k_ipad[SHA_MESSAGE_BYTES ]; +u8 k_opad[SHA_MESSAGE_BYTES ]; +int i; + +prepare_kiopad (k_ipad, k_opad, key, key_sz); + +/* SHA-1 on k_ipad */ +sha_init (ipad); +sha_transform (ipad, k_ipad, ws); + +for (i =0 ; i <SHA_DIGEST_WORDS ; i++) + ipad[i] =cpu_to_be32 (ipad[i]); + +/* SHA-1 on k_opad */ +sha_init (opad); +sha_transform (opad, k_opad, ws); + +for (i =0 ; i <SHA_DIGEST_WORDS ; i++) + opad[i] =cpu_to_be32 (opad[i]); +} +/* Derive the inverse key used in AES-CBC decryption operation */ static inline int sa_aes_inv_key (u8 *inv_key,const u8 *key,u16 key_sz) {
@@ -814,6 +857,45 @@ static void sa_aes_dma_in_callback(void *data)ablkcipher_request_complete (req,0 ); } +static void sa_aead_dma_in_callback (void *data) +{ +struct sa_rx_data *rxd = (struct sa_rx_data *)data; +struct aead_request *req = (struct aead_request *)rxd->req; +struct crypto_aead *tfm =crypto_aead_reqtfm (req); +u32 *mdptr; +unsigned int start = req->assoclen + req->cryptlen; +unsigned int authsize =crypto_aead_authsize (tfm); +u8 auth_tag[SA_MAX_AUTH_TAG_SZ ]; +int i, sglen, err =0 ; +size_t pl, ml; + + mdptr = (u32 *)dmaengine_desc_get_metadata_ptr (rxd->tx_in, &pl, &ml); +for (i =0 ; i < (authsize /4 ); i++) + mdptr[i +4 ] =htonl (mdptr[i +4 ]); + +if (rxd->enc) { +scatterwalk_map_and_copy ((void *)&mdptr[4 ], req->dst, + start,crypto_aead_authsize (tfm),1 ); + }else { + start -= authsize; +scatterwalk_map_and_copy (auth_tag, req->src, + start,crypto_aead_authsize (tfm),0 ); + + err =memcmp ((void *)&mdptr[4 ], + auth_tag, authsize) ? -EBADMSG :0 ; + } + + sglen =sg_nents_for_len (req->dst, req->cryptlen + authsize); +dma_unmap_sg (rxd->ddev, req->dst, sglen,DMA_FROM_DEVICE ); + + sglen =sg_nents_for_len (req->src, req->assoclen + req->cryptlen); +dma_unmap_sg (rxd->ddev, req->src, sglen,DMA_TO_DEVICE ); + +aead_request_complete (req, err); + +kfree (rxd); +} +static void sa_prepare_tx_desc (u32 *mdptr,u32 pslen,u32 *psdata,u32 epiblen,u32 *epib) {
@@ -965,6 +1047,300 @@ static int sa_aes_cbc_decrypt(struct ablkcipher_request *req)return sa_aes_run (req, req->info,0 ); } +static int sa_init_tfm (struct crypto_tfm *tfm) +{ +struct crypto_alg *alg = tfm->__crt_alg; +struct sa_tfm_ctx *ctx =crypto_tfm_ctx (tfm); +struct sa_crypto_data *data =dev_get_drvdata (sa_k3_dev); +int ret; + +if ((alg->cra_flags &CRYPTO_ALG_TYPE_MASK ) ==CRYPTO_ALG_TYPE_AEAD ) { +memset (ctx,0 ,sizeof (*ctx)); + ctx->dev_data = data; + + ret =sa_init_ctx_info (&ctx->enc, data); +if (ret) +return ret; + ret =sa_init_ctx_info (&ctx->dec, data); +if (ret) { +sa_free_ctx_info (&ctx->enc, data); +return ret; + } + } + +dev_dbg (sa_k3_dev,"%s(0x%p) sc-ids(0x%x(0x%pad), 0x%x(0x%pad))\n" , + __func__, tfm, ctx->enc.sc_id, &ctx->enc.sc_phys, + ctx->dec.sc_id, &ctx->dec.sc_phys); +return 0 ; +} + +/* Algorithm init */ +static int sa_cra_init_aead (struct crypto_aead *tfm) +{ +return sa_init_tfm (crypto_aead_tfm (tfm)); +} + +/* Algorithm context teardown */ +static void sa_exit_tfm (struct crypto_tfm *tfm) +{ +struct crypto_alg *alg = tfm->__crt_alg; +struct sa_tfm_ctx *ctx =crypto_tfm_ctx (tfm); +struct sa_crypto_data *data =dev_get_drvdata (sa_k3_dev); + +dev_dbg (sa_k3_dev,"%s(0x%p) sc-ids(0x%x(0x%pad), 0x%x(0x%pad))\n" , + __func__, tfm, ctx->enc.sc_id, &ctx->enc.sc_phys, + ctx->dec.sc_id, &ctx->dec.sc_phys); + +if ((alg->cra_flags &CRYPTO_ALG_TYPE_MASK ) + ==CRYPTO_ALG_TYPE_AEAD ) { +sa_free_ctx_info (&ctx->enc, data); +sa_free_ctx_info (&ctx->dec, data); + } +} + +static void sa_exit_tfm_aead (struct crypto_aead *tfm) +{ +return sa_exit_tfm (crypto_aead_tfm (tfm)); +} + +/* AEAD algorithm configuration interface function */ +static int sa_aead_setkey (struct crypto_aead *authenc, +const u8 *key,unsigned int keylen, +struct algo_data *ad) +{ +struct sa_tfm_ctx *ctx =crypto_aead_ctx (authenc); +struct crypto_authenc_keys keys; + +const char *cra_name; +int cmdl_len; +struct sa_cmdl_cfg cfg; + +if (crypto_authenc_extractkeys (&keys, key, keylen) !=0 ) + goto badkey; + + cra_name =crypto_tfm_alg_name (crypto_aead_tfm (authenc)); + +memset (&cfg,0 ,sizeof (cfg)); + cfg.enc1st =1 ; + cfg.aalg = ad->aalg_id; + cfg.enc_eng_id = ad->enc_eng.eng_id; + cfg.auth_eng_id = ad->auth_eng.eng_id; + cfg.iv_size =crypto_aead_ivsize (authenc); + cfg.akey = keys.authkey; + cfg.akey_len = keys.authkeylen; + +/* Setup Encryption Security Context & Command label template */ +if (sa_init_sc (&ctx->enc, keys.enckey, keys.enckeylen, + keys.authkey, keys.authkeylen, + ad,1 , &ctx->enc.epib[1 ], true)) + goto badkey; + + cmdl_len =sa_format_cmdl_gen (&cfg, + (u8 *)ctx->enc.cmdl, + &ctx->enc.cmdl_upd_info); +if (cmdl_len <=0 || (cmdl_len >SA_MAX_CMDL_WORDS *sizeof (u32))) + goto badkey; + + ctx->enc.cmdl_size = cmdl_len; + +/* Setup Decryption Security Context & Command label template */ +if (sa_init_sc (&ctx->dec, keys.enckey, keys.enckeylen, + keys.authkey, keys.authkeylen, + ad,0 , &ctx->dec.epib[1 ], true)) + goto badkey; + + cfg.enc1st =0 ; + cfg.enc_eng_id = ad->enc_eng.eng_id; + cmdl_len =sa_format_cmdl_gen (&cfg, (u8 *)ctx->dec.cmdl, + &ctx->dec.cmdl_upd_info); + +if (cmdl_len <=0 || (cmdl_len >SA_MAX_CMDL_WORDS *sizeof (u32))) + goto badkey; + + ctx->dec.cmdl_size = cmdl_len; + +kfree (ad); + +return 0 ; + +badkey: +dev_err (sa_k3_dev,"%s: badkey\n" , __func__); +return -EINVAL ; +} + +static int sa_aead_cbc_sha1_setkey (struct crypto_aead *authenc, +const u8 *key,unsigned int keylen) +{ +struct algo_data *ad =kzalloc (sizeof (*ad),GFP_KERNEL ); +struct crypto_authenc_keys keys; +int ret =0 , key_idx; + + ret =crypto_authenc_extractkeys (&keys, key, keylen); +if (ret) +return ret; + +/* Convert the key size (16/24/32) to the key size index (0/1/2) */ + key_idx = (keys.enckeylen >>3 ) -2 ; + ad->enc_eng.eng_id =SA_ENG_ID_EM1 ; + ad->enc_eng.sc_size =SA_CTX_ENC_TYPE1_SZ ; + ad->auth_eng.eng_id =SA_ENG_ID_AM1 ; + ad->auth_eng.sc_size =SA_CTX_AUTH_TYPE2_SZ ; + ad->mci_enc = mci_cbc_enc_array[key_idx]; + ad->mci_dec = mci_cbc_dec_array[key_idx]; + ad->inv_key = true; + ad->keyed_mac = true; + ad->ealg_id =SA_EALG_ID_AES_CBC ; + ad->aalg_id =SA_AALG_ID_HMAC_SHA1 ; + ad->hash_size =SHA1_DIGEST_SIZE ; + ad->auth_ctrl =0x2 ; + ad->prep_iopad = sa_hmac_sha1_get_pad; + +return sa_aead_setkey (authenc, key, keylen, ad); +} + +static int sa_aead_run (struct aead_request *req,u8 *iv,int enc) +{ +struct crypto_aead *tfm =crypto_aead_reqtfm (req); +struct sa_tfm_ctx *ctx =crypto_aead_ctx (tfm); +struct sa_ctx_info *sa_ctx = enc ? &ctx->enc : &ctx->dec; +struct sa_rx_data *rxd; +struct dma_async_tx_descriptor *tx_in, *tx_out; +struct sa_crypto_data *pdata =dev_get_drvdata (sa_k3_dev); +struct sa_dma_req_ctx req_ctx; +u8 enc_offset; +int sg_nents, dst_nents; +int psdata_offset; +u8 auth_offset =0 ; +u8 *auth_iv =NULL ; +u8 *aad =NULL ; +u8 aad_len =0 ; +u16 enc_len; +u16 auth_len =0 ; +u32 *mdptr; +u32 req_type; +struct dma_chan *dma_rx; +gfp_t flags; +size_t pl, ml; +struct device *ddev; + + flags = req->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ? +GFP_KERNEL :GFP_ATOMIC ; + +if (enc) { + iv = (u8 *)(req->iv); + enc_offset = req->assoclen; + enc_len = req->cryptlen; + auth_len = req->assoclen + req->cryptlen; + }else { + enc_offset = req->assoclen; + enc_len = req->cryptlen -crypto_aead_authsize (tfm); + auth_len = req->assoclen + req->cryptlen - +crypto_aead_authsize (tfm); + } + +if (enc_len >=256 ) + dma_rx = pdata->dma_rx2; +else + dma_rx = pdata->dma_rx1; + + ddev = dma_rx->device->dev; +/* Allocate descriptor & submit packet */ + sg_nents =sg_nents_for_len (req->src, enc_len + req->assoclen); + dst_nents =sg_nents_for_len (req->dst, enc_len + +crypto_aead_authsize (tfm)); + +memcpy (req_ctx.cmdl, sa_ctx->cmdl, sa_ctx->cmdl_size); +/* Update Command Label */ +sa_update_cmdl (sa_k3_dev, enc_offset, enc_len, + iv, auth_offset, auth_len, + auth_iv, aad_len, aad, + &sa_ctx->cmdl_upd_info, req_ctx.cmdl); + +/* +* Last 2 words in PSDATA will have the crypto alg type & +* crypto request pointer +*/ + req_type =CRYPTO_ALG_TYPE_AEAD ; +if (enc) + req_type |= (SA_REQ_SUBTYPE_ENC <<SA_REQ_SUBTYPE_SHIFT ); +else + req_type |= (SA_REQ_SUBTYPE_DEC <<SA_REQ_SUBTYPE_SHIFT ); + + psdata_offset = sa_ctx->cmdl_size /sizeof (u32); + +/* map the packet */ + req_ctx.src = req->src; + req_ctx.src_nents =dma_map_sg (ddev, req->src, + sg_nents,DMA_TO_DEVICE ); + dst_nents =dma_map_sg (ddev, req->dst, + dst_nents,DMA_FROM_DEVICE ); + +if (unlikely (req_ctx.src_nents != sg_nents)) { +dev_warn_ratelimited (sa_k3_dev,"failed to map tx pkt\n" ); +return -EIO ; + } + + req_ctx.dev_data = pdata; + req_ctx.pkt = true; + +dma_sync_sg_for_device (pdata->dev, req->src, req_ctx.src_nents, +DMA_TO_DEVICE ); + + tx_in =dmaengine_prep_slave_sg (dma_rx, req->dst, dst_nents, +DMA_DEV_TO_MEM , +DMA_PREP_INTERRUPT |DMA_CTRL_ACK ); +if (!tx_in) { +dev_err (pdata->dev,"IN prep_slave_sg() failed\n" ); +return -EINVAL ; + } + + rxd =kzalloc (sizeof (*rxd),GFP_KERNEL ); + rxd->req = (void *)req; + rxd->enc = enc; + rxd->tx_in = tx_in; + rxd->ddev = ddev; + +/* IN */ + tx_in->callback = sa_aead_dma_in_callback; + tx_in->callback_param = rxd; + + tx_out =dmaengine_prep_slave_sg (pdata->dma_tx, req->src, + req_ctx.src_nents,DMA_MEM_TO_DEV , +DMA_PREP_INTERRUPT |DMA_CTRL_ACK ); +if (!tx_out) { +dev_err (pdata->dev,"OUT prep_slave_sg() failed\n" ); +return -EINVAL ; + } + + mdptr = (u32 *)dmaengine_desc_get_metadata_ptr (tx_out, &pl, &ml); + +sa_prepare_tx_desc (mdptr, (sa_ctx->cmdl_size + (SA_PSDATA_CTX_WORDS * +sizeof (u32))), req_ctx.cmdl, +sizeof (sa_ctx->epib), sa_ctx->epib); + + ml = sa_ctx->cmdl_size + (SA_PSDATA_CTX_WORDS *sizeof (u32)); +dmaengine_desc_set_metadata_len (tx_out,52 ); + +dmaengine_submit (tx_out); +dmaengine_submit (tx_in); + +dma_async_issue_pending (dma_rx); +dma_async_issue_pending (pdata->dma_tx); +return -EINPROGRESS ; +} + +/* AEAD algorithm encrypt interface function */ +static int sa_aead_encrypt (struct aead_request *req) +{ +return sa_aead_run (req, req->iv,1 ); +} + +/* AEAD algorithm decrypt interface function */ +static int sa_aead_decrypt (struct aead_request *req) +{ +return sa_aead_run (req, req->iv,0 ); +} +static struct sa_alg_tmpl sa_algs[] = { {.type =CRYPTO_ALG_TYPE_ABLKCIPHER , .alg.crypto = {
@@ -1016,6 +1392,32 @@ static struct sa_alg_tmpl sa_algs[] = { } } }, +/* AEAD algorithms */ + {.type = CRYPTO_ALG_TYPE_AEAD, + .alg.aead = { + .base = { + .cra_name = "authenc(hmac(sha1),cbc(aes))", + .cra_driver_name = + "authenc(hmac(sha1),cbc(aes))-keystone-sa", + .cra_blocksize = AES_BLOCK_SIZE, + .cra_flags =CRYPTO_ALG_TYPE_AEAD | +CRYPTO_ALG_KERN_DRIVER_ONLY | + CRYPTO_ALG_ASYNC, + .cra_ctxsize = sizeof(struct sa_tfm_ctx), + .cra_module = THIS_MODULE, + .cra_alignmask = 0, + .cra_priority = 3000, + }, + .ivsize = AES_BLOCK_SIZE, + .maxauthsize = SHA1_DIGEST_SIZE, + + .init = sa_cra_init_aead, + .exit = sa_exit_tfm_aead, + .setkey = sa_aead_cbc_sha1_setkey, + .encrypt = sa_aead_encrypt, + .decrypt = sa_aead_decrypt, + } + }, };/* Register the algorithms in crypto framework */
Signature · 1 line
2.17.1
PATCH RESEND 5/10 crypto: sha256_generic: Export the Transform function
In reply to KeerthyThe transform function can be used as is by other crypto drivers that need to transform the 256 bit key using cpu. Hence export it.
--- crypto/sha256_generic.c | 3 ++- include/crypto/sha.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
crypto/sha256_generic.c +2 -1
@@ -63,7 +63,7 @@ static inline void BLEND_OP(int I, u32 *W)W [I ] =s1 (W [I -2 ]) +W [I -7 ] +s0 (W [I -15 ]) +W [I -16 ]; } -static void sha256_transform (u32 *state,const u8 *input) +void sha256_transform (u32 *state,const u8 *input) {u32 a, b, c, d, e, f, g, h, t1, t2;u32 W [64 ];
@@ -225,6 +225,7 @@ static void sha256_transform(u32 *state, const u8 *input) a = b = c = d = e = f = g = h = t1 = t2 =0 ;memzero_explicit (W ,64 *sizeof (u32)); } +EXPORT_SYMBOL (sha256_transform);static void sha256_generic_block_fn (struct sha256_state *sst,u8 const *src,int blocks)
include/crypto/sha.h +1 -0
@@ -95,6 +95,7 @@ struct sha512_state {struct shash_desc ; +extern void sha256_transform (u32 *state,const u8 *input);extern int crypto_sha1_update (struct shash_desc *desc,const u8 *data,unsigned int len);
Signature · 1 line
2.17.1
PATCH RESEND 6/10 crypto: sa2ul: Add hmac(sha256)cbc(aes) AEAD Algo support
In reply to KeerthyAdd aead support for hmac(sha256)cbc(aes) algorithm. Authenticated encryption (AE) and authenticated encryption with associated data (AEAD) is a form of encryption which simultaneously provides confidentiality, integrity, and authenticity assurances on the data.
hmac(sha256) has a digest size of 32 bytes is used for authetication and AES in CBC mode is used in conjunction for encryption/decryption.
--- drivers/crypto/sa2ul.c | 92 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+)
drivers/crypto/sa2ul.c +92 -0
@@ -271,6 +271,42 @@ void sa_hmac_sha1_get_pad(const u8 *key, u16 key_sz, u32 *ipad, u32 *opad) opad[i] =cpu_to_be32 (opad[i]); } +void sha256_init (u32 *buf) +{ + buf[0 ] =SHA256_H0 ; + buf[1 ] =SHA256_H1 ; + buf[2 ] =SHA256_H2 ; + buf[3 ] =SHA256_H3 ; + buf[4 ] =SHA256_H4 ; + buf[5 ] =SHA256_H5 ; + buf[6 ] =SHA256_H6 ; + buf[7 ] =SHA256_H7 ; +} + +static void sa_hmac_sha256_get_pad (const u8 *key,u16 key_sz,u32 *ipad, +u32 *opad) +{ +u8 k_ipad[SHA_MESSAGE_BYTES ]; +u8 k_opad[SHA_MESSAGE_BYTES ]; +int i; + +prepare_kiopad (k_ipad, k_opad, key, key_sz); + +/* SHA-256 on k_ipad */ +sha256_init (ipad); +sha256_transform (ipad, k_ipad); + +for (i =0 ; i <SHA256_DIGEST_WORDS ; i++) + ipad[i] =cpu_to_be32 (ipad[i]); + +/* SHA-256 on k_opad */ +sha256_init (opad); +sha256_transform (opad, k_opad); + +for (i =0 ; i <SHA256_DIGEST_WORDS ; i++) + opad[i] =cpu_to_be32 (opad[i]); +} +/* Derive the inverse key used in AES-CBC decryption operation */ static inline int sa_aes_inv_key (u8 *inv_key,const u8 *key,u16 key_sz) {
@@ -1198,6 +1234,37 @@ static int sa_aead_cbc_sha1_setkey(struct crypto_aead *authenc,return sa_aead_setkey (authenc, key, keylen, ad); } +static int sa_aead_cbc_sha256_setkey (struct crypto_aead *authenc, +const u8 *key,unsigned int keylen) +{ +struct algo_data *ad =kzalloc (sizeof (*ad),GFP_KERNEL ); +struct crypto_authenc_keys keys; +int ret =0 , key_idx; + + ret =crypto_authenc_extractkeys (&keys, key, keylen); +if (ret) +return ret; + +/* Convert the key size (16/24/32) to the key size index (0/1/2) */ + key_idx = (keys.enckeylen >>3 ) -2 ; + + ad->enc_eng.eng_id =SA_ENG_ID_EM1 ; + ad->enc_eng.sc_size =SA_CTX_ENC_TYPE1_SZ ; + ad->auth_eng.eng_id =SA_ENG_ID_AM1 ; + ad->auth_eng.sc_size =SA_CTX_AUTH_TYPE2_SZ ; + ad->mci_enc = mci_cbc_enc_array[key_idx]; + ad->mci_dec = mci_cbc_dec_array[key_idx]; + ad->inv_key = true; + ad->keyed_mac = true; + ad->ealg_id =SA_EALG_ID_AES_CBC ; + ad->aalg_id =SA_AALG_ID_HMAC_SHA2_256 ; + ad->hash_size =SHA256_DIGEST_SIZE ; + ad->auth_ctrl =0x4 ; + ad->prep_iopad = sa_hmac_sha256_get_pad; + +return sa_aead_setkey (authenc, key, keylen, ad); +} +static int sa_aead_run (struct aead_request *req,u8 *iv,int enc) {struct crypto_aead *tfm =crypto_aead_reqtfm (req);
@@ -1418,6 +1485,31 @@ static struct sa_alg_tmpl sa_algs[] = { .decrypt = sa_aead_decrypt, } }, + {.type = CRYPTO_ALG_TYPE_AEAD, + .alg.aead = { + .base = { + .cra_name = "authenc(hmac(sha256),cbc(aes))", + .cra_driver_name = + "authenc(hmac(sha256),cbc(aes))-keystone-sa", + .cra_blocksize = AES_BLOCK_SIZE, + .cra_flags =CRYPTO_ALG_TYPE_AEAD | +CRYPTO_ALG_KERN_DRIVER_ONLY | + CRYPTO_ALG_ASYNC, + .cra_ctxsize = sizeof(struct sa_tfm_ctx), + .cra_module = THIS_MODULE, + .cra_alignmask = 0, + .cra_priority = 3000, + }, + .ivsize = AES_BLOCK_SIZE, + .maxauthsize = SHA256_DIGEST_SIZE, + + .init = sa_cra_init_aead, + .exit = sa_exit_tfm_aead, + .setkey = sa_aead_cbc_sha256_setkey, + .encrypt = sa_aead_encrypt, + .decrypt = sa_aead_decrypt, + } + }, };/* Register the algorithms in crypto framework */
Signature · 1 line
2.17.1
PATCH RESEND 7/10 crypto: sa2ul: Add hmac(sha1) HMAC algorithm support
In reply to KeerthyHMAC hash-based message authentication code) is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and the authentication of a message, as with any MAC. Add hmac(sha1) HMAC algorithm support and the message digest size is 20 bytes.
--- drivers/crypto/sa2ul.c | 347 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 347 insertions(+)
drivers/crypto/sa2ul.c +347 -0
@@ -1408,6 +1408,307 @@ static int sa_aead_decrypt(struct aead_request *req)return sa_aead_run (req, req->iv,0 ); } +static int sa_sham_cra_init_alg (struct crypto_tfm *tfm,const char *alg_base) +{ +struct sa_tfm_ctx *ctx =crypto_tfm_ctx (tfm); +struct crypto_alg *alg = tfm->__crt_alg; +struct sa_crypto_data *data =dev_get_drvdata (sa_k3_dev); +int ret; + +if ((alg->cra_flags &CRYPTO_ALG_TYPE_MASK ) == +CRYPTO_ALG_TYPE_AHASH ) { +memset (ctx,0 ,sizeof (*ctx)); + ctx->dev_data = data; + ret =sa_init_ctx_info (&ctx->enc, data); +if (ret) +return ret; + } + +if (alg_base) { + ctx->shash =crypto_alloc_shash (alg_base,0 , +CRYPTO_ALG_NEED_FALLBACK ); +if (IS_ERR (ctx->shash)) { +pr_err ("base driver %s couldn't be loaded\n" , alg_base); +return PTR_ERR (ctx->shash); + } + } + +dev_dbg (sa_k3_dev,"%s(0x%p) sc-ids(0x%x(0x%pad), 0x%x(0x%pad))\n" , + __func__, tfm, ctx->enc.sc_id, &ctx->enc.sc_phys, + ctx->dec.sc_id, &ctx->dec.sc_phys); + +crypto_ahash_set_reqsize (__crypto_ahash_cast (tfm), +sizeof (struct sa_dma_req_ctx ) + +SHA512_BLOCK_SIZE ); + +return 0 ; +} + +static void sa_sham_dma_in_callback (void *data) +{ +struct sa_rx_data *rxd = (struct sa_rx_data *)data; +struct ahash_request *req = (struct ahash_request *)rxd->req; +struct crypto_ahash *tfm =crypto_ahash_reqtfm (req); +unsigned int authsize =crypto_ahash_digestsize (tfm); +int i, sg_nents; +size_t ml, pl; +u32 *mdptr, *result; + + mdptr = (u32 *)dmaengine_desc_get_metadata_ptr (rxd->tx_in, &pl, &ml); + result = (u32 *)req->result; + +kfree (rxd); + +for (i =0 ; i < (authsize /4 ); i++) + result[i] =htonl (mdptr[i +4 ]); + + sg_nents =sg_nents_for_len (req->src, req->nbytes); +dma_unmap_sg (rxd->ddev, req->src, sg_nents,DMA_FROM_DEVICE ); + +ahash_request_complete (req,0 ); + +kfree (rxd); +} + +static int sa_sham_digest (struct ahash_request *req) +{ +struct sa_tfm_ctx *ctx =crypto_ahash_ctx (crypto_ahash_reqtfm (req)); +struct sa_ctx_info *sa_ctx = &ctx->enc; +struct dma_async_tx_descriptor *tx_in, *tx_out; +struct sa_crypto_data *pdata =dev_get_drvdata (sa_k3_dev); +struct sa_dma_req_ctx req_ctx; +struct sa_rx_data *rxd; +u8 enc_offset; +int sg_nents; +int psdata_offset; +u8 auth_offset =0 ; +u8 *auth_iv =NULL ; +u8 *aad =NULL ; +u8 aad_len =0 ; +u16 enc_len; +u16 auth_len =0 ; +u32 req_type; +u32 *mdptr; +struct dma_chan *dma_rx; +gfp_t flags; +size_t pl, ml; +struct device *ddev; + + flags = req->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ? +GFP_KERNEL :GFP_ATOMIC ; + enc_len =0 ; + auth_len = req->nbytes; + enc_offset =0 ; + +if (enc_len >256 ) + dma_rx = pdata->dma_rx2; +else + dma_rx = pdata->dma_rx1; + + ddev = dma_rx->device->dev; +/* Allocate descriptor & submit packet */ + sg_nents =sg_nents_for_len (req->src, req->nbytes); + +memcpy (req_ctx.cmdl, sa_ctx->cmdl, sa_ctx->cmdl_size); +/* Update Command Label */ +sa_update_cmdl (sa_k3_dev, enc_offset, enc_len, +NULL , auth_offset, auth_len, + auth_iv, aad_len, aad, + &sa_ctx->cmdl_upd_info, req_ctx.cmdl); + +/* +* Last 2 words in PSDATA will have the crypto alg type & +* crypto request pointer +*/ + req_type =CRYPTO_ALG_TYPE_AHASH ; + + psdata_offset = sa_ctx->cmdl_size /sizeof (u32); + req_ctx.cmdl[psdata_offset++] = req_type; + +/* map the packet */ + req_ctx.src = req->src; + req_ctx.src_nents =dma_map_sg (ddev, req->src, sg_nents,DMA_TO_DEVICE ); + +if (unlikely (req_ctx.src_nents != sg_nents)) { +dev_warn_ratelimited (sa_k3_dev,"failed to map tx pkt\n" ); +return -EIO ; + } + + req_ctx.dev_data = pdata; + req_ctx.pkt = true; + +dma_sync_sg_for_device (pdata->dev, req->src, req_ctx.src_nents, +DMA_TO_DEVICE ); + + tx_in =dmaengine_prep_slave_sg (dma_rx, req->src, req_ctx.src_nents, +DMA_DEV_TO_MEM , +DMA_PREP_INTERRUPT |DMA_CTRL_ACK ); +if (!tx_in) { +dev_err (pdata->dev,"IN prep_slave_sg() failed\n" ); +return -EINVAL ; + } + + rxd =kzalloc (sizeof (*rxd),GFP_KERNEL ); + rxd->req = (void *)req; + rxd->tx_in = tx_in; + rxd->ddev = ddev; + tx_in->callback = sa_sham_dma_in_callback; + tx_in->callback_param = rxd; + + tx_out =dmaengine_prep_slave_sg (pdata->dma_tx, req->src, + req_ctx.src_nents,DMA_MEM_TO_DEV , +DMA_PREP_INTERRUPT |DMA_CTRL_ACK ); +if (!tx_out) { +dev_err (pdata->dev,"OUT prep_slave_sg() failed\n" ); +return -EINVAL ; + } + + mdptr = (u32 *)dmaengine_desc_get_metadata_ptr (tx_out, &pl, &ml); +sa_prepare_tx_desc (mdptr, (sa_ctx->cmdl_size + (SA_PSDATA_CTX_WORDS * +sizeof (u32))), req_ctx.cmdl, +sizeof (sa_ctx->epib), sa_ctx->epib); + +dmaengine_desc_set_metadata_len (tx_out,28 ); + +dmaengine_submit (tx_out); +dmaengine_submit (tx_in); + +dma_async_issue_pending (dma_rx); +dma_async_issue_pending (pdata->dma_tx); + +return -EINPROGRESS ; +} + +static int sa_sham_init (struct ahash_request *req) +{ +struct crypto_ahash *tfm =crypto_ahash_reqtfm (req); + +dev_dbg (sa_k3_dev,"init: digest size: %d\n" , +crypto_ahash_digestsize (tfm)); + +return 0 ; +} + +static int sa_sham_shash_digest (struct crypto_shash *tfm,u32 flags, +const u8 *data,unsigned int len,u8 *out) +{ +SHASH_DESC_ON_STACK (shash, tfm); + + shash->tfm = tfm; + +return crypto_shash_digest (shash, data, len, out); +} + +static int sa_sham_setkey (struct crypto_ahash *tfm,const u8 *key, +unsigned int keylen,struct algo_data *ad) +{ +struct sa_tfm_ctx *ctx =crypto_ahash_ctx (tfm); +int bs =crypto_shash_blocksize (ctx->shash); +int ds =crypto_shash_digestsize (ctx->shash); +int cmdl_len; +struct sa_cmdl_cfg cfg; +int err; + +if (keylen > bs) { + err =sa_sham_shash_digest (ctx->shash, +crypto_shash_get_flags (ctx->shash), + key, keylen, ctx->authkey); +if (err) +return err; + keylen = ds; + }else { +memcpy (ctx->authkey, key, keylen); + } + +memset (ctx->authkey + keylen,0 , bs - keylen); +memset (&cfg,0 ,sizeof (cfg)); + cfg.enc1st =0 ; + cfg.aalg = ad->aalg_id; + cfg.enc_eng_id = ad->enc_eng.eng_id; + cfg.auth_eng_id = ad->auth_eng.eng_id; + cfg.iv_size =0 ; + cfg.akey = ctx->authkey; + cfg.akey_len = keylen; + +/* Setup Encryption Security Context & Command label template */ +if (sa_init_sc (&ctx->enc,NULL ,0 , ctx->authkey, keylen, ad,0 , + &ctx->enc.epib[1 ], true)) + goto badkey; + + cmdl_len =sa_format_cmdl_gen (&cfg, + (u8 *)ctx->enc.cmdl, + &ctx->enc.cmdl_upd_info); +if (cmdl_len <=0 || (cmdl_len >SA_MAX_CMDL_WORDS *sizeof (u32))) + goto badkey; + + ctx->enc.cmdl_size = cmdl_len; + +kfree (ad); + +return 0 ; +badkey: +dev_err (sa_k3_dev,"%s: badkey\n" , __func__); +return -EINVAL ; +} + +static int sa_sham_sha1_setkey (struct crypto_ahash *tfm,const u8 *key, +unsigned int keylen) +{ +struct algo_data *ad =kzalloc (sizeof (*ad),GFP_KERNEL ); + + ad->enc_eng.eng_id =SA_ENG_ID_NONE ; + ad->enc_eng.sc_size =SA_CTX_ENC_TYPE1_SZ ; + ad->auth_eng.eng_id =SA_ENG_ID_AM1 ; + ad->auth_eng.sc_size =SA_CTX_AUTH_TYPE2_SZ ; + ad->mci_enc =NULL ; + ad->mci_dec =NULL ; + ad->inv_key = false; + ad->keyed_mac = true; + ad->ealg_id =SA_EALG_ID_NONE ; + ad->aalg_id =SA_AALG_ID_HMAC_SHA1 ; + ad->hash_size =SHA1_DIGEST_SIZE ; + ad->auth_ctrl =0x2 ; + ad->prep_iopad = sa_hmac_sha1_get_pad; + +return sa_sham_setkey (tfm, key, keylen, ad); +} + +static int sa_sham_cra_sha1_init (struct crypto_tfm *tfm) +{ +return sa_sham_cra_init_alg (tfm,"sha1" ); +} + +static void sa_sham_cra_exit (struct crypto_tfm *tfm) +{ +struct crypto_alg *alg = tfm->__crt_alg; +struct sa_tfm_ctx *ctx =crypto_tfm_ctx (tfm); +struct sa_crypto_data *data =dev_get_drvdata (sa_k3_dev); + +dev_dbg (sa_k3_dev,"%s(0x%p) sc-ids(0x%x(0x%pad), 0x%x(0x%pad))\n" , + __func__, tfm, ctx->enc.sc_id, &ctx->enc.sc_phys, + ctx->dec.sc_id, &ctx->dec.sc_phys); + +if ((alg->cra_flags &CRYPTO_ALG_TYPE_AHASH ) + ==CRYPTO_ALG_TYPE_AHASH ) { +sa_free_ctx_info (&ctx->enc, data); + } +} + +static int sa_sham_update (struct ahash_request *req) +{ +return -ENOTSUPP ; +} + +static int sa_sham_final (struct ahash_request *req) +{ +return sa_sham_digest (req); +} + +static int sa_sham_finup (struct ahash_request *req) +{ +return sa_sham_digest (req); +} +static struct sa_alg_tmpl sa_algs[] = { {.type =CRYPTO_ALG_TYPE_ABLKCIPHER , .alg.crypto = {
@@ -1512,6 +1813,34 @@ static struct sa_alg_tmpl sa_algs[] = { }, }; +static struct ahash_alg algs_sha[] = { +{ + .init = sa_sham_init, + .update = sa_sham_update, + .final = sa_sham_final, + .finup = sa_sham_finup, + .digest = sa_sham_digest, + .setkey = sa_sham_sha1_setkey, + .halg.digestsize =SHA1_DIGEST_SIZE , + .halg.statesize =128 , + .halg.base = { + .cra_name ="hmac(sha1)" , + .cra_driver_name ="sa-hmac-sha1" , + .cra_priority =400 , + .cra_flags =CRYPTO_ALG_TYPE_AHASH | +CRYPTO_ALG_ASYNC | +CRYPTO_ALG_KERN_DRIVER_ONLY | +CRYPTO_ALG_NEED_FALLBACK , + .cra_blocksize =SHA1_BLOCK_SIZE , + .cra_ctxsize =sizeof (struct sa_tfm_ctx ), + .cra_alignmask =SA_ALIGN_MASK , + .cra_module =THIS_MODULE , + .cra_init = sa_sham_cra_sha1_init, + .cra_exit = sa_sham_cra_exit, + } +}, +}; +/* Register the algorithms in crypto framework */ void sa_register_algos (const struct device *dev) {
@@ -1539,6 +1868,15 @@ void sa_register_algos(const struct device *dev)else sa_algs[i].registered =1 ; } + + num_algs =ARRAY_SIZE (algs_sha); +for (i =0 ; i < num_algs; i++) { + alg_name = algs_sha[i].halg.base.cra_name; + err =crypto_register_ahash (&algs_sha[i]); +if (err) +dev_err (dev,"Failed to register '%s'\n" , + alg_name); + } }/* Unregister the algorithms in crypto framework */
@@ -1560,6 +1898,15 @@ void sa_unregister_algos(const struct device *dev) sa_algs[i].registered =0 ; } + + num_algs =ARRAY_SIZE (algs_sha); +for (i =0 ; i < num_algs; i++) { + alg_name = algs_sha[i].halg.base.cra_name; + err =crypto_unregister_ahash (&algs_sha[i]); +if (err) +dev_err (dev,"Failed to register '%s'\n" , + alg_name); + } }static int sa_init_mem (struct sa_crypto_data *dev_data)
Signature · 1 line
2.17.1
PATCH RESEND 8/10 crypto: sa2ul: Add hmac(sha256) HMAC algorithm support
In reply to KeerthyHMAC hash-based message authentication code) is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and the authentication of a message, as with any MAC. Add hmac(sha256) HMAC algorithm support and the message digest size is 32 bytes.
--- drivers/crypto/sa2ul.c | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
drivers/crypto/sa2ul.c +52 -0
@@ -1673,11 +1673,38 @@ static int sa_sham_sha1_setkey(struct crypto_ahash *tfm, const u8 *key,return sa_sham_setkey (tfm, key, keylen, ad); } +static int sa_sham_sha256_setkey (struct crypto_ahash *tfm,const u8 *key, +unsigned int keylen) +{ +struct algo_data *ad =kzalloc (sizeof (*ad),GFP_KERNEL ); + + ad->enc_eng.eng_id =SA_ENG_ID_NONE ; + ad->enc_eng.sc_size =SA_CTX_ENC_TYPE1_SZ ; + ad->auth_eng.eng_id =SA_ENG_ID_AM1 ; + ad->auth_eng.sc_size =SA_CTX_AUTH_TYPE2_SZ ; + ad->mci_enc =NULL ; + ad->mci_dec =NULL ; + ad->inv_key = false; + ad->keyed_mac = true; + ad->ealg_id =SA_EALG_ID_NONE ; + ad->aalg_id =SA_AALG_ID_HMAC_SHA2_256 ; + ad->hash_size =SHA256_DIGEST_SIZE ; + ad->auth_ctrl =0x4 ; + ad->prep_iopad = sa_hmac_sha256_get_pad; + +return sa_sham_setkey (tfm, key, keylen, ad); +} +static int sa_sham_cra_sha1_init (struct crypto_tfm *tfm) {return sa_sham_cra_init_alg (tfm,"sha1" ); } +static int sa_sham_cra_sha256_init (struct crypto_tfm *tfm) +{ +return sa_sham_cra_init_alg (tfm,"sha256" ); +} +static void sa_sham_cra_exit (struct crypto_tfm *tfm) {struct crypto_alg *alg = tfm->__crt_alg;
@@ -1839,6 +1866,31 @@ static struct ahash_alg algs_sha[] = { .cra_exit = sa_sham_cra_exit, } }, +{ + .init = sa_sham_init, + .update = sa_sham_update, + .final = sa_sham_final, + .finup = sa_sham_finup, + .digest = sa_sham_digest, + .setkey = sa_sham_sha256_setkey, + .halg.digestsize = SHA256_DIGEST_SIZE, + .halg.statesize = 128, + .halg.base = { + .cra_name = "hmac(sha256)", + .cra_driver_name = "sa-hmac-sha256", + .cra_priority = 400, + .cra_flags =CRYPTO_ALG_TYPE_AHASH | +CRYPTO_ALG_ASYNC | +CRYPTO_ALG_KERN_DRIVER_ONLY | + CRYPTO_ALG_NEED_FALLBACK, + .cra_blocksize = SHA256_BLOCK_SIZE, + .cra_ctxsize = sizeof(struct sa_tfm_ctx), + .cra_alignmask = SA_ALIGN_MASK, + .cra_module = THIS_MODULE, + .cra_init = sa_sham_cra_sha256_init, + .cra_exit = sa_sham_cra_exit, + } +}, };/* Register the algorithms in crypto framework */
Signature · 1 line
2.17.1
PATCH RESEND 9/10 sa2ul: Add 3DES ECB & CBC Mode support
In reply to KeerthyTriple DES (3DES), officially the Triple Data Encryption Algorithm (TDEA or Triple DEA), is a symmetric-key block cipher, which applies the DES cipher algorithm three times to each data block
Add 3DES ECB(Electronic code book) & CBC(Cipher Block Chaining) Mode support.
--- drivers/crypto/sa2ul.c | 112 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+)
drivers/crypto/sa2ul.c +112 -0
@@ -210,6 +210,35 @@ static u8 mci_ecb_dec_array[3][27] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, }; +/* +* Mode Control Instructions for DES algorithm +* For CBC (Cipher Block Chaining) mode and ECB mode +* encryption and for decryption respectively +*/ +static u8 mci_cbc_3des_enc_array[MODE_CONTROL_BYTES ] = { +0x20 ,0x00 ,0x00 ,0x18 ,0x88 ,0x52 ,0xaa ,0x4b ,0x7e ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 , +}; + +static u8 mci_cbc_3des_dec_array[MODE_CONTROL_BYTES ] = { +0x30 ,0x00 ,0x00 ,0x85 ,0x0a ,0xca ,0x98 ,0xf4 ,0x40 ,0xc0 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 , +}; + +static u8 mci_ecb_3des_enc_array[MODE_CONTROL_BYTES ] = { +0x20 ,0x00 ,0x00 ,0x85 ,0x0a ,0x04 ,0xb7 ,0x90 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 , +}; + +static u8 mci_ecb_3des_dec_array[MODE_CONTROL_BYTES ] = { +0x30 ,0x00 ,0x00 ,0x85 ,0x0a ,0x04 ,0xb7 ,0x90 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 , +}; +/* * Perform 16 byte or 128 bit swizzling * The SA2UL Expects the security context to
@@ -877,6 +906,39 @@ static int sa_aes_ecb_setkey(struct crypto_ablkcipher *tfm, const u8 *key,return sa_aes_setkey (tfm, key, keylen, ad); } +static int sa_3des_cbc_setkey (struct crypto_ablkcipher *tfm,const u8 *key, +unsigned int keylen) +{ +struct algo_data *ad =kzalloc (sizeof (*ad),GFP_KERNEL ); + + ad->enc_eng.eng_id =SA_ENG_ID_EM1 ; + ad->enc_eng.sc_size =SA_CTX_ENC_TYPE1_SZ ; + ad->auth_eng.eng_id =SA_ENG_ID_NONE ; + ad->auth_eng.sc_size =0 ; + ad->mci_enc = mci_cbc_3des_enc_array; + ad->mci_dec = mci_cbc_3des_dec_array; + ad->ealg_id =SA_EALG_ID_3DES_CBC ; + ad->aalg_id =SA_AALG_ID_NONE ; + +return sa_aes_setkey (tfm, key, keylen, ad); +} + +static int sa_3des_ecb_setkey (struct crypto_ablkcipher *tfm,const u8 *key, +unsigned int keylen) +{ +struct algo_data *ad =kzalloc (sizeof (*ad),GFP_KERNEL ); + + ad->enc_eng.eng_id =SA_ENG_ID_EM1 ; + ad->enc_eng.sc_size =SA_CTX_ENC_TYPE1_SZ ; + ad->auth_eng.eng_id =SA_ENG_ID_NONE ; + ad->auth_eng.sc_size =0 ; + ad->mci_enc = mci_ecb_3des_enc_array; + ad->mci_dec = mci_ecb_3des_dec_array; + ad->aalg_id =SA_AALG_ID_NONE ; + +return sa_aes_setkey (tfm, key, keylen, ad); +} +static void sa_aes_dma_in_callback (void *data) {struct sa_rx_data *rxd = (struct sa_rx_data *)data;
@@ -1787,6 +1849,56 @@ static struct sa_alg_tmpl sa_algs[] = { } } }, + { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, + .alg.crypto = { + .cra_name = "cbc(des3_ede)", + .cra_driver_name = "cbc-des3-sa2ul", + .cra_priority = 30000, + .cra_flags =CRYPTO_ALG_TYPE_ABLKCIPHER | +CRYPTO_ALG_KERN_DRIVER_ONLY | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK, + .cra_blocksize = DES_BLOCK_SIZE, + .cra_ctxsize = sizeof(struct sa_tfm_ctx), + .cra_alignmask = 0, + .cra_type = &crypto_ablkcipher_type, + .cra_module = THIS_MODULE, + .cra_init = sa_aes_cra_init, + .cra_exit = sa_aes_cra_exit, + .cra_u.ablkcipher = { + .min_keysize = 3 * DES_KEY_SIZE, + .max_keysize = 3 * DES_KEY_SIZE, + .ivsize = DES_BLOCK_SIZE, + .setkey = sa_3des_cbc_setkey, + .encrypt = sa_aes_cbc_encrypt, + .decrypt = sa_aes_cbc_decrypt, + } + } + }, + { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, + .alg.crypto = { + .cra_name = "ecb(des3_ede)", + .cra_driver_name = "ecb-des3-sa2ul", + .cra_priority = 30000, + .cra_flags =CRYPTO_ALG_TYPE_ABLKCIPHER | +CRYPTO_ALG_KERN_DRIVER_ONLY | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK, + .cra_blocksize = DES_BLOCK_SIZE, + .cra_ctxsize = sizeof(struct sa_tfm_ctx), + .cra_alignmask = 0, + .cra_type = &crypto_ablkcipher_type, + .cra_module = THIS_MODULE, + .cra_init = sa_aes_cra_init, + .cra_exit = sa_aes_cra_exit, + .cra_u.ablkcipher = { + .min_keysize = 3 * DES_KEY_SIZE, + .max_keysize = 3 * DES_KEY_SIZE, + .ivsize = DES_BLOCK_SIZE, + .setkey = sa_3des_ecb_setkey, + .encrypt = sa_aes_cbc_encrypt, + .decrypt = sa_aes_cbc_decrypt, + } + } + }, /* AEAD algorithms */ {.type = CRYPTO_ALG_TYPE_AEAD, .alg.aead = {
Signature · 1 line
2.17.1
PATCH RESEND 10/10 arm64: dts: k3-am6: Add crypto accelarator node
In reply to KeerthyAdd crypto accelarator node. Define the psil specific config node as well. This can be used in Packet Mode alone.
--- arch/arm64/boot/dts/ti/k3-am65-main.dtsi | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
arch/arm64/boot/dts/ti/k3-am65-main.dtsi +33 -0
@@ -91,6 +91,39 @@ power-domains = <&k3_pds 148>; }; + crypto: crypto@4E00000 { + compatible = "ti,sa2ul-crypto"; + label = "crypto-aes-gbe"; + reg = <0x0 0x4E00000 0x0 0x1200>; + + status = "okay"; + ti,psil-base = <0x4000>; + + /* tx: crypto_pnp-1, rx: crypto_pnp-1 */ + dmas = <&main_udmap &crypto 0 UDMA_DIR_TX>, + <&main_udmap &crypto 0 UDMA_DIR_RX>, + <&main_udmap &crypto 1 UDMA_DIR_RX>; + dma-names = "tx", "rx1", "rx2"; + + ti,psil-config0 { + linux,udma-mode = <UDMA_PKT_MODE>; + ti,needs-epib; + ti,psd-size = <64>; + }; + + ti,psil-config1 { + linux,udma-mode = <UDMA_PKT_MODE>; + ti,needs-epib; + ti,psd-size = <64>; + }; + + ti,psil-config2 { + linux,udma-mode = <UDMA_PKT_MODE>; + ti,needs-epib; + ti,psd-size = <64>; + }; + }; + main_pmx0: pinmux@11c000 { compatible = "pinctrl-single"; reg = <0x0 0x11c000 0x0 0x2e4>;
Signature · 1 line
2.17.1
Hi Keerthy,
Quoted 35 lines · Keerthy
The series adds Crypto hardware accelerator support for SA2UL. SA2UL stands for security accelerator ultra lite.
The Security Accelerator (
SA2_UL) subsystem provides hardware cryptographic acceleration for the following use cases:
• Encryption and authentication for secure boot
• Encryption and authentication of content in applications requiring DRM (digital rights management) and content/asset protection
The device includes one instantiation ofSA2_ULnamedSA2_UL0SA2UL needs on tx channel and a pair of rx dma channels.
This series has dependency on UDMA series. Hence is based on top of:
https://patchwork.kernel.org/project/linux-dmaengine/list/?series=114105
The above series adds couple of dmaengine APIs that are used by the sa2ul driver. Hence there is a hard dependency on the above series.
Resending with linux-crypto list in Cc.
Keerthy (10):
dt-bindings: crypto: k3: Add sa2ul bindings documentation
crypto: sa2ul: Add crypto driver
crypto: sa2ul: Add AES ECB Mode support
crypto: sa2ul: Add aead support for hmac(sha1)cbc(aes) algorithm
crypto:sha256_generic: Export the Transform function
crypto: sa2ul: Add hmac(sha256)cbc(aes) AEAD Algo support
crypto: sa2ul: Add hmac(sha1) HMAC algorithm support
crypto: sa2ul: Add hmac(sha256) HMAC algorithm support
sa2ul: Add 3DES ECB & CBC Mode support
arm64: dts: k3-am6: Add crypto accelarator node
Quoted 12 lines
.../devicetree/bindings/crypto/sa2ul.txt | 47 + arch/arm64/boot/dts/ti/k3-am65-main.dtsi | 33 + crypto/sha256_generic.c | 3 +- drivers/crypto/Kconfig | 17 + drivers/crypto/Makefile | 1 + drivers/crypto/sa2ul.c | 2232 +++++++++++++++++ drivers/crypto/sa2ul.h | 384 +++ include/crypto/sha.h | 1 + 8 files changed, 2717 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/crypto/sa2ul.txt create mode 100644 drivers/crypto/sa2ul.c create mode 100644 drivers/crypto/sa2ul.h
Did you run the crypto self-tests on this driver? i.e. boot a kernel with
# CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is not set CONFIG_DEBUG_KERNEL=y CONFIG_CRYPTO_MANAGER_EXTRA_TESTS=y
What are the results?
Also, this patchset does not compile for me.
Error: arch/arm64/boot/dts/ti/k3-am65-main.dtsi:103.33-34 syntax error
FATAL ERROR: Unable to parse input tree
DTC arch/arm64/boot/dts/nvidia/tegra210-p2571.dtb
make[2]: *** [scripts/Makefile.lib:294: arch/arm64/boot/dts/ti/k3-am654-base-board.dtb] Error 1 make[1]: *** [scripts/Makefile.build:489: arch/arm64/boot/dts/ti] Error 2 make[1]: *** Waiting for unfinished jobs....
- Eric
Re: [RESEND PATCH 02/10] crypto: sa2ul: Add crypto driver
In reply to KeerthyQuoted 18 lines · Keerthy
The Security Accelerator (
SA2_UL) subsystem provides hardware cryptographic acceleration for the following use cases:
• Encryption and authentication for secure boot
• Encryption and authentication of content in applications requiring DRM (digital rights management) and content/asset protection
The device includes one instantiation ofSA2_ULnamedSA2_UL0
SA2_ULsupports the following cryptographic industry standards to enable data authentication, data integrity and data confidentiality.Crypto function library for software acceleration
o AES operation
o 3DES operation
o SHA1 operation
o MD5 operation
o SHA2 – 224, 256, 384, 512 operation
Quoted 7 lines
Authentication supported via following hardware cores
o SHA1
o MD5
o SHA2 -224
o SHA2-256
o SHA2-384
o SHA2-512
What about HMAC?
Your actual driver only exposes HMAC-SHA*, not SHA* anything.
What does the hardware actually support?
Quoted 14 lines
drivers/crypto/Kconfig +6
-0@@ -785,4 +785,21 @@ config CRYPTO_DEV_CCREE source "drivers/crypto/hisilicon/Kconfig" +config CRYPTO_DEV_SA2UL + tristate "Support for TI security accelerator" + depends on ARCH_K3 || COMPILE_TEST + select ARM64_CRYPTO + select CRYPTO_AES + select CRYPTO_AES_ARM64
drivers/crypto/Kconfig config CRYPTO_DEV_CCREE · line 803
Quoted 10 lines
drivers/crypto/Kconfig +10
-0+ select CRYPTO_SHA1 + select CRYPTO_MD5 + select CRYPTO_ALGAPI + select CRYPTO_AUTHENC + select HW_RANDOM + default m if ARCH_K3 + help + Keystone devices include a security accelerator engine that may be + used for crypto offload. Select this if you want to use hardware + acceleration for cryptographic algorithms on these devices.
This shouldn't be enabled by default. Note that arm64 defconfig sets ARCH_K3 as well as lots of other ARCH_* options, so clearly just because ARCH_K3 is set doesn't mean the kernel is being built specifically for your platform.
Quoted 5 lines
drivers/crypto/Kconfig +5
-0+/* + * Mode Control Instructions for various Key lengths 128, 192, 256 + * For CBC (Cipher Block Chaining) mode for encryption + */ +static u8 mci_cbc_enc_array[3][MODE_CONTROL_BYTES] = {
drivers/crypto/Kconfig config CRYPTO_DEV_CCREE
Quoted 10 lines
drivers/crypto/Kconfig +10
-0+ { 0x21, 0x00, 0x00, 0x18, 0x88, 0x0a, 0xaa, 0x4b, 0x7e, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x21, 0x00, 0x00, 0x18, 0x88, 0x4a, 0xaa, 0x4b, 0x7e, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x21, 0x00, 0x00, 0x18, 0x88, 0x8a, 0xaa, 0x4b, 0x7e, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, +};
Use 'const' for static constants.
drivers/crypto/Kconfig
Quoted 4 lines
drivers/crypto/Kconfig +4
-0+static int sa_aes_cbc_setkey(struct crypto_ablkcipher *tfm, const u8 *key, + unsigned int keylen) +{ + struct algo_data *ad = kzalloc(sizeof(*ad), GFP_KERNEL);
Need to check from error for all memory allocations.
drivers/crypto/Kconfig
Quoted 2 lines
drivers/crypto/Kconfig +2
-0+static struct sa_alg_tmpl sa_algs[] = { + {.type = CRYPTO_ALG_TYPE_ABLKCIPHER,
ablkcipher API is deprecated. Use skcipher instead.
(To be clear, these are just a few things I happened to notice from very quickly skimming through this patch. I don't have time to do a proper review of random drivers.)
- Eric
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [RESEND PATCH 05/10] crypto: sha256_generic: Export the Transform function
In reply to KeerthyQuoted 3 lines · Keerthy
The transform function can be used as is by other crypto drivers that need to transform the 256 bit key using cpu. Hence export it.
What is this supposed to mean? SHA-256 is an unkeyed hash function.
Also, you need to actually explain why this is needed. If your hardware supports SHA-256, why do you need to use the C sha256_transform()?
- Eric
Re: [RESEND PATCH 06/10] crypto: sa2ul: Add hmac(sha256)cbc(aes) AEAD Algo support
In reply to KeerthyQuoted 18 lines · Keerthy
Add aead support for hmac(sha256)cbc(aes) algorithm. Authenticated encryption (AE) and authenticated encryption with associated data (AEAD) is a form of encryption which simultaneously provides confidentiality, integrity, and authenticity assurances on the data.
hmac(sha256) has a digest size of 32 bytes is used for authetication and AES in CBC mode is used in conjunction for encryption/decryption.
Signed-off-by Keerthy <[email protected]>--- drivers/crypto/sa2ul.c | 92 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+)drivers/crypto/sa2ul.c +0
-0
drivers/crypto/sa2ul.c void sa_hmac_sha1_get_pad(const u8 *key, u16 key_sz, u32 *ipad, u32 *opad) · line 274
Quoted 4 lines
drivers/crypto/sa2ul.c +1
-0@@ -271,6 +271,42 @@ void sa_hmac_sha1_get_pad(const u8 *key, u16 key_sz, u32 *ipad, u32 *opad) opad[i] =cpu_to_be32 (opad[i]); } +void sha256_init (u32 *buf)
This needs to be static.
drivers/crypto/sa2ul.c static int sa_aead_cbc_sha1_setkey(struct crypto_aead *authenc, · line 1249
Quoted 13 lines
drivers/crypto/sa2ul.c +13
-0+static int sa_aead_cbc_sha256_setkey (struct crypto_aead *authenc, +const u8 *key,unsigned int keylen) +{ +struct algo_data *ad =kzalloc (sizeof (*ad),GFP_KERNEL ); +struct crypto_authenc_keys keys; +int ret =0 , key_idx; + + ret =crypto_authenc_extractkeys (&keys, key, keylen); +if (ret) +return ret; + +/* Convert the key size (16/24/32) to the key size index (0/1/2) */ + key_idx = (keys.enckeylen >>3 ) -2 ;
Where do you validate the key length?
- Eric
Re: [RESEND PATCH 07/10] crypto: sa2ul: Add hmac(sha1) HMAC algorithm support
In reply to KeerthyQuoted 4 lines · Keerthy
drivers/crypto/sa2ul.c +4
-0+static int sa_sham_update (struct ahash_request *req) +{ +return -ENOTSUPP ; +}
drivers/crypto/sa2ul.c static int sa_aead_decrypt(struct aead_request *req) · line 1710
Quoted 10 lines
drivers/crypto/sa2ul.c +10
-0+ +static int sa_sham_final (struct ahash_request *req) +{ +return sa_sham_digest (req); +} + +static int sa_sham_finup (struct ahash_request *req) +{ +return sa_sham_digest (req); +}
You can't just not support update(). You need to support update().
- Eric
Quoted 51 lines · Eric Biggers
Hi Keerthy,
Quoted 44 lines · Keerthy
The series adds Crypto hardware accelerator support for SA2UL. SA2UL stands for security accelerator ultra lite.
The Security Accelerator (
SA2_UL) subsystem provides hardware cryptographic acceleration for the following use cases:
• Encryption and authentication for secure boot
• Encryption and authentication of content in applications requiring DRM (digital rights management) and content/asset protection
The device includes one instantiation ofSA2_ULnamedSA2_UL0SA2UL needs on tx channel and a pair of rx dma channels.
This series has dependency on UDMA series. Hence is based on top of:
https://patchwork.kernel.org/project/linux-dmaengine/list/?series=114105
The above series adds couple of dmaengine APIs that are used by the sa2ul driver. Hence there is a hard dependency on the above series.
Resending with linux-crypto list in Cc.
Keerthy (10):
dt-bindings: crypto: k3: Add sa2ul bindings documentation
crypto: sa2ul: Add crypto driver
crypto: sa2ul: Add AES ECB Mode support
crypto: sa2ul: Add aead support for hmac(sha1)cbc(aes) algorithm
crypto:sha256_generic: Export the Transform function
crypto: sa2ul: Add hmac(sha256)cbc(aes) AEAD Algo support
crypto: sa2ul: Add hmac(sha1) HMAC algorithm support
crypto: sa2ul: Add hmac(sha256) HMAC algorithm support
sa2ul: Add 3DES ECB & CBC Mode support
arm64: dts: k3-am6: Add crypto accelarator node.../devicetree/bindings/crypto/sa2ul.txt | 47 + arch/arm64/boot/dts/ti/k3-am65-main.dtsi | 33 + crypto/sha256_generic.c | 3 +- drivers/crypto/Kconfig | 17 + drivers/crypto/Makefile | 1 + drivers/crypto/sa2ul.c | 2232 +++++++++++++++++ drivers/crypto/sa2ul.h | 384 +++ include/crypto/sha.h | 1 + 8 files changed, 2717 insertions(+), 1 deletion(-)Quoted 3 lines
create mode 100644
Documentation/devicetree/bindings/crypto/sa2ul.txtcreate mode 100644drivers/crypto/sa2ul.c
create mode 100644drivers/crypto/sa2ul.h
Quoted 7 lines
Did you run the crypto self-tests on this driver? i.e. boot a kernel with
#
CONFIG_CRYPTO_MANAGER_DISABLE_TESTSis not setCONFIG_DEBUG_KERNEL=yCONFIG_CRYPTO_MANAGER_EXTRA_TESTS=yWhat are the results?
Eric,
Thanks for your response. I did try with that. All test cases were passing on 4.19 kernel before the testmgr revamp.
Currently few of the test cases do fail. For ex: Appending the last ivlen bytes of cipher text as the IV.
Quoted 2 lines
Also, this patchset does not compile for me.
This has dependency on UDMA series: https://patchwork.kernel.org/cover/10930969/
Quoted 10 lines
Error: arch/arm64/boot/dts/ti/k3-am65-main.dtsi:103.33-34 syntax error
FATAL ERROR: Unable to parse input tree
DTCarch/arm64/boot/dts/nvidia/tegra210-p2571.dtb
make[2]: *** [scripts/Makefile.lib:294:arch/arm64/boot/dts/ti/k3-am654-base-board.dtb] Error 1 make[1]: *** [scripts/Makefile.build:489:arch/arm64/boot/dts/ti] Error 2 make[1]: *** Waiting for unfinished jobs....- Eric
Re: [RESEND PATCH 02/10] crypto: sa2ul: Add crypto driver
In reply to Eric BiggersQuoted 27 lines · Eric Biggers
Quoted 18 lines · Keerthy
The Security Accelerator (
SA2_UL) subsystem provides hardware cryptographic acceleration for the following use cases:
• Encryption and authentication for secure boot
• Encryption and authentication of content in applications requiring DRM (digital rights management) and content/asset protection
The device includes one instantiation ofSA2_ULnamedSA2_UL0
SA2_ULsupports the following cryptographic industry standards to enable data authentication, data integrity and data confidentiality.Crypto function library for software acceleration
o AES operation
o 3DES operation
o SHA1 operation
o MD5 operation
o SHA2 – 224, 256, 384, 512 operationQuoted 7 lines
Authentication supported via following hardware cores
o SHA1
o MD5
o SHA2 -224
o SHA2-256
o SHA2-384
o SHA2-512
Quoted 5 lines
What about HMAC?
Your actual driver only exposes HMAC-SHA*, not SHA* anything.
What does the hardware actually support?
Hardware supports both SHA and HMAC-SHA
Quoted 21 lines
Quoted 21 lines
drivers/crypto/Kconfig +12
-0@@ -785,4 +785,21 @@ config CRYPTO_DEV_CCREE source "drivers/crypto/hisilicon/Kconfig" +config CRYPTO_DEV_SA2UL + tristate "Support for TI security accelerator" + depends on ARCH_K3 || COMPILE_TEST + select ARM64_CRYPTO + select CRYPTO_AES + select CRYPTO_AES_ARM64 + select CRYPTO_SHA1 + select CRYPTO_MD5 + select CRYPTO_ALGAPI + select CRYPTO_AUTHENC + select HW_RANDOM + default m if ARCH_K3
Quoted 8 lines
drivers/crypto/Kconfig config CRYPTO_DEV_CCREE · line 803
Quoted 4 lines
drivers/crypto/Kconfig +4
-0+ help + Keystone devices include a security accelerator engine that may be + used for crypto offload. Select this if you want to use hardware + acceleration for cryptographic algorithms on these devices.This shouldn't be enabled by default. Note that arm64 defconfig sets
ARCH_K3as well as lots of other ARCH_* options, so clearly just becauseARCH_K3is set doesn't mean the kernel is being built specifically for your platform.
okay. I will remove that.
Quoted 10 lines
Quoted 10 lines
drivers/crypto/Kconfig +9
-0+/* + * Mode Control Instructions for various Key lengths 128, 192, 256 + * For CBC (Cipher Block Chaining) mode for encryption + */ +static u8 mci_cbc_enc_array[3][MODE_CONTROL_BYTES] = { + { 0x21, 0x00, 0x00, 0x18, 0x88, 0x0a, 0xaa, 0x4b, 0x7e, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x21, 0x00, 0x00, 0x18, 0x88, 0x4a, 0xaa, 0x4b, 0x7e, 0x00,
Quoted 8 lines
drivers/crypto/Kconfig
Quoted 6 lines
drivers/crypto/Kconfig +6
-0+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x21, 0x00, 0x00, 0x18, 0x88, 0x8a, 0xaa, 0x4b, 0x7e, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, +};Use 'const' for static constants.
Okay
Quoted 8 lines
drivers/crypto/Kconfig
Quoted 5 lines
drivers/crypto/Kconfig +4
-0+static int sa_aes_cbc_setkey(struct crypto_ablkcipher *tfm, const u8 *key, + unsigned int keylen) +{ + struct algo_data *ad = kzalloc(sizeof(*ad), GFP_KERNEL);Need to check from error for all memory allocations.
Quoted 4 lines
drivers/crypto/Kconfig
Quoted 2 lines
drivers/crypto/Kconfig +2
-0+static struct sa_alg_tmpl sa_algs[] = { + {.type = CRYPTO_ALG_TYPE_ABLKCIPHER,ablkcipher API is deprecated. Use skcipher instead.
Okay
Quoted 4 lines
(To be clear, these are just a few things I happened to notice from very quickly skimming through this patch. I don't have time to do a proper review of random drivers.)
I will incorporate the comments in v2.
Thanks for your quick review.
Quoted 3 lines
- Eric
Quoted 60 lines · keerthy
Quoted 57 lines · Eric Biggers
Hi Keerthy,
Quoted 44 lines · Keerthy
The series adds Crypto hardware accelerator support for SA2UL. SA2UL stands for security accelerator ultra lite.
The Security Accelerator (
SA2_UL) subsystem provides hardware cryptographic acceleration for the following use cases:
• Encryption and authentication for secure boot
• Encryption and authentication of content in applications requiring DRM (digital rights management) and content/asset protection
The device includes one instantiation ofSA2_ULnamedSA2_UL0SA2UL needs on tx channel and a pair of rx dma channels.
This series has dependency on UDMA series. Hence is based on top of:
https://patchwork.kernel.org/project/linux-dmaengine/list/?series=114105
The above series adds couple of dmaengine APIs that are used by the sa2ul driver. Hence there is a hard dependency on the above series.
Resending with linux-crypto list in Cc.
Keerthy (10):
dt-bindings: crypto: k3: Add sa2ul bindings documentation
crypto: sa2ul: Add crypto driver
crypto: sa2ul: Add AES ECB Mode support
crypto: sa2ul: Add aead support for hmac(sha1)cbc(aes) algorithm
crypto:sha256_generic: Export the Transform function
crypto: sa2ul: Add hmac(sha256)cbc(aes) AEAD Algo support
crypto: sa2ul: Add hmac(sha1) HMAC algorithm support
crypto: sa2ul: Add hmac(sha256) HMAC algorithm support
sa2ul: Add 3DES ECB & CBC Mode support
arm64: dts: k3-am6: Add crypto accelarator node.../devicetree/bindings/crypto/sa2ul.txt | 47 + arch/arm64/boot/dts/ti/k3-am65-main.dtsi | 33 + crypto/sha256_generic.c | 3 +- drivers/crypto/Kconfig | 17 + drivers/crypto/Makefile | 1 + drivers/crypto/sa2ul.c | 2232 +++++++++++++++++ drivers/crypto/sa2ul.h | 384 +++ include/crypto/sha.h | 1 + 8 files changed, 2717 insertions(+), 1 deletion(-)Quoted 3 lines
create mode 100644
Documentation/devicetree/bindings/crypto/sa2ul.txtcreate mode 100644drivers/crypto/sa2ul.c
create mode 100644drivers/crypto/sa2ul.hDid you run the crypto self-tests on this driver? i.e. boot a kernel with
#
CONFIG_CRYPTO_MANAGER_DISABLE_TESTSis not setCONFIG_DEBUG_KERNEL=yCONFIG_CRYPTO_MANAGER_EXTRA_TESTS=y
Quoted 7 lines
Quoted 1 line
What are the results?
Eric,
Thanks for your response. I did try with that. All test cases were passing on 4.19 kernel before the testmgr revamp.
That's surprising, since your driver doesn't implement update() for hashing, so it should have been failing at least the HMAC tests. Are you sure you really ran the tests?
Quoted 2 lines
Currently few of the test cases do fail. For ex: Appending the last ivlen bytes of cipher text as the IV.
Well, these need to be fixed.
Quoted 6 lines
Quoted 3 lines
Also, this patchset does not compile for me.
This has dependency on UDMA series:
https://patchwork.kernel.org/cover/10930969/
I had that applied.
- Eric
Re: [RESEND PATCH 05/10] crypto: sha256_generic: Export the Transform function
In reply to Eric BiggersQuoted 6 lines · Eric Biggers
Quoted 3 lines · Keerthy
The transform function can be used as is by other crypto drivers that need to transform the 256 bit key using cpu. Hence export it.
What is this supposed to mean? SHA-256 is an unkeyed hash function.
HMAC-SHA256 my bad.
Quoted 3 lines
Also, you need to actually explain why this is needed. If your hardware supports SHA-256, why do you need to use the C
sha256_transform()?
Hardware supports only HMAC from pre-computed inner and outer digests is supported, i.e. the host must carry out initial preparation stage to generate intermediate hash state for both inner pad and outer pad.
Hence the need to export the transform function. I will add it in the commit message.
Quoted 3 lines
- Eric
Quoted 65 lines · Eric Biggers
Quoted 64 lines · keerthy
Quoted 51 lines · Eric Biggers
Hi Keerthy,
Quoted 44 lines · Keerthy
The series adds Crypto hardware accelerator support for SA2UL. SA2UL stands for security accelerator ultra lite.
The Security Accelerator (
SA2_UL) subsystem provides hardware cryptographic acceleration for the following use cases:
• Encryption and authentication for secure boot
• Encryption and authentication of content in applications requiring DRM (digital rights management) and content/asset protection
The device includes one instantiation ofSA2_ULnamedSA2_UL0SA2UL needs on tx channel and a pair of rx dma channels.
This series has dependency on UDMA series. Hence is based on top of:
https://patchwork.kernel.org/project/linux-dmaengine/list/?series=114105
The above series adds couple of dmaengine APIs that are used by the sa2ul driver. Hence there is a hard dependency on the above series.
Resending with linux-crypto list in Cc.
Keerthy (10):
dt-bindings: crypto: k3: Add sa2ul bindings documentation
crypto: sa2ul: Add crypto driver
crypto: sa2ul: Add AES ECB Mode support
crypto: sa2ul: Add aead support for hmac(sha1)cbc(aes) algorithm
crypto:sha256_generic: Export the Transform function
crypto: sa2ul: Add hmac(sha256)cbc(aes) AEAD Algo support
crypto: sa2ul: Add hmac(sha1) HMAC algorithm support
crypto: sa2ul: Add hmac(sha256) HMAC algorithm support
sa2ul: Add 3DES ECB & CBC Mode support
arm64: dts: k3-am6: Add crypto accelarator node.../devicetree/bindings/crypto/sa2ul.txt | 47 + arch/arm64/boot/dts/ti/k3-am65-main.dtsi | 33 + crypto/sha256_generic.c | 3 +- drivers/crypto/Kconfig | 17 + drivers/crypto/Makefile | 1 + drivers/crypto/sa2ul.c | 2232 +++++++++++++++++ drivers/crypto/sa2ul.h | 384 +++ include/crypto/sha.h | 1 + 8 files changed, 2717 insertions(+), 1 deletion(-)Quoted 3 lines
create mode 100644
Documentation/devicetree/bindings/crypto/sa2ul.txtcreate mode 100644drivers/crypto/sa2ul.c
create mode 100644drivers/crypto/sa2ul.hQuoted 7 lines
Did you run the crypto self-tests on this driver? i.e. boot a kernel with
#
CONFIG_CRYPTO_MANAGER_DISABLE_TESTSis not setCONFIG_DEBUG_KERNEL=yCONFIG_CRYPTO_MANAGER_EXTRA_TESTS=yWhat are the results?
Eric,
Quoted 7 lines
Quoted 3 lines
Thanks for your response. I did try with that. All test cases were passing on 4.19 kernel before the testmgr revamp.
That's surprising, since your driver doesn't implement
update()for hashing, so it should have been failing at least the HMAC tests. Are you sure you really ran the tests?
Yes partial update was the failing case.
Quoted 5 lines
Quoted 3 lines
Currently few of the test cases do fail. For ex: Appending the last ivlen bytes of cipher text as the IV.
Well, these need to be fixed.
Okay. So passing all the crypto manager test cases seems to be the prerequisite. I will work on them.
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Also, this patchset does not compile for me.
This has dependency on UDMA series:
https://patchwork.kernel.org/cover/10930969/I had that applied.
Okay. I will check if there were additional patches that were needed.
Thanks,
Keerthy
Quoted 3 lines
- Eric
Re: [RESEND PATCH 07/10] crypto: sa2ul: Add hmac(sha1) HMAC algorithm support
In reply to Eric BiggersQuoted 17 lines · Eric Biggers
Quoted 4 lines · Keerthy
drivers/crypto/sa2ul.c +4
-0+static int sa_sham_update (struct ahash_request *req) +{ +return -ENOTSUPP ; +}drivers/crypto/sa2ul.c static int sa_aead_decrypt(struct aead_request *req) · line 1710
Quoted 10 lines
drivers/crypto/sa2ul.c +10
-0+ +static int sa_sham_final (struct ahash_request *req) +{ +return sa_sham_digest (req); +} + +static int sa_sham_finup (struct ahash_request *req) +{ +return sa_sham_digest (req); +}You can't just not support
update(). You need to supportupdate().
Okay. I will add that.
Quoted 3 lines
- Eric
Rob Herring
maintainerRe: [RESEND PATCH 01/10] dt-bindings: crypto: k3: Add sa2ul bindings documentation
In reply to KeerthyQuoted 25 lines · Keerthy
The series adds Crypto hardware accelerator support for SA2UL. SA2UL stands for security accelerator ultra lite.
The Security Accelerator (
SA2_UL) subsystem provides hardware cryptographic acceleration for the following use cases:
• Encryption and authentication for secure boot
• Encryption and authentication of content in applications requiring DRM (digital rights management) and content/asset protection
The device includes one instantiation ofSA2_ULnamedSA2_UL0SA2UL needs on tx channel and a pair of rx dma channels.
Signed-off-by Keerthy <[email protected]>--- .../devicetree/bindings/crypto/sa2ul.txt | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/sa2ul.txtDocumentation/devicetree/bindings/crypto/sa2ul.txt new file +0
-0
Documentation/devicetree/bindings/crypto/sa2ul.txt line 6
Quoted 6 lines
Documentation/devicetree/bindings/crypto/sa2ul.txt new file +6
-0@@ -0,0 +1,47 @@ +K3 SoC SA2UL crypto module + +Required properties: + +- compatible : Should be: + - "ti,sa2ul-crypto"
Needs to be SoC specific.
Documentation/devicetree/bindings/crypto/sa2ul.txt line 17
Quoted 11 lines
Documentation/devicetree/bindings/crypto/sa2ul.txt new file +11
-0+- reg : Offset and length of the register set for the module + +- dmas: DMA specifiers for tx and rx dma. sa2ul needs one tx channel + and 2 rx channels. First rx channel for < 256 bytes and + the other one for >=256 bytes. See the DMA client binding, + Documentation/devicetree/bindings/dma/dma.txt +- dma-names: DMA request names has to have one tx and 2 rx names + corresponding to dmas abive. +- ti,psil-config* - UDMA PSIL native Peripheral using packet mode. + SA2UL must have EPIB(Extended protocal information block) + and PSDATA(protocol specific data) properties.
If ti,needs-epib is required, then why do you need to specify it in DT? In any case, this all seems like channel config info that should be part of the #dma-cells.
Also, don't use vendor prefixes on node names.
Quoted 33 lines
Documentation/devicetree/bindings/crypto/sa2ul.txt new file +30
-0+ +Example AM654 SA2UL: +crypto: crypto@4E00000 { + compatible = "ti,sa2ul-crypto"; + reg = <0x0 0x4E00000 0x0 0x1200>; + ti,psil-base = <0x4000>; + + dmas = <&main_udmap &crypto 0 UDMA_DIR_TX>, + <&main_udmap &crypto 0 UDMA_DIR_RX>, + <&main_udmap &crypto 1 UDMA_DIR_RX>; + dma-names = "tx", "rx1", "rx2"; + + ti,psil-config0 { + linux,udma-mode = <UDMA_PKT_MODE>; + ti,needs-epib; + ti,psd-size = <64>; + }; + + ti,psil-config1 { + linux,udma-mode = <UDMA_PKT_MODE>; + ti,needs-epib; + ti,psd-size = <64>; + }; + + ti,psil-config2 { + linux,udma-mode = <UDMA_PKT_MODE>; + ti,needs-epib; + ti,psd-size = <64>; + }; +};Signature · 1 line
2.17.1
Re: [RESEND PATCH 01/10] dt-bindings: crypto: k3: Add sa2ul bindings documentation
Quoted 20 lines · Rob Herring
Quoted 19 lines · Keerthy
The series adds Crypto hardware accelerator support for SA2UL. SA2UL stands for security accelerator ultra lite.
The Security Accelerator (
SA2_UL) subsystem provides hardware cryptographic acceleration for the following use cases:
• Encryption and authentication for secure boot
• Encryption and authentication of content in applications requiring DRM (digital rights management) and content/asset protection
The device includes one instantiation ofSA2_ULnamedSA2_UL0SA2UL needs on tx channel and a pair of rx dma channels.
Signed-off-by Keerthy <[email protected]>--- .../devicetree/bindings/crypto/sa2ul.txt | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+)create mode 100644
Documentation/devicetree/bindings/crypto/sa2ul.txt
Quoted 14 lines
Documentation/devicetree/bindings/crypto/sa2ul.txt line 6
Quoted 12 lines
Documentation/devicetree/bindings/crypto/sa2ul.txt new file +6
-0@@ -0,0 +1,47 @@ +K3 SoC SA2UL crypto module + +Required properties: + +- compatible : Should be: + - "ti,sa2ul-crypto"Needs to be SoC specific.
okay
Quoted 16 lines
Documentation/devicetree/bindings/crypto/sa2ul.txt line 17
Quoted 12 lines
Documentation/devicetree/bindings/crypto/sa2ul.txt new file +11
-0+- reg : Offset and length of the register set for the module + +- dmas: DMA specifiers for tx and rx dma. sa2ul needs one tx channel + and 2 rx channels. First rx channel for < 256 bytes and + the other one for >=256 bytes. See the DMA client binding, + Documentation/devicetree/bindings/dma/dma.txt +- dma-names: DMA request names has to have one tx and 2 rx names + corresponding to dmas abive. +- ti,psil-config* - UDMA PSIL native Peripheral using packet mode. + SA2UL must have EPIB(Extended protocal information block) + and PSDATA(protocol specific data) properties.If ti,needs-epib is required, then why do you need to specify it in DT? In any case, this all seems like channel config info that should be part of the #dma-cells.
ti,needs-epib is the udma client(Here sa2ul) conveying the udma layer. Not every udma client needs epib.
Peter,
Any thoughts on the above?
- Keerthy
Quoted 2 lines
Also, don't use vendor prefixes on node names.
Okay
Quoted 26 lines
Quoted 26 lines
Documentation/devicetree/bindings/crypto/sa2ul.txt new file +25
-0+ +Example AM654 SA2UL: +crypto: crypto@4E00000 { + compatible = "ti,sa2ul-crypto"; + reg = <0x0 0x4E00000 0x0 0x1200>; + ti,psil-base = <0x4000>; + + dmas = <&main_udmap &crypto 0 UDMA_DIR_TX>, + <&main_udmap &crypto 0 UDMA_DIR_RX>, + <&main_udmap &crypto 1 UDMA_DIR_RX>; + dma-names = "tx", "rx1", "rx2"; + + ti,psil-config0 { + linux,udma-mode = <UDMA_PKT_MODE>; + ti,needs-epib; + ti,psd-size = <64>; + }; + + ti,psil-config1 { + linux,udma-mode = <UDMA_PKT_MODE>; + ti,needs-epib; + ti,psd-size = <64>; + }; + + ti,psil-config2 {
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/crypto/sa2ul.txt new file +5
-0+ linux,udma-mode = <UDMA_PKT_MODE>; + ti,needs-epib; + ti,psd-size = <64>; + }; +};Signature · 1 line
2.17.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Rob Herring
maintainerRe: [RESEND PATCH 01/10] dt-bindings: crypto: k3: Add sa2ul bindings documentation
Quoted 54 lines · Keerthy
Quoted 20 lines · Rob Herring
Quoted 19 lines · Keerthy
The series adds Crypto hardware accelerator support for SA2UL. SA2UL stands for security accelerator ultra lite.
The Security Accelerator (
SA2_UL) subsystem provides hardware cryptographic acceleration for the following use cases:
• Encryption and authentication for secure boot
• Encryption and authentication of content in applications requiring DRM (digital rights management) and content/asset protection
The device includes one instantiation ofSA2_ULnamedSA2_UL0SA2UL needs on tx channel and a pair of rx dma channels.
Signed-off-by Keerthy <[email protected]>--- .../devicetree/bindings/crypto/sa2ul.txt | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+)create mode 100644
Documentation/devicetree/bindings/crypto/sa2ul.txtQuoted 14 lines
Documentation/devicetree/bindings/crypto/sa2ul.txt line 6
Quoted 12 lines
Documentation/devicetree/bindings/crypto/sa2ul.txt new file +6
-0@@ -0,0 +1,47 @@ +K3 SoC SA2UL crypto module + +Required properties: + +- compatible : Should be: + - "ti,sa2ul-crypto"Needs to be SoC specific.
okay
Quoted 13 lines
Quoted 12 lines
Documentation/devicetree/bindings/crypto/sa2ul.txt new file +11
-0+- reg : Offset and length of the register set for the module + +- dmas: DMA specifiers for tx and rx dma. sa2ul needs one tx channel + and 2 rx channels. First rx channel for < 256 bytes and + the other one for >=256 bytes. See the DMA client binding, + Documentation/devicetree/bindings/dma/dma.txt +- dma-names: DMA request names has to have one tx and 2 rx names + corresponding to dmas abive. +- ti,psil-config* - UDMA PSIL native Peripheral using packet mode. + SA2UL must have EPIB(Extended protocal information block) + and PSDATA(protocol specific data) properties.
Quoted 6 lines
Quoted 3 lines
If ti,needs-epib is required, then why do you need to specify it in DT? In any case, this all seems like channel config info that should be part of the #dma-cells.
ti,needs-epib is the udma client(Here sa2ul) conveying the udma layer. Not every udma client needs epib.
Right, but if sa2ul always needs it, then it can be implied and set by the driver.