diff options
| author | jsing <> | 2023-04-16 17:06:19 +0000 |
|---|---|---|
| committer | jsing <> | 2023-04-16 17:06:19 +0000 |
| commit | 4b973a635aefcde8476827db5990f5afeb2f858a (patch) | |
| tree | 43d762c93e59f7c4bfec4130d545027ef48f43fe /src | |
| parent | f4810c6bc277cfaab018eeaf4a4d06bb68addf21 (diff) | |
| download | openbsd-4b973a635aefcde8476827db5990f5afeb2f858a.tar.gz openbsd-4b973a635aefcde8476827db5990f5afeb2f858a.tar.bz2 openbsd-4b973a635aefcde8476827db5990f5afeb2f858a.zip | |
Provide EVP methods for SHA3 224/256/384/512.
ok tb@
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/evp/evp.h | 10 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/m_sha3.c | 173 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha3_internal.h | 12 |
3 files changed, 193 insertions, 2 deletions
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h index 8b3c1d9ae7..830774a740 100644 --- a/src/lib/libcrypto/evp/evp.h +++ b/src/lib/libcrypto/evp/evp.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: evp.h,v 1.115 2023/04/16 16:42:06 jsing Exp $ */ | 1 | /* $OpenBSD: evp.h,v 1.116 2023/04/16 17:06:19 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -626,6 +626,14 @@ const EVP_MD *EVP_sha512_224(void); | |||
| 626 | const EVP_MD *EVP_sha512_256(void); | 626 | const EVP_MD *EVP_sha512_256(void); |
| 627 | #endif | 627 | #endif |
| 628 | #endif | 628 | #endif |
| 629 | #ifndef OPENSSL_NO_SHA3 | ||
| 630 | #if defined(LIBRESSL_INTERNAL) || defined(LIBRESSL_NEXT_API) | ||
| 631 | const EVP_MD *EVP_sha3_224(void); | ||
| 632 | const EVP_MD *EVP_sha3_256(void); | ||
| 633 | const EVP_MD *EVP_sha3_384(void); | ||
| 634 | const EVP_MD *EVP_sha3_512(void); | ||
| 635 | #endif | ||
| 636 | #endif | ||
| 629 | #ifndef OPENSSL_NO_SM3 | 637 | #ifndef OPENSSL_NO_SM3 |
| 630 | const EVP_MD *EVP_sm3(void); | 638 | const EVP_MD *EVP_sm3(void); |
| 631 | #endif | 639 | #endif |
diff --git a/src/lib/libcrypto/evp/m_sha3.c b/src/lib/libcrypto/evp/m_sha3.c new file mode 100644 index 0000000000..9944ec979d --- /dev/null +++ b/src/lib/libcrypto/evp/m_sha3.c | |||
| @@ -0,0 +1,173 @@ | |||
| 1 | /* $OpenBSD: m_sha3.c,v 1.1 2023/04/16 17:06:19 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <openssl/evp.h> | ||
| 19 | |||
| 20 | #include "evp_local.h" | ||
| 21 | #include "sha3_internal.h" | ||
| 22 | |||
| 23 | static int | ||
| 24 | sha3_224_init(EVP_MD_CTX *ctx) | ||
| 25 | { | ||
| 26 | return sha3_init(ctx->md_data, SHA3_224_DIGEST_LENGTH); | ||
| 27 | } | ||
| 28 | |||
| 29 | static int | ||
| 30 | sha3_224_update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
| 31 | { | ||
| 32 | return sha3_update(ctx->md_data, data, count); | ||
| 33 | } | ||
| 34 | |||
| 35 | static int | ||
| 36 | sha3_224_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 37 | { | ||
| 38 | return sha3_final(md, ctx->md_data); | ||
| 39 | } | ||
| 40 | |||
| 41 | static const EVP_MD sha3_224_md = { | ||
| 42 | .type = NID_sha3_224, | ||
| 43 | .pkey_type = NID_RSA_SHA3_224, | ||
| 44 | .md_size = SHA3_224_DIGEST_LENGTH, | ||
| 45 | .flags = EVP_MD_FLAG_DIGALGID_ABSENT, | ||
| 46 | .init = sha3_224_init, | ||
| 47 | .update = sha3_224_update, | ||
| 48 | .final = sha3_224_final, | ||
| 49 | .copy = NULL, | ||
| 50 | .cleanup = NULL, | ||
| 51 | .block_size = SHA3_224_BLOCK_SIZE, | ||
| 52 | .ctx_size = sizeof(EVP_MD *) + sizeof(sha3_ctx), | ||
| 53 | }; | ||
| 54 | |||
| 55 | const EVP_MD * | ||
| 56 | EVP_sha3_224(void) | ||
| 57 | { | ||
| 58 | return &sha3_224_md; | ||
| 59 | } | ||
| 60 | |||
| 61 | static int | ||
| 62 | sha3_256_init(EVP_MD_CTX *ctx) | ||
| 63 | { | ||
| 64 | return sha3_init(ctx->md_data, SHA3_256_DIGEST_LENGTH); | ||
| 65 | } | ||
| 66 | |||
| 67 | static int | ||
| 68 | sha3_256_update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
| 69 | { | ||
| 70 | return sha3_update(ctx->md_data, data, count); | ||
| 71 | } | ||
| 72 | |||
| 73 | static int | ||
| 74 | sha3_256_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 75 | { | ||
| 76 | return sha3_final(md, ctx->md_data); | ||
| 77 | } | ||
| 78 | |||
| 79 | static const EVP_MD sha3_256_md = { | ||
| 80 | .type = NID_sha3_256, | ||
| 81 | .pkey_type = NID_RSA_SHA3_256, | ||
| 82 | .md_size = SHA3_256_DIGEST_LENGTH, | ||
| 83 | .flags = EVP_MD_FLAG_DIGALGID_ABSENT, | ||
| 84 | .init = sha3_256_init, | ||
| 85 | .update = sha3_256_update, | ||
| 86 | .final = sha3_256_final, | ||
| 87 | .copy = NULL, | ||
| 88 | .cleanup = NULL, | ||
| 89 | .block_size = SHA3_256_BLOCK_SIZE, | ||
| 90 | .ctx_size = sizeof(EVP_MD *) + sizeof(sha3_ctx), | ||
| 91 | }; | ||
| 92 | |||
| 93 | const EVP_MD * | ||
| 94 | EVP_sha3_256(void) | ||
| 95 | { | ||
| 96 | return &sha3_256_md; | ||
| 97 | } | ||
| 98 | |||
| 99 | static int | ||
| 100 | sha3_384_init(EVP_MD_CTX *ctx) | ||
| 101 | { | ||
| 102 | return sha3_init(ctx->md_data, SHA3_384_DIGEST_LENGTH); | ||
| 103 | } | ||
| 104 | |||
| 105 | static int | ||
| 106 | sha3_384_update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
| 107 | { | ||
| 108 | return sha3_update(ctx->md_data, data, count); | ||
| 109 | } | ||
| 110 | |||
| 111 | static int | ||
| 112 | sha3_384_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 113 | { | ||
| 114 | return sha3_final(md, ctx->md_data); | ||
| 115 | } | ||
| 116 | |||
| 117 | static const EVP_MD sha3_384_md = { | ||
| 118 | .type = NID_sha3_384, | ||
| 119 | .pkey_type = NID_RSA_SHA3_384, | ||
| 120 | .md_size = SHA3_384_DIGEST_LENGTH, | ||
| 121 | .flags = EVP_MD_FLAG_DIGALGID_ABSENT, | ||
| 122 | .init = sha3_384_init, | ||
| 123 | .update = sha3_384_update, | ||
| 124 | .final = sha3_384_final, | ||
| 125 | .copy = NULL, | ||
| 126 | .cleanup = NULL, | ||
| 127 | .block_size = SHA3_384_BLOCK_SIZE, | ||
| 128 | .ctx_size = sizeof(EVP_MD *) + sizeof(sha3_ctx), | ||
| 129 | }; | ||
| 130 | |||
| 131 | const EVP_MD * | ||
| 132 | EVP_sha3_384(void) | ||
| 133 | { | ||
| 134 | return &sha3_384_md; | ||
| 135 | } | ||
| 136 | |||
| 137 | static int | ||
| 138 | sha3_512_init(EVP_MD_CTX *ctx) | ||
| 139 | { | ||
| 140 | return sha3_init(ctx->md_data, SHA3_512_DIGEST_LENGTH); | ||
| 141 | } | ||
| 142 | |||
| 143 | static int | ||
| 144 | sha3_512_update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
| 145 | { | ||
| 146 | return sha3_update(ctx->md_data, data, count); | ||
| 147 | } | ||
| 148 | |||
| 149 | static int | ||
| 150 | sha3_512_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 151 | { | ||
| 152 | return sha3_final(md, ctx->md_data); | ||
| 153 | } | ||
| 154 | |||
| 155 | static const EVP_MD sha3_512_md = { | ||
| 156 | .type = NID_sha3_512, | ||
| 157 | .pkey_type = NID_RSA_SHA3_512, | ||
| 158 | .md_size = SHA3_512_DIGEST_LENGTH, | ||
| 159 | .flags = EVP_MD_FLAG_DIGALGID_ABSENT, | ||
| 160 | .init = sha3_512_init, | ||
| 161 | .update = sha3_512_update, | ||
| 162 | .final = sha3_512_final, | ||
| 163 | .copy = NULL, | ||
| 164 | .cleanup = NULL, | ||
| 165 | .block_size = SHA3_512_BLOCK_SIZE, | ||
| 166 | .ctx_size = sizeof(EVP_MD *) + sizeof(sha3_ctx), | ||
| 167 | }; | ||
| 168 | |||
| 169 | const EVP_MD * | ||
| 170 | EVP_sha3_512(void) | ||
| 171 | { | ||
| 172 | return &sha3_512_md; | ||
| 173 | } | ||
diff --git a/src/lib/libcrypto/sha/sha3_internal.h b/src/lib/libcrypto/sha/sha3_internal.h index 91b1a43b25..d6fe3b8345 100644 --- a/src/lib/libcrypto/sha/sha3_internal.h +++ b/src/lib/libcrypto/sha/sha3_internal.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: sha3_internal.h,v 1.13 2023/04/15 20:00:24 jsing Exp $ */ | 1 | /* $OpenBSD: sha3_internal.h,v 1.14 2023/04/16 17:06:19 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * The MIT License (MIT) | 3 | * The MIT License (MIT) |
| 4 | * | 4 | * |
| @@ -29,6 +29,16 @@ | |||
| 29 | #ifndef HEADER_SHA3_INTERNAL_H | 29 | #ifndef HEADER_SHA3_INTERNAL_H |
| 30 | #define HEADER_SHA3_INTERNAL_H | 30 | #define HEADER_SHA3_INTERNAL_H |
| 31 | 31 | ||
| 32 | #define NID_sha3_224 1031 | ||
| 33 | #define NID_sha3_256 1032 | ||
| 34 | #define NID_sha3_384 1033 | ||
| 35 | #define NID_sha3_512 1034 | ||
| 36 | |||
| 37 | #define NID_RSA_SHA3_224 1049 | ||
| 38 | #define NID_RSA_SHA3_256 1050 | ||
| 39 | #define NID_RSA_SHA3_384 1051 | ||
| 40 | #define NID_RSA_SHA3_512 1052 | ||
| 41 | |||
| 32 | #define KECCAK_BIT_WIDTH 1600 | 42 | #define KECCAK_BIT_WIDTH 1600 |
| 33 | #define KECCAK_BYTE_WIDTH (KECCAK_BIT_WIDTH / 8) | 43 | #define KECCAK_BYTE_WIDTH (KECCAK_BIT_WIDTH / 8) |
| 34 | 44 | ||
