5656
5757#define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100
5858#define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200
59+ #define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400
5960#define CRYPTO_TFM_RES_WEAK_KEY 0x00100000
6061#define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000
6162#define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000
8889#endif
8990
9091struct scatterlist ;
92+ struct crypto_ablkcipher ;
93+ struct crypto_async_request ;
9194struct crypto_blkcipher ;
9295struct crypto_hash ;
9396struct crypto_tfm ;
9497struct crypto_type ;
9598
99+ typedef void (* crypto_completion_t )(struct crypto_async_request * req , int err );
100+
101+ struct crypto_async_request {
102+ struct list_head list ;
103+ crypto_completion_t complete ;
104+ void * data ;
105+ struct crypto_tfm * tfm ;
106+
107+ u32 flags ;
108+ };
109+
110+ struct ablkcipher_request {
111+ struct crypto_async_request base ;
112+
113+ unsigned int nbytes ;
114+
115+ void * info ;
116+
117+ struct scatterlist * src ;
118+ struct scatterlist * dst ;
119+
120+ void * __ctx [] CRYPTO_MINALIGN_ATTR ;
121+ };
122+
96123struct blkcipher_desc {
97124 struct crypto_blkcipher * tfm ;
98125 void * info ;
@@ -232,6 +259,15 @@ static inline int crypto_has_alg(const char *name, u32 type, u32 mask)
232259 * crypto_free_*(), as well as the various helpers below.
233260 */
234261
262+ struct ablkcipher_tfm {
263+ int (* setkey )(struct crypto_ablkcipher * tfm , const u8 * key ,
264+ unsigned int keylen );
265+ int (* encrypt )(struct ablkcipher_request * req );
266+ int (* decrypt )(struct ablkcipher_request * req );
267+ unsigned int ivsize ;
268+ unsigned int reqsize ;
269+ };
270+
235271struct blkcipher_tfm {
236272 void * iv ;
237273 int (* setkey )(struct crypto_tfm * tfm , const u8 * key ,
@@ -290,6 +326,7 @@ struct compress_tfm {
290326 u8 * dst , unsigned int * dlen );
291327};
292328
329+ #define crt_ablkcipher crt_u.ablkcipher
293330#define crt_blkcipher crt_u.blkcipher
294331#define crt_cipher crt_u.cipher
295332#define crt_hash crt_u.hash
@@ -300,6 +337,7 @@ struct crypto_tfm {
300337 u32 crt_flags ;
301338
302339 union {
340+ struct ablkcipher_tfm ablkcipher ;
303341 struct blkcipher_tfm blkcipher ;
304342 struct cipher_tfm cipher ;
305343 struct hash_tfm hash ;
@@ -311,6 +349,10 @@ struct crypto_tfm {
311349 void * __crt_ctx [] CRYPTO_MINALIGN_ATTR ;
312350};
313351
352+ struct crypto_ablkcipher {
353+ struct crypto_tfm base ;
354+ };
355+
314356struct crypto_blkcipher {
315357 struct crypto_tfm base ;
316358};
@@ -411,6 +453,155 @@ static inline unsigned int crypto_tfm_ctx_alignment(void)
411453/*
412454 * API wrappers.
413455 */
456+ static inline struct crypto_ablkcipher * __crypto_ablkcipher_cast (
457+ struct crypto_tfm * tfm )
458+ {
459+ return (struct crypto_ablkcipher * )tfm ;
460+ }
461+
462+ static inline struct crypto_ablkcipher * crypto_alloc_ablkcipher (
463+ const char * alg_name , u32 type , u32 mask )
464+ {
465+ type &= ~CRYPTO_ALG_TYPE_MASK ;
466+ type |= CRYPTO_ALG_TYPE_BLKCIPHER ;
467+ mask |= CRYPTO_ALG_TYPE_MASK ;
468+
469+ return __crypto_ablkcipher_cast (
470+ crypto_alloc_base (alg_name , type , mask ));
471+ }
472+
473+ static inline struct crypto_tfm * crypto_ablkcipher_tfm (
474+ struct crypto_ablkcipher * tfm )
475+ {
476+ return & tfm -> base ;
477+ }
478+
479+ static inline void crypto_free_ablkcipher (struct crypto_ablkcipher * tfm )
480+ {
481+ crypto_free_tfm (crypto_ablkcipher_tfm (tfm ));
482+ }
483+
484+ static inline int crypto_has_ablkcipher (const char * alg_name , u32 type ,
485+ u32 mask )
486+ {
487+ type &= ~CRYPTO_ALG_TYPE_MASK ;
488+ type |= CRYPTO_ALG_TYPE_BLKCIPHER ;
489+ mask |= CRYPTO_ALG_TYPE_MASK ;
490+
491+ return crypto_has_alg (alg_name , type , mask );
492+ }
493+
494+ static inline struct ablkcipher_tfm * crypto_ablkcipher_crt (
495+ struct crypto_ablkcipher * tfm )
496+ {
497+ return & crypto_ablkcipher_tfm (tfm )-> crt_ablkcipher ;
498+ }
499+
500+ static inline unsigned int crypto_ablkcipher_ivsize (
501+ struct crypto_ablkcipher * tfm )
502+ {
503+ return crypto_ablkcipher_crt (tfm )-> ivsize ;
504+ }
505+
506+ static inline unsigned int crypto_ablkcipher_blocksize (
507+ struct crypto_ablkcipher * tfm )
508+ {
509+ return crypto_tfm_alg_blocksize (crypto_ablkcipher_tfm (tfm ));
510+ }
511+
512+ static inline unsigned int crypto_ablkcipher_alignmask (
513+ struct crypto_ablkcipher * tfm )
514+ {
515+ return crypto_tfm_alg_alignmask (crypto_ablkcipher_tfm (tfm ));
516+ }
517+
518+ static inline u32 crypto_ablkcipher_get_flags (struct crypto_ablkcipher * tfm )
519+ {
520+ return crypto_tfm_get_flags (crypto_ablkcipher_tfm (tfm ));
521+ }
522+
523+ static inline void crypto_ablkcipher_set_flags (struct crypto_ablkcipher * tfm ,
524+ u32 flags )
525+ {
526+ crypto_tfm_set_flags (crypto_ablkcipher_tfm (tfm ), flags );
527+ }
528+
529+ static inline void crypto_ablkcipher_clear_flags (struct crypto_ablkcipher * tfm ,
530+ u32 flags )
531+ {
532+ crypto_tfm_clear_flags (crypto_ablkcipher_tfm (tfm ), flags );
533+ }
534+
535+ static inline int crypto_ablkcipher_setkey (struct crypto_ablkcipher * tfm ,
536+ const u8 * key , unsigned int keylen )
537+ {
538+ return crypto_ablkcipher_crt (tfm )-> setkey (tfm , key , keylen );
539+ }
540+
541+ static inline struct crypto_ablkcipher * crypto_ablkcipher_reqtfm (
542+ struct ablkcipher_request * req )
543+ {
544+ return __crypto_ablkcipher_cast (req -> base .tfm );
545+ }
546+
547+ static inline int crypto_ablkcipher_encrypt (struct ablkcipher_request * req )
548+ {
549+ struct ablkcipher_tfm * crt =
550+ crypto_ablkcipher_crt (crypto_ablkcipher_reqtfm (req ));
551+ return crt -> encrypt (req );
552+ }
553+
554+ static inline int crypto_ablkcipher_decrypt (struct ablkcipher_request * req )
555+ {
556+ struct ablkcipher_tfm * crt =
557+ crypto_ablkcipher_crt (crypto_ablkcipher_reqtfm (req ));
558+ return crt -> decrypt (req );
559+ }
560+
561+ static inline int crypto_ablkcipher_reqsize (struct crypto_ablkcipher * tfm )
562+ {
563+ return crypto_ablkcipher_crt (tfm )-> reqsize ;
564+ }
565+
566+ static inline struct ablkcipher_request * ablkcipher_request_alloc (
567+ struct crypto_ablkcipher * tfm , gfp_t gfp )
568+ {
569+ struct ablkcipher_request * req ;
570+
571+ req = kmalloc (sizeof (struct ablkcipher_request ) +
572+ crypto_ablkcipher_reqsize (tfm ), gfp );
573+
574+ if (likely (req ))
575+ req -> base .tfm = crypto_ablkcipher_tfm (tfm );
576+
577+ return req ;
578+ }
579+
580+ static inline void ablkcipher_request_free (struct ablkcipher_request * req )
581+ {
582+ kfree (req );
583+ }
584+
585+ static inline void ablkcipher_request_set_callback (
586+ struct ablkcipher_request * req ,
587+ u32 flags , crypto_completion_t complete , void * data )
588+ {
589+ req -> base .complete = complete ;
590+ req -> base .data = data ;
591+ req -> base .flags = flags ;
592+ }
593+
594+ static inline void ablkcipher_request_set_crypt (
595+ struct ablkcipher_request * req ,
596+ struct scatterlist * src , struct scatterlist * dst ,
597+ unsigned int nbytes , void * iv )
598+ {
599+ req -> src = src ;
600+ req -> dst = dst ;
601+ req -> nbytes = nbytes ;
602+ req -> info = iv ;
603+ }
604+
414605static inline struct crypto_blkcipher * __crypto_blkcipher_cast (
415606 struct crypto_tfm * tfm )
416607{
@@ -427,9 +618,9 @@ static inline struct crypto_blkcipher *crypto_blkcipher_cast(
427618static inline struct crypto_blkcipher * crypto_alloc_blkcipher (
428619 const char * alg_name , u32 type , u32 mask )
429620{
430- type &= ~CRYPTO_ALG_TYPE_MASK ;
621+ type &= ~( CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC ) ;
431622 type |= CRYPTO_ALG_TYPE_BLKCIPHER ;
432- mask |= CRYPTO_ALG_TYPE_MASK ;
623+ mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC ;
433624
434625 return __crypto_blkcipher_cast (crypto_alloc_base (alg_name , type , mask ));
435626}
@@ -447,9 +638,9 @@ static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm)
447638
448639static inline int crypto_has_blkcipher (const char * alg_name , u32 type , u32 mask )
449640{
450- type &= ~CRYPTO_ALG_TYPE_MASK ;
641+ type &= ~( CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC ) ;
451642 type |= CRYPTO_ALG_TYPE_BLKCIPHER ;
452- mask |= CRYPTO_ALG_TYPE_MASK ;
643+ mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC ;
453644
454645 return crypto_has_alg (alg_name , type , mask );
455646}
0 commit comments