Clean up code that generates session keys
This patch simply reworks the code to make it more understandable and
reduce if() branches.
It also avoids reallocs, and instead uses a support buffer to hold
intermediate results of the hmac function so that no buffer overrides
happen when the requested size is not an exact mutiple of the digest_len.
Signed-off-by: Simo Sorce <firstname.lastname@example.org>
Reviewed-by: Anderson Toshiyuki Sasaki <email@example.com>
Reviewed-by: Andreas Schneider <firstname.lastname@example.org>