1 /* wrappers for the EVP API of OpenSSL 3+ */
2 #ifndef SHA256_OPENSSL_H
3 #define SHA256_OPENSSL_H
4 #include <openssl/evp.h>
6 struct openssl_SHA256_CTX
{
10 typedef struct openssl_SHA256_CTX openssl_SHA256_CTX
;
12 static inline void openssl_SHA256_Init(struct openssl_SHA256_CTX
*ctx
)
14 const EVP_MD
*type
= EVP_sha256();
16 ctx
->ectx
= EVP_MD_CTX_new();
18 die("EVP_MD_CTX_new: out of memory");
20 EVP_DigestInit_ex(ctx
->ectx
, type
, NULL
);
23 static inline void openssl_SHA256_Update(struct openssl_SHA256_CTX
*ctx
,
27 EVP_DigestUpdate(ctx
->ectx
, data
, len
);
30 static inline void openssl_SHA256_Final(unsigned char *digest
,
31 struct openssl_SHA256_CTX
*ctx
)
33 EVP_DigestFinal_ex(ctx
->ectx
, digest
, NULL
);
34 EVP_MD_CTX_free(ctx
->ectx
);
37 static inline void openssl_SHA256_Clone(struct openssl_SHA256_CTX
*dst
,
38 const struct openssl_SHA256_CTX
*src
)
40 EVP_MD_CTX_copy_ex(dst
->ectx
, src
->ectx
);
43 #define platform_SHA256_CTX openssl_SHA256_CTX
44 #define platform_SHA256_Init openssl_SHA256_Init
45 #define platform_SHA256_Clone openssl_SHA256_Clone
46 #define platform_SHA256_Update openssl_SHA256_Update
47 #define platform_SHA256_Final openssl_SHA256_Final
49 #endif /* SHA256_OPENSSL_H */