blob: 94a8c914a0af8c22d3dfcc49ebd63b3bbb0118c9 [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
Vernon Mauery7e9e2ef2017-11-29 08:36:29 -080048std::vector<uint8_t> AlgoSHA256::generateHMAC(
49 const std::vector<uint8_t>& input) const
50{
51 std::vector<uint8_t> output(SHA256_DIGEST_LENGTH);
52 unsigned int mdLen = 0;
53
54 if (HMAC(EVP_sha256(), userKey.data(), userKey.size(), input.data(),
55 input.size(), output.data(), &mdLen) == NULL)
56 {
57 std::cerr << "Generate HMAC_SHA256 failed\n";
58 output.resize(0);
59 }
60
61 return output;
62}
63
64std::vector<uint8_t> AlgoSHA256::generateICV(
65 const std::vector<uint8_t>& input) const
66{
67 std::vector<uint8_t> output(SHA256_DIGEST_LENGTH);
68 unsigned int mdLen = 0;
69
70 if (HMAC(EVP_sha256(),
71 sessionIntegrityKey.data(), sessionIntegrityKey.size(),
72 input.data(), input.size(), output.data(), &mdLen) == NULL)
73 {
74 std::cerr << "Generate HMAC_SHA256_128 Integrity Check Value failed\n";
75 output.resize(0);
76 }
77 output.resize(integrityCheckValueLength);
78
79 return output;
80}
81
Tom Joseph8c0446c2016-08-05 07:13:07 -050082} // namespace auth
83
84} // namespace cipher