From: rasky Date: Thu, 30 Sep 2010 12:00:18 +0000 (+0000) Subject: Fix coding convention for HMAC module. X-Git-Tag: 2.6.0~21 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=9f24779338003c85f83e64b9dcc7aa2a430ca8ff;p=bertos.git Fix coding convention for HMAC module. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4380 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/sec/mac/hmac.c b/bertos/sec/mac/hmac.c index bbedca5e..7e077e94 100644 --- a/bertos/sec/mac/hmac.c +++ b/bertos/sec/mac/hmac.c @@ -40,9 +40,9 @@ #include -static void HMAC_set_key(Mac *m, const void *key, size_t key_len) +static void hmac_set_key(Mac *m, const void *key, size_t key_len) { - HMAC_Context *ctx = (HMAC_Context *)m; + HmacContext *ctx = (HmacContext *)m; memset(ctx->key, 0, ctx->m.key_len); if (key_len <= ctx->m.key_len) @@ -57,9 +57,9 @@ static void HMAC_set_key(Mac *m, const void *key, size_t key_len) xor_block_const(ctx->key, ctx->key, 0x5C, ctx->m.key_len); } -static void HMAC_begin(Mac *m) +static void hmac_begin(Mac *m) { - HMAC_Context *ctx = (HMAC_Context *)m; + HmacContext *ctx = (HmacContext *)m; int klen = ctx->m.key_len; xor_block_const(ctx->key, ctx->key, 0x36^0x5C, klen); @@ -67,15 +67,15 @@ static void HMAC_begin(Mac *m) hash_update(ctx->h, ctx->key, klen); } -static void HMAC_update(Mac *m, const void *data, size_t len) +static void hmac_update(Mac *m, const void *data, size_t len) { - HMAC_Context *ctx = (HMAC_Context *)m; + HmacContext *ctx = (HmacContext *)m; hash_update(ctx->h, data, len); } -static uint8_t *HMAC_final(Mac *m) +static uint8_t *hmac_final(Mac *m) { - HMAC_Context *ctx = (HMAC_Context *)m; + HmacContext *ctx = (HmacContext *)m; int hlen = hash_digest_len(ctx->h); uint8_t temp[hlen]; @@ -92,14 +92,14 @@ static uint8_t *HMAC_final(Mac *m) /*********************************************************************/ -void HMAC_init(HMAC_Context *ctx, Hash *h) +void hmac_init(HmacContext *ctx, Hash *h) { ctx->h = h; ctx->m.key_len = hash_block_len(h); ctx->m.digest_len = hash_digest_len(h); - ctx->m.set_key = HMAC_set_key; - ctx->m.begin = HMAC_begin; - ctx->m.update = HMAC_update; - ctx->m.final = HMAC_final; + ctx->m.set_key = hmac_set_key; + ctx->m.begin = hmac_begin; + ctx->m.update = hmac_update; + ctx->m.final = hmac_final; ASSERT(sizeof(ctx->key) >= ctx->m.key_len); } diff --git a/bertos/sec/mac/hmac.h b/bertos/sec/mac/hmac.h index 88de9fab..038c4575 100644 --- a/bertos/sec/mac/hmac.h +++ b/bertos/sec/mac/hmac.h @@ -32,7 +32,7 @@ * * \brief HMAC (RFC 2104) implementation * \author Giovanni Bajo - * + * */ #ifndef SEC_MAC_HMAC_H @@ -42,20 +42,20 @@ #include #include -typedef struct HMAC_Context +typedef struct HmacContext { Mac m; - Hash *h; + Hash *h; uint8_t key[64]; -} HMAC_Context; +} HmacContext; -void HMAC_init(HMAC_Context* hmac, Hash *h); +void hmac_init(HmacContext* hmac, Hash *h); -#define HMAC_stackinit(...) \ - ({ HMAC_Context *ctx = alloca(sizeof(HMAC_Context)); HMAC_init(ctx, ##__VA_ARGS__); &ctx->m; }) +#define hmac_stackinit(...) \ + ({ HmacContext *ctx = alloca(sizeof(HmacContext)); hmac_init(ctx, ##__VA_ARGS__); &ctx->m; }) -int HMAC_testSetup(void); -int HMAC_testRun(void); -int HMAC_testTearDown(void); +int hmac_testSetup(void); +int hmac_testRun(void); +int hmac_testTearDown(void); #endif /* SEC_MAC_HMAC_H */ diff --git a/bertos/sec/mac/hmac_test.c b/bertos/sec/mac/hmac_test.c index 29b6620e..a5edc460 100644 --- a/bertos/sec/mac/hmac_test.c +++ b/bertos/sec/mac/hmac_test.c @@ -1,18 +1,18 @@ -#include +#include "hmac.h" #include #include #include #include #include -int HMAC_testSetup(void) +int hmac_testSetup(void) { kdbg_init(); return 0; } -int HMAC_testTearDown(void) +int hmac_testTearDown(void) { return 0; } @@ -28,13 +28,13 @@ struct Test_HMAC const struct Test_HMAC tests_hmac_md5[] = { - { + { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 16, "Hi There", 8, "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d", }, { - "Jefe", 4, + "Jefe", 4, "what do ya want for nothing?", 28, "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38", }, @@ -100,7 +100,7 @@ const struct Test_HMAC tests_hmac_sha1[] = "Jefe", 4, "what do ya want for nothing?", 28, "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79", - }, + }, { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20, "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd" @@ -162,13 +162,15 @@ static void algo_run_tests(Mac *mac, const struct Test_HMAC *t, int count) } } -int HMAC_testRun(void) +int hmac_testRun(void) { - algo_run_tests(HMAC_stackinit(MD5_stackinit()), + algo_run_tests(hmac_stackinit(MD5_stackinit()), tests_hmac_md5, countof(tests_hmac_md5)); - algo_run_tests(HMAC_stackinit(SHA1_stackinit()), + algo_run_tests(hmac_stackinit(SHA1_stackinit()), tests_hmac_sha1, countof(tests_hmac_sha1)); + + return 0; } TEST_MAIN(HMAC); diff --git a/bertos/sec/util.c b/bertos/sec/util.c index b5982b38..7af6cdbe 100644 --- a/bertos/sec/util.c +++ b/bertos/sec/util.c @@ -32,7 +32,7 @@ * * \brief Generic utilities. * \author Giovanni Bajo - * + * */ #include "util.h" @@ -48,10 +48,10 @@ void password2key(const char *pwd, size_t pwd_len, uint8_t *key, size_t key_len) { - Kdf *kdf = PBKDF2_stackinit(HMAC_stackinit(SHA1_stackinit())); - + Kdf *kdf = PBKDF2_stackinit(hmac_stackinit(SHA1_stackinit())); + kdf_begin(kdf, pwd, pwd_len, (uint8_t*)SALT, sizeof(SALT)); kdf_read(kdf, key, key_len); - + // FIXME: how to purge the stack? }