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 | |
Vernon Mauery | 7e9e2ef | 2017-11-29 08:36:29 -0800 | [diff] [blame] | 48 | std::vector<uint8_t> AlgoSHA256::generateHMAC( |
| 49 | const std::vector<uint8_t>& input) const |
| 50 | { |
| 51 | std::vector<uint8_t> output(SHA256_DIGEST_LENGTH); |
| 52 | unsigned int mdLen = 0; |
| 53 | |
| 54 | if (HMAC(EVP_sha256(), userKey.data(), userKey.size(), input.data(), |
| 55 | input.size(), output.data(), &mdLen) == NULL) |
| 56 | { |
| 57 | std::cerr << "Generate HMAC_SHA256 failed\n"; |
| 58 | output.resize(0); |
| 59 | } |
| 60 | |
| 61 | return output; |
| 62 | } |
| 63 | |
| 64 | std::vector<uint8_t> AlgoSHA256::generateICV( |
| 65 | const std::vector<uint8_t>& input) const |
| 66 | { |
| 67 | std::vector<uint8_t> output(SHA256_DIGEST_LENGTH); |
| 68 | unsigned int mdLen = 0; |
| 69 | |
| 70 | if (HMAC(EVP_sha256(), |
| 71 | sessionIntegrityKey.data(), sessionIntegrityKey.size(), |
| 72 | input.data(), input.size(), output.data(), &mdLen) == NULL) |
| 73 | { |
| 74 | std::cerr << "Generate HMAC_SHA256_128 Integrity Check Value failed\n"; |
| 75 | output.resize(0); |
| 76 | } |
| 77 | output.resize(integrityCheckValueLength); |
| 78 | |
| 79 | return output; |
| 80 | } |
| 81 | |
Tom Joseph | 8c0446c | 2016-08-05 07:13:07 -0500 | [diff] [blame] | 82 | } // namespace auth |
| 83 | |
| 84 | } // namespace cipher |