-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsha256.h
61 lines (49 loc) · 1.46 KB
/
sha256.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*!
* @file libxutils/src/crypt/sha256.h
*
* This source is part of "libxutils" project
* 2015-2020 Sun Dro (s.kalatoz@gmail.com)
*
* @brief SHA-256 computing implementation for C/C++ based
* on pseudocode for the SHA-256 algorithm from Wikipedia.
*/
#ifndef __XUTILS_SHA256_H__
#define __XUTILS_SHA256_H__
#ifdef __cplusplus
extern "C" {
#endif
#define XSHA256_BLOCK_SIZE 64
#define XSHA256_DIGEST_SIZE 32
#define XSHA256_PADDING_SIZE 19
#define XSHA256_LENGTH 64
#include "xstd.h"
typedef union
{
uint32_t hBytes[8];
uint8_t digest[32];
} xsha256_digest_t;
typedef union
{
uint32_t wBytes[16];
uint8_t block[64];
} xsha256_block_t;
typedef struct XSHA256
{
xsha256_digest_t uDigest;
xsha256_block_t uBlock;
size_t nTotalSize;
size_t nSize;
} xsha256_t;
void XSHA256_Init(xsha256_t *pSha);
void XSHA256_ProcessBlock(xsha256_t *pSha);
void XSHA256_Final(xsha256_t *pSha, uint8_t *pDigest);
void XSHA256_FinalRaw(xsha256_t *pSha, uint8_t *pDigest);
void XSHA256_Update(xsha256_t *pSha, const uint8_t *pData, size_t nLength);
XSTATUS XSHA256_Compute(uint8_t *pOutput, size_t nSize, const uint8_t *pInput, size_t nLength);
XSTATUS XSHA256_ComputeSum(char *pOutput, size_t nSize, const uint8_t *pInput, size_t nLength);
uint8_t* XSHA256_Encrypt(const uint8_t *pInput, size_t nLength);
char* XSHA256_Sum(const uint8_t *pInput, size_t nLength);
#ifdef __cplusplus
}
#endif
#endif /* __XUTILS_SHA256_H__ */