summaryrefslogtreecommitdiffstats
path: root/auth_algo.cpp
blob: 4572831234f2e1be1bd5953aedf849196ddc82e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "auth_algo.hpp"

#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <openssl/sha.h>

#include <phosphor-logging/log.hpp>

using namespace phosphor::logging;

namespace cipher
{

namespace rakp_auth
{

const std::string userName = "admin";

std::vector<uint8_t>
    AlgoSHA1::generateHMAC(const std::vector<uint8_t>& input) const
{
    std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
    unsigned int mdLen = 0;

    if (HMAC(EVP_sha1(), userKey.data(), userKey.size(), input.data(),
             input.size(), output.data(), &mdLen) == NULL)
    {
        log<level::ERR>("Generate HMAC failed");
        output.resize(0);
    }

    return output;
}

std::vector<uint8_t>
    AlgoSHA1::generateICV(const std::vector<uint8_t>& input) const
{
    std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
    unsigned int mdLen = 0;

    if (HMAC(EVP_sha1(), sessionIntegrityKey.data(), SHA_DIGEST_LENGTH,
             input.data(), input.size(), output.data(), &mdLen) == NULL)
    {
        log<level::ERR>("Generate Session Integrity Key failed");
        output.resize(0);
    }
    output.resize(integrityCheckValueLength);

    return output;
}

std::vector<uint8_t>
    AlgoSHA256::generateHMAC(const std::vector<uint8_t>& input) const
{
    std::vector<uint8_t> output(SHA256_DIGEST_LENGTH);
    unsigned int mdLen = 0;

    if (HMAC(EVP_sha256(), userKey.data(), userKey.size(), input.data(),
             input.size(), output.data(), &mdLen) == NULL)
    {
        log<level::ERR>("Generate HMAC_SHA256 failed");
        output.resize(0);
    }

    return output;
}

std::vector<uint8_t>
    AlgoSHA256::generateICV(const std::vector<uint8_t>& input) const
{
    std::vector<uint8_t> output(SHA256_DIGEST_LENGTH);
    unsigned int mdLen = 0;

    if (HMAC(EVP_sha256(), sessionIntegrityKey.data(),
             sessionIntegrityKey.size(), input.data(), input.size(),
             output.data(), &mdLen) == NULL)
    {
        log<level::ERR>(
            "Generate HMAC_SHA256_128 Integrity Check Value failed");
        output.resize(0);
    }
    output.resize(integrityCheckValueLength);

    return output;
}

} // namespace rakp_auth

} // namespace cipher
OpenPOWER on IntegriCloud