SEcube
SEcube Open Source Library - Host
sha256.h
1 #pragma once
2 
3 #include <stdint.h>
4 #include <string.h>
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
14 #define B5_SHA256_RES_OK ( 0)
16 #define B5_SHA256_RES_INVALID_CONTEXT (-1)
17 #define B5_SHA256_RES_CANNOT_ALLOCATE_CONTEXT (-2)
18 #define B5_SHA256_RES_INVALID_ARGUMENT (-3)
19 
29 #define B5_SHA256_DIGEST_SIZE 32
31 #define B5_SHA256_BLOCK_SIZE 64
32 
39 typedef struct
41 {
42  uint32_t total[2];
43  uint32_t state[8];
44  uint8_t buffer[64];
45  uint32_t W[64];
48 
55 
62 int32_t B5_Sha256_Init (B5_tSha256Ctx *ctx);
63 
71 int32_t B5_Sha256_Update (B5_tSha256Ctx *ctx, const uint8_t *data, int32_t dataLen);
72 
79 int32_t B5_Sha256_Finit (B5_tSha256Ctx *ctx, uint8_t *rDigest);
81 
89 #define B5_HMAC_SHA256_RES_OK ( 0)
91 #define B5_HMAC_SHA256_RES_INVALID_CONTEXT (-1)
92 #define B5_HMAC_SHA256_RES_CANNOT_ALLOCATE_CONTEXT (-2)
93 #define B5_HMAC_SHA256_RES_INVALID_ARGUMENT (-3)
94 
102 typedef struct
104 {
105  B5_tSha256Ctx shaCtx;
106  uint8_t iPad[64];
107  uint8_t oPad[64];
110 
118 
127 int32_t B5_HmacSha256_Init (B5_tHmacSha256Ctx *ctx, const uint8_t *Key, int16_t keySize);
128 
136 int32_t B5_HmacSha256_Update (B5_tHmacSha256Ctx *ctx, const uint8_t *data, int32_t dataLen);
137 
144 int32_t B5_HmacSha256_Finit (B5_tHmacSha256Ctx *ctx, uint8_t *rDigest);
146 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 
155 
156 
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:369
int32_t B5_HmacSha256_Finit(B5_tHmacSha256Ctx *ctx, uint8_t *rDigest)
De-initialize the current HMAC-SHA256 context.
Definition: sha256.c:393
int32_t B5_HmacSha256_Init(B5_tHmacSha256Ctx *ctx, const uint8_t *Key, int16_t keySize)
Initialize the HMAC-SHA256 context.
Definition: sha256.c:316
int32_t B5_Sha256_Finit(B5_tSha256Ctx *ctx, uint8_t *rDigest)
De-initialize the current SHA256 context.
Definition: sha256.c:262
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:210
Definition: sha256.h:40
int32_t B5_Sha256_Init(B5_tSha256Ctx *ctx)
Initialize the SHA256 context.
Definition: sha256.c:181
Definition: sha256.h:103