blob: b3a46c515d1b7ed2cedb5185898e9b6a685ea434 [file] [log] [blame]
Herbert Xu378f4f52007-12-17 20:07:31 +08001/*
2 * Symmetric key ciphers.
3 *
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#ifndef _CRYPTO_INTERNAL_SKCIPHER_H
14#define _CRYPTO_INTERNAL_SKCIPHER_H
15
16#include <crypto/algapi.h>
Herbert Xu61da88e2007-12-17 21:51:27 +080017#include <crypto/skcipher.h>
Herbert Xuecfc4322007-12-05 21:08:36 +110018#include <linux/types.h>
19
20struct rtattr;
Herbert Xu378f4f52007-12-17 20:07:31 +080021
22struct crypto_skcipher_spawn {
23 struct crypto_spawn base;
24};
25
Herbert Xu61da88e2007-12-17 21:51:27 +080026extern const struct crypto_type crypto_givcipher_type;
27
Herbert Xu378f4f52007-12-17 20:07:31 +080028static inline void crypto_set_skcipher_spawn(
29 struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst)
30{
31 crypto_set_spawn(&spawn->base, inst);
32}
33
34int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
35 u32 type, u32 mask);
36
Steffen Klassert1e122992012-03-29 09:03:47 +020037struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type, u32 mask);
38
Herbert Xu378f4f52007-12-17 20:07:31 +080039static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn)
40{
41 crypto_drop_spawn(&spawn->base);
42}
43
44static inline struct crypto_alg *crypto_skcipher_spawn_alg(
45 struct crypto_skcipher_spawn *spawn)
46{
47 return spawn->base.alg;
48}
49
50static inline struct crypto_ablkcipher *crypto_spawn_skcipher(
51 struct crypto_skcipher_spawn *spawn)
52{
53 return __crypto_ablkcipher_cast(
54 crypto_spawn_tfm(&spawn->base, crypto_skcipher_type(0),
55 crypto_skcipher_mask(0)));
56}
57
Herbert Xub9c55aa2007-12-04 12:46:48 +110058int skcipher_null_givencrypt(struct skcipher_givcrypt_request *req);
59int skcipher_null_givdecrypt(struct skcipher_givcrypt_request *req);
Herbert Xuecfc4322007-12-05 21:08:36 +110060const char *crypto_default_geniv(const struct crypto_alg *alg);
61
62struct crypto_instance *skcipher_geniv_alloc(struct crypto_template *tmpl,
63 struct rtattr **tb, u32 type,
64 u32 mask);
65void skcipher_geniv_free(struct crypto_instance *inst);
66int skcipher_geniv_init(struct crypto_tfm *tfm);
67void skcipher_geniv_exit(struct crypto_tfm *tfm);
68
69static inline struct crypto_ablkcipher *skcipher_geniv_cipher(
70 struct crypto_ablkcipher *geniv)
71{
72 return crypto_ablkcipher_crt(geniv)->base;
73}
74
Herbert Xue7cd2512007-12-14 22:28:14 +080075static inline int skcipher_enqueue_givcrypt(
76 struct crypto_queue *queue, struct skcipher_givcrypt_request *request)
77{
78 return ablkcipher_enqueue_request(queue, &request->creq);
79}
80
81static inline struct skcipher_givcrypt_request *skcipher_dequeue_givcrypt(
82 struct crypto_queue *queue)
83{
Marek Vasutd656c182014-05-26 18:51:48 +020084 return skcipher_givcrypt_cast(crypto_dequeue_request(queue));
Herbert Xue7cd2512007-12-14 22:28:14 +080085}
86
Herbert Xu61da88e2007-12-17 21:51:27 +080087static inline void *skcipher_givcrypt_reqctx(
88 struct skcipher_givcrypt_request *req)
89{
90 return ablkcipher_request_ctx(&req->creq);
91}
92
Herbert Xu15c67282007-11-30 20:17:28 +110093static inline void ablkcipher_request_complete(struct ablkcipher_request *req,
94 int err)
95{
96 req->base.complete(&req->base, err);
97}
98
99static inline void skcipher_givcrypt_complete(
100 struct skcipher_givcrypt_request *req, int err)
101{
102 ablkcipher_request_complete(&req->creq, err);
103}
104
Herbert Xu3631c652007-12-13 22:28:59 +0800105static inline u32 ablkcipher_request_flags(struct ablkcipher_request *req)
106{
107 return req->base.flags;
108}
109
Herbert Xu378f4f52007-12-17 20:07:31 +0800110#endif /* _CRYPTO_INTERNAL_SKCIPHER_H */
111