| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Symmetric key ciphers. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * 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 | 6 | */ |
|---|
| 12 | 7 | |
|---|
| 13 | 8 | #ifndef _CRYPTO_INTERNAL_SKCIPHER_H |
|---|
| 14 | 9 | #define _CRYPTO_INTERNAL_SKCIPHER_H |
|---|
| 15 | 10 | |
|---|
| 16 | 11 | #include <crypto/algapi.h> |
|---|
| 12 | +#include <crypto/internal/cipher.h> |
|---|
| 17 | 13 | #include <crypto/skcipher.h> |
|---|
| 18 | 14 | #include <linux/list.h> |
|---|
| 19 | 15 | #include <linux/types.h> |
|---|
| .. | .. |
|---|
| 70 | 66 | unsigned int alignmask; |
|---|
| 71 | 67 | }; |
|---|
| 72 | 68 | |
|---|
| 73 | | -extern const struct crypto_type crypto_givcipher_type; |
|---|
| 74 | | - |
|---|
| 75 | 69 | static inline struct crypto_instance *skcipher_crypto_instance( |
|---|
| 76 | 70 | struct skcipher_instance *inst) |
|---|
| 77 | 71 | { |
|---|
| .. | .. |
|---|
| 95 | 89 | req->base.complete(&req->base, err); |
|---|
| 96 | 90 | } |
|---|
| 97 | 91 | |
|---|
| 98 | | -static inline void crypto_set_skcipher_spawn( |
|---|
| 99 | | - struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst) |
|---|
| 100 | | -{ |
|---|
| 101 | | - crypto_set_spawn(&spawn->base, inst); |
|---|
| 102 | | -} |
|---|
| 103 | | - |
|---|
| 104 | | -int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name, |
|---|
| 105 | | - u32 type, u32 mask); |
|---|
| 92 | +int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, |
|---|
| 93 | + struct crypto_instance *inst, |
|---|
| 94 | + const char *name, u32 type, u32 mask); |
|---|
| 106 | 95 | |
|---|
| 107 | 96 | static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn) |
|---|
| 108 | 97 | { |
|---|
| .. | .. |
|---|
| 147 | 136 | void skcipher_walk_atomise(struct skcipher_walk *walk); |
|---|
| 148 | 137 | int skcipher_walk_async(struct skcipher_walk *walk, |
|---|
| 149 | 138 | struct skcipher_request *req); |
|---|
| 150 | | -int skcipher_walk_aead(struct skcipher_walk *walk, struct aead_request *req, |
|---|
| 151 | | - bool atomic); |
|---|
| 152 | 139 | int skcipher_walk_aead_encrypt(struct skcipher_walk *walk, |
|---|
| 153 | 140 | struct aead_request *req, bool atomic); |
|---|
| 154 | 141 | int skcipher_walk_aead_decrypt(struct skcipher_walk *walk, |
|---|
| 155 | 142 | struct aead_request *req, bool atomic); |
|---|
| 156 | 143 | void skcipher_walk_complete(struct skcipher_walk *walk, int err); |
|---|
| 157 | 144 | |
|---|
| 158 | | -static inline void ablkcipher_request_complete(struct ablkcipher_request *req, |
|---|
| 159 | | - int err) |
|---|
| 145 | +static inline void skcipher_walk_abort(struct skcipher_walk *walk) |
|---|
| 160 | 146 | { |
|---|
| 161 | | - req->base.complete(&req->base, err); |
|---|
| 162 | | -} |
|---|
| 163 | | - |
|---|
| 164 | | -static inline u32 ablkcipher_request_flags(struct ablkcipher_request *req) |
|---|
| 165 | | -{ |
|---|
| 166 | | - return req->base.flags; |
|---|
| 147 | + skcipher_walk_done(walk, -ECANCELED); |
|---|
| 167 | 148 | } |
|---|
| 168 | 149 | |
|---|
| 169 | 150 | static inline void *crypto_skcipher_ctx(struct crypto_skcipher *tfm) |
|---|
| .. | .. |
|---|
| 184 | 165 | static inline unsigned int crypto_skcipher_alg_min_keysize( |
|---|
| 185 | 166 | struct skcipher_alg *alg) |
|---|
| 186 | 167 | { |
|---|
| 187 | | - if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) == |
|---|
| 188 | | - CRYPTO_ALG_TYPE_BLKCIPHER) |
|---|
| 189 | | - return alg->base.cra_blkcipher.min_keysize; |
|---|
| 190 | | - |
|---|
| 191 | | - if (alg->base.cra_ablkcipher.encrypt) |
|---|
| 192 | | - return alg->base.cra_ablkcipher.min_keysize; |
|---|
| 193 | | - |
|---|
| 194 | 168 | return alg->min_keysize; |
|---|
| 195 | 169 | } |
|---|
| 196 | 170 | |
|---|
| 197 | 171 | static inline unsigned int crypto_skcipher_alg_max_keysize( |
|---|
| 198 | 172 | struct skcipher_alg *alg) |
|---|
| 199 | 173 | { |
|---|
| 200 | | - if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) == |
|---|
| 201 | | - CRYPTO_ALG_TYPE_BLKCIPHER) |
|---|
| 202 | | - return alg->base.cra_blkcipher.max_keysize; |
|---|
| 203 | | - |
|---|
| 204 | | - if (alg->base.cra_ablkcipher.encrypt) |
|---|
| 205 | | - return alg->base.cra_ablkcipher.max_keysize; |
|---|
| 206 | | - |
|---|
| 207 | 174 | return alg->max_keysize; |
|---|
| 208 | 175 | } |
|---|
| 209 | 176 | |
|---|
| 177 | +static inline unsigned int crypto_skcipher_alg_walksize( |
|---|
| 178 | + struct skcipher_alg *alg) |
|---|
| 179 | +{ |
|---|
| 180 | + return alg->walksize; |
|---|
| 181 | +} |
|---|
| 182 | + |
|---|
| 183 | +/** |
|---|
| 184 | + * crypto_skcipher_walksize() - obtain walk size |
|---|
| 185 | + * @tfm: cipher handle |
|---|
| 186 | + * |
|---|
| 187 | + * In some cases, algorithms can only perform optimally when operating on |
|---|
| 188 | + * multiple blocks in parallel. This is reflected by the walksize, which |
|---|
| 189 | + * must be a multiple of the chunksize (or equal if the concern does not |
|---|
| 190 | + * apply) |
|---|
| 191 | + * |
|---|
| 192 | + * Return: walk size in bytes |
|---|
| 193 | + */ |
|---|
| 194 | +static inline unsigned int crypto_skcipher_walksize( |
|---|
| 195 | + struct crypto_skcipher *tfm) |
|---|
| 196 | +{ |
|---|
| 197 | + return crypto_skcipher_alg_walksize(crypto_skcipher_alg(tfm)); |
|---|
| 198 | +} |
|---|
| 199 | + |
|---|
| 200 | +/* Helpers for simple block cipher modes of operation */ |
|---|
| 201 | +struct skcipher_ctx_simple { |
|---|
| 202 | + struct crypto_cipher *cipher; /* underlying block cipher */ |
|---|
| 203 | +}; |
|---|
| 204 | +static inline struct crypto_cipher * |
|---|
| 205 | +skcipher_cipher_simple(struct crypto_skcipher *tfm) |
|---|
| 206 | +{ |
|---|
| 207 | + struct skcipher_ctx_simple *ctx = crypto_skcipher_ctx(tfm); |
|---|
| 208 | + |
|---|
| 209 | + return ctx->cipher; |
|---|
| 210 | +} |
|---|
| 211 | + |
|---|
| 212 | +struct skcipher_instance *skcipher_alloc_instance_simple( |
|---|
| 213 | + struct crypto_template *tmpl, struct rtattr **tb); |
|---|
| 214 | + |
|---|
| 215 | +static inline struct crypto_alg *skcipher_ialg_simple( |
|---|
| 216 | + struct skcipher_instance *inst) |
|---|
| 217 | +{ |
|---|
| 218 | + struct crypto_cipher_spawn *spawn = skcipher_instance_ctx(inst); |
|---|
| 219 | + |
|---|
| 220 | + return crypto_spawn_cipher_alg(spawn); |
|---|
| 221 | +} |
|---|
| 222 | + |
|---|
| 210 | 223 | #endif /* _CRYPTO_INTERNAL_SKCIPHER_H */ |
|---|
| 211 | 224 | |
|---|