1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Shared glue code for 128bit block ciphers
6 #ifndef _CRYPTO_GLUE_HELPER_H
7 #define _CRYPTO_GLUE_HELPER_H
9 #include <crypto/internal/skcipher.h>
10 #include <linux/kernel.h>
11 #include <asm/fpu/api.h>
13 typedef void (*common_glue_func_t)(const void *ctx, u8 *dst, const u8 *src);
14 typedef void (*common_glue_cbc_func_t)(const void *ctx, u8 *dst, const u8 *src);
16 struct common_glue_func_entry {
17 unsigned int num_blocks; /* number of blocks that @fn will process */
19 common_glue_func_t ecb;
20 common_glue_cbc_func_t cbc;
24 struct common_glue_ctx {
25 unsigned int num_funcs;
26 int fpu_blocks_limit; /* -1 means fpu not needed at all */
29 * First funcs entry must have largest num_blocks and last funcs entry
30 * must have num_blocks == 1!
32 struct common_glue_func_entry funcs[];
35 static inline bool glue_fpu_begin(unsigned int bsize, int fpu_blocks_limit,
36 struct skcipher_walk *walk,
37 bool fpu_enabled, unsigned int nbytes)
39 if (likely(fpu_blocks_limit < 0))
46 * Vector-registers are only used when chunk to be processed is large
47 * enough, so do not enable FPU until it is necessary.
49 if (nbytes < bsize * (unsigned int)fpu_blocks_limit)
52 /* prevent sleeping if FPU is in use */
53 skcipher_walk_atomise(walk);
59 static inline void glue_fpu_end(bool fpu_enabled)
65 extern int glue_ecb_req_128bit(const struct common_glue_ctx *gctx,
66 struct skcipher_request *req);
68 extern int glue_cbc_encrypt_req_128bit(const common_glue_func_t fn,
69 struct skcipher_request *req);
71 extern int glue_cbc_decrypt_req_128bit(const struct common_glue_ctx *gctx,
72 struct skcipher_request *req);
74 #endif /* _CRYPTO_GLUE_HELPER_H */