1 #include "auth_algo.hpp" 2 3 #include <error.h> 4 #include <openssl/evp.h> 5 #include <openssl/hmac.h> 6 #include <openssl/sha.h> 7 #include <string.h> 8 9 #include <phosphor-logging/lg2.hpp> 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 lg2::error("Generate HMAC failed: {ERROR}", "ERROR", strerror(errno)); 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 lg2::error("Generate Session Integrity Key failed: {ERROR}", "ERROR", 45 strerror(errno)); 46 output.resize(0); 47 } 48 output.resize(integrityCheckValueLength); 49 50 return output; 51 } 52 53 std::vector<uint8_t> 54 AlgoSHA256::generateHMAC(const std::vector<uint8_t>& input) const 55 { 56 std::vector<uint8_t> output(SHA256_DIGEST_LENGTH); 57 unsigned int mdLen = 0; 58 59 if (HMAC(EVP_sha256(), userKey.data(), userKey.size(), input.data(), 60 input.size(), output.data(), &mdLen) == NULL) 61 { 62 lg2::error("Generate HMAC_SHA256 failed: {ERROR}", "ERROR", 63 strerror(errno)); 64 output.resize(0); 65 } 66 67 return output; 68 } 69 70 std::vector<uint8_t> 71 AlgoSHA256::generateICV(const std::vector<uint8_t>& input) const 72 { 73 std::vector<uint8_t> output(SHA256_DIGEST_LENGTH); 74 unsigned int mdLen = 0; 75 76 if (HMAC(EVP_sha256(), sessionIntegrityKey.data(), 77 sessionIntegrityKey.size(), input.data(), input.size(), 78 output.data(), &mdLen) == NULL) 79 { 80 lg2::error( 81 "Generate HMAC_SHA256_128 Integrity Check Value failed: {ERROR}", 82 "ERROR", strerror(errno)); 83 output.resize(0); 84 } 85 output.resize(integrityCheckValueLength); 86 87 return output; 88 } 89 90 } // namespace rakp_auth 91 92 } // namespace cipher 93