45
45
* funneled through AES are...16 bytes in size!
46
46
*/
47
47
48
+ #include <crypto/skcipher.h>
48
49
#include <linux/crypto.h>
49
50
#include <linux/module.h>
50
51
#include <linux/err.h>
@@ -195,21 +196,22 @@ static void bytewise_xor(void *_bo, const void *_bi1, const void *_bi2,
195
196
* NOTE: blen is not aligned to a block size, we'll pad zeros, that's
196
197
* what sg[4] is for. Maybe there is a smarter way to do this.
197
198
*/
198
- static int wusb_ccm_mac (struct crypto_blkcipher * tfm_cbc ,
199
+ static int wusb_ccm_mac (struct crypto_skcipher * tfm_cbc ,
199
200
struct crypto_cipher * tfm_aes , void * mic ,
200
201
const struct aes_ccm_nonce * n ,
201
202
const struct aes_ccm_label * a , const void * b ,
202
203
size_t blen )
203
204
{
204
205
int result = 0 ;
205
- struct blkcipher_desc desc ;
206
+ SKCIPHER_REQUEST_ON_STACK ( req , tfm_cbc ) ;
206
207
struct aes_ccm_b0 b0 ;
207
208
struct aes_ccm_b1 b1 ;
208
209
struct aes_ccm_a ax ;
209
210
struct scatterlist sg [4 ], sg_dst ;
210
- void * iv , * dst_buf ;
211
- size_t ivsize , dst_size ;
211
+ void * dst_buf ;
212
+ size_t dst_size ;
212
213
const u8 bzero [16 ] = { 0 };
214
+ u8 iv [crypto_skcipher_ivsize (tfm_cbc )];
213
215
size_t zero_padding ;
214
216
215
217
/*
@@ -232,9 +234,7 @@ static int wusb_ccm_mac(struct crypto_blkcipher *tfm_cbc,
232
234
goto error_dst_buf ;
233
235
}
234
236
235
- iv = crypto_blkcipher_crt (tfm_cbc )-> iv ;
236
- ivsize = crypto_blkcipher_ivsize (tfm_cbc );
237
- memset (iv , 0 , ivsize );
237
+ memset (iv , 0 , sizeof (iv ));
238
238
239
239
/* Setup B0 */
240
240
b0 .flags = 0x59 ; /* Format B0 */
@@ -259,9 +259,11 @@ static int wusb_ccm_mac(struct crypto_blkcipher *tfm_cbc,
259
259
sg_set_buf (& sg [3 ], bzero , zero_padding );
260
260
sg_init_one (& sg_dst , dst_buf , dst_size );
261
261
262
- desc .tfm = tfm_cbc ;
263
- desc .flags = 0 ;
264
- result = crypto_blkcipher_encrypt (& desc , & sg_dst , sg , dst_size );
262
+ skcipher_request_set_tfm (req , tfm_cbc );
263
+ skcipher_request_set_callback (req , 0 , NULL , NULL );
264
+ skcipher_request_set_crypt (req , sg , & sg_dst , dst_size , iv );
265
+ result = crypto_skcipher_encrypt (req );
266
+ skcipher_request_zero (req );
265
267
if (result < 0 ) {
266
268
printk (KERN_ERR "E: can't compute CBC-MAC tag (MIC): %d\n" ,
267
269
result );
@@ -301,18 +303,18 @@ ssize_t wusb_prf(void *out, size_t out_size,
301
303
{
302
304
ssize_t result , bytes = 0 , bitr ;
303
305
struct aes_ccm_nonce n = * _n ;
304
- struct crypto_blkcipher * tfm_cbc ;
306
+ struct crypto_skcipher * tfm_cbc ;
305
307
struct crypto_cipher * tfm_aes ;
306
308
u64 sfn = 0 ;
307
309
__le64 sfn_le ;
308
310
309
- tfm_cbc = crypto_alloc_blkcipher ("cbc(aes)" , 0 , CRYPTO_ALG_ASYNC );
311
+ tfm_cbc = crypto_alloc_skcipher ("cbc(aes)" , 0 , CRYPTO_ALG_ASYNC );
310
312
if (IS_ERR (tfm_cbc )) {
311
313
result = PTR_ERR (tfm_cbc );
312
314
printk (KERN_ERR "E: can't load CBC(AES): %d\n" , (int )result );
313
315
goto error_alloc_cbc ;
314
316
}
315
- result = crypto_blkcipher_setkey (tfm_cbc , key , 16 );
317
+ result = crypto_skcipher_setkey (tfm_cbc , key , 16 );
316
318
if (result < 0 ) {
317
319
printk (KERN_ERR "E: can't set CBC key: %d\n" , (int )result );
318
320
goto error_setkey_cbc ;
@@ -345,7 +347,7 @@ ssize_t wusb_prf(void *out, size_t out_size,
345
347
crypto_free_cipher (tfm_aes );
346
348
error_alloc_aes :
347
349
error_setkey_cbc :
348
- crypto_free_blkcipher (tfm_cbc );
350
+ crypto_free_skcipher (tfm_cbc );
349
351
error_alloc_cbc :
350
352
return result ;
351
353
}
0 commit comments