hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/include/crypto/skcipher.h
....@@ -1,13 +1,8 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * Symmetric key ciphers.
34 *
45 * Copyright (c) 2007-2015 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
- *
116 */
127
138 #ifndef _CRYPTO_SKCIPHER_H
....@@ -23,7 +18,7 @@
2318 * @iv: Initialisation Vector
2419 * @src: Source SG list
2520 * @dst: Destination SG list
26
- * @base: Underlying async request request
21
+ * @base: Underlying async request
2722 * @__ctx: Start of private context data
2823 */
2924 struct skcipher_request {
....@@ -39,28 +34,8 @@
3934 void *__ctx[] CRYPTO_MINALIGN_ATTR;
4035 };
4136
42
-/**
43
- * struct skcipher_givcrypt_request - Crypto request with IV generation
44
- * @seq: Sequence number for IV generation
45
- * @giv: Space for generated IV
46
- * @creq: The crypto request itself
47
- */
48
-struct skcipher_givcrypt_request {
49
- u64 seq;
50
- u8 *giv;
51
-
52
- struct ablkcipher_request creq;
53
-};
54
-
5537 struct crypto_skcipher {
56
- int (*setkey)(struct crypto_skcipher *tfm, const u8 *key,
57
- unsigned int keylen);
58
- int (*encrypt)(struct skcipher_request *req);
59
- int (*decrypt)(struct skcipher_request *req);
60
-
61
- unsigned int ivsize;
6238 unsigned int reqsize;
63
- unsigned int keysize;
6439
6540 struct crypto_tfm base;
6641 };
....@@ -156,11 +131,6 @@
156131 ] CRYPTO_MINALIGN_ATTR; \
157132 struct skcipher_request *name = (void *)__##name##_desc
158133
159
-#define SKCIPHER_REQUEST_ON_STACK(name, tfm) \
160
- char __##name##_desc[sizeof(struct skcipher_request) + \
161
- crypto_skcipher_reqsize(tfm)] CRYPTO_MINALIGN_ATTR; \
162
- struct skcipher_request *name = (void *)__##name##_desc
163
-
164134 /**
165135 * DOC: Symmetric Key Cipher API
166136 *
....@@ -243,30 +213,13 @@
243213 * crypto_has_skcipher() - Search for the availability of an skcipher.
244214 * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
245215 * skcipher
246
- * @type: specifies the type of the cipher
247
- * @mask: specifies the mask for the cipher
248
- *
249
- * Return: true when the skcipher is known to the kernel crypto API; false
250
- * otherwise
251
- */
252
-static inline int crypto_has_skcipher(const char *alg_name, u32 type,
253
- u32 mask)
254
-{
255
- return crypto_has_alg(alg_name, crypto_skcipher_type(type),
256
- crypto_skcipher_mask(mask));
257
-}
258
-
259
-/**
260
- * crypto_has_skcipher2() - Search for the availability of an skcipher.
261
- * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
262
- * skcipher
263216 * @type: specifies the type of the skcipher
264217 * @mask: specifies the mask for the skcipher
265218 *
266219 * Return: true when the skcipher is known to the kernel crypto API; false
267220 * otherwise
268221 */
269
-int crypto_has_skcipher2(const char *alg_name, u32 type, u32 mask);
222
+int crypto_has_skcipher(const char *alg_name, u32 type, u32 mask);
270223
271224 static inline const char *crypto_skcipher_driver_name(
272225 struct crypto_skcipher *tfm)
....@@ -283,13 +236,6 @@
283236
284237 static inline unsigned int crypto_skcipher_alg_ivsize(struct skcipher_alg *alg)
285238 {
286
- if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) ==
287
- CRYPTO_ALG_TYPE_BLKCIPHER)
288
- return alg->base.cra_blkcipher.ivsize;
289
-
290
- if (alg->base.cra_ablkcipher.encrypt)
291
- return alg->base.cra_ablkcipher.ivsize;
292
-
293239 return alg->ivsize;
294240 }
295241
....@@ -304,7 +250,7 @@
304250 */
305251 static inline unsigned int crypto_skcipher_ivsize(struct crypto_skcipher *tfm)
306252 {
307
- return tfm->ivsize;
253
+ return crypto_skcipher_alg(tfm)->ivsize;
308254 }
309255
310256 static inline unsigned int crypto_sync_skcipher_ivsize(
....@@ -313,30 +259,26 @@
313259 return crypto_skcipher_ivsize(&tfm->base);
314260 }
315261
262
+/**
263
+ * crypto_skcipher_blocksize() - obtain block size of cipher
264
+ * @tfm: cipher handle
265
+ *
266
+ * The block size for the skcipher referenced with the cipher handle is
267
+ * returned. The caller may use that information to allocate appropriate
268
+ * memory for the data returned by the encryption or decryption operation
269
+ *
270
+ * Return: block size of cipher
271
+ */
272
+static inline unsigned int crypto_skcipher_blocksize(
273
+ struct crypto_skcipher *tfm)
274
+{
275
+ return crypto_tfm_alg_blocksize(crypto_skcipher_tfm(tfm));
276
+}
277
+
316278 static inline unsigned int crypto_skcipher_alg_chunksize(
317279 struct skcipher_alg *alg)
318280 {
319
- if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) ==
320
- CRYPTO_ALG_TYPE_BLKCIPHER)
321
- return alg->base.cra_blocksize;
322
-
323
- if (alg->base.cra_ablkcipher.encrypt)
324
- return alg->base.cra_blocksize;
325
-
326281 return alg->chunksize;
327
-}
328
-
329
-static inline unsigned int crypto_skcipher_alg_walksize(
330
- struct skcipher_alg *alg)
331
-{
332
- if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) ==
333
- CRYPTO_ALG_TYPE_BLKCIPHER)
334
- return alg->base.cra_blocksize;
335
-
336
- if (alg->base.cra_ablkcipher.encrypt)
337
- return alg->base.cra_blocksize;
338
-
339
- return alg->walksize;
340282 }
341283
342284 /**
....@@ -354,39 +296,6 @@
354296 struct crypto_skcipher *tfm)
355297 {
356298 return crypto_skcipher_alg_chunksize(crypto_skcipher_alg(tfm));
357
-}
358
-
359
-/**
360
- * crypto_skcipher_walksize() - obtain walk size
361
- * @tfm: cipher handle
362
- *
363
- * In some cases, algorithms can only perform optimally when operating on
364
- * multiple blocks in parallel. This is reflected by the walksize, which
365
- * must be a multiple of the chunksize (or equal if the concern does not
366
- * apply)
367
- *
368
- * Return: walk size in bytes
369
- */
370
-static inline unsigned int crypto_skcipher_walksize(
371
- struct crypto_skcipher *tfm)
372
-{
373
- return crypto_skcipher_alg_walksize(crypto_skcipher_alg(tfm));
374
-}
375
-
376
-/**
377
- * crypto_skcipher_blocksize() - obtain block size of cipher
378
- * @tfm: cipher handle
379
- *
380
- * The block size for the skcipher referenced with the cipher handle is
381
- * returned. The caller may use that information to allocate appropriate
382
- * memory for the data returned by the encryption or decryption operation
383
- *
384
- * Return: block size of cipher
385
- */
386
-static inline unsigned int crypto_skcipher_blocksize(
387
- struct crypto_skcipher *tfm)
388
-{
389
- return crypto_tfm_alg_blocksize(crypto_skcipher_tfm(tfm));
390299 }
391300
392301 static inline unsigned int crypto_sync_skcipher_blocksize(
....@@ -452,11 +361,8 @@
452361 *
453362 * Return: 0 if the setting of the key was successful; < 0 if an error occurred
454363 */
455
-static inline int crypto_skcipher_setkey(struct crypto_skcipher *tfm,
456
- const u8 *key, unsigned int keylen)
457
-{
458
- return tfm->setkey(tfm, key, keylen);
459
-}
364
+int crypto_skcipher_setkey(struct crypto_skcipher *tfm,
365
+ const u8 *key, unsigned int keylen);
460366
461367 static inline int crypto_sync_skcipher_setkey(struct crypto_sync_skcipher *tfm,
462368 const u8 *key, unsigned int keylen)
....@@ -464,10 +370,16 @@
464370 return crypto_skcipher_setkey(&tfm->base, key, keylen);
465371 }
466372
467
-static inline unsigned int crypto_skcipher_default_keysize(
373
+static inline unsigned int crypto_skcipher_min_keysize(
468374 struct crypto_skcipher *tfm)
469375 {
470
- return tfm->keysize;
376
+ return crypto_skcipher_alg(tfm)->min_keysize;
377
+}
378
+
379
+static inline unsigned int crypto_skcipher_max_keysize(
380
+ struct crypto_skcipher *tfm)
381
+{
382
+ return crypto_skcipher_alg(tfm)->max_keysize;
471383 }
472384
473385 /**
....@@ -504,15 +416,7 @@
504416 *
505417 * Return: 0 if the cipher operation was successful; < 0 if an error occurred
506418 */
507
-static inline int crypto_skcipher_encrypt(struct skcipher_request *req)
508
-{
509
- struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
510
-
511
- if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
512
- return -ENOKEY;
513
-
514
- return tfm->encrypt(req);
515
-}
419
+int crypto_skcipher_encrypt(struct skcipher_request *req);
516420
517421 /**
518422 * crypto_skcipher_decrypt() - decrypt ciphertext
....@@ -525,15 +429,7 @@
525429 *
526430 * Return: 0 if the cipher operation was successful; < 0 if an error occurred
527431 */
528
-static inline int crypto_skcipher_decrypt(struct skcipher_request *req)
529
-{
530
- struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
531
-
532
- if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
533
- return -ENOKEY;
534
-
535
- return tfm->decrypt(req);
536
-}
432
+int crypto_skcipher_decrypt(struct skcipher_request *req);
537433
538434 /**
539435 * DOC: Symmetric Key Cipher Request Handle
....@@ -614,7 +510,7 @@
614510 */
615511 static inline void skcipher_request_free(struct skcipher_request *req)
616512 {
617
- kzfree(req);
513
+ kfree_sensitive(req);
618514 }
619515
620516 static inline void skcipher_request_zero(struct skcipher_request *req)