summaryrefslogtreecommitdiff
path: root/lib/libcrypto/evp
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2023-04-16 16:42:07 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2023-04-16 16:42:07 +0000
commitbcf67539b62765b60f0d11869ead64d5686ff3f0 (patch)
treeb3a155b99c2d92b2d2d7995176bd159d91512bf3 /lib/libcrypto/evp
parentb66b11f24a30a432af7cbd928df25e1b669ed6e1 (diff)
Provide EVP methods for SHA512/224 and SHA512/256.
ok tb@
Diffstat (limited to 'lib/libcrypto/evp')
-rw-r--r--lib/libcrypto/evp/evp.h6
-rw-r--r--lib/libcrypto/evp/m_sha1.c79
2 files changed, 83 insertions, 2 deletions
diff --git a/lib/libcrypto/evp/evp.h b/lib/libcrypto/evp/evp.h
index 035b4ad28c1..8b3c1d9ae71 100644
--- a/lib/libcrypto/evp/evp.h
+++ b/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/lib/libcrypto/evp/m_sha1.c b/lib/libcrypto/evp/m_sha1.c
index 92d8c30a8cc..b7f4705d861 100644
--- a/lib/libcrypto/evp/m_sha1.c
+++ b/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 */