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