diff options
author | Eneas U de Queiroz <cote2004-github@yahoo.com> | 2018-11-05 18:54:17 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2018-12-10 13:19:26 +0100 |
commit | b2db94d1d0bb79a80e188aaf459698ae5cbabe7d (patch) | |
tree | 2f0e563d7942d240f81bc0a79df1375e4db7162c /crypto/engine | |
parent | eng_devcrypto: make sure digest can do copy (diff) | |
download | openssl-b2db94d1d0bb79a80e188aaf459698ae5cbabe7d.tar.xz openssl-b2db94d1d0bb79a80e188aaf459698ae5cbabe7d.zip |
eng_devcrypto: save ioctl if EVP_MD_..FLAG_ONESHOT
Since each ioctl causes a context switch, slowing things down, if
EVP_MD_CTX_FLAG_ONESHOT is set, then:
- call the ioctl in digest_update, saving the result; and
- just copy the result in digest_final, instead of using another ioctl.
Signed-off-by: Eneas U de Queiroz <cote2004-github@yahoo.com>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7585)
Diffstat (limited to 'crypto/engine')
-rw-r--r-- | crypto/engine/eng_devcrypto.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/crypto/engine/eng_devcrypto.c b/crypto/engine/eng_devcrypto.c index 4a32d53016..1f6cbf3355 100644 --- a/crypto/engine/eng_devcrypto.c +++ b/crypto/engine/eng_devcrypto.c @@ -437,6 +437,7 @@ struct digest_ctx { struct session_op sess; /* This signals that the init function was called, not that it succeeded. */ int init_called; + unsigned char digest_res[HASH_MAX_LEN]; }; static const struct digest_data_st { @@ -539,12 +540,15 @@ static int digest_update(EVP_MD_CTX *ctx, const void *data, size_t count) if (digest_ctx == NULL) return 0; - if (digest_op(digest_ctx, data, count, NULL, COP_FLAG_UPDATE) < 0) { - SYSerr(SYS_F_IOCTL, errno); - return 0; + if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_ONESHOT)) { + if (digest_op(digest_ctx, data, count, digest_ctx->digest_res, 0) >= 0) + return 1; + } else if (digest_op(digest_ctx, data, count, NULL, COP_FLAG_UPDATE) >= 0) { + return 1; } - return 1; + SYSerr(SYS_F_IOCTL, errno); + return 0; } static int digest_final(EVP_MD_CTX *ctx, unsigned char *md) @@ -554,7 +558,10 @@ static int digest_final(EVP_MD_CTX *ctx, unsigned char *md) if (md == NULL || digest_ctx == NULL) return 0; - if (digest_op(digest_ctx, NULL, 0, md, COP_FLAG_FINAL) < 0) { + + if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_ONESHOT)) { + memcpy(md, digest_ctx->digest_res, EVP_MD_CTX_size(ctx)); + } else if (digest_op(digest_ctx, NULL, 0, md, COP_FLAG_FINAL) < 0) { SYSerr(SYS_F_IOCTL, errno); return 0; } |