1 #include "auth_algo.hpp"
2 
3 #include <openssl/evp.h>
4 #include <openssl/hmac.h>
5 #include <openssl/sha.h>
6 
7 #include <phosphor-logging/log.hpp>
8 
9 using namespace phosphor::logging;
10 
11 namespace cipher
12 {
13 
14 namespace rakp_auth
15 {
16 
17 const std::string userName = "admin";
18 
19 std::vector<uint8_t>
20     AlgoSHA1::generateHMAC(const std::vector<uint8_t>& input) const
21 {
22     std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
23     unsigned int mdLen = 0;
24 
25     if (HMAC(EVP_sha1(), userKey.data(), userKey.size(), input.data(),
26              input.size(), output.data(), &mdLen) == NULL)
27     {
28         log<level::ERR>("Generate HMAC failed");
29         output.resize(0);
30     }
31 
32     return output;
33 }
34 
35 std::vector<uint8_t>
36     AlgoSHA1::generateICV(const std::vector<uint8_t>& input) const
37 {
38     std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
39     unsigned int mdLen = 0;
40 
41     if (HMAC(EVP_sha1(), sessionIntegrityKey.data(), SHA_DIGEST_LENGTH,
42              input.data(), input.size(), output.data(), &mdLen) == NULL)
43     {
44         log<level::ERR>("Generate Session Integrity Key failed");
45         output.resize(0);
46     }
47     output.resize(integrityCheckValueLength);
48 
49     return output;
50 }
51 
52 std::vector<uint8_t>
53     AlgoSHA256::generateHMAC(const std::vector<uint8_t>& input) const
54 {
55     std::vector<uint8_t> output(SHA256_DIGEST_LENGTH);
56     unsigned int mdLen = 0;
57 
58     if (HMAC(EVP_sha256(), userKey.data(), userKey.size(), input.data(),
59              input.size(), output.data(), &mdLen) == NULL)
60     {
61         log<level::ERR>("Generate HMAC_SHA256 failed");
62         output.resize(0);
63     }
64 
65     return output;
66 }
67 
68 std::vector<uint8_t>
69     AlgoSHA256::generateICV(const std::vector<uint8_t>& input) const
70 {
71     std::vector<uint8_t> output(SHA256_DIGEST_LENGTH);
72     unsigned int mdLen = 0;
73 
74     if (HMAC(EVP_sha256(), sessionIntegrityKey.data(),
75              sessionIntegrityKey.size(), input.data(), input.size(),
76              output.data(), &mdLen) == NULL)
77     {
78         log<level::ERR>(
79             "Generate HMAC_SHA256_128 Integrity Check Value failed");
80         output.resize(0);
81     }
82     output.resize(integrityCheckValueLength);
83 
84     return output;
85 }
86 
87 } // namespace rakp_auth
88 
89 } // namespace cipher
90