feat: HMAC support in Crypto APIs
This commit is contained in:
@ -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() {}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user