Skip to content

Commit 6fa4b1f

Browse files
committed
[Review OP-TEE#4] drivers: caam: implement NXP CAAM driver - Cipher
Minor fixes. Signed-off-by: Clement Faure <clement.faure@nxp.com>
1 parent a1892ca commit 6fa4b1f

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

core/drivers/crypto/caam/cipher/caam_cipher.c

+16-24
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ static TEE_Result do_update_cipher(struct drvcrypt_cipher_update *dupdate);
4040
* Constants definition of the AES algorithm
4141
*/
4242
static const struct cipheralg aes_alg[] = {
43-
{
44-
/* AES ECB No Pad */
43+
[TEE_CHAIN_MODE_ECB_NOPAD] = {
4544
.type = OP_ALGO(AES) | ALGO_AAI(AES_ECB),
4645
.size_block = TEE_AES_BLOCK_SIZE,
4746
.size_ctx = 0,
@@ -50,8 +49,7 @@ static const struct cipheralg aes_alg[] = {
5049
.def_key = { .min = 16, .max = 32, .mod = 8 },
5150
.update = do_update_cipher,
5251
},
53-
{
54-
/* AES CBC No Pad */
52+
[TEE_CHAIN_MODE_CBC_NOPAD] = {
5553
.type = OP_ALGO(AES) | ALGO_AAI(AES_CBC),
5654
.size_block = TEE_AES_BLOCK_SIZE,
5755
.size_ctx = 2 * sizeof(uint64_t),
@@ -60,8 +58,7 @@ static const struct cipheralg aes_alg[] = {
6058
.def_key = { .min = 16, .max = 32, .mod = 8 },
6159
.update = do_update_cipher,
6260
},
63-
{
64-
/* AES CTR */
61+
[TEE_CHAIN_MODE_CTR] = {
6562
.type = OP_ALGO(AES) | ALGO_AAI(AES_CTR_MOD128),
6663
.size_block = TEE_AES_BLOCK_SIZE,
6764
.size_ctx = 2 * sizeof(uint64_t),
@@ -70,12 +67,10 @@ static const struct cipheralg aes_alg[] = {
7067
.def_key = { .min = 16, .max = 32, .mod = 8 },
7168
.update = do_update_streaming,
7269
},
73-
{
74-
/* AES CTS, combination of CBC and ECB mode */
70+
[TEE_CHAIN_MODE_CTS] = {
7571
.type = 0,
7672
},
77-
{
78-
/* AES XTS, tweakable ECB cipher block */
73+
[TEE_CHAIN_MODE_XTS] = {
7974
.type = OP_ALGO(AES) | ALGO_AAI(AES_ECB),
8075
.size_block = TEE_AES_BLOCK_SIZE,
8176
.size_ctx = 0,
@@ -90,8 +85,7 @@ static const struct cipheralg aes_alg[] = {
9085
* Constants definition of the DES algorithm
9186
*/
9287
static const struct cipheralg des_alg[] = {
93-
{
94-
/* DES ECB No Pad */
88+
[TEE_CHAIN_MODE_ECB_NOPAD] = {
9589
.type = OP_ALGO(DES) | ALGO_AAI(DES_ECB),
9690
.size_block = TEE_DES_BLOCK_SIZE,
9791
.size_ctx = 0,
@@ -100,8 +94,7 @@ static const struct cipheralg des_alg[] = {
10094
.def_key = { .min = 8, .max = 8, .mod = 8 },
10195
.update = do_update_cipher,
10296
},
103-
{
104-
/* DES CBC No Pad */
97+
[TEE_CHAIN_MODE_CBC_NOPAD] = {
10598
.type = OP_ALGO(DES) | ALGO_AAI(DES_CBC),
10699
.size_block = TEE_DES_BLOCK_SIZE,
107100
.size_ctx = sizeof(uint64_t),
@@ -116,8 +109,7 @@ static const struct cipheralg des_alg[] = {
116109
* Constants definition of the DES3 algorithm
117110
*/
118111
static const struct cipheralg des3_alg[] = {
119-
{
120-
/* Triple-DES ECB No Pad */
112+
[TEE_CHAIN_MODE_ECB_NOPAD] = {
121113
.type = OP_ALGO(3DES) | ALGO_AAI(DES_ECB),
122114
.size_block = TEE_DES_BLOCK_SIZE,
123115
.size_ctx = 0,
@@ -126,7 +118,7 @@ static const struct cipheralg des3_alg[] = {
126118
.def_key = { .min = 16, .max = 24, .mod = 8 },
127119
.update = do_update_cipher,
128120
},
129-
{
121+
[TEE_CHAIN_MODE_CBC_NOPAD] = {
130122
/* Triple-DES CBC No Pad */
131123
.type = OP_ALGO(3DES) | ALGO_AAI(DES_CBC),
132124
.size_block = TEE_DES_BLOCK_SIZE,
@@ -186,7 +178,7 @@ enum caam_status caam_cipher_block(struct cipherdata *ctx, bool savectx,
186178
struct caambuf *outdata, bool blockbuf)
187179
{
188180
enum caam_status retstatus = CAAM_FAILURE;
189-
struct caam_jobctx jobctx = {};
181+
struct caam_jobctx jobctx = { };
190182
uint32_t *desc = ctx->descriptor;
191183
struct caamsgtbuf src_sgt = {
192184
.sgt_type = false
@@ -705,15 +697,15 @@ static TEE_Result do_update_streaming(struct drvcrypt_cipher_update *dupdate)
705697
TEE_Result ret = TEE_ERROR_GENERIC;
706698
enum caam_status retstatus = CAAM_FAILURE;
707699
struct cipherdata *ctx = dupdate->ctx;
708-
struct caambuf srcbuf = {};
709-
struct caambuf dstbuf = {};
700+
struct caambuf srcbuf = { };
701+
struct caambuf dstbuf = { };
710702
paddr_t psrc = 0;
711703
size_t fullSize = 0;
712704
size_t size_topost = 0;
713705
size_t size_todo = 0;
714706
size_t size_indone = 0;
715707
int realloc = 0;
716-
struct caambuf dst_align = {};
708+
struct caambuf dst_align = { };
717709

718710
CIPHER_TRACE("Length=%zu - %s", dupdate->src.length,
719711
ctx->encrypt ? "Encrypt" : "Decrypt");
@@ -871,10 +863,10 @@ static TEE_Result do_update_cipher(struct drvcrypt_cipher_update *dupdate)
871863
TEE_Result ret = TEE_ERROR_GENERIC;
872864
enum caam_status retstatus = CAAM_FAILURE;
873865
struct cipherdata *ctx = dupdate->ctx;
874-
struct caambuf srcbuf = {};
875-
struct caambuf dstbuf = {};
866+
struct caambuf srcbuf = { };
867+
struct caambuf dstbuf = { };
876868
int realloc = 0;
877-
struct caambuf dst_align = {};
869+
struct caambuf dst_align = { };
878870
unsigned int nb_buf = 0;
879871
size_t offset = 0;
880872

core/drivers/crypto/caam/cipher/caam_cipher_xts.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ TEE_Result caam_cipher_update_xts(struct drvcrypt_cipher_update *dupdate)
7777
TEE_Result ret = TEE_ERROR_GENERIC;
7878
enum caam_status retstatus = CAAM_FAILURE;
7979
struct cipherdata *ctx = dupdate->ctx;
80-
struct caambuf enc_tweak = {};
81-
struct caambuf tmpsrc = {};
82-
struct caambuf tmpdst = {};
83-
struct caambuf srcbuf = {};
84-
struct caambuf dstbuf = {};
80+
struct caambuf enc_tweak = { };
81+
struct caambuf tmpsrc = { };
82+
struct caambuf tmpdst = { };
83+
struct caambuf srcbuf = { };
84+
struct caambuf dstbuf = { };
8585
size_t idx = 0;
8686
size_t fullsize = 0;
8787
size_t lastblk = 0;

0 commit comments

Comments
 (0)