From 78905baffa23c95020899d18298bdde2edaf6ea3 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Sat, 20 Feb 2010 09:12:51 +0100 Subject: [PATCH] Use only async API since it is a superset of the synchronous one. Cleanup in structures. --- cryptodev_cipher.c | 739 ++++++++++++++++++++++------------------------------- cryptodev_int.h | 39 +-- cryptodev_main.c | 14 +- 3 files changed, 323 insertions(+), 469 deletions(-) rewrite cryptodev_cipher.c (67%) diff --git a/cryptodev_cipher.c b/cryptodev_cipher.c dissimilarity index 67% index 5c54196..622684f 100644 --- a/cryptodev_cipher.c +++ b/cryptodev_cipher.c @@ -1,436 +1,303 @@ -/* - * Driver for /dev/crypto device (aka CryptoDev) - * - * Copyright (c) 2010 Nikos Mavrogiannopoulos - * - * This file is part of linux cryptodev. - * - * cryptodev is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * cryptodev is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "cryptodev.h" -#include "cryptodev_int.h" - - -struct cryptodev_result { - struct completion completion; - int err; -}; - -static void cryptodev_complete(struct crypto_async_request *req, int err) -{ - struct cryptodev_result *res = req->data; - - if (err == -EINPROGRESS) - return; - - res->err = err; - complete(&res->completion); -} - -int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, uint8_t __user * key, size_t keylen) -{ - uint8_t keyp[CRYPTO_CIPHER_MAX_KEY_LEN]; - int ret; - - memset(out, 0, sizeof(*out)); - - if (crypto_has_ablkcipher(alg_name, 0, 0) != 0) { - out->type = 2; - } else { - out->type = 1; - } - - if (unlikely(keylen > CRYPTO_CIPHER_MAX_KEY_LEN)) { - dprintk(1,KERN_DEBUG,"Setting key failed for %s-%zu.\n", - alg_name, keylen*8); - return -EINVAL; - } - /* Copy the key from user and set to TFM. */ - copy_from_user(keyp, key, keylen); - - if (out->type == 1) { - struct blkcipher_alg* alg; - - out->u.blk.s = crypto_alloc_blkcipher(alg_name, 0, CRYPTO_ALG_ASYNC); - if (IS_ERR(out->u.blk.s)) { - dprintk(1,KERN_DEBUG,"%s: Failed to load cipher %s\n", __func__, - alg_name); - return -EINVAL; - } - - alg = crypto_blkcipher_alg(out->u.blk.s); - - if (alg != NULL) { - /* Was correct key length supplied? */ - if ((keylen < alg->min_keysize) || - (keylen > alg->max_keysize)) { - 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; - goto error; - } - } - - ret = crypto_blkcipher_setkey(out->u.blk.s, keyp, keylen); - if (ret) { - dprintk(1,KERN_DEBUG,"Setting key failed for %s-%zu.\n", - alg_name, keylen*8); - ret = -EINVAL; - goto error; - } - - out->blocksize = crypto_blkcipher_blocksize(out->u.blk.s); - out->ivsize = crypto_blkcipher_ivsize(out->u.blk.s); - - out->u.blk.desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP; - out->u.blk.desc.tfm = out->u.blk.s; - - } else { /* async */ - struct ablkcipher_alg* alg; - - out->u.ablk.s = crypto_alloc_ablkcipher(alg_name, 0, 0); - if (IS_ERR(out->u.ablk.s)) { - dprintk(1,KERN_DEBUG,"%s: Failed to load cipher %s\n", __func__, - alg_name); - return -EINVAL; - } - - alg = crypto_ablkcipher_alg(out->u.ablk.s); - - if (alg != NULL) { - /* Was correct key length supplied? */ - if ((keylen < alg->min_keysize) || - (keylen > alg->max_keysize)) { - 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; - goto error; - } - } - - ret = crypto_ablkcipher_setkey(out->u.ablk.s, keyp, keylen); - if (ret) { - dprintk(1,KERN_DEBUG,"Setting key failed for %s-%zu.\n", - alg_name, keylen*8); - ret = -EINVAL; - goto error; - } - - out->blocksize = crypto_ablkcipher_blocksize(out->u.ablk.s); - out->ivsize = crypto_ablkcipher_ivsize(out->u.ablk.s); - - out->u.ablk.async_result = kmalloc(sizeof(*out->u.ablk.async_result), GFP_KERNEL); - if (!out->u.ablk.async_result) { - ret = -ENOMEM; - goto error; - } - - memset(out->u.ablk.async_result, 0, sizeof(*out->u.ablk.async_result)); - init_completion(&out->u.ablk.async_result->completion); - - out->u.ablk.async_request = ablkcipher_request_alloc(out->u.ablk.s, GFP_KERNEL); - if (!out->u.ablk.async_request) { - dprintk(1,KERN_ERR,"error allocating async crypto request\n"); - ret = -ENOMEM; - goto error; - } - - ablkcipher_request_set_callback(out->u.ablk.async_request, CRYPTO_TFM_REQ_MAY_BACKLOG, - cryptodev_complete, out->u.ablk.async_result); - } - - return 0; -error: - if (out->type == 1) - crypto_free_blkcipher(out->u.blk.s); - else { - crypto_free_ablkcipher(out->u.ablk.s); - kfree(out->u.ablk.async_result); - ablkcipher_request_free(out->u.ablk.async_request); - } - - return ret; -} - -void cryptodev_cipher_deinit(struct cipher_data* cdata) -{ - if (cdata->type == 1) - crypto_free_blkcipher(cdata->u.blk.s); - else if (cdata->type == 2) { - crypto_free_ablkcipher(cdata->u.ablk.s); - kfree(cdata->u.ablk.async_result); - ablkcipher_request_free(cdata->u.ablk.async_request); - } - cdata->type = 0; -} - -void cryptodev_cipher_set_iv(struct cipher_data* cdata, void __user* iv, size_t iv_size) -{ - if (cdata->type == 1) { - uint8_t _iv[EALG_MAX_BLOCK_LEN]; - - copy_from_user(_iv, iv, min(iv_size,sizeof(_iv))); - crypto_blkcipher_set_iv(cdata->u.blk.s, _iv, iv_size); - } else { - copy_from_user(cdata->u.ablk.iv, iv, min(iv_size,sizeof(cdata->u.ablk.iv))); - } -} - -static inline int waitfor (struct cryptodev_result* cr, ssize_t ret) -{ - switch (ret) { - case 0: - break; - case -EINPROGRESS: - case -EBUSY: - ret = wait_for_completion_interruptible( - &cr->completion); - /* no error from wait_for_completion */ - if (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; - } - - return 0; -} - -ssize_t cryptodev_cipher_encrypt( struct cipher_data* cdata, struct scatterlist *sg1, struct scatterlist *sg2, size_t len) -{ - if (cdata->type == 1) - return crypto_blkcipher_encrypt(&cdata->u.blk.desc, sg1, sg2, len); - else { - int ret; - - INIT_COMPLETION(cdata->u.ablk.async_result->completion); - ablkcipher_request_set_crypt(cdata->u.ablk.async_request, sg1, sg2, - len, cdata->u.ablk.iv); - ret = crypto_ablkcipher_encrypt(cdata->u.ablk.async_request); - - return waitfor(cdata->u.ablk.async_result,ret); - } -} - -ssize_t cryptodev_cipher_decrypt( struct cipher_data* cdata, struct scatterlist *sg1, struct scatterlist *sg2, size_t len) -{ - if (cdata->type == 1) - return crypto_blkcipher_encrypt(&cdata->u.blk.desc, sg1, sg2, len); - else { - int ret; - - INIT_COMPLETION(cdata->u.ablk.async_result->completion); - ablkcipher_request_set_crypt(cdata->u.ablk.async_request, sg1, sg2, - len, cdata->u.ablk.iv); - ret = crypto_ablkcipher_decrypt(cdata->u.ablk.async_request); - - return waitfor(cdata->u.ablk.async_result, ret); - } -} - -/* Hash functions */ - -static int _crypto_has_ahash(const char* alg_name) -{ -uint32_t type = 0, mask = 0; - type &= ~CRYPTO_ALG_TYPE_MASK; - mask &= ~CRYPTO_ALG_TYPE_MASK; - type |= CRYPTO_ALG_TYPE_AHASH; - mask |= CRYPTO_ALG_TYPE_AHASH_MASK; - - return crypto_has_alg(alg_name, type, mask); -} - -int cryptodev_hash_init( struct hash_data* hdata, const char* alg_name, int hmac_mode, void __user* mackey, size_t mackeylen) -{ -int ret; -uint8_t hkeyp[CRYPTO_HMAC_MAX_KEY_LEN]; - - if (_crypto_has_ahash(alg_name) != 0) { - hdata->type = 2; - } else { - hdata->type = 1; - } - - if (mackeylen > CRYPTO_HMAC_MAX_KEY_LEN) { - dprintk(1,KERN_DEBUG,"Setting hmac key failed for %s-%zu.\n", - alg_name, mackeylen*8); - return -EINVAL; - } - copy_from_user(hkeyp, mackey, mackeylen); - - if (hdata->type == 1) { - hdata->u.sync.s = crypto_alloc_hash(alg_name, 0, CRYPTO_ALG_ASYNC); - if (IS_ERR(hdata->u.sync.s)) { - dprintk(1,KERN_DEBUG,"%s: Failed to load transform for %s\n", __func__, - alg_name); - return -EINVAL; - } - - /* Copy the key from user and set to TFM. */ - if (hmac_mode != 0) { - - ret = crypto_hash_setkey(hdata->u.sync.s, hkeyp, mackeylen); - if (ret) { - dprintk(1,KERN_DEBUG,"Setting hmac key failed for %s-%zu.\n", - alg_name, mackeylen*8); - ret = -EINVAL; - goto error; - } - } - - hdata->u.sync.desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP; - hdata->u.sync.desc.tfm = hdata->u.sync.s; - - hdata->digestsize = crypto_hash_digestsize(hdata->u.sync.s); - - } else { - hdata->u.async.s = crypto_alloc_ahash(alg_name, 0, 0); - if (IS_ERR(hdata->u.async.s)) { - dprintk(1,KERN_DEBUG,"%s: Failed to load transform for %s\n", __func__, - alg_name); - return -EINVAL; - } - - /* Copy the key from user and set to TFM. */ - if (hmac_mode != 0) { - - ret = crypto_ahash_setkey(hdata->u.async.s, hkeyp, mackeylen); - if (ret) { - dprintk(1,KERN_DEBUG,"Setting hmac key failed for %s-%zu.\n", - alg_name, mackeylen*8); - ret = -EINVAL; - goto error; - } - } - - hdata->digestsize = crypto_ahash_digestsize(hdata->u.async.s); - - hdata->u.async.async_result = kmalloc(sizeof(*hdata->u.async.async_result), GFP_KERNEL); - if (!hdata->u.async.async_result) { - ret = -ENOMEM; - goto error; - } - - memset(hdata->u.async.async_result, 0, sizeof(*hdata->u.async.async_result)); - init_completion(&hdata->u.async.async_result->completion); - - hdata->u.async.async_request = ahash_request_alloc(hdata->u.async.s, GFP_KERNEL); - if (!hdata->u.async.async_request) { - dprintk(0,KERN_ERR,"error allocating async crypto request\n"); - ret = -ENOMEM; - goto error; - } - - ahash_request_set_callback(hdata->u.async.async_request, CRYPTO_TFM_REQ_MAY_BACKLOG, - cryptodev_complete, hdata->u.async.async_result); - - - } - - return 0; - -error: - if (hdata->type == 1) - crypto_free_hash(hdata->u.sync.s); - else - crypto_free_ahash(hdata->u.async.s); - return ret; -} - -void cryptodev_hash_deinit(struct hash_data* hdata) -{ - if (hdata->type == 1) - crypto_free_hash(hdata->u.sync.s); - else if (hdata->type == 2) - crypto_free_ahash(hdata->u.async.s); - hdata->type = 0; -} - -int cryptodev_hash_reset( struct hash_data* hdata) -{ -int ret; - if (hdata->type == 1) { - ret = crypto_hash_init(&hdata->u.sync.desc); - if (unlikely(ret)) { - 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)) { - dprintk(0,KERN_ERR, - "error in crypto_hash_init()\n"); - return ret; - } - } - - return 0; - -} - -ssize_t cryptodev_hash_update( struct hash_data* hdata, struct scatterlist *sg, size_t len) -{ - if (hdata->type == 1) - return crypto_hash_update(&hdata->u.sync.desc, sg, len); - else { - int ret; - - INIT_COMPLETION(hdata->u.async.async_result->completion); - ahash_request_set_crypt(hdata->u.async.async_request, sg, NULL, - len); - - ret = crypto_ahash_update(hdata->u.async.async_request); - - return waitfor(hdata->u.async.async_result,ret); - } -} - - -int cryptodev_hash_final( struct hash_data* hdata, void* output) -{ - if (hdata->type == 1) - return crypto_hash_final(&hdata->u.sync.desc, output); - else { - int ret; - - INIT_COMPLETION(hdata->u.async.async_result->completion); - ahash_request_set_crypt(hdata->u.async.async_request, NULL, output, 0); - - ret = crypto_ahash_final(hdata->u.async.async_request); - - return waitfor(hdata->u.async.async_result,ret); - } -} +/* + * Driver for /dev/crypto device (aka CryptoDev) + * + * Copyright (c) 2010 Nikos Mavrogiannopoulos + * + * This file is part of linux cryptodev. + * + * cryptodev is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * cryptodev is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "cryptodev.h" +#include "cryptodev_int.h" + + +struct cryptodev_result { + struct completion completion; + int err; +}; + +static void cryptodev_complete(struct crypto_async_request *req, int err) +{ + struct cryptodev_result *res = req->data; + + if (err == -EINPROGRESS) + return; + + res->err = err; + complete(&res->completion); +} + +int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, uint8_t __user * key, size_t keylen) +{ + uint8_t keyp[CRYPTO_CIPHER_MAX_KEY_LEN]; + struct ablkcipher_alg* alg; + int ret; + + memset(out, 0, sizeof(*out)); + + out->init = 1; + + if (unlikely(keylen > CRYPTO_CIPHER_MAX_KEY_LEN)) { + dprintk(1,KERN_DEBUG,"Setting key failed for %s-%zu.\n", + alg_name, keylen*8); + return -EINVAL; + } + /* Copy the key from user and set to TFM. */ + copy_from_user(keyp, key, keylen); + + out->async.s = crypto_alloc_ablkcipher(alg_name, 0, 0); + if (IS_ERR(out->async.s)) { + dprintk(1,KERN_DEBUG,"%s: Failed to load cipher %s\n", __func__, + alg_name); + return -EINVAL; + } + + alg = crypto_ablkcipher_alg(out->async.s); + + if (alg != NULL) { + /* Was correct key length supplied? */ + if ((keylen < alg->min_keysize) || + (keylen > alg->max_keysize)) { + 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; + goto error; + } + } + + ret = crypto_ablkcipher_setkey(out->async.s, keyp, keylen); + if (ret) { + dprintk(1,KERN_DEBUG,"Setting key failed for %s-%zu.\n", + alg_name, keylen*8); + ret = -EINVAL; + goto error; + } + + out->blocksize = crypto_ablkcipher_blocksize(out->async.s); + out->ivsize = crypto_ablkcipher_ivsize(out->async.s); + + out->async.result = kmalloc(sizeof(*out->async.result), GFP_KERNEL); + if (!out->async.result) { + ret = -ENOMEM; + goto error; + } + + memset(out->async.result, 0, sizeof(*out->async.result)); + init_completion(&out->async.result->completion); + + out->async.request = ablkcipher_request_alloc(out->async.s, GFP_KERNEL); + if (!out->async.request) { + dprintk(1,KERN_ERR,"error allocating async crypto request\n"); + ret = -ENOMEM; + goto error; + } + + ablkcipher_request_set_callback(out->async.request, CRYPTO_TFM_REQ_MAY_BACKLOG, + cryptodev_complete, out->async.result); + + return 0; +error: + crypto_free_ablkcipher(out->async.s); + kfree(out->async.result); + ablkcipher_request_free(out->async.request); + + return ret; +} + +void cryptodev_cipher_deinit(struct cipher_data* cdata) +{ + crypto_free_ablkcipher(cdata->async.s); + kfree(cdata->async.result); + ablkcipher_request_free(cdata->async.request); + + cdata->init = 0; +} + +void cryptodev_cipher_set_iv(struct cipher_data* cdata, void __user* iv, size_t iv_size) +{ + copy_from_user(cdata->async.iv, iv, min(iv_size,sizeof(cdata->async.iv))); +} + +static inline int waitfor (struct cryptodev_result* cr, ssize_t ret) +{ + switch (ret) { + case 0: + break; + case -EINPROGRESS: + case -EBUSY: + ret = wait_for_completion_interruptible( + &cr->completion); + /* no error from wait_for_completion */ + if (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; + } + + return 0; +} + +ssize_t cryptodev_cipher_encrypt( struct cipher_data* cdata, struct scatterlist *sg1, struct scatterlist *sg2, size_t len) +{ + int ret; + + INIT_COMPLETION(cdata->async.result->completion); + ablkcipher_request_set_crypt(cdata->async.request, sg1, sg2, + len, cdata->async.iv); + ret = crypto_ablkcipher_encrypt(cdata->async.request); + + return waitfor(cdata->async.result,ret); +} + +ssize_t cryptodev_cipher_decrypt( struct cipher_data* cdata, struct scatterlist *sg1, struct scatterlist *sg2, size_t len) +{ + int ret; + + INIT_COMPLETION(cdata->async.result->completion); + ablkcipher_request_set_crypt(cdata->async.request, sg1, sg2, + len, cdata->async.iv); + ret = crypto_ablkcipher_decrypt(cdata->async.request); + + return waitfor(cdata->async.result, ret); +} + +/* Hash functions */ + +int cryptodev_hash_init( struct hash_data* hdata, const char* alg_name, int hmac_mode, void __user* mackey, size_t mackeylen) +{ +int ret; +uint8_t hkeyp[CRYPTO_HMAC_MAX_KEY_LEN]; + + hdata->init = 1; + + if (mackeylen > CRYPTO_HMAC_MAX_KEY_LEN) { + dprintk(1,KERN_DEBUG,"Setting hmac key failed for %s-%zu.\n", + alg_name, mackeylen*8); + return -EINVAL; + } + copy_from_user(hkeyp, mackey, mackeylen); + + hdata->async.s = crypto_alloc_ahash(alg_name, 0, 0); + if (IS_ERR(hdata->async.s)) { + dprintk(1,KERN_DEBUG,"%s: Failed to load transform for %s\n", __func__, + alg_name); + return -EINVAL; + } + + /* Copy the key from user and set to TFM. */ + if (hmac_mode != 0) { + + ret = crypto_ahash_setkey(hdata->async.s, hkeyp, mackeylen); + if (ret) { + dprintk(1,KERN_DEBUG,"Setting hmac key failed for %s-%zu.\n", + alg_name, mackeylen*8); + ret = -EINVAL; + goto error; + } + } + + hdata->digestsize = crypto_ahash_digestsize(hdata->async.s); + + hdata->async.result = kmalloc(sizeof(*hdata->async.result), GFP_KERNEL); + if (!hdata->async.result) { + ret = -ENOMEM; + goto error; + } + + memset(hdata->async.result, 0, sizeof(*hdata->async.result)); + init_completion(&hdata->async.result->completion); + + hdata->async.request = ahash_request_alloc(hdata->async.s, GFP_KERNEL); + if (!hdata->async.request) { + dprintk(0,KERN_ERR,"error allocating async crypto request\n"); + ret = -ENOMEM; + goto error; + } + + ahash_request_set_callback(hdata->async.request, CRYPTO_TFM_REQ_MAY_BACKLOG, + cryptodev_complete, hdata->async.result); + + + return 0; + +error: + crypto_free_ahash(hdata->async.s); + return ret; +} + +void cryptodev_hash_deinit(struct hash_data* hdata) +{ + crypto_free_ahash(hdata->async.s); + hdata->init = 0; +} + +int cryptodev_hash_reset( struct hash_data* hdata) +{ +int ret; + ret = crypto_ahash_init(hdata->async.request); + if (unlikely(ret)) { + dprintk(0,KERN_ERR, + "error in crypto_hash_init()\n"); + return ret; + } + + return 0; + +} + +ssize_t cryptodev_hash_update( struct hash_data* hdata, struct scatterlist *sg, size_t len) +{ + int ret; + + INIT_COMPLETION(hdata->async.result->completion); + ahash_request_set_crypt(hdata->async.request, sg, NULL, + len); + + ret = crypto_ahash_update(hdata->async.request); + + return waitfor(hdata->async.result,ret); +} + + +int cryptodev_hash_final( struct hash_data* hdata, void* output) +{ + int ret; + + INIT_COMPLETION(hdata->async.result->completion); + ahash_request_set_crypt(hdata->async.request, NULL, output, 0); + + ret = crypto_ahash_final(hdata->async.request); + + return waitfor(hdata->async.result,ret); +} diff --git a/cryptodev_int.h b/cryptodev_int.h index e82a761..19cd6a3 100644 --- a/cryptodev_int.h +++ b/cryptodev_int.h @@ -25,21 +25,15 @@ extern int cryptodev_verbosity; struct cipher_data { - int type; /* 1 synchronous, 2 async, 0 uninitialized */ + int init; /* 0 uninitialized */ int blocksize; int ivsize; - union { - struct { - struct crypto_blkcipher* s; - struct blkcipher_desc desc; - } blk; - struct { - struct crypto_ablkcipher* s; - struct cryptodev_result *async_result; - struct ablkcipher_request *async_request; - uint8_t iv[EALG_MAX_BLOCK_LEN]; - } ablk; - } u; + struct { + struct crypto_ablkcipher* s; + struct cryptodev_result *result; + struct ablkcipher_request *request; + uint8_t iv[EALG_MAX_BLOCK_LEN]; + } async; }; int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, __user uint8_t * key, size_t keylen); @@ -51,20 +45,13 @@ void cryptodev_cipher_set_iv(struct cipher_data* cdata, void* iv, size_t iv_size /* hash stuff */ struct hash_data { - int type; /* 1 synchronous, 2 async, 0 uninitialized */ + int init; /* 0 uninitialized */ int digestsize; - union { - struct { - struct crypto_hash* s; - struct hash_desc desc; - } sync; - struct { - struct crypto_ahash *s; - struct cryptodev_result *async_result; - struct ahash_request *async_request; - } async; - } u; - + struct { + struct crypto_ahash *s; + struct cryptodev_result *result; + struct ahash_request *request; + } async; }; int cryptodev_hash_final( struct hash_data* hdata, void* output); diff --git a/cryptodev_main.c b/cryptodev_main.c index 0162486..1d6b614 100644 --- a/cryptodev_main.c +++ b/cryptodev_main.c @@ -369,7 +369,7 @@ crypto_run(struct fcrypt *fcr, struct crypt_op *cop) nbytes = cop->len; - if (ses_ptr->hdata.type != 0) { + if (ses_ptr->hdata.init != 0) { ret = cryptodev_hash_reset(&ses_ptr->hdata); if (unlikely(ret)) { dprintk(1, KERN_ERR, @@ -378,7 +378,7 @@ crypto_run(struct fcrypt *fcr, struct crypt_op *cop) } } - if (ses_ptr->cdata.type != 0) { + if (ses_ptr->cdata.init != 0) { int blocksize = ses_ptr->cdata.blocksize; if (unlikely(nbytes % blocksize)) { @@ -411,14 +411,14 @@ crypto_run(struct fcrypt *fcr, struct crypt_op *cop) * we should introduce a flag to switch... TBD later on. */ if (cop->op == COP_ENCRYPT) { - if (ses_ptr->hdata.type != 0) { + if (ses_ptr->hdata.init != 0) { ret = cryptodev_hash_update(&ses_ptr->hdata, &sg, current_len); if (unlikely(ret)) { dprintk(0, KERN_ERR, "CryptoAPI failure: %d\n",ret); goto out; } } - if (ses_ptr->cdata.type != 0) { + if (ses_ptr->cdata.init != 0) { ret = cryptodev_cipher_encrypt( &ses_ptr->cdata, &sg, &sg, current_len); if (unlikely(ret)) { @@ -429,7 +429,7 @@ crypto_run(struct fcrypt *fcr, struct crypt_op *cop) dst += current_len; } } else { - if (ses_ptr->cdata.type != 0) { + if (ses_ptr->cdata.init != 0) { ret = cryptodev_cipher_decrypt( &ses_ptr->cdata, &sg, &sg, current_len); if (unlikely(ret)) { @@ -441,7 +441,7 @@ crypto_run(struct fcrypt *fcr, struct crypt_op *cop) } - if (ses_ptr->hdata.type != 0) { + if (ses_ptr->hdata.init != 0) { ret = cryptodev_hash_update(&ses_ptr->hdata, &sg, current_len); if (unlikely(ret)) { dprintk(0, KERN_ERR, "CryptoAPI failure: %d\n",ret); @@ -454,7 +454,7 @@ crypto_run(struct fcrypt *fcr, struct crypt_op *cop) src += current_len; } - if (ses_ptr->hdata.type != 0) { + if (ses_ptr->hdata.init != 0) { ret = cryptodev_hash_final(&ses_ptr->hdata, hash_output); if (unlikely(ret)) { dprintk(0, KERN_ERR, "CryptoAPI failure: %d\n",ret); -- 2.11.4.GIT