1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
From 8dff3535f4db62f83e7a2781d82f87c7526cc16c Mon Sep 17 00:00:00 2001
From: jsing <>
Date: Sun, 16 Apr 2023 16:42:06 +0000
Subject: [PATCH] Provide EVP methods for SHA512/224 and SHA512/256.
ok tb@
---
src/lib/libcrypto/Makefile | 3 +-
src/lib/libcrypto/evp/evp.h | 6 ++-
src/lib/libcrypto/evp/m_sha1.c | 79 +++++++++++++++++++++++++++-
src/lib/libcrypto/sha/sha_internal.h | 7 ++-
4 files changed, 91 insertions(+), 4 deletions(-)
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile
index 726f23aecc..30876f19e8 100644
--- a/src/lib/libcrypto/Makefile
+++ b/src/lib/libcrypto/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.103 2023/04/14 11:10:11 jsing Exp $
+# $OpenBSD: Makefile,v 1.104 2023/04/16 16:42:06 jsing Exp $
LIB= crypto
LIBREBUILD=y
@@ -52,6 +52,7 @@ CFLAGS+= -I${LCRYPTO_SRC}/modes
CFLAGS+= -I${LCRYPTO_SRC}/ocsp
CFLAGS+= -I${LCRYPTO_SRC}/pkcs12
CFLAGS+= -I${LCRYPTO_SRC}/rsa
+CFLAGS+= -I${LCRYPTO_SRC}/sha
CFLAGS+= -I${LCRYPTO_SRC}/ts
CFLAGS+= -I${LCRYPTO_SRC}/x509
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
index 035b4ad28c..8b3c1d9ae7 100644
--- a/src/lib/libcrypto/evp/evp.h
+++ b/src/lib/libcrypto/evp/evp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: evp.h,v 1.114 2023/03/10 16:41:07 tb Exp $ */
+/* $OpenBSD: evp.h,v 1.115 2023/04/16 16:42:06 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -621,6 +621,10 @@ const EVP_MD *EVP_sha256(void);
#ifndef OPENSSL_NO_SHA512
const EVP_MD *EVP_sha384(void);
const EVP_MD *EVP_sha512(void);
+#if defined(LIBRESSL_INTERNAL) || defined(LIBRESSL_NEXT_API)
+const EVP_MD *EVP_sha512_224(void);
+const EVP_MD *EVP_sha512_256(void);
+#endif
#endif
#ifndef OPENSSL_NO_SM3
const EVP_MD *EVP_sm3(void);
diff --git a/src/lib/libcrypto/evp/m_sha1.c b/src/lib/libcrypto/evp/m_sha1.c
index 92d8c30a8c..b7f4705d86 100644
--- a/src/lib/libcrypto/evp/m_sha1.c
+++ b/src/lib/libcrypto/evp/m_sha1.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: m_sha1.c,v 1.22 2023/04/09 15:47:41 jsing Exp $ */
+/* $OpenBSD: m_sha1.c,v 1.23 2023/04/16 16:42:06 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -71,6 +71,7 @@
#endif
#include "evp_local.h"
+#include "sha_internal.h"
static int
sha1_init(EVP_MD_CTX *ctx)
@@ -271,4 +272,80 @@ EVP_sha512(void)
{
return &sha512_md;
}
+
+static int
+sha512_224_init(EVP_MD_CTX *ctx)
+{
+ return SHA512_224_Init(ctx->md_data);
+}
+
+static int
+sha512_224_update(EVP_MD_CTX *ctx, const void *data, size_t count)
+{
+ return SHA512_224_Update(ctx->md_data, data, count);
+}
+
+static int
+sha512_224_final(EVP_MD_CTX *ctx, unsigned char *md)
+{
+ return SHA512_224_Final(md, ctx->md_data);
+}
+
+static const EVP_MD sha512_224_md = {
+ .type = NID_sha512_224,
+ .pkey_type = NID_sha512_224WithRSAEncryption,
+ .md_size = SHA512_224_DIGEST_LENGTH,
+ .flags = EVP_MD_FLAG_DIGALGID_ABSENT,
+ .init = sha512_224_init,
+ .update = sha512_224_update,
+ .final = sha512_224_final,
+ .copy = NULL,
+ .cleanup = NULL,
+ .block_size = SHA512_CBLOCK,
+ .ctx_size = sizeof(EVP_MD *) + sizeof(SHA512_CTX),
+};
+
+const EVP_MD *
+EVP_sha512_224(void)
+{
+ return &sha512_224_md;
+}
+
+static int
+sha512_256_init(EVP_MD_CTX *ctx)
+{
+ return SHA512_256_Init(ctx->md_data);
+}
+
+static int
+sha512_256_update(EVP_MD_CTX *ctx, const void *data, size_t count)
+{
+ return SHA512_256_Update(ctx->md_data, data, count);
+}
+
+static int
+sha512_256_final(EVP_MD_CTX *ctx, unsigned char *md)
+{
+ return SHA512_256_Final(md, ctx->md_data);
+}
+
+static const EVP_MD sha512_256_md = {
+ .type = NID_sha512_256,
+ .pkey_type = NID_sha512_256WithRSAEncryption,
+ .md_size = SHA512_256_DIGEST_LENGTH,
+ .flags = EVP_MD_FLAG_DIGALGID_ABSENT,
+ .init = sha512_256_init,
+ .update = sha512_256_update,
+ .final = sha512_256_final,
+ .copy = NULL,
+ .cleanup = NULL,
+ .block_size = SHA512_CBLOCK,
+ .ctx_size = sizeof(EVP_MD *) + sizeof(SHA512_CTX),
+};
+
+const EVP_MD *
+EVP_sha512_256(void)
+{
+ return &sha512_256_md;
+}
#endif /* ifndef OPENSSL_NO_SHA512 */
diff --git a/src/lib/libcrypto/sha/sha_internal.h b/src/lib/libcrypto/sha/sha_internal.h
index c479993185..1a0f449a20 100644
--- a/src/lib/libcrypto/sha/sha_internal.h
+++ b/src/lib/libcrypto/sha/sha_internal.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sha_internal.h,v 1.1 2023/04/14 10:45:15 jsing Exp $ */
+/* $OpenBSD: sha_internal.h,v 1.2 2023/04/16 16:42:06 jsing Exp $ */
/*
* Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
*
@@ -20,6 +20,11 @@
#ifndef HEADER_SHA_INTERNAL_H
#define HEADER_SHA_INTERNAL_H
+#define NID_sha512_224WithRSAEncryption 1025
+#define NID_sha512_256WithRSAEncryption 1026
+#define NID_sha512_224 1029
+#define NID_sha512_256 1030
+
#define SHA512_224_DIGEST_LENGTH 28
#define SHA512_256_DIGEST_LENGTH 32
|