Merge branch 'work.init' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[platform/kernel/linux-starfive.git] / fs / ksmbd / crypto_ctx.h
1 /* 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
12 enum {
13         CRYPTO_SHASH_HMACMD5    = 0,
14         CRYPTO_SHASH_HMACSHA256,
15         CRYPTO_SHASH_CMACAES,
16         CRYPTO_SHASH_SHA256,
17         CRYPTO_SHASH_SHA512,
18         CRYPTO_SHASH_MD4,
19         CRYPTO_SHASH_MD5,
20         CRYPTO_SHASH_MAX,
21 };
22
23 enum {
24         CRYPTO_AEAD_AES_GCM = 16,
25         CRYPTO_AEAD_AES_CCM,
26         CRYPTO_AEAD_MAX,
27 };
28
29 enum {
30         CRYPTO_BLK_ECBDES       = 32,
31         CRYPTO_BLK_MAX,
32 };
33
34 struct ksmbd_crypto_ctx {
35         struct list_head                list;
36
37         struct shash_desc               *desc[CRYPTO_SHASH_MAX];
38         struct crypto_aead              *ccmaes[CRYPTO_AEAD_MAX];
39 };
40
41 #define CRYPTO_HMACMD5(c)       ((c)->desc[CRYPTO_SHASH_HMACMD5])
42 #define CRYPTO_HMACSHA256(c)    ((c)->desc[CRYPTO_SHASH_HMACSHA256])
43 #define CRYPTO_CMACAES(c)       ((c)->desc[CRYPTO_SHASH_CMACAES])
44 #define CRYPTO_SHA256(c)        ((c)->desc[CRYPTO_SHASH_SHA256])
45 #define CRYPTO_SHA512(c)        ((c)->desc[CRYPTO_SHASH_SHA512])
46 #define CRYPTO_MD4(c)           ((c)->desc[CRYPTO_SHASH_MD4])
47 #define CRYPTO_MD5(c)           ((c)->desc[CRYPTO_SHASH_MD5])
48
49 #define CRYPTO_HMACMD5_TFM(c)   ((c)->desc[CRYPTO_SHASH_HMACMD5]->tfm)
50 #define CRYPTO_HMACSHA256_TFM(c)\
51                                 ((c)->desc[CRYPTO_SHASH_HMACSHA256]->tfm)
52 #define CRYPTO_CMACAES_TFM(c)   ((c)->desc[CRYPTO_SHASH_CMACAES]->tfm)
53 #define CRYPTO_SHA256_TFM(c)    ((c)->desc[CRYPTO_SHASH_SHA256]->tfm)
54 #define CRYPTO_SHA512_TFM(c)    ((c)->desc[CRYPTO_SHASH_SHA512]->tfm)
55 #define CRYPTO_MD4_TFM(c)       ((c)->desc[CRYPTO_SHASH_MD4]->tfm)
56 #define CRYPTO_MD5_TFM(c)       ((c)->desc[CRYPTO_SHASH_MD5]->tfm)
57
58 #define CRYPTO_GCM(c)           ((c)->ccmaes[CRYPTO_AEAD_AES_GCM])
59 #define CRYPTO_CCM(c)           ((c)->ccmaes[CRYPTO_AEAD_AES_CCM])
60
61 void ksmbd_release_crypto_ctx(struct ksmbd_crypto_ctx *ctx);
62 struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacmd5(void);
63 struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacsha256(void);
64 struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_cmacaes(void);
65 struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_sha512(void);
66 struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_sha256(void);
67 struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_md4(void);
68 struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_md5(void);
69 struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_gcm(void);
70 struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_ccm(void);
71 void ksmbd_crypto_destroy(void);
72 int ksmbd_crypto_create(void);
73
74 #endif /* __CRYPTO_CTX_H__ */