summaryrefslogtreecommitdiffstats
path: root/src/hkdf_sha256.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-11-29 05:33:12 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-11-29 05:35:49 +0100
commit61349d3d273aa23935b0c413c5885005db2669db (patch)
tree9cbc05acb31476d45b48d4a51e9edca19328b8e8 /src/hkdf_sha256.c
parentc13fe36e4c0730037ae75d51f7f052d916486aac (diff)
downloadfastd-61349d3d273aa23935b0c413c5885005db2669db.tar
fastd-61349d3d273aa23935b0c413c5885005db2669db.zip
Compile with -std=c99 and restructure some code to ensure there is no invalid aliasing (hopefully)
Diffstat (limited to 'src/hkdf_sha256.c')
-rw-r--r--src/hkdf_sha256.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/hkdf_sha256.c b/src/hkdf_sha256.c
index 8d04ae0..26568f9 100644
--- a/src/hkdf_sha256.c
+++ b/src/hkdf_sha256.c
@@ -34,20 +34,19 @@ void fastd_hkdf_sha256_expand(fastd_sha256_t *out, size_t blocks, fastd_sha256_t
return;
size_t len = sizeof(fastd_sha256_t) + infolen + 1;
+ uint32_t buf[(len+3)/4];
- uint8_t buf[len] __attribute__((aligned(4)));
+ memset(buf, 0, FASTD_SHA256_HASH_BYTES);
+ memcpy(buf+FASTD_SHA256_HASH_WORDS, info, infolen);
+ ((uint8_t*)buf)[len-1] = 0x01;
- memset(buf, 0, sizeof(fastd_sha256_t));
- memcpy(buf+sizeof(fastd_sha256_t), info, infolen);
- buf[len-1] = 0x01;
-
- fastd_hmacsha256(out, prk->w, (uint32_t*)(buf+sizeof(fastd_sha256_t)), infolen + 1);
+ fastd_hmacsha256(out, prk->w, buf+FASTD_SHA256_HASH_WORDS, infolen + 1);
while (--blocks) {
- memcpy(buf, out, sizeof(fastd_sha256_t));
+ memcpy(buf, out, FASTD_SHA256_HASH_BYTES);
out++;
- buf[len-1]++;
+ ((uint8_t*)buf)[len-1]++;
- fastd_hmacsha256(out, prk->w, (uint32_t*)buf, len);
+ fastd_hmacsha256(out, prk->w, buf, len);
}
}