|
11 | 11 | #include <linux/writeback.h> |
12 | 12 | #include <linux/uio.h> |
13 | 13 | #include <linux/xattr.h> |
14 | | -#include <crypto/hash.h> |
15 | 14 | #include <crypto/aead.h> |
| 15 | +#include <crypto/aes-cbc-macs.h> |
16 | 16 | #include <crypto/md5.h> |
17 | 17 | #include <crypto/sha2.h> |
18 | 18 | #include <crypto/utils.h> |
@@ -490,46 +490,21 @@ void ksmbd_sign_smb2_pdu(struct ksmbd_conn *conn, char *key, struct kvec *iov, |
490 | 490 | * @sig: signature value generated for client request packet |
491 | 491 | * |
492 | 492 | */ |
493 | | -int ksmbd_sign_smb3_pdu(struct ksmbd_conn *conn, char *key, struct kvec *iov, |
494 | | - int n_vec, char *sig) |
| 493 | +void ksmbd_sign_smb3_pdu(struct ksmbd_conn *conn, char *key, struct kvec *iov, |
| 494 | + int n_vec, char *sig) |
495 | 495 | { |
496 | | - struct ksmbd_crypto_ctx *ctx; |
497 | | - int rc, i; |
498 | | - |
499 | | - ctx = ksmbd_crypto_ctx_find_cmacaes(); |
500 | | - if (!ctx) { |
501 | | - ksmbd_debug(AUTH, "could not crypto alloc cmac\n"); |
502 | | - return -ENOMEM; |
503 | | - } |
504 | | - |
505 | | - rc = crypto_shash_setkey(CRYPTO_CMACAES_TFM(ctx), |
506 | | - key, |
507 | | - SMB2_CMACAES_SIZE); |
508 | | - if (rc) |
509 | | - goto out; |
510 | | - |
511 | | - rc = crypto_shash_init(CRYPTO_CMACAES(ctx)); |
512 | | - if (rc) { |
513 | | - ksmbd_debug(AUTH, "cmaces init error %d\n", rc); |
514 | | - goto out; |
515 | | - } |
| 496 | + struct aes_cmac_key cmac_key; |
| 497 | + struct aes_cmac_ctx cmac_ctx; |
| 498 | + int i; |
516 | 499 |
|
517 | | - for (i = 0; i < n_vec; i++) { |
518 | | - rc = crypto_shash_update(CRYPTO_CMACAES(ctx), |
519 | | - iov[i].iov_base, |
520 | | - iov[i].iov_len); |
521 | | - if (rc) { |
522 | | - ksmbd_debug(AUTH, "cmaces update error %d\n", rc); |
523 | | - goto out; |
524 | | - } |
525 | | - } |
| 500 | + /* This cannot fail, since we always pass a valid key length. */ |
| 501 | + static_assert(SMB2_CMACAES_SIZE == AES_KEYSIZE_128); |
| 502 | + aes_cmac_preparekey(&cmac_key, key, SMB2_CMACAES_SIZE); |
526 | 503 |
|
527 | | - rc = crypto_shash_final(CRYPTO_CMACAES(ctx), sig); |
528 | | - if (rc) |
529 | | - ksmbd_debug(AUTH, "cmaces generation error %d\n", rc); |
530 | | -out: |
531 | | - ksmbd_release_crypto_ctx(ctx); |
532 | | - return rc; |
| 504 | + aes_cmac_init(&cmac_ctx, &cmac_key); |
| 505 | + for (i = 0; i < n_vec; i++) |
| 506 | + aes_cmac_update(&cmac_ctx, iov[i].iov_base, iov[i].iov_len); |
| 507 | + aes_cmac_final(&cmac_ctx, sig); |
533 | 508 | } |
534 | 509 |
|
535 | 510 | struct derivation { |
|
0 commit comments