feat: HMAC support in Crypto APIs

This commit is contained in:
Jon Bonazza
2020-11-14 04:42:47 -08:00
parent ed2f84735b
commit d5925fd522
13 changed files with 480 additions and 4 deletions

View File

@ -67,6 +67,23 @@ public:
virtual Error save(String p_path) = 0;
};
class HMACContext : public Reference {
GDCLASS(HMACContext, Reference);
protected:
static void _bind_methods();
static HMACContext *(*_create)();
public:
static HMACContext *create();
virtual Error start(HashingContext::HashType p_hash_type, PackedByteArray p_key) = 0;
virtual Error update(PackedByteArray p_data) = 0;
virtual PackedByteArray finish() = 0;
HMACContext() {}
};
class Crypto : public Reference {
GDCLASS(Crypto, Reference);
@ -88,6 +105,12 @@ public:
virtual Vector<uint8_t> encrypt(Ref<CryptoKey> p_key, Vector<uint8_t> p_plaintext) = 0;
virtual Vector<uint8_t> decrypt(Ref<CryptoKey> p_key, Vector<uint8_t> p_ciphertext) = 0;
PackedByteArray hmac_digest(HashingContext::HashType p_hash_type, PackedByteArray p_key, PackedByteArray p_msg);
// Compares two PackedByteArrays for equality without leaking timing information in order to prevent timing attacks.
// @see: https://paragonie.com/blog/2015/11/preventing-timing-attacks-on-string-comparison-with-double-hmac-strategy
bool constant_time_compare(PackedByteArray p_trusted, PackedByteArray p_received);
Crypto() {}
};