Commit 94f8644f authored by Niels Möller's avatar Niels Möller

Minor reorganization of hkdf_expand.

* hkdf.c (hkdf_expand): Eliminate a (signed) ssize_t variable, use
break rather than return at loop termination.
parent 89abb7b8
2017-09-06 Niels Möller <nisse@lysator.liu.se>
* hkdf.c (hkdf_expand): Eliminate a (signed) ssize_t variable, use
break rather than return at loop termination.
2017-09-06 Niels Möller <nisse@lysator.liu.se> 2017-09-06 Niels Möller <nisse@lysator.liu.se>
HKDF implementation, contributed by Nikos Mavrogiannopoulos. HKDF implementation, contributed by Nikos Mavrogiannopoulos.
......
...@@ -63,23 +63,20 @@ hkdf_expand(void *mac_ctx, ...@@ -63,23 +63,20 @@ hkdf_expand(void *mac_ctx,
size_t length, uint8_t *dst) size_t length, uint8_t *dst)
{ {
uint8_t i = 1; uint8_t i = 1;
ssize_t left = length;
if (!left) if (!length)
return; return;
for (;; dst += digest_size, left -= digest_size, i++) { for (;; dst += digest_size, length -= digest_size, i++)
update(mac_ctx, info_size, info); {
update(mac_ctx, 1, &i); update(mac_ctx, info_size, info);
if (left <= digest_size) { update(mac_ctx, 1, &i);
if (left > 0) if (length <= digest_size)
digest(mac_ctx, left, dst); break;
return;
}
digest(mac_ctx, digest_size, dst); digest(mac_ctx, digest_size, dst);
update(mac_ctx, digest_size, dst); update(mac_ctx, digest_size, dst);
} }
return; digest(mac_ctx, length, dst);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment