Herbert Xu | 378f4f5 | 2007-12-17 20:07:31 +0800 | [diff] [blame] | 1 | /* |
| 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 Xu | 61da88e | 2007-12-17 21:51:27 +0800 | [diff] [blame] | 17 | #include <crypto/skcipher.h> |
Herbert Xu | ecfc432 | 2007-12-05 21:08:36 +1100 | [diff] [blame] | 18 | #include <linux/types.h> |
| 19 | |
| 20 | struct rtattr; |
Herbert Xu | 378f4f5 | 2007-12-17 20:07:31 +0800 | [diff] [blame] | 21 | |
Herbert Xu | 4e6c3df | 2016-07-12 13:17:31 +0800 | [diff] [blame] | 22 | struct skcipher_instance { |
| 23 | void (*free)(struct skcipher_instance *inst); |
| 24 | union { |
| 25 | struct { |
| 26 | char head[offsetof(struct skcipher_alg, base)]; |
| 27 | struct crypto_instance base; |
| 28 | } s; |
| 29 | struct skcipher_alg alg; |
| 30 | }; |
| 31 | }; |
| 32 | |
Herbert Xu | 378f4f5 | 2007-12-17 20:07:31 +0800 | [diff] [blame] | 33 | struct crypto_skcipher_spawn { |
| 34 | struct crypto_spawn base; |
| 35 | }; |
| 36 | |
Herbert Xu | 61da88e | 2007-12-17 21:51:27 +0800 | [diff] [blame] | 37 | extern const struct crypto_type crypto_givcipher_type; |
| 38 | |
Herbert Xu | 4e6c3df | 2016-07-12 13:17:31 +0800 | [diff] [blame] | 39 | static inline struct crypto_instance *skcipher_crypto_instance( |
| 40 | struct skcipher_instance *inst) |
| 41 | { |
| 42 | return &inst->s.base; |
| 43 | } |
| 44 | |
| 45 | static inline struct skcipher_instance *skcipher_alg_instance( |
| 46 | struct crypto_skcipher *skcipher) |
| 47 | { |
| 48 | return container_of(crypto_skcipher_alg(skcipher), |
| 49 | struct skcipher_instance, alg); |
| 50 | } |
| 51 | |
| 52 | static inline void *skcipher_instance_ctx(struct skcipher_instance *inst) |
| 53 | { |
| 54 | return crypto_instance_ctx(skcipher_crypto_instance(inst)); |
| 55 | } |
| 56 | |
| 57 | static inline void skcipher_request_complete(struct skcipher_request *req, int err) |
| 58 | { |
| 59 | req->base.complete(&req->base, err); |
| 60 | } |
| 61 | |
Herbert Xu | 378f4f5 | 2007-12-17 20:07:31 +0800 | [diff] [blame] | 62 | static inline void crypto_set_skcipher_spawn( |
| 63 | struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst) |
| 64 | { |
| 65 | crypto_set_spawn(&spawn->base, inst); |
| 66 | } |
| 67 | |
| 68 | int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name, |
| 69 | u32 type, u32 mask); |
Herbert Xu | 3a01d0e | 2016-07-12 13:17:50 +0800 | [diff] [blame] | 70 | |
| 71 | static inline int crypto_grab_skcipher2(struct crypto_skcipher_spawn *spawn, |
| 72 | const char *name, u32 type, u32 mask) |
| 73 | { |
| 74 | return crypto_grab_skcipher(spawn, name, type, mask); |
| 75 | } |
Herbert Xu | 378f4f5 | 2007-12-17 20:07:31 +0800 | [diff] [blame] | 76 | |
Steffen Klassert | 1e12299 | 2012-03-29 09:03:47 +0200 | [diff] [blame] | 77 | struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type, u32 mask); |
| 78 | |
Herbert Xu | 378f4f5 | 2007-12-17 20:07:31 +0800 | [diff] [blame] | 79 | static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn) |
| 80 | { |
| 81 | crypto_drop_spawn(&spawn->base); |
| 82 | } |
| 83 | |
Herbert Xu | 3a01d0e | 2016-07-12 13:17:50 +0800 | [diff] [blame] | 84 | static inline struct skcipher_alg *crypto_skcipher_spawn_alg( |
Herbert Xu | 4e6c3df | 2016-07-12 13:17:31 +0800 | [diff] [blame] | 85 | struct crypto_skcipher_spawn *spawn) |
| 86 | { |
| 87 | return container_of(spawn->base.alg, struct skcipher_alg, base); |
| 88 | } |
| 89 | |
Herbert Xu | 3a01d0e | 2016-07-12 13:17:50 +0800 | [diff] [blame] | 90 | static inline struct skcipher_alg *crypto_spawn_skcipher_alg( |
Herbert Xu | 378f4f5 | 2007-12-17 20:07:31 +0800 | [diff] [blame] | 91 | struct crypto_skcipher_spawn *spawn) |
| 92 | { |
Herbert Xu | 3a01d0e | 2016-07-12 13:17:50 +0800 | [diff] [blame] | 93 | return crypto_skcipher_spawn_alg(spawn); |
| 94 | } |
| 95 | |
| 96 | static inline struct crypto_skcipher *crypto_spawn_skcipher( |
| 97 | struct crypto_skcipher_spawn *spawn) |
| 98 | { |
| 99 | return crypto_spawn_tfm2(&spawn->base); |
Herbert Xu | 378f4f5 | 2007-12-17 20:07:31 +0800 | [diff] [blame] | 100 | } |
| 101 | |
Herbert Xu | 4e6c3df | 2016-07-12 13:17:31 +0800 | [diff] [blame] | 102 | static inline struct crypto_skcipher *crypto_spawn_skcipher2( |
| 103 | struct crypto_skcipher_spawn *spawn) |
| 104 | { |
Herbert Xu | 3a01d0e | 2016-07-12 13:17:50 +0800 | [diff] [blame] | 105 | return crypto_spawn_skcipher(spawn); |
Herbert Xu | 4e6c3df | 2016-07-12 13:17:31 +0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static inline void crypto_skcipher_set_reqsize( |
| 109 | struct crypto_skcipher *skcipher, unsigned int reqsize) |
| 110 | { |
| 111 | skcipher->reqsize = reqsize; |
| 112 | } |
| 113 | |
| 114 | int crypto_register_skcipher(struct skcipher_alg *alg); |
| 115 | void crypto_unregister_skcipher(struct skcipher_alg *alg); |
| 116 | int crypto_register_skciphers(struct skcipher_alg *algs, int count); |
| 117 | void crypto_unregister_skciphers(struct skcipher_alg *algs, int count); |
| 118 | int skcipher_register_instance(struct crypto_template *tmpl, |
| 119 | struct skcipher_instance *inst); |
| 120 | |
Herbert Xu | 15c6728 | 2007-11-30 20:17:28 +1100 | [diff] [blame] | 121 | static inline void ablkcipher_request_complete(struct ablkcipher_request *req, |
| 122 | int err) |
| 123 | { |
| 124 | req->base.complete(&req->base, err); |
| 125 | } |
| 126 | |
Herbert Xu | 3631c65 | 2007-12-13 22:28:59 +0800 | [diff] [blame] | 127 | static inline u32 ablkcipher_request_flags(struct ablkcipher_request *req) |
| 128 | { |
| 129 | return req->base.flags; |
| 130 | } |
| 131 | |
Herbert Xu | 7a7ffe6 | 2015-08-20 15:21:45 +0800 | [diff] [blame] | 132 | static inline void *crypto_skcipher_ctx(struct crypto_skcipher *tfm) |
| 133 | { |
| 134 | return crypto_tfm_ctx(&tfm->base); |
| 135 | } |
| 136 | |
| 137 | static inline void *skcipher_request_ctx(struct skcipher_request *req) |
| 138 | { |
| 139 | return req->__ctx; |
| 140 | } |
| 141 | |
| 142 | static inline u32 skcipher_request_flags(struct skcipher_request *req) |
| 143 | { |
| 144 | return req->base.flags; |
| 145 | } |
| 146 | |
Herbert Xu | 4e6c3df | 2016-07-12 13:17:31 +0800 | [diff] [blame] | 147 | static inline unsigned int crypto_skcipher_alg_min_keysize( |
| 148 | struct skcipher_alg *alg) |
| 149 | { |
| 150 | if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) == |
| 151 | CRYPTO_ALG_TYPE_BLKCIPHER) |
| 152 | return alg->base.cra_blkcipher.min_keysize; |
| 153 | |
| 154 | if (alg->base.cra_ablkcipher.encrypt) |
| 155 | return alg->base.cra_ablkcipher.min_keysize; |
| 156 | |
| 157 | return alg->min_keysize; |
| 158 | } |
| 159 | |
| 160 | static inline unsigned int crypto_skcipher_alg_max_keysize( |
| 161 | struct skcipher_alg *alg) |
| 162 | { |
| 163 | if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) == |
| 164 | CRYPTO_ALG_TYPE_BLKCIPHER) |
| 165 | return alg->base.cra_blkcipher.max_keysize; |
| 166 | |
| 167 | if (alg->base.cra_ablkcipher.encrypt) |
| 168 | return alg->base.cra_ablkcipher.max_keysize; |
| 169 | |
| 170 | return alg->max_keysize; |
| 171 | } |
| 172 | |
Herbert Xu | 378f4f5 | 2007-12-17 20:07:31 +0800 | [diff] [blame] | 173 | #endif /* _CRYPTO_INTERNAL_SKCIPHER_H */ |
| 174 | |