completion: zsh: stop leaking local cache variable
[alt-git.git] / sha256 / gcrypt.h
blob17a90f1052526c84847aa6d530a3e54e2558329f
1 #ifndef SHA256_GCRYPT_H
2 #define SHA256_GCRYPT_H
4 #include <gcrypt.h>
6 #define SHA256_DIGEST_SIZE 32
8 typedef gcry_md_hd_t gcrypt_SHA256_CTX;
10 static inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx)
12 gcry_error_t err = gcry_md_open(ctx, GCRY_MD_SHA256, 0);
13 if (err)
14 die("gcry_md_open: %s", gcry_strerror(err));
17 static inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data, size_t len)
19 gcry_md_write(*ctx, data, len);
22 static inline void gcrypt_SHA256_Final(unsigned char *digest, gcrypt_SHA256_CTX *ctx)
24 memcpy(digest, gcry_md_read(*ctx, GCRY_MD_SHA256), SHA256_DIGEST_SIZE);
25 gcry_md_close(*ctx);
28 static inline void gcrypt_SHA256_Clone(gcrypt_SHA256_CTX *dst, const gcrypt_SHA256_CTX *src)
30 gcry_md_copy(dst, *src);
33 #define platform_SHA256_CTX gcrypt_SHA256_CTX
34 #define platform_SHA256_Init gcrypt_SHA256_Init
35 #define platform_SHA256_Clone gcrypt_SHA256_Clone
36 #define platform_SHA256_Update gcrypt_SHA256_Update
37 #define platform_SHA256_Final gcrypt_SHA256_Final
39 #endif