interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / sha256 / openssl.h

55 lines · 1425 bytes Raw Blame History
1/* wrappers for the EVP API of OpenSSL 3+ */
2#ifndef SHA256_OPENSSL_H
3#define SHA256_OPENSSL_H
4#include <openssl/evp.h>
5
6struct openssl_SHA256_CTX {
7 EVP_MD_CTX *ectx;
8};
9
10typedef struct openssl_SHA256_CTX openssl_SHA256_CTX;
11
12static inline void openssl_SHA256_Init(struct openssl_SHA256_CTX *ctx)
13{
14 const EVP_MD *type = EVP_sha256();
15
16 ctx->ectx = EVP_MD_CTX_new();
17 if (!ctx->ectx)
18 die("EVP_MD_CTX_new: out of memory");
19
20 EVP_DigestInit_ex(ctx->ectx, type, NULL);
21}
22
23static inline void openssl_SHA256_Update(struct openssl_SHA256_CTX *ctx,
24 const void *data,
25 size_t len)
26{
27 EVP_DigestUpdate(ctx->ectx, data, len);
28}
29
30static inline void openssl_SHA256_Final(unsigned char *digest,
31 struct openssl_SHA256_CTX *ctx)
32{
33 EVP_DigestFinal_ex(ctx->ectx, digest, NULL);
34 EVP_MD_CTX_free(ctx->ectx);
35}
36
37static inline void openssl_SHA256_Clone(struct openssl_SHA256_CTX *dst,
38 const struct openssl_SHA256_CTX *src)
39{
40 EVP_MD_CTX_copy_ex(dst->ectx, src->ectx);
41}
42
43static inline void openssl_SHA256_Discard(struct openssl_SHA256_CTX *ctx)
44{
45 EVP_MD_CTX_free(ctx->ectx);
46}
47
48#define platform_SHA256_CTX openssl_SHA256_CTX
49#define platform_SHA256_Init openssl_SHA256_Init
50#define platform_SHA256_Clone openssl_SHA256_Clone
51#define platform_SHA256_Update openssl_SHA256_Update
52#define platform_SHA256_Final openssl_SHA256_Final
53#define platform_SHA256_Discard openssl_SHA256_Discard
54
55#endif /* SHA256_OPENSSL_H */