blob: 4a367c62f6536662979a3cb4caf8ad2a253fcb9a [file] [log] [blame]
Namjae Jeone2f34482021-03-16 10:49:09 +09001/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Copyright (C) 2019 Samsung Electronics Co., Ltd.
4 */
5
6#ifndef __CRYPTO_CTX_H__
7#define __CRYPTO_CTX_H__
8
9#include <crypto/hash.h>
10#include <crypto/aead.h>
11
12enum {
13 CRYPTO_SHASH_HMACMD5 = 0,
14 CRYPTO_SHASH_HMACSHA256,
15 CRYPTO_SHASH_CMACAES,
16 CRYPTO_SHASH_SHA256,
17 CRYPTO_SHASH_SHA512,
Namjae Jeone2f34482021-03-16 10:49:09 +090018 CRYPTO_SHASH_MAX,
19};
20
21enum {
Namjae Jeon5a0ca772021-05-06 11:43:37 +090022 CRYPTO_AEAD_AES_GCM = 16,
23 CRYPTO_AEAD_AES_CCM,
Namjae Jeone2f34482021-03-16 10:49:09 +090024 CRYPTO_AEAD_MAX,
25};
26
27enum {
28 CRYPTO_BLK_ECBDES = 32,
29 CRYPTO_BLK_MAX,
30};
31
32struct ksmbd_crypto_ctx {
33 struct list_head list;
34
35 struct shash_desc *desc[CRYPTO_SHASH_MAX];
36 struct crypto_aead *ccmaes[CRYPTO_AEAD_MAX];
37};
38
39#define CRYPTO_HMACMD5(c) ((c)->desc[CRYPTO_SHASH_HMACMD5])
40#define CRYPTO_HMACSHA256(c) ((c)->desc[CRYPTO_SHASH_HMACSHA256])
41#define CRYPTO_CMACAES(c) ((c)->desc[CRYPTO_SHASH_CMACAES])
42#define CRYPTO_SHA256(c) ((c)->desc[CRYPTO_SHASH_SHA256])
43#define CRYPTO_SHA512(c) ((c)->desc[CRYPTO_SHASH_SHA512])
Namjae Jeone2f34482021-03-16 10:49:09 +090044
45#define CRYPTO_HMACMD5_TFM(c) ((c)->desc[CRYPTO_SHASH_HMACMD5]->tfm)
46#define CRYPTO_HMACSHA256_TFM(c)\
47 ((c)->desc[CRYPTO_SHASH_HMACSHA256]->tfm)
48#define CRYPTO_CMACAES_TFM(c) ((c)->desc[CRYPTO_SHASH_CMACAES]->tfm)
49#define CRYPTO_SHA256_TFM(c) ((c)->desc[CRYPTO_SHASH_SHA256]->tfm)
50#define CRYPTO_SHA512_TFM(c) ((c)->desc[CRYPTO_SHASH_SHA512]->tfm)
Namjae Jeone2f34482021-03-16 10:49:09 +090051
Namjae Jeon5a0ca772021-05-06 11:43:37 +090052#define CRYPTO_GCM(c) ((c)->ccmaes[CRYPTO_AEAD_AES_GCM])
53#define CRYPTO_CCM(c) ((c)->ccmaes[CRYPTO_AEAD_AES_CCM])
Namjae Jeone2f34482021-03-16 10:49:09 +090054
55void ksmbd_release_crypto_ctx(struct ksmbd_crypto_ctx *ctx);
Namjae Jeone2f34482021-03-16 10:49:09 +090056struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacmd5(void);
57struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacsha256(void);
58struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_cmacaes(void);
59struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_sha512(void);
60struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_sha256(void);
Namjae Jeone2f34482021-03-16 10:49:09 +090061struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_gcm(void);
62struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_ccm(void);
Namjae Jeone2f34482021-03-16 10:49:09 +090063void ksmbd_crypto_destroy(void);
64int ksmbd_crypto_create(void);
65
66#endif /* __CRYPTO_CTX_H__ */