aboutsummaryrefslogtreecommitdiffstats
path: root/security/nettle/files/patch-examples-nettle-openssl.c
blob: d7cf037c61c32694b8895c62c635098caeffe99e (plain) (blame)
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
--- examples/nettle-openssl.c.orig	2021-03-21 08:32:25 UTC
+++ examples/nettle-openssl.c
@@ -374,6 +374,7 @@ openssl_hash_update(void *p,
   EVP_DigestUpdate(ctx->evp, src, length);
 }
 
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
 #define OPENSSL_HASH(NAME, name)					\
 static void								\
 openssl_##name##_init(void *p)						\
@@ -404,6 +405,38 @@ nettle_openssl_##name = {						\
   openssl_hash_update,							\
   openssl_##name##_digest						\
 };
+#else
+#define OPENSSL_HASH(NAME, name)					\
+static void								\
+openssl_##name##_init(void *p)						\
+{									\
+  struct openssl_hash_ctx *ctx = p;					\
+  if ((ctx->evp = EVP_MD_CTX_create()) == NULL)			\
+    return;								\
+									\
+  EVP_DigestInit(ctx->evp, EVP_##name());				\
+}									\
+									\
+static void								\
+openssl_##name##_digest(void *p,					\
+		    size_t length, uint8_t *dst)			\
+{									\
+  struct openssl_hash_ctx *ctx = p;					\
+  assert(length == NAME##_DIGEST_LENGTH);				\
+									\
+  EVP_DigestFinal(ctx->evp, dst, NULL);					\
+  EVP_DigestInit(ctx->evp, EVP_##name());				\
+}									\
+									\
+const struct nettle_hash						\
+nettle_openssl_##name = {						\
+  "openssl " #name, sizeof(struct openssl_hash_ctx),			\
+  NAME##_DIGEST_LENGTH, NAME##_CBLOCK,					\
+  openssl_##name##_init,						\
+  openssl_hash_update,							\
+  openssl_##name##_digest						\
+};
+#endif
 
 OPENSSL_HASH(MD5, md5)
 OPENSSL_HASH(SHA, sha1)