blob: b658d6ab6b02d239d4a6579c5b995686ccdbd546 [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
Tom Joseph56527b92018-03-21 19:31:58 +053015const std::string userName = "admin";
16
Vernon Mauery70fd29c2017-11-30 13:11:43 -080017std::vector<uint8_t> AlgoSHA1::generateHMAC(
18 const std::vector<uint8_t>& input) const
Tom Joseph8c0446c2016-08-05 07:13:07 -050019{
20 std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
21 unsigned int mdLen = 0;
22
23 if (HMAC(EVP_sha1(), userKey.data(), userKey.size(), input.data(),
24 input.size(), output.data(), &mdLen) == NULL)
25 {
26 std::cerr << "Generate HMAC failed\n";
27 output.resize(0);
28 }
29
30 return output;
31}
32
Vernon Mauery70fd29c2017-11-30 13:11:43 -080033std::vector<uint8_t> AlgoSHA1::generateICV(
34 const std::vector<uint8_t>& input) const
Tom Joseph8c0446c2016-08-05 07:13:07 -050035{
36 std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
37 unsigned int mdLen = 0;
38
39 if (HMAC(EVP_sha1(), sessionIntegrityKey.data(), SHA_DIGEST_LENGTH,
40 input.data(), input.size(), output.data(), &mdLen) == NULL)
41 {
42 std::cerr << "Generate Session Integrity Key failed\n";
43 output.resize(0);
44 }
Vernon Mauery2207f512017-11-30 10:48:08 -080045 output.resize(integrityCheckValueLength);
Tom Joseph8c0446c2016-08-05 07:13:07 -050046
47 return output;
48}
49
Vernon Mauery7e9e2ef2017-11-29 08:36:29 -080050std::vector<uint8_t> AlgoSHA256::generateHMAC(
51 const std::vector<uint8_t>& input) const
52{
53 std::vector<uint8_t> output(SHA256_DIGEST_LENGTH);
54 unsigned int mdLen = 0;
55
56 if (HMAC(EVP_sha256(), userKey.data(), userKey.size(), input.data(),
57 input.size(), output.data(), &mdLen) == NULL)
58 {
59 std::cerr << "Generate HMAC_SHA256 failed\n";
60 output.resize(0);
61 }
62
63 return output;
64}
65
66std::vector<uint8_t> AlgoSHA256::generateICV(
67 const std::vector<uint8_t>& input) const
68{
69 std::vector<uint8_t> output(SHA256_DIGEST_LENGTH);
70 unsigned int mdLen = 0;
71
72 if (HMAC(EVP_sha256(),
73 sessionIntegrityKey.data(), sessionIntegrityKey.size(),
74 input.data(), input.size(), output.data(), &mdLen) == NULL)
75 {
76 std::cerr << "Generate HMAC_SHA256_128 Integrity Check Value failed\n";
77 output.resize(0);
78 }
79 output.resize(integrityCheckValueLength);
80
81 return output;
82}
83
Tom Joseph8c0446c2016-08-05 07:13:07 -050084} // namespace auth
85
86} // namespace cipher