Skip to content

renaming sha256 functions to avoid clashing with esp8266:esp8266:huzzah #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extras/test/src/sha256/test_sha256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
16 changes: 8 additions & 8 deletions src/sha256/SHA256.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -47,7 +47,7 @@ namespace arduino { namespace sha256 {

private:

sha256_ctx _ctx;
acu_sha256_ctx _ctx;
};

}} // arduino::sha256
18 changes: 9 additions & 9 deletions src/sha256/sha2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 12 additions & 7 deletions src/sha256/sha2.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@
#include <stddef.h>
#include <string.h>

#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" {
Expand All @@ -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
}
Expand Down
Loading