Moved hash_byte & hash_nbytes functions to common

Also fixed possible overflow on large payload hashing
This commit is contained in:
Alexandre Paillier
2022-11-25 16:40:15 +01:00
parent f17104312b
commit e15899c92e
3 changed files with 12 additions and 19 deletions

22
src_common/hash_bytes.c Normal file
View File

@@ -0,0 +1,22 @@
#include "hash_bytes.h"
/**
* Continue given progressive hash on given bytes
*
* @param[in] bytes_ptr pointer to bytes
* @param[in] n number of bytes to hash
* @param[in] hash_ctx pointer to the hashing context
*/
void hash_nbytes(const uint8_t *bytes_ptr, size_t n, cx_hash_t *hash_ctx) {
cx_hash(hash_ctx, 0, bytes_ptr, n, NULL, 0);
}
/**
* Continue given progressive hash on given byte
*
* @param[in] byte byte to hash
* @param[in] hash_ctx pointer to the hashing context
*/
void hash_byte(uint8_t byte, cx_hash_t *hash_ctx) {
hash_nbytes(&byte, 1, hash_ctx);
}

10
src_common/hash_bytes.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef HASH_BYTES_H_
#define HASH_BYTES_H_
#include <stdint.h>
#include "cx.h"
void hash_nbytes(const uint8_t *const bytes_ptr, size_t n, cx_hash_t *hash_ctx);
void hash_byte(uint8_t byte, cx_hash_t *hash_ctx);
#endif // HASH_BYTES_H_