21
21
22
22
#include <crypto/internal/aead.h>
23
23
#include <crypto/aes.h>
24
- #include <crypto/algapi.h>
25
24
#include <crypto/scatterwalk.h>
26
25
#include <linux/module.h>
27
26
#include <linux/types.h>
28
- #include <linux/crypto.h>
29
27
#include <asm/vio.h>
30
28
31
29
#include "nx_csbcpb.h"
@@ -36,7 +34,7 @@ static int gcm_aes_nx_set_key(struct crypto_aead *tfm,
36
34
const u8 * in_key ,
37
35
unsigned int key_len )
38
36
{
39
- struct nx_crypto_ctx * nx_ctx = crypto_tfm_ctx ( & tfm -> base );
37
+ struct nx_crypto_ctx * nx_ctx = crypto_aead_ctx ( tfm );
40
38
struct nx_csbcpb * csbcpb = nx_ctx -> csbcpb ;
41
39
struct nx_csbcpb * csbcpb_aead = nx_ctx -> csbcpb_aead ;
42
40
@@ -75,7 +73,7 @@ static int gcm4106_aes_nx_set_key(struct crypto_aead *tfm,
75
73
const u8 * in_key ,
76
74
unsigned int key_len )
77
75
{
78
- struct nx_crypto_ctx * nx_ctx = crypto_tfm_ctx ( & tfm -> base );
76
+ struct nx_crypto_ctx * nx_ctx = crypto_aead_ctx ( tfm );
79
77
char * nonce = nx_ctx -> priv .gcm .nonce ;
80
78
int rc ;
81
79
@@ -110,13 +108,14 @@ static int gcm4106_aes_nx_setauthsize(struct crypto_aead *tfm,
110
108
111
109
static int nx_gca (struct nx_crypto_ctx * nx_ctx ,
112
110
struct aead_request * req ,
113
- u8 * out )
111
+ u8 * out ,
112
+ unsigned int assoclen )
114
113
{
115
114
int rc ;
116
115
struct nx_csbcpb * csbcpb_aead = nx_ctx -> csbcpb_aead ;
117
116
struct scatter_walk walk ;
118
117
struct nx_sg * nx_sg = nx_ctx -> in_sg ;
119
- unsigned int nbytes = req -> assoclen ;
118
+ unsigned int nbytes = assoclen ;
120
119
unsigned int processed = 0 , to_process ;
121
120
unsigned int max_sg_len ;
122
121
@@ -167,7 +166,7 @@ static int nx_gca(struct nx_crypto_ctx *nx_ctx,
167
166
NX_CPB_FDM (csbcpb_aead ) |= NX_FDM_CONTINUATION ;
168
167
169
168
atomic_inc (& (nx_ctx -> stats -> aes_ops ));
170
- atomic64_add (req -> assoclen , & (nx_ctx -> stats -> aes_bytes ));
169
+ atomic64_add (assoclen , & (nx_ctx -> stats -> aes_bytes ));
171
170
172
171
processed += to_process ;
173
172
} while (processed < nbytes );
@@ -177,13 +176,15 @@ static int nx_gca(struct nx_crypto_ctx *nx_ctx,
177
176
return rc ;
178
177
}
179
178
180
- static int gmac (struct aead_request * req , struct blkcipher_desc * desc )
179
+ static int gmac (struct aead_request * req , struct blkcipher_desc * desc ,
180
+ unsigned int assoclen )
181
181
{
182
182
int rc ;
183
- struct nx_crypto_ctx * nx_ctx = crypto_tfm_ctx (req -> base .tfm );
183
+ struct nx_crypto_ctx * nx_ctx =
184
+ crypto_aead_ctx (crypto_aead_reqtfm (req ));
184
185
struct nx_csbcpb * csbcpb = nx_ctx -> csbcpb ;
185
186
struct nx_sg * nx_sg ;
186
- unsigned int nbytes = req -> assoclen ;
187
+ unsigned int nbytes = assoclen ;
187
188
unsigned int processed = 0 , to_process ;
188
189
unsigned int max_sg_len ;
189
190
@@ -238,7 +239,7 @@ static int gmac(struct aead_request *req, struct blkcipher_desc *desc)
238
239
NX_CPB_FDM (csbcpb ) |= NX_FDM_CONTINUATION ;
239
240
240
241
atomic_inc (& (nx_ctx -> stats -> aes_ops ));
241
- atomic64_add (req -> assoclen , & (nx_ctx -> stats -> aes_bytes ));
242
+ atomic64_add (assoclen , & (nx_ctx -> stats -> aes_bytes ));
242
243
243
244
processed += to_process ;
244
245
} while (processed < nbytes );
@@ -253,7 +254,8 @@ static int gcm_empty(struct aead_request *req, struct blkcipher_desc *desc,
253
254
int enc )
254
255
{
255
256
int rc ;
256
- struct nx_crypto_ctx * nx_ctx = crypto_tfm_ctx (req -> base .tfm );
257
+ struct nx_crypto_ctx * nx_ctx =
258
+ crypto_aead_ctx (crypto_aead_reqtfm (req ));
257
259
struct nx_csbcpb * csbcpb = nx_ctx -> csbcpb ;
258
260
char out [AES_BLOCK_SIZE ];
259
261
struct nx_sg * in_sg , * out_sg ;
@@ -314,9 +316,11 @@ static int gcm_empty(struct aead_request *req, struct blkcipher_desc *desc,
314
316
return rc ;
315
317
}
316
318
317
- static int gcm_aes_nx_crypt (struct aead_request * req , int enc )
319
+ static int gcm_aes_nx_crypt (struct aead_request * req , int enc ,
320
+ unsigned int assoclen )
318
321
{
319
- struct nx_crypto_ctx * nx_ctx = crypto_tfm_ctx (req -> base .tfm );
322
+ struct nx_crypto_ctx * nx_ctx =
323
+ crypto_aead_ctx (crypto_aead_reqtfm (req ));
320
324
struct nx_gcm_rctx * rctx = aead_request_ctx (req );
321
325
struct nx_csbcpb * csbcpb = nx_ctx -> csbcpb ;
322
326
struct blkcipher_desc desc ;
@@ -332,20 +336,21 @@ static int gcm_aes_nx_crypt(struct aead_request *req, int enc)
332
336
* (u32 * )(desc .info + NX_GCM_CTR_OFFSET ) = 1 ;
333
337
334
338
if (nbytes == 0 ) {
335
- if (req -> assoclen == 0 )
339
+ if (assoclen == 0 )
336
340
rc = gcm_empty (req , & desc , enc );
337
341
else
338
- rc = gmac (req , & desc );
342
+ rc = gmac (req , & desc , assoclen );
339
343
if (rc )
340
344
goto out ;
341
345
else
342
346
goto mac ;
343
347
}
344
348
345
349
/* Process associated data */
346
- csbcpb -> cpb .aes_gcm .bit_length_aad = req -> assoclen * 8 ;
347
- if (req -> assoclen ) {
348
- rc = nx_gca (nx_ctx , req , csbcpb -> cpb .aes_gcm .in_pat_or_aad );
350
+ csbcpb -> cpb .aes_gcm .bit_length_aad = assoclen * 8 ;
351
+ if (assoclen ) {
352
+ rc = nx_gca (nx_ctx , req , csbcpb -> cpb .aes_gcm .in_pat_or_aad ,
353
+ assoclen );
349
354
if (rc )
350
355
goto out ;
351
356
}
@@ -363,7 +368,6 @@ static int gcm_aes_nx_crypt(struct aead_request *req, int enc)
363
368
to_process = nbytes - processed ;
364
369
365
370
csbcpb -> cpb .aes_gcm .bit_length_data = nbytes * 8 ;
366
- desc .tfm = (struct crypto_blkcipher * ) req -> base .tfm ;
367
371
rc = nx_build_sg_lists (nx_ctx , & desc , req -> dst ,
368
372
req -> src , & to_process ,
369
373
processed + req -> assoclen ,
@@ -430,7 +434,7 @@ static int gcm_aes_nx_encrypt(struct aead_request *req)
430
434
431
435
memcpy (iv , req -> iv , 12 );
432
436
433
- return gcm_aes_nx_crypt (req , 1 );
437
+ return gcm_aes_nx_crypt (req , 1 , req -> assoclen );
434
438
}
435
439
436
440
static int gcm_aes_nx_decrypt (struct aead_request * req )
@@ -440,33 +444,41 @@ static int gcm_aes_nx_decrypt(struct aead_request *req)
440
444
441
445
memcpy (iv , req -> iv , 12 );
442
446
443
- return gcm_aes_nx_crypt (req , 0 );
447
+ return gcm_aes_nx_crypt (req , 0 , req -> assoclen );
444
448
}
445
449
446
450
static int gcm4106_aes_nx_encrypt (struct aead_request * req )
447
451
{
448
- struct nx_crypto_ctx * nx_ctx = crypto_tfm_ctx (req -> base .tfm );
452
+ struct nx_crypto_ctx * nx_ctx =
453
+ crypto_aead_ctx (crypto_aead_reqtfm (req ));
449
454
struct nx_gcm_rctx * rctx = aead_request_ctx (req );
450
455
char * iv = rctx -> iv ;
451
456
char * nonce = nx_ctx -> priv .gcm .nonce ;
452
457
453
458
memcpy (iv , nonce , NX_GCM4106_NONCE_LEN );
454
459
memcpy (iv + NX_GCM4106_NONCE_LEN , req -> iv , 8 );
455
460
456
- return gcm_aes_nx_crypt (req , 1 );
461
+ if (req -> assoclen < 8 )
462
+ return - EINVAL ;
463
+
464
+ return gcm_aes_nx_crypt (req , 1 , req -> assoclen - 8 );
457
465
}
458
466
459
467
static int gcm4106_aes_nx_decrypt (struct aead_request * req )
460
468
{
461
- struct nx_crypto_ctx * nx_ctx = crypto_tfm_ctx (req -> base .tfm );
469
+ struct nx_crypto_ctx * nx_ctx =
470
+ crypto_aead_ctx (crypto_aead_reqtfm (req ));
462
471
struct nx_gcm_rctx * rctx = aead_request_ctx (req );
463
472
char * iv = rctx -> iv ;
464
473
char * nonce = nx_ctx -> priv .gcm .nonce ;
465
474
466
475
memcpy (iv , nonce , NX_GCM4106_NONCE_LEN );
467
476
memcpy (iv + NX_GCM4106_NONCE_LEN , req -> iv , 8 );
468
477
469
- return gcm_aes_nx_crypt (req , 0 );
478
+ if (req -> assoclen < 8 )
479
+ return - EINVAL ;
480
+
481
+ return gcm_aes_nx_crypt (req , 0 , req -> assoclen - 8 );
470
482
}
471
483
472
484
/* tell the block cipher walk routines that this is a stream cipher by
@@ -478,6 +490,7 @@ struct aead_alg nx_gcm_aes_alg = {
478
490
.base = {
479
491
.cra_name = "gcm(aes)" ,
480
492
.cra_driver_name = "gcm-aes-nx" ,
493
+ .cra_flags = CRYPTO_ALG_AEAD_NEW ,
481
494
.cra_priority = 300 ,
482
495
.cra_blocksize = 1 ,
483
496
.cra_ctxsize = sizeof (struct nx_crypto_ctx ),
@@ -496,6 +509,7 @@ struct aead_alg nx_gcm4106_aes_alg = {
496
509
.base = {
497
510
.cra_name = "rfc4106(gcm(aes))" ,
498
511
.cra_driver_name = "rfc4106-gcm-aes-nx" ,
512
+ .cra_flags = CRYPTO_ALG_AEAD_NEW ,
499
513
.cra_priority = 300 ,
500
514
.cra_blocksize = 1 ,
501
515
.cra_ctxsize = sizeof (struct nx_crypto_ctx ),
0 commit comments