aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'crypto')
-rw-r--r--crypto/hmac.c19
-rw-r--r--crypto/tcrypt.c52
2 files changed, 20 insertions, 51 deletions
diff --git a/crypto/hmac.c b/crypto/hmac.c
index da0456b37109..46120dee5ada 100644
--- a/crypto/hmac.c
+++ b/crypto/hmac.c
@@ -18,18 +18,15 @@
18#include <linux/mm.h> 18#include <linux/mm.h>
19#include <linux/highmem.h> 19#include <linux/highmem.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <asm/scatterlist.h> 21#include <linux/scatterlist.h>
22#include "internal.h" 22#include "internal.h"
23 23
24static void hash_key(struct crypto_tfm *tfm, u8 *key, unsigned int keylen) 24static void hash_key(struct crypto_tfm *tfm, u8 *key, unsigned int keylen)
25{ 25{
26 struct scatterlist tmp; 26 struct scatterlist tmp;
27 27
28 tmp.page = virt_to_page(key); 28 sg_set_buf(&tmp, key, keylen);
29 tmp.offset = offset_in_page(key);
30 tmp.length = keylen;
31 crypto_digest_digest(tfm, &tmp, 1, key); 29 crypto_digest_digest(tfm, &tmp, 1, key);
32
33} 30}
34 31
35int crypto_alloc_hmac_block(struct crypto_tfm *tfm) 32int crypto_alloc_hmac_block(struct crypto_tfm *tfm)
@@ -69,9 +66,7 @@ void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen)
69 for (i = 0; i < crypto_tfm_alg_blocksize(tfm); i++) 66 for (i = 0; i < crypto_tfm_alg_blocksize(tfm); i++)
70 ipad[i] ^= 0x36; 67 ipad[i] ^= 0x36;
71 68
72 tmp.page = virt_to_page(ipad); 69 sg_set_buf(&tmp, ipad, crypto_tfm_alg_blocksize(tfm));
73 tmp.offset = offset_in_page(ipad);
74 tmp.length = crypto_tfm_alg_blocksize(tfm);
75 70
76 crypto_digest_init(tfm); 71 crypto_digest_init(tfm);
77 crypto_digest_update(tfm, &tmp, 1); 72 crypto_digest_update(tfm, &tmp, 1);
@@ -103,16 +98,12 @@ void crypto_hmac_final(struct crypto_tfm *tfm, u8 *key,
103 for (i = 0; i < crypto_tfm_alg_blocksize(tfm); i++) 98 for (i = 0; i < crypto_tfm_alg_blocksize(tfm); i++)
104 opad[i] ^= 0x5c; 99 opad[i] ^= 0x5c;
105 100
106 tmp.page = virt_to_page(opad); 101 sg_set_buf(&tmp, opad, crypto_tfm_alg_blocksize(tfm));
107 tmp.offset = offset_in_page(opad);
108 tmp.length = crypto_tfm_alg_blocksize(tfm);
109 102
110 crypto_digest_init(tfm); 103 crypto_digest_init(tfm);
111 crypto_digest_update(tfm, &tmp, 1); 104 crypto_digest_update(tfm, &tmp, 1);
112 105
113 tmp.page = virt_to_page(out); 106 sg_set_buf(&tmp, out, crypto_tfm_alg_digestsize(tfm));
114 tmp.offset = offset_in_page(out);
115 tmp.length = crypto_tfm_alg_digestsize(tfm);
116 107
117 crypto_digest_update(tfm, &tmp, 1); 108 crypto_digest_update(tfm, &tmp, 1);
118 crypto_digest_final(tfm, out); 109 crypto_digest_final(tfm, out);
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 68639419c5bd..577a3aff3113 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -21,7 +21,7 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <asm/scatterlist.h> 24#include <linux/scatterlist.h>
25#include <linux/string.h> 25#include <linux/string.h>
26#include <linux/crypto.h> 26#include <linux/crypto.h>
27#include <linux/highmem.h> 27#include <linux/highmem.h>
@@ -86,7 +86,6 @@ static void hexdump(unsigned char *buf, unsigned int len)
86static void test_hash(char *algo, struct hash_testvec *template, 86static void test_hash(char *algo, struct hash_testvec *template,
87 unsigned int tcount) 87 unsigned int tcount)
88{ 88{
89 char *p;
90 unsigned int i, j, k, temp; 89 unsigned int i, j, k, temp;
91 struct scatterlist sg[8]; 90 struct scatterlist sg[8];
92 char result[64]; 91 char result[64];
@@ -116,10 +115,7 @@ static void test_hash(char *algo, struct hash_testvec *template,
116 printk("test %u:\n", i + 1); 115 printk("test %u:\n", i + 1);
117 memset(result, 0, 64); 116 memset(result, 0, 64);
118 117
119 p = hash_tv[i].plaintext; 118 sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
120 sg[0].page = virt_to_page(p);
121 sg[0].offset = offset_in_page(p);
122 sg[0].length = hash_tv[i].psize;
123 119
124 crypto_digest_init(tfm); 120 crypto_digest_init(tfm);
125 if (tfm->crt_u.digest.dit_setkey) { 121 if (tfm->crt_u.digest.dit_setkey) {
@@ -154,10 +150,8 @@ static void test_hash(char *algo, struct hash_testvec *template,
154 hash_tv[i].plaintext + temp, 150 hash_tv[i].plaintext + temp,
155 hash_tv[i].tap[k]); 151 hash_tv[i].tap[k]);
156 temp += hash_tv[i].tap[k]; 152 temp += hash_tv[i].tap[k];
157 p = &xbuf[IDX[k]]; 153 sg_set_buf(&sg[k], &xbuf[IDX[k]],
158 sg[k].page = virt_to_page(p); 154 hash_tv[i].tap[k]);
159 sg[k].offset = offset_in_page(p);
160 sg[k].length = hash_tv[i].tap[k];
161 } 155 }
162 156
163 crypto_digest_digest(tfm, sg, hash_tv[i].np, result); 157 crypto_digest_digest(tfm, sg, hash_tv[i].np, result);
@@ -179,7 +173,6 @@ static void test_hash(char *algo, struct hash_testvec *template,
179static void test_hmac(char *algo, struct hmac_testvec *template, 173static void test_hmac(char *algo, struct hmac_testvec *template,
180 unsigned int tcount) 174 unsigned int tcount)
181{ 175{
182 char *p;
183 unsigned int i, j, k, temp; 176 unsigned int i, j, k, temp;
184 struct scatterlist sg[8]; 177 struct scatterlist sg[8];
185 char result[64]; 178 char result[64];
@@ -210,11 +203,8 @@ static void test_hmac(char *algo, struct hmac_testvec *template,
210 printk("test %u:\n", i + 1); 203 printk("test %u:\n", i + 1);
211 memset(result, 0, sizeof (result)); 204 memset(result, 0, sizeof (result));
212 205
213 p = hmac_tv[i].plaintext;
214 klen = hmac_tv[i].ksize; 206 klen = hmac_tv[i].ksize;
215 sg[0].page = virt_to_page(p); 207 sg_set_buf(&sg[0], hmac_tv[i].plaintext, hmac_tv[i].psize);
216 sg[0].offset = offset_in_page(p);
217 sg[0].length = hmac_tv[i].psize;
218 208
219 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 1, result); 209 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 1, result);
220 210
@@ -243,10 +233,8 @@ static void test_hmac(char *algo, struct hmac_testvec *template,
243 hmac_tv[i].plaintext + temp, 233 hmac_tv[i].plaintext + temp,
244 hmac_tv[i].tap[k]); 234 hmac_tv[i].tap[k]);
245 temp += hmac_tv[i].tap[k]; 235 temp += hmac_tv[i].tap[k];
246 p = &xbuf[IDX[k]]; 236 sg_set_buf(&sg[k], &xbuf[IDX[k]],
247 sg[k].page = virt_to_page(p); 237 hmac_tv[i].tap[k]);
248 sg[k].offset = offset_in_page(p);
249 sg[k].length = hmac_tv[i].tap[k];
250 } 238 }
251 239
252 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 240 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg,
@@ -270,7 +258,7 @@ static void test_cipher(char *algo, int mode, int enc,
270{ 258{
271 unsigned int ret, i, j, k, temp; 259 unsigned int ret, i, j, k, temp;
272 unsigned int tsize; 260 unsigned int tsize;
273 char *p, *q; 261 char *q;
274 struct crypto_tfm *tfm; 262 struct crypto_tfm *tfm;
275 char *key; 263 char *key;
276 struct cipher_testvec *cipher_tv; 264 struct cipher_testvec *cipher_tv;
@@ -330,10 +318,8 @@ static void test_cipher(char *algo, int mode, int enc,
330 goto out; 318 goto out;
331 } 319 }
332 320
333 p = cipher_tv[i].input; 321 sg_set_buf(&sg[0], cipher_tv[i].input,
334 sg[0].page = virt_to_page(p); 322 cipher_tv[i].ilen);
335 sg[0].offset = offset_in_page(p);
336 sg[0].length = cipher_tv[i].ilen;
337 323
338 if (!mode) { 324 if (!mode) {
339 crypto_cipher_set_iv(tfm, cipher_tv[i].iv, 325 crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
@@ -389,10 +375,8 @@ static void test_cipher(char *algo, int mode, int enc,
389 cipher_tv[i].input + temp, 375 cipher_tv[i].input + temp,
390 cipher_tv[i].tap[k]); 376 cipher_tv[i].tap[k]);
391 temp += cipher_tv[i].tap[k]; 377 temp += cipher_tv[i].tap[k];
392 p = &xbuf[IDX[k]]; 378 sg_set_buf(&sg[k], &xbuf[IDX[k]],
393 sg[k].page = virt_to_page(p); 379 cipher_tv[i].tap[k]);
394 sg[k].offset = offset_in_page(p);
395 sg[k].length = cipher_tv[i].tap[k];
396 } 380 }
397 381
398 if (!mode) { 382 if (!mode) {
@@ -436,9 +420,7 @@ static int test_cipher_jiffies(struct crypto_tfm *tfm, int enc, char *p,
436 int bcount; 420 int bcount;
437 int ret; 421 int ret;
438 422
439 sg[0].page = virt_to_page(p); 423 sg_set_buf(&sg[0], p, blen);
440 sg[0].offset = offset_in_page(p);
441 sg[0].length = blen;
442 424
443 for (start = jiffies, end = start + sec * HZ, bcount = 0; 425 for (start = jiffies, end = start + sec * HZ, bcount = 0;
444 time_before(jiffies, end); bcount++) { 426 time_before(jiffies, end); bcount++) {
@@ -464,9 +446,7 @@ static int test_cipher_cycles(struct crypto_tfm *tfm, int enc, char *p,
464 int ret = 0; 446 int ret = 0;
465 int i; 447 int i;
466 448
467 sg[0].page = virt_to_page(p); 449 sg_set_buf(&sg[0], p, blen);
468 sg[0].offset = offset_in_page(p);
469 sg[0].length = blen;
470 450
471 local_bh_disable(); 451 local_bh_disable();
472 local_irq_disable(); 452 local_irq_disable();
@@ -709,9 +689,7 @@ static void test_crc32c(void)
709 for (i = 0; i < NUMVEC; i++) { 689 for (i = 0; i < NUMVEC; i++) {
710 for (j = 0; j < VECSIZE; j++) 690 for (j = 0; j < VECSIZE; j++)
711 test_vec[i][j] = ++b; 691 test_vec[i][j] = ++b;
712 sg[i].page = virt_to_page(test_vec[i]); 692 sg_set_buf(&sg[i], test_vec[i], VECSIZE);
713 sg[i].offset = offset_in_page(test_vec[i]);
714 sg[i].length = VECSIZE;
715 } 693 }
716 694
717 seed = SEEDTESTVAL; 695 seed = SEEDTESTVAL;