sha: convert SHA one shot macros back to being functions
authorPauli <pauli@openssl.org>
Wed, 9 Jun 2021 03:38:30 +0000 (13:38 +1000)
committerPauli <pauli@openssl.org>
Thu, 10 Jun 2021 04:18:06 +0000 (14:18 +1000)
Fixes #15655

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/15668)

crypto/sha/sha1_one.c
include/openssl/sha.h

index a21a1aded3fd646f9ecaa80c699bfe50f5204328..d6f5d1ecce9aefddc09589e80da1197bb407a715 100644 (file)
@@ -17,6 +17,7 @@
 #include <string.h>
 #include <openssl/crypto.h>
 #include <openssl/sha.h>
+#include <openssl/evp.h>
 #include "crypto/sha.h"
 
 unsigned char *ossl_sha1(const unsigned char *d, size_t n, unsigned char *md)
@@ -33,3 +34,28 @@ unsigned char *ossl_sha1(const unsigned char *d, size_t n, unsigned char *md)
     OPENSSL_cleanse(&c, sizeof(c));
     return md;
 }
+
+unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md)
+{
+    return EVP_Q_digest(NULL, "SHA1", NULL, d, n, md, NULL) ? md : NULL;
+}
+
+unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md)
+{
+    return EVP_Q_digest(NULL, "SHA224", NULL, d, n, md, NULL) ? md : NULL;
+}
+
+unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md)
+{
+    return EVP_Q_digest(NULL, "SHA256", NULL, d, n, md, NULL) ? md : NULL;
+}
+
+unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md)
+{
+    return EVP_Q_digest(NULL, "SHA384", NULL, d, n, md, NULL) ? md : NULL;
+}
+
+unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md)
+{
+    return EVP_Q_digest(NULL, "SHA512", NULL, d, n, md, NULL) ? md : NULL;
+}
index eac4b79302fcce89b947dd231dd0c9113859f17a..6e65a0408969e3cdc1dd4822bda23ecc52792b76 100644 (file)
@@ -17,7 +17,6 @@
 # endif
 
 # include <openssl/e_os2.h>
-# include <openssl/evp.h>
 # include <stddef.h>
 
 # ifdef  __cplusplus
@@ -53,8 +52,7 @@ OSSL_DEPRECATEDIN_3_0 int SHA1_Final(unsigned char *md, SHA_CTX *c);
 OSSL_DEPRECATEDIN_3_0 void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
 # endif
 
-# define SHA1(d, n, md) \
-    (EVP_Q_digest(NULL, "SHA1", NULL, d, n, md, NULL) ? md : NULL)
+unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);
 
 # ifndef OPENSSL_NO_DEPRECATED_3_0
 #  define SHA256_CBLOCK   (SHA_LBLOCK*4)/* SHA-256 treats input data as a
@@ -80,10 +78,8 @@ OSSL_DEPRECATEDIN_3_0 void SHA256_Transform(SHA256_CTX *c,
                                             const unsigned char *data);
 # endif
 
-# define SHA224(d, n, md) \
-    (EVP_Q_digest(NULL, "SHA224", NULL, d, n, md, NULL) ? md : NULL)
-# define SHA256(d, n, md) \
-    (EVP_Q_digest(NULL, "SHA256", NULL, d, n, md, NULL) ? md : NULL)
+unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md);
+unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md);
 
 # define SHA224_DIGEST_LENGTH    28
 # define SHA256_DIGEST_LENGTH    32
@@ -132,10 +128,8 @@ OSSL_DEPRECATEDIN_3_0 void SHA512_Transform(SHA512_CTX *c,
                                             const unsigned char *data);
 # endif
 
-# define SHA384(d, n, md) \
-    (EVP_Q_digest(NULL, "SHA384", NULL, d, n, md, NULL) ? md : NULL)
-# define SHA512(d, n, md) \
-    (EVP_Q_digest(NULL, "SHA512", NULL, d, n, md, NULL) ? md : NULL)
+unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md);
+unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md);
 
 # ifdef  __cplusplus
 }