blob: 0bc255549e9eb5423b14af05c8584113f3e7b170 [file] [log] [blame]
Tom Joseph8c0446c2016-08-05 07:13:07 -05001#include "auth_algo.hpp"
2
Vernon Mauery9b307be2017-11-22 09:28:16 -08003#include <openssl/evp.h>
Tom Joseph8c0446c2016-08-05 07:13:07 -05004#include <openssl/hmac.h>
5#include <openssl/sha.h>
6
7#include <iostream>
8
9namespace cipher
10{
11
12namespace rakp_auth
13{
14
Vernon Mauery70fd29c2017-11-30 13:11:43 -080015std::vector<uint8_t> AlgoSHA1::generateHMAC(
16 const std::vector<uint8_t>& input) const
Tom Joseph8c0446c2016-08-05 07:13:07 -050017{
18 std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
19 unsigned int mdLen = 0;
20
21 if (HMAC(EVP_sha1(), userKey.data(), userKey.size(), input.data(),
22 input.size(), output.data(), &mdLen) == NULL)
23 {
24 std::cerr << "Generate HMAC failed\n";
25 output.resize(0);
26 }
27
28 return output;
29}
30
Vernon Mauery70fd29c2017-11-30 13:11:43 -080031std::vector<uint8_t> AlgoSHA1::generateICV(
32 const std::vector<uint8_t>& input) const
Tom Joseph8c0446c2016-08-05 07:13:07 -050033{
34 std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
35 unsigned int mdLen = 0;
36
37 if (HMAC(EVP_sha1(), sessionIntegrityKey.data(), SHA_DIGEST_LENGTH,
38 input.data(), input.size(), output.data(), &mdLen) == NULL)
39 {
40 std::cerr << "Generate Session Integrity Key failed\n";
41 output.resize(0);
42 }
Vernon Mauery2207f512017-11-30 10:48:08 -080043 output.resize(integrityCheckValueLength);
Tom Joseph8c0446c2016-08-05 07:13:07 -050044
45 return output;
46}
47
48} // namespace auth
49
50} // namespace cipher