1 From 2187b18ffe4851efcb6465ca02ac036d2fe031b8 Mon Sep 17 00:00:00 2001
2 From: Cristian Stoica <cristian.stoica@nxp.com>
3 Date: Tue, 15 Dec 2015 12:23:13 +0200
4 Subject: [PATCH 27/48] cryptodev: put all digest ioctls into a single function
6 Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
8 crypto/engine/eng_cryptodev.c | 44 +++++++++++++++++++------------------------
9 1 file changed, 19 insertions(+), 25 deletions(-)
11 diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c
12 index 048e050..76faa35 100644
13 --- a/crypto/engine/eng_cryptodev.c
14 +++ b/crypto/engine/eng_cryptodev.c
15 @@ -1577,13 +1577,6 @@ static int cryptodev_digest_init(EVP_MD_CTX *ctx)
16 sess->mackeylen = digest_key_length(ctx->digest->type);
19 - if (ioctl(state->d_fd, CIOCGSESSION, sess) < 0) {
20 - put_dev_crypto(state->d_fd);
22 - printf("cryptodev_digest_init: Open session failed\n");
29 @@ -1623,6 +1616,7 @@ static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data,
31 static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md)
35 struct dev_crypto_state *state = ctx->md_data;
36 struct session_op *sess = &state->d_sess;
37 @@ -1632,6 +1626,11 @@ static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md)
41 + if (ioctl(state->d_fd, CIOCGSESSION, sess) < 0) {
42 + printf("cryptodev_digest_init: Open session failed\n");
46 memset(&cryp, 0, sizeof(cryp));
49 @@ -1642,43 +1641,38 @@ static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md)
51 if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) {
52 printf("cryptodev_digest_final: digest failed\n");
58 + if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) < 0) {
59 + printf("cryptodev_digest_cleanup: failed to close session\n");
65 static int cryptodev_digest_cleanup(EVP_MD_CTX *ctx)
68 struct dev_crypto_state *state = ctx->md_data;
69 struct session_op *sess = &state->d_sess;
72 + if (state == NULL) {
75 - if (state->d_fd < 0) {
76 - printf("cryptodev_digest_cleanup: illegal input\n");
80 if (!(ctx->flags & EVP_MD_CTX_FLAG_ONESHOT)) {
81 OPENSSL_free(state->mac_data);
83 - state->mac_data = NULL;
86 - if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) < 0) {
87 - printf("cryptodev_digest_cleanup: failed to close session\n");
91 + if (state->d_fd >= 0) {
92 + put_dev_crypto(state->d_fd);
96 - put_dev_crypto(state->d_fd);
98 + state->mac_data = NULL;
105 static int cryptodev_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)