|
18 | 18 |
|
19 | 19 | #include "local.h"
|
20 | 20 |
|
| 21 | +/* |
| 22 | + * Maximum job ring descriptor entries |
| 23 | + */ |
| 24 | +#ifdef CFG_CAAM_64BIT |
| 25 | +#define MAX_DESC_ENTRIES 22 |
| 26 | +#else |
| 27 | +#define MAX_DESC_ENTRIES 16 |
| 28 | +#endif |
| 29 | + |
21 | 30 | /*
|
22 | 31 | * Max Cipher Buffer to encrypt/decrypt at each operation
|
23 | 32 | */
|
@@ -165,10 +174,8 @@ static enum caam_status copy_ctx_data(struct caambuf *dst,
|
165 | 174 | static enum caam_status do_check_keysize(const struct caamdefkey *def,
|
166 | 175 | size_t size)
|
167 | 176 | {
|
168 |
| - if (size >= def->min && size <= def->max) { |
169 |
| - if (!(size % def->mod)) |
170 |
| - return CAAM_NO_ERROR; |
171 |
| - } |
| 177 | + if (size >= def->min && size <= def->max && !(size % def->mod)) |
| 178 | + return CAAM_NO_ERROR; |
172 | 179 |
|
173 | 180 | return CAAM_BAD_PARAM;
|
174 | 181 | }
|
@@ -263,9 +270,9 @@ enum caam_status caam_cipher_block(struct cipherdata *ctx, bool savectx,
|
263 | 270 | src_sgt.length);
|
264 | 271 | }
|
265 | 272 |
|
266 |
| - /* No output data to do - just create/update operation context */ |
| 273 | + /* No output data - just create/update operation context */ |
267 | 274 | if (!outdata)
|
268 |
| - goto desc_no_outdata; |
| 275 | + goto handle_context; |
269 | 276 |
|
270 | 277 | /*
|
271 | 278 | * Output data storage.
|
@@ -310,7 +317,7 @@ enum caam_status caam_cipher_block(struct cipherdata *ctx, bool savectx,
|
310 | 317 | dst_sgt.length);
|
311 | 318 | }
|
312 | 319 |
|
313 |
| -desc_no_outdata: |
| 320 | +handle_context: |
314 | 321 | if (ctx->ctx.length && ctx->alg->size_ctx) {
|
315 | 322 | if (savectx) {
|
316 | 323 | /* Store the context */
|
@@ -383,31 +390,24 @@ static const struct cipheralg *get_cipheralgo(uint32_t algo)
|
383 | 390 | break;
|
384 | 391 | }
|
385 | 392 |
|
386 |
| - if (ca) |
387 |
| - if (ca->type) |
388 |
| - return ca; |
| 393 | + if (ca && ca->type) |
| 394 | + return ca; |
389 | 395 |
|
390 | 396 | return NULL;
|
391 | 397 | }
|
392 | 398 |
|
393 | 399 | /*
|
394 | 400 | * Allocate the SW cipher data context
|
395 | 401 | *
|
396 |
| - * @algo Algorithm ID of the context |
397 | 402 | * @ctx [out] Caller context variable
|
| 403 | + * @algo Algorithm ID of the context |
398 | 404 | */
|
399 | 405 | static TEE_Result do_allocate(void **ctx, uint32_t algo)
|
400 | 406 | {
|
401 | 407 | TEE_Result ret = TEE_ERROR_NOT_IMPLEMENTED;
|
402 | 408 | struct cipherdata *cipherdata = NULL;
|
403 | 409 | const struct cipheralg *alg = NULL;
|
404 | 410 |
|
405 |
| -#ifdef CFG_CAAM_64BIT |
406 |
| -#define MAX_DESC_ENTRIES 22 |
407 |
| -#else |
408 |
| -#define MAX_DESC_ENTRIES 16 |
409 |
| -#endif |
410 |
| - |
411 | 411 | CIPHER_TRACE("Allocate Algo 0x%" PRIX32 " Context (%p)", algo, ctx);
|
412 | 412 |
|
413 | 413 | alg = get_cipheralgo(algo);
|
@@ -450,7 +450,7 @@ static TEE_Result do_allocate(void **ctx, uint32_t algo)
|
450 | 450 | /*
|
451 | 451 | * Free the internal cipher data context
|
452 | 452 | *
|
453 |
| - * @ctx Caller context variable |
| 453 | + * @ctx Caller context variable or NULL |
454 | 454 | */
|
455 | 455 | static void do_free_intern(struct cipherdata *ctx)
|
456 | 456 | {
|
@@ -480,7 +480,7 @@ static void do_free_intern(struct cipherdata *ctx)
|
480 | 480 | /*
|
481 | 481 | * Free the SW Cipher data context
|
482 | 482 | *
|
483 |
| - * @ctx Caller context variable |
| 483 | + * @ctx Caller context variable or NULL |
484 | 484 | */
|
485 | 485 | static void do_free(void *ctx)
|
486 | 486 | {
|
@@ -661,7 +661,7 @@ static TEE_Result do_init(struct drvcrypt_cipher_init *dinit)
|
661 | 661 | ret = caam_calloc_align_buf(&cipherdata->tweak,
|
662 | 662 | alg->size_block);
|
663 | 663 | if (ret != CAAM_NO_ERROR)
|
664 |
| - return ret; |
| 664 | + goto out; |
665 | 665 | } else {
|
666 | 666 | /* Fill it with 0's */
|
667 | 667 | memset(cipherdata->tweak.data, 0,
|
@@ -805,13 +805,14 @@ static TEE_Result do_update_streaming(struct drvcrypt_cipher_update *dupdate)
|
805 | 805 | }
|
806 | 806 |
|
807 | 807 | if (size_topost) {
|
808 |
| - CIPHER_TRACE("Save input data %zu bytes (done %zu)", |
809 |
| - size_topost, size_indone); |
810 | 808 | struct caambuf cpysrc = {
|
811 | 809 | .data = dupdate->src.data,
|
812 | 810 | .length = dupdate->src.length
|
813 | 811 | };
|
814 | 812 |
|
| 813 | + CIPHER_TRACE("Save input data %zu bytes (done %zu)", |
| 814 | + size_topost, size_indone); |
| 815 | + |
815 | 816 | retstatus = caam_cpy_block_src(&ctx->blockbuf, &cpysrc,
|
816 | 817 | size_indone);
|
817 | 818 | if (retstatus != CAAM_NO_ERROR) {
|
@@ -944,27 +945,26 @@ static TEE_Result do_update_cipher(struct drvcrypt_cipher_update *dupdate)
|
944 | 945 | srcbuf.length = MAX_CIPHER_BUFFER;
|
945 | 946 | dstbuf.length = MAX_CIPHER_BUFFER;
|
946 | 947 |
|
947 |
| - for (; nb_buf; nb_buf--) { |
| 948 | + while (nb_buf--) { |
948 | 949 | srcbuf.data += offset;
|
949 | 950 | srcbuf.paddr += offset;
|
950 | 951 |
|
951 |
| - CIPHER_TRACE("Do nb_buf=%" PRId32 ", offset %zu", nb_buf, |
952 |
| - offset); |
| 952 | + CIPHER_TRACE("Do nb_buf=%u, offset %zu", nb_buf, offset); |
| 953 | + |
953 | 954 | retstatus =
|
954 | 955 | caam_cipher_block(ctx, true, NEED_KEY1, ctx->encrypt,
|
955 | 956 | &srcbuf, &dstbuf, false);
|
956 | 957 |
|
957 |
| - if (retstatus == CAAM_NO_ERROR) { |
958 |
| - cache_operation(TEE_CACHEINVALIDATE, dstbuf.data, |
959 |
| - dstbuf.length); |
960 |
| - |
961 |
| - memcpy(dupdate->dst.data + offset, dstbuf.data, |
962 |
| - dstbuf.length); |
963 |
| - } else { |
| 958 | + if (retstatus != CAAM_NO_ERROR) { |
964 | 959 | ret = TEE_ERROR_GENERIC;
|
965 | 960 | goto out;
|
966 | 961 | }
|
967 | 962 |
|
| 963 | + cache_operation(TEE_CACHEINVALIDATE, dstbuf.data, |
| 964 | + dstbuf.length); |
| 965 | + |
| 966 | + memcpy(dupdate->dst.data + offset, dstbuf.data, dstbuf.length); |
| 967 | + |
968 | 968 | offset += MAX_CIPHER_BUFFER;
|
969 | 969 | }
|
970 | 970 |
|
@@ -1017,18 +1017,15 @@ static TEE_Result do_update_cipher(struct drvcrypt_cipher_update *dupdate)
|
1017 | 1017 | */
|
1018 | 1018 | static TEE_Result do_update(struct drvcrypt_cipher_update *dupdate)
|
1019 | 1019 | {
|
1020 |
| - TEE_Result ret = TEE_ERROR_GENERIC; |
1021 | 1020 | struct cipherdata *cipherdata = dupdate->ctx;
|
1022 | 1021 |
|
1023 |
| - ret = cipherdata->alg->update(dupdate); |
1024 |
| - |
1025 |
| - return ret; |
| 1022 | + return cipherdata->alg->update(dupdate); |
1026 | 1023 | }
|
1027 | 1024 |
|
1028 | 1025 | /*
|
1029 | 1026 | * Finalize of the cipher operation
|
1030 | 1027 | *
|
1031 |
| - * @ctx Caller context variable |
| 1028 | + * @ctx Caller context variable or NULL |
1032 | 1029 | */
|
1033 | 1030 | static void do_final(void *ctx __unused)
|
1034 | 1031 | {
|
|
0 commit comments