summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cryptodev_cipher.c40
-rw-r--r--cryptodev_int.h24
-rw-r--r--cryptodev_main.c25
3 files changed, 50 insertions, 39 deletions
diff --git a/cryptodev_cipher.c b/cryptodev_cipher.c
index 9cc42ac..af7571d 100644
--- a/cryptodev_cipher.c
+++ b/cryptodev_cipher.c
@@ -62,7 +62,7 @@ int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, __user
}
if (unlikely(keylen > CRYPTO_CIPHER_MAX_KEY_LEN)) {
- printk(KERN_DEBUG"Setting key failed for %s-%zu.\n",
+ dprintk(1,KERN_DEBUG,"Setting key failed for %s-%zu.\n",
alg_name, keylen*8);
return -EINVAL;
}
@@ -74,7 +74,7 @@ int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, __user
out->u.blk.s = crypto_alloc_blkcipher(alg_name, 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(out->u.blk.s)) {
- printk(KERN_DEBUG"%s: Failed to load cipher %s\n", __func__,
+ dprintk(1,KERN_DEBUG,"%s: Failed to load cipher %s\n", __func__,
alg_name);
return -EINVAL;
}
@@ -85,7 +85,7 @@ int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, __user
/* Was correct key length supplied? */
if ((keylen < alg->min_keysize) ||
(keylen > alg->max_keysize)) {
- printk(KERN_DEBUG"Wrong keylen '%zu' for algorithm '%s'. Use %u to %u.\n",
+ dprintk(1,KERN_DEBUG,"Wrong keylen '%zu' for algorithm '%s'. Use %u to %u.\n",
keylen, alg_name, alg->min_keysize,
alg->max_keysize);
ret = -EINVAL;
@@ -95,7 +95,7 @@ int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, __user
ret = crypto_blkcipher_setkey(out->u.blk.s, keyp, keylen);
if (ret) {
- printk(KERN_DEBUG"Setting key failed for %s-%zu.\n",
+ dprintk(1,KERN_DEBUG,"Setting key failed for %s-%zu.\n",
alg_name, keylen*8);
ret = -EINVAL;
goto error;
@@ -112,7 +112,7 @@ int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, __user
out->u.ablk.s = crypto_alloc_ablkcipher(alg_name, 0, 0);
if (IS_ERR(out->u.ablk.s)) {
- printk(KERN_DEBUG"%s: Failed to load cipher %s\n", __func__,
+ dprintk(1,KERN_DEBUG,"%s: Failed to load cipher %s\n", __func__,
alg_name);
return -EINVAL;
}
@@ -123,7 +123,7 @@ int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, __user
/* Was correct key length supplied? */
if ((keylen < alg->min_keysize) ||
(keylen > alg->max_keysize)) {
- printk(KERN_DEBUG"Wrong keylen '%zu' for algorithm '%s'. Use %u to %u.\n",
+ dprintk(1,KERN_DEBUG,"Wrong keylen '%zu' for algorithm '%s'. Use %u to %u.\n",
keylen, alg_name, alg->min_keysize,
alg->max_keysize);
ret = -EINVAL;
@@ -133,7 +133,7 @@ int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, __user
ret = crypto_ablkcipher_setkey(out->u.ablk.s, keyp, keylen);
if (ret) {
- printk(KERN_DEBUG"Setting key failed for %s-%zu.\n",
+ dprintk(1,KERN_DEBUG,"Setting key failed for %s-%zu.\n",
alg_name, keylen*8);
ret = -EINVAL;
goto error;
@@ -153,7 +153,7 @@ int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, __user
out->u.ablk.async_request = ablkcipher_request_alloc(out->u.ablk.s, GFP_KERNEL);
if (!out->u.ablk.async_request) {
- printk(KERN_ERR"error allocating async crypto request\n");
+ dprintk(1,KERN_ERR,"error allocating async crypto request\n");
ret = -ENOMEM;
goto error;
}
@@ -210,9 +210,15 @@ static inline int waitfor (struct cryptodev_result* cr, ssize_t ret)
&cr->completion);
/* no error from wait_for_completion */
if (ret) {
- printk(KERN_ERR"error waiting for async request completion: %zd\n", ret);
+ dprintk(0,KERN_ERR,"error waiting for async request completion: %zd\n", ret);
return ret;
}
+
+ if (cr->err) {
+ dprintk(0,KERN_ERR,"error from async request: %zd \n", ret);
+ return cr->err;
+ }
+
break;
default:
return ret;
@@ -278,7 +284,7 @@ uint8_t hkeyp[CRYPTO_HMAC_MAX_KEY_LEN];
}
if (mackeylen > CRYPTO_HMAC_MAX_KEY_LEN) {
- printk(KERN_DEBUG"Setting hmac key failed for %s-%zu.\n",
+ dprintk(1,KERN_DEBUG,"Setting hmac key failed for %s-%zu.\n",
alg_name, mackeylen*8);
return -EINVAL;
}
@@ -287,7 +293,7 @@ uint8_t hkeyp[CRYPTO_HMAC_MAX_KEY_LEN];
if (hdata->type == 1) {
hdata->u.sync.s = crypto_alloc_hash(alg_name, 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(hdata->u.sync.s)) {
- printk(KERN_DEBUG"%s: Failed to load transform for %s\n", __func__,
+ dprintk(1,KERN_DEBUG,"%s: Failed to load transform for %s\n", __func__,
alg_name);
return -EINVAL;
}
@@ -297,7 +303,7 @@ uint8_t hkeyp[CRYPTO_HMAC_MAX_KEY_LEN];
ret = crypto_hash_setkey(hdata->u.sync.s, hkeyp, mackeylen);
if (ret) {
- printk(KERN_DEBUG"Setting hmac key failed for %s-%zu.\n",
+ dprintk(1,KERN_DEBUG,"Setting hmac key failed for %s-%zu.\n",
alg_name, mackeylen*8);
ret = -EINVAL;
goto error;
@@ -312,7 +318,7 @@ uint8_t hkeyp[CRYPTO_HMAC_MAX_KEY_LEN];
} else {
hdata->u.async.s = crypto_alloc_ahash(alg_name, 0, 0);
if (IS_ERR(hdata->u.async.s)) {
- printk(KERN_DEBUG"%s: Failed to load transform for %s\n", __func__,
+ dprintk(1,KERN_DEBUG,"%s: Failed to load transform for %s\n", __func__,
alg_name);
return -EINVAL;
}
@@ -322,7 +328,7 @@ uint8_t hkeyp[CRYPTO_HMAC_MAX_KEY_LEN];
ret = crypto_ahash_setkey(hdata->u.async.s, hkeyp, mackeylen);
if (ret) {
- printk(KERN_DEBUG"Setting hmac key failed for %s-%zu.\n",
+ dprintk(1,KERN_DEBUG,"Setting hmac key failed for %s-%zu.\n",
alg_name, mackeylen*8);
ret = -EINVAL;
goto error;
@@ -342,7 +348,7 @@ uint8_t hkeyp[CRYPTO_HMAC_MAX_KEY_LEN];
hdata->u.async.async_request = ahash_request_alloc(hdata->u.async.s, GFP_KERNEL);
if (!hdata->u.async.async_request) {
- printk(KERN_ERR"error allocating async crypto request\n");
+ dprintk(0,KERN_ERR,"error allocating async crypto request\n");
ret = -ENOMEM;
goto error;
}
@@ -378,14 +384,14 @@ int ret;
if (hdata->type == 1) {
ret = crypto_hash_init(&hdata->u.sync.desc);
if (unlikely(ret)) {
- printk(KERN_ERR
+ dprintk(0,KERN_ERR,
"error in crypto_hash_init()\n");
return ret;
}
} else {
ret = crypto_ahash_init(hdata->u.async.async_request);
if (unlikely(ret)) {
- printk(KERN_ERR
+ dprintk(0,KERN_ERR,
"error in crypto_hash_init()\n");
return ret;
}
diff --git a/cryptodev_int.h b/cryptodev_int.h
index 3aab19c..e82a761 100644
--- a/cryptodev_int.h
+++ b/cryptodev_int.h
@@ -1,5 +1,28 @@
/* cipher stuff */
+#ifndef CRYPTODEV_INT_H
+# define CRYPTODEV_INT_H
+
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/fs.h>
+#include <linux/file.h>
+#include <linux/fdtable.h>
+#include <linux/miscdevice.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+
+#define PFX "cryptodev: "
+#define dprintk(level,severity,format,a...) \
+ do { \
+ if (level <= cryptodev_verbosity) \
+ printk(severity PFX "%s[%u]: " format, \
+ current->comm, current->pid, \
+ ##a); \
+ } while (0)
+
+extern int cryptodev_verbosity;
+
struct cipher_data
{
int type; /* 1 synchronous, 2 async, 0 uninitialized */
@@ -50,3 +73,4 @@ int cryptodev_hash_reset( struct hash_data* hdata);
void cryptodev_hash_deinit(struct hash_data* hdata);
int cryptodev_hash_init( struct hash_data* hdata, const char* alg_name, int hmac_mode, __user void* mackey, size_t mackeylen);
+#endif /* CRYPTODEV_INT_H */
diff --git a/cryptodev_main.c b/cryptodev_main.c
index bdf7017..0162486 100644
--- a/cryptodev_main.c
+++ b/cryptodev_main.c
@@ -31,14 +31,6 @@
*
*/
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/init.h>
-#include <linux/sched.h>
-#include <linux/fs.h>
-#include <linux/file.h>
-#include <linux/fdtable.h>
-#include <linux/miscdevice.h>
#include <linux/crypto.h>
#include <linux/mm.h>
#include <linux/highmem.h>
@@ -59,9 +51,9 @@ MODULE_LICENSE("GPL");
/* ====== Module parameters ====== */
-static int verbosity = 0;
-module_param(verbosity, int, 0644);
-MODULE_PARM_DESC(verbosity, "0: normal, 1: verbose, 2: debug");
+int cryptodev_verbosity = 0;
+module_param(cryptodev_verbosity, int, 0644);
+MODULE_PARM_DESC(cryptodev_verbosity, "0: normal, 1: verbose, 2: debug");
#ifdef CRYPTODEV_STATS
static int enable_stats = 0;
@@ -69,17 +61,6 @@ module_param(enable_stats, int, 0644);
MODULE_PARM_DESC(enable_stats, "collect statictics about cryptodev usage");
#endif
-/* ====== Debug helpers ====== */
-
-#define PFX "cryptodev: "
-#define dprintk(level,severity,format,a...) \
- do { \
- if (level <= verbosity) \
- printk(severity PFX "%s[%u]: " format, \
- current->comm, current->pid, \
- ##a); \
- } while (0)
-
/* ====== CryptoAPI ====== */
#define FILL_SG(sg,ptr,len) \