Skip to content

Commit

Permalink
drivers: caam: change caam_cipher_block() prototype for added block
Browse files Browse the repository at this point in the history
Introduce 'blocks' parameter for caam_cipher_block() function for
addtionnal data block to handle during cipher operations.
Add `enum caam_cipher_block` to describe these additionnal data blocks.

Signed-off-by: Clement Faure <[email protected]>
Acked-by: Jens Wiklander <[email protected]>
Acked-by: Etienne Carriere <[email protected]>
  • Loading branch information
clementfaure authored and jforissier committed Jun 15, 2020
1 parent 6f0990d commit 9625d30
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
27 changes: 15 additions & 12 deletions core/drivers/crypto/caam/cipher/caam_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ static enum caam_status do_check_keysize(const struct caamdefkey *def,
enum caam_status caam_cipher_block(struct cipherdata *ctx, bool savectx,
uint8_t keyid, bool encrypt,
struct caambuf *indata,
struct caambuf *outdata, bool blockbuf)
struct caambuf *outdata,
enum caam_cipher_block blocks)
{
enum caam_status retstatus = CAAM_FAILURE;
struct caam_jobctx jobctx = { };
Expand Down Expand Up @@ -214,7 +215,7 @@ enum caam_status caam_cipher_block(struct cipherdata *ctx, bool savectx,
* If Source data is a User Data buffer mapped on multiple pages
* create a Scatter/Gather table.
*/
if (blockbuf)
if (blocks == CIPHER_BLOCK_IN || blocks == CIPHER_BLOCK_BOTH)
retstatus = caam_sgt_build_block_data(&src_sgt, &ctx->blockbuf,
indata);
else
Expand Down Expand Up @@ -264,7 +265,7 @@ enum caam_status caam_cipher_block(struct cipherdata *ctx, bool savectx,
* If Output data is a User Data buffer mapped on multiple pages
* create a Scatter/Gather table.
*/
if (blockbuf)
if (blocks == CIPHER_BLOCK_OUT || blocks == CIPHER_BLOCK_BOTH)
retstatus = caam_sgt_build_block_data(&dst_sgt, &ctx->blockbuf,
outdata);
else
Expand Down Expand Up @@ -757,7 +758,8 @@ static TEE_Result do_update_streaming(struct drvcrypt_cipher_update *dupdate)

retstatus = caam_cipher_block(ctx, true, NEED_KEY1,
ctx->encrypt, &srcbuf,
&dstbuf, true);
&dstbuf,
CIPHER_BLOCK_BOTH);

ctx->blockbuf.filled = 0;
} else {
Expand All @@ -771,9 +773,10 @@ static TEE_Result do_update_streaming(struct drvcrypt_cipher_update *dupdate)
dstbuf.paddr = dst_align.paddr;
dstbuf.nocache = dst_align.nocache;

retstatus = caam_cipher_block(ctx, true, NEED_KEY1,
ctx->encrypt, &srcbuf,
&dstbuf, false);
retstatus =
caam_cipher_block(ctx, true, NEED_KEY1,
ctx->encrypt, &srcbuf,
&dstbuf, CIPHER_BLOCK_NONE);
}

if (retstatus != CAAM_NO_ERROR) {
Expand Down Expand Up @@ -816,7 +819,7 @@ static TEE_Result do_update_streaming(struct drvcrypt_cipher_update *dupdate)

retstatus = caam_cipher_block(ctx, false, NEED_KEY1,
ctx->encrypt, &srcbuf, &dstbuf,
false);
CIPHER_BLOCK_NONE);

if (retstatus != CAAM_NO_ERROR) {
ret = TEE_ERROR_GENERIC;
Expand Down Expand Up @@ -935,9 +938,9 @@ static TEE_Result do_update_cipher(struct drvcrypt_cipher_update *dupdate)

CIPHER_TRACE("Do nb_buf=%u, offset %zu", nb_buf, offset);

retstatus =
caam_cipher_block(ctx, true, NEED_KEY1, ctx->encrypt,
&srcbuf, &dstbuf, false);
retstatus = caam_cipher_block(ctx, true, NEED_KEY1,
ctx->encrypt, &srcbuf, &dstbuf,
CIPHER_BLOCK_NONE);

if (retstatus != CAAM_NO_ERROR) {
ret = TEE_ERROR_GENERIC;
Expand Down Expand Up @@ -967,7 +970,7 @@ static TEE_Result do_update_cipher(struct drvcrypt_cipher_update *dupdate)

retstatus = caam_cipher_block(ctx, true, NEED_KEY1,
ctx->encrypt, &srcbuf, &dstbuf,
false);
CIPHER_BLOCK_NONE);

if (retstatus == CAAM_NO_ERROR) {
if (!dstbuf.nocache)
Expand Down
6 changes: 3 additions & 3 deletions core/drivers/crypto/caam/cipher/caam_cipher_xts.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static enum caam_status do_tweak_block(struct cipherdata *ctx,
tmp->data[idx] = srcbuf->data[idx] ^ enc_tweak->data[idx];

retstatus = caam_cipher_block(ctx, false, NEED_KEY1, ctx->encrypt, tmp,
tmp, false);
tmp, CIPHER_BLOCK_NONE);

if (retstatus != CAAM_NO_ERROR)
return retstatus;
Expand Down Expand Up @@ -115,7 +115,7 @@ TEE_Result caam_cipher_update_xts(struct drvcrypt_cipher_update *dupdate)
}

retstatus = caam_cipher_block(ctx, false, NEED_KEY2, true, &ctx->tweak,
&enc_tweak, false);
&enc_tweak, CIPHER_BLOCK_NONE);
if (retstatus != CAAM_NO_ERROR) {
CIPHER_TRACE("Tweak encryption error");
ret = TEE_ERROR_GENERIC;
Expand Down Expand Up @@ -237,7 +237,7 @@ TEE_Result caam_cipher_update_xts(struct drvcrypt_cipher_update *dupdate)

/* Finalize by decrypting the tweak back */
retstatus = caam_cipher_block(ctx, false, NEED_KEY2, false, &enc_tweak,
&ctx->tweak, false);
&ctx->tweak, CIPHER_BLOCK_NONE);
if (retstatus != CAAM_NO_ERROR) {
CIPHER_TRACE("Tweak decryption error");
ret = TEE_ERROR_GENERIC;
Expand Down
14 changes: 12 additions & 2 deletions core/drivers/crypto/caam/cipher/local.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ struct cipherdata {
const struct cipheralg *alg; /* Reference to the algo constants */
};

/*
* Cipher additionnal data block
*/
enum caam_cipher_block {
CIPHER_BLOCK_NONE = 0,
CIPHER_BLOCK_IN,
CIPHER_BLOCK_OUT,
CIPHER_BLOCK_BOTH,
};

/*
* Update of the cipher operation of complete block except
* if last block. Last block can be partial block.
Expand All @@ -65,12 +75,12 @@ struct cipherdata {
* @encrypt Encrypt or decrypt direction
* @src Source data to encrypt/decrypt
* @dst [out] Destination data encrypted/decrypted
* @blockbuf Saved block during previous streaming update
* @blocks Additionnal data block to handle (input/output)
*/
enum caam_status caam_cipher_block(struct cipherdata *ctx, bool savectx,
uint8_t keyid, bool encrypt,
struct caambuf *src, struct caambuf *dst,
bool blockbuf);
enum caam_cipher_block blocks);

/*
* Update of the cipher operation in xts mode.
Expand Down

0 comments on commit 9625d30

Please sign in to comment.