diff --git a/extras/test/src/sha256/test_sha256.cpp b/extras/test/src/sha256/test_sha256.cpp index 216d732..b80dec5 100644 --- a/extras/test/src/sha256/test_sha256.cpp +++ b/extras/test/src/sha256/test_sha256.cpp @@ -19,7 +19,7 @@ #ifdef TEST_VECTORS_LONG static void test_sha256_long_message(uint8_t *digest) { - sha256_ctx ctx; + acu_sha256_ctx ctx; uint8_t message[1000]; int i; @@ -36,7 +36,7 @@ static void test_sha256_long_message(uint8_t *digest) static void test_sha256_message4(uint8_t *digest) { /* Message of 929271 bytes */ - sha256_ctx ctx; + acu_sha256_ctx ctx; uint8_t message[1000]; int i; diff --git a/src/sha256/SHA256.h b/src/sha256/SHA256.h index 4498e9d..bf4b92b 100644 --- a/src/sha256/SHA256.h +++ b/src/sha256/SHA256.h @@ -14,17 +14,17 @@ namespace arduino { namespace sha256 { - inline void begin(sha256_ctx * ctx) { - return sha256_init(ctx); + inline void begin(acu_sha256_ctx * ctx) { + return acu_sha256_init(ctx); } - inline void update(sha256_ctx *ctx, const uint8_t *input, uint32_t length) { - return sha256_update(ctx, input, length); + inline void update(acu_sha256_ctx *ctx, const uint8_t *input, uint32_t length) { + return acu_sha256_update(ctx, input, length); } - inline void finalize(sha256_ctx * ctx, uint8_t digest[SHA256_DIGEST_SIZE]) { - return sha256_final(ctx, digest); + inline void finalize(acu_sha256_ctx * ctx, uint8_t digest[SHA256_DIGEST_SIZE]) { + return acu_sha256_final(ctx, digest); } inline void sha256(const unsigned char *input, unsigned int ilen, unsigned char *output) { - ::sha256(input, ilen, output); + ::acu_sha256(input, ilen, output); } class SHA256 { @@ -47,7 +47,7 @@ namespace arduino { namespace sha256 { private: - sha256_ctx _ctx; + acu_sha256_ctx _ctx; }; }} // arduino::sha256 diff --git a/src/sha256/sha2.c b/src/sha256/sha2.c index e0337d6..7e967b9 100644 --- a/src/sha256/sha2.c +++ b/src/sha256/sha2.c @@ -128,7 +128,7 @@ static const uint32_t sha256_k[64] = /* SHA-2 internal function */ -static void sha256_transf(sha256_ctx *ctx, const uint8_t *message, +static void sha256_transf(acu_sha256_ctx *ctx, const uint8_t *message, uint64_t block_nb) { uint32_t w[64]; @@ -245,16 +245,16 @@ static void sha256_transf(sha256_ctx *ctx, const uint8_t *message, /* SHA-256 functions */ -void sha256(const uint8_t *message, uint64_t len, uint8_t *digest) +void acu_sha256(const uint8_t *message, uint64_t len, uint8_t *digest) { - sha256_ctx ctx; + acu_sha256_ctx ctx; - sha256_init(&ctx); - sha256_update(&ctx, message, len); - sha256_final(&ctx, digest); + acu_sha256_init(&ctx); + acu_sha256_update(&ctx, message, len); + acu_sha256_final(&ctx, digest); } -void sha256_init(sha256_ctx *ctx) +void acu_sha256_init(acu_sha256_ctx *ctx) { #ifndef UNROLL_LOOPS int i; @@ -272,7 +272,7 @@ void sha256_init(sha256_ctx *ctx) ctx->tot_len = 0; } -void sha256_update(sha256_ctx *ctx, const uint8_t *message, uint64_t len) +void acu_sha256_update(acu_sha256_ctx *ctx, const uint8_t *message, uint64_t len) { uint64_t block_nb; uint64_t new_len, rem_len, tmp_len; @@ -304,7 +304,7 @@ void sha256_update(sha256_ctx *ctx, const uint8_t *message, uint64_t len) ctx->tot_len += (block_nb + 1) << 6; } -void sha256_final(sha256_ctx *ctx, uint8_t *digest) +void acu_sha256_final(acu_sha256_ctx *ctx, uint8_t *digest) { uint64_t block_nb; uint64_t pm_len; diff --git a/src/sha256/sha2.h b/src/sha256/sha2.h index d6de3a6..4e84df2 100644 --- a/src/sha256/sha2.h +++ b/src/sha256/sha2.h @@ -37,8 +37,13 @@ #include #include -#define SHA256_DIGEST_SIZE ( 256 / 8) -#define SHA256_BLOCK_SIZE ( 512 / 8) +#ifndef SHA256_DIGEST_SIZE + #define SHA256_DIGEST_SIZE ( 256 / 8) +#endif // SHA256_DIGEST_SIZE + +#ifndef SHA256_BLOCK_SIZE + #define SHA256_BLOCK_SIZE ( 512 / 8) +#endif // SHA256_BLOCK_SIZE #ifdef __cplusplus extern "C" { @@ -49,12 +54,12 @@ typedef struct { uint64_t len; uint8_t block[2 * SHA256_BLOCK_SIZE]; uint32_t h[8]; -} sha256_ctx; +} acu_sha256_ctx; -void sha256_init(sha256_ctx * ctx); -void sha256_update(sha256_ctx *ctx, const uint8_t *message, uint64_t len); -void sha256_final(sha256_ctx *ctx, uint8_t *digest); -void sha256(const uint8_t *message, uint64_t len, uint8_t *digest); +void acu_sha256_init(acu_sha256_ctx * ctx); +void acu_sha256_update(acu_sha256_ctx *ctx, const uint8_t *message, uint64_t len); +void acu_sha256_final(acu_sha256_ctx *ctx, uint8_t *digest); +void acu_sha256(const uint8_t *message, uint64_t len, uint8_t *digest); #ifdef __cplusplus }