Tom Joseph | 8c0446c | 2016-08-05 07:13:07 -0500 | [diff] [blame] | 1 | #include "auth_algo.hpp" |
| 2 | |
Vernon Mauery | 9b307be | 2017-11-22 09:28:16 -0800 | [diff] [blame^] | 3 | #include <openssl/evp.h> |
Tom Joseph | 8c0446c | 2016-08-05 07:13:07 -0500 | [diff] [blame] | 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 | |
Vernon Mauery | 70fd29c | 2017-11-30 13:11:43 -0800 | [diff] [blame] | 15 | std::vector<uint8_t> AlgoSHA1::generateHMAC( |
| 16 | const std::vector<uint8_t>& input) const |
Tom Joseph | 8c0446c | 2016-08-05 07:13:07 -0500 | [diff] [blame] | 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 | |
Vernon Mauery | 70fd29c | 2017-11-30 13:11:43 -0800 | [diff] [blame] | 31 | std::vector<uint8_t> AlgoSHA1::generateICV( |
| 32 | const std::vector<uint8_t>& input) const |
Tom Joseph | 8c0446c | 2016-08-05 07:13:07 -0500 | [diff] [blame] | 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 | } |
Vernon Mauery | 2207f51 | 2017-11-30 10:48:08 -0800 | [diff] [blame] | 43 | output.resize(integrityCheckValueLength); |
Tom Joseph | 8c0446c | 2016-08-05 07:13:07 -0500 | [diff] [blame] | 44 | |
| 45 | return output; |
| 46 | } |
| 47 | |
| 48 | } // namespace auth |
| 49 | |
| 50 | } // namespace cipher |