| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/crypto/crypto.h" |
| 34 |
#include "core/crypto/hashing_context.h" |
| 35 |
|
| 36 |
#include "tests/test_macros.h" |
| 37 |
#include "tests/test_utils.h" |
| 38 |
|
| 39 |
namespace TestCryptoMbedTLS { |
| 40 |
|
| 41 |
void hmac_digest_test(HashingContext::HashType ht, String expected_hex); |
| 42 |
|
| 43 |
TEST_CASE("[CryptoMbedTLS] HMAC digest") { |
| 44 |
|
| 45 |
hmac_digest_test(HashingContext::HashType::HASH_SHA256, "fe442023f8a7d36a810e1e7cd8a8e2816457f350a008fbf638296afa12085e59"); |
| 46 |
|
| 47 |
|
| 48 |
hmac_digest_test(HashingContext::HashType::HASH_SHA1, "a0ac4cd68a2f4812c355983d94e8d025afe7dddf"); |
| 49 |
} |
| 50 |
|
| 51 |
void hmac_context_digest_test(HashingContext::HashType ht, String expected_hex); |
| 52 |
|
| 53 |
TEST_CASE("[HMACContext] HMAC digest") { |
| 54 |
|
| 55 |
hmac_context_digest_test(HashingContext::HashType::HASH_SHA256, "fe442023f8a7d36a810e1e7cd8a8e2816457f350a008fbf638296afa12085e59"); |
| 56 |
|
| 57 |
|
| 58 |
hmac_context_digest_test(HashingContext::HashType::HASH_SHA1, "a0ac4cd68a2f4812c355983d94e8d025afe7dddf"); |
| 59 |
} |
| 60 |
|
| 61 |
void crypto_key_public_only_test(const String &p_key_path, bool public_only); |
| 62 |
|
| 63 |
TEST_CASE("[Crypto] CryptoKey is_public_only") { |
| 64 |
crypto_key_public_only_test(TestUtils::get_data_path("crypto/in.key"), false); |
| 65 |
crypto_key_public_only_test(TestUtils::get_data_path("crypto/in.pub"), true); |
| 66 |
} |
| 67 |
|
| 68 |
void crypto_key_save_test(const String &p_in_path, const String &p_out_path, bool public_only); |
| 69 |
|
| 70 |
TEST_CASE("[Crypto] CryptoKey save") { |
| 71 |
const String in_priv_path = TestUtils::get_data_path("crypto/in.key"); |
| 72 |
const String out_priv_path = TestUtils::get_data_path("crypto/out.key"); |
| 73 |
crypto_key_save_test(in_priv_path, out_priv_path, false); |
| 74 |
|
| 75 |
const String in_pub_path = TestUtils::get_data_path("crypto/in.pub"); |
| 76 |
const String out_pub_path = TestUtils::get_data_path("crypto/out.pub"); |
| 77 |
crypto_key_save_test(in_pub_path, out_pub_path, true); |
| 78 |
} |
| 79 |
|
| 80 |
void crypto_key_save_public_only_test(const String &p_in_priv_path, const String &p_in_pub_path, const String &p_out_path); |
| 81 |
|
| 82 |
TEST_CASE("[Crypto] CryptoKey save public_only") { |
| 83 |
const String in_priv_path = TestUtils::get_data_path("crypto/in.key"); |
| 84 |
const String in_pub_path = TestUtils::get_data_path("crypto/in.pub"); |
| 85 |
const String out_path = TestUtils::get_data_path("crypto/out_public_only.pub"); |
| 86 |
crypto_key_save_public_only_test(in_priv_path, in_pub_path, out_path); |
| 87 |
} |
| 88 |
|
| 89 |
} |