blob: 55df86d5eae515e70e2e9b9c341296b12ac70374 [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 Mauery9e801a22018-10-12 13:20:49 -070017std::vector<uint8_t>
18 AlgoSHA1::generateHMAC(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 Mauery9e801a22018-10-12 13:20:49 -070033std::vector<uint8_t>
34 AlgoSHA1::generateICV(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 Mauery9e801a22018-10-12 13:20:49 -070050std::vector<uint8_t>
51 AlgoSHA256::generateHMAC(const std::vector<uint8_t>& input) const
Vernon Mauery7e9e2ef2017-11-29 08:36:29 -080052{
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
Vernon Mauery9e801a22018-10-12 13:20:49 -070066std::vector<uint8_t>
67 AlgoSHA256::generateICV(const std::vector<uint8_t>& input) const
Vernon Mauery7e9e2ef2017-11-29 08:36:29 -080068{
69 std::vector<uint8_t> output(SHA256_DIGEST_LENGTH);
70 unsigned int mdLen = 0;
71
Vernon Mauery9e801a22018-10-12 13:20:49 -070072 if (HMAC(EVP_sha256(), sessionIntegrityKey.data(),
73 sessionIntegrityKey.size(), input.data(), input.size(),
74 output.data(), &mdLen) == NULL)
Vernon Mauery7e9e2ef2017-11-29 08:36:29 -080075 {
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
Vernon Mauery9e801a22018-10-12 13:20:49 -070084} // namespace rakp_auth
Tom Joseph8c0446c2016-08-05 07:13:07 -050085
86} // namespace cipher