mirror of
https://github.com/kmackay/micro-ecc.git
synced 2026-08-10 04:07:46 +00:00
uECC_HashContext => const uECC_HashContext
This is an important piece of "documentation" as it indicates to the caller that a uECC_HashContext can be initialized and subsequently used multiple times (for multiple signatures).
This commit is contained in:
@@ -23,19 +23,19 @@ typedef struct SHA256_HashContext {
|
||||
SHA256_CTX ctx;
|
||||
} SHA256_HashContext;
|
||||
|
||||
static void init_SHA256(uECC_HashContext *base) {
|
||||
static void init_SHA256(const uECC_HashContext *base) {
|
||||
SHA256_HashContext *context = (SHA256_HashContext *)base;
|
||||
SHA256_Init(&context->ctx);
|
||||
}
|
||||
|
||||
static void update_SHA256(uECC_HashContext *base,
|
||||
static void update_SHA256(const uECC_HashContext *base,
|
||||
const uint8_t *message,
|
||||
unsigned message_size) {
|
||||
SHA256_HashContext *context = (SHA256_HashContext *)base;
|
||||
SHA256_Update(&context->ctx, message, message_size);
|
||||
}
|
||||
|
||||
static void finish_SHA256(uECC_HashContext *base, uint8_t *hash_result) {
|
||||
static void finish_SHA256(const uECC_HashContext *base, uint8_t *hash_result) {
|
||||
SHA256_HashContext *context = (SHA256_HashContext *)base;
|
||||
SHA256_Final(hash_result, &context->ctx);
|
||||
}
|
||||
|
||||
@@ -1231,7 +1231,7 @@ int uECC_sign(const uint8_t *private_key,
|
||||
|
||||
/* Compute an HMAC using K as a key (as in RFC 6979). Note that K is always
|
||||
the same size as the hash result size. */
|
||||
static void HMAC_init(uECC_HashContext *hash_context, const uint8_t *K) {
|
||||
static void HMAC_init(const uECC_HashContext *hash_context, const uint8_t *K) {
|
||||
uint8_t *pad = hash_context->tmp + 2 * hash_context->result_size;
|
||||
unsigned i;
|
||||
for (i = 0; i < hash_context->result_size; ++i)
|
||||
@@ -1243,13 +1243,15 @@ static void HMAC_init(uECC_HashContext *hash_context, const uint8_t *K) {
|
||||
hash_context->update_hash(hash_context, pad, hash_context->block_size);
|
||||
}
|
||||
|
||||
static void HMAC_update(uECC_HashContext *hash_context,
|
||||
static void HMAC_update(const uECC_HashContext *hash_context,
|
||||
const uint8_t *message,
|
||||
unsigned message_size) {
|
||||
hash_context->update_hash(hash_context, message, message_size);
|
||||
}
|
||||
|
||||
static void HMAC_finish(uECC_HashContext *hash_context, const uint8_t *K, uint8_t *result) {
|
||||
static void HMAC_finish(const uECC_HashContext *hash_context,
|
||||
const uint8_t *K,
|
||||
uint8_t *result) {
|
||||
uint8_t *pad = hash_context->tmp + 2 * hash_context->result_size;
|
||||
unsigned i;
|
||||
for (i = 0; i < hash_context->result_size; ++i)
|
||||
@@ -1266,7 +1268,7 @@ static void HMAC_finish(uECC_HashContext *hash_context, const uint8_t *K, uint8_
|
||||
}
|
||||
|
||||
/* V = HMAC_K(V) */
|
||||
static void update_V(uECC_HashContext *hash_context, uint8_t *K, uint8_t *V) {
|
||||
static void update_V(const uECC_HashContext *hash_context, uint8_t *K, uint8_t *V) {
|
||||
HMAC_init(hash_context, K);
|
||||
HMAC_update(hash_context, V, hash_context->result_size);
|
||||
HMAC_finish(hash_context, K, V);
|
||||
@@ -1281,7 +1283,7 @@ static void update_V(uECC_HashContext *hash_context, uint8_t *K, uint8_t *V) {
|
||||
int uECC_sign_deterministic(const uint8_t *private_key,
|
||||
const uint8_t *message_hash,
|
||||
unsigned hash_size,
|
||||
uECC_HashContext *hash_context,
|
||||
const uECC_HashContext *hash_context,
|
||||
uint8_t *signature,
|
||||
uECC_Curve curve) {
|
||||
uint8_t *K = hash_context->tmp;
|
||||
|
||||
@@ -265,11 +265,11 @@ void finish_SHA256(uECC_HashContext *base, uint8_t *hash_result) {
|
||||
}
|
||||
*/
|
||||
typedef struct uECC_HashContext {
|
||||
void (*init_hash)(struct uECC_HashContext *context);
|
||||
void (*update_hash)(struct uECC_HashContext *context,
|
||||
void (*init_hash)(const struct uECC_HashContext *context);
|
||||
void (*update_hash)(const struct uECC_HashContext *context,
|
||||
const uint8_t *message,
|
||||
unsigned message_size);
|
||||
void (*finish_hash)(struct uECC_HashContext *context, uint8_t *hash_result);
|
||||
void (*finish_hash)(const struct uECC_HashContext *context, uint8_t *hash_result);
|
||||
unsigned block_size; /* Hash function block size in bytes, eg 64 for SHA-256. */
|
||||
unsigned result_size; /* Hash function result size in bytes, eg 32 for SHA-256. */
|
||||
uint8_t *tmp; /* Must point to a buffer of at least (2 * result_size + block_size) bytes. */
|
||||
@@ -299,7 +299,7 @@ Returns 1 if the signature generated successfully, 0 if an error occurred.
|
||||
int uECC_sign_deterministic(const uint8_t *private_key,
|
||||
const uint8_t *message_hash,
|
||||
unsigned hash_size,
|
||||
uECC_HashContext *hash_context,
|
||||
const uECC_HashContext *hash_context,
|
||||
uint8_t *signature,
|
||||
uECC_Curve curve);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user