71c9fdd438df946c5e0cf6991e5f0528a7b73bc9
[openwrt/staging/noltari.git] / package / libs / openssl / patches / 400-eng_devcrypto-save-ioctl-if-EVP_MD_.FLAG_ONESHOT.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Eneas U de Queiroz <cote2004-github@yahoo.com>
3 Date: Mon, 5 Nov 2018 15:54:17 -0200
4 Subject: eng_devcrypto: save ioctl if EVP_MD_..FLAG_ONESHOT
5
6 Since each ioctl causes a context switch, slowing things down, if
7 EVP_MD_CTX_FLAG_ONESHOT is set, then:
8 - call the ioctl in digest_update, saving the result; and
9 - just copy the result in digest_final, instead of using another ioctl.
10
11 Signed-off-by: Eneas U de Queiroz <cote2004-github@yahoo.com>
12
13 Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
14 Reviewed-by: Richard Levitte <levitte@openssl.org>
15 (Merged from https://github.com/openssl/openssl/pull/7585)
16
17 diff --git a/crypto/engine/eng_devcrypto.c b/crypto/engine/eng_devcrypto.c
18 --- a/crypto/engine/eng_devcrypto.c
19 +++ b/crypto/engine/eng_devcrypto.c
20 @@ -461,6 +461,7 @@ struct digest_ctx {
21 struct session_op sess;
22 /* This signals that the init function was called, not that it succeeded. */
23 int init_called;
24 + unsigned char digest_res[HASH_MAX_LEN];
25 };
26
27 static const struct digest_data_st {
28 @@ -564,12 +565,15 @@ static int digest_update(EVP_MD_CTX *ctx, const void *data, size_t count)
29 if (digest_ctx == NULL)
30 return 0;
31
32 - if (digest_op(digest_ctx, data, count, NULL, COP_FLAG_UPDATE) < 0) {
33 - SYSerr(SYS_F_IOCTL, errno);
34 - return 0;
35 + if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_ONESHOT)) {
36 + if (digest_op(digest_ctx, data, count, digest_ctx->digest_res, 0) >= 0)
37 + return 1;
38 + } else if (digest_op(digest_ctx, data, count, NULL, COP_FLAG_UPDATE) >= 0) {
39 + return 1;
40 }
41
42 - return 1;
43 + SYSerr(SYS_F_IOCTL, errno);
44 + return 0;
45 }
46
47 static int digest_final(EVP_MD_CTX *ctx, unsigned char *md)
48 @@ -579,7 +583,10 @@ static int digest_final(EVP_MD_CTX *ctx, unsigned char *md)
49
50 if (md == NULL || digest_ctx == NULL)
51 return 0;
52 - if (digest_op(digest_ctx, NULL, 0, md, COP_FLAG_FINAL) < 0) {
53 +
54 + if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_ONESHOT)) {
55 + memcpy(md, digest_ctx->digest_res, EVP_MD_CTX_size(ctx));
56 + } else if (digest_op(digest_ctx, NULL, 0, md, COP_FLAG_FINAL) < 0) {
57 SYSerr(SYS_F_IOCTL, errno);
58 return 0;
59 }