Skip to content

Commit 77c003d

Browse files
renaming sha256 functions to avoid clashing with esp8266:esp8266:huzzah
1 parent 0d100c3 commit 77c003d

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

extras/test/src/sha256/test_sha256.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifdef TEST_VECTORS_LONG
2020
static void test_sha256_long_message(uint8_t *digest)
2121
{
22-
sha256_ctx ctx;
22+
acu_sha256_ctx ctx;
2323
uint8_t message[1000];
2424
int i;
2525

@@ -36,7 +36,7 @@ static void test_sha256_long_message(uint8_t *digest)
3636
static void test_sha256_message4(uint8_t *digest)
3737
{
3838
/* Message of 929271 bytes */
39-
sha256_ctx ctx;
39+
acu_sha256_ctx ctx;
4040
uint8_t message[1000];
4141
int i;
4242

src/sha256/SHA256.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414

1515
namespace arduino { namespace sha256 {
1616

17-
inline void begin(sha256_ctx * ctx) {
18-
return sha256_init(ctx);
17+
inline void begin(acu_sha256_ctx * ctx) {
18+
return acu_sha256_init(ctx);
1919
}
20-
inline void update(sha256_ctx *ctx, const uint8_t *input, uint32_t length) {
21-
return sha256_update(ctx, input, length);
20+
inline void update(acu_sha256_ctx *ctx, const uint8_t *input, uint32_t length) {
21+
return acu_sha256_update(ctx, input, length);
2222
}
23-
inline void finalize(sha256_ctx * ctx, uint8_t digest[SHA256_DIGEST_SIZE]) {
24-
return sha256_final(ctx, digest);
23+
inline void finalize(acu_sha256_ctx * ctx, uint8_t digest[SHA256_DIGEST_SIZE]) {
24+
return acu_sha256_final(ctx, digest);
2525
}
2626
inline void sha256(const unsigned char *input, unsigned int ilen, unsigned char *output) {
27-
::sha256(input, ilen, output);
27+
::acu_sha256(input, ilen, output);
2828
}
2929

3030
class SHA256 {
@@ -47,7 +47,7 @@ namespace arduino { namespace sha256 {
4747

4848
private:
4949

50-
sha256_ctx _ctx;
50+
acu_sha256_ctx _ctx;
5151
};
5252

5353
}} // arduino::sha256

src/sha256/sha2.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static const uint32_t sha256_k[64] =
128128

129129
/* SHA-2 internal function */
130130

131-
static void sha256_transf(sha256_ctx *ctx, const uint8_t *message,
131+
static void sha256_transf(acu_sha256_ctx *ctx, const uint8_t *message,
132132
uint64_t block_nb)
133133
{
134134
uint32_t w[64];
@@ -245,16 +245,16 @@ static void sha256_transf(sha256_ctx *ctx, const uint8_t *message,
245245

246246
/* SHA-256 functions */
247247

248-
void sha256(const uint8_t *message, uint64_t len, uint8_t *digest)
248+
void acu_sha256(const uint8_t *message, uint64_t len, uint8_t *digest)
249249
{
250-
sha256_ctx ctx;
250+
acu_sha256_ctx ctx;
251251

252-
sha256_init(&ctx);
253-
sha256_update(&ctx, message, len);
254-
sha256_final(&ctx, digest);
252+
acu_sha256_init(&ctx);
253+
acu_sha256_update(&ctx, message, len);
254+
acu_sha256_final(&ctx, digest);
255255
}
256256

257-
void sha256_init(sha256_ctx *ctx)
257+
void acu_sha256_init(acu_sha256_ctx *ctx)
258258
{
259259
#ifndef UNROLL_LOOPS
260260
int i;
@@ -272,7 +272,7 @@ void sha256_init(sha256_ctx *ctx)
272272
ctx->tot_len = 0;
273273
}
274274

275-
void sha256_update(sha256_ctx *ctx, const uint8_t *message, uint64_t len)
275+
void acu_sha256_update(acu_sha256_ctx *ctx, const uint8_t *message, uint64_t len)
276276
{
277277
uint64_t block_nb;
278278
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)
304304
ctx->tot_len += (block_nb + 1) << 6;
305305
}
306306

307-
void sha256_final(sha256_ctx *ctx, uint8_t *digest)
307+
void acu_sha256_final(acu_sha256_ctx *ctx, uint8_t *digest)
308308
{
309309
uint64_t block_nb;
310310
uint64_t pm_len;

src/sha256/sha2.h

+12-7
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@
3737
#include <stddef.h>
3838
#include <string.h>
3939

40-
#define SHA256_DIGEST_SIZE ( 256 / 8)
41-
#define SHA256_BLOCK_SIZE ( 512 / 8)
40+
#ifndef SHA256_DIGEST_SIZE
41+
#define SHA256_DIGEST_SIZE ( 256 / 8)
42+
#endif // SHA256_DIGEST_SIZE
43+
44+
#ifndef SHA256_BLOCK_SIZE
45+
#define SHA256_BLOCK_SIZE ( 512 / 8)
46+
#endif // SHA256_BLOCK_SIZE
4247

4348
#ifdef __cplusplus
4449
extern "C" {
@@ -49,12 +54,12 @@ typedef struct {
4954
uint64_t len;
5055
uint8_t block[2 * SHA256_BLOCK_SIZE];
5156
uint32_t h[8];
52-
} sha256_ctx;
57+
} acu_sha256_ctx;
5358

54-
void sha256_init(sha256_ctx * ctx);
55-
void sha256_update(sha256_ctx *ctx, const uint8_t *message, uint64_t len);
56-
void sha256_final(sha256_ctx *ctx, uint8_t *digest);
57-
void sha256(const uint8_t *message, uint64_t len, uint8_t *digest);
59+
void acu_sha256_init(acu_sha256_ctx * ctx);
60+
void acu_sha256_update(acu_sha256_ctx *ctx, const uint8_t *message, uint64_t len);
61+
void acu_sha256_final(acu_sha256_ctx *ctx, uint8_t *digest);
62+
void acu_sha256(const uint8_t *message, uint64_t len, uint8_t *digest);
5863

5964
#ifdef __cplusplus
6065
}

0 commit comments

Comments
 (0)