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 | |
Tom Joseph | 56527b9 | 2018-03-21 19:31:58 +0530 | [diff] [blame] | 15 | const std::string userName = "admin"; |
| 16 | |
Vernon Mauery | 70fd29c | 2017-11-30 13:11:43 -0800 | [diff] [blame] | 17 | std::vector<uint8_t> AlgoSHA1::generateHMAC( |
| 18 | const std::vector<uint8_t>& input) const |
Tom Joseph | 8c0446c | 2016-08-05 07:13:07 -0500 | [diff] [blame] | 19 | { |
| 20 | std::vector<uint8_t> output(SHA_DIGEST_LENGTH); |
| 21 | unsigned int mdLen = 0; |
| 22 | |
| 23 | if (HMAC(EVP_sha1(), userKey.data(), userKey.size(), input.data(), |
| 24 | input.size(), output.data(), &mdLen) == NULL) |
| 25 | { |
| 26 | std::cerr << "Generate HMAC failed\n"; |
| 27 | output.resize(0); |
| 28 | } |
| 29 | |
| 30 | return output; |
| 31 | } |
| 32 | |
Vernon Mauery | 70fd29c | 2017-11-30 13:11:43 -0800 | [diff] [blame] | 33 | std::vector<uint8_t> AlgoSHA1::generateICV( |
| 34 | const std::vector<uint8_t>& input) const |
Tom Joseph | 8c0446c | 2016-08-05 07:13:07 -0500 | [diff] [blame] | 35 | { |
| 36 | std::vector<uint8_t> output(SHA_DIGEST_LENGTH); |
| 37 | unsigned int mdLen = 0; |
| 38 | |
| 39 | if (HMAC(EVP_sha1(), sessionIntegrityKey.data(), SHA_DIGEST_LENGTH, |
| 40 | input.data(), input.size(), output.data(), &mdLen) == NULL) |
| 41 | { |
| 42 | std::cerr << "Generate Session Integrity Key failed\n"; |
| 43 | output.resize(0); |
| 44 | } |
Vernon Mauery | 2207f51 | 2017-11-30 10:48:08 -0800 | [diff] [blame] | 45 | output.resize(integrityCheckValueLength); |
Tom Joseph | 8c0446c | 2016-08-05 07:13:07 -0500 | [diff] [blame] | 46 | |
| 47 | return output; |
| 48 | } |
| 49 | |
Vernon Mauery | 7e9e2ef | 2017-11-29 08:36:29 -0800 | [diff] [blame] | 50 | std::vector<uint8_t> AlgoSHA256::generateHMAC( |
| 51 | const std::vector<uint8_t>& input) const |
| 52 | { |
| 53 | std::vector<uint8_t> output(SHA256_DIGEST_LENGTH); |
| 54 | unsigned int mdLen = 0; |
| 55 | |
| 56 | if (HMAC(EVP_sha256(), userKey.data(), userKey.size(), input.data(), |
| 57 | input.size(), output.data(), &mdLen) == NULL) |
| 58 | { |
| 59 | std::cerr << "Generate HMAC_SHA256 failed\n"; |
| 60 | output.resize(0); |
| 61 | } |
| 62 | |
| 63 | return output; |
| 64 | } |
| 65 | |
| 66 | std::vector<uint8_t> AlgoSHA256::generateICV( |
| 67 | const std::vector<uint8_t>& input) const |
| 68 | { |
| 69 | std::vector<uint8_t> output(SHA256_DIGEST_LENGTH); |
| 70 | unsigned int mdLen = 0; |
| 71 | |
| 72 | if (HMAC(EVP_sha256(), |
| 73 | sessionIntegrityKey.data(), sessionIntegrityKey.size(), |
| 74 | input.data(), input.size(), output.data(), &mdLen) == NULL) |
| 75 | { |
| 76 | std::cerr << "Generate HMAC_SHA256_128 Integrity Check Value failed\n"; |
| 77 | output.resize(0); |
| 78 | } |
| 79 | output.resize(integrityCheckValueLength); |
| 80 | |
| 81 | return output; |
| 82 | } |
| 83 | |
Tom Joseph | 8c0446c | 2016-08-05 07:13:07 -0500 | [diff] [blame] | 84 | } // namespace auth |
| 85 | |
| 86 | } // namespace cipher |