summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2023-04-16 16:42:06 +0000
committerjsing <>2023-04-16 16:42:06 +0000
commit8d66484d5bc1482f15919f88c5812dc2994b81e7 (patch)
treee64ce8b789b434b3699244e110a8a1f63ac84413 /src/lib
parent50bbf7a93efba8cdbac043586d793a869d8ef88c (diff)
downloadopenbsd-8d66484d5bc1482f15919f88c5812dc2994b81e7.tar.gz
openbsd-8d66484d5bc1482f15919f88c5812dc2994b81e7.tar.bz2
openbsd-8d66484d5bc1482f15919f88c5812dc2994b81e7.zip
Provide EVP methods for SHA512/224 and SHA512/256.
ok tb@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/Makefile3
-rw-r--r--src/lib/libcrypto/evp/evp.h6
-rw-r--r--src/lib/libcrypto/evp/m_sha1.c79
-rw-r--r--src/lib/libcrypto/sha/sha_internal.h7
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 @@
1# $OpenBSD: Makefile,v 1.103 2023/04/14 11:10:11 jsing Exp $ 1# $OpenBSD: Makefile,v 1.104 2023/04/16 16:42:06 jsing Exp $
2 2
3LIB= crypto 3LIB= crypto
4LIBREBUILD=y 4LIBREBUILD=y
@@ -52,6 +52,7 @@ CFLAGS+= -I${LCRYPTO_SRC}/modes
52CFLAGS+= -I${LCRYPTO_SRC}/ocsp 52CFLAGS+= -I${LCRYPTO_SRC}/ocsp
53CFLAGS+= -I${LCRYPTO_SRC}/pkcs12 53CFLAGS+= -I${LCRYPTO_SRC}/pkcs12
54CFLAGS+= -I${LCRYPTO_SRC}/rsa 54CFLAGS+= -I${LCRYPTO_SRC}/rsa
55CFLAGS+= -I${LCRYPTO_SRC}/sha
55CFLAGS+= -I${LCRYPTO_SRC}/ts 56CFLAGS+= -I${LCRYPTO_SRC}/ts
56CFLAGS+= -I${LCRYPTO_SRC}/x509 57CFLAGS+= -I${LCRYPTO_SRC}/x509
57 58
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 @@
1/* $OpenBSD: evp.h,v 1.114 2023/03/10 16:41:07 tb Exp $ */ 1/* $OpenBSD: evp.h,v 1.115 2023/04/16 16:42:06 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 *
@@ -621,6 +621,10 @@ const EVP_MD *EVP_sha256(void);
621#ifndef OPENSSL_NO_SHA512 621#ifndef OPENSSL_NO_SHA512
622const EVP_MD *EVP_sha384(void); 622const EVP_MD *EVP_sha384(void);
623const EVP_MD *EVP_sha512(void); 623const EVP_MD *EVP_sha512(void);
624#if defined(LIBRESSL_INTERNAL) || defined(LIBRESSL_NEXT_API)
625const EVP_MD *EVP_sha512_224(void);
626const EVP_MD *EVP_sha512_256(void);
627#endif
624#endif 628#endif
625#ifndef OPENSSL_NO_SM3 629#ifndef OPENSSL_NO_SM3
626const EVP_MD *EVP_sm3(void); 630const 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 @@
1/* $OpenBSD: m_sha1.c,v 1.22 2023/04/09 15:47:41 jsing Exp $ */ 1/* $OpenBSD: m_sha1.c,v 1.23 2023/04/16 16:42:06 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 *
@@ -71,6 +71,7 @@
71#endif 71#endif
72 72
73#include "evp_local.h" 73#include "evp_local.h"
74#include "sha_internal.h"
74 75
75static int 76static int
76sha1_init(EVP_MD_CTX *ctx) 77sha1_init(EVP_MD_CTX *ctx)
@@ -271,4 +272,80 @@ EVP_sha512(void)
271{ 272{
272 return &sha512_md; 273 return &sha512_md;
273} 274}
275
276static int
277sha512_224_init(EVP_MD_CTX *ctx)
278{
279 return SHA512_224_Init(ctx->md_data);
280}
281
282static int
283sha512_224_update(EVP_MD_CTX *ctx, const void *data, size_t count)
284{
285 return SHA512_224_Update(ctx->md_data, data, count);
286}
287
288static int
289sha512_224_final(EVP_MD_CTX *ctx, unsigned char *md)
290{
291 return SHA512_224_Final(md, ctx->md_data);
292}
293
294static const EVP_MD sha512_224_md = {
295 .type = NID_sha512_224,
296 .pkey_type = NID_sha512_224WithRSAEncryption,
297 .md_size = SHA512_224_DIGEST_LENGTH,
298 .flags = EVP_MD_FLAG_DIGALGID_ABSENT,
299 .init = sha512_224_init,
300 .update = sha512_224_update,
301 .final = sha512_224_final,
302 .copy = NULL,
303 .cleanup = NULL,
304 .block_size = SHA512_CBLOCK,
305 .ctx_size = sizeof(EVP_MD *) + sizeof(SHA512_CTX),
306};
307
308const EVP_MD *
309EVP_sha512_224(void)
310{
311 return &sha512_224_md;
312}
313
314static int
315sha512_256_init(EVP_MD_CTX *ctx)
316{
317 return SHA512_256_Init(ctx->md_data);
318}
319
320static int
321sha512_256_update(EVP_MD_CTX *ctx, const void *data, size_t count)
322{
323 return SHA512_256_Update(ctx->md_data, data, count);
324}
325
326static int
327sha512_256_final(EVP_MD_CTX *ctx, unsigned char *md)
328{
329 return SHA512_256_Final(md, ctx->md_data);
330}
331
332static const EVP_MD sha512_256_md = {
333 .type = NID_sha512_256,
334 .pkey_type = NID_sha512_256WithRSAEncryption,
335 .md_size = SHA512_256_DIGEST_LENGTH,
336 .flags = EVP_MD_FLAG_DIGALGID_ABSENT,
337 .init = sha512_256_init,
338 .update = sha512_256_update,
339 .final = sha512_256_final,
340 .copy = NULL,
341 .cleanup = NULL,
342 .block_size = SHA512_CBLOCK,
343 .ctx_size = sizeof(EVP_MD *) + sizeof(SHA512_CTX),
344};
345
346const EVP_MD *
347EVP_sha512_256(void)
348{
349 return &sha512_256_md;
350}
274#endif /* ifndef OPENSSL_NO_SHA512 */ 351#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 @@
1/* $OpenBSD: sha_internal.h,v 1.1 2023/04/14 10:45:15 jsing Exp $ */ 1/* $OpenBSD: sha_internal.h,v 1.2 2023/04/16 16:42:06 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -20,6 +20,11 @@
20#ifndef HEADER_SHA_INTERNAL_H 20#ifndef HEADER_SHA_INTERNAL_H
21#define HEADER_SHA_INTERNAL_H 21#define HEADER_SHA_INTERNAL_H
22 22
23#define NID_sha512_224WithRSAEncryption 1025
24#define NID_sha512_256WithRSAEncryption 1026
25#define NID_sha512_224 1029
26#define NID_sha512_256 1030
27
23#define SHA512_224_DIGEST_LENGTH 28 28#define SHA512_224_DIGEST_LENGTH 28
24#define SHA512_256_DIGEST_LENGTH 32 29#define SHA512_256_DIGEST_LENGTH 32
25 30