libbtc
bitcoinclibrary
sha2.h
Go to the documentation of this file.
1 
32 #ifndef __SHA2_H__
33 #define __SHA2_H__
34 
35 #include <stdint.h>
36 #include <stddef.h>
37 
38 #define SHA256_BLOCK_LENGTH 64
39 #define SHA256_DIGEST_LENGTH 32
40 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
41 #define SHA512_BLOCK_LENGTH 128
42 #define SHA512_DIGEST_LENGTH 64
43 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
44 
45 typedef struct _SHA256_CTX
46 {
47  uint32_t state[8];
48  uint64_t bitcount;
50 } SHA256_CTX;
51 typedef struct _SHA512_CTX
52 {
53  uint64_t state[8];
54  uint64_t bitcount[2];
56 } SHA512_CTX;
57 
58 void sha256_Init(SHA256_CTX*);
59 void sha256_Update(SHA256_CTX*, const uint8_t*, size_t);
61 void sha256_Raw(const uint8_t*, size_t, uint8_t[SHA256_DIGEST_LENGTH]);
62 
63 void sha512_Init(SHA512_CTX*);
64 void sha512_Update(SHA512_CTX*, const uint8_t*, size_t);
66 void sha512_Raw(const uint8_t*, size_t, uint8_t[SHA512_DIGEST_LENGTH]);
67 
68 void hmac_sha256(const uint8_t* key, const uint32_t keylen, const uint8_t* msg, const uint32_t msglen, uint8_t* hmac);
69 void hmac_sha512(const uint8_t* key, const uint32_t keylen, const uint8_t* msg, const uint32_t msglen, uint8_t* hmac);
70 #endif
void sha512_Init(SHA512_CTX *)
Definition: sha2.c:662
void sha256_Init(SHA256_CTX *)
Definition: sha2.c:360
uint32_t state[8]
Definition: sha2.h:47
#define SHA256_BLOCK_LENGTH
Definition: sha2.h:38
uint64_t bitcount[2]
Definition: sha2.h:54
struct _SHA512_CTX SHA512_CTX
void hmac_sha512(const uint8_t *key, const uint32_t keylen, const uint8_t *msg, const uint32_t msglen, uint8_t *hmac)
Definition: sha2.c:996
void sha512_Update(SHA512_CTX *, const uint8_t *, size_t)
Definition: sha2.c:840
struct _SHA256_CTX SHA256_CTX
void hmac_sha256(const uint8_t *key, const uint32_t keylen, const uint8_t *msg, const uint32_t msglen, uint8_t *hmac)
Definition: sha2.c:966
uint64_t bitcount
Definition: sha2.h:48
void sha512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX *)
void sha512_Raw(const uint8_t *, size_t, uint8_t[SHA512_DIGEST_LENGTH])
Definition: sha2.c:958
#define SHA256_DIGEST_LENGTH
Definition: sha2.h:39
void sha256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX *)
Definition: buffer.h:13
void sha256_Raw(const uint8_t *, size_t, uint8_t[SHA256_DIGEST_LENGTH])
Definition: sha2.c:652
uint64_t state[8]
Definition: sha2.h:53
#define SHA512_DIGEST_LENGTH
Definition: sha2.h:42
#define SHA512_BLOCK_LENGTH
Definition: sha2.h:41
void sha256_Update(SHA256_CTX *, const uint8_t *, size_t)
Definition: sha2.c:544