@@ -33,7 +33,6 @@ static int aead_null_givdecrypt(struct aead_givcrypt_request *req);
33
33
static int setkey_unaligned (struct crypto_aead * tfm , const u8 * key ,
34
34
unsigned int keylen )
35
35
{
36
- struct old_aead_alg * aead = crypto_old_aead_alg (tfm );
37
36
unsigned long alignmask = crypto_aead_alignmask (tfm );
38
37
int ret ;
39
38
u8 * buffer , * alignbuffer ;
@@ -46,7 +45,7 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
46
45
47
46
alignbuffer = (u8 * )ALIGN ((unsigned long )buffer , alignmask + 1 );
48
47
memcpy (alignbuffer , key , keylen );
49
- ret = aead -> setkey (tfm , alignbuffer , keylen );
48
+ ret = tfm -> setkey (tfm , alignbuffer , keylen );
50
49
memset (alignbuffer , 0 , keylen );
51
50
kfree (buffer );
52
51
return ret ;
@@ -55,28 +54,26 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
55
54
int crypto_aead_setkey (struct crypto_aead * tfm ,
56
55
const u8 * key , unsigned int keylen )
57
56
{
58
- struct old_aead_alg * aead = crypto_old_aead_alg (tfm );
59
57
unsigned long alignmask = crypto_aead_alignmask (tfm );
60
58
61
59
tfm = tfm -> child ;
62
60
63
61
if ((unsigned long )key & alignmask )
64
62
return setkey_unaligned (tfm , key , keylen );
65
63
66
- return aead -> setkey (tfm , key , keylen );
64
+ return tfm -> setkey (tfm , key , keylen );
67
65
}
68
66
EXPORT_SYMBOL_GPL (crypto_aead_setkey );
69
67
70
68
int crypto_aead_setauthsize (struct crypto_aead * tfm , unsigned int authsize )
71
69
{
72
70
int err ;
73
71
74
- if (authsize > crypto_old_aead_alg ( tfm ) -> maxauthsize )
72
+ if (authsize > tfm -> maxauthsize )
75
73
return - EINVAL ;
76
74
77
- if (crypto_old_aead_alg (tfm )-> setauthsize ) {
78
- err = crypto_old_aead_alg (tfm )-> setauthsize (
79
- tfm -> child , authsize );
75
+ if (tfm -> setauthsize ) {
76
+ err = tfm -> setauthsize (tfm -> child , authsize );
80
77
if (err )
81
78
return err ;
82
79
}
@@ -145,14 +142,16 @@ static int no_givcrypt(struct aead_givcrypt_request *req)
145
142
return - ENOSYS ;
146
143
}
147
144
148
- static int crypto_aead_init_tfm (struct crypto_tfm * tfm )
145
+ static int crypto_old_aead_init_tfm (struct crypto_tfm * tfm )
149
146
{
150
147
struct old_aead_alg * alg = & tfm -> __crt_alg -> cra_aead ;
151
148
struct crypto_aead * crt = __crypto_aead_cast (tfm );
152
149
153
150
if (max (alg -> maxauthsize , alg -> ivsize ) > PAGE_SIZE / 8 )
154
151
return - EINVAL ;
155
152
153
+ crt -> setkey = alg -> setkey ;
154
+ crt -> setauthsize = alg -> setauthsize ;
156
155
crt -> encrypt = old_encrypt ;
157
156
crt -> decrypt = old_decrypt ;
158
157
if (alg -> ivsize ) {
@@ -164,13 +163,34 @@ static int crypto_aead_init_tfm(struct crypto_tfm *tfm)
164
163
}
165
164
crt -> child = __crypto_aead_cast (tfm );
166
165
crt -> ivsize = alg -> ivsize ;
166
+ crt -> maxauthsize = alg -> maxauthsize ;
167
167
crt -> authsize = alg -> maxauthsize ;
168
168
169
169
return 0 ;
170
170
}
171
171
172
+ static int crypto_aead_init_tfm (struct crypto_tfm * tfm )
173
+ {
174
+ struct crypto_aead * aead = __crypto_aead_cast (tfm );
175
+ struct aead_alg * alg = crypto_aead_alg (aead );
176
+
177
+ if (crypto_old_aead_alg (aead )-> encrypt )
178
+ return crypto_old_aead_init_tfm (tfm );
179
+
180
+ aead -> setkey = alg -> setkey ;
181
+ aead -> setauthsize = alg -> setauthsize ;
182
+ aead -> encrypt = alg -> encrypt ;
183
+ aead -> decrypt = alg -> decrypt ;
184
+ aead -> child = __crypto_aead_cast (tfm );
185
+ aead -> ivsize = alg -> ivsize ;
186
+ aead -> maxauthsize = alg -> maxauthsize ;
187
+ aead -> authsize = alg -> maxauthsize ;
188
+
189
+ return 0 ;
190
+ }
191
+
172
192
#ifdef CONFIG_NET
173
- static int crypto_aead_report (struct sk_buff * skb , struct crypto_alg * alg )
193
+ static int crypto_old_aead_report (struct sk_buff * skb , struct crypto_alg * alg )
174
194
{
175
195
struct crypto_report_aead raead ;
176
196
struct old_aead_alg * aead = & alg -> cra_aead ;
@@ -191,15 +211,15 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
191
211
return - EMSGSIZE ;
192
212
}
193
213
#else
194
- static int crypto_aead_report (struct sk_buff * skb , struct crypto_alg * alg )
214
+ static int crypto_old_aead_report (struct sk_buff * skb , struct crypto_alg * alg )
195
215
{
196
216
return - ENOSYS ;
197
217
}
198
218
#endif
199
219
200
- static void crypto_aead_show (struct seq_file * m , struct crypto_alg * alg )
220
+ static void crypto_old_aead_show (struct seq_file * m , struct crypto_alg * alg )
201
221
__attribute__ ((unused ));
202
- static void crypto_aead_show (struct seq_file * m , struct crypto_alg * alg )
222
+ static void crypto_old_aead_show (struct seq_file * m , struct crypto_alg * alg )
203
223
{
204
224
struct old_aead_alg * aead = & alg -> cra_aead ;
205
225
@@ -216,9 +236,9 @@ const struct crypto_type crypto_aead_type = {
216
236
.extsize = crypto_alg_extsize ,
217
237
.init_tfm = crypto_aead_init_tfm ,
218
238
#ifdef CONFIG_PROC_FS
219
- .show = crypto_aead_show ,
239
+ .show = crypto_old_aead_show ,
220
240
#endif
221
- .report = crypto_aead_report ,
241
+ .report = crypto_old_aead_report ,
222
242
.lookup = crypto_lookup_aead ,
223
243
.maskclear = ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV ),
224
244
.maskset = CRYPTO_ALG_TYPE_MASK ,
@@ -227,6 +247,62 @@ const struct crypto_type crypto_aead_type = {
227
247
};
228
248
EXPORT_SYMBOL_GPL (crypto_aead_type );
229
249
250
+ #ifdef CONFIG_NET
251
+ static int crypto_aead_report (struct sk_buff * skb , struct crypto_alg * alg )
252
+ {
253
+ struct crypto_report_aead raead ;
254
+ struct aead_alg * aead = container_of (alg , struct aead_alg , base );
255
+
256
+ strncpy (raead .type , "aead" , sizeof (raead .type ));
257
+ strncpy (raead .geniv , "<none>" , sizeof (raead .geniv ));
258
+
259
+ raead .blocksize = alg -> cra_blocksize ;
260
+ raead .maxauthsize = aead -> maxauthsize ;
261
+ raead .ivsize = aead -> ivsize ;
262
+
263
+ if (nla_put (skb , CRYPTOCFGA_REPORT_AEAD ,
264
+ sizeof (struct crypto_report_aead ), & raead ))
265
+ goto nla_put_failure ;
266
+ return 0 ;
267
+
268
+ nla_put_failure :
269
+ return - EMSGSIZE ;
270
+ }
271
+ #else
272
+ static int crypto_aead_report (struct sk_buff * skb , struct crypto_alg * alg )
273
+ {
274
+ return - ENOSYS ;
275
+ }
276
+ #endif
277
+
278
+ static void crypto_aead_show (struct seq_file * m , struct crypto_alg * alg )
279
+ __attribute__ ((unused ));
280
+ static void crypto_aead_show (struct seq_file * m , struct crypto_alg * alg )
281
+ {
282
+ struct aead_alg * aead = container_of (alg , struct aead_alg , base );
283
+
284
+ seq_printf (m , "type : aead\n" );
285
+ seq_printf (m , "async : %s\n" , alg -> cra_flags & CRYPTO_ALG_ASYNC ?
286
+ "yes" : "no" );
287
+ seq_printf (m , "blocksize : %u\n" , alg -> cra_blocksize );
288
+ seq_printf (m , "ivsize : %u\n" , aead -> ivsize );
289
+ seq_printf (m , "maxauthsize : %u\n" , aead -> maxauthsize );
290
+ seq_printf (m , "geniv : <none>\n" );
291
+ }
292
+
293
+ static const struct crypto_type crypto_new_aead_type = {
294
+ .extsize = crypto_alg_extsize ,
295
+ .init_tfm = crypto_aead_init_tfm ,
296
+ #ifdef CONFIG_PROC_FS
297
+ .show = crypto_aead_show ,
298
+ #endif
299
+ .report = crypto_aead_report ,
300
+ .maskclear = ~CRYPTO_ALG_TYPE_MASK ,
301
+ .maskset = CRYPTO_ALG_TYPE_MASK ,
302
+ .type = CRYPTO_ALG_TYPE_AEAD ,
303
+ .tfmsize = offsetof(struct crypto_aead , base ),
304
+ };
305
+
230
306
static int aead_null_givencrypt (struct aead_givcrypt_request * req )
231
307
{
232
308
return crypto_aead_encrypt (& req -> areq );
@@ -552,5 +628,51 @@ struct crypto_aead *crypto_alloc_aead(const char *alg_name, u32 type, u32 mask)
552
628
}
553
629
EXPORT_SYMBOL_GPL (crypto_alloc_aead );
554
630
631
+ static int aead_prepare_alg (struct aead_alg * alg )
632
+ {
633
+ struct crypto_alg * base = & alg -> base ;
634
+
635
+ if (max (alg -> maxauthsize , alg -> ivsize ) > PAGE_SIZE / 8 )
636
+ return - EINVAL ;
637
+
638
+ base -> cra_type = & crypto_new_aead_type ;
639
+ base -> cra_flags &= ~CRYPTO_ALG_TYPE_MASK ;
640
+ base -> cra_flags |= CRYPTO_ALG_TYPE_AEAD ;
641
+
642
+ return 0 ;
643
+ }
644
+
645
+ int crypto_register_aead (struct aead_alg * alg )
646
+ {
647
+ struct crypto_alg * base = & alg -> base ;
648
+ int err ;
649
+
650
+ err = aead_prepare_alg (alg );
651
+ if (err )
652
+ return err ;
653
+
654
+ return crypto_register_alg (base );
655
+ }
656
+ EXPORT_SYMBOL_GPL (crypto_register_aead );
657
+
658
+ int crypto_unregister_aead (struct aead_alg * alg )
659
+ {
660
+ return crypto_unregister_alg (& alg -> base );
661
+ }
662
+ EXPORT_SYMBOL_GPL (crypto_unregister_aead );
663
+
664
+ int aead_register_instance (struct crypto_template * tmpl ,
665
+ struct aead_instance * inst )
666
+ {
667
+ int err ;
668
+
669
+ err = aead_prepare_alg (& inst -> alg );
670
+ if (err )
671
+ return err ;
672
+
673
+ return crypto_register_instance (tmpl , aead_crypto_instance (inst ));
674
+ }
675
+ EXPORT_SYMBOL_GPL (aead_register_instance );
676
+
555
677
MODULE_LICENSE ("GPL" );
556
678
MODULE_DESCRIPTION ("Authenticated Encryption with Associated Data (AEAD)" );
0 commit comments