Skip to content

Commit

Permalink
[Review OP-TEE#4] drivers: caam: implement NXP CAAM driver - Cipher
Browse files Browse the repository at this point in the history
Minor fixes.

Signed-off-by: Clement Faure <[email protected]>
  • Loading branch information
clementfaure committed Mar 12, 2020
1 parent a1892ca commit 6fa4b1f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
40 changes: 16 additions & 24 deletions core/drivers/crypto/caam/cipher/caam_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ static TEE_Result do_update_cipher(struct drvcrypt_cipher_update *dupdate);
* Constants definition of the AES algorithm
*/
static const struct cipheralg aes_alg[] = {
{
/* AES ECB No Pad */
[TEE_CHAIN_MODE_ECB_NOPAD] = {
.type = OP_ALGO(AES) | ALGO_AAI(AES_ECB),
.size_block = TEE_AES_BLOCK_SIZE,
.size_ctx = 0,
Expand All @@ -50,8 +49,7 @@ static const struct cipheralg aes_alg[] = {
.def_key = { .min = 16, .max = 32, .mod = 8 },
.update = do_update_cipher,
},
{
/* AES CBC No Pad */
[TEE_CHAIN_MODE_CBC_NOPAD] = {
.type = OP_ALGO(AES) | ALGO_AAI(AES_CBC),
.size_block = TEE_AES_BLOCK_SIZE,
.size_ctx = 2 * sizeof(uint64_t),
Expand All @@ -60,8 +58,7 @@ static const struct cipheralg aes_alg[] = {
.def_key = { .min = 16, .max = 32, .mod = 8 },
.update = do_update_cipher,
},
{
/* AES CTR */
[TEE_CHAIN_MODE_CTR] = {
.type = OP_ALGO(AES) | ALGO_AAI(AES_CTR_MOD128),
.size_block = TEE_AES_BLOCK_SIZE,
.size_ctx = 2 * sizeof(uint64_t),
Expand All @@ -70,12 +67,10 @@ static const struct cipheralg aes_alg[] = {
.def_key = { .min = 16, .max = 32, .mod = 8 },
.update = do_update_streaming,
},
{
/* AES CTS, combination of CBC and ECB mode */
[TEE_CHAIN_MODE_CTS] = {
.type = 0,
},
{
/* AES XTS, tweakable ECB cipher block */
[TEE_CHAIN_MODE_XTS] = {
.type = OP_ALGO(AES) | ALGO_AAI(AES_ECB),
.size_block = TEE_AES_BLOCK_SIZE,
.size_ctx = 0,
Expand All @@ -90,8 +85,7 @@ static const struct cipheralg aes_alg[] = {
* Constants definition of the DES algorithm
*/
static const struct cipheralg des_alg[] = {
{
/* DES ECB No Pad */
[TEE_CHAIN_MODE_ECB_NOPAD] = {
.type = OP_ALGO(DES) | ALGO_AAI(DES_ECB),
.size_block = TEE_DES_BLOCK_SIZE,
.size_ctx = 0,
Expand All @@ -100,8 +94,7 @@ static const struct cipheralg des_alg[] = {
.def_key = { .min = 8, .max = 8, .mod = 8 },
.update = do_update_cipher,
},
{
/* DES CBC No Pad */
[TEE_CHAIN_MODE_CBC_NOPAD] = {
.type = OP_ALGO(DES) | ALGO_AAI(DES_CBC),
.size_block = TEE_DES_BLOCK_SIZE,
.size_ctx = sizeof(uint64_t),
Expand All @@ -116,8 +109,7 @@ static const struct cipheralg des_alg[] = {
* Constants definition of the DES3 algorithm
*/
static const struct cipheralg des3_alg[] = {
{
/* Triple-DES ECB No Pad */
[TEE_CHAIN_MODE_ECB_NOPAD] = {
.type = OP_ALGO(3DES) | ALGO_AAI(DES_ECB),
.size_block = TEE_DES_BLOCK_SIZE,
.size_ctx = 0,
Expand All @@ -126,7 +118,7 @@ static const struct cipheralg des3_alg[] = {
.def_key = { .min = 16, .max = 24, .mod = 8 },
.update = do_update_cipher,
},
{
[TEE_CHAIN_MODE_CBC_NOPAD] = {
/* Triple-DES CBC No Pad */
.type = OP_ALGO(3DES) | ALGO_AAI(DES_CBC),
.size_block = TEE_DES_BLOCK_SIZE,
Expand Down Expand Up @@ -186,7 +178,7 @@ enum caam_status caam_cipher_block(struct cipherdata *ctx, bool savectx,
struct caambuf *outdata, bool blockbuf)
{
enum caam_status retstatus = CAAM_FAILURE;
struct caam_jobctx jobctx = {};
struct caam_jobctx jobctx = { };
uint32_t *desc = ctx->descriptor;
struct caamsgtbuf src_sgt = {
.sgt_type = false
Expand Down Expand Up @@ -705,15 +697,15 @@ static TEE_Result do_update_streaming(struct drvcrypt_cipher_update *dupdate)
TEE_Result ret = TEE_ERROR_GENERIC;
enum caam_status retstatus = CAAM_FAILURE;
struct cipherdata *ctx = dupdate->ctx;
struct caambuf srcbuf = {};
struct caambuf dstbuf = {};
struct caambuf srcbuf = { };
struct caambuf dstbuf = { };
paddr_t psrc = 0;
size_t fullSize = 0;
size_t size_topost = 0;
size_t size_todo = 0;
size_t size_indone = 0;
int realloc = 0;
struct caambuf dst_align = {};
struct caambuf dst_align = { };

CIPHER_TRACE("Length=%zu - %s", dupdate->src.length,
ctx->encrypt ? "Encrypt" : "Decrypt");
Expand Down Expand Up @@ -871,10 +863,10 @@ static TEE_Result do_update_cipher(struct drvcrypt_cipher_update *dupdate)
TEE_Result ret = TEE_ERROR_GENERIC;
enum caam_status retstatus = CAAM_FAILURE;
struct cipherdata *ctx = dupdate->ctx;
struct caambuf srcbuf = {};
struct caambuf dstbuf = {};
struct caambuf srcbuf = { };
struct caambuf dstbuf = { };
int realloc = 0;
struct caambuf dst_align = {};
struct caambuf dst_align = { };
unsigned int nb_buf = 0;
size_t offset = 0;

Expand Down
10 changes: 5 additions & 5 deletions core/drivers/crypto/caam/cipher/caam_cipher_xts.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ TEE_Result caam_cipher_update_xts(struct drvcrypt_cipher_update *dupdate)
TEE_Result ret = TEE_ERROR_GENERIC;
enum caam_status retstatus = CAAM_FAILURE;
struct cipherdata *ctx = dupdate->ctx;
struct caambuf enc_tweak = {};
struct caambuf tmpsrc = {};
struct caambuf tmpdst = {};
struct caambuf srcbuf = {};
struct caambuf dstbuf = {};
struct caambuf enc_tweak = { };
struct caambuf tmpsrc = { };
struct caambuf tmpdst = { };
struct caambuf srcbuf = { };
struct caambuf dstbuf = { };
size_t idx = 0;
size_t fullsize = 0;
size_t lastblk = 0;
Expand Down

0 comments on commit 6fa4b1f

Please sign in to comment.