Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/mbedtls/tests/test_crypto_mbedtls.h
10278 views
1
/**************************************************************************/
2
/* test_crypto_mbedtls.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
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
// SHA-256
45
hmac_digest_test(HashingContext::HashType::HASH_SHA256, "fe442023f8a7d36a810e1e7cd8a8e2816457f350a008fbf638296afa12085e59");
46
47
// SHA-1
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
// SHA-256
55
hmac_context_digest_test(HashingContext::HashType::HASH_SHA256, "fe442023f8a7d36a810e1e7cd8a8e2816457f350a008fbf638296afa12085e59");
56
57
// SHA-1
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
} // namespace TestCryptoMbedTLS
90
91