Merge branch 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorri...
[linux-2.6-block.git] / include / crypto / morus1280_glue.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * The MORUS-1280 Authenticated-Encryption Algorithm
4  *   Common glue skeleton -- header file
5  *
6  * Copyright (c) 2016-2018 Ondrej Mosnacek <omosnacek@gmail.com>
7  * Copyright (C) 2017-2018 Red Hat, Inc. All rights reserved.
8  */
9
10 #ifndef _CRYPTO_MORUS1280_GLUE_H
11 #define _CRYPTO_MORUS1280_GLUE_H
12
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <crypto/algapi.h>
16 #include <crypto/aead.h>
17 #include <crypto/morus_common.h>
18
19 #define MORUS1280_WORD_SIZE 8
20 #define MORUS1280_BLOCK_SIZE (MORUS_BLOCK_WORDS * MORUS1280_WORD_SIZE)
21
22 struct morus1280_block {
23         u8 bytes[MORUS1280_BLOCK_SIZE];
24 };
25
26 struct morus1280_glue_ops {
27         void (*init)(void *state, const void *key, const void *iv);
28         void (*ad)(void *state, const void *data, unsigned int length);
29         void (*enc)(void *state, const void *src, void *dst, unsigned int length);
30         void (*dec)(void *state, const void *src, void *dst, unsigned int length);
31         void (*enc_tail)(void *state, const void *src, void *dst, unsigned int length);
32         void (*dec_tail)(void *state, const void *src, void *dst, unsigned int length);
33         void (*final)(void *state, void *tag_xor, u64 assoclen, u64 cryptlen);
34 };
35
36 struct morus1280_ctx {
37         const struct morus1280_glue_ops *ops;
38         struct morus1280_block key;
39 };
40
41 void crypto_morus1280_glue_init_ops(struct crypto_aead *aead,
42                                     const struct morus1280_glue_ops *ops);
43 int crypto_morus1280_glue_setkey(struct crypto_aead *aead, const u8 *key,
44                                  unsigned int keylen);
45 int crypto_morus1280_glue_setauthsize(struct crypto_aead *tfm,
46                                       unsigned int authsize);
47 int crypto_morus1280_glue_encrypt(struct aead_request *req);
48 int crypto_morus1280_glue_decrypt(struct aead_request *req);
49
50 int cryptd_morus1280_glue_setkey(struct crypto_aead *aead, const u8 *key,
51                                  unsigned int keylen);
52 int cryptd_morus1280_glue_setauthsize(struct crypto_aead *aead,
53                                       unsigned int authsize);
54 int cryptd_morus1280_glue_encrypt(struct aead_request *req);
55 int cryptd_morus1280_glue_decrypt(struct aead_request *req);
56 int cryptd_morus1280_glue_init_tfm(struct crypto_aead *aead);
57 void cryptd_morus1280_glue_exit_tfm(struct crypto_aead *aead);
58
59 #define MORUS1280_DECLARE_ALGS(id, driver_name, priority) \
60         static const struct morus1280_glue_ops crypto_morus1280_##id##_ops = {\
61                 .init = crypto_morus1280_##id##_init, \
62                 .ad = crypto_morus1280_##id##_ad, \
63                 .enc = crypto_morus1280_##id##_enc, \
64                 .enc_tail = crypto_morus1280_##id##_enc_tail, \
65                 .dec = crypto_morus1280_##id##_dec, \
66                 .dec_tail = crypto_morus1280_##id##_dec_tail, \
67                 .final = crypto_morus1280_##id##_final, \
68         }; \
69         \
70         static int crypto_morus1280_##id##_init_tfm(struct crypto_aead *tfm) \
71         { \
72                 crypto_morus1280_glue_init_ops(tfm, &crypto_morus1280_##id##_ops); \
73                 return 0; \
74         } \
75         \
76         static void crypto_morus1280_##id##_exit_tfm(struct crypto_aead *tfm) \
77         { \
78         } \
79         \
80         static struct aead_alg crypto_morus1280_##id##_algs[] = {\
81                 { \
82                         .setkey = crypto_morus1280_glue_setkey, \
83                         .setauthsize = crypto_morus1280_glue_setauthsize, \
84                         .encrypt = crypto_morus1280_glue_encrypt, \
85                         .decrypt = crypto_morus1280_glue_decrypt, \
86                         .init = crypto_morus1280_##id##_init_tfm, \
87                         .exit = crypto_morus1280_##id##_exit_tfm, \
88                         \
89                         .ivsize = MORUS_NONCE_SIZE, \
90                         .maxauthsize = MORUS_MAX_AUTH_SIZE, \
91                         .chunksize = MORUS1280_BLOCK_SIZE, \
92                         \
93                         .base = { \
94                                 .cra_flags = CRYPTO_ALG_INTERNAL, \
95                                 .cra_blocksize = 1, \
96                                 .cra_ctxsize = sizeof(struct morus1280_ctx), \
97                                 .cra_alignmask = 0, \
98                                 \
99                                 .cra_name = "__morus1280", \
100                                 .cra_driver_name = "__"driver_name, \
101                                 \
102                                 .cra_module = THIS_MODULE, \
103                         } \
104                 }, { \
105                         .setkey = cryptd_morus1280_glue_setkey, \
106                         .setauthsize = cryptd_morus1280_glue_setauthsize, \
107                         .encrypt = cryptd_morus1280_glue_encrypt, \
108                         .decrypt = cryptd_morus1280_glue_decrypt, \
109                         .init = cryptd_morus1280_glue_init_tfm, \
110                         .exit = cryptd_morus1280_glue_exit_tfm, \
111                         \
112                         .ivsize = MORUS_NONCE_SIZE, \
113                         .maxauthsize = MORUS_MAX_AUTH_SIZE, \
114                         .chunksize = MORUS1280_BLOCK_SIZE, \
115                         \
116                         .base = { \
117                                 .cra_flags = CRYPTO_ALG_ASYNC, \
118                                 .cra_blocksize = 1, \
119                                 .cra_ctxsize = sizeof(struct crypto_aead *), \
120                                 .cra_alignmask = 0, \
121                                 \
122                                 .cra_priority = priority, \
123                                 \
124                                 .cra_name = "morus1280", \
125                                 .cra_driver_name = driver_name, \
126                                 \
127                                 .cra_module = THIS_MODULE, \
128                         } \
129                 } \
130         }
131
132 #endif /* _CRYPTO_MORUS1280_GLUE_H */