From 4bed94f0c11ef63587c6b2edb03c3c438e221604 Mon Sep 17 00:00:00 2001 From: Pauli Date: Wed, 17 Jan 2018 13:20:22 +1000 Subject: SHA512/224 and SHA512/256 Support added for these two digests, available only via the EVP interface. Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/5093) --- crypto/evp/m_sha1.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'crypto/evp/m_sha1.c') diff --git a/crypto/evp/m_sha1.c b/crypto/evp/m_sha1.c index 0fa184b310..d73e412b8d 100644 --- a/crypto/evp/m_sha1.c +++ b/crypto/evp/m_sha1.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,6 +15,7 @@ #include #include #include "internal/evp_int.h" +#include "internal/sha.h" static int init(EVP_MD_CTX *ctx) { @@ -173,6 +174,16 @@ const EVP_MD *EVP_sha256(void) return &sha256_md; } +static int init512_224(EVP_MD_CTX *ctx) +{ + return sha512_224_init(EVP_MD_CTX_md_data(ctx)); +} + +static int init512_256(EVP_MD_CTX *ctx) +{ + return sha512_256_init(EVP_MD_CTX_md_data(ctx)); +} + static int init384(EVP_MD_CTX *ctx) { return SHA384_Init(EVP_MD_CTX_md_data(ctx)); @@ -194,6 +205,44 @@ static int final512(EVP_MD_CTX *ctx, unsigned char *md) return SHA512_Final(md, EVP_MD_CTX_md_data(ctx)); } +static const EVP_MD sha512_224_md = { + NID_sha512_224, + NID_sha512_224WithRSAEncryption, + SHA224_DIGEST_LENGTH, + EVP_MD_FLAG_DIGALGID_ABSENT, + init512_224, + update512, + final512, + NULL, + NULL, + SHA512_CBLOCK, + sizeof(EVP_MD *) + sizeof(SHA512_CTX), +}; + +const EVP_MD *EVP_sha512_224(void) +{ + return &sha512_224_md; +} + +static const EVP_MD sha512_256_md = { + NID_sha512_256, + NID_sha512_256WithRSAEncryption, + SHA256_DIGEST_LENGTH, + EVP_MD_FLAG_DIGALGID_ABSENT, + init512_256, + update512, + final512, + NULL, + NULL, + SHA512_CBLOCK, + sizeof(EVP_MD *) + sizeof(SHA512_CTX), +}; + +const EVP_MD *EVP_sha512_256(void) +{ + return &sha512_256_md; +} + static const EVP_MD sha384_md = { NID_sha384, NID_sha384WithRSAEncryption, -- cgit v1.2.3