.. | .. |
---|
9 | 9 | |
---|
10 | 10 | #include <crypto/aes.h> |
---|
11 | 11 | #include <crypto/algapi.h> |
---|
12 | | -#include <crypto/des.h> |
---|
| 12 | +#include <crypto/internal/des.h> |
---|
13 | 13 | #include <crypto/skcipher.h> |
---|
14 | 14 | #include <crypto/xts.h> |
---|
15 | 15 | #include <crypto/internal/skcipher.h> |
---|
.. | .. |
---|
237 | 237 | memset(ctx->key, 0, SEC_MAX_CIPHER_KEY); |
---|
238 | 238 | } else { |
---|
239 | 239 | /* new key */ |
---|
240 | | - ctx->key = dma_zalloc_coherent(dev, SEC_MAX_CIPHER_KEY, |
---|
241 | | - &ctx->pkey, GFP_KERNEL); |
---|
| 240 | + ctx->key = dma_alloc_coherent(dev, SEC_MAX_CIPHER_KEY, |
---|
| 241 | + &ctx->pkey, GFP_KERNEL); |
---|
242 | 242 | if (!ctx->key) { |
---|
243 | 243 | mutex_unlock(&ctx->lock); |
---|
244 | 244 | return -ENOMEM; |
---|
.. | .. |
---|
343 | 343 | static int sec_alg_skcipher_setkey_des_ecb(struct crypto_skcipher *tfm, |
---|
344 | 344 | const u8 *key, unsigned int keylen) |
---|
345 | 345 | { |
---|
346 | | - if (keylen != DES_KEY_SIZE) |
---|
347 | | - return -EINVAL; |
---|
348 | | - |
---|
349 | | - return sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_DES_ECB_64); |
---|
| 346 | + return verify_skcipher_des_key(tfm, key) ?: |
---|
| 347 | + sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_DES_ECB_64); |
---|
350 | 348 | } |
---|
351 | 349 | |
---|
352 | 350 | static int sec_alg_skcipher_setkey_des_cbc(struct crypto_skcipher *tfm, |
---|
353 | 351 | const u8 *key, unsigned int keylen) |
---|
354 | 352 | { |
---|
355 | | - if (keylen != DES_KEY_SIZE) |
---|
356 | | - return -EINVAL; |
---|
357 | | - |
---|
358 | | - return sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_DES_CBC_64); |
---|
| 353 | + return verify_skcipher_des_key(tfm, key) ?: |
---|
| 354 | + sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_DES_CBC_64); |
---|
359 | 355 | } |
---|
360 | 356 | |
---|
361 | 357 | static int sec_alg_skcipher_setkey_3des_ecb(struct crypto_skcipher *tfm, |
---|
362 | 358 | const u8 *key, unsigned int keylen) |
---|
363 | 359 | { |
---|
364 | | - if (keylen != DES_KEY_SIZE * 3) |
---|
365 | | - return -EINVAL; |
---|
366 | | - |
---|
367 | | - return sec_alg_skcipher_setkey(tfm, key, keylen, |
---|
| 360 | + return verify_skcipher_des3_key(tfm, key) ?: |
---|
| 361 | + sec_alg_skcipher_setkey(tfm, key, keylen, |
---|
368 | 362 | SEC_C_3DES_ECB_192_3KEY); |
---|
369 | 363 | } |
---|
370 | 364 | |
---|
371 | 365 | static int sec_alg_skcipher_setkey_3des_cbc(struct crypto_skcipher *tfm, |
---|
372 | 366 | const u8 *key, unsigned int keylen) |
---|
373 | 367 | { |
---|
374 | | - if (keylen != DES3_EDE_KEY_SIZE) |
---|
375 | | - return -EINVAL; |
---|
376 | | - |
---|
377 | | - return sec_alg_skcipher_setkey(tfm, key, keylen, |
---|
| 368 | + return verify_skcipher_des3_key(tfm, key) ?: |
---|
| 369 | + sec_alg_skcipher_setkey(tfm, key, keylen, |
---|
378 | 370 | SEC_C_3DES_CBC_192_3KEY); |
---|
379 | 371 | } |
---|
380 | 372 | |
---|
.. | .. |
---|
457 | 449 | */ |
---|
458 | 450 | } |
---|
459 | 451 | |
---|
460 | | - mutex_lock(&ctx->queue->queuelock); |
---|
| 452 | + spin_lock_bh(&ctx->queue->queuelock); |
---|
461 | 453 | /* Put the IV in place for chained cases */ |
---|
462 | 454 | switch (ctx->cipher_alg) { |
---|
463 | 455 | case SEC_C_AES_CBC_128: |
---|
.. | .. |
---|
517 | 509 | list_del(&backlog_req->backlog_head); |
---|
518 | 510 | } |
---|
519 | 511 | } |
---|
520 | | - mutex_unlock(&ctx->queue->queuelock); |
---|
| 512 | + spin_unlock_bh(&ctx->queue->queuelock); |
---|
521 | 513 | |
---|
522 | 514 | mutex_lock(&sec_req->lock); |
---|
523 | 515 | list_del(&sec_req_el->head); |
---|
.. | .. |
---|
806 | 798 | */ |
---|
807 | 799 | |
---|
808 | 800 | /* Grab a big lock for a long time to avoid concurrency issues */ |
---|
809 | | - mutex_lock(&queue->queuelock); |
---|
| 801 | + spin_lock_bh(&queue->queuelock); |
---|
810 | 802 | |
---|
811 | 803 | /* |
---|
812 | 804 | * Can go on to queue if we have space in either: |
---|
.. | .. |
---|
822 | 814 | ret = -EBUSY; |
---|
823 | 815 | if ((skreq->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) { |
---|
824 | 816 | list_add_tail(&sec_req->backlog_head, &ctx->backlog); |
---|
825 | | - mutex_unlock(&queue->queuelock); |
---|
| 817 | + spin_unlock_bh(&queue->queuelock); |
---|
826 | 818 | goto out; |
---|
827 | 819 | } |
---|
828 | 820 | |
---|
829 | | - mutex_unlock(&queue->queuelock); |
---|
| 821 | + spin_unlock_bh(&queue->queuelock); |
---|
830 | 822 | goto err_free_elements; |
---|
831 | 823 | } |
---|
832 | 824 | ret = sec_send_request(sec_req, queue); |
---|
833 | | - mutex_unlock(&queue->queuelock); |
---|
| 825 | + spin_unlock_bh(&queue->queuelock); |
---|
834 | 826 | if (ret) |
---|
835 | 827 | goto err_free_elements; |
---|
836 | 828 | |
---|
.. | .. |
---|
889 | 881 | if (IS_ERR(ctx->queue)) |
---|
890 | 882 | return PTR_ERR(ctx->queue); |
---|
891 | 883 | |
---|
892 | | - mutex_init(&ctx->queue->queuelock); |
---|
| 884 | + spin_lock_init(&ctx->queue->queuelock); |
---|
893 | 885 | ctx->queue->havesoftqueue = false; |
---|
894 | 886 | |
---|
895 | 887 | return 0; |
---|
.. | .. |
---|
942 | 934 | .cra_name = "ecb(aes)", |
---|
943 | 935 | .cra_driver_name = "hisi_sec_aes_ecb", |
---|
944 | 936 | .cra_priority = 4001, |
---|
945 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 937 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 938 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
946 | 939 | .cra_blocksize = AES_BLOCK_SIZE, |
---|
947 | 940 | .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx), |
---|
948 | 941 | .cra_alignmask = 0, |
---|
.. | .. |
---|
961 | 954 | .cra_name = "cbc(aes)", |
---|
962 | 955 | .cra_driver_name = "hisi_sec_aes_cbc", |
---|
963 | 956 | .cra_priority = 4001, |
---|
964 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 957 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 958 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
965 | 959 | .cra_blocksize = AES_BLOCK_SIZE, |
---|
966 | 960 | .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx), |
---|
967 | 961 | .cra_alignmask = 0, |
---|
.. | .. |
---|
980 | 974 | .cra_name = "ctr(aes)", |
---|
981 | 975 | .cra_driver_name = "hisi_sec_aes_ctr", |
---|
982 | 976 | .cra_priority = 4001, |
---|
983 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 977 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 978 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
984 | 979 | .cra_blocksize = AES_BLOCK_SIZE, |
---|
985 | 980 | .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx), |
---|
986 | 981 | .cra_alignmask = 0, |
---|
.. | .. |
---|
999 | 994 | .cra_name = "xts(aes)", |
---|
1000 | 995 | .cra_driver_name = "hisi_sec_aes_xts", |
---|
1001 | 996 | .cra_priority = 4001, |
---|
1002 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 997 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 998 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
1003 | 999 | .cra_blocksize = AES_BLOCK_SIZE, |
---|
1004 | 1000 | .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx), |
---|
1005 | 1001 | .cra_alignmask = 0, |
---|
.. | .. |
---|
1019 | 1015 | .cra_name = "ecb(des)", |
---|
1020 | 1016 | .cra_driver_name = "hisi_sec_des_ecb", |
---|
1021 | 1017 | .cra_priority = 4001, |
---|
1022 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 1018 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 1019 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
1023 | 1020 | .cra_blocksize = DES_BLOCK_SIZE, |
---|
1024 | 1021 | .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx), |
---|
1025 | 1022 | .cra_alignmask = 0, |
---|
.. | .. |
---|
1038 | 1035 | .cra_name = "cbc(des)", |
---|
1039 | 1036 | .cra_driver_name = "hisi_sec_des_cbc", |
---|
1040 | 1037 | .cra_priority = 4001, |
---|
1041 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 1038 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 1039 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
1042 | 1040 | .cra_blocksize = DES_BLOCK_SIZE, |
---|
1043 | 1041 | .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx), |
---|
1044 | 1042 | .cra_alignmask = 0, |
---|
.. | .. |
---|
1057 | 1055 | .cra_name = "cbc(des3_ede)", |
---|
1058 | 1056 | .cra_driver_name = "hisi_sec_3des_cbc", |
---|
1059 | 1057 | .cra_priority = 4001, |
---|
1060 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 1058 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 1059 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
1061 | 1060 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
---|
1062 | 1061 | .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx), |
---|
1063 | 1062 | .cra_alignmask = 0, |
---|
.. | .. |
---|
1076 | 1075 | .cra_name = "ecb(des3_ede)", |
---|
1077 | 1076 | .cra_driver_name = "hisi_sec_3des_ecb", |
---|
1078 | 1077 | .cra_priority = 4001, |
---|
1079 | | - .cra_flags = CRYPTO_ALG_ASYNC, |
---|
| 1078 | + .cra_flags = CRYPTO_ALG_ASYNC | |
---|
| 1079 | + CRYPTO_ALG_ALLOCATES_MEMORY, |
---|
1080 | 1080 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
---|
1081 | 1081 | .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx), |
---|
1082 | 1082 | .cra_alignmask = 0, |
---|