mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Merge pull request #27830 from zhanglistar/master
Add sha512 hash functions
This commit is contained in:
commit
40a4a6663e
@ -303,6 +303,7 @@ function run_tests
|
||||
01683_codec_encrypted # Depends on OpenSSL
|
||||
01776_decrypt_aead_size_check # Depends on OpenSSL
|
||||
01811_filter_by_null # Depends on OpenSSL
|
||||
02012_sha512_fixedstring # Depends on OpenSSL
|
||||
01281_unsucceeded_insert_select_queries_counter
|
||||
01292_create_user
|
||||
01294_lazy_database_concurrent
|
||||
|
@ -143,7 +143,9 @@ It works faster than intHash32. Average quality.
|
||||
|
||||
## SHA256 {#sha256}
|
||||
|
||||
Calculates SHA-1, SHA-224, or SHA-256 from a string and returns the resulting set of bytes as FixedString(20), FixedString(28), or FixedString(32).
|
||||
## SHA512 {#sha512}
|
||||
|
||||
Calculates SHA-1, SHA-224, SHA-256 or SHA-512 from a string and returns the resulting set of bytes as FixedString(20), FixedString(28), FixedString(32), or FixedString(64).
|
||||
The function works fairly slowly (SHA-1 processes about 5 million short strings per second per processor core, while SHA-224 and SHA-256 process about 2.2 million).
|
||||
We recommend using this function only in cases when you need a specific hash function and you can’t select it.
|
||||
Even in these cases, we recommend applying the function offline and pre-calculating values when inserting them into the table, instead of applying it in SELECTS.
|
||||
|
@ -14,6 +14,7 @@ void registerFunctionsHashing(FunctionFactory & factory)
|
||||
factory.registerFunction<FunctionSHA1>();
|
||||
factory.registerFunction<FunctionSHA224>();
|
||||
factory.registerFunction<FunctionSHA256>();
|
||||
factory.registerFunction<FunctionSHA512>();
|
||||
#endif
|
||||
factory.registerFunction<FunctionSipHash64>();
|
||||
factory.registerFunction<FunctionSipHash128>();
|
||||
|
@ -193,6 +193,20 @@ struct SHA256Impl
|
||||
SHA256_Final(out_char_data, &ctx);
|
||||
}
|
||||
};
|
||||
|
||||
struct SHA512Impl
|
||||
{
|
||||
static constexpr auto name = "SHA512";
|
||||
enum { length = 64 };
|
||||
|
||||
static void apply(const char * begin, const size_t size, unsigned char * out_char_data)
|
||||
{
|
||||
SHA512_CTX ctx;
|
||||
SHA512_Init(&ctx);
|
||||
SHA512_Update(&ctx, reinterpret_cast<const unsigned char *>(begin), size);
|
||||
SHA512_Final(out_char_data, &ctx);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
struct SipHash64Impl
|
||||
@ -1318,6 +1332,7 @@ using FunctionMD5 = FunctionStringHashFixedString<MD5Impl>;
|
||||
using FunctionSHA1 = FunctionStringHashFixedString<SHA1Impl>;
|
||||
using FunctionSHA224 = FunctionStringHashFixedString<SHA224Impl>;
|
||||
using FunctionSHA256 = FunctionStringHashFixedString<SHA256Impl>;
|
||||
using FunctionSHA512 = FunctionStringHashFixedString<SHA512Impl>;
|
||||
#endif
|
||||
using FunctionSipHash128 = FunctionStringHashFixedString<SipHash128Impl>;
|
||||
using FunctionCityHash64 = FunctionAnyHash<ImplCityHash64>;
|
||||
|
22
tests/queries/0_stateless/02012_sha512_fixedstring.reference
Normal file
22
tests/queries/0_stateless/02012_sha512_fixedstring.reference
Normal file
@ -0,0 +1,22 @@
|
||||
CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9CE47D0D13C5D85F2B0FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E
|
||||
DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F
|
||||
5809F3ECB4AA006F71AF562D4381F2BF64EA0931FD530E939740D0C38F6EEB2A71FA0113A21C170569D8319B8C4DE8A1C1A5ABA1A1C5B23A886B06712D373B9E
|
||||
6FDB5E5BCCBD093ECC48DD262A99E6B867D6F48E1DAE014D26428365E7529B0022F000CBF852BEA38F43A2034E8FE7555AC41B9EA9E27FE72F4E968926998EA8
|
||||
8018978D8AAE19322205E4CACFA045CDF7A0C4A5773A93FD24331064AFC5726F324B76802AA6FC30DFC412A6E5C3EEF4693AE4E2D0A1EA24A2D3EC46439B7923
|
||||
22F1080BFD1CEA5B86CFDEFE129D2FF67E756AA3DA0EADB4C6EBA86A0710F3C2E0F91815A28062BDA4FBF23E5FA1BD66A3CFDA37AC7354516943AB6E08E88106
|
||||
08788919600C5C9B93704570858D8B64D5B335FAD2B23E28A5E68A08BCC4AD9BCA1991178FEA22BDAAA3C9C2FEB061FF4919C1C840DFA8188858D80EDCE98499
|
||||
0EFD835B217A94C32F45B9C3720644D7A4A49DD3A74EDE4257CFBB74164C80382322B8EA7B6131747609BA1B2776E84AEC2820D9414FC5F66B6A42D3F90F1D9F
|
||||
C161DA64EE30E86768040C4BB7B88C3FAE5A1E79CA2441B2DB66552B126C00F952D2D854DF2F5D56FB85ED57C5A39E95BFE485A6AF70963A81BE67DFDB96CFBF
|
||||
F65B5379D687EA1FB38E32F8251F0FB270061DC6DF9AECA1E258A6F1BAFF70D4E979FC9315ED1FAE24D000CC0EF7937D02703B2061694B3DCA2308C5C0779184
|
||||
DF25395F5FFF00E5B64BF5EEAFD94A1A21B4F4FC4FAE01DF48C27C77E0C9DC6FC253C7E7F32185146048190B73E3ED53BC76F626D24E9DE3FBA3EBC48B671CC0
|
||||
F1DD6EFB26D0169259FBD53150D6E0C4F2E1FFF2F9DA6B77EC9AD065AD67D33F95411CC5E5B31CEAB970974E5C8E3C6376445D8422F052CABB121BCE1449C494
|
||||
561A1DEDBB03FD632DBFDCC73E83A8DBD17D6E30B14642BAC8EBF3DF6622150A5E51ACC059E2C44EF71A00FBEEB062F2EE7A610E5462E6B4805449574AAE857F
|
||||
D59943FE43CB50F2C3AE74F9BD09F72140519EA30C1A24E6F7A4BCBBD12860D954F9752A24FBAA1D606F362564D905E8B29806903B1542D948C2B8293FC09A59
|
||||
E18A99CED7BD69979406C5A666336D7316E11240FF5F8C1632F17BEB1BD58838E0222CCD48D4227F0751592F1C731B4BB11C325F09FB15923F0334C64303D73A
|
||||
0508B92D15B0750343F9B3E2218C7D54BB6D9A3ABA5FA941977832AA89300516505E91034E4ECD4812A7A58438251651C00974DDCD3C471B9ED02451871F4A48
|
||||
ADFDC00D41881138C96581D43298C5724C20500C5A966144B51531FFB2FE6CE265BE3101CD19B985A2253A7B48EE4EC5EBD4B2876CF0E66F1095EB0A2521C525
|
||||
758ABA28159AABFFF659E6698397AD7A9EBBA77AA3FFC25551B7CF2057930AD051D357866259E5288B0B837E3F5C4ED1D1229320595F914381903CD48DF76CB2
|
||||
E7A061D9B066E2CA44CF959A76FC04D8B02998CB9D46A60C19E015EA9389F3F9595CBBC4CC46E1319B02B3269FBD21F62D15A6F13428F8389CB4507AF6DB6D89
|
||||
3438D75650E1EDB8A11EF4F63A5DFF239A70B28B6A14F13FCFDD14D02BE8BD00E84DF956C159CFDC85D6E44DB62D00E9206F40453FFD9CC97C38449527D33FF6
|
||||
DB229C3A53B0340E94EFDA4D03B54F161313699757CAC312F377B731AE6C62010E0C0010E78F73E6D6B0BB438F644D176244B2614897799F9FA3F85DA980C218
|
||||
FDD9FD54050D95855B8E3A34F3A54E309E1CA87CD44A8506EB10051D1CA650DB64ABD0BE4F4F44E45F630C22CA270FA7694AC2261DF2EFD766B8CED53F285A27
|
14
tests/queries/0_stateless/02012_sha512_fixedstring.sql
Normal file
14
tests/queries/0_stateless/02012_sha512_fixedstring.sql
Normal file
@ -0,0 +1,14 @@
|
||||
SELECT hex(SHA512(''));
|
||||
SELECT hex(SHA512('abc'));
|
||||
|
||||
DROP TABLE IF EXISTS defaults;
|
||||
CREATE TABLE defaults
|
||||
(
|
||||
s FixedString(20)
|
||||
)ENGINE = Memory();
|
||||
|
||||
INSERT INTO defaults SELECT s FROM generateRandom('s FixedString(20)', 1, 1, 1) LIMIT 20;
|
||||
|
||||
SELECT hex(SHA512(s)) FROM defaults;
|
||||
|
||||
DROP TABLE defaults;
|
Loading…
Reference in New Issue
Block a user