diff --git a/doc/sql.extensions/README.builtin_functions.txt b/doc/sql.extensions/README.builtin_functions.txt index f78c96ea79..e387f8f52d 100644 --- a/doc/sql.extensions/README.builtin_functions.txt +++ b/doc/sql.extensions/README.builtin_functions.txt @@ -371,7 +371,7 @@ Function: Format: CRYPT_HASH( USING ) - algorithm ::= { MD5 | SHA1 | SHA256 | SHA512 } + algorithm ::= { MD5 | SHA1 | SHA256 | SHA512 | SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 } Important: - This function returns VARCHAR strings with OCTETS charset with length depended on algorithm. diff --git a/extern/libtomcrypt/src/headers/tomcrypt_custom.h b/extern/libtomcrypt/src/headers/tomcrypt_custom.h index f73e98e5ef..99afa02984 100644 --- a/extern/libtomcrypt/src/headers/tomcrypt_custom.h +++ b/extern/libtomcrypt/src/headers/tomcrypt_custom.h @@ -31,6 +31,7 @@ #define LTC_NO_HASHES #define LTC_MD5 #define LTC_SHA1 +#define LTC_SHA3 #define LTC_SHA256 #define LTC_SHA512 #define LTC_HASH_HELPERS diff --git a/src/common/classes/Hash.h b/src/common/classes/Hash.h index dbd22f02dd..fe7b3cc9d3 100644 --- a/src/common/classes/Hash.h +++ b/src/common/classes/Hash.h @@ -401,6 +401,30 @@ namespace Firebird Sha1HashContext(MemoryPool& pool); }; + class Sha3_512_HashContext final : public LibTomCryptHashContext + { + public: + Sha3_512_HashContext(MemoryPool& pool); + }; + + class Sha3_384_HashContext final : public LibTomCryptHashContext + { + public: + Sha3_384_HashContext(MemoryPool& pool); + }; + + class Sha3_256_HashContext final : public LibTomCryptHashContext + { + public: + Sha3_256_HashContext(MemoryPool& pool); + }; + + class Sha3_224_HashContext final : public LibTomCryptHashContext + { + public: + Sha3_224_HashContext(MemoryPool& pool); + }; + class Sha256HashContext final : public LibTomCryptHashContext { public: diff --git a/src/common/classes/TomCryptHash.cpp b/src/common/classes/TomCryptHash.cpp index 6e54ea3d06..1816cc0d52 100644 --- a/src/common/classes/TomCryptHash.cpp +++ b/src/common/classes/TomCryptHash.cpp @@ -87,6 +87,33 @@ Sha1HashContext::Sha1HashContext(MemoryPool& pool) { } +static LibTomCryptHashContext::Descriptor sha3_512_Descriptor{&sha3_512_desc}; + +Sha3_512_HashContext::Sha3_512_HashContext(MemoryPool& pool) + : LibTomCryptHashContext(pool, &sha3_512_Descriptor) +{ +} + +static LibTomCryptHashContext::Descriptor sha3_384_Descriptor{&sha3_384_desc}; + +Sha3_384_HashContext::Sha3_384_HashContext(MemoryPool& pool) + : LibTomCryptHashContext(pool, &sha3_384_Descriptor) +{ +} + +static LibTomCryptHashContext::Descriptor sha3_256_Descriptor{&sha3_256_desc}; + +Sha3_256_HashContext::Sha3_256_HashContext(MemoryPool& pool) + : LibTomCryptHashContext(pool, &sha3_256_Descriptor) +{ +} + +static LibTomCryptHashContext::Descriptor sha3_224_Descriptor{&sha3_224_desc}; + +Sha3_224_HashContext::Sha3_224_HashContext(MemoryPool& pool) + : LibTomCryptHashContext(pool, &sha3_224_Descriptor) +{ +} static LibTomCryptHashContext::Descriptor sha256Descriptor{&sha256_desc}; diff --git a/src/jrd/SysFunction.cpp b/src/jrd/SysFunction.cpp index cc6bd8cc45..0a23f70ce1 100644 --- a/src/jrd/SysFunction.cpp +++ b/src/jrd/SysFunction.cpp @@ -163,6 +163,10 @@ static const HashAlgorithmDescriptor* cryptHashAlgorithmDescriptors[] = { HashAlgorithmDescriptorFactory::getInstance("SHA1", 20), HashAlgorithmDescriptorFactory::getInstance("SHA256", 32), HashAlgorithmDescriptorFactory::getInstance("SHA512", 64), + HashAlgorithmDescriptorFactory::getInstance("SHA3_512", 64), + HashAlgorithmDescriptorFactory::getInstance("SHA3_384", 48), + HashAlgorithmDescriptorFactory::getInstance("SHA3_256", 32), + HashAlgorithmDescriptorFactory::getInstance("SHA3_224", 28), nullptr }; @@ -2964,6 +2968,10 @@ public: registerHash(md5_desc); registerHash(sha1_desc); + registerHash(sha3_512_desc); + registerHash(sha3_384_desc); + registerHash(sha3_256_desc); + registerHash(sha3_224_desc); registerHash(sha256_desc); registerHash(sha512_desc); }