blob: f062b0f3ad63a1916f6fc3b744da872e270a20ff [file] [log] [blame]
Tom Joseph8c0446c2016-08-05 07:13:07 -05001#include "auth_algo.hpp"
2
3#include <openssl/hmac.h>
4#include <openssl/sha.h>
5
6#include <iostream>
7
8namespace cipher
9{
10
11namespace rakp_auth
12{
13
Vernon Mauery70fd29c2017-11-30 13:11:43 -080014std::vector<uint8_t> AlgoSHA1::generateHMAC(
15 const std::vector<uint8_t>& input) const
Tom Joseph8c0446c2016-08-05 07:13:07 -050016{
17 std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
18 unsigned int mdLen = 0;
19
20 if (HMAC(EVP_sha1(), userKey.data(), userKey.size(), input.data(),
21 input.size(), output.data(), &mdLen) == NULL)
22 {
23 std::cerr << "Generate HMAC failed\n";
24 output.resize(0);
25 }
26
27 return output;
28}
29
Vernon Mauery70fd29c2017-11-30 13:11:43 -080030std::vector<uint8_t> AlgoSHA1::generateICV(
31 const std::vector<uint8_t>& input) const
Tom Joseph8c0446c2016-08-05 07:13:07 -050032{
33 std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
34 unsigned int mdLen = 0;
35
36 if (HMAC(EVP_sha1(), sessionIntegrityKey.data(), SHA_DIGEST_LENGTH,
37 input.data(), input.size(), output.data(), &mdLen) == NULL)
38 {
39 std::cerr << "Generate Session Integrity Key failed\n";
40 output.resize(0);
41 }
Vernon Mauery2207f512017-11-30 10:48:08 -080042 output.resize(integrityCheckValueLength);
Tom Joseph8c0446c2016-08-05 07:13:07 -050043
44 return output;
45}
46
47} // namespace auth
48
49} // namespace cipher