Commit b4021a7a authored by James Morris's avatar James Morris

[CRYPTO]: Run tcrypt through lindent, plus doc update.

parent 612893c0
......@@ -46,7 +46,8 @@ static int mode = 0;
static char *xbuf;
static char *tvmem;
static void hexdump(unsigned char *buf, size_t len)
static void
hexdump(unsigned char *buf, size_t len)
{
while (len--)
printk("%02x", *buf++);
......@@ -54,7 +55,8 @@ static void hexdump(unsigned char *buf, size_t len)
printk("\n");
}
static void test_md5(void)
static void
test_md5(void)
{
char *p;
int i;
......@@ -67,14 +69,15 @@ static void test_md5(void)
printk("\ntesting md5\n");
tsize = sizeof(md5_tv_template);
tsize = sizeof (md5_tv_template);
if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, TVMEMSIZE);
printk("template (%Zd) too big for tvmem (%d)\n", tsize,
TVMEMSIZE);
return;
}
memcpy(tvmem, md5_tv_template, tsize);
md5_tv = (void *)tvmem;
md5_tv = (void *) tvmem;
tfm = crypto_alloc_tfm("md5", 0);
if (tfm == NULL) {
......@@ -84,11 +87,11 @@ static void test_md5(void)
for (i = 0; i < MD5_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1);
memset(result, 0, sizeof(result));
memset(result, 0, sizeof (result));
p = md5_tv[i].plaintext;
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = strlen(md5_tv[i].plaintext);
crypto_digest_init(tfm);
......@@ -96,85 +99,99 @@ static void test_md5(void)
crypto_digest_final(tfm, result);
hexdump(result, crypto_tfm_alg_digestsize(tfm));
printk("%s\n", memcmp(result, md5_tv[i].digest, crypto_tfm_alg_digestsize(tfm)) ? "fail" : "pass");
printk("%s\n",
memcmp(result, md5_tv[i].digest,
crypto_tfm_alg_digestsize(tfm)) ? "fail" :
"pass");
}
printk("\ntesting md5 across pages\n");
/* setup the dummy buffer first */
memset(xbuf, 0, sizeof(xbuf));
memset(xbuf, 0, sizeof (xbuf));
memcpy(&xbuf[IDX1], "abcdefghijklm", 13);
memcpy(&xbuf[IDX2], "nopqrstuvwxyz", 13);
p = &xbuf[IDX1];
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = 13;
p = &xbuf[IDX2];
sg[1].page = virt_to_page(p);
sg[1].offset = ((long)p & ~PAGE_MASK);
sg[1].offset = ((long) p & ~PAGE_MASK);
sg[1].length = 13;
memset(result, 0, sizeof(result));
memset(result, 0, sizeof (result));
crypto_digest_digest(tfm, sg, 2, result);
hexdump(result, crypto_tfm_alg_digestsize(tfm));
printk("%s\n", memcmp(result, md5_tv[4].digest, crypto_tfm_alg_digestsize(tfm)) ? "fail" : "pass");
printk("%s\n",
memcmp(result, md5_tv[4].digest,
crypto_tfm_alg_digestsize(tfm)) ? "fail" : "pass");
printk("\ntesting hmac_md5\n");
tsize = sizeof(hmac_md5_tv_template);
tsize = sizeof (hmac_md5_tv_template);
if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, TVMEMSIZE);
printk("template (%Zd) too big for tvmem (%d)\n", tsize,
TVMEMSIZE);
return;
}
memcpy(tvmem, hmac_md5_tv_template, tsize);
hmac_md5_tv = (void *)tvmem;
hmac_md5_tv = (void *) tvmem;
for (i = 0; i < HMAC_MD5_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1);
memset(result, 0, sizeof(result));
memset(result, 0, sizeof (result));
p = hmac_md5_tv[i].plaintext;
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = strlen(hmac_md5_tv[i].plaintext);
crypto_digest_hmac(tfm, hmac_md5_tv[i].key, strlen(hmac_md5_tv[i].key),sg , 1, result);
crypto_digest_hmac(tfm, hmac_md5_tv[i].key,
strlen(hmac_md5_tv[i].key), sg, 1, result);
hexdump(result, crypto_tfm_alg_digestsize(tfm));
printk("%s\n", memcmp(result, hmac_md5_tv[i].digest, crypto_tfm_alg_digestsize(tfm)) ? "fail" : "pass");
printk("%s\n",
memcmp(result, hmac_md5_tv[i].digest,
crypto_tfm_alg_digestsize(tfm)) ? "fail" :
"pass");
}
printk("\ntesting hmac_md5 across pages\n");
memset(xbuf, 0, sizeof(xbuf));
memset(xbuf, 0, sizeof (xbuf));
memcpy(&xbuf[IDX1], "what do ya want ", 16);
memcpy(&xbuf[IDX2], "for nothing?", 12);
p = &xbuf[IDX1];
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = 16;
p = &xbuf[IDX2];
sg[1].page = virt_to_page(p);
sg[1].offset = ((long)p & ~PAGE_MASK);
sg[1].offset = ((long) p & ~PAGE_MASK);
sg[1].length = 12;
memset(result, 0, sizeof(result));
crypto_digest_hmac(tfm, hmac_md5_tv[1].key, strlen(hmac_md5_tv[1].key), sg, 2, result);
memset(result, 0, sizeof (result));
crypto_digest_hmac(tfm, hmac_md5_tv[1].key, strlen(hmac_md5_tv[1].key),
sg, 2, result);
hexdump(result, crypto_tfm_alg_digestsize(tfm));
printk("%s\n", memcmp(result, hmac_md5_tv[1].digest, crypto_tfm_alg_digestsize(tfm)) ? "fail" : "pass");
printk("%s\n",
memcmp(result, hmac_md5_tv[1].digest,
crypto_tfm_alg_digestsize(tfm)) ? "fail" : "pass");
crypto_free_tfm(tfm);
}
static void test_md4(void)
static void
test_md4(void)
{
char *p;
int i;
......@@ -186,14 +203,15 @@ static void test_md4(void)
printk("\ntesting md4\n");
tsize = sizeof(md4_tv_template);
tsize = sizeof (md4_tv_template);
if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, TVMEMSIZE);
printk("template (%Zd) too big for tvmem (%d)\n", tsize,
TVMEMSIZE);
return;
}
memcpy(tvmem, md4_tv_template, tsize);
md4_tv = (void *)tvmem;
md4_tv = (void *) tvmem;
tfm = crypto_alloc_tfm("md4", 0);
if (tfm == NULL) {
......@@ -203,23 +221,27 @@ static void test_md4(void)
for (i = 0; i < MD4_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1);
memset(result, 0, sizeof(result));
memset(result, 0, sizeof (result));
p = md4_tv[i].plaintext;
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = strlen(md4_tv[i].plaintext);
crypto_digest_digest(tfm, sg, 1, result);
hexdump(result, crypto_tfm_alg_digestsize(tfm));
printk("%s\n", memcmp(result, md4_tv[i].digest, crypto_tfm_alg_digestsize(tfm)) ? "fail" : "pass");
printk("%s\n",
memcmp(result, md4_tv[i].digest,
crypto_tfm_alg_digestsize(tfm)) ? "fail" :
"pass");
}
crypto_free_tfm(tfm);
}
static void test_sha1(void)
static void
test_sha1(void)
{
char *p;
int i;
......@@ -232,14 +254,15 @@ static void test_sha1(void)
printk("\ntesting sha1\n");
tsize = sizeof(sha1_tv_template);
tsize = sizeof (sha1_tv_template);
if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, TVMEMSIZE);
printk("template (%Zd) too big for tvmem (%d)\n", tsize,
TVMEMSIZE);
return;
}
memcpy(tvmem, sha1_tv_template, tsize);
sha1_tv = (void *)tvmem;
sha1_tv = (void *) tvmem;
tfm = crypto_alloc_tfm("sha1", 0);
if (tfm == NULL) {
......@@ -249,11 +272,11 @@ static void test_sha1(void)
for (i = 0; i < SHA1_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1);
memset(result, 0, sizeof(result));
memset(result, 0, sizeof (result));
p = sha1_tv[i].plaintext;
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = strlen(sha1_tv[i].plaintext);
crypto_digest_init(tfm);
......@@ -261,84 +284,98 @@ static void test_sha1(void)
crypto_digest_final(tfm, result);
hexdump(result, crypto_tfm_alg_digestsize(tfm));
printk("%s\n", memcmp(result, sha1_tv[i].digest, crypto_tfm_alg_digestsize(tfm)) ? "fail" : "pass");
printk("%s\n",
memcmp(result, sha1_tv[i].digest,
crypto_tfm_alg_digestsize(tfm)) ? "fail" :
"pass");
}
printk("\ntesting sha1 across pages\n");
/* setup the dummy buffer first */
memset(xbuf, 0, sizeof(xbuf));
memset(xbuf, 0, sizeof (xbuf));
memcpy(&xbuf[IDX1], "abcdbcdecdefdefgefghfghighij", 28);
memcpy(&xbuf[IDX2], "hijkijkljklmklmnlmnomnopnopq", 28);
p = &xbuf[IDX1];
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = 28;
p = &xbuf[IDX2];
sg[1].page = virt_to_page(p);
sg[1].offset = ((long)p & ~PAGE_MASK);
sg[1].offset = ((long) p & ~PAGE_MASK);
sg[1].length = 28;
memset(result, 0, sizeof(result));
memset(result, 0, sizeof (result));
crypto_digest_digest(tfm, sg, 2, result);
hexdump(result, crypto_tfm_alg_digestsize(tfm));
printk("%s\n", memcmp(result, sha1_tv[1].digest, crypto_tfm_alg_digestsize(tfm)) ? "fail" : "pass");
printk("%s\n",
memcmp(result, sha1_tv[1].digest,
crypto_tfm_alg_digestsize(tfm)) ? "fail" : "pass");
printk("\ntesting hmac_sha1\n");
tsize = sizeof(hmac_sha1_tv_template);
tsize = sizeof (hmac_sha1_tv_template);
if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, TVMEMSIZE);
printk("template (%Zd) too big for tvmem (%d)\n", tsize,
TVMEMSIZE);
return;
}
memcpy(tvmem, hmac_sha1_tv_template, tsize);
hmac_sha1_tv = (void *)tvmem;
hmac_sha1_tv = (void *) tvmem;
for (i = 0; i < HMAC_SHA1_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1);
memset(result, 0, sizeof(result));
memset(result, 0, sizeof (result));
p = hmac_sha1_tv[i].plaintext;
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = strlen(hmac_sha1_tv[i].plaintext);
crypto_digest_hmac(tfm, hmac_sha1_tv[i].key, strlen(hmac_sha1_tv[i].key),sg , 1, result);
crypto_digest_hmac(tfm, hmac_sha1_tv[i].key,
strlen(hmac_sha1_tv[i].key), sg, 1, result);
hexdump(result, sizeof(result));
printk("%s\n", memcmp(result, hmac_sha1_tv[i].digest, crypto_tfm_alg_digestsize(tfm)) ? "fail" : "pass");
hexdump(result, sizeof (result));
printk("%s\n",
memcmp(result, hmac_sha1_tv[i].digest,
crypto_tfm_alg_digestsize(tfm)) ? "fail" :
"pass");
}
printk("\ntesting hmac_sha1 across pages\n");
/* setup the dummy buffer first */
memset(xbuf, 0, sizeof(xbuf));
memset(xbuf, 0, sizeof (xbuf));
memcpy(&xbuf[IDX1], "what do ya want ", 16);
memcpy(&xbuf[IDX2], "for nothing?", 12);
p = &xbuf[IDX1];
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = 16;
p = &xbuf[IDX2];
sg[1].page = virt_to_page(p);
sg[1].offset = ((long)p & ~PAGE_MASK);
sg[1].offset = ((long) p & ~PAGE_MASK);
sg[1].length = 12;
memset(result, 0, sizeof(result));
crypto_digest_hmac(tfm, hmac_sha1_tv[1].key, strlen(hmac_sha1_tv[1].key), sg, 2, result);
memset(result, 0, sizeof (result));
crypto_digest_hmac(tfm, hmac_sha1_tv[1].key,
strlen(hmac_sha1_tv[1].key), sg, 2, result);
hexdump(result, crypto_tfm_alg_digestsize(tfm));
printk("%s\n", memcmp(result, hmac_sha1_tv[1].digest, crypto_tfm_alg_digestsize(tfm)) ? "fail" : "pass");
printk("%s\n",
memcmp(result, hmac_sha1_tv[1].digest,
crypto_tfm_alg_digestsize(tfm)) ? "fail" : "pass");
crypto_free_tfm(tfm);
}
void test_des(void)
void
test_des(void)
{
int ret, i, len;
size_t tsize;
......@@ -351,14 +388,15 @@ void test_des(void)
printk("\ntesting des encryption\n");
tsize = sizeof(des_enc_tv_template);
tsize = sizeof (des_enc_tv_template);
if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, TVMEMSIZE);
printk("template (%Zd) too big for tvmem (%d)\n", tsize,
TVMEMSIZE);
return;
}
memcpy(tvmem, des_enc_tv_template, tsize);
des_tv = (void *)tvmem;
des_tv = (void *) tvmem;
tfm = crypto_alloc_tfm("des", 0);
if (tfm == NULL) {
......@@ -384,7 +422,7 @@ void test_des(void)
p = des_tv[i].plaintext;
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = len;
ret = crypto_cipher_encrypt(tfm, sg, 1);
if (ret) {
......@@ -395,7 +433,8 @@ void test_des(void)
q = kmap(sg[0].page) + sg[0].offset;
hexdump(q, len);
printk("%s\n", memcmp(q, des_tv[i].result, len) ? "fail" : "pass");
printk("%s\n",
memcmp(q, des_tv[i].result, len) ? "fail" : "pass");
}
......@@ -414,18 +453,18 @@ void test_des(void)
}
/* setup the dummy buffer first */
memset(xbuf, 0, sizeof(xbuf));
memset(xbuf, 0, sizeof (xbuf));
memcpy(&xbuf[IDX1], des_tv[i].plaintext, 8);
memcpy(&xbuf[IDX2], des_tv[i].plaintext + 8 , 8);
memcpy(&xbuf[IDX2], des_tv[i].plaintext + 8, 8);
p = &xbuf[IDX1];
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = 8;
p = &xbuf[IDX2];
sg[1].page = virt_to_page(p);
sg[1].offset = ((long)p & ~PAGE_MASK);
sg[1].offset = ((long) p & ~PAGE_MASK);
sg[1].length = 8;
ret = crypto_cipher_encrypt(tfm, sg, 2);
......@@ -470,7 +509,7 @@ void test_des(void)
}
/* setup the dummy buffer first */
memset(xbuf, 0, sizeof(xbuf));
memset(xbuf, 0, sizeof (xbuf));
/* Frag 1: 8 + 6 */
memcpy(&xbuf[IDX3], des_tv[i].plaintext, 14);
......@@ -483,17 +522,17 @@ void test_des(void)
p = &xbuf[IDX3];
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = 14;
p = &xbuf[IDX4];
sg[1].page = virt_to_page(p);
sg[1].offset = ((long)p & ~PAGE_MASK);
sg[1].offset = ((long) p & ~PAGE_MASK);
sg[1].length = 10;
p = &xbuf[IDX5];
sg[2].page = virt_to_page(p);
sg[2].offset = ((long)p & ~PAGE_MASK);
sg[2].offset = ((long) p & ~PAGE_MASK);
sg[2].length = 8;
ret = crypto_cipher_encrypt(tfm, sg, 3);
......@@ -538,7 +577,7 @@ void test_des(void)
}
/* setup the dummy buffer first */
memset(xbuf, 0, sizeof(xbuf));
memset(xbuf, 0, sizeof (xbuf));
/* Frag 1: 2 */
memcpy(&xbuf[IDX3], des_tv[i].plaintext, 2);
......@@ -554,22 +593,22 @@ void test_des(void)
p = &xbuf[IDX3];
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = 2;
p = &xbuf[IDX4];
sg[1].page = virt_to_page(p);
sg[1].offset = ((long)p & ~PAGE_MASK);
sg[1].offset = ((long) p & ~PAGE_MASK);
sg[1].length = 1;
p = &xbuf[IDX5];
sg[2].page = virt_to_page(p);
sg[2].offset = ((long)p & ~PAGE_MASK);
sg[2].offset = ((long) p & ~PAGE_MASK);
sg[2].length = 3;
p = &xbuf[IDX6];
sg[3].page = virt_to_page(p);
sg[3].offset = ((long)p & ~PAGE_MASK);
sg[3].offset = ((long) p & ~PAGE_MASK);
sg[3].length = 18;
ret = crypto_cipher_encrypt(tfm, sg, 4);
......@@ -619,7 +658,7 @@ void test_des(void)
}
/* setup the dummy buffer first */
memset(xbuf, 0, sizeof(xbuf));
memset(xbuf, 0, sizeof (xbuf));
/* Frag 1: 2 */
memcpy(&xbuf[IDX3], des_tv[i].plaintext, 2);
......@@ -638,27 +677,27 @@ void test_des(void)
p = &xbuf[IDX3];
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = 2;
p = &xbuf[IDX4];
sg[1].page = virt_to_page(p);
sg[1].offset = ((long)p & ~PAGE_MASK);
sg[1].offset = ((long) p & ~PAGE_MASK);
sg[1].length = 2;
p = &xbuf[IDX5];
sg[2].page = virt_to_page(p);
sg[2].offset = ((long)p & ~PAGE_MASK);
sg[2].offset = ((long) p & ~PAGE_MASK);
sg[2].length = 2;
p = &xbuf[IDX6];
sg[3].page = virt_to_page(p);
sg[3].offset = ((long)p & ~PAGE_MASK);
sg[3].offset = ((long) p & ~PAGE_MASK);
sg[3].length = 2;
p = &xbuf[IDX7];
sg[4].page = virt_to_page(p);
sg[4].offset = ((long)p & ~PAGE_MASK);
sg[4].offset = ((long) p & ~PAGE_MASK);
sg[4].length = 8;
ret = crypto_cipher_encrypt(tfm, sg, 5);
......@@ -709,7 +748,7 @@ void test_des(void)
}
/* setup the dummy buffer first */
memset(xbuf, 0, sizeof(xbuf));
memset(xbuf, 0, sizeof (xbuf));
xbuf[IDX1] = des_tv[i].plaintext[0];
xbuf[IDX2] = des_tv[i].plaintext[1];
......@@ -722,42 +761,42 @@ void test_des(void)
p = &xbuf[IDX1];
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = 1;
p = &xbuf[IDX2];
sg[1].page = virt_to_page(p);
sg[1].offset = ((long)p & ~PAGE_MASK);
sg[1].offset = ((long) p & ~PAGE_MASK);
sg[1].length = 1;
p = &xbuf[IDX3];
sg[2].page = virt_to_page(p);
sg[2].offset = ((long)p & ~PAGE_MASK);
sg[2].offset = ((long) p & ~PAGE_MASK);
sg[2].length = 1;
p = &xbuf[IDX4];
sg[3].page = virt_to_page(p);
sg[3].offset = ((long)p & ~PAGE_MASK);
sg[3].offset = ((long) p & ~PAGE_MASK);
sg[3].length = 1;
p = &xbuf[IDX5];
sg[4].page = virt_to_page(p);
sg[4].offset = ((long)p & ~PAGE_MASK);
sg[4].offset = ((long) p & ~PAGE_MASK);
sg[4].length = 1;
p = &xbuf[IDX6];
sg[5].page = virt_to_page(p);
sg[5].offset = ((long)p & ~PAGE_MASK);
sg[5].offset = ((long) p & ~PAGE_MASK);
sg[5].length = 1;
p = &xbuf[IDX7];
sg[6].page = virt_to_page(p);
sg[6].offset = ((long)p & ~PAGE_MASK);
sg[6].offset = ((long) p & ~PAGE_MASK);
sg[6].length = 1;
p = &xbuf[IDX8];
sg[7].page = virt_to_page(p);
sg[7].offset = ((long)p & ~PAGE_MASK);
sg[7].offset = ((long) p & ~PAGE_MASK);
sg[7].length = 1;
ret = crypto_cipher_encrypt(tfm, sg, 8);
......@@ -767,21 +806,21 @@ void test_des(void)
}
for (i = 0; i < 8; i++)
res[i] = *(char *)(kmap(sg[i].page) + sg[i].offset);
res[i] = *(char *) (kmap(sg[i].page) + sg[i].offset);
hexdump(res, 8);
printk("%s\n", memcmp(res, des_tv[7].result, 8) ? "fail" : "pass");
printk("\ntesting des decryption\n");
tsize = sizeof(des_dec_tv_template);
tsize = sizeof (des_dec_tv_template);
if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, TVMEMSIZE);
printk("template (%Zd) too big for tvmem (%d)\n", tsize,
TVMEMSIZE);
return;
}
memcpy(tvmem, des_dec_tv_template, tsize);
des_tv = (void *)tvmem;
des_tv = (void *) tvmem;
for (i = 0; i < DES_DEC_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1);
......@@ -799,19 +838,21 @@ void test_des(void)
p = des_tv[i].plaintext;
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = len;
ret = crypto_cipher_decrypt(tfm, sg, 1);
if (ret) {
printk("des_decrypt() failed flags=%x\n", tfm->crt_flags);
printk("des_decrypt() failed flags=%x\n",
tfm->crt_flags);
goto out;
}
q = kmap(sg[0].page) + sg[0].offset;
hexdump(q, len);
printk("%s\n", memcmp(q, des_tv[i].result, len) ? "fail" : "pass");
printk("%s\n",
memcmp(q, des_tv[i].result, len) ? "fail" : "pass");
}
......@@ -829,18 +870,18 @@ void test_des(void)
}
/* setup the dummy buffer first */
memset(xbuf, 0, sizeof(xbuf));
memset(xbuf, 0, sizeof (xbuf));
memcpy(&xbuf[IDX1], des_tv[i].plaintext, 8);
memcpy(&xbuf[IDX2], des_tv[i].plaintext + 8 , 8);
memcpy(&xbuf[IDX2], des_tv[i].plaintext + 8, 8);
p = &xbuf[IDX1];
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = 8;
p = &xbuf[IDX2];
sg[1].page = virt_to_page(p);
sg[1].offset = ((long)p & ~PAGE_MASK);
sg[1].offset = ((long) p & ~PAGE_MASK);
sg[1].length = 8;
ret = crypto_cipher_decrypt(tfm, sg, 2);
......@@ -859,7 +900,6 @@ void test_des(void)
hexdump(q, 8);
printk("%s\n", memcmp(q, des_tv[i].result + 8, 8) ? "fail" : "pass");
/*
* Scenario E:
*
......@@ -880,7 +920,7 @@ void test_des(void)
}
/* setup the dummy buffer first */
memset(xbuf, 0, sizeof(xbuf));
memset(xbuf, 0, sizeof (xbuf));
memcpy(&xbuf[IDX1], des_tv[i].plaintext, 3);
memcpy(&xbuf[IDX2], des_tv[i].plaintext + 3, 12);
......@@ -888,17 +928,17 @@ void test_des(void)
p = &xbuf[IDX1];
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = 3;
p = &xbuf[IDX2];
sg[1].page = virt_to_page(p);
sg[1].offset = ((long)p & ~PAGE_MASK);
sg[1].offset = ((long) p & ~PAGE_MASK);
sg[1].length = 12;
p = &xbuf[IDX3];
sg[2].page = virt_to_page(p);
sg[2].offset = ((long)p & ~PAGE_MASK);
sg[2].offset = ((long) p & ~PAGE_MASK);
sg[2].length = 1;
ret = crypto_cipher_decrypt(tfm, sg, 3);
......@@ -933,13 +973,14 @@ void test_des(void)
printk("\ntesting des cbc encryption (atomic)\n");
tsize = sizeof(des_cbc_enc_tv_template);
tsize = sizeof (des_cbc_enc_tv_template);
if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, TVMEMSIZE);
printk("template (%Zd) too big for tvmem (%d)\n", tsize,
TVMEMSIZE);
return;
}
memcpy(tvmem, des_cbc_enc_tv_template, tsize);
des_tv = (void *)tvmem;
des_tv = (void *) tvmem;
for (i = 0; i < DES_CBC_ENC_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1);
......@@ -957,21 +998,24 @@ void test_des(void)
p = des_tv[i].plaintext;
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = len;
crypto_cipher_copy_iv(tfm, des_tv[i].iv, crypto_tfm_alg_ivsize(tfm));
crypto_cipher_copy_iv(tfm, des_tv[i].iv,
crypto_tfm_alg_ivsize(tfm));
ret = crypto_cipher_encrypt(tfm, sg, 1);
if (ret) {
printk("des_cbc_encrypt() failed flags=%x\n", tfm->crt_flags);
printk("des_cbc_encrypt() failed flags=%x\n",
tfm->crt_flags);
goto out;
}
q = kmap(sg[0].page) + sg[0].offset;
hexdump(q, len);
printk("%s\n", memcmp(q, des_tv[i].result, len) ? "fail" : "pass");
printk("%s\n",
memcmp(q, des_tv[i].result, len) ? "fail" : "pass");
}
crypto_free_tfm(tfm);
......@@ -1002,19 +1046,19 @@ void test_des(void)
}
/* setup the dummy buffer first */
memset(xbuf, 0, sizeof(xbuf));
memset(xbuf, 0, sizeof (xbuf));
memcpy(&xbuf[IDX1], des_tv[i].plaintext, 13);
memcpy(&xbuf[IDX2], des_tv[i].plaintext + 13, 11);
p = &xbuf[IDX1];
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = 13;
p = &xbuf[IDX2];
sg[1].page = virt_to_page(p);
sg[1].offset = ((long)p & ~PAGE_MASK);
sg[1].offset = ((long) p & ~PAGE_MASK);
sg[1].length = 11;
crypto_cipher_copy_iv(tfm, des_tv[i].iv, crypto_tfm_alg_ivsize(tfm));
......@@ -1035,14 +1079,14 @@ void test_des(void)
hexdump(q, 11);
printk("%s\n", memcmp(q, des_tv[i].result + 13, 11) ? "fail" : "pass");
tsize = sizeof(des_cbc_dec_tv_template);
tsize = sizeof (des_cbc_dec_tv_template);
if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, TVMEMSIZE);
printk("template (%Zd) too big for tvmem (%d)\n", tsize,
TVMEMSIZE);
return;
}
memcpy(tvmem, des_cbc_dec_tv_template, tsize);
des_tv = (void *)tvmem;
des_tv = (void *) tvmem;
printk("\ntesting des cbc decryption\n");
......@@ -1062,14 +1106,16 @@ void test_des(void)
p = des_tv[i].plaintext;
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = len;
crypto_cipher_copy_iv(tfm, des_tv[i].iv, crypto_tfm_alg_blocksize(tfm));
crypto_cipher_copy_iv(tfm, des_tv[i].iv,
crypto_tfm_alg_blocksize(tfm));
ret = crypto_cipher_decrypt(tfm, sg, 1);
if (ret) {
printk("des_cbc_decrypt() failed flags=%x\n", tfm->crt_flags);
printk("des_cbc_decrypt() failed flags=%x\n",
tfm->crt_flags);
goto out;
}
......@@ -1078,7 +1124,8 @@ void test_des(void)
q = kmap(sg[0].page) + sg[0].offset;
hexdump(q, len);
printk("%s\n", memcmp(q, des_tv[i].result, len) ? "fail" : "pass");
printk("%s\n",
memcmp(q, des_tv[i].result, len) ? "fail" : "pass");
}
/*
......@@ -1101,18 +1148,18 @@ void test_des(void)
}
/* setup the dummy buffer first */
memset(xbuf, 0, sizeof(xbuf));
memset(xbuf, 0, sizeof (xbuf));
memcpy(&xbuf[IDX1], des_tv[i].plaintext, 4);
memcpy(&xbuf[IDX2], des_tv[i].plaintext + 4, 4);
p = &xbuf[IDX1];
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = 4;
p = &xbuf[IDX2];
sg[1].page = virt_to_page(p);
sg[1].offset = ((long)p & ~PAGE_MASK);
sg[1].offset = ((long) p & ~PAGE_MASK);
sg[1].length = 4;
crypto_cipher_copy_iv(tfm, des_tv[i].iv, crypto_tfm_alg_ivsize(tfm));
......@@ -1133,32 +1180,34 @@ void test_des(void)
hexdump(q, 4);
printk("%s\n", memcmp(q, des_tv[i].result + 4, 4) ? "fail" : "pass");
out:
out:
crypto_free_tfm(tfm);
return;
}
void test_des3_ede(void)
void
test_des3_ede(void)
{
int ret, i, len;
size_t tsize;
char *p, *q;
struct crypto_tfm *tfm;
char *key;
/*char res[8];*/
/*char res[8]; */
struct des_tv *des_tv;
struct scatterlist sg[8];
printk("\ntesting des3 ede encryption\n");
tsize = sizeof(des3_ede_enc_tv_template);
tsize = sizeof (des3_ede_enc_tv_template);
if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, TVMEMSIZE);
printk("template (%Zd) too big for tvmem (%d)\n", tsize,
TVMEMSIZE);
return;
}
memcpy(tvmem, des3_ede_enc_tv_template, tsize);
des_tv = (void *)tvmem;
des_tv = (void *) tvmem;
tfm = crypto_alloc_tfm("des3_ede", CRYPTO_TFM_MODE_ECB);
if (tfm == NULL) {
......@@ -1182,7 +1231,7 @@ void test_des3_ede(void)
p = des_tv[i].plaintext;
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = len;
ret = crypto_cipher_encrypt(tfm, sg, 1);
if (ret) {
......@@ -1193,19 +1242,21 @@ void test_des3_ede(void)
q = kmap(sg[0].page) + sg[0].offset;
hexdump(q, len);
printk("%s\n", memcmp(q, des_tv[i].result, len) ? "fail" : "pass");
printk("%s\n",
memcmp(q, des_tv[i].result, len) ? "fail" : "pass");
}
printk("\ntesting des3 ede decryption\n");
tsize = sizeof(des3_ede_dec_tv_template);
tsize = sizeof (des3_ede_dec_tv_template);
if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, TVMEMSIZE);
printk("template (%Zd) too big for tvmem (%d)\n", tsize,
TVMEMSIZE);
return;
}
memcpy(tvmem, des3_ede_dec_tv_template, tsize);
des_tv = (void *)tvmem;
des_tv = (void *) tvmem;
for (i = 0; i < DES3_EDE_DEC_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1);
......@@ -1223,7 +1274,7 @@ void test_des3_ede(void)
p = des_tv[i].plaintext;
sg[0].page = virt_to_page(p);
sg[0].offset = ((long)p & ~PAGE_MASK);
sg[0].offset = ((long) p & ~PAGE_MASK);
sg[0].length = len;
ret = crypto_cipher_decrypt(tfm, sg, 1);
if (ret) {
......@@ -1234,16 +1285,17 @@ void test_des3_ede(void)
q = kmap(sg[0].page) + sg[0].offset;
hexdump(q, len);
printk("%s\n", memcmp(q, des_tv[i].result, len) ? "fail" : "pass");
printk("%s\n",
memcmp(q, des_tv[i].result, len) ? "fail" : "pass");
}
out:
out:
crypto_free_tfm(tfm);
return;
}
static void do_test(void)
static void
do_test(void)
{
switch (mode) {
......@@ -1282,8 +1334,8 @@ static void do_test(void)
}
}
static int __init init(void)
static int __init
init(void)
{
tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
if (tvmem == NULL)
......
......@@ -59,7 +59,8 @@ struct md4_testvec {
0x1c, 0xe6, 0x27, 0xe1, 0x53, 0xe7, 0xf0, 0xe4 }
},
{ "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
{ "123456789012345678901234567890123456789012345678901234567890123"
"45678901234567890",
{ 0xe3, 0x3b, 0x4d, 0xdc, 0x9c, 0x38, 0xf2, 0x19,
0x9c, 0x3e, 0x7b, 0x16, 0x4f, 0xcc, 0x05, 0x36 }
},
......@@ -146,7 +147,8 @@ struct hmac_md5_testvec hmac_md5_tv_template[] =
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0x00 },
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0x00 },
{ 0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88,
0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6 }
......@@ -162,7 +164,8 @@ struct hmac_md5_testvec hmac_md5_tv_template[] =
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0x00 },
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0x00 },
{ 0x69, 0x7e, 0xaf, 0x0a, 0xca, 0x3a, 0x3a, 0xea,
0x3a, 0x75, 0x16, 0x47, 0x46, 0xff, 0xaa, 0x79 }
......@@ -186,7 +189,8 @@ struct hmac_md5_testvec hmac_md5_tv_template[] =
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x00 },
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0x00 },
"Test Using Larger Than Block-Size Key - Hash Key First",
......@@ -202,9 +206,11 @@ struct hmac_md5_testvec hmac_md5_tv_template[] =
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x00 },
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0x00 },
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
"Test Using Larger Than Block-Size Key and Larger Than One "
"Block-Size Data",
{ 0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee,
0x1f, 0xb1, 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e }
......@@ -226,7 +232,8 @@ struct hmac_sha1_testvec {
{
{ 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x00},
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x00},
"Hi There",
......@@ -247,14 +254,16 @@ struct hmac_sha1_testvec {
{
{ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x00},
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0x00},
{ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0x00 },
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0x00 },
{ 0x12, 0x5d, 0x73, 0x42, 0xb9, 0xac, 0x11, 0xcd, 0x91, 0xa3,
0x9a, 0xf4, 0x8a, 0xa1, 0x7b, 0x4f, 0x63, 0xf1, 0x75, 0xd3 }
......@@ -271,7 +280,8 @@ struct hmac_sha1_testvec {
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0x00 },
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0x00 },
{ 0x4c, 0x90, 0x07, 0xf4, 0x02, 0x62, 0x50, 0xc6, 0xbc, 0x84,
0x14, 0xf9, 0xbf, 0x50, 0xc8, 0x6c, 0x2d, 0x72, 0x35, 0xda }
......@@ -280,7 +290,8 @@ struct hmac_sha1_testvec {
{
{ 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x00 },
0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
0x00 },
"Test With Truncation",
......@@ -297,7 +308,8 @@ struct hmac_sha1_testvec {
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x00 },
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0x00 },
"Test Using Larger Than Block-Size Key - Hash Key First",
......@@ -314,9 +326,11 @@ struct hmac_sha1_testvec {
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x00 },
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0x00 },
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
"Test Using Larger Than Block-Size Key and Larger Than One "
"Block-Size Data",
{ 0xe8, 0xe9, 0x9d, 0x0f, 0x45, 0x23, 0x7d, 0x78, 0x6d, 0x6b,
0xba, 0xa7, 0x96, 0x5c, 0x78, 0x08, 0xbb, 0xff, 0x1a, 0x91 }
......
......@@ -166,6 +166,9 @@ struct crypto_tfm {
* If that fails and the kernel supports dynamically loadable modules, it
* will then attempt to load a module of the same name or alias. A refcount
* is grabbed on the algorithm which is then associated with the new transform.
*
* crypto_free_tfm() frees up the transform and any associated resources,
* then drops the refcount on the associated algorithm.
*/
struct crypto_tfm *crypto_alloc_tfm(char *alg_name, u32 tfm_flags);
void crypto_free_tfm(struct crypto_tfm *tfm);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment