From e333542da8e7ebde5019c453e116766c884d6c80 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Fri, 23 Mar 2012 19:30:53 +0100 Subject: [PATCH] updated --- extras/eng_cryptodev.c | 60 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/extras/eng_cryptodev.c b/extras/eng_cryptodev.c index fd90008..e3265bb 100644 --- a/extras/eng_cryptodev.c +++ b/extras/eng_cryptodev.c @@ -702,6 +702,8 @@ static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data, size_t count) { struct dev_crypto_state *state = ctx->md_data; + struct crypt_op cryp; + struct session_op *sess = &state->d_sess; if (!data || state->d_fd < 0) { printf("cryptodev_digest_update: illegal inputs \n"); @@ -712,16 +714,33 @@ static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data, return (1); } - state->mac_data = OPENSSL_realloc(state->mac_data, state->mac_len + count); + if (!(ctx->flags & EVP_MD_CTX_FLAG_ONESHOT)) { + /* if application doesn't support one buffer */ + state->mac_data = OPENSSL_realloc(state->mac_data, state->mac_len + count); - if (!state->mac_data) { - printf("cryptodev_digest_update: realloc failed\n"); - return (0); - } + if (!state->mac_data) { + printf("cryptodev_digest_update: realloc failed\n"); + return (0); + } - memcpy(state->mac_data + state->mac_len, data, count); - state->mac_len += count; + memcpy(state->mac_data + state->mac_len, data, count); + state->mac_len += count; + return (1); + } + + memset(&cryp, 0, sizeof(cryp)); + + cryp.ses = sess->ses; + cryp.flags = 0; + cryp.len = count; + cryp.src = (void*) data; + cryp.dst = NULL; + cryp.mac = (void*) state->digest_res; + if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) { + printf("cryptodev_digest_update: digest failed\n"); + return (0); + } return (1); } @@ -737,21 +756,26 @@ static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md) return(0); } - memset(&cryp, 0, sizeof(cryp)); - cryp.ses = sess->ses; - cryp.flags = 0; - cryp.len = state->mac_len; - cryp.src = (void*)state->mac_data; - cryp.dst = NULL; - cryp.mac = (void*)state->digest_res; - if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) { - printf("cryptodev_digest_final: digest failed\n"); - return (0); + if (! (ctx->flags & EVP_MD_CTX_FLAG_ONESHOT) ) { + /* if application doesn't support one buffer */ + memset(&cryp, 0, sizeof(cryp)); + cryp.ses = sess->ses; + cryp.flags = 0; + cryp.len = state->mac_len; + cryp.src = state->mac_data; + cryp.dst = NULL; + cryp.mac = (void*)md; + if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) { + printf("cryptodev_digest_final: digest failed\n"); + return (0); + } + + return 1; } memcpy(md, state->digest_res, ctx->digest->md_size); - return (1); + return 1; } -- 2.11.4.GIT