]> git.ipfire.org Git - thirdparty/git.git/blame - sha256/gcrypt.h
Merge branch 'mg/editorconfig-makefile'
[thirdparty/git.git] / sha256 / gcrypt.h
CommitLineData
27dc04c5 1#ifndef SHA256_GCRYPT_H
2#define SHA256_GCRYPT_H
3
4#include <gcrypt.h>
5
6#define SHA256_DIGEST_SIZE 32
7
8typedef gcry_md_hd_t gcrypt_SHA256_CTX;
9
b4b85e41 10static inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx)
27dc04c5 11{
823839bd
EW
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));
27dc04c5 15}
16
b4b85e41 17static inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data, size_t len)
27dc04c5 18{
19 gcry_md_write(*ctx, data, len);
20}
21
b4b85e41 22static inline void gcrypt_SHA256_Final(unsigned char *digest, gcrypt_SHA256_CTX *ctx)
27dc04c5 23{
24 memcpy(digest, gcry_md_read(*ctx, GCRY_MD_SHA256), SHA256_DIGEST_SIZE);
8b608f3f 25 gcry_md_close(*ctx);
27dc04c5 26}
27
b4b85e41 28static inline void gcrypt_SHA256_Clone(gcrypt_SHA256_CTX *dst, const gcrypt_SHA256_CTX *src)
768e30ea 29{
30 gcry_md_copy(dst, *src);
31}
32
27dc04c5 33#define platform_SHA256_CTX gcrypt_SHA256_CTX
34#define platform_SHA256_Init gcrypt_SHA256_Init
768e30ea 35#define platform_SHA256_Clone gcrypt_SHA256_Clone
27dc04c5 36#define platform_SHA256_Update gcrypt_SHA256_Update
37#define platform_SHA256_Final gcrypt_SHA256_Final
38
39#endif