From cdcb458991053a9a972ddf2f9e2cd3fca3c96dd6 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Wed, 7 Mar 2012 23:34:50 +0100 Subject: [PATCH] when using cryptodev do not set all the digest function since they are not always faster. --- lib/accelerated/cryptodev.c | 149 ++++---------------------------------------- 1 file changed, 11 insertions(+), 138 deletions(-) diff --git a/lib/accelerated/cryptodev.c b/lib/accelerated/cryptodev.c index 5117f7962..7d1eacc2f 100644 --- a/lib/accelerated/cryptodev.c +++ b/lib/accelerated/cryptodev.c @@ -312,98 +312,6 @@ static const int gnutls_mac_map[] = { }; static int -cryptodev_mac_init (gnutls_mac_algorithm_t algorithm, void **_ctx) -{ - struct cryptodev_ctx *ctx; - int mac = gnutls_mac_map[algorithm]; - - *_ctx = gnutls_calloc (1, sizeof (struct cryptodev_ctx)); - if (*_ctx == NULL) - { - gnutls_assert (); - return GNUTLS_E_MEMORY_ERROR; - } - - ctx = *_ctx; - - ctx->cfd = _gnutls_cryptodev_fd; - - ctx->sess.mac = mac; - - return 0; -} - -static int -cryptodev_mac_setkey (void *_ctx, const void *key, size_t keysize) -{ - struct cryptodev_ctx *ctx = _ctx; - - ctx->sess.mackeylen = keysize; - ctx->sess.mackey = (void*)key; - - if (ioctl (ctx->cfd, CIOCGSESSION, &ctx->sess)) - { - gnutls_assert (); - return GNUTLS_E_CRYPTODEV_IOCTL_ERROR; - } - ctx->cryp.ses = ctx->sess.ses; - - return 0; -} - -static int -cryptodev_mac_hash (void *_ctx, const void *text, size_t textsize) -{ - struct cryptodev_ctx *ctx = _ctx; - - ctx->cryp.len = textsize; - ctx->cryp.src = (void *) text; - ctx->cryp.dst = NULL; - ctx->cryp.op = COP_ENCRYPT; - ctx->cryp.flags = COP_FLAG_UPDATE; - if (ctx->reset) - { - ctx->cryp.flags |= COP_FLAG_RESET; - ctx->reset = 0; - } - - if (ioctl (ctx->cfd, CIOCCRYPT, &ctx->cryp)) - { - gnutls_assert (); - return GNUTLS_E_CRYPTODEV_IOCTL_ERROR; - } - return 0; -} - -static int -cryptodev_mac_output (void *_ctx, void *digest, size_t digestsize) -{ - struct cryptodev_ctx *ctx = _ctx; - - ctx->cryp.len = 0; - ctx->cryp.src = NULL; - ctx->cryp.mac = digest; - ctx->cryp.op = COP_ENCRYPT; - ctx->cryp.flags = COP_FLAG_FINAL; - - if (ioctl (ctx->cfd, CIOCCRYPT, &ctx->cryp)) - { - gnutls_assert (); - return GNUTLS_E_CRYPTODEV_IOCTL_ERROR; - } - - return 0; -} - -static void -cryptodev_mac_reset (void *_ctx) -{ - struct cryptodev_ctx *ctx = _ctx; - - ctx->reset = 1; -} - -static int cryptodev_mac_fast (gnutls_mac_algorithm_t algo, const void *key, size_t key_size, const void *text, size_t text_size, void *digest) @@ -441,12 +349,12 @@ int ret; #define cryptodev_mac_deinit cryptodev_deinit static const gnutls_crypto_mac_st mac_struct = { - .init = cryptodev_mac_init, - .setkey = cryptodev_mac_setkey, - .hash = cryptodev_mac_hash, - .output = cryptodev_mac_output, - .deinit = cryptodev_mac_deinit, - .reset = cryptodev_mac_reset, + .init = NULL, + .setkey = NULL, + .hash = NULL, + .output = NULL, + .deinit = NULL, + .reset = NULL, .fast = cryptodev_mac_fast }; @@ -461,39 +369,6 @@ static const int gnutls_digest_map[] = { }; static int -cryptodev_digest_init (gnutls_digest_algorithm_t algorithm, void **_ctx) -{ - struct cryptodev_ctx *ctx; - int dig = gnutls_digest_map[algorithm]; - - *_ctx = gnutls_calloc (1, sizeof (struct cryptodev_ctx)); - if (*_ctx == NULL) - { - gnutls_assert (); - return GNUTLS_E_MEMORY_ERROR; - } - - ctx = *_ctx; - - ctx->cfd = _gnutls_cryptodev_fd; - ctx->sess.mac = dig; - - if (ioctl (ctx->cfd, CIOCGSESSION, &ctx->sess)) - { - gnutls_assert (); - gnutls_free(ctx); - return GNUTLS_E_CRYPTODEV_IOCTL_ERROR; - } - ctx->cryp.ses = ctx->sess.ses; - - return 0; -} - -#define cryptodev_digest_hash cryptodev_mac_hash -#define cryptodev_digest_output cryptodev_mac_output -#define cryptodev_digest_reset cryptodev_mac_reset - -static int cryptodev_digest_fast (gnutls_digest_algorithm_t algo, const void *text, size_t text_size, void *digest) @@ -525,14 +400,12 @@ int ret; return 0; } -#define cryptodev_digest_deinit cryptodev_deinit - static const gnutls_crypto_digest_st digest_struct = { - .init = cryptodev_digest_init, - .hash = cryptodev_digest_hash, - .output = cryptodev_digest_output, - .deinit = cryptodev_digest_deinit, - .reset = cryptodev_digest_reset, + .init = NULL, + .hash = NULL, + .output = NULL, + .deinit = NULL, + .reset = NULL, .fast = cryptodev_digest_fast }; -- 2.11.4.GIT