diff options
| author | Herbert Xu <herbert@gondor.apana.org.au> | 2008-07-31 02:03:44 -0400 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2008-08-29 01:49:52 -0400 |
| commit | bdecd22821a0fab1f5c9e4c9b7fba894593507d4 (patch) | |
| tree | c741a5f39ca2f75c7f4f94a0b592f45bf3ff58ea /crypto | |
| parent | 8cb51ba8e06570a5fff674b3744d12a1b089f2d0 (diff) | |
crypto: tcrypt - Abort and only log if there is an error
The info printed is a complete waste of space when there is no error
since it doesn't tell us anything that we don't already know. If there
is an error, we can also be more verbose.
In case that there is an error, this patch also aborts the test and
returns the error to the caller. In future this will be used to
algorithms at registration time.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
| -rw-r--r-- | crypto/tcrypt.c | 346 |
1 files changed, 200 insertions, 146 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index b6d4b5ce00a3..97ec2bdfcce0 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
| @@ -98,8 +98,8 @@ static void tcrypt_complete(struct crypto_async_request *req, int err) | |||
| 98 | complete(&res->completion); | 98 | complete(&res->completion); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | static void test_hash(char *algo, struct hash_testvec *template, | 101 | static int test_hash(char *algo, struct hash_testvec *template, |
| 102 | unsigned int tcount) | 102 | unsigned int tcount) |
| 103 | { | 103 | { |
| 104 | unsigned int i, j, k, temp; | 104 | unsigned int i, j, k, temp; |
| 105 | struct scatterlist sg[8]; | 105 | struct scatterlist sg[8]; |
| @@ -110,27 +110,26 @@ static void test_hash(char *algo, struct hash_testvec *template, | |||
| 110 | int ret; | 110 | int ret; |
| 111 | void *hash_buff; | 111 | void *hash_buff; |
| 112 | 112 | ||
| 113 | printk("\ntesting %s\n", algo); | ||
| 114 | |||
| 115 | init_completion(&tresult.completion); | 113 | init_completion(&tresult.completion); |
| 116 | 114 | ||
| 117 | tfm = crypto_alloc_ahash(algo, 0, 0); | 115 | tfm = crypto_alloc_ahash(algo, 0, 0); |
| 118 | if (IS_ERR(tfm)) { | 116 | if (IS_ERR(tfm)) { |
| 119 | printk("failed to load transform for %s: %ld\n", algo, | 117 | printk(KERN_ERR "alg: hash: Failed to load transform for %s: " |
| 120 | PTR_ERR(tfm)); | 118 | "%ld\n", algo, PTR_ERR(tfm)); |
| 121 | return; | 119 | return PTR_ERR(tfm); |
| 122 | } | 120 | } |
| 123 | 121 | ||
| 124 | req = ahash_request_alloc(tfm, GFP_KERNEL); | 122 | req = ahash_request_alloc(tfm, GFP_KERNEL); |
| 125 | if (!req) { | 123 | if (!req) { |
| 126 | printk(KERN_ERR "failed to allocate request for %s\n", algo); | 124 | printk(KERN_ERR "alg: hash: Failed to allocate request for " |
| 125 | "%s\n", algo); | ||
| 126 | ret = -ENOMEM; | ||
| 127 | goto out_noreq; | 127 | goto out_noreq; |
| 128 | } | 128 | } |
| 129 | ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, | 129 | ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 130 | tcrypt_complete, &tresult); | 130 | tcrypt_complete, &tresult); |
| 131 | 131 | ||
| 132 | for (i = 0; i < tcount; i++) { | 132 | for (i = 0; i < tcount; i++) { |
| 133 | printk("test %u:\n", i + 1); | ||
| 134 | memset(result, 0, 64); | 133 | memset(result, 0, 64); |
| 135 | 134 | ||
| 136 | hash_buff = xbuf[0]; | 135 | hash_buff = xbuf[0]; |
| @@ -143,7 +142,9 @@ static void test_hash(char *algo, struct hash_testvec *template, | |||
| 143 | ret = crypto_ahash_setkey(tfm, template[i].key, | 142 | ret = crypto_ahash_setkey(tfm, template[i].key, |
| 144 | template[i].ksize); | 143 | template[i].ksize); |
| 145 | if (ret) { | 144 | if (ret) { |
| 146 | printk("setkey() failed ret=%d\n", ret); | 145 | printk(KERN_ERR "alg: hash: setkey failed on " |
| 146 | "test %d for %s: ret=%d\n", i + 1, algo, | ||
| 147 | -ret); | ||
| 147 | goto out; | 148 | goto out; |
| 148 | } | 149 | } |
| 149 | } | 150 | } |
| @@ -163,24 +164,25 @@ static void test_hash(char *algo, struct hash_testvec *template, | |||
| 163 | } | 164 | } |
| 164 | /* fall through */ | 165 | /* fall through */ |
| 165 | default: | 166 | default: |
| 166 | printk("digest () failed ret=%d\n", ret); | 167 | printk(KERN_ERR "alg: hash: digest failed on test %d " |
| 168 | "for %s: ret=%d\n", i + 1, algo, -ret); | ||
| 167 | goto out; | 169 | goto out; |
| 168 | } | 170 | } |
| 169 | 171 | ||
| 170 | hexdump(result, crypto_ahash_digestsize(tfm)); | 172 | if (memcmp(result, template[i].digest, |
| 171 | printk("%s\n", | 173 | crypto_ahash_digestsize(tfm))) { |
| 172 | memcmp(result, template[i].digest, | 174 | printk(KERN_ERR "alg: hash: Test %d failed for %s\n", |
| 173 | crypto_ahash_digestsize(tfm)) ? | 175 | i + 1, algo); |
| 174 | "fail" : "pass"); | 176 | hexdump(result, crypto_ahash_digestsize(tfm)); |
| 177 | ret = -EINVAL; | ||
| 178 | goto out; | ||
| 179 | } | ||
| 175 | } | 180 | } |
| 176 | 181 | ||
| 177 | printk("testing %s across pages\n", algo); | ||
| 178 | |||
| 179 | j = 0; | 182 | j = 0; |
| 180 | for (i = 0; i < tcount; i++) { | 183 | for (i = 0; i < tcount; i++) { |
| 181 | if (template[i].np) { | 184 | if (template[i].np) { |
| 182 | j++; | 185 | j++; |
| 183 | printk("test %u:\n", j); | ||
| 184 | memset(result, 0, 64); | 186 | memset(result, 0, 64); |
| 185 | 187 | ||
| 186 | temp = 0; | 188 | temp = 0; |
| @@ -201,7 +203,10 @@ static void test_hash(char *algo, struct hash_testvec *template, | |||
| 201 | template[i].ksize); | 203 | template[i].ksize); |
| 202 | 204 | ||
| 203 | if (ret) { | 205 | if (ret) { |
| 204 | printk("setkey() failed ret=%d\n", ret); | 206 | printk(KERN_ERR "alg: hash: setkey " |
| 207 | "failed on chunking test %d " | ||
| 208 | "for %s: ret=%d\n", j, algo, | ||
| 209 | -ret); | ||
| 205 | goto out; | 210 | goto out; |
| 206 | } | 211 | } |
| 207 | } | 212 | } |
| @@ -222,28 +227,37 @@ static void test_hash(char *algo, struct hash_testvec *template, | |||
| 222 | } | 227 | } |
| 223 | /* fall through */ | 228 | /* fall through */ |
| 224 | default: | 229 | default: |
| 225 | printk("digest () failed ret=%d\n", ret); | 230 | printk(KERN_ERR "alg: hash: digest failed " |
| 231 | "on chunking test %d for %s: " | ||
| 232 | "ret=%d\n", j, algo, -ret); | ||
| 226 | goto out; | 233 | goto out; |
| 227 | } | 234 | } |
| 228 | 235 | ||
| 229 | hexdump(result, crypto_ahash_digestsize(tfm)); | 236 | if (memcmp(result, template[i].digest, |
| 230 | printk("%s\n", | 237 | crypto_ahash_digestsize(tfm))) { |
| 231 | memcmp(result, template[i].digest, | 238 | printk(KERN_ERR "alg: hash: Chunking test %d " |
| 232 | crypto_ahash_digestsize(tfm)) ? | 239 | "failed for %s\n", j, algo); |
| 233 | "fail" : "pass"); | 240 | hexdump(result, crypto_ahash_digestsize(tfm)); |
| 241 | ret = -EINVAL; | ||
| 242 | goto out; | ||
| 243 | } | ||
| 234 | } | 244 | } |
| 235 | } | 245 | } |
| 236 | 246 | ||
| 247 | ret = 0; | ||
| 248 | |||
| 237 | out: | 249 | out: |
| 238 | ahash_request_free(req); | 250 | ahash_request_free(req); |
| 239 | out_noreq: | 251 | out_noreq: |
| 240 | crypto_free_ahash(tfm); | 252 | crypto_free_ahash(tfm); |
| 253 | return ret; | ||
| 241 | } | 254 | } |
| 242 | 255 | ||
| 243 | static void test_aead(char *algo, int enc, struct aead_testvec *template, | 256 | static int test_aead(char *algo, int enc, struct aead_testvec *template, |
| 244 | unsigned int tcount) | 257 | unsigned int tcount) |
| 245 | { | 258 | { |
| 246 | unsigned int ret, i, j, k, n, temp; | 259 | unsigned int i, j, k, n, temp; |
| 260 | int ret = 0; | ||
| 247 | char *q; | 261 | char *q; |
| 248 | struct crypto_aead *tfm; | 262 | struct crypto_aead *tfm; |
| 249 | char *key; | 263 | char *key; |
| @@ -262,21 +276,21 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template, | |||
| 262 | else | 276 | else |
| 263 | e = "decryption"; | 277 | e = "decryption"; |
| 264 | 278 | ||
| 265 | printk(KERN_INFO "\ntesting %s %s\n", algo, e); | ||
| 266 | |||
| 267 | init_completion(&result.completion); | 279 | init_completion(&result.completion); |
| 268 | 280 | ||
| 269 | tfm = crypto_alloc_aead(algo, 0, 0); | 281 | tfm = crypto_alloc_aead(algo, 0, 0); |
| 270 | 282 | ||
| 271 | if (IS_ERR(tfm)) { | 283 | if (IS_ERR(tfm)) { |
| 272 | printk(KERN_INFO "failed to load transform for %s: %ld\n", | 284 | printk(KERN_ERR "alg: aead: Failed to load transform for %s: " |
| 273 | algo, PTR_ERR(tfm)); | 285 | "%ld\n", algo, PTR_ERR(tfm)); |
| 274 | return; | 286 | return PTR_ERR(tfm); |
| 275 | } | 287 | } |
| 276 | < | ||
