1 #include "auth_algo.hpp" 2 3 #include <openssl/hmac.h> 4 #include <openssl/sha.h> 5 6 #include <iostream> 7 8 namespace cipher 9 { 10 11 namespace rakp_auth 12 { 13 14 std::vector<uint8_t> AlgoSHA1::generateHMAC( 15 const std::vector<uint8_t>& input) const 16 { 17 std::vector<uint8_t> output(SHA_DIGEST_LENGTH); 18 unsigned int mdLen = 0; 19 20 if (HMAC(EVP_sha1(), userKey.data(), userKey.size(), input.data(), 21 input.size(), output.data(), &mdLen) == NULL) 22 { 23 std::cerr << "Generate HMAC failed\n"; 24 output.resize(0); 25 } 26 27 return output; 28 } 29 30 std::vector<uint8_t> AlgoSHA1::generateICV( 31 const std::vector<uint8_t>& input) const 32 { 33 std::vector<uint8_t> output(SHA_DIGEST_LENGTH); 34 unsigned int mdLen = 0; 35 36 if (HMAC(EVP_sha1(), sessionIntegrityKey.data(), SHA_DIGEST_LENGTH, 37 input.data(), input.size(), output.data(), &mdLen) == NULL) 38 { 39 std::cerr << "Generate Session Integrity Key failed\n"; 40 output.resize(0); 41 } 42 output.resize(integrityCheckValueLength); 43 44 return output; 45 } 46 47 } // namespace auth 48 49 } // namespace cipher 50