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.
pull/1737/head
Paul Sokolovsky 2015-12-20 16:57:57 +02:00
rodzic 664bc44f30
commit 1b7f622410
3 zmienionych plików z 12 dodań i 12 usunięć

Wyświetl plik

@ -41,7 +41,7 @@ static const WORD k[64] = {
};
/*********************** FUNCTION DEFINITIONS ***********************/
static void sha256_transform(SHA256_CTX *ctx, const BYTE data[])
static void sha256_transform(CRYAL_SHA256_CTX *ctx, const BYTE data[])
{
WORD a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];
@ -82,7 +82,7 @@ static void sha256_transform(SHA256_CTX *ctx, const BYTE data[])
ctx->state[7] += h;
}
void sha256_init(SHA256_CTX *ctx)
void sha256_init(CRYAL_SHA256_CTX *ctx)
{
ctx->datalen = 0;
ctx->bitlen = 0;
@ -96,7 +96,7 @@ void sha256_init(SHA256_CTX *ctx)
ctx->state[7] = 0x5be0cd19;
}
void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len)
void sha256_update(CRYAL_SHA256_CTX *ctx, const BYTE data[], size_t len)
{
WORD i;
@ -111,7 +111,7 @@ void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len)
}
}
void sha256_final(SHA256_CTX *ctx, BYTE hash[])
void sha256_final(CRYAL_SHA256_CTX *ctx, BYTE hash[])
{
WORD i;

Wyświetl plik

@ -24,11 +24,11 @@ typedef struct {
WORD datalen;
unsigned long long bitlen;
WORD state[8];
} SHA256_CTX;
} CRYAL_SHA256_CTX;
/*********************** FUNCTION DECLARATIONS **********************/
void sha256_init(SHA256_CTX *ctx);
void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len);
void sha256_final(SHA256_CTX *ctx, BYTE hash[]);
void sha256_init(CRYAL_SHA256_CTX *ctx);
void sha256_update(CRYAL_SHA256_CTX *ctx, const BYTE data[], size_t len);
void sha256_final(CRYAL_SHA256_CTX *ctx, BYTE hash[]);
#endif // SHA256_H

Wyświetl plik

@ -43,9 +43,9 @@ STATIC mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg);
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) {
mp_arg_check_num(n_args, n_kw, 0, 1, false);
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(SHA256_CTX));
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX));
o->base.type = MP_OBJ_TO_PTR(type_in);
sha256_init((SHA256_CTX*)o->state);
sha256_init((CRYAL_SHA256_CTX*)o->state);
if (n_args == 1) {
hash_update(MP_OBJ_FROM_PTR(o), args[0]);
}
@ -56,7 +56,7 @@ STATIC mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg) {
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
sha256_update((SHA256_CTX*)self->state, bufinfo.buf, bufinfo.len);
sha256_update((CRYAL_SHA256_CTX*)self->state, bufinfo.buf, bufinfo.len);
return mp_const_none;
}
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) {
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
vstr_t vstr;
vstr_init_len(&vstr, SHA256_BLOCK_SIZE);
sha256_final((SHA256_CTX*)self->state, (byte*)vstr.buf);
sha256_final((CRYAL_SHA256_CTX*)self->state, (byte*)vstr.buf);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
MP_DEFINE_CONST_FUN_OBJ_1(hash_digest_obj, hash_digest);