Skip to content

Commit ab1e6fa

Browse files
committed
wusb: Use skcipher
This patch replaces uses of blkcipher with skcipher. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent c3a7922 commit ab1e6fa

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

drivers/usb/wusbcore/crypto.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
* funneled through AES are...16 bytes in size!
4646
*/
4747

48+
#include <crypto/skcipher.h>
4849
#include <linux/crypto.h>
4950
#include <linux/module.h>
5051
#include <linux/err.h>
@@ -195,21 +196,22 @@ static void bytewise_xor(void *_bo, const void *_bi1, const void *_bi2,
195196
* NOTE: blen is not aligned to a block size, we'll pad zeros, that's
196197
* what sg[4] is for. Maybe there is a smarter way to do this.
197198
*/
198-
static int wusb_ccm_mac(struct crypto_blkcipher *tfm_cbc,
199+
static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
199200
struct crypto_cipher *tfm_aes, void *mic,
200201
const struct aes_ccm_nonce *n,
201202
const struct aes_ccm_label *a, const void *b,
202203
size_t blen)
203204
{
204205
int result = 0;
205-
struct blkcipher_desc desc;
206+
SKCIPHER_REQUEST_ON_STACK(req, tfm_cbc);
206207
struct aes_ccm_b0 b0;
207208
struct aes_ccm_b1 b1;
208209
struct aes_ccm_a ax;
209210
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;
212213
const u8 bzero[16] = { 0 };
214+
u8 iv[crypto_skcipher_ivsize(tfm_cbc)];
213215
size_t zero_padding;
214216

215217
/*
@@ -232,9 +234,7 @@ static int wusb_ccm_mac(struct crypto_blkcipher *tfm_cbc,
232234
goto error_dst_buf;
233235
}
234236

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));
238238

239239
/* Setup B0 */
240240
b0.flags = 0x59; /* Format B0 */
@@ -259,9 +259,11 @@ static int wusb_ccm_mac(struct crypto_blkcipher *tfm_cbc,
259259
sg_set_buf(&sg[3], bzero, zero_padding);
260260
sg_init_one(&sg_dst, dst_buf, dst_size);
261261

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);
265267
if (result < 0) {
266268
printk(KERN_ERR "E: can't compute CBC-MAC tag (MIC): %d\n",
267269
result);
@@ -301,18 +303,18 @@ ssize_t wusb_prf(void *out, size_t out_size,
301303
{
302304
ssize_t result, bytes = 0, bitr;
303305
struct aes_ccm_nonce n = *_n;
304-
struct crypto_blkcipher *tfm_cbc;
306+
struct crypto_skcipher *tfm_cbc;
305307
struct crypto_cipher *tfm_aes;
306308
u64 sfn = 0;
307309
__le64 sfn_le;
308310

309-
tfm_cbc = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
311+
tfm_cbc = crypto_alloc_skcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
310312
if (IS_ERR(tfm_cbc)) {
311313
result = PTR_ERR(tfm_cbc);
312314
printk(KERN_ERR "E: can't load CBC(AES): %d\n", (int)result);
313315
goto error_alloc_cbc;
314316
}
315-
result = crypto_blkcipher_setkey(tfm_cbc, key, 16);
317+
result = crypto_skcipher_setkey(tfm_cbc, key, 16);
316318
if (result < 0) {
317319
printk(KERN_ERR "E: can't set CBC key: %d\n", (int)result);
318320
goto error_setkey_cbc;
@@ -345,7 +347,7 @@ ssize_t wusb_prf(void *out, size_t out_size,
345347
crypto_free_cipher(tfm_aes);
346348
error_alloc_aes:
347349
error_setkey_cbc:
348-
crypto_free_blkcipher(tfm_cbc);
350+
crypto_free_skcipher(tfm_cbc);
349351
error_alloc_cbc:
350352
return result;
351353
}

0 commit comments

Comments
 (0)