SEcube open-source SDK
sha256.h
1 #include <stdint.h>
2 #include <string.h>
3 
8 #define B5_SHA256_RES_OK ( 0)
10 #define B5_SHA256_RES_INVALID_CONTEXT (-1)
11 #define B5_SHA256_RES_CANNOT_ALLOCATE_CONTEXT (-2)
12 #define B5_SHA256_RES_INVALID_ARGUMENT (-3)
13 
23 #define B5_SHA256_DIGEST_SIZE 32
25 #define B5_SHA256_BLOCK_SIZE 64
26 
33 typedef struct
35 {
36  uint32_t total[2];
37  uint32_t state[8];
38  uint8_t buffer[64];
39  uint32_t W[64];
40 } B5_tSha256Ctx;
42 
49 
56 int32_t B5_Sha256_Init (B5_tSha256Ctx *ctx);
57 
65 int32_t B5_Sha256_Update (B5_tSha256Ctx *ctx, const uint8_t *data, int32_t dataLen);
66 
73 int32_t B5_Sha256_Finit (B5_tSha256Ctx *ctx, uint8_t *rDigest);
75 
83 #define B5_HMAC_SHA256_RES_OK ( 0)
85 #define B5_HMAC_SHA256_RES_INVALID_CONTEXT (-1)
86 #define B5_HMAC_SHA256_RES_CANNOT_ALLOCATE_CONTEXT (-2)
87 #define B5_HMAC_SHA256_RES_INVALID_ARGUMENT (-3)
88 
96 typedef struct
98 {
99  B5_tSha256Ctx shaCtx;
100  uint8_t iPad[64];
101  uint8_t oPad[64];
102 } B5_tHmacSha256Ctx;
104 
112 
121 int32_t B5_HmacSha256_Init (B5_tHmacSha256Ctx *ctx, const uint8_t *Key, int16_t keySize);
122 
130 int32_t B5_HmacSha256_Update (B5_tHmacSha256Ctx *ctx, const uint8_t *data, int32_t dataLen);
131 
138 int32_t B5_HmacSha256_Finit (B5_tHmacSha256Ctx *ctx, uint8_t *rDigest);
B5_HmacSha256_Update
int32_t B5_HmacSha256_Update(B5_tHmacSha256Ctx *ctx, const uint8_t *data, int32_t dataLen)
Compute the HMAC-SHA256 algorithm on input data depending on the current status of the HMAC-SHA256 co...
Definition: sha256.c:374
B5_HmacSha256_Init
int32_t B5_HmacSha256_Init(B5_tHmacSha256Ctx *ctx, const uint8_t *Key, int16_t keySize)
Initialize the HMAC-SHA256 context.
Definition: sha256.c:321
B5_HmacSha256_Finit
int32_t B5_HmacSha256_Finit(B5_tHmacSha256Ctx *ctx, uint8_t *rDigest)
De-initialize the current HMAC-SHA256 context.
Definition: sha256.c:398
B5_Sha256_Finit
int32_t B5_Sha256_Finit(B5_tSha256Ctx *ctx, uint8_t *rDigest)
De-initialize the current SHA256 context.
Definition: sha256.c:267
B5_Sha256_Update
int32_t B5_Sha256_Update(B5_tSha256Ctx *ctx, const uint8_t *data, int32_t dataLen)
Compute the SHA256 algorithm on input data depending on the current status of the SHA256 context.
Definition: sha256.c:215
B5_Sha256_Init
int32_t B5_Sha256_Init(B5_tSha256Ctx *ctx)
Initialize the SHA256 context.
Definition: sha256.c:186