test_crypto_mbedtls.h 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #pragma once
  31. #include "core/crypto/crypto.h"
  32. #include "core/crypto/hashing_context.h"
  33. #include "tests/test_macros.h"
  34. #include "tests/test_utils.h"
  35. namespace TestCryptoMbedTLS {
  36. void hmac_digest_test(HashingContext::HashType ht, String expected_hex);
  37. TEST_CASE("[CryptoMbedTLS] HMAC digest") {
  38. // SHA-256
  39. hmac_digest_test(HashingContext::HashType::HASH_SHA256, "fe442023f8a7d36a810e1e7cd8a8e2816457f350a008fbf638296afa12085e59");
  40. // SHA-1
  41. hmac_digest_test(HashingContext::HashType::HASH_SHA1, "a0ac4cd68a2f4812c355983d94e8d025afe7dddf");
  42. }
  43. void hmac_context_digest_test(HashingContext::HashType ht, String expected_hex);
  44. TEST_CASE("[HMACContext] HMAC digest") {
  45. // SHA-256
  46. hmac_context_digest_test(HashingContext::HashType::HASH_SHA256, "fe442023f8a7d36a810e1e7cd8a8e2816457f350a008fbf638296afa12085e59");
  47. // SHA-1
  48. hmac_context_digest_test(HashingContext::HashType::HASH_SHA1, "a0ac4cd68a2f4812c355983d94e8d025afe7dddf");
  49. }
  50. void crypto_key_public_only_test(const String &p_key_path, bool public_only);
  51. TEST_CASE("[Crypto] CryptoKey is_public_only") {
  52. crypto_key_public_only_test(TestUtils::get_data_path("crypto/in.key"), false);
  53. crypto_key_public_only_test(TestUtils::get_data_path("crypto/in.pub"), true);
  54. }
  55. void crypto_key_save_test(const String &p_in_path, const String &p_out_path, bool public_only);
  56. TEST_CASE("[Crypto] CryptoKey save") {
  57. const String in_priv_path = TestUtils::get_data_path("crypto/in.key");
  58. const String out_priv_path = TestUtils::get_data_path("crypto/out.key");
  59. crypto_key_save_test(in_priv_path, out_priv_path, false);
  60. const String in_pub_path = TestUtils::get_data_path("crypto/in.pub");
  61. const String out_pub_path = TestUtils::get_data_path("crypto/out.pub");
  62. crypto_key_save_test(in_pub_path, out_pub_path, true);
  63. }
  64. void crypto_key_save_public_only_test(const String &p_in_priv_path, const String &p_in_pub_path, const String &p_out_path);
  65. TEST_CASE("[Crypto] CryptoKey save public_only") {
  66. const String in_priv_path = TestUtils::get_data_path("crypto/in.key");
  67. const String in_pub_path = TestUtils::get_data_path("crypto/in.pub");
  68. const String out_path = TestUtils::get_data_path("crypto/out_public_only.pub");
  69. crypto_key_save_public_only_test(in_priv_path, in_pub_path, out_path);
  70. }
  71. } // namespace TestCryptoMbedTLS