aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2014-12-04 03:43:29 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2014-12-05 10:57:47 -0500
commit8606813a6c8997fd3bb805186056d78670eb86ca (patch)
tree40a3f31e5c71113650b6794d233e9027724343d3 /crypto
parentaf8e80731a94ff9de9508b01d9e5d931d538dc6b (diff)
crypto: tcrypt - Allow speed testing of arbitrary hash functions
This patch allows the testing of arbitrary hash functions specified by the alg module parameter by using them in mode 300 (for sync hash) and mode 400 (for async hash). For example, you could do modprobe tcrypt mode=300 alg='vmac(aes)' Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/tcrypt.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 890449e6e7ef..1d864e988ea9 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -1225,15 +1225,22 @@ static inline int tcrypt_test(const char *alg)
1225 return ret; 1225 return ret;
1226} 1226}
1227 1227
1228static int do_test(int m) 1228static int do_test(const char *alg, u32 type, u32 mask, int m)
1229{ 1229{
1230 int i; 1230 int i;
1231 int ret = 0; 1231 int ret = 0;
1232 1232
1233 switch (m) { 1233 switch (m) {
1234 case 0: 1234 case 0:
1235 if (alg) {
1236 if (!crypto_has_alg(alg, type,
1237 mask ?: CRYPTO_ALG_TYPE_MASK))
1238 ret = -ENOENT;
1239 break;
1240 }
1241
1235 for (i = 1; i < 200; i++) 1242 for (i = 1; i < 200; i++)
1236 ret += do_test(i); 1243 ret += do_test(NULL, 0, 0, i);
1237 break; 1244 break;
1238 1245
1239 case 1: 1246 case 1:
@@ -1752,6 +1759,11 @@ static int do_test(int m)
1752 break; 1759 break;
1753 1760
1754 case 300: 1761 case 300:
1762 if (alg) {
1763 test_hash_speed(alg, sec, generic_hash_speed_template);
1764 break;
1765 }
1766
1755 /* fall through */ 1767 /* fall through */
1756 1768
1757 case 301: 1769 case 301:
@@ -1838,6 +1850,11 @@ static int do_test(int m)
1838 break; 1850 break;
1839 1851
1840 case 400: 1852 case 400:
1853 if (alg) {
1854 test_ahash_speed(alg, sec, generic_hash_speed_template);
1855 break;
1856 }
1857
1841 /* fall through */ 1858 /* fall through */
1842 1859
1843 case 401: 1860 case 401:
@@ -2127,12 +2144,6 @@ static int do_test(int m)
2127 return ret; 2144 return ret;
2128} 2145}
2129 2146
2130static int do_alg_test(const char *alg, u32 type, u32 mask)
2131{
2132 return crypto_has_alg(alg, type, mask ?: CRYPTO_ALG_TYPE_MASK) ?
2133 0 : -ENOENT;
2134}
2135
2136static int __init tcrypt_mod_init(void) 2147static int __init tcrypt_mod_init(void)
2137{ 2148{
2138 int err = -ENOMEM; 2149 int err = -ENOMEM;
@@ -2144,10 +2155,7 @@ static int __init tcrypt_mod_init(void)
2144 goto err_free_tv; 2155 goto err_free_tv;
2145 } 2156 }
2146 2157
2147 if (alg) 2158 err = do_test(alg, type, mask, mode);
2148 err = do_alg_test(alg, type, mask);
2149 else
2150 err = do_test(mode);
2151 2159
2152 if (err) { 2160 if (err) {
2153 printk(KERN_ERR "tcrypt: one or more tests failed!\n"); 2161 printk(KERN_ERR "tcrypt: one or more tests failed!\n");