From dfcc11fa52622680fe427c19dfe0528563a0691e Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sat, 6 Jun 2020 15:42:46 +0200 Subject: Implement sign and verify in crypto. --- core/crypto/crypto.cpp | 2 ++ core/crypto/crypto.h | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'core/crypto') diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp index a6b1fa9f03..f1d13b0633 100644 --- a/core/crypto/crypto.cpp +++ b/core/crypto/crypto.cpp @@ -86,6 +86,8 @@ void Crypto::_bind_methods() { ClassDB::bind_method(D_METHOD("generate_random_bytes", "size"), &Crypto::generate_random_bytes); ClassDB::bind_method(D_METHOD("generate_rsa", "size"), &Crypto::generate_rsa); ClassDB::bind_method(D_METHOD("generate_self_signed_certificate", "key", "issuer_name", "not_before", "not_after"), &Crypto::generate_self_signed_certificate, DEFVAL("CN=myserver,O=myorganisation,C=IT"), DEFVAL("20140101000000"), DEFVAL("20340101000000")); + ClassDB::bind_method(D_METHOD("sign", "hash_type", "hash", "key"), &Crypto::sign); + ClassDB::bind_method(D_METHOD("verify", "hash_type", "hash", "signature", "key"), &Crypto::verify); } /// Resource loader/saver diff --git a/core/crypto/crypto.h b/core/crypto/crypto.h index c1bc2024bb..472ad8ab9d 100644 --- a/core/crypto/crypto.h +++ b/core/crypto/crypto.h @@ -31,6 +31,7 @@ #ifndef CRYPTO_H #define CRYPTO_H +#include "core/crypto/hashing_context.h" #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" #include "core/reference.h" @@ -82,6 +83,9 @@ public: virtual Ref generate_rsa(int p_bytes) = 0; virtual Ref generate_self_signed_certificate(Ref p_key, String p_issuer_name, String p_not_before, String p_not_after) = 0; + virtual Vector sign(HashingContext::HashType p_hash_type, Vector p_hash, Ref p_key) = 0; + virtual bool verify(HashingContext::HashType p_hash_type, Vector p_hash, Vector p_signature, Ref p_key) = 0; + Crypto() {} }; -- cgit v1.2.3