mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
ksmbd: Use SHA-512 library for SMB3.1.1 preauth hash
Convert ksmbd_gen_preauth_integrity_hash() to use the SHA-512 library instead of a "sha512" crypto_shash. This is simpler and faster. With the library there's no need to allocate memory, no need to handle errors, and the SHA-512 code is accessed directly without inefficient indirect calls and other unnecessary API overhead. Signed-off-by: Eric Biggers <ebiggers@kernel.org> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
This commit is contained in:
committed by
Steve French
parent
7d0a66e4bb
commit
e009cb1e30
@@ -13,9 +13,9 @@ config SMB_SERVER
|
||||
select CRYPTO_LIB_ARC4
|
||||
select CRYPTO_LIB_DES
|
||||
select CRYPTO_LIB_SHA256
|
||||
select CRYPTO_LIB_SHA512
|
||||
select CRYPTO_SHA256
|
||||
select CRYPTO_CMAC
|
||||
select CRYPTO_SHA512
|
||||
select CRYPTO_AEAD2
|
||||
select CRYPTO_CCM
|
||||
select CRYPTO_GCM
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <linux/xattr.h>
|
||||
#include <crypto/hash.h>
|
||||
#include <crypto/aead.h>
|
||||
#include <crypto/sha2.h>
|
||||
#include <linux/random.h>
|
||||
#include <linux/scatterlist.h>
|
||||
|
||||
@@ -934,48 +935,20 @@ int ksmbd_gen_smb311_encryptionkey(struct ksmbd_conn *conn,
|
||||
int ksmbd_gen_preauth_integrity_hash(struct ksmbd_conn *conn, char *buf,
|
||||
__u8 *pi_hash)
|
||||
{
|
||||
int rc;
|
||||
struct smb2_hdr *rcv_hdr = smb2_get_msg(buf);
|
||||
char *all_bytes_msg = (char *)&rcv_hdr->ProtocolId;
|
||||
int msg_size = get_rfc1002_len(buf);
|
||||
struct ksmbd_crypto_ctx *ctx = NULL;
|
||||
struct sha512_ctx sha_ctx;
|
||||
|
||||
if (conn->preauth_info->Preauth_HashId !=
|
||||
SMB2_PREAUTH_INTEGRITY_SHA512)
|
||||
return -EINVAL;
|
||||
|
||||
ctx = ksmbd_crypto_ctx_find_sha512();
|
||||
if (!ctx) {
|
||||
ksmbd_debug(AUTH, "could not alloc sha512\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = crypto_shash_init(CRYPTO_SHA512(ctx));
|
||||
if (rc) {
|
||||
ksmbd_debug(AUTH, "could not init shashn");
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = crypto_shash_update(CRYPTO_SHA512(ctx), pi_hash, 64);
|
||||
if (rc) {
|
||||
ksmbd_debug(AUTH, "could not update with n\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = crypto_shash_update(CRYPTO_SHA512(ctx), all_bytes_msg, msg_size);
|
||||
if (rc) {
|
||||
ksmbd_debug(AUTH, "could not update with n\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = crypto_shash_final(CRYPTO_SHA512(ctx), pi_hash);
|
||||
if (rc) {
|
||||
ksmbd_debug(AUTH, "Could not generate hash err : %d\n", rc);
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
ksmbd_release_crypto_ctx(ctx);
|
||||
return rc;
|
||||
sha512_init(&sha_ctx);
|
||||
sha512_update(&sha_ctx, pi_hash, 64);
|
||||
sha512_update(&sha_ctx, all_bytes_msg, msg_size);
|
||||
sha512_final(&sha_ctx, pi_hash);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ksmbd_get_encryption_key(struct ksmbd_work *work, __u64 ses_id,
|
||||
|
||||
@@ -75,9 +75,6 @@ static struct shash_desc *alloc_shash_desc(int id)
|
||||
case CRYPTO_SHASH_CMACAES:
|
||||
tfm = crypto_alloc_shash("cmac(aes)", 0, 0);
|
||||
break;
|
||||
case CRYPTO_SHASH_SHA512:
|
||||
tfm = crypto_alloc_shash("sha512", 0, 0);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
@@ -195,11 +192,6 @@ struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_cmacaes(void)
|
||||
return ____crypto_shash_ctx_find(CRYPTO_SHASH_CMACAES);
|
||||
}
|
||||
|
||||
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_sha512(void)
|
||||
{
|
||||
return ____crypto_shash_ctx_find(CRYPTO_SHASH_SHA512);
|
||||
}
|
||||
|
||||
static struct ksmbd_crypto_ctx *____crypto_aead_ctx_find(int id)
|
||||
{
|
||||
struct ksmbd_crypto_ctx *ctx;
|
||||
|
||||
@@ -13,7 +13,6 @@ enum {
|
||||
CRYPTO_SHASH_HMACMD5 = 0,
|
||||
CRYPTO_SHASH_HMACSHA256,
|
||||
CRYPTO_SHASH_CMACAES,
|
||||
CRYPTO_SHASH_SHA512,
|
||||
CRYPTO_SHASH_MAX,
|
||||
};
|
||||
|
||||
@@ -38,13 +37,11 @@ struct ksmbd_crypto_ctx {
|
||||
#define CRYPTO_HMACMD5(c) ((c)->desc[CRYPTO_SHASH_HMACMD5])
|
||||
#define CRYPTO_HMACSHA256(c) ((c)->desc[CRYPTO_SHASH_HMACSHA256])
|
||||
#define CRYPTO_CMACAES(c) ((c)->desc[CRYPTO_SHASH_CMACAES])
|
||||
#define CRYPTO_SHA512(c) ((c)->desc[CRYPTO_SHASH_SHA512])
|
||||
|
||||
#define CRYPTO_HMACMD5_TFM(c) ((c)->desc[CRYPTO_SHASH_HMACMD5]->tfm)
|
||||
#define CRYPTO_HMACSHA256_TFM(c)\
|
||||
((c)->desc[CRYPTO_SHASH_HMACSHA256]->tfm)
|
||||
#define CRYPTO_CMACAES_TFM(c) ((c)->desc[CRYPTO_SHASH_CMACAES]->tfm)
|
||||
#define CRYPTO_SHA512_TFM(c) ((c)->desc[CRYPTO_SHASH_SHA512]->tfm)
|
||||
|
||||
#define CRYPTO_GCM(c) ((c)->ccmaes[CRYPTO_AEAD_AES_GCM])
|
||||
#define CRYPTO_CCM(c) ((c)->ccmaes[CRYPTO_AEAD_AES_CCM])
|
||||
@@ -53,7 +50,6 @@ void ksmbd_release_crypto_ctx(struct ksmbd_crypto_ctx *ctx);
|
||||
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacmd5(void);
|
||||
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacsha256(void);
|
||||
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_cmacaes(void);
|
||||
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_sha512(void);
|
||||
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_gcm(void);
|
||||
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_ccm(void);
|
||||
void ksmbd_crypto_destroy(void);
|
||||
|
||||
@@ -628,7 +628,6 @@ MODULE_SOFTDEP("pre: nls");
|
||||
MODULE_SOFTDEP("pre: aes");
|
||||
MODULE_SOFTDEP("pre: cmac");
|
||||
MODULE_SOFTDEP("pre: sha256");
|
||||
MODULE_SOFTDEP("pre: sha512");
|
||||
MODULE_SOFTDEP("pre: aead2");
|
||||
MODULE_SOFTDEP("pre: ccm");
|
||||
MODULE_SOFTDEP("pre: gcm");
|
||||
|
||||
Reference in New Issue
Block a user