Tom Joseph | 8c0446c | 2016-08-05 07:13:07 -0500 | [diff] [blame] | 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(std::vector<uint8_t>& input) const |
| 15 | { |
| 16 | std::vector<uint8_t> output(SHA_DIGEST_LENGTH); |
| 17 | unsigned int mdLen = 0; |
| 18 | |
| 19 | if (HMAC(EVP_sha1(), userKey.data(), userKey.size(), input.data(), |
| 20 | input.size(), output.data(), &mdLen) == NULL) |
| 21 | { |
| 22 | std::cerr << "Generate HMAC failed\n"; |
| 23 | output.resize(0); |
| 24 | } |
| 25 | |
| 26 | return output; |
| 27 | } |
| 28 | |
| 29 | std::vector<uint8_t> AlgoSHA1::generateICV(std::vector<uint8_t>& input) const |
| 30 | { |
| 31 | std::vector<uint8_t> output(SHA_DIGEST_LENGTH); |
| 32 | unsigned int mdLen = 0; |
| 33 | |
| 34 | if (HMAC(EVP_sha1(), sessionIntegrityKey.data(), SHA_DIGEST_LENGTH, |
| 35 | input.data(), input.size(), output.data(), &mdLen) == NULL) |
| 36 | { |
| 37 | std::cerr << "Generate Session Integrity Key failed\n"; |
| 38 | output.resize(0); |
| 39 | } |
Vernon Mauery | 2207f51 | 2017-11-30 10:48:08 -0800 | [diff] [blame^] | 40 | output.resize(integrityCheckValueLength); |
Tom Joseph | 8c0446c | 2016-08-05 07:13:07 -0500 | [diff] [blame] | 41 | |
| 42 | return output; |
| 43 | } |
| 44 | |
| 45 | } // namespace auth |
| 46 | |
| 47 | } // namespace cipher |