From cb8c15a231a9a8e49d6654a7d599fe9152159ae8 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Sat, 13 Jul 2019 17:59:42 +0200 Subject: SHA512 challenge response authentication Signed-off-by: Toni Uhlig --- src/challenge.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/challenge.c') diff --git a/src/challenge.c b/src/challenge.c index f0b02ad..d12beea 100644 --- a/src/challenge.c +++ b/src/challenge.c @@ -109,13 +109,27 @@ int validate_challenge_md5(challenge_t *local, challenge_digest_t *remote) { } #ifdef ENABLE_SHA512 -void generate_response_sha512(challenge_t *challenge) +void generate_response_sha512(challenge_plain_t *plain, challenge_digest_t *digest) { - /* TODO: Implement me! */ + unsigned char buf[sizeof(*plain) + kSHA512_digest_size]; + + digest->hash_type = HT_SHA512; + memcpy(buf, plain, sizeof(*plain)); + memcpy(&buf[sizeof(*plain)], opts.sha512_password_digest, kSHA512_digest_size); + memset(plain, 0, sizeof(*plain)); + + SHA512(buf, sizeof(*plain) + kSHA512_digest_size, &digest->sha512[0]); } -int validate_challenge_sha512(challenge_t *local, challenge_t *remote) +int validate_challenge_sha512(challenge_t *local, challenge_digest_t *remote) { - /* TODO: Implement me! */ + generate_response_sha512(&local->plain, &local->digest); + + if (remote->hash_type == HT_SHA512 && + memcmp(&local->digest.sha512[0], &remote->sha512[0], sizeof(local->digest.sha512)) == 0) + { + return 1; + } + return 0; } #endif /* ENABLE_SHA512 */ -- cgit v1.2.3