blob: d2acebf1edef10029d16aee4dbd690afd9c072db [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
14std::vector<uint8_t> AlgoSHA1::generateHMAC(std::vector<uint8_t>& input) const
15{
16 std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
17 unsigned int mdLen = 0;
18
19 if (HMAC(EVP_sha1(), userKey.data(), userKey.size(), input.data(),
20 input.size(), output.data(), &mdLen) == NULL)
21 {
22 std::cerr << "Generate HMAC failed\n";
23 output.resize(0);
24 }
25
26 return output;
27}
28
29std::vector<uint8_t> AlgoSHA1::generateICV(std::vector<uint8_t>& input) const
30{
31 std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
32 unsigned int mdLen = 0;
33
34 if (HMAC(EVP_sha1(), sessionIntegrityKey.data(), SHA_DIGEST_LENGTH,
35 input.data(), input.size(), output.data(), &mdLen) == NULL)
36 {
37 std::cerr << "Generate Session Integrity Key failed\n";
38 output.resize(0);
39 }
40
41 return output;
42}
43
44} // namespace auth
45
46} // namespace cipher