2626
2727#include "internal.h"
2828
29+ static int aead_null_givencrypt (struct aead_givcrypt_request * req );
30+ static int aead_null_givdecrypt (struct aead_givcrypt_request * req );
31+
2932static int setkey_unaligned (struct crypto_aead * tfm , const u8 * key ,
3033 unsigned int keylen )
3134{
@@ -48,63 +51,63 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
4851 return ret ;
4952}
5053
51- static int setkey (struct crypto_aead * tfm , const u8 * key , unsigned int keylen )
54+ int crypto_aead_setkey (struct crypto_aead * tfm ,
55+ const u8 * key , unsigned int keylen )
5256{
5357 struct aead_alg * aead = crypto_aead_alg (tfm );
5458 unsigned long alignmask = crypto_aead_alignmask (tfm );
5559
60+ tfm = tfm -> child ;
61+
5662 if ((unsigned long )key & alignmask )
5763 return setkey_unaligned (tfm , key , keylen );
5864
5965 return aead -> setkey (tfm , key , keylen );
6066}
67+ EXPORT_SYMBOL_GPL (crypto_aead_setkey );
6168
6269int crypto_aead_setauthsize (struct crypto_aead * tfm , unsigned int authsize )
6370{
64- struct aead_tfm * crt = crypto_aead_crt (tfm );
6571 int err ;
6672
6773 if (authsize > crypto_aead_alg (tfm )-> maxauthsize )
6874 return - EINVAL ;
6975
7076 if (crypto_aead_alg (tfm )-> setauthsize ) {
71- err = crypto_aead_alg (tfm )-> setauthsize (crt -> base , authsize );
77+ err = crypto_aead_alg (tfm )-> setauthsize (tfm -> child , authsize );
7278 if (err )
7379 return err ;
7480 }
7581
76- crypto_aead_crt ( crt -> base ) -> authsize = authsize ;
77- crt -> authsize = authsize ;
82+ tfm -> child -> authsize = authsize ;
83+ tfm -> authsize = authsize ;
7884 return 0 ;
7985}
8086EXPORT_SYMBOL_GPL (crypto_aead_setauthsize );
8187
82- static unsigned int crypto_aead_ctxsize (struct crypto_alg * alg , u32 type ,
83- u32 mask )
84- {
85- return alg -> cra_ctxsize ;
86- }
87-
8888static int no_givcrypt (struct aead_givcrypt_request * req )
8989{
9090 return - ENOSYS ;
9191}
9292
93- static int crypto_init_aead_ops (struct crypto_tfm * tfm , u32 type , u32 mask )
93+ static int crypto_aead_init_tfm (struct crypto_tfm * tfm )
9494{
9595 struct aead_alg * alg = & tfm -> __crt_alg -> cra_aead ;
96- struct aead_tfm * crt = & tfm -> crt_aead ;
96+ struct crypto_aead * crt = __crypto_aead_cast ( tfm ) ;
9797
9898 if (max (alg -> maxauthsize , alg -> ivsize ) > PAGE_SIZE / 8 )
9999 return - EINVAL ;
100100
101- crt -> setkey = tfm -> __crt_alg -> cra_flags & CRYPTO_ALG_GENIV ?
102- alg -> setkey : setkey ;
103101 crt -> encrypt = alg -> encrypt ;
104102 crt -> decrypt = alg -> decrypt ;
105- crt -> givencrypt = alg -> givencrypt ?: no_givcrypt ;
106- crt -> givdecrypt = alg -> givdecrypt ?: no_givcrypt ;
107- crt -> base = __crypto_aead_cast (tfm );
103+ if (alg -> ivsize ) {
104+ crt -> givencrypt = alg -> givencrypt ?: no_givcrypt ;
105+ crt -> givdecrypt = alg -> givdecrypt ?: no_givcrypt ;
106+ } else {
107+ crt -> givencrypt = aead_null_givencrypt ;
108+ crt -> givdecrypt = aead_null_givdecrypt ;
109+ }
110+ crt -> child = __crypto_aead_cast (tfm );
108111 crt -> ivsize = alg -> ivsize ;
109112 crt -> authsize = alg -> maxauthsize ;
110113
@@ -155,12 +158,17 @@ static void crypto_aead_show(struct seq_file *m, struct crypto_alg *alg)
155158}
156159
157160const struct crypto_type crypto_aead_type = {
158- .ctxsize = crypto_aead_ctxsize ,
159- .init = crypto_init_aead_ops ,
161+ .extsize = crypto_alg_extsize ,
162+ .init_tfm = crypto_aead_init_tfm ,
160163#ifdef CONFIG_PROC_FS
161164 .show = crypto_aead_show ,
162165#endif
163166 .report = crypto_aead_report ,
167+ .lookup = crypto_lookup_aead ,
168+ .maskclear = ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV ),
169+ .maskset = CRYPTO_ALG_TYPE_MASK ,
170+ .type = CRYPTO_ALG_TYPE_AEAD ,
171+ .tfmsize = offsetof(struct crypto_aead , base ),
164172};
165173EXPORT_SYMBOL_GPL (crypto_aead_type );
166174
@@ -174,28 +182,6 @@ static int aead_null_givdecrypt(struct aead_givcrypt_request *req)
174182 return crypto_aead_decrypt (& req -> areq );
175183}
176184
177- static int crypto_init_nivaead_ops (struct crypto_tfm * tfm , u32 type , u32 mask )
178- {
179- struct aead_alg * alg = & tfm -> __crt_alg -> cra_aead ;
180- struct aead_tfm * crt = & tfm -> crt_aead ;
181-
182- if (max (alg -> maxauthsize , alg -> ivsize ) > PAGE_SIZE / 8 )
183- return - EINVAL ;
184-
185- crt -> setkey = setkey ;
186- crt -> encrypt = alg -> encrypt ;
187- crt -> decrypt = alg -> decrypt ;
188- if (!alg -> ivsize ) {
189- crt -> givencrypt = aead_null_givencrypt ;
190- crt -> givdecrypt = aead_null_givdecrypt ;
191- }
192- crt -> base = __crypto_aead_cast (tfm );
193- crt -> ivsize = alg -> ivsize ;
194- crt -> authsize = alg -> maxauthsize ;
195-
196- return 0 ;
197- }
198-
199185#ifdef CONFIG_NET
200186static int crypto_nivaead_report (struct sk_buff * skb , struct crypto_alg * alg )
201187{
@@ -241,32 +227,24 @@ static void crypto_nivaead_show(struct seq_file *m, struct crypto_alg *alg)
241227}
242228
243229const struct crypto_type crypto_nivaead_type = {
244- .ctxsize = crypto_aead_ctxsize ,
245- .init = crypto_init_nivaead_ops ,
230+ .extsize = crypto_alg_extsize ,
231+ .init_tfm = crypto_aead_init_tfm ,
246232#ifdef CONFIG_PROC_FS
247233 .show = crypto_nivaead_show ,
248234#endif
249235 .report = crypto_nivaead_report ,
236+ .maskclear = ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV ),
237+ .maskset = CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV ,
238+ .type = CRYPTO_ALG_TYPE_AEAD ,
239+ .tfmsize = offsetof(struct crypto_aead , base ),
250240};
251241EXPORT_SYMBOL_GPL (crypto_nivaead_type );
252242
253243static int crypto_grab_nivaead (struct crypto_aead_spawn * spawn ,
254244 const char * name , u32 type , u32 mask )
255245{
256- struct crypto_alg * alg ;
257- int err ;
258-
259- type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV );
260- type |= CRYPTO_ALG_TYPE_AEAD ;
261- mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV ;
262-
263- alg = crypto_alg_mod_lookup (name , type , mask );
264- if (IS_ERR (alg ))
265- return PTR_ERR (alg );
266-
267- err = crypto_init_spawn (& spawn -> base , alg , spawn -> base .inst , mask );
268- crypto_mod_put (alg );
269- return err ;
246+ spawn -> base .frontend = & crypto_nivaead_type ;
247+ return crypto_grab_spawn (& spawn -> base , name , type , mask );
270248}
271249
272250struct crypto_instance * aead_geniv_alloc (struct crypto_template * tmpl ,
@@ -374,22 +352,25 @@ EXPORT_SYMBOL_GPL(aead_geniv_free);
374352int aead_geniv_init (struct crypto_tfm * tfm )
375353{
376354 struct crypto_instance * inst = (void * )tfm -> __crt_alg ;
355+ struct crypto_aead * child ;
377356 struct crypto_aead * aead ;
378357
379- aead = crypto_spawn_aead (crypto_instance_ctx (inst ));
380- if (IS_ERR (aead ))
381- return PTR_ERR (aead );
358+ aead = __crypto_aead_cast (tfm );
382359
383- tfm -> crt_aead .base = aead ;
384- tfm -> crt_aead .reqsize += crypto_aead_reqsize (aead );
360+ child = crypto_spawn_aead (crypto_instance_ctx (inst ));
361+ if (IS_ERR (child ))
362+ return PTR_ERR (child );
363+
364+ aead -> child = child ;
365+ aead -> reqsize += crypto_aead_reqsize (child );
385366
386367 return 0 ;
387368}
388369EXPORT_SYMBOL_GPL (aead_geniv_init );
389370
390371void aead_geniv_exit (struct crypto_tfm * tfm )
391372{
392- crypto_free_aead (tfm -> crt_aead . base );
373+ crypto_free_aead (__crypto_aead_cast ( tfm ) -> child );
393374}
394375EXPORT_SYMBOL_GPL (aead_geniv_exit );
395376
@@ -505,60 +486,14 @@ EXPORT_SYMBOL_GPL(crypto_lookup_aead);
505486int crypto_grab_aead (struct crypto_aead_spawn * spawn , const char * name ,
506487 u32 type , u32 mask )
507488{
508- struct crypto_alg * alg ;
509- int err ;
510-
511- type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV );
512- type |= CRYPTO_ALG_TYPE_AEAD ;
513- mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV );
514- mask |= CRYPTO_ALG_TYPE_MASK ;
515-
516- alg = crypto_lookup_aead (name , type , mask );
517- if (IS_ERR (alg ))
518- return PTR_ERR (alg );
519-
520- err = crypto_init_spawn (& spawn -> base , alg , spawn -> base .inst , mask );
521- crypto_mod_put (alg );
522- return err ;
489+ spawn -> base .frontend = & crypto_aead_type ;
490+ return crypto_grab_spawn (& spawn -> base , name , type , mask );
523491}
524492EXPORT_SYMBOL_GPL (crypto_grab_aead );
525493
526494struct crypto_aead * crypto_alloc_aead (const char * alg_name , u32 type , u32 mask )
527495{
528- struct crypto_tfm * tfm ;
529- int err ;
530-
531- type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV );
532- type |= CRYPTO_ALG_TYPE_AEAD ;
533- mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV );
534- mask |= CRYPTO_ALG_TYPE_MASK ;
535-
536- for (;;) {
537- struct crypto_alg * alg ;
538-
539- alg = crypto_lookup_aead (alg_name , type , mask );
540- if (IS_ERR (alg )) {
541- err = PTR_ERR (alg );
542- goto err ;
543- }
544-
545- tfm = __crypto_alloc_tfm (alg , type , mask );
546- if (!IS_ERR (tfm ))
547- return __crypto_aead_cast (tfm );
548-
549- crypto_mod_put (alg );
550- err = PTR_ERR (tfm );
551-
552- err :
553- if (err != - EAGAIN )
554- break ;
555- if (signal_pending (current )) {
556- err = - EINTR ;
557- break ;
558- }
559- }
560-
561- return ERR_PTR (err );
496+ return crypto_alloc_tfm (alg_name , & crypto_aead_type , type , mask );
562497}
563498EXPORT_SYMBOL_GPL (crypto_alloc_aead );
564499
0 commit comments