blob: 4572831234f2e1be1bd5953aedf849196ddc82e8 [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
Vernon Maueryfc37e592018-12-19 14:55:15 -08007#include <phosphor-logging/log.hpp>
8
9using namespace phosphor::logging;
Tom Joseph8c0446c2016-08-05 07:13:07 -050010
11namespace cipher
12{
13
14namespace rakp_auth
15{
16
Tom Joseph56527b92018-03-21 19:31:58 +053017const std::string userName = "admin";
18
Vernon Mauery9e801a22018-10-12 13:20:49 -070019std::vector<uint8_t>
20 AlgoSHA1::generateHMAC(const std::vector<uint8_t>& input) const
Tom Joseph8c0446c2016-08-05 07:13:07 -050021{
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 {
Vernon Maueryfc37e592018-12-19 14:55:15 -080028 log<level::ERR>("Generate HMAC failed");
Tom Joseph8c0446c2016-08-05 07:13:07 -050029 output.resize(0);
30 }
31
32 return output;
33}
34
Vernon Mauery9e801a22018-10-12 13:20:49 -070035std::vector<uint8_t>
36 AlgoSHA1::generateICV(const std::vector<uint8_t>& input) const
Tom Joseph8c0446c2016-08-05 07:13:07 -050037{
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 {
Vernon Maueryfc37e592018-12-19 14:55:15 -080044 log<level::ERR>("Generate Session Integrity Key failed");
Tom Joseph8c0446c2016-08-05 07:13:07 -050045 output.resize(0);
46 }
Vernon Mauery2207f512017-11-30 10:48:08 -080047 output.resize(integrityCheckValueLength);
Tom Joseph8c0446c2016-08-05 07:13:07 -050048
49 return output;
50}
51
Vernon Mauery9e801a22018-10-12 13:20:49 -070052std::vector<uint8_t>
53 AlgoSHA256::generateHMAC(const std::vector<uint8_t>& input) const
Vernon Mauery7e9e2ef2017-11-29 08:36:29 -080054{
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 {
Vernon Maueryfc37e592018-12-19 14:55:15 -080061 log<level::ERR>("Generate HMAC_SHA256 failed");
Vernon Mauery7e9e2ef2017-11-29 08:36:29 -080062 output.resize(0);
63 }
64
65 return output;
66}
67
Vernon Mauery9e801a22018-10-12 13:20:49 -070068std::vector<uint8_t>
69 AlgoSHA256::generateICV(const std::vector<uint8_t>& input) const
Vernon Mauery7e9e2ef2017-11-29 08:36:29 -080070{
71 std::vector<uint8_t> output(SHA256_DIGEST_LENGTH);
72 unsigned int mdLen = 0;
73
Vernon Mauery9e801a22018-10-12 13:20:49 -070074 if (HMAC(EVP_sha256(), sessionIntegrityKey.data(),
75 sessionIntegrityKey.size(), input.data(), input.size(),
76 output.data(), &mdLen) == NULL)
Vernon Mauery7e9e2ef2017-11-29 08:36:29 -080077 {
Vernon Maueryfc37e592018-12-19 14:55:15 -080078 log<level::ERR>(
79 "Generate HMAC_SHA256_128 Integrity Check Value failed");
Vernon Mauery7e9e2ef2017-11-29 08:36:29 -080080 output.resize(0);
81 }
82 output.resize(integrityCheckValueLength);
83
84 return output;
85}
86
Vernon Mauery9e801a22018-10-12 13:20:49 -070087} // namespace rakp_auth
Tom Joseph8c0446c2016-08-05 07:13:07 -050088
89} // namespace cipher