diff options
author | Zoltan Sogor <weth@inf.u-szeged.hu> | 2007-12-07 03:48:11 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2008-01-10 16:16:34 -0500 |
commit | 91755a921c4af51c355bcb74a98b717d5c1818b6 (patch) | |
tree | 272e77001ce7a7a836f7ce48e18a24d57b9feca7 | |
parent | 8bff664cdf8797564fb6b59b7be028846fab8c27 (diff) |
[CRYPTO] tcrypt: Add common compression tester function
Add common compression tester function
Modify deflate test case to use the common compressor test function
Signed-off-by: Zoltan Sogor <weth@inf.u-szeged.hu>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/tcrypt.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index a6d4160c37f7..c8d3e600c541 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
@@ -1019,7 +1019,8 @@ out: | |||
1019 | crypto_free_hash(tfm); | 1019 | crypto_free_hash(tfm); |
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | static void test_deflate(void) | 1022 | static void test_comp(char *algo, struct comp_testvec *ctemplate, |
1023 | struct comp_testvec *dtemplate, int ctcount, int dtcount) | ||
1023 | { | 1024 | { |
1024 | unsigned int i; | 1025 | unsigned int i; |
1025 | char result[COMP_BUF_SIZE]; | 1026 | char result[COMP_BUF_SIZE]; |
@@ -1027,25 +1028,26 @@ static void test_deflate(void) | |||
1027 | struct comp_testvec *tv; | 1028 | struct comp_testvec *tv; |
1028 | unsigned int tsize; | 1029 | unsigned int tsize; |
1029 | 1030 | ||
1030 | printk("\ntesting deflate compression\n"); | 1031 | printk("\ntesting %s compression\n", algo); |
1031 | 1032 | ||
1032 | tsize = sizeof (deflate_comp_tv_template); | 1033 | tsize = sizeof(struct comp_testvec); |
1034 | tsize *= ctcount; | ||
1033 | if (tsize > TVMEMSIZE) { | 1035 | if (tsize > TVMEMSIZE) { |
1034 | printk("template (%u) too big for tvmem (%u)\n", tsize, | 1036 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
1035 | TVMEMSIZE); | 1037 | TVMEMSIZE); |
1036 | return; | 1038 | return; |
1037 | } | 1039 | } |
1038 | 1040 | ||
1039 | memcpy(tvmem, deflate_comp_tv_template, tsize); | 1041 | memcpy(tvmem, ctemplate, tsize); |
1040 | tv = (void *)tvmem; | 1042 | tv = (void *)tvmem; |
1041 | 1043 | ||
1042 | tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC); | 1044 | tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC); |
1043 | if (IS_ERR(tfm)) { | 1045 | if (IS_ERR(tfm)) { |
1044 | printk("failed to load transform for deflate\n"); | 1046 | printk("failed to load transform for %s\n", algo); |
1045 | return; | 1047 | return; |
1046 | } | 1048 | } |
1047 | 1049 | ||
1048 | for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) { | 1050 | for (i = 0; i < ctcount; i++) { |
1049 | int ilen, ret, dlen = COMP_BUF_SIZE; | 1051 | int ilen, ret, dlen = COMP_BUF_SIZE; |
1050 | 1052 | ||
1051 | printk("test %u:\n", i + 1); | 1053 | printk("test %u:\n", i + 1); |
@@ -1064,19 +1066,20 @@ static void test_deflate(void) | |||
1064 | ilen, dlen); | 1066 | ilen, dlen); |
1065 | } | 1067 | } |
1066 | 1068 | ||
1067 | printk("\ntesting deflate decompression\n"); | 1069 | printk("\ntesting %s decompression\n", algo); |
1068 | 1070 | ||
1069 | tsize = sizeof (deflate_decomp_tv_template); | 1071 | tsize = sizeof(struct comp_testvec); |
1072 | tsize *= dtcount; | ||
1070 | if (tsize > TVMEMSIZE) { | 1073 | if (tsize > TVMEMSIZE) { |
1071 | printk("template (%u) too big for tvmem (%u)\n", tsize, | 1074 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
1072 | TVMEMSIZE); | 1075 | TVMEMSIZE); |
1073 | goto out; | 1076 | goto out; |
1074 | } | 1077 | } |
1075 | 1078 | ||
1076 | memcpy(tvmem, deflate_decomp_tv_template, tsize); | 1079 | memcpy(tvmem, dtemplate, tsize); |
1077 | tv = (void *)tvmem; | 1080 | tv = (void *)tvmem; |
1078 | 1081 | ||
1079 | for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) { | 1082 | for (i = 0; i < dtcount; i++) { |
1080 | int ilen, ret, dlen = COMP_BUF_SIZE; | 1083 | int ilen, ret, dlen = COMP_BUF_SIZE; |
1081 | 1084 | ||
1082 | printk("test %u:\n", i + 1); | 1085 | printk("test %u:\n", i + 1); |
@@ -1286,7 +1289,9 @@ static void do_test(void) | |||
1286 | test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS); | 1289 | test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS); |
1287 | test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); | 1290 | test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); |
1288 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); | 1291 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); |
1289 | test_deflate(); | 1292 | test_comp("deflate", deflate_comp_tv_template, |
1293 | deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS, | ||
1294 | DEFLATE_DECOMP_TEST_VECTORS); | ||
1290 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); | 1295 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); |
1291 | test_hash("hmac(md5)", hmac_md5_tv_template, | 1296 | test_hash("hmac(md5)", hmac_md5_tv_template, |
1292 | HMAC_MD5_TEST_VECTORS); | 1297 | HMAC_MD5_TEST_VECTORS); |
@@ -1402,7 +1407,9 @@ static void do_test(void) | |||
1402 | break; | 1407 | break; |
1403 | 1408 | ||
1404 | case 13: | 1409 | case 13: |
1405 | test_deflate(); | 1410 | test_comp("deflate", deflate_comp_tv_template, |
1411 | deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS, | ||
1412 | DEFLATE_DECOMP_TEST_VECTORS); | ||
1406 | break; | 1413 | break; |
1407 | 1414 | ||
1408 | case 14: | 1415 | case 14: |