Skip to content

Commit 1b7f622

Browse files
committed
extmod/moduhashlib: Add namespace prefix for crypto-algorithms/sha256.h.
Everyone loves to names similar things the same, then there're conflicts between different libraries. The namespace prefix used is "CRYAL_", which is weird, and that's good, as that minimizes chance of another conflict.
1 parent 664bc44 commit 1b7f622

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

extmod/crypto-algorithms/sha256.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static const WORD k[64] = {
4141
};
4242

4343
/*********************** FUNCTION DEFINITIONS ***********************/
44-
static void sha256_transform(SHA256_CTX *ctx, const BYTE data[])
44+
static void sha256_transform(CRYAL_SHA256_CTX *ctx, const BYTE data[])
4545
{
4646
WORD a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];
4747

@@ -82,7 +82,7 @@ static void sha256_transform(SHA256_CTX *ctx, const BYTE data[])
8282
ctx->state[7] += h;
8383
}
8484

85-
void sha256_init(SHA256_CTX *ctx)
85+
void sha256_init(CRYAL_SHA256_CTX *ctx)
8686
{
8787
ctx->datalen = 0;
8888
ctx->bitlen = 0;
@@ -96,7 +96,7 @@ void sha256_init(SHA256_CTX *ctx)
9696
ctx->state[7] = 0x5be0cd19;
9797
}
9898

99-
void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len)
99+
void sha256_update(CRYAL_SHA256_CTX *ctx, const BYTE data[], size_t len)
100100
{
101101
WORD i;
102102

@@ -111,7 +111,7 @@ void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len)
111111
}
112112
}
113113

114-
void sha256_final(SHA256_CTX *ctx, BYTE hash[])
114+
void sha256_final(CRYAL_SHA256_CTX *ctx, BYTE hash[])
115115
{
116116
WORD i;
117117

extmod/crypto-algorithms/sha256.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ typedef struct {
2424
WORD datalen;
2525
unsigned long long bitlen;
2626
WORD state[8];
27-
} SHA256_CTX;
27+
} CRYAL_SHA256_CTX;
2828

2929
/*********************** FUNCTION DECLARATIONS **********************/
30-
void sha256_init(SHA256_CTX *ctx);
31-
void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len);
32-
void sha256_final(SHA256_CTX *ctx, BYTE hash[]);
30+
void sha256_init(CRYAL_SHA256_CTX *ctx);
31+
void sha256_update(CRYAL_SHA256_CTX *ctx, const BYTE data[], size_t len);
32+
void sha256_final(CRYAL_SHA256_CTX *ctx, BYTE hash[]);
3333

3434
#endif // SHA256_H

extmod/moduhashlib.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ STATIC mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg);
4343

4444
STATIC mp_obj_t hash_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
4545
mp_arg_check_num(n_args, n_kw, 0, 1, false);
46-
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(SHA256_CTX));
46+
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX));
4747
o->base.type = MP_OBJ_TO_PTR(type_in);
48-
sha256_init((SHA256_CTX*)o->state);
48+
sha256_init((CRYAL_SHA256_CTX*)o->state);
4949
if (n_args == 1) {
5050
hash_update(MP_OBJ_FROM_PTR(o), args[0]);
5151
}
@@ -56,7 +56,7 @@ STATIC mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg) {
5656
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
5757
mp_buffer_info_t bufinfo;
5858
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
59-
sha256_update((SHA256_CTX*)self->state, bufinfo.buf, bufinfo.len);
59+
sha256_update((CRYAL_SHA256_CTX*)self->state, bufinfo.buf, bufinfo.len);
6060
return mp_const_none;
6161
}
6262
MP_DEFINE_CONST_FUN_OBJ_2(hash_update_obj, hash_update);
@@ -65,7 +65,7 @@ STATIC mp_obj_t hash_digest(mp_obj_t self_in) {
6565
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
6666
vstr_t vstr;
6767
vstr_init_len(&vstr, SHA256_BLOCK_SIZE);
68-
sha256_final((SHA256_CTX*)self->state, (byte*)vstr.buf);
68+
sha256_final((CRYAL_SHA256_CTX*)self->state, (byte*)vstr.buf);
6969
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
7070
}
7171
MP_DEFINE_CONST_FUN_OBJ_1(hash_digest_obj, hash_digest);

0 commit comments

Comments
 (0)