Signed-off-by: falkTX <falktx@falktx.com>tags/2020-12-27
@@ -2,33 +2,33 @@ | |||
if linux_embed | |||
juce_current_srcs = [ | |||
'source/modules/juce_audio_basics/juce_audio_basics.cpp', | |||
'source/modules/juce_audio_devices/juce_audio_devices.cpp', | |||
'source/modules/juce_audio_formats/juce_audio_formats.cpp', | |||
'source/modules/juce_audio_processors/juce_audio_processors.cpp', | |||
'source/modules/juce_audio_utils/juce_audio_utils.cpp', | |||
'source/modules/juce_core/juce_core.cpp', | |||
'source/modules/juce_cryptography/juce_cryptography.cpp', | |||
'source/modules/juce_data_structures/juce_data_structures.cpp', | |||
'source/modules/juce_dsp/juce_dsp.cpp', | |||
'source/modules/juce_events/juce_events.cpp', | |||
'source/juce_audio_basics/juce_audio_basics.cpp', | |||
'source/juce_audio_devices/juce_audio_devices.cpp', | |||
'source/juce_audio_formats/juce_audio_formats.cpp', | |||
'source/juce_audio_processors/juce_audio_processors.cpp', | |||
'source/juce_audio_utils/juce_audio_utils.cpp', | |||
'source/juce_core/juce_core.cpp', | |||
'source/juce_cryptography/juce_cryptography.cpp', | |||
'source/juce_data_structures/juce_data_structures.cpp', | |||
'source/juce_dsp/juce_dsp.cpp', | |||
'source/juce_events/juce_events.cpp', | |||
] | |||
else | |||
juce_current_srcs = [ | |||
'source/modules/juce_audio_basics/juce_audio_basics.cpp', | |||
'source/modules/juce_audio_devices/juce_audio_devices.cpp', | |||
'source/modules/juce_audio_formats/juce_audio_formats.cpp', | |||
'source/modules/juce_audio_processors/juce_audio_processors.cpp', | |||
'source/modules/juce_audio_utils/juce_audio_utils.cpp', | |||
'source/modules/juce_core/juce_core.cpp', | |||
'source/modules/juce_cryptography/juce_cryptography.cpp', | |||
'source/modules/juce_data_structures/juce_data_structures.cpp', | |||
'source/modules/juce_dsp/juce_dsp.cpp', | |||
'source/modules/juce_events/juce_events.cpp', | |||
'source/modules/juce_graphics/juce_graphics.cpp', | |||
'source/modules/juce_gui_basics/juce_gui_basics.cpp', | |||
'source/modules/juce_gui_extra/juce_gui_extra.cpp', | |||
'source/modules/juce_opengl/juce_opengl.cpp', | |||
'source/juce_audio_basics/juce_audio_basics.cpp', | |||
'source/juce_audio_devices/juce_audio_devices.cpp', | |||
'source/juce_audio_formats/juce_audio_formats.cpp', | |||
'source/juce_audio_processors/juce_audio_processors.cpp', | |||
'source/juce_audio_utils/juce_audio_utils.cpp', | |||
'source/juce_core/juce_core.cpp', | |||
'source/juce_cryptography/juce_cryptography.cpp', | |||
'source/juce_data_structures/juce_data_structures.cpp', | |||
'source/juce_dsp/juce_dsp.cpp', | |||
'source/juce_events/juce_events.cpp', | |||
'source/juce_graphics/juce_graphics.cpp', | |||
'source/juce_gui_basics/juce_gui_basics.cpp', | |||
'source/juce_gui_extra/juce_gui_extra.cpp', | |||
'source/juce_opengl/juce_opengl.cpp', | |||
] | |||
endif | |||
@@ -37,10 +37,9 @@ lib_juce_current = static_library('juce-current', | |||
include_directories: [ | |||
include_directories('.'), | |||
include_directories('source'), | |||
include_directories('source' / 'modules'), | |||
include_directories('..' / 'juced' / 'source' / 'dependancies' / 'ladspa_sdk' / 'src'), | |||
], | |||
cpp_args: build_flags_cpp, | |||
cpp_args: build_flags_cpp + ['-std=gnu++14'], | |||
dependencies: dependencies, | |||
pic: true, | |||
install: false, | |||
@@ -0,0 +1,477 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
BlowFish::BlowFish (const void* const keyData, const int keyBytes) | |||
{ | |||
jassert (keyData != nullptr); | |||
jassert (keyBytes > 0); | |||
static const uint32 initialPValues[18] = | |||
{ | |||
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, | |||
0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, | |||
0x9216d5d9, 0x8979fb1b | |||
}; | |||
static const uint32 initialSValues[4 * 256] = | |||
{ | |||
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, | |||
0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, | |||
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, | |||
0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, | |||
0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, | |||
0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, | |||
0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, | |||
0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, | |||
0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, | |||
0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, | |||
0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, | |||
0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, | |||
0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, | |||
0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, | |||
0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, | |||
0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, | |||
0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, | |||
0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, | |||
0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, | |||
0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, | |||
0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, | |||
0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, | |||
0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, | |||
0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, | |||
0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, | |||
0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, | |||
0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, | |||
0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, | |||
0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, | |||
0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, | |||
0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, | |||
0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a, | |||
0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, | |||
0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, | |||
0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, | |||
0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, | |||
0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, | |||
0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, | |||
0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, | |||
0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, | |||
0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, | |||
0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, | |||
0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, | |||
0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, | |||
0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, | |||
0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, | |||
0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, | |||
0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, | |||
0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, | |||
0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, | |||
0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, | |||
0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, | |||
0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, | |||
0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, | |||
0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, | |||
0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, | |||
0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, | |||
0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, | |||
0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, | |||
0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, | |||
0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, | |||
0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, | |||
0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, | |||
0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7, | |||
0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, | |||
0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, | |||
0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, | |||
0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, | |||
0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, | |||
0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, | |||
0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, | |||
0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, | |||
0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, | |||
0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, | |||
0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, | |||
0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, | |||
0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, | |||
0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, | |||
0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, | |||
0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, | |||
0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, | |||
0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, | |||
0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, | |||
0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, | |||
0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, | |||
0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, | |||
0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, | |||
0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, | |||
0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, | |||
0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, | |||
0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, | |||
0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, | |||
0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, | |||
0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, | |||
0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, | |||
0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0, | |||
0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, | |||
0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, | |||
0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, | |||
0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, | |||
0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, | |||
0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, | |||
0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, | |||
0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, | |||
0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, | |||
0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, | |||
0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, | |||
0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, | |||
0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, | |||
0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, | |||
0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, | |||
0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, | |||
0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, | |||
0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, | |||
0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, | |||
0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, | |||
0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, | |||
0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, | |||
0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, | |||
0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, | |||
0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, | |||
0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, | |||
0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, | |||
0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, | |||
0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, | |||
0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, | |||
0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, | |||
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 | |||
}; | |||
memcpy (p, initialPValues, sizeof (p)); | |||
int keyIndex = 0; | |||
for (int i = 0; i < 4; ++i) | |||
{ | |||
s[i].malloc (256); | |||
memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32)); | |||
} | |||
for (int i = 0; i < 18; ++i) | |||
{ | |||
uint32 d = 0; | |||
for (int k = 0; k < 4; ++k) | |||
{ | |||
d = (d << 8) | static_cast<const uint8*> (keyData)[keyIndex]; | |||
if (++keyIndex >= keyBytes) | |||
keyIndex = 0; | |||
} | |||
p[i] = initialPValues[i] ^ d; | |||
} | |||
uint32 l = 0, r = 0; | |||
for (int i = 0; i < 18; i += 2) | |||
{ | |||
encrypt (l, r); | |||
p[i] = l; | |||
p[i + 1] = r; | |||
} | |||
for (int i = 0; i < 4; ++i) | |||
{ | |||
for (int j = 0; j < 256; j += 2) | |||
{ | |||
encrypt (l, r); | |||
s[i][j] = l; | |||
s[i][j + 1] = r; | |||
} | |||
} | |||
} | |||
BlowFish::BlowFish (const BlowFish& other) | |||
{ | |||
for (auto& block : s) | |||
block.malloc (256); | |||
operator= (other); | |||
} | |||
BlowFish& BlowFish::operator= (const BlowFish& other) noexcept | |||
{ | |||
memcpy (p, other.p, sizeof (p)); | |||
for (int i = 4; --i >= 0;) | |||
memcpy (s[i], other.s[i], 256 * sizeof (uint32)); | |||
return *this; | |||
} | |||
BlowFish::~BlowFish() noexcept {} | |||
uint32 BlowFish::F (const uint32 x) const noexcept | |||
{ | |||
return ((s[0][(x >> 24) & 0xff] + s[1][(x >> 16) & 0xff]) | |||
^ s[2][(x >> 8) & 0xff]) + s[3][x & 0xff]; | |||
} | |||
void BlowFish::encrypt (uint32& data1, uint32& data2) const noexcept | |||
{ | |||
auto l = data1; | |||
auto r = data2; | |||
for (int i = 0; i < 16; ++i) | |||
{ | |||
l ^= p[i]; | |||
r ^= F(l); | |||
std::swap (l, r); | |||
} | |||
data1 = r ^ p[17]; | |||
data2 = l ^ p[16]; | |||
} | |||
void BlowFish::decrypt (uint32& data1, uint32& data2) const noexcept | |||
{ | |||
auto l = data1; | |||
auto r = data2; | |||
for (int i = 17; i > 1; --i) | |||
{ | |||
l ^= p[i]; | |||
r ^= F(l); | |||
std::swap (l, r); | |||
} | |||
data1 = r ^ p[0]; | |||
data2 = l ^ p[1]; | |||
} | |||
void BlowFish::encrypt (MemoryBlock& data) const | |||
{ | |||
auto size = data.getSize(); | |||
data.setSize (size + (8u - (size % 8u))); | |||
auto success = encrypt (data.getData(), size, data.getSize()); | |||
ignoreUnused (success); | |||
jassert (success >= 0); | |||
} | |||
void BlowFish::decrypt (MemoryBlock& data) const | |||
{ | |||
auto newSize = decrypt (data.getData(), data.getSize()); | |||
if (newSize >= 0) | |||
data.setSize (static_cast<size_t> (newSize)); | |||
else | |||
jassertfalse; | |||
} | |||
int BlowFish::encrypt (void* data, size_t size, size_t bufferSize) const noexcept | |||
{ | |||
auto encryptedSize = pad (data, size, bufferSize); | |||
if (encryptedSize >= 0 && apply (data, static_cast<size_t> (encryptedSize), &BlowFish::encrypt)) | |||
return encryptedSize; | |||
return -1; | |||
} | |||
int BlowFish::decrypt (void* data, size_t size) const noexcept | |||
{ | |||
if (apply (data, size, &BlowFish::decrypt)) | |||
return unpad (data, size); | |||
return -1; | |||
} | |||
bool BlowFish::apply (void* data, size_t size, void (BlowFish::*op) (uint32&, uint32&) const) const | |||
{ | |||
union AlignedAccessHelper | |||
{ | |||
int8 byte[sizeof(uint32) * 2]; | |||
uint32 data[2]; | |||
}; | |||
if ((size % 8u) != 0) | |||
return false; | |||
auto n = size / 8u; | |||
auto* ptr = reinterpret_cast<AlignedAccessHelper*> (data); | |||
for (size_t i = 0; i < n; ++i) | |||
(this->*op) (ptr[i].data[0], ptr[i].data[1]); | |||
return true; | |||
} | |||
int BlowFish::pad (void* data, size_t size, size_t bufferSize) noexcept | |||
{ | |||
// add padding according to https://tools.ietf.org/html/rfc2898#section-6.1.1 | |||
const uint8 paddingSize = static_cast<uint8> (8u - (size % 8u)); | |||
auto n = size + paddingSize; | |||
if (n > bufferSize) | |||
return -1; | |||
auto* dst = reinterpret_cast<uint8*> (data); | |||
for (size_t i = size; i < n; ++i) | |||
dst[i] = paddingSize; | |||
return static_cast<int> (n); | |||
} | |||
int BlowFish::unpad (const void* data, size_t size) noexcept | |||
{ | |||
if (size == 0) | |||
return -1; | |||
// remove padding according to https://tools.ietf.org/html/rfc2898#section-6.1.1 | |||
auto paddingSize = reinterpret_cast<const uint8*>(data)[size - 1u]; | |||
if (paddingSize == 0 || paddingSize > 8 || paddingSize > size) | |||
return -1; | |||
return static_cast<int> (size - static_cast<size_t> (paddingSize)); | |||
} | |||
//============================================================================== | |||
//============================================================================== | |||
#if JUCE_UNIT_TESTS | |||
class BlowFishTests : public UnitTest | |||
{ | |||
public: | |||
BlowFishTests() | |||
: UnitTest ("BlowFish", UnitTestCategories::cryptography) | |||
{} | |||
static void fillMemoryBlockWithRandomData (MemoryBlock& block, Random& random) | |||
{ | |||
const size_t n = block.getSize() / sizeof (int32); | |||
auto* dst = reinterpret_cast<uint8*> (block.getData()); | |||
for (size_t i = 0; i < n; ++i) | |||
dst[i] = static_cast<uint8> (random.nextInt(255)); | |||
} | |||
void expectEqualData (const void* dataA, const void* dataB, size_t size, const String& failureMessage) | |||
{ | |||
auto* a = reinterpret_cast<const uint8*> (dataA); | |||
auto* b = reinterpret_cast<const uint8*> (dataB); | |||
for (size_t i = 0; i < size; ++i) | |||
expectEquals ((int) a[i], (int) b[i], failureMessage); | |||
} | |||
void expectEqualMemoryBlocks (const MemoryBlock& a, const MemoryBlock& b, const String& failureMessage) | |||
{ | |||
expectEquals ((int) a.getSize(), (int) b.getSize(), failureMessage); | |||
expectEqualData (a.getData(), b.getData(), a.getSize(), failureMessage); | |||
} | |||
void encryptDecryptTest (const BlowFish& blowFish, void* data, size_t size, size_t bufferSize) | |||
{ | |||
MemoryBlock copy (data, size); | |||
int encryptedSize = blowFish.encrypt (data, size, bufferSize); | |||
expectGreaterThan (encryptedSize, (int) size); | |||
expectLessOrEqual (encryptedSize, (int) bufferSize); | |||
int decryptedSize = blowFish.decrypt (data, static_cast<size_t> (encryptedSize)); | |||
expectEquals ((int) size, decryptedSize); | |||
expectEqualData (data, copy.getData(), size, "Length/Content changed during encryption"); | |||
} | |||
void encryptDecryptTest (const BlowFish& blowFish, MemoryBlock& data) | |||
{ | |||
MemoryBlock copy (data); | |||
blowFish.encrypt (data); | |||
blowFish.decrypt (data); | |||
expectEqualMemoryBlocks (data, copy, "Length/Content changed during encryption"); | |||
} | |||
void encryptDecryptTest (const BlowFish& blowFish, const String& data) | |||
{ | |||
MemoryBlock block (data.toRawUTF8(), static_cast<size_t> (data.length())); | |||
encryptDecryptTest (blowFish, block); | |||
} | |||
void runTest() override | |||
{ | |||
beginTest ("BlowFish"); | |||
auto random = getRandom(); | |||
for (int i = 0; i < 100; ++i) | |||
{ | |||
const int keySize = (random.nextInt(17) + 1) * static_cast<int> (sizeof (uint32)); | |||
MemoryBlock key (static_cast<size_t> (keySize)); | |||
fillMemoryBlockWithRandomData (key, random); | |||
BlowFish bf (key.getData(), keySize); | |||
encryptDecryptTest (bf, ""); | |||
encryptDecryptTest (bf, "a"); | |||
encryptDecryptTest (bf, "Hello World!"); | |||
const int minSize = 8 + sizeof (void*); | |||
const int dataSize = random.nextInt (2048 - minSize) + minSize; | |||
MemoryBlock data (static_cast<size_t> (dataSize)); | |||
fillMemoryBlockWithRandomData (data, random); | |||
encryptDecryptTest (bf, data); | |||
encryptDecryptTest (bf, data.getData(), data.getSize() - 8, data.getSize()); | |||
encryptDecryptTest (bf, data.getData(), 0, 8); | |||
{ | |||
// Test unaligned data encryption/decryption. This will be flagged up by a check for | |||
// undefined behaviour! | |||
auto nudge = static_cast<uintptr_t> (random.nextInt (sizeof(void*) - 1)); | |||
auto unalignedData = (void*) (reinterpret_cast<uintptr_t> (data.getData()) + nudge); | |||
size_t newSize = data.getSize() - nudge; | |||
encryptDecryptTest (bf, unalignedData, newSize - 8, newSize); | |||
} | |||
} | |||
} | |||
}; | |||
static BlowFishTests blowFishUnitTests; | |||
#endif | |||
} // namespace juce |
@@ -0,0 +1,112 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
//============================================================================== | |||
/** | |||
BlowFish encryption class. | |||
@tags{Cryptography} | |||
*/ | |||
class JUCE_API BlowFish | |||
{ | |||
public: | |||
//============================================================================== | |||
/** Creates an object that can encode/decode based on the specified key. | |||
The key data can be up to 72 bytes long. | |||
*/ | |||
BlowFish (const void* keyData, int keyBytes); | |||
/** Creates a copy of another blowfish object. */ | |||
BlowFish (const BlowFish&); | |||
/** Copies another blowfish object. */ | |||
BlowFish& operator= (const BlowFish&) noexcept; | |||
/** Destructor. */ | |||
~BlowFish() noexcept; | |||
//============================================================================== | |||
/** Encrypts a pair of 32-bit integers. */ | |||
void encrypt (uint32& data1, uint32& data2) const noexcept; | |||
/** Decrypts a pair of 32-bit integers. */ | |||
void decrypt (uint32& data1, uint32& data2) const noexcept; | |||
//============================================================================== | |||
/** Encrypts a memory block */ | |||
void encrypt (MemoryBlock& data) const; | |||
/** Decrypts a memory block */ | |||
void decrypt (MemoryBlock& data) const; | |||
//============================================================================== | |||
/** Encrypts data in-place | |||
@param buffer The message that should be encrypted. See bufferSize on size | |||
requirements! | |||
@param sizeOfMsg The size of the message that should be encrypted in bytes | |||
@param bufferSize The size of the buffer in bytes. To accommodate the encrypted | |||
data, the buffer must be larger than the message: the size of | |||
the buffer needs to be equal or greater than the size of the | |||
message in bytes rounded to the next integer which is divisible | |||
by eight. If the message size in bytes is already divisible by eight | |||
then you need to add eight bytes to the buffer size. If in doubt | |||
simply use bufferSize = sizeOfMsg + 8. | |||
@returns The size of the decrypted data in bytes or -1 if the decryption failed. | |||
*/ | |||
int encrypt (void* buffer, size_t sizeOfMsg, size_t bufferSize) const noexcept; | |||
/** Decrypts data in-place | |||
@param buffer The encrypted data that should be decrypted | |||
@param bytes The size of the encrypted data in bytes | |||
@returns The size of the decrypted data in bytes or -1 if the decryption failed. | |||
*/ | |||
int decrypt (void* buffer, size_t bytes) const noexcept; | |||
private: | |||
//============================================================================== | |||
static int pad (void*, size_t, size_t) noexcept; | |||
static int unpad (const void*, size_t) noexcept; | |||
bool apply (void*, size_t, void (BlowFish::*op) (uint32&, uint32&) const) const; | |||
//============================================================================== | |||
uint32 p[18]; | |||
HeapBlock<uint32> s[4]; | |||
uint32 F (uint32) const noexcept; | |||
JUCE_LEAK_DETECTOR (BlowFish) | |||
}; | |||
} // namespace juce |
@@ -0,0 +1,244 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
namespace PrimesHelpers | |||
{ | |||
static void createSmallSieve (const int numBits, BigInteger& result) | |||
{ | |||
result.setBit (numBits); | |||
result.clearBit (numBits); // to enlarge the array | |||
result.setBit (0); | |||
int n = 2; | |||
do | |||
{ | |||
for (int i = n + n; i < numBits; i += n) | |||
result.setBit (i); | |||
n = result.findNextClearBit (n + 1); | |||
} | |||
while (n <= (numBits >> 1)); | |||
} | |||
static void bigSieve (const BigInteger& base, const int numBits, BigInteger& result, | |||
const BigInteger& smallSieve, const int smallSieveSize) | |||
{ | |||
jassert (! base[0]); // must be even! | |||
result.setBit (numBits); | |||
result.clearBit (numBits); // to enlarge the array | |||
int index = smallSieve.findNextClearBit (0); | |||
do | |||
{ | |||
const unsigned int prime = ((unsigned int) index << 1) + 1; | |||
BigInteger r (base), remainder; | |||
r.divideBy (prime, remainder); | |||
unsigned int i = prime - remainder.getBitRangeAsInt (0, 32); | |||
if (r.isZero()) | |||
i += prime; | |||
if ((i & 1) == 0) | |||
i += prime; | |||
i = (i - 1) >> 1; | |||
while (i < (unsigned int) numBits) | |||
{ | |||
result.setBit ((int) i); | |||
i += prime; | |||
} | |||
index = smallSieve.findNextClearBit (index + 1); | |||
} | |||
while (index < smallSieveSize); | |||
} | |||
static bool findCandidate (const BigInteger& base, const BigInteger& sieve, | |||
const int numBits, BigInteger& result, const int certainty) | |||
{ | |||
for (int i = 0; i < numBits; ++i) | |||
{ | |||
if (! sieve[i]) | |||
{ | |||
result = base + (unsigned int) ((i << 1) + 1); | |||
if (Primes::isProbablyPrime (result, certainty)) | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
static bool passesMillerRabin (const BigInteger& n, int iterations) | |||
{ | |||
const BigInteger one (1), two (2); | |||
const BigInteger nMinusOne (n - one); | |||
BigInteger d (nMinusOne); | |||
const int s = d.findNextSetBit (0); | |||
d >>= s; | |||
BigInteger smallPrimes; | |||
int numBitsInSmallPrimes = 0; | |||
for (;;) | |||
{ | |||
numBitsInSmallPrimes += 256; | |||
createSmallSieve (numBitsInSmallPrimes, smallPrimes); | |||
const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits(); | |||
if (numPrimesFound > iterations + 1) | |||
break; | |||
} | |||
int smallPrime = 2; | |||
while (--iterations >= 0) | |||
{ | |||
smallPrime = smallPrimes.findNextClearBit (smallPrime + 1); | |||
BigInteger r (smallPrime); | |||
r.exponentModulo (d, n); | |||
if (r != one && r != nMinusOne) | |||
{ | |||
for (int j = 0; j < s; ++j) | |||
{ | |||
r.exponentModulo (two, n); | |||
if (r == nMinusOne) | |||
break; | |||
} | |||
if (r != nMinusOne) | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
} | |||
//============================================================================== | |||
BigInteger Primes::createProbablePrime (const int bitLength, | |||
const int certainty, | |||
const int* randomSeeds, | |||
int numRandomSeeds) | |||
{ | |||
using namespace PrimesHelpers; | |||
int defaultSeeds [16]; | |||
if (numRandomSeeds <= 0) | |||
{ | |||
randomSeeds = defaultSeeds; | |||
numRandomSeeds = numElementsInArray (defaultSeeds); | |||
Random r1, r2; | |||
for (int j = 10; --j >= 0;) | |||
{ | |||
r1.setSeedRandomly(); | |||
for (int i = numRandomSeeds; --i >= 0;) | |||
defaultSeeds[i] ^= r1.nextInt() ^ r2.nextInt(); | |||
} | |||
} | |||
BigInteger smallSieve; | |||
const int smallSieveSize = 15000; | |||
createSmallSieve (smallSieveSize, smallSieve); | |||
BigInteger p; | |||
for (int i = numRandomSeeds; --i >= 0;) | |||
{ | |||
BigInteger p2; | |||
Random r (randomSeeds[i]); | |||
r.fillBitsRandomly (p2, 0, bitLength); | |||
p ^= p2; | |||
} | |||
p.setBit (bitLength - 1); | |||
p.clearBit (0); | |||
const int searchLen = jmax (1024, (bitLength / 20) * 64); | |||
while (p.getHighestBit() < bitLength) | |||
{ | |||
p += 2 * searchLen; | |||
BigInteger sieve; | |||
bigSieve (p, searchLen, sieve, | |||
smallSieve, smallSieveSize); | |||
BigInteger candidate; | |||
if (findCandidate (p, sieve, searchLen, candidate, certainty)) | |||
return candidate; | |||
} | |||
jassertfalse; | |||
return BigInteger(); | |||
} | |||
bool Primes::isProbablyPrime (const BigInteger& number, const int certainty) | |||
{ | |||
using namespace PrimesHelpers; | |||
if (! number[0]) | |||
return false; | |||
if (number.getHighestBit() <= 10) | |||
{ | |||
const unsigned int num = number.getBitRangeAsInt (0, 10); | |||
for (unsigned int i = num / 2; --i > 1;) | |||
if (num % i == 0) | |||
return false; | |||
return true; | |||
} | |||
else | |||
{ | |||
if (number.findGreatestCommonDivisor (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23) != 1) | |||
return false; | |||
return passesMillerRabin (number, certainty); | |||
} | |||
} | |||
} // namespace juce |
@@ -0,0 +1,74 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
//============================================================================== | |||
/** | |||
Prime number creation class. | |||
This class contains static methods for generating and testing prime numbers. | |||
@see BigInteger | |||
@tags{Cryptography} | |||
*/ | |||
class JUCE_API Primes | |||
{ | |||
public: | |||
//============================================================================== | |||
/** Creates a random prime number with a given bit-length. | |||
The certainty parameter specifies how many iterations to use when testing | |||
for primality. A safe value might be anything over about 20-30. | |||
The randomSeeds parameter lets you optionally pass it a set of values with | |||
which to seed the random number generation, improving the security of the | |||
keys generated. | |||
*/ | |||
static BigInteger createProbablePrime (int bitLength, | |||
int certainty, | |||
const int* randomSeeds = nullptr, | |||
int numRandomSeeds = 0); | |||
/** Tests a number to see if it's prime. | |||
This isn't a bulletproof test, it uses a Miller-Rabin test to determine | |||
whether the number is prime. | |||
The certainty parameter specifies how many iterations to use when testing - a | |||
safe value might be anything over about 20-30. | |||
*/ | |||
static bool isProbablyPrime (const BigInteger& number, int certainty); | |||
private: | |||
Primes(); | |||
JUCE_DECLARE_NON_COPYABLE (Primes) | |||
}; | |||
} // namespace juce |
@@ -0,0 +1,141 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
RSAKey::RSAKey() | |||
{ | |||
} | |||
RSAKey::RSAKey (const String& s) | |||
{ | |||
if (s.containsChar (',')) | |||
{ | |||
part1.parseString (s.upToFirstOccurrenceOf (",", false, false), 16); | |||
part2.parseString (s.fromFirstOccurrenceOf (",", false, false), 16); | |||
} | |||
else | |||
{ | |||
// the string needs to be two hex numbers, comma-separated.. | |||
jassertfalse; | |||
} | |||
} | |||
RSAKey::~RSAKey() | |||
{ | |||
} | |||
bool RSAKey::operator== (const RSAKey& other) const noexcept | |||
{ | |||
return part1 == other.part1 && part2 == other.part2; | |||
} | |||
bool RSAKey::operator!= (const RSAKey& other) const noexcept | |||
{ | |||
return ! operator== (other); | |||
} | |||
bool RSAKey::isValid() const noexcept | |||
{ | |||
return operator!= (RSAKey()); | |||
} | |||
String RSAKey::toString() const | |||
{ | |||
return part1.toString (16) + "," + part2.toString (16); | |||
} | |||
bool RSAKey::applyToValue (BigInteger& value) const | |||
{ | |||
if (part1.isZero() || part2.isZero() || value <= 0) | |||
{ | |||
jassertfalse; // using an uninitialised key | |||
value.clear(); | |||
return false; | |||
} | |||
BigInteger result; | |||
while (! value.isZero()) | |||
{ | |||
result *= part2; | |||
BigInteger remainder; | |||
value.divideBy (part2, remainder); | |||
remainder.exponentModulo (part1, part2); | |||
result += remainder; | |||
} | |||
value.swapWith (result); | |||
return true; | |||
} | |||
BigInteger RSAKey::findBestCommonDivisor (const BigInteger& p, const BigInteger& q) | |||
{ | |||
// try 3, 5, 9, 17, etc first because these only contain 2 bits and so | |||
// are fast to divide + multiply | |||
for (int i = 2; i <= 65536; i *= 2) | |||
{ | |||
const BigInteger e (1 + i); | |||
if (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne()) | |||
return e; | |||
} | |||
BigInteger e (4); | |||
while (! (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne())) | |||
++e; | |||
return e; | |||
} | |||
void RSAKey::createKeyPair (RSAKey& publicKey, RSAKey& privateKey, | |||
const int numBits, const int* randomSeeds, const int numRandomSeeds) | |||
{ | |||
jassert (numBits > 16); // not much point using less than this.. | |||
jassert (numRandomSeeds == 0 || numRandomSeeds >= 2); // you need to provide plenty of seeds here! | |||
BigInteger p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds / 2)); | |||
BigInteger q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds == nullptr ? nullptr : (randomSeeds + numRandomSeeds / 2), numRandomSeeds - numRandomSeeds / 2)); | |||
const BigInteger n (p * q); | |||
const BigInteger m (--p * --q); | |||
const BigInteger e (findBestCommonDivisor (p, q)); | |||
BigInteger d (e); | |||
d.inverseModulo (m); | |||
publicKey.part1 = e; | |||
publicKey.part2 = n; | |||
privateKey.part1 = d; | |||
privateKey.part2 = n; | |||
} | |||
} // namespace juce |
@@ -0,0 +1,175 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
//============================================================================== | |||
/** | |||
RSA public/private key-pair encryption class. | |||
An object of this type makes up one half of a public/private RSA key pair. Use the | |||
createKeyPair() method to create a matching pair for encoding/decoding. | |||
If you need to use this class in conjunction with a compatible enc/decryption | |||
algorithm on a webserver, you can achieve the same thing in PHP like this: | |||
@code | |||
include ('Math/BigInteger.php'); // get this from: phpseclib.sourceforge.net | |||
function applyToValue ($message, $key_part1, $key_part2) | |||
{ | |||
$result = new Math_BigInteger(); | |||
$zero = new Math_BigInteger(); | |||
$value = new Math_BigInteger (strrev ($message), 256); | |||
$part1 = new Math_BigInteger ($key_part1, 16); | |||
$part2 = new Math_BigInteger ($key_part2, 16); | |||
while (! $value->equals ($zero)) | |||
{ | |||
$result = $result->multiply ($part2); | |||
list ($value, $remainder) = $value->divide ($part2); | |||
$result = $result->add ($remainder->modPow ($part1, $part2)); | |||
} | |||
return ($result->toBytes()); | |||
} | |||
@endcode | |||
..or in Java with something like this: | |||
@code | |||
public class RSAKey | |||
{ | |||
static BigInteger applyToValue (BigInteger value, String key_part1, String key_part2) | |||
{ | |||
BigInteger result = BigInteger.ZERO; | |||
BigInteger part1 = new BigInteger (key_part1, 16); | |||
BigInteger part2 = new BigInteger (key_part2, 16); | |||
if (part1.equals (BigInteger.ZERO) || part2.equals (BigInteger.ZERO) | |||
|| value.compareTo (BigInteger.ZERO) <= 0) | |||
return result; | |||
while (! value.equals (BigInteger.ZERO)) | |||
{ | |||
result = result.multiply (part2); | |||
BigInteger[] div = value.divideAndRemainder (part2); | |||
value = div[0]; | |||
result = result.add (div[1].modPow (part1, part2)); | |||
} | |||
return result; | |||
} | |||
} | |||
@endcode | |||
Disclaimer: neither of the code snippets above are tested! Please let me know if you have | |||
any corrections for them! | |||
@tags{Cryptography} | |||
*/ | |||
class JUCE_API RSAKey | |||
{ | |||
public: | |||
//============================================================================== | |||
/** Creates a null key object. | |||
Initialise a pair of objects for use with the createKeyPair() method. | |||
*/ | |||
RSAKey(); | |||
/** Loads a key from an encoded string representation. | |||
This reloads a key from a string created by the toString() method. | |||
*/ | |||
explicit RSAKey (const String& stringRepresentation); | |||
/** Destructor. */ | |||
~RSAKey(); | |||
bool operator== (const RSAKey& other) const noexcept; | |||
bool operator!= (const RSAKey& other) const noexcept; | |||
//============================================================================== | |||
/** Turns the key into a string representation. | |||
This can be reloaded using the constructor that takes a string. | |||
*/ | |||
String toString() const; | |||
/** Returns true if the object is a valid key, or false if it was created by | |||
the default constructor. | |||
*/ | |||
bool isValid() const noexcept; | |||
//============================================================================== | |||
/** Encodes or decodes a value. | |||
Call this on the public key object to encode some data, then use the matching | |||
private key object to decode it. | |||
Returns false if the operation couldn't be completed, e.g. if this key hasn't been | |||
initialised correctly. | |||
NOTE: This method dumbly applies this key to this data. If you encode some data | |||
and then try to decode it with a key that doesn't match, this method will still | |||
happily do its job and return true, but the result won't be what you were expecting. | |||
It's your responsibility to check that the result is what you wanted. | |||
*/ | |||
bool applyToValue (BigInteger& value) const; | |||
//============================================================================== | |||
/** Creates a public/private key-pair. | |||
Each key will perform one-way encryption that can only be reversed by | |||
using the other key. | |||
The numBits parameter specifies the size of key, e.g. 128, 256, 512 bit. Bigger | |||
sizes are more secure, but this method will take longer to execute. | |||
The randomSeeds parameter lets you optionally pass it a set of values with | |||
which to seed the random number generation, improving the security of the | |||
keys generated. If you supply these, make sure you provide more than 2 values, | |||
and the more your provide, the better the security. | |||
*/ | |||
static void createKeyPair (RSAKey& publicKey, | |||
RSAKey& privateKey, | |||
int numBits, | |||
const int* randomSeeds = nullptr, | |||
int numRandomSeeds = 0); | |||
protected: | |||
//============================================================================== | |||
BigInteger part1, part2; | |||
private: | |||
//============================================================================== | |||
static BigInteger findBestCommonDivisor (const BigInteger& p, const BigInteger& q); | |||
JUCE_LEAK_DETECTOR (RSAKey) | |||
}; | |||
} // namespace juce |
@@ -0,0 +1,308 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
struct MD5Generator | |||
{ | |||
void processBlock (const void* data, size_t dataSize) noexcept | |||
{ | |||
auto bufferPos = ((count[0] >> 3) & 0x3f); | |||
count[0] += (uint32_t) (dataSize << 3); | |||
if (count[0] < ((uint32_t) dataSize << 3)) | |||
count[1]++; | |||
count[1] += (uint32_t) (dataSize >> 29); | |||
auto spaceLeft = (size_t) 64 - (size_t) bufferPos; | |||
size_t i = 0; | |||
if (dataSize >= spaceLeft) | |||
{ | |||
memcpy (buffer + bufferPos, data, spaceLeft); | |||
transform (buffer); | |||
for (i = spaceLeft; i + 64 <= dataSize; i += 64) | |||
transform (static_cast<const char*> (data) + i); | |||
bufferPos = 0; | |||
} | |||
memcpy (buffer + bufferPos, static_cast<const char*> (data) + i, dataSize - i); | |||
} | |||
void transform (const void* bufferToTransform) noexcept | |||
{ | |||
auto a = state[0]; | |||
auto b = state[1]; | |||
auto c = state[2]; | |||
auto d = state[3]; | |||
uint32_t x[16]; | |||
copyWithEndiannessConversion (x, bufferToTransform, 64); | |||
enum Constants | |||
{ | |||
S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20, | |||
S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21 | |||
}; | |||
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); | |||
FF (c, d, a, b, x[ 2], S13, 0x242070db); FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); | |||
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); FF (d, a, b, c, x[ 5], S12, 0x4787c62a); | |||
FF (c, d, a, b, x[ 6], S13, 0xa8304613); FF (b, c, d, a, x[ 7], S14, 0xfd469501); | |||
FF (a, b, c, d, x[ 8], S11, 0x698098d8); FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); | |||
FF (c, d, a, b, x[10], S13, 0xffff5bb1); FF (b, c, d, a, x[11], S14, 0x895cd7be); | |||
FF (a, b, c, d, x[12], S11, 0x6b901122); FF (d, a, b, c, x[13], S12, 0xfd987193); | |||
FF (c, d, a, b, x[14], S13, 0xa679438e); FF (b, c, d, a, x[15], S14, 0x49b40821); | |||
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); GG (d, a, b, c, x[ 6], S22, 0xc040b340); | |||
GG (c, d, a, b, x[11], S23, 0x265e5a51); GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); | |||
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); GG (d, a, b, c, x[10], S22, 0x02441453); | |||
GG (c, d, a, b, x[15], S23, 0xd8a1e681); GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); | |||
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); GG (d, a, b, c, x[14], S22, 0xc33707d6); | |||
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); GG (b, c, d, a, x[ 8], S24, 0x455a14ed); | |||
GG (a, b, c, d, x[13], S21, 0xa9e3e905); GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); | |||
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); | |||
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); HH (d, a, b, c, x[ 8], S32, 0x8771f681); | |||
HH (c, d, a, b, x[11], S33, 0x6d9d6122); HH (b, c, d, a, x[14], S34, 0xfde5380c); | |||
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); | |||
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); HH (b, c, d, a, x[10], S34, 0xbebfbc70); | |||
HH (a, b, c, d, x[13], S31, 0x289b7ec6); HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); | |||
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); HH (b, c, d, a, x[ 6], S34, 0x04881d05); | |||
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); HH (d, a, b, c, x[12], S32, 0xe6db99e5); | |||
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); | |||
II (a, b, c, d, x[ 0], S41, 0xf4292244); II (d, a, b, c, x[ 7], S42, 0x432aff97); | |||
II (c, d, a, b, x[14], S43, 0xab9423a7); II (b, c, d, a, x[ 5], S44, 0xfc93a039); | |||
II (a, b, c, d, x[12], S41, 0x655b59c3); II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); | |||
II (c, d, a, b, x[10], S43, 0xffeff47d); II (b, c, d, a, x[ 1], S44, 0x85845dd1); | |||
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); II (d, a, b, c, x[15], S42, 0xfe2ce6e0); | |||
II (c, d, a, b, x[ 6], S43, 0xa3014314); II (b, c, d, a, x[13], S44, 0x4e0811a1); | |||
II (a, b, c, d, x[ 4], S41, 0xf7537e82); II (d, a, b, c, x[11], S42, 0xbd3af235); | |||
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); II (b, c, d, a, x[ 9], S44, 0xeb86d391); | |||
state[0] += a; | |||
state[1] += b; | |||
state[2] += c; | |||
state[3] += d; | |||
} | |||
void finish (uint8_t* result) noexcept | |||
{ | |||
uint8_t encodedLength[8]; | |||
copyWithEndiannessConversion (encodedLength, count, 8); | |||
// Pad out to 56 mod 64. | |||
auto index = (count[0] >> 3) & 0x3f; | |||
auto paddingLength = (index < 56 ? 56 : 120) - index; | |||
uint8_t paddingBuffer[64] = { 0x80 }; // first byte is 0x80, remaining bytes are zero. | |||
processBlock (paddingBuffer, (size_t) paddingLength); | |||
processBlock (encodedLength, 8); | |||
copyWithEndiannessConversion (result, state, 16); | |||
} | |||
private: | |||
uint8_t buffer[64] = {}; | |||
uint32_t state[4] = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 }; | |||
uint32_t count[2] = {}; | |||
static void copyWithEndiannessConversion (void* output, const void* input, size_t numBytes) noexcept | |||
{ | |||
#if JUCE_LITTLE_ENDIAN | |||
memcpy (output, input, numBytes); | |||
#else | |||
auto dst = static_cast<uint8_t*> (output); | |||
auto src = static_cast<const uint8_t*> (input); | |||
for (size_t i = 0; i < numBytes; i += 4) | |||
{ | |||
dst[i + 0] = src[i + 3]; | |||
dst[i + 1] = src[i + 2]; | |||
dst[i + 2] = src[i + 1]; | |||
dst[i + 3] = src[i + 0]; | |||
} | |||
#endif | |||
} | |||
static uint32_t rotateLeft (uint32_t x, uint32_t n) noexcept { return (x << n) | (x >> (32 - n)); } | |||
static uint32_t F (uint32_t x, uint32_t y, uint32_t z) noexcept { return (x & y) | (~x & z); } | |||
static uint32_t G (uint32_t x, uint32_t y, uint32_t z) noexcept { return (x & z) | (y & ~z); } | |||
static uint32_t H (uint32_t x, uint32_t y, uint32_t z) noexcept { return x ^ y ^ z; } | |||
static uint32_t I (uint32_t x, uint32_t y, uint32_t z) noexcept { return y ^ (x | ~z); } | |||
static void FF (uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) noexcept | |||
{ | |||
a = rotateLeft (a + F (b, c, d) + x + ac, s) + b; | |||
} | |||
static void GG (uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) noexcept | |||
{ | |||
a = rotateLeft (a + G (b, c, d) + x + ac, s) + b; | |||
} | |||
static void HH (uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) noexcept | |||
{ | |||
a = rotateLeft (a + H (b, c, d) + x + ac, s) + b; | |||
} | |||
static void II (uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) noexcept | |||
{ | |||
a = rotateLeft (a + I (b, c, d) + x + ac, s) + b; | |||
} | |||
}; | |||
//============================================================================== | |||
MD5::MD5() = default; | |||
MD5::~MD5() = default; | |||
MD5::MD5 (const MD5&) = default; | |||
MD5& MD5::operator= (const MD5&) = default; | |||
MD5::MD5 (const void* data, size_t numBytes) noexcept | |||
{ | |||
MD5Generator generator; | |||
generator.processBlock (data, numBytes); | |||
generator.finish (result); | |||
} | |||
MD5::MD5 (const MemoryBlock& data) noexcept : MD5 (data.getData(), data.getSize()) {} | |||
MD5::MD5 (CharPointer_UTF8 utf8) noexcept : MD5 (utf8.getAddress(), utf8.getAddress() != nullptr ? utf8.sizeInBytes() - 1 : 0) {} | |||
MD5 MD5::fromUTF32 (StringRef text) | |||
{ | |||
MD5 m; | |||
MD5Generator generator; | |||
for (auto t = text.text; t.isNotEmpty();) | |||
{ | |||
auto unicodeChar = ByteOrder::swapIfBigEndian ((uint32_t) t.getAndAdvance()); | |||
generator.processBlock (&unicodeChar, sizeof (unicodeChar)); | |||
} | |||
generator.finish (m.result); | |||
return m; | |||
} | |||
MD5::MD5 (InputStream& input, int64 numBytesToRead) | |||
{ | |||
processStream (input, numBytesToRead); | |||
} | |||
MD5::MD5 (const File& file) | |||
{ | |||
FileInputStream fin (file); | |||
if (fin.openedOk()) | |||
processStream (fin, -1); | |||
} | |||
void MD5::processStream (InputStream& input, int64 numBytesToRead) | |||
{ | |||
MD5Generator generator; | |||
if (numBytesToRead < 0) | |||
numBytesToRead = std::numeric_limits<int64>::max(); | |||
while (numBytesToRead > 0) | |||
{ | |||
uint8_t tempBuffer[512]; | |||
auto bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer))); | |||
if (bytesRead <= 0) | |||
break; | |||
numBytesToRead -= bytesRead; | |||
generator.processBlock (tempBuffer, (size_t) bytesRead); | |||
} | |||
generator.finish (result); | |||
} | |||
//============================================================================== | |||
MemoryBlock MD5::getRawChecksumData() const | |||
{ | |||
return MemoryBlock (result, sizeof (result)); | |||
} | |||
String MD5::toHexString() const | |||
{ | |||
return String::toHexString (result, sizeof (result), 0); | |||
} | |||
//============================================================================== | |||
bool MD5::operator== (const MD5& other) const noexcept { return memcmp (result, other.result, sizeof (result)) == 0; } | |||
bool MD5::operator!= (const MD5& other) const noexcept { return ! operator== (other); } | |||
//============================================================================== | |||
//============================================================================== | |||
#if JUCE_UNIT_TESTS | |||
class MD5Tests : public UnitTest | |||
{ | |||
public: | |||
MD5Tests() | |||
: UnitTest ("MD5", UnitTestCategories::cryptography) | |||
{} | |||
void test (const char* input, const char* expected) | |||
{ | |||
{ | |||
MD5 hash (input, strlen (input)); | |||
expectEquals (hash.toHexString(), String (expected)); | |||
} | |||
{ | |||
MemoryInputStream m (input, strlen (input), false); | |||
MD5 hash (m); | |||
expectEquals (hash.toHexString(), String (expected)); | |||
} | |||
} | |||
void runTest() override | |||
{ | |||
beginTest ("MD5"); | |||
test ("", "d41d8cd98f00b204e9800998ecf8427e"); | |||
test ("The quick brown fox jumps over the lazy dog", "9e107d9d372bb6826bd81d3542a419d6"); | |||
test ("The quick brown fox jumps over the lazy dog.", "e4d909c290d0fb1ca068ffaddf22cbd0"); | |||
expectEquals (MD5 (CharPointer_UTF8(nullptr)).toHexString(), String ("d41d8cd98f00b204e9800998ecf8427e")); | |||
} | |||
}; | |||
static MD5Tests MD5UnitTests; | |||
#endif | |||
} // namespace juce |
@@ -0,0 +1,119 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
//============================================================================== | |||
/** | |||
MD5 checksum class. | |||
Create one of these with a block of source data or a stream, and it calculates | |||
the MD5 checksum of that data. | |||
You can then retrieve this checksum as a 16-byte block, or as a hex string. | |||
@see SHA256 | |||
@tags{Cryptography} | |||
*/ | |||
class JUCE_API MD5 | |||
{ | |||
public: | |||
//============================================================================== | |||
/** Creates a null MD5 object. */ | |||
MD5(); | |||
/** Creates a copy of another MD5. */ | |||
MD5 (const MD5&); | |||
/** Copies another MD5. */ | |||
MD5& operator= (const MD5&); | |||
//============================================================================== | |||
/** Creates a checksum for a block of binary data. */ | |||
explicit MD5 (const MemoryBlock&) noexcept; | |||
/** Creates a checksum for a block of binary data. */ | |||
MD5 (const void* data, size_t numBytes) noexcept; | |||
/** Creates a checksum for the input from a stream. | |||
This will read up to the given number of bytes from the stream, and produce the | |||
checksum of that. If the number of bytes to read is negative, it'll read | |||
until the stream is exhausted. | |||
*/ | |||
MD5 (InputStream& input, int64 numBytesToRead = -1); | |||
/** Creates a checksum for the contents of a file. */ | |||
explicit MD5 (const File&); | |||
/** Creates a checksum of the characters in a UTF-8 buffer. | |||
E.g. | |||
@code MD5 checksum (myString.toUTF8()); | |||
@endcode | |||
*/ | |||
explicit MD5 (CharPointer_UTF8 utf8Text) noexcept; | |||
/** Destructor. */ | |||
~MD5(); | |||
//============================================================================== | |||
/** Returns the checksum as a 16-byte block of data. */ | |||
MemoryBlock getRawChecksumData() const; | |||
/** Returns a pointer to the 16-byte array of result data. */ | |||
const uint8* getChecksumDataArray() const noexcept { return result; } | |||
/** Returns the checksum as a 32-digit hex string. */ | |||
String toHexString() const; | |||
/** Creates an MD5 from a little-endian UTF-32 encoded string. | |||
Note that this method is provided for backwards-compatibility with the old | |||
version of this class, which had a constructor that took a string and performed | |||
this operation on it. In new code, you shouldn't use this, and are recommended to | |||
use the constructor that takes a CharPointer_UTF8 instead. | |||
*/ | |||
static MD5 fromUTF32 (StringRef); | |||
//============================================================================== | |||
bool operator== (const MD5&) const noexcept; | |||
bool operator!= (const MD5&) const noexcept; | |||
private: | |||
//============================================================================== | |||
uint8 result[16] = {}; | |||
void processStream (InputStream&, int64); | |||
// This private constructor is declared here to prevent you accidentally passing a | |||
// String and having it unexpectedly call the constructor that takes a File. | |||
explicit MD5 (const String&) = delete; | |||
JUCE_LEAK_DETECTOR (MD5) | |||
}; | |||
} // namespace juce |
@@ -0,0 +1,259 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
struct SHA256Processor | |||
{ | |||
// expects 64 bytes of data | |||
void processFullBlock (const void* data) noexcept | |||
{ | |||
const uint32_t constants[] = | |||
{ | |||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, | |||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, | |||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, | |||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, | |||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, | |||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, | |||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, | |||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 | |||
}; | |||
uint32_t block[16], s[8]; | |||
memcpy (s, state, sizeof (s)); | |||
auto d = static_cast<const uint8_t*> (data); | |||
for (auto& b : block) | |||
{ | |||
b = (uint32_t (d[0]) << 24) | (uint32_t (d[1]) << 16) | (uint32_t (d[2]) << 8) | d[3]; | |||
d += 4; | |||
} | |||
auto convolve = [&] (uint32_t i, uint32_t j) | |||
{ | |||
s[(7 - i) & 7] += S1 (s[(4 - i) & 7]) + ch (s[(4 - i) & 7], s[(5 - i) & 7], s[(6 - i) & 7]) + constants[i + j] | |||
+ (j != 0 ? (block[i & 15] += s1 (block[(i - 2) & 15]) + block[(i - 7) & 15] + s0 (block[(i - 15) & 15])) | |||
: block[i]); | |||
s[(3 - i) & 7] += s[(7 - i) & 7]; | |||
s[(7 - i) & 7] += S0 (s[(0 - i) & 7]) + maj (s[(0 - i) & 7], s[(1 - i) & 7], s[(2 - i) & 7]); | |||
}; | |||
for (uint32_t j = 0; j < 64; j += 16) | |||
for (uint32_t i = 0; i < 16; ++i) | |||
convolve (i, j); | |||
for (int i = 0; i < 8; ++i) | |||
state[i] += s[i]; | |||
length += 64; | |||
} | |||
void processFinalBlock (const void* data, uint32_t numBytes) noexcept | |||
{ | |||
jassert (numBytes < 64); | |||
length += numBytes; | |||
length *= 8; // (the length is stored as a count of bits, not bytes) | |||
uint8_t finalBlocks[128]; | |||
memcpy (finalBlocks, data, numBytes); | |||
finalBlocks[numBytes++] = 128; // append a '1' bit | |||
while (numBytes != 56 && numBytes < 64 + 56) | |||
finalBlocks[numBytes++] = 0; // pad with zeros.. | |||
for (int i = 8; --i >= 0;) | |||
finalBlocks[numBytes++] = (uint8_t) (length >> (i * 8)); // append the length. | |||
jassert (numBytes == 64 || numBytes == 128); | |||
processFullBlock (finalBlocks); | |||
if (numBytes > 64) | |||
processFullBlock (finalBlocks + 64); | |||
} | |||
void copyResult (uint8_t* result) const noexcept | |||
{ | |||
for (auto s : state) | |||
{ | |||
*result++ = (uint8_t) (s >> 24); | |||
*result++ = (uint8_t) (s >> 16); | |||
*result++ = (uint8_t) (s >> 8); | |||
*result++ = (uint8_t) s; | |||
} | |||
} | |||
void processStream (InputStream& input, int64_t numBytesToRead, uint8_t* result) | |||
{ | |||
if (numBytesToRead < 0) | |||
numBytesToRead = std::numeric_limits<int64_t>::max(); | |||
for (;;) | |||
{ | |||
uint8_t buffer[64]; | |||
auto bytesRead = input.read (buffer, (int) jmin (numBytesToRead, (int64_t) sizeof (buffer))); | |||
if (bytesRead < (int) sizeof (buffer)) | |||
{ | |||
processFinalBlock (buffer, (unsigned int) bytesRead); | |||
break; | |||
} | |||
numBytesToRead -= (int64_t) sizeof (buffer); | |||
processFullBlock (buffer); | |||
} | |||
copyResult (result); | |||
} | |||
private: | |||
uint32_t state[8] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, | |||
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 }; | |||
uint64_t length = 0; | |||
static uint32_t rotate (uint32_t x, uint32_t y) noexcept { return (x >> y) | (x << (32 - y)); } | |||
static uint32_t ch (uint32_t x, uint32_t y, uint32_t z) noexcept { return z ^ ((y ^ z) & x); } | |||
static uint32_t maj (uint32_t x, uint32_t y, uint32_t z) noexcept { return y ^ ((y ^ z) & (x ^ y)); } | |||
static uint32_t s0 (uint32_t x) noexcept { return rotate (x, 7) ^ rotate (x, 18) ^ (x >> 3); } | |||
static uint32_t s1 (uint32_t x) noexcept { return rotate (x, 17) ^ rotate (x, 19) ^ (x >> 10); } | |||
static uint32_t S0 (uint32_t x) noexcept { return rotate (x, 2) ^ rotate (x, 13) ^ rotate (x, 22); } | |||
static uint32_t S1 (uint32_t x) noexcept { return rotate (x, 6) ^ rotate (x, 11) ^ rotate (x, 25); } | |||
}; | |||
//============================================================================== | |||
SHA256::SHA256() = default; | |||
SHA256::~SHA256() = default; | |||
SHA256::SHA256 (const SHA256&) = default; | |||
SHA256& SHA256::operator= (const SHA256&) = default; | |||
SHA256::SHA256 (const MemoryBlock& data) | |||
{ | |||
process (data.getData(), data.getSize()); | |||
} | |||
SHA256::SHA256 (const void* data, size_t numBytes) | |||
{ | |||
process (data, numBytes); | |||
} | |||
SHA256::SHA256 (InputStream& input, int64 numBytesToRead) | |||
{ | |||
SHA256Processor processor; | |||
processor.processStream (input, numBytesToRead, result); | |||
} | |||
SHA256::SHA256 (const File& file) | |||
{ | |||
FileInputStream fin (file); | |||
if (fin.getStatus().wasOk()) | |||
{ | |||
SHA256Processor processor; | |||
processor.processStream (fin, -1, result); | |||
} | |||
else | |||
{ | |||
zerostruct (result); | |||
} | |||
} | |||
SHA256::SHA256 (CharPointer_UTF8 utf8) noexcept | |||
{ | |||
jassert (utf8.getAddress() != nullptr); | |||
process (utf8.getAddress(), utf8.sizeInBytes() - 1); | |||
} | |||
void SHA256::process (const void* data, size_t numBytes) | |||
{ | |||
MemoryInputStream m (data, numBytes, false); | |||
SHA256Processor processor; | |||
processor.processStream (m, -1, result); | |||
} | |||
MemoryBlock SHA256::getRawData() const | |||
{ | |||
return MemoryBlock (result, sizeof (result)); | |||
} | |||
String SHA256::toHexString() const | |||
{ | |||
return String::toHexString (result, sizeof (result), 0); | |||
} | |||
bool SHA256::operator== (const SHA256& other) const noexcept { return memcmp (result, other.result, sizeof (result)) == 0; } | |||
bool SHA256::operator!= (const SHA256& other) const noexcept { return ! operator== (other); } | |||
//============================================================================== | |||
#if JUCE_UNIT_TESTS | |||
class SHA256Tests : public UnitTest | |||
{ | |||
public: | |||
SHA256Tests() | |||
: UnitTest ("SHA-256", UnitTestCategories::cryptography) | |||
{} | |||
void test (const char* input, const char* expected) | |||
{ | |||
{ | |||
SHA256 hash (input, strlen (input)); | |||
expectEquals (hash.toHexString(), String (expected)); | |||
} | |||
{ | |||
CharPointer_UTF8 utf8 (input); | |||
SHA256 hash (utf8); | |||
expectEquals (hash.toHexString(), String (expected)); | |||
} | |||
{ | |||
MemoryInputStream m (input, strlen (input), false); | |||
SHA256 hash (m); | |||
expectEquals (hash.toHexString(), String (expected)); | |||
} | |||
} | |||
void runTest() override | |||
{ | |||
beginTest ("SHA256"); | |||
test ("", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); | |||
test ("The quick brown fox jumps over the lazy dog", "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"); | |||
test ("The quick brown fox jumps over the lazy dog.", "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c"); | |||
} | |||
}; | |||
static SHA256Tests sha256UnitTests; | |||
#endif | |||
} // namespace juce |
@@ -0,0 +1,108 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
//============================================================================== | |||
/** | |||
SHA-256 secure hash generator. | |||
Create one of these objects from a block of source data or a stream, and it | |||
calculates the SHA-256 hash of that data. | |||
You can retrieve the hash as a raw 32-byte block, or as a 64-digit hex string. | |||
@see MD5 | |||
@tags{Cryptography} | |||
*/ | |||
class JUCE_API SHA256 | |||
{ | |||
public: | |||
//============================================================================== | |||
/** Creates an empty SHA256 object. | |||
The default constructor just creates a hash filled with zeros. (This is not | |||
equal to the hash of an empty block of data). | |||
*/ | |||
SHA256(); | |||
/** Destructor. */ | |||
~SHA256(); | |||
/** Creates a copy of another SHA256. */ | |||
SHA256 (const SHA256&); | |||
/** Copies another SHA256. */ | |||
SHA256& operator= (const SHA256&); | |||
//============================================================================== | |||
/** Creates a hash from a block of raw data. */ | |||
explicit SHA256 (const MemoryBlock& data); | |||
/** Creates a hash from a block of raw data. */ | |||
SHA256 (const void* data, size_t numBytes); | |||
/** Creates a hash from the contents of a stream. | |||
This will read from the stream until the stream is exhausted, or until | |||
maxBytesToRead bytes have been read. If maxBytesToRead is negative, the entire | |||
stream will be read. | |||
*/ | |||
SHA256 (InputStream& input, int64 maxBytesToRead = -1); | |||
/** Reads a file and generates the hash of its contents. | |||
If the file can't be opened, the hash will be left uninitialised (i.e. full | |||
of zeros). | |||
*/ | |||
explicit SHA256 (const File& file); | |||
/** Creates a checksum from a UTF-8 buffer. | |||
E.g. | |||
@code SHA256 checksum (myString.toUTF8()); | |||
@endcode | |||
*/ | |||
explicit SHA256 (CharPointer_UTF8 utf8Text) noexcept; | |||
//============================================================================== | |||
/** Returns the hash as a 32-byte block of data. */ | |||
MemoryBlock getRawData() const; | |||
/** Returns the checksum as a 64-digit hex string. */ | |||
String toHexString() const; | |||
//============================================================================== | |||
bool operator== (const SHA256&) const noexcept; | |||
bool operator!= (const SHA256&) const noexcept; | |||
private: | |||
//============================================================================== | |||
uint8 result[32] = {}; | |||
void process (const void*, size_t); | |||
JUCE_LEAK_DETECTOR (SHA256) | |||
}; | |||
} // namespace juce |
@@ -0,0 +1,660 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
struct WhirlpoolProcessor | |||
{ | |||
WhirlpoolProcessor() = default; | |||
void processStream (InputStream& input, int64_t numBytesToRead, uint8_t* result) | |||
{ | |||
if (numBytesToRead < 0) | |||
numBytesToRead = std::numeric_limits<int64_t>::max(); | |||
for (;;) | |||
{ | |||
uint8_t data[64]; | |||
auto bytesRead = input.read (data, (int) jmin (numBytesToRead, (int64_t) sizeof (data))); | |||
if (bytesRead < 0) | |||
break; | |||
add (data, bytesRead * 8); | |||
if (bytesRead < (int) sizeof (data)) | |||
break; | |||
numBytesToRead -= (int64_t) sizeof (data); | |||
} | |||
finalize (result); | |||
} | |||
uint8_t bitLength[32] = {}; | |||
uint8_t buffer[64] = {}; | |||
int bufferBits = 0, bufferPos = 0; | |||
uint64_t hash[8] = {}; | |||
private: | |||
void add (const uint8_t* source, int numBits) noexcept | |||
{ | |||
int sourcePos = 0; // index of leftmost source uint8_t containing data (1 to 8 bits) | |||
int sourceGap = (8 - (numBits & 7)) & 7; // space on source[sourcePos] | |||
int bufferRem = bufferBits & 7; // occupied bits on buffer[bufferPos] | |||
uint64_t value = (uint64_t) numBits, carry = 0; | |||
for (int i = 32; --i >= 0 && (carry != 0 || value != 0);) | |||
{ | |||
carry += bitLength[i] + ((uint32) value & 0xff); | |||
bitLength[i] = (uint8_t) carry; | |||
carry >>= 8; | |||
value >>= 8; | |||
} | |||
uint32 b = 0; | |||
while (numBits > 8) | |||
{ | |||
b = ((source[sourcePos] << sourceGap) & 0xff) | |||
| (uint32) ((source[sourcePos + 1] & 0xff) >> (8 - sourceGap)); | |||
buffer[bufferPos++] |= (uint8_t) (b >> bufferRem); | |||
bufferBits += 8 - bufferRem; | |||
if (bufferBits == 64 * 8) | |||
{ | |||
processNextBuffer(); | |||
bufferBits = bufferPos = 0; | |||
} | |||
buffer[bufferPos] = static_cast<uint8_t> (b << (8 - bufferRem)); | |||
bufferBits += bufferRem; | |||
numBits -= 8; | |||
++sourcePos; | |||
} | |||
if (numBits > 0) | |||
{ | |||
b = (source[sourcePos] << sourceGap) & 0xff; | |||
buffer[bufferPos] = static_cast<uint8_t> (buffer[bufferPos] | (b >> bufferRem)); | |||
} | |||
else | |||
{ | |||
b = 0; | |||
} | |||
if (bufferRem + numBits < 8) | |||
{ | |||
bufferBits += numBits; | |||
} | |||
else | |||
{ | |||
++bufferPos; | |||
bufferBits += 8 - bufferRem; | |||
numBits -= 8 - bufferRem; | |||
if (bufferBits == 64 * 8) | |||
{ | |||
processNextBuffer(); | |||
bufferBits = bufferPos = 0; | |||
} | |||
buffer[bufferPos] = static_cast<uint8_t> (b << (8 - bufferRem)); | |||
bufferBits += numBits; | |||
} | |||
} | |||
void finalize (uint8_t* result) noexcept | |||
{ | |||
// append a '1'-bit | |||
buffer[bufferPos] = static_cast<uint8_t> (buffer[bufferPos] | (0x80u >> (bufferBits & 7))); | |||
bufferPos++; | |||
// pad with zero bits to complete (N*(64*8) - (32*8)) bits | |||
if (bufferPos > 32) | |||
{ | |||
if (bufferPos < 64) | |||
zeromem (buffer + bufferPos, (size_t) (64 - bufferPos)); | |||
processNextBuffer(); | |||
bufferPos = 0; | |||
} | |||
if (bufferPos < 32) | |||
zeromem (buffer + bufferPos, (size_t) (32 - bufferPos)); | |||
bufferPos = 32; | |||
memcpy (buffer + 32, bitLength, 32); // append bit length of hashed data | |||
processNextBuffer(); | |||
uint8_t* digest = result; | |||
for (auto h : hash) | |||
{ | |||
*digest++ = (uint8_t) (h >> 56); | |||
*digest++ = (uint8_t) (h >> 48); | |||
*digest++ = (uint8_t) (h >> 40); | |||
*digest++ = (uint8_t) (h >> 32); | |||
*digest++ = (uint8_t) (h >> 24); | |||
*digest++ = (uint8_t) (h >> 16); | |||
*digest++ = (uint8_t) (h >> 8); | |||
*digest++ = (uint8_t) h; | |||
} | |||
} | |||
void processNextBuffer() noexcept | |||
{ | |||
static const uint64_t rc[] = | |||
{ 0x1823c6e887b8014full, 0x36a6d2f5796f9152ull, 0x60bc9b8ea30c7b35ull, 0x1de0d7c22e4bfe57ull, 0x157737e59ff04adaull, | |||
0x58c9290ab1a06b85ull, 0xbd5d10f4cb3e0567ull, 0xe427418ba77d95d8ull, 0xfbee7c66dd17479eull, 0xca2dbf07ad5a8333ull | |||
}; | |||
static const uint64_t C0[] = | |||
{ 0x18186018c07830d8ull, 0x23238c2305af4626ull, 0xc6c63fc67ef991b8ull, 0xe8e887e8136fcdfbull, 0x878726874ca113cbull, 0xb8b8dab8a9626d11ull, 0x0101040108050209ull, 0x4f4f214f426e9e0dull, | |||
0x3636d836adee6c9bull, 0xa6a6a2a6590451ffull, 0xd2d26fd2debdb90cull, 0xf5f5f3f5fb06f70eull, 0x7979f979ef80f296ull, 0x6f6fa16f5fcede30ull, 0x91917e91fcef3f6dull, 0x52525552aa07a4f8ull, | |||
0x60609d6027fdc047ull, 0xbcbccabc89766535ull, 0x9b9b569baccd2b37ull, 0x8e8e028e048c018aull, 0xa3a3b6a371155bd2ull, 0x0c0c300c603c186cull, 0x7b7bf17bff8af684ull, 0x3535d435b5e16a80ull, | |||
0x1d1d741de8693af5ull, 0xe0e0a7e05347ddb3ull, 0xd7d77bd7f6acb321ull, 0xc2c22fc25eed999cull, 0x2e2eb82e6d965c43ull, 0x4b4b314b627a9629ull, 0xfefedffea321e15dull, 0x575741578216aed5ull, | |||
0x15155415a8412abdull, 0x7777c1779fb6eee8ull, 0x3737dc37a5eb6e92ull, 0xe5e5b3e57b56d79eull, 0x9f9f469f8cd92313ull, 0xf0f0e7f0d317fd23ull, 0x4a4a354a6a7f9420ull, 0xdada4fda9e95a944ull, | |||
0x58587d58fa25b0a2ull, 0xc9c903c906ca8fcfull, 0x2929a429558d527cull, 0x0a0a280a5022145aull, 0xb1b1feb1e14f7f50ull, 0xa0a0baa0691a5dc9ull, 0x6b6bb16b7fdad614ull, 0x85852e855cab17d9ull, | |||
0xbdbdcebd8173673cull, 0x5d5d695dd234ba8full, 0x1010401080502090ull, 0xf4f4f7f4f303f507ull, 0xcbcb0bcb16c08bddull, 0x3e3ef83eedc67cd3ull, 0x0505140528110a2dull, 0x676781671fe6ce78ull, | |||
0xe4e4b7e47353d597ull, 0x27279c2725bb4e02ull, 0x4141194132588273ull, 0x8b8b168b2c9d0ba7ull, 0xa7a7a6a7510153f6ull, 0x7d7de97dcf94fab2ull, 0x95956e95dcfb3749ull, 0xd8d847d88e9fad56ull, | |||
0xfbfbcbfb8b30eb70ull, 0xeeee9fee2371c1cdull, 0x7c7ced7cc791f8bbull, 0x6666856617e3cc71ull, 0xdddd53dda68ea77bull, 0x17175c17b84b2eafull, 0x4747014702468e45ull, 0x9e9e429e84dc211aull, | |||
0xcaca0fca1ec589d4ull, 0x2d2db42d75995a58ull, 0xbfbfc6bf9179632eull, 0x07071c07381b0e3full, 0xadad8ead012347acull, 0x5a5a755aea2fb4b0ull, 0x838336836cb51befull, 0x3333cc3385ff66b6ull, | |||
0x636391633ff2c65cull, 0x02020802100a0412ull, 0xaaaa92aa39384993ull, 0x7171d971afa8e2deull, 0xc8c807c80ecf8dc6ull, 0x19196419c87d32d1ull, 0x494939497270923bull, 0xd9d943d9869aaf5full, | |||
0xf2f2eff2c31df931ull, 0xe3e3abe34b48dba8ull, 0x5b5b715be22ab6b9ull, 0x88881a8834920dbcull, 0x9a9a529aa4c8293eull, 0x262698262dbe4c0bull, 0x3232c8328dfa64bfull, 0xb0b0fab0e94a7d59ull, | |||
0xe9e983e91b6acff2ull, 0x0f0f3c0f78331e77ull, 0xd5d573d5e6a6b733ull, 0x80803a8074ba1df4ull, 0xbebec2be997c6127ull, 0xcdcd13cd26de87ebull, 0x3434d034bde46889ull, 0x48483d487a759032ull, | |||
0xffffdbffab24e354ull, 0x7a7af57af78ff48dull, 0x90907a90f4ea3d64ull, 0x5f5f615fc23ebe9dull, 0x202080201da0403dull, 0x6868bd6867d5d00full, 0x1a1a681ad07234caull, 0xaeae82ae192c41b7ull, | |||
0xb4b4eab4c95e757dull, 0x54544d549a19a8ceull, 0x93937693ece53b7full, 0x222288220daa442full, 0x64648d6407e9c863ull, 0xf1f1e3f1db12ff2aull, 0x7373d173bfa2e6ccull, 0x12124812905a2482ull, | |||
0x40401d403a5d807aull, 0x0808200840281048ull, 0xc3c32bc356e89b95ull, 0xecec97ec337bc5dfull, 0xdbdb4bdb9690ab4dull, 0xa1a1bea1611f5fc0ull, 0x8d8d0e8d1c830791ull, 0x3d3df43df5c97ac8ull, | |||
0x97976697ccf1335bull, 0x0000000000000000ull, 0xcfcf1bcf36d483f9ull, 0x2b2bac2b4587566eull, 0x7676c57697b3ece1ull, 0x8282328264b019e6ull, 0xd6d67fd6fea9b128ull, 0x1b1b6c1bd87736c3ull, | |||
0xb5b5eeb5c15b7774ull, 0xafaf86af112943beull, 0x6a6ab56a77dfd41dull, 0x50505d50ba0da0eaull, 0x45450945124c8a57ull, 0xf3f3ebf3cb18fb38ull, 0x3030c0309df060adull, 0xefef9bef2b74c3c4ull, | |||
0x3f3ffc3fe5c37edaull, 0x55554955921caac7ull, 0xa2a2b2a2791059dbull, 0xeaea8fea0365c9e9ull, 0x656589650fecca6aull, 0xbabad2bab9686903ull, 0x2f2fbc2f65935e4aull, 0xc0c027c04ee79d8eull, | |||
0xdede5fdebe81a160ull, 0x1c1c701ce06c38fcull, 0xfdfdd3fdbb2ee746ull, 0x4d4d294d52649a1full, 0x92927292e4e03976ull, 0x7575c9758fbceafaull, 0x06061806301e0c36ull, 0x8a8a128a249809aeull, | |||
0xb2b2f2b2f940794bull, 0xe6e6bfe66359d185ull, 0x0e0e380e70361c7eull, 0x1f1f7c1ff8633ee7ull, 0x6262956237f7c455ull, 0xd4d477d4eea3b53aull, 0xa8a89aa829324d81ull, 0x96966296c4f43152ull, | |||
0xf9f9c3f99b3aef62ull, 0xc5c533c566f697a3ull, 0x2525942535b14a10ull, 0x59597959f220b2abull, 0x84842a8454ae15d0ull, 0x7272d572b7a7e4c5ull, 0x3939e439d5dd72ecull, 0x4c4c2d4c5a619816ull, | |||
0x5e5e655eca3bbc94ull, 0x7878fd78e785f09full, 0x3838e038ddd870e5ull, 0x8c8c0a8c14860598ull, 0xd1d163d1c6b2bf17ull, 0xa5a5aea5410b57e4ull, 0xe2e2afe2434dd9a1ull, 0x616199612ff8c24eull, | |||
0xb3b3f6b3f1457b42ull, 0x2121842115a54234ull, 0x9c9c4a9c94d62508ull, 0x1e1e781ef0663ceeull, 0x4343114322528661ull, 0xc7c73bc776fc93b1ull, 0xfcfcd7fcb32be54full, 0x0404100420140824ull, | |||
0x51515951b208a2e3ull, 0x99995e99bcc72f25ull, 0x6d6da96d4fc4da22ull, 0x0d0d340d68391a65ull, 0xfafacffa8335e979ull, 0xdfdf5bdfb684a369ull, 0x7e7ee57ed79bfca9ull, 0x242490243db44819ull, | |||
0x3b3bec3bc5d776feull, 0xabab96ab313d4b9aull, 0xcece1fce3ed181f0ull, 0x1111441188552299ull, 0x8f8f068f0c890383ull, 0x4e4e254e4a6b9c04ull, 0xb7b7e6b7d1517366ull, 0xebeb8beb0b60cbe0ull, | |||
0x3c3cf03cfdcc78c1ull, 0x81813e817cbf1ffdull, 0x94946a94d4fe3540ull, 0xf7f7fbf7eb0cf31cull, 0xb9b9deb9a1676f18ull, 0x13134c13985f268bull, 0x2c2cb02c7d9c5851ull, 0xd3d36bd3d6b8bb05ull, | |||
0xe7e7bbe76b5cd38cull, 0x6e6ea56e57cbdc39ull, 0xc4c437c46ef395aaull, 0x03030c03180f061bull, 0x565645568a13acdcull, 0x44440d441a49885eull, 0x7f7fe17fdf9efea0ull, 0xa9a99ea921374f88ull, | |||
0x2a2aa82a4d825467ull, 0xbbbbd6bbb16d6b0aull, 0xc1c123c146e29f87ull, 0x53535153a202a6f1ull, 0xdcdc57dcae8ba572ull, 0x0b0b2c0b58271653ull, 0x9d9d4e9d9cd32701ull, 0x6c6cad6c47c1d82bull, | |||
0x3131c43195f562a4ull, 0x7474cd7487b9e8f3ull, 0xf6f6fff6e309f115ull, 0x464605460a438c4cull, 0xacac8aac092645a5ull, 0x89891e893c970fb5ull, 0x14145014a04428b4ull, 0xe1e1a3e15b42dfbaull, | |||
0x16165816b04e2ca6ull, 0x3a3ae83acdd274f7ull, 0x6969b9696fd0d206ull, 0x09092409482d1241ull, 0x7070dd70a7ade0d7ull, 0xb6b6e2b6d954716full, 0xd0d067d0ceb7bd1eull, 0xeded93ed3b7ec7d6ull, | |||
0xcccc17cc2edb85e2ull, 0x424215422a578468ull, 0x98985a98b4c22d2cull, 0xa4a4aaa4490e55edull, 0x2828a0285d885075ull, 0x5c5c6d5cda31b886ull, 0xf8f8c7f8933fed6bull, 0x8686228644a411c2ull | |||
}; | |||
static const uint64_t C1[] = | |||
{ 0xd818186018c07830ull, 0x2623238c2305af46ull, 0xb8c6c63fc67ef991ull, 0xfbe8e887e8136fcdull, 0xcb878726874ca113ull, 0x11b8b8dab8a9626dull, 0x0901010401080502ull, 0x0d4f4f214f426e9eull, | |||
0x9b3636d836adee6cull, 0xffa6a6a2a6590451ull, 0x0cd2d26fd2debdb9ull, 0x0ef5f5f3f5fb06f7ull, 0x967979f979ef80f2ull, 0x306f6fa16f5fcedeull, 0x6d91917e91fcef3full, 0xf852525552aa07a4ull, | |||
0x4760609d6027fdc0ull, 0x35bcbccabc897665ull, 0x379b9b569baccd2bull, 0x8a8e8e028e048c01ull, 0xd2a3a3b6a371155bull, 0x6c0c0c300c603c18ull, 0x847b7bf17bff8af6ull, 0x803535d435b5e16aull, | |||
0xf51d1d741de8693aull, 0xb3e0e0a7e05347ddull, 0x21d7d77bd7f6acb3ull, 0x9cc2c22fc25eed99ull, 0x432e2eb82e6d965cull, 0x294b4b314b627a96ull, 0x5dfefedffea321e1ull, 0xd5575741578216aeull, | |||
0xbd15155415a8412aull, 0xe87777c1779fb6eeull, 0x923737dc37a5eb6eull, 0x9ee5e5b3e57b56d7ull, 0x139f9f469f8cd923ull, 0x23f0f0e7f0d317fdull, 0x204a4a354a6a7f94ull, 0x44dada4fda9e95a9ull, | |||
0xa258587d58fa25b0ull, 0xcfc9c903c906ca8full, 0x7c2929a429558d52ull, 0x5a0a0a280a502214ull, 0x50b1b1feb1e14f7full, 0xc9a0a0baa0691a5dull, 0x146b6bb16b7fdad6ull, 0xd985852e855cab17ull, | |||
0x3cbdbdcebd817367ull, 0x8f5d5d695dd234baull, 0x9010104010805020ull, 0x07f4f4f7f4f303f5ull, 0xddcbcb0bcb16c08bull, 0xd33e3ef83eedc67cull, 0x2d0505140528110aull, 0x78676781671fe6ceull, | |||
0x97e4e4b7e47353d5ull, 0x0227279c2725bb4eull, 0x7341411941325882ull, 0xa78b8b168b2c9d0bull, 0xf6a7a7a6a7510153ull, 0xb27d7de97dcf94faull, 0x4995956e95dcfb37ull, 0x56d8d847d88e9fadull, | |||
0x70fbfbcbfb8b30ebull, 0xcdeeee9fee2371c1ull, 0xbb7c7ced7cc791f8ull, 0x716666856617e3ccull, 0x7bdddd53dda68ea7ull, 0xaf17175c17b84b2eull, 0x454747014702468eull, 0x1a9e9e429e84dc21ull, | |||
0xd4caca0fca1ec589ull, 0x582d2db42d75995aull, 0x2ebfbfc6bf917963ull, 0x3f07071c07381b0eull, 0xacadad8ead012347ull, 0xb05a5a755aea2fb4ull, 0xef838336836cb51bull, 0xb63333cc3385ff66ull, | |||
0x5c636391633ff2c6ull, 0x1202020802100a04ull, 0x93aaaa92aa393849ull, 0xde7171d971afa8e2ull, 0xc6c8c807c80ecf8dull, 0xd119196419c87d32ull, 0x3b49493949727092ull, 0x5fd9d943d9869aafull, | |||
0x31f2f2eff2c31df9ull, 0xa8e3e3abe34b48dbull, 0xb95b5b715be22ab6ull, 0xbc88881a8834920dull, 0x3e9a9a529aa4c829ull, 0x0b262698262dbe4cull, 0xbf3232c8328dfa64ull, 0x59b0b0fab0e94a7dull, | |||
0xf2e9e983e91b6acfull, 0x770f0f3c0f78331eull, 0x33d5d573d5e6a6b7ull, 0xf480803a8074ba1dull, 0x27bebec2be997c61ull, 0xebcdcd13cd26de87ull, 0x893434d034bde468ull, 0x3248483d487a7590ull, | |||
0x54ffffdbffab24e3ull, 0x8d7a7af57af78ff4ull, 0x6490907a90f4ea3dull, 0x9d5f5f615fc23ebeull, 0x3d202080201da040ull, 0x0f6868bd6867d5d0ull, 0xca1a1a681ad07234ull, 0xb7aeae82ae192c41ull, | |||
0x7db4b4eab4c95e75ull, 0xce54544d549a19a8ull, 0x7f93937693ece53bull, 0x2f222288220daa44ull, 0x6364648d6407e9c8ull, 0x2af1f1e3f1db12ffull, 0xcc7373d173bfa2e6ull, 0x8212124812905a24ull, | |||
0x7a40401d403a5d80ull, 0x4808082008402810ull, 0x95c3c32bc356e89bull, 0xdfecec97ec337bc5ull, 0x4ddbdb4bdb9690abull, 0xc0a1a1bea1611f5full, 0x918d8d0e8d1c8307ull, 0xc83d3df43df5c97aull, | |||
0x5b97976697ccf133ull, 0x0000000000000000ull, 0xf9cfcf1bcf36d483ull, 0x6e2b2bac2b458756ull, 0xe17676c57697b3ecull, 0xe68282328264b019ull, 0x28d6d67fd6fea9b1ull, 0xc31b1b6c1bd87736ull, | |||
0x74b5b5eeb5c15b77ull, 0xbeafaf86af112943ull, 0x1d6a6ab56a77dfd4ull, 0xea50505d50ba0da0ull, 0x5745450945124c8aull, 0x38f3f3ebf3cb18fbull, 0xad3030c0309df060ull, 0xc4efef9bef2b74c3ull, | |||
0xda3f3ffc3fe5c37eull, 0xc755554955921caaull, 0xdba2a2b2a2791059ull, 0xe9eaea8fea0365c9ull, 0x6a656589650feccaull, 0x03babad2bab96869ull, 0x4a2f2fbc2f65935eull, 0x8ec0c027c04ee79dull, | |||
0x60dede5fdebe81a1ull, 0xfc1c1c701ce06c38ull, 0x46fdfdd3fdbb2ee7ull, 0x1f4d4d294d52649aull, 0x7692927292e4e039ull, 0xfa7575c9758fbceaull, 0x3606061806301e0cull, 0xae8a8a128a249809ull, | |||
0x4bb2b2f2b2f94079ull, 0x85e6e6bfe66359d1ull, 0x7e0e0e380e70361cull, 0xe71f1f7c1ff8633eull, 0x556262956237f7c4ull, 0x3ad4d477d4eea3b5ull, 0x81a8a89aa829324dull, 0x5296966296c4f431ull, | |||
0x62f9f9c3f99b3aefull, 0xa3c5c533c566f697ull, 0x102525942535b14aull, 0xab59597959f220b2ull, 0xd084842a8454ae15ull, 0xc57272d572b7a7e4ull, 0xec3939e439d5dd72ull, 0x164c4c2d4c5a6198ull, | |||
0x945e5e655eca3bbcull, 0x9f7878fd78e785f0ull, 0xe53838e038ddd870ull, 0x988c8c0a8c148605ull, 0x17d1d163d1c6b2bfull, 0xe4a5a5aea5410b57ull, 0xa1e2e2afe2434dd9ull, 0x4e616199612ff8c2ull, | |||
0x42b3b3f6b3f1457bull, 0x342121842115a542ull, 0x089c9c4a9c94d625ull, 0xee1e1e781ef0663cull, 0x6143431143225286ull, 0xb1c7c73bc776fc93ull, 0x4ffcfcd7fcb32be5ull, 0x2404041004201408ull, | |||
0xe351515951b208a2ull, 0x2599995e99bcc72full, 0x226d6da96d4fc4daull, 0x650d0d340d68391aull, 0x79fafacffa8335e9ull, 0x69dfdf5bdfb684a3ull, 0xa97e7ee57ed79bfcull, 0x19242490243db448ull, | |||
0xfe3b3bec3bc5d776ull, 0x9aabab96ab313d4bull, 0xf0cece1fce3ed181ull, 0x9911114411885522ull, 0x838f8f068f0c8903ull, 0x044e4e254e4a6b9cull, 0x66b7b7e6b7d15173ull, 0xe0ebeb8beb0b60cbull, | |||
0xc13c3cf03cfdcc78ull, 0xfd81813e817cbf1full, 0x4094946a94d4fe35ull, 0x1cf7f7fbf7eb0cf3ull, 0x18b9b9deb9a1676full, 0x8b13134c13985f26ull, 0x512c2cb02c7d9c58ull, 0x05d3d36bd3d6b8bbull, | |||
0x8ce7e7bbe76b5cd3ull, 0x396e6ea56e57cbdcull, 0xaac4c437c46ef395ull, 0x1b03030c03180f06ull, 0xdc565645568a13acull, 0x5e44440d441a4988ull, 0xa07f7fe17fdf9efeull, 0x88a9a99ea921374full, | |||
0x672a2aa82a4d8254ull, 0x0abbbbd6bbb16d6bull, 0x87c1c123c146e29full, 0xf153535153a202a6ull, 0x72dcdc57dcae8ba5ull, 0x530b0b2c0b582716ull, 0x019d9d4e9d9cd327ull, 0x2b6c6cad6c47c1d8ull, | |||
0xa43131c43195f562ull, 0xf37474cd7487b9e8ull, 0x15f6f6fff6e309f1ull, 0x4c464605460a438cull, 0xa5acac8aac092645ull, 0xb589891e893c970full, 0xb414145014a04428ull, 0xbae1e1a3e15b42dfull, | |||
0xa616165816b04e2cull, 0xf73a3ae83acdd274ull, 0x066969b9696fd0d2ull, 0x4109092409482d12ull, 0xd77070dd70a7ade0ull, 0x6fb6b6e2b6d95471ull, 0x1ed0d067d0ceb7bdull, 0xd6eded93ed3b7ec7ull, | |||
0xe2cccc17cc2edb85ull, 0x68424215422a5784ull, 0x2c98985a98b4c22dull, 0xeda4a4aaa4490e55ull, 0x752828a0285d8850ull, 0x865c5c6d5cda31b8ull, 0x6bf8f8c7f8933fedull, 0xc28686228644a411ull | |||
}; | |||
static const uint64_t C2[] = | |||
{ 0x30d818186018c078ull, 0x462623238c2305afull, 0x91b8c6c63fc67ef9ull, 0xcdfbe8e887e8136full, 0x13cb878726874ca1ull, 0x6d11b8b8dab8a962ull, 0x0209010104010805ull, 0x9e0d4f4f214f426eull, | |||
0x6c9b3636d836adeeull, 0x51ffa6a6a2a65904ull, 0xb90cd2d26fd2debdull, 0xf70ef5f5f3f5fb06ull, 0xf2967979f979ef80ull, 0xde306f6fa16f5fceull, 0x3f6d91917e91fcefull, 0xa4f852525552aa07ull, | |||
0xc04760609d6027fdull, 0x6535bcbccabc8976ull, 0x2b379b9b569baccdull, 0x018a8e8e028e048cull, 0x5bd2a3a3b6a37115ull, 0x186c0c0c300c603cull, 0xf6847b7bf17bff8aull, 0x6a803535d435b5e1ull, | |||
0x3af51d1d741de869ull, 0xddb3e0e0a7e05347ull, 0xb321d7d77bd7f6acull, 0x999cc2c22fc25eedull, 0x5c432e2eb82e6d96ull, 0x96294b4b314b627aull, 0xe15dfefedffea321ull, 0xaed5575741578216ull, | |||
0x2abd15155415a841ull, 0xeee87777c1779fb6ull, 0x6e923737dc37a5ebull, 0xd79ee5e5b3e57b56ull, 0x23139f9f469f8cd9ull, 0xfd23f0f0e7f0d317ull, 0x94204a4a354a6a7full, 0xa944dada4fda9e95ull, | |||
0xb0a258587d58fa25ull, 0x8fcfc9c903c906caull, 0x527c2929a429558dull, 0x145a0a0a280a5022ull, 0x7f50b1b1feb1e14full, 0x5dc9a0a0baa0691aull, 0xd6146b6bb16b7fdaull, 0x17d985852e855cabull, | |||
0x673cbdbdcebd8173ull, 0xba8f5d5d695dd234ull, 0x2090101040108050ull, 0xf507f4f4f7f4f303ull, 0x8bddcbcb0bcb16c0ull, 0x7cd33e3ef83eedc6ull, 0x0a2d050514052811ull, 0xce78676781671fe6ull, | |||
0xd597e4e4b7e47353ull, 0x4e0227279c2725bbull, 0x8273414119413258ull, 0x0ba78b8b168b2c9dull, 0x53f6a7a7a6a75101ull, 0xfab27d7de97dcf94ull, 0x374995956e95dcfbull, 0xad56d8d847d88e9full, | |||
0xeb70fbfbcbfb8b30ull, 0xc1cdeeee9fee2371ull, 0xf8bb7c7ced7cc791ull, 0xcc716666856617e3ull, 0xa77bdddd53dda68eull, 0x2eaf17175c17b84bull, 0x8e45474701470246ull, 0x211a9e9e429e84dcull, | |||
0x89d4caca0fca1ec5ull, 0x5a582d2db42d7599ull, 0x632ebfbfc6bf9179ull, 0x0e3f07071c07381bull, 0x47acadad8ead0123ull, 0xb4b05a5a755aea2full, 0x1bef838336836cb5ull, 0x66b63333cc3385ffull, | |||
0xc65c636391633ff2ull, 0x041202020802100aull, 0x4993aaaa92aa3938ull, 0xe2de7171d971afa8ull, 0x8dc6c8c807c80ecfull, 0x32d119196419c87dull, 0x923b494939497270ull, 0xaf5fd9d943d9869aull, | |||
0xf931f2f2eff2c31dull, 0xdba8e3e3abe34b48ull, 0xb6b95b5b715be22aull, 0x0dbc88881a883492ull, 0x293e9a9a529aa4c8ull, 0x4c0b262698262dbeull, 0x64bf3232c8328dfaull, 0x7d59b0b0fab0e94aull, | |||
0xcff2e9e983e91b6aull, 0x1e770f0f3c0f7833ull, 0xb733d5d573d5e6a6ull, 0x1df480803a8074baull, 0x6127bebec2be997cull, 0x87ebcdcd13cd26deull, 0x68893434d034bde4ull, 0x903248483d487a75ull, | |||
0xe354ffffdbffab24ull, 0xf48d7a7af57af78full, 0x3d6490907a90f4eaull, 0xbe9d5f5f615fc23eull, 0x403d202080201da0ull, 0xd00f6868bd6867d5ull, 0x34ca1a1a681ad072ull, 0x41b7aeae82ae192cull, | |||
0x757db4b4eab4c95eull, 0xa8ce54544d549a19ull, 0x3b7f93937693ece5ull, 0x442f222288220daaull, 0xc86364648d6407e9ull, 0xff2af1f1e3f1db12ull, 0xe6cc7373d173bfa2ull, 0x248212124812905aull, | |||
0x807a40401d403a5dull, 0x1048080820084028ull, 0x9b95c3c32bc356e8ull, 0xc5dfecec97ec337bull, 0xab4ddbdb4bdb9690ull, 0x5fc0a1a1bea1611full, 0x07918d8d0e8d1c83ull, 0x7ac83d3df43df5c9ull, | |||
0x335b97976697ccf1ull, 0x0000000000000000ull, 0x83f9cfcf1bcf36d4ull, 0x566e2b2bac2b4587ull, 0xece17676c57697b3ull, 0x19e68282328264b0ull, 0xb128d6d67fd6fea9ull, 0x36c31b1b6c1bd877ull, | |||
0x7774b5b5eeb5c15bull, 0x43beafaf86af1129ull, 0xd41d6a6ab56a77dfull, 0xa0ea50505d50ba0dull, 0x8a5745450945124cull, 0xfb38f3f3ebf3cb18ull, 0x60ad3030c0309df0ull, 0xc3c4efef9bef2b74ull, | |||
0x7eda3f3ffc3fe5c3ull, 0xaac755554955921cull, 0x59dba2a2b2a27910ull, 0xc9e9eaea8fea0365ull, 0xca6a656589650fecull, 0x6903babad2bab968ull, 0x5e4a2f2fbc2f6593ull, 0x9d8ec0c027c04ee7ull, | |||
0xa160dede5fdebe81ull, 0x38fc1c1c701ce06cull, 0xe746fdfdd3fdbb2eull, 0x9a1f4d4d294d5264ull, 0x397692927292e4e0ull, 0xeafa7575c9758fbcull, 0x0c3606061806301eull, 0x09ae8a8a128a2498ull, | |||
0x794bb2b2f2b2f940ull, 0xd185e6e6bfe66359ull, 0x1c7e0e0e380e7036ull, 0x3ee71f1f7c1ff863ull, 0xc4556262956237f7ull, 0xb53ad4d477d4eea3ull, 0x4d81a8a89aa82932ull, 0x315296966296c4f4ull, | |||
0xef62f9f9c3f99b3aull, 0x97a3c5c533c566f6ull, 0x4a102525942535b1ull, 0xb2ab59597959f220ull, 0x15d084842a8454aeull, 0xe4c57272d572b7a7ull, 0x72ec3939e439d5ddull, 0x98164c4c2d4c5a61ull, | |||
0xbc945e5e655eca3bull, 0xf09f7878fd78e785ull, 0x70e53838e038ddd8ull, 0x05988c8c0a8c1486ull, 0xbf17d1d163d1c6b2ull, 0x57e4a5a5aea5410bull, 0xd9a1e2e2afe2434dull, 0xc24e616199612ff8ull, | |||
0x7b42b3b3f6b3f145ull, 0x42342121842115a5ull, 0x25089c9c4a9c94d6ull, 0x3cee1e1e781ef066ull, 0x8661434311432252ull, 0x93b1c7c73bc776fcull, 0xe54ffcfcd7fcb32bull, 0x0824040410042014ull, | |||
0xa2e351515951b208ull, 0x2f2599995e99bcc7ull, 0xda226d6da96d4fc4ull, 0x1a650d0d340d6839ull, 0xe979fafacffa8335ull, 0xa369dfdf5bdfb684ull, 0xfca97e7ee57ed79bull, 0x4819242490243db4ull, | |||
0x76fe3b3bec3bc5d7ull, 0x4b9aabab96ab313dull, 0x81f0cece1fce3ed1ull, 0x2299111144118855ull, 0x03838f8f068f0c89ull, 0x9c044e4e254e4a6bull, 0x7366b7b7e6b7d151ull, 0xcbe0ebeb8beb0b60ull, | |||
0x78c13c3cf03cfdccull, 0x1ffd81813e817cbfull, 0x354094946a94d4feull, 0xf31cf7f7fbf7eb0cull, 0x6f18b9b9deb9a167ull, 0x268b13134c13985full, 0x58512c2cb02c7d9cull, 0xbb05d3d36bd3d6b8ull, | |||
0xd38ce7e7bbe76b5cull, 0xdc396e6ea56e57cbull, 0x95aac4c437c46ef3ull, 0x061b03030c03180full, 0xacdc565645568a13ull, 0x885e44440d441a49ull, 0xfea07f7fe17fdf9eull, 0x4f88a9a99ea92137ull, | |||
0x54672a2aa82a4d82ull, 0x6b0abbbbd6bbb16dull, 0x9f87c1c123c146e2ull, 0xa6f153535153a202ull, 0xa572dcdc57dcae8bull, 0x16530b0b2c0b5827ull, 0x27019d9d4e9d9cd3ull, 0xd82b6c6cad6c47c1ull, | |||
0x62a43131c43195f5ull, 0xe8f37474cd7487b9ull, 0xf115f6f6fff6e309ull, 0x8c4c464605460a43ull, 0x45a5acac8aac0926ull, 0x0fb589891e893c97ull, 0x28b414145014a044ull, 0xdfbae1e1a3e15b42ull, | |||
0x2ca616165816b04eull, 0x74f73a3ae83acdd2ull, 0xd2066969b9696fd0ull, 0x124109092409482dull, 0xe0d77070dd70a7adull, 0x716fb6b6e2b6d954ull, 0xbd1ed0d067d0ceb7ull, 0xc7d6eded93ed3b7eull, | |||
0x85e2cccc17cc2edbull, 0x8468424215422a57ull, 0x2d2c98985a98b4c2ull, 0x55eda4a4aaa4490eull, 0x50752828a0285d88ull, 0xb8865c5c6d5cda31ull, 0xed6bf8f8c7f8933full, 0x11c28686228644a4ull | |||
}; | |||
static const uint64_t C3[] = | |||
{ 0x7830d818186018c0ull, 0xaf462623238c2305ull, 0xf991b8c6c63fc67eull, 0x6fcdfbe8e887e813ull, 0xa113cb878726874cull, 0x626d11b8b8dab8a9ull, 0x0502090101040108ull, 0x6e9e0d4f4f214f42ull, | |||
0xee6c9b3636d836adull, 0x0451ffa6a6a2a659ull, 0xbdb90cd2d26fd2deull, 0x06f70ef5f5f3f5fbull, 0x80f2967979f979efull, 0xcede306f6fa16f5full, 0xef3f6d91917e91fcull, 0x07a4f852525552aaull, | |||
0xfdc04760609d6027ull, 0x766535bcbccabc89ull, 0xcd2b379b9b569bacull, 0x8c018a8e8e028e04ull, 0x155bd2a3a3b6a371ull, 0x3c186c0c0c300c60ull, 0x8af6847b7bf17bffull, 0xe16a803535d435b5ull, | |||
0x693af51d1d741de8ull, 0x47ddb3e0e0a7e053ull, 0xacb321d7d77bd7f6ull, 0xed999cc2c22fc25eull, 0x965c432e2eb82e6dull, 0x7a96294b4b314b62ull, 0x21e15dfefedffea3ull, 0x16aed55757415782ull, | |||
0x412abd15155415a8ull, 0xb6eee87777c1779full, 0xeb6e923737dc37a5ull, 0x56d79ee5e5b3e57bull, 0xd923139f9f469f8cull, 0x17fd23f0f0e7f0d3ull, 0x7f94204a4a354a6aull, 0x95a944dada4fda9eull, | |||
0x25b0a258587d58faull, 0xca8fcfc9c903c906ull, 0x8d527c2929a42955ull, 0x22145a0a0a280a50ull, 0x4f7f50b1b1feb1e1ull, 0x1a5dc9a0a0baa069ull, 0xdad6146b6bb16b7full, 0xab17d985852e855cull, | |||
0x73673cbdbdcebd81ull, 0x34ba8f5d5d695dd2ull, 0x5020901010401080ull, 0x03f507f4f4f7f4f3ull, 0xc08bddcbcb0bcb16ull, 0xc67cd33e3ef83eedull, 0x110a2d0505140528ull, 0xe6ce78676781671full, | |||
0x53d597e4e4b7e473ull, 0xbb4e0227279c2725ull, 0x5882734141194132ull, 0x9d0ba78b8b168b2cull, 0x0153f6a7a7a6a751ull, 0x94fab27d7de97dcfull, 0xfb374995956e95dcull, 0x9fad56d8d847d88eull, | |||
0x30eb70fbfbcbfb8bull, 0x71c1cdeeee9fee23ull, 0x91f8bb7c7ced7cc7ull, 0xe3cc716666856617ull, 0x8ea77bdddd53dda6ull, 0x4b2eaf17175c17b8ull, 0x468e454747014702ull, 0xdc211a9e9e429e84ull, | |||
0xc589d4caca0fca1eull, 0x995a582d2db42d75ull, 0x79632ebfbfc6bf91ull, 0x1b0e3f07071c0738ull, 0x2347acadad8ead01ull, 0x2fb4b05a5a755aeaull, 0xb51bef838336836cull, 0xff66b63333cc3385ull, | |||
0xf2c65c636391633full, 0x0a04120202080210ull, 0x384993aaaa92aa39ull, 0xa8e2de7171d971afull, 0xcf8dc6c8c807c80eull, 0x7d32d119196419c8ull, 0x70923b4949394972ull, 0x9aaf5fd9d943d986ull, | |||
0x1df931f2f2eff2c3ull, 0x48dba8e3e3abe34bull, 0x2ab6b95b5b715be2ull, 0x920dbc88881a8834ull, 0xc8293e9a9a529aa4ull, 0xbe4c0b262698262dull, 0xfa64bf3232c8328dull, 0x4a7d59b0b0fab0e9ull, | |||
0x6acff2e9e983e91bull, 0x331e770f0f3c0f78ull, 0xa6b733d5d573d5e6ull, 0xba1df480803a8074ull, 0x7c6127bebec2be99ull, 0xde87ebcdcd13cd26ull, 0xe468893434d034bdull, 0x75903248483d487aull, | |||
0x24e354ffffdbffabull, 0x8ff48d7a7af57af7ull, 0xea3d6490907a90f4ull, 0x3ebe9d5f5f615fc2ull, 0xa0403d202080201dull, 0xd5d00f6868bd6867ull, 0x7234ca1a1a681ad0ull, 0x2c41b7aeae82ae19ull, | |||
0x5e757db4b4eab4c9ull, 0x19a8ce54544d549aull, 0xe53b7f93937693ecull, 0xaa442f222288220dull, 0xe9c86364648d6407ull, 0x12ff2af1f1e3f1dbull, 0xa2e6cc7373d173bfull, 0x5a24821212481290ull, | |||
0x5d807a40401d403aull, 0x2810480808200840ull, 0xe89b95c3c32bc356ull, 0x7bc5dfecec97ec33ull, 0x90ab4ddbdb4bdb96ull, 0x1f5fc0a1a1bea161ull, 0x8307918d8d0e8d1cull, 0xc97ac83d3df43df5ull, | |||
0xf1335b97976697ccull, 0x0000000000000000ull, 0xd483f9cfcf1bcf36ull, 0x87566e2b2bac2b45ull, 0xb3ece17676c57697ull, 0xb019e68282328264ull, 0xa9b128d6d67fd6feull, 0x7736c31b1b6c1bd8ull, | |||
0x5b7774b5b5eeb5c1ull, 0x2943beafaf86af11ull, 0xdfd41d6a6ab56a77ull, 0x0da0ea50505d50baull, 0x4c8a574545094512ull, 0x18fb38f3f3ebf3cbull, 0xf060ad3030c0309dull, 0x74c3c4efef9bef2bull, | |||
0xc37eda3f3ffc3fe5ull, 0x1caac75555495592ull, 0x1059dba2a2b2a279ull, 0x65c9e9eaea8fea03ull, 0xecca6a656589650full, 0x686903babad2bab9ull, 0x935e4a2f2fbc2f65ull, 0xe79d8ec0c027c04eull, | |||
0x81a160dede5fdebeull, 0x6c38fc1c1c701ce0ull, 0x2ee746fdfdd3fdbbull, 0x649a1f4d4d294d52ull, 0xe0397692927292e4ull, 0xbceafa7575c9758full, 0x1e0c360606180630ull, 0x9809ae8a8a128a24ull, | |||
0x40794bb2b2f2b2f9ull, 0x59d185e6e6bfe663ull, 0x361c7e0e0e380e70ull, 0x633ee71f1f7c1ff8ull, 0xf7c4556262956237ull, 0xa3b53ad4d477d4eeull, 0x324d81a8a89aa829ull, 0xf4315296966296c4ull, | |||
0x3aef62f9f9c3f99bull, 0xf697a3c5c533c566ull, 0xb14a102525942535ull, 0x20b2ab59597959f2ull, 0xae15d084842a8454ull, 0xa7e4c57272d572b7ull, 0xdd72ec3939e439d5ull, 0x6198164c4c2d4c5aull, | |||
0x3bbc945e5e655ecaull, 0x85f09f7878fd78e7ull, 0xd870e53838e038ddull, 0x8605988c8c0a8c14ull, 0xb2bf17d1d163d1c6ull, 0x0b57e4a5a5aea541ull, 0x4dd9a1e2e2afe243ull, 0xf8c24e616199612full, | |||
0x457b42b3b3f6b3f1ull, 0xa542342121842115ull, 0xd625089c9c4a9c94ull, 0x663cee1e1e781ef0ull, 0x5286614343114322ull, 0xfc93b1c7c73bc776ull, 0x2be54ffcfcd7fcb3ull, 0x1408240404100420ull, | |||
0x08a2e351515951b2ull, 0xc72f2599995e99bcull, 0xc4da226d6da96d4full, 0x391a650d0d340d68ull, 0x35e979fafacffa83ull, 0x84a369dfdf5bdfb6ull, 0x9bfca97e7ee57ed7ull, 0xb44819242490243dull, | |||
0xd776fe3b3bec3bc5ull, 0x3d4b9aabab96ab31ull, 0xd181f0cece1fce3eull, 0x5522991111441188ull, 0x8903838f8f068f0cull, 0x6b9c044e4e254e4aull, 0x517366b7b7e6b7d1ull, 0x60cbe0ebeb8beb0bull, | |||
0xcc78c13c3cf03cfdull, 0xbf1ffd81813e817cull, 0xfe354094946a94d4ull, 0x0cf31cf7f7fbf7ebull, 0x676f18b9b9deb9a1ull, 0x5f268b13134c1398ull, 0x9c58512c2cb02c7dull, 0xb8bb05d3d36bd3d6ull, | |||
0x5cd38ce7e7bbe76bull, 0xcbdc396e6ea56e57ull, 0xf395aac4c437c46eull, 0x0f061b03030c0318ull, 0x13acdc565645568aull, 0x49885e44440d441aull, 0x9efea07f7fe17fdfull, 0x374f88a9a99ea921ull, | |||
0x8254672a2aa82a4dull, 0x6d6b0abbbbd6bbb1ull, 0xe29f87c1c123c146ull, 0x02a6f153535153a2ull, 0x8ba572dcdc57dcaeull, 0x2716530b0b2c0b58ull, 0xd327019d9d4e9d9cull, 0xc1d82b6c6cad6c47ull, | |||
0xf562a43131c43195ull, 0xb9e8f37474cd7487ull, 0x09f115f6f6fff6e3ull, 0x438c4c464605460aull, 0x2645a5acac8aac09ull, 0x970fb589891e893cull, 0x4428b414145014a0ull, 0x42dfbae1e1a3e15bull, | |||
0x4e2ca616165816b0ull, 0xd274f73a3ae83acdull, 0xd0d2066969b9696full, 0x2d12410909240948ull, 0xade0d77070dd70a7ull, 0x54716fb6b6e2b6d9ull, 0xb7bd1ed0d067d0ceull, 0x7ec7d6eded93ed3bull, | |||
0xdb85e2cccc17cc2eull, 0x578468424215422aull, 0xc22d2c98985a98b4ull, 0x0e55eda4a4aaa449ull, 0x8850752828a0285dull, 0x31b8865c5c6d5cdaull, 0x3fed6bf8f8c7f893ull, 0xa411c28686228644ull | |||
}; | |||
static const uint64_t C4[] = | |||
{ 0xc07830d818186018ull, 0x05af462623238c23ull, 0x7ef991b8c6c63fc6ull, 0x136fcdfbe8e887e8ull, 0x4ca113cb87872687ull, 0xa9626d11b8b8dab8ull, 0x0805020901010401ull, 0x426e9e0d4f4f214full, | |||
0xadee6c9b3636d836ull, 0x590451ffa6a6a2a6ull, 0xdebdb90cd2d26fd2ull, 0xfb06f70ef5f5f3f5ull, 0xef80f2967979f979ull, 0x5fcede306f6fa16full, 0xfcef3f6d91917e91ull, 0xaa07a4f852525552ull, | |||
0x27fdc04760609d60ull, 0x89766535bcbccabcull, 0xaccd2b379b9b569bull, 0x048c018a8e8e028eull, 0x71155bd2a3a3b6a3ull, 0x603c186c0c0c300cull, 0xff8af6847b7bf17bull, 0xb5e16a803535d435ull, | |||
0xe8693af51d1d741dull, 0x5347ddb3e0e0a7e0ull, 0xf6acb321d7d77bd7ull, 0x5eed999cc2c22fc2ull, 0x6d965c432e2eb82eull, 0x627a96294b4b314bull, 0xa321e15dfefedffeull, 0x8216aed557574157ull, | |||
0xa8412abd15155415ull, 0x9fb6eee87777c177ull, 0xa5eb6e923737dc37ull, 0x7b56d79ee5e5b3e5ull, 0x8cd923139f9f469full, 0xd317fd23f0f0e7f0ull, 0x6a7f94204a4a354aull, 0x9e95a944dada4fdaull, | |||
0xfa25b0a258587d58ull, 0x06ca8fcfc9c903c9ull, 0x558d527c2929a429ull, 0x5022145a0a0a280aull, 0xe14f7f50b1b1feb1ull, 0x691a5dc9a0a0baa0ull, 0x7fdad6146b6bb16bull, 0x5cab17d985852e85ull, | |||
0x8173673cbdbdcebdull, 0xd234ba8f5d5d695dull, 0x8050209010104010ull, 0xf303f507f4f4f7f4ull, 0x16c08bddcbcb0bcbull, 0xedc67cd33e3ef83eull, 0x28110a2d05051405ull, 0x1fe6ce7867678167ull, | |||
0x7353d597e4e4b7e4ull, 0x25bb4e0227279c27ull, 0x3258827341411941ull, 0x2c9d0ba78b8b168bull, 0x510153f6a7a7a6a7ull, 0xcf94fab27d7de97dull, 0xdcfb374995956e95ull, 0x8e9fad56d8d847d8ull, | |||
0x8b30eb70fbfbcbfbull, 0x2371c1cdeeee9feeull, 0xc791f8bb7c7ced7cull, 0x17e3cc7166668566ull, 0xa68ea77bdddd53ddull, 0xb84b2eaf17175c17ull, 0x02468e4547470147ull, 0x84dc211a9e9e429eull, | |||
0x1ec589d4caca0fcaull, 0x75995a582d2db42dull, 0x9179632ebfbfc6bfull, 0x381b0e3f07071c07ull, 0x012347acadad8eadull, 0xea2fb4b05a5a755aull, 0x6cb51bef83833683ull, 0x85ff66b63333cc33ull, | |||
0x3ff2c65c63639163ull, 0x100a041202020802ull, 0x39384993aaaa92aaull, 0xafa8e2de7171d971ull, 0x0ecf8dc6c8c807c8ull, 0xc87d32d119196419ull, 0x7270923b49493949ull, 0x869aaf5fd9d943d9ull, | |||
0xc31df931f2f2eff2ull, 0x4b48dba8e3e3abe3ull, 0xe22ab6b95b5b715bull, 0x34920dbc88881a88ull, 0xa4c8293e9a9a529aull, 0x2dbe4c0b26269826ull, 0x8dfa64bf3232c832ull, 0xe94a7d59b0b0fab0ull, | |||
0x1b6acff2e9e983e9ull, 0x78331e770f0f3c0full, 0xe6a6b733d5d573d5ull, 0x74ba1df480803a80ull, 0x997c6127bebec2beull, 0x26de87ebcdcd13cdull, 0xbde468893434d034ull, 0x7a75903248483d48ull, | |||
0xab24e354ffffdbffull, 0xf78ff48d7a7af57aull, 0xf4ea3d6490907a90ull, 0xc23ebe9d5f5f615full, 0x1da0403d20208020ull, 0x67d5d00f6868bd68ull, 0xd07234ca1a1a681aull, 0x192c41b7aeae82aeull, | |||
0xc95e757db4b4eab4ull, 0x9a19a8ce54544d54ull, 0xece53b7f93937693ull, 0x0daa442f22228822ull, 0x07e9c86364648d64ull, 0xdb12ff2af1f1e3f1ull, 0xbfa2e6cc7373d173ull, 0x905a248212124812ull, | |||
0x3a5d807a40401d40ull, 0x4028104808082008ull, 0x56e89b95c3c32bc3ull, 0x337bc5dfecec97ecull, 0x9690ab4ddbdb4bdbull, 0x611f5fc0a1a1bea1ull, 0x1c8307918d8d0e8dull, 0xf5c97ac83d3df43dull, | |||
0xccf1335b97976697ull, 0x0000000000000000ull, 0x36d483f9cfcf1bcfull, 0x4587566e2b2bac2bull, 0x97b3ece17676c576ull, 0x64b019e682823282ull, 0xfea9b128d6d67fd6ull, 0xd87736c31b1b6c1bull, | |||
0xc15b7774b5b5eeb5ull, 0x112943beafaf86afull, 0x77dfd41d6a6ab56aull, 0xba0da0ea50505d50ull, 0x124c8a5745450945ull, 0xcb18fb38f3f3ebf3ull, 0x9df060ad3030c030ull, 0x2b74c3c4efef9befull, | |||
0xe5c37eda3f3ffc3full, 0x921caac755554955ull, 0x791059dba2a2b2a2ull, 0x0365c9e9eaea8feaull, 0x0fecca6a65658965ull, 0xb9686903babad2baull, 0x65935e4a2f2fbc2full, 0x4ee79d8ec0c027c0ull, | |||
0xbe81a160dede5fdeull, 0xe06c38fc1c1c701cull, 0xbb2ee746fdfdd3fdull, 0x52649a1f4d4d294dull, 0xe4e0397692927292ull, 0x8fbceafa7575c975ull, 0x301e0c3606061806ull, 0x249809ae8a8a128aull, | |||
0xf940794bb2b2f2b2ull, 0x6359d185e6e6bfe6ull, 0x70361c7e0e0e380eull, 0xf8633ee71f1f7c1full, 0x37f7c45562629562ull, 0xeea3b53ad4d477d4ull, 0x29324d81a8a89aa8ull, 0xc4f4315296966296ull, | |||
0x9b3aef62f9f9c3f9ull, 0x66f697a3c5c533c5ull, 0x35b14a1025259425ull, 0xf220b2ab59597959ull, 0x54ae15d084842a84ull, 0xb7a7e4c57272d572ull, 0xd5dd72ec3939e439ull, 0x5a6198164c4c2d4cull, | |||
0xca3bbc945e5e655eull, 0xe785f09f7878fd78ull, 0xddd870e53838e038ull, 0x148605988c8c0a8cull, 0xc6b2bf17d1d163d1ull, 0x410b57e4a5a5aea5ull, 0x434dd9a1e2e2afe2ull, 0x2ff8c24e61619961ull, | |||
0xf1457b42b3b3f6b3ull, 0x15a5423421218421ull, 0x94d625089c9c4a9cull, 0xf0663cee1e1e781eull, 0x2252866143431143ull, 0x76fc93b1c7c73bc7ull, 0xb32be54ffcfcd7fcull, 0x2014082404041004ull, | |||
0xb208a2e351515951ull, 0xbcc72f2599995e99ull, 0x4fc4da226d6da96dull, 0x68391a650d0d340dull, 0x8335e979fafacffaull, 0xb684a369dfdf5bdfull, 0xd79bfca97e7ee57eull, 0x3db4481924249024ull, | |||
0xc5d776fe3b3bec3bull, 0x313d4b9aabab96abull, 0x3ed181f0cece1fceull, 0x8855229911114411ull, 0x0c8903838f8f068full, 0x4a6b9c044e4e254eull, 0xd1517366b7b7e6b7ull, 0x0b60cbe0ebeb8bebull, | |||
0xfdcc78c13c3cf03cull, 0x7cbf1ffd81813e81ull, 0xd4fe354094946a94ull, 0xeb0cf31cf7f7fbf7ull, 0xa1676f18b9b9deb9ull, 0x985f268b13134c13ull, 0x7d9c58512c2cb02cull, 0xd6b8bb05d3d36bd3ull, | |||
0x6b5cd38ce7e7bbe7ull, 0x57cbdc396e6ea56eull, 0x6ef395aac4c437c4ull, 0x180f061b03030c03ull, 0x8a13acdc56564556ull, 0x1a49885e44440d44ull, 0xdf9efea07f7fe17full, 0x21374f88a9a99ea9ull, | |||
0x4d8254672a2aa82aull, 0xb16d6b0abbbbd6bbull, 0x46e29f87c1c123c1ull, 0xa202a6f153535153ull, 0xae8ba572dcdc57dcull, 0x582716530b0b2c0bull, 0x9cd327019d9d4e9dull, 0x47c1d82b6c6cad6cull, | |||
0x95f562a43131c431ull, 0x87b9e8f37474cd74ull, 0xe309f115f6f6fff6ull, 0x0a438c4c46460546ull, 0x092645a5acac8aacull, 0x3c970fb589891e89ull, 0xa04428b414145014ull, 0x5b42dfbae1e1a3e1ull, | |||
0xb04e2ca616165816ull, 0xcdd274f73a3ae83aull, 0x6fd0d2066969b969ull, 0x482d124109092409ull, 0xa7ade0d77070dd70ull, 0xd954716fb6b6e2b6ull, 0xceb7bd1ed0d067d0ull, 0x3b7ec7d6eded93edull, | |||
0x2edb85e2cccc17ccull, 0x2a57846842421542ull, 0xb4c22d2c98985a98ull, 0x490e55eda4a4aaa4ull, 0x5d8850752828a028ull, 0xda31b8865c5c6d5cull, 0x933fed6bf8f8c7f8ull, 0x44a411c286862286ull | |||
}; | |||
static const uint64_t C5[] = | |||
{ 0x18c07830d8181860ull, 0x2305af462623238cull, 0xc67ef991b8c6c63full, 0xe8136fcdfbe8e887ull, 0x874ca113cb878726ull, 0xb8a9626d11b8b8daull, 0x0108050209010104ull, 0x4f426e9e0d4f4f21ull, | |||
0x36adee6c9b3636d8ull, 0xa6590451ffa6a6a2ull, 0xd2debdb90cd2d26full, 0xf5fb06f70ef5f5f3ull, 0x79ef80f2967979f9ull, 0x6f5fcede306f6fa1ull, 0x91fcef3f6d91917eull, 0x52aa07a4f8525255ull, | |||
0x6027fdc04760609dull, 0xbc89766535bcbccaull, 0x9baccd2b379b9b56ull, 0x8e048c018a8e8e02ull, 0xa371155bd2a3a3b6ull, 0x0c603c186c0c0c30ull, 0x7bff8af6847b7bf1ull, 0x35b5e16a803535d4ull, | |||
0x1de8693af51d1d74ull, 0xe05347ddb3e0e0a7ull, 0xd7f6acb321d7d77bull, 0xc25eed999cc2c22full, 0x2e6d965c432e2eb8ull, 0x4b627a96294b4b31ull, 0xfea321e15dfefedfull, 0x578216aed5575741ull, | |||
0x15a8412abd151554ull, 0x779fb6eee87777c1ull, 0x37a5eb6e923737dcull, 0xe57b56d79ee5e5b3ull, 0x9f8cd923139f9f46ull, 0xf0d317fd23f0f0e7ull, 0x4a6a7f94204a4a35ull, 0xda9e95a944dada4full, | |||
0x58fa25b0a258587dull, 0xc906ca8fcfc9c903ull, 0x29558d527c2929a4ull, 0x0a5022145a0a0a28ull, 0xb1e14f7f50b1b1feull, 0xa0691a5dc9a0a0baull, 0x6b7fdad6146b6bb1ull, 0x855cab17d985852eull, | |||
0xbd8173673cbdbdceull, 0x5dd234ba8f5d5d69ull, 0x1080502090101040ull, 0xf4f303f507f4f4f7ull, 0xcb16c08bddcbcb0bull, 0x3eedc67cd33e3ef8ull, 0x0528110a2d050514ull, 0x671fe6ce78676781ull, | |||
0xe47353d597e4e4b7ull, 0x2725bb4e0227279cull, 0x4132588273414119ull, 0x8b2c9d0ba78b8b16ull, 0xa7510153f6a7a7a6ull, 0x7dcf94fab27d7de9ull, 0x95dcfb374995956eull, 0xd88e9fad56d8d847ull, | |||
0xfb8b30eb70fbfbcbull, 0xee2371c1cdeeee9full, 0x7cc791f8bb7c7cedull, 0x6617e3cc71666685ull, 0xdda68ea77bdddd53ull, 0x17b84b2eaf17175cull, 0x4702468e45474701ull, 0x9e84dc211a9e9e42ull, | |||
0xca1ec589d4caca0full, 0x2d75995a582d2db4ull, 0xbf9179632ebfbfc6ull, 0x07381b0e3f07071cull, 0xad012347acadad8eull, 0x5aea2fb4b05a5a75ull, 0x836cb51bef838336ull, 0x3385ff66b63333ccull, | |||
0x633ff2c65c636391ull, 0x02100a0412020208ull, 0xaa39384993aaaa92ull, 0x71afa8e2de7171d9ull, 0xc80ecf8dc6c8c807ull, 0x19c87d32d1191964ull, 0x497270923b494939ull, 0xd9869aaf5fd9d943ull, | |||
0xf2c31df931f2f2efull, 0xe34b48dba8e3e3abull, 0x5be22ab6b95b5b71ull, 0x8834920dbc88881aull, 0x9aa4c8293e9a9a52ull, 0x262dbe4c0b262698ull, 0x328dfa64bf3232c8ull, 0xb0e94a7d59b0b0faull, | |||
0xe91b6acff2e9e983ull, 0x0f78331e770f0f3cull, 0xd5e6a6b733d5d573ull, 0x8074ba1df480803aull, 0xbe997c6127bebec2ull, 0xcd26de87ebcdcd13ull, 0x34bde468893434d0ull, 0x487a75903248483dull, | |||
0xffab24e354ffffdbull, 0x7af78ff48d7a7af5ull, 0x90f4ea3d6490907aull, 0x5fc23ebe9d5f5f61ull, 0x201da0403d202080ull, 0x6867d5d00f6868bdull, 0x1ad07234ca1a1a68ull, 0xae192c41b7aeae82ull, | |||
0xb4c95e757db4b4eaull, 0x549a19a8ce54544dull, 0x93ece53b7f939376ull, 0x220daa442f222288ull, 0x6407e9c86364648dull, 0xf1db12ff2af1f1e3ull, 0x73bfa2e6cc7373d1ull, 0x12905a2482121248ull, | |||
0x403a5d807a40401dull, 0x0840281048080820ull, 0xc356e89b95c3c32bull, 0xec337bc5dfecec97ull, 0xdb9690ab4ddbdb4bull, 0xa1611f5fc0a1a1beull, 0x8d1c8307918d8d0eull, 0x3df5c97ac83d3df4ull, | |||
0x97ccf1335b979766ull, 0x0000000000000000ull, 0xcf36d483f9cfcf1bull, 0x2b4587566e2b2bacull, 0x7697b3ece17676c5ull, 0x8264b019e6828232ull, 0xd6fea9b128d6d67full, 0x1bd87736c31b1b6cull, | |||
0xb5c15b7774b5b5eeull, 0xaf112943beafaf86ull, 0x6a77dfd41d6a6ab5ull, 0x50ba0da0ea50505dull, 0x45124c8a57454509ull, 0xf3cb18fb38f3f3ebull, 0x309df060ad3030c0ull, 0xef2b74c3c4efef9bull, | |||
0x3fe5c37eda3f3ffcull, 0x55921caac7555549ull, 0xa2791059dba2a2b2ull, 0xea0365c9e9eaea8full, 0x650fecca6a656589ull, 0xbab9686903babad2ull, 0x2f65935e4a2f2fbcull, 0xc04ee79d8ec0c027ull, | |||
0xdebe81a160dede5full, 0x1ce06c38fc1c1c70ull, 0xfdbb2ee746fdfdd3ull, 0x4d52649a1f4d4d29ull, 0x92e4e03976929272ull, 0x758fbceafa7575c9ull, 0x06301e0c36060618ull, 0x8a249809ae8a8a12ull, | |||
0xb2f940794bb2b2f2ull, 0xe66359d185e6e6bfull, 0x0e70361c7e0e0e38ull, 0x1ff8633ee71f1f7cull, 0x6237f7c455626295ull, 0xd4eea3b53ad4d477ull, 0xa829324d81a8a89aull, 0x96c4f43152969662ull, | |||
0xf99b3aef62f9f9c3ull, 0xc566f697a3c5c533ull, 0x2535b14a10252594ull, 0x59f220b2ab595979ull, 0x8454ae15d084842aull, 0x72b7a7e4c57272d5ull, 0x39d5dd72ec3939e4ull, 0x4c5a6198164c4c2dull, | |||
0x5eca3bbc945e5e65ull, 0x78e785f09f7878fdull, 0x38ddd870e53838e0ull, 0x8c148605988c8c0aull, 0xd1c6b2bf17d1d163ull, 0xa5410b57e4a5a5aeull, 0xe2434dd9a1e2e2afull, 0x612ff8c24e616199ull, | |||
0xb3f1457b42b3b3f6ull, 0x2115a54234212184ull, 0x9c94d625089c9c4aull, 0x1ef0663cee1e1e78ull, 0x4322528661434311ull, 0xc776fc93b1c7c73bull, 0xfcb32be54ffcfcd7ull, 0x0420140824040410ull, | |||
0x51b208a2e3515159ull, 0x99bcc72f2599995eull, 0x6d4fc4da226d6da9ull, 0x0d68391a650d0d34ull, 0xfa8335e979fafacfull, 0xdfb684a369dfdf5bull, 0x7ed79bfca97e7ee5ull, 0x243db44819242490ull, | |||
0x3bc5d776fe3b3becull, 0xab313d4b9aabab96ull, 0xce3ed181f0cece1full, 0x1188552299111144ull, 0x8f0c8903838f8f06ull, 0x4e4a6b9c044e4e25ull, 0xb7d1517366b7b7e6ull, 0xeb0b60cbe0ebeb8bull, | |||
0x3cfdcc78c13c3cf0ull, 0x817cbf1ffd81813eull, 0x94d4fe354094946aull, 0xf7eb0cf31cf7f7fbull, 0xb9a1676f18b9b9deull, 0x13985f268b13134cull, 0x2c7d9c58512c2cb0ull, 0xd3d6b8bb05d3d36bull, | |||
0xe76b5cd38ce7e7bbull, 0x6e57cbdc396e6ea5ull, 0xc46ef395aac4c437ull, 0x03180f061b03030cull, 0x568a13acdc565645ull, 0x441a49885e44440dull, 0x7fdf9efea07f7fe1ull, 0xa921374f88a9a99eull, | |||
0x2a4d8254672a2aa8ull, 0xbbb16d6b0abbbbd6ull, 0xc146e29f87c1c123ull, 0x53a202a6f1535351ull, 0xdcae8ba572dcdc57ull, 0x0b582716530b0b2cull, 0x9d9cd327019d9d4eull, 0x6c47c1d82b6c6cadull, | |||
0x3195f562a43131c4ull, 0x7487b9e8f37474cdull, 0xf6e309f115f6f6ffull, 0x460a438c4c464605ull, 0xac092645a5acac8aull, 0x893c970fb589891eull, 0x14a04428b4141450ull, 0xe15b42dfbae1e1a3ull, | |||
0x16b04e2ca6161658ull, 0x3acdd274f73a3ae8ull, 0x696fd0d2066969b9ull, 0x09482d1241090924ull, 0x70a7ade0d77070ddull, 0xb6d954716fb6b6e2ull, 0xd0ceb7bd1ed0d067ull, 0xed3b7ec7d6eded93ull, | |||
0xcc2edb85e2cccc17ull, 0x422a578468424215ull, 0x98b4c22d2c98985aull, 0xa4490e55eda4a4aaull, 0x285d8850752828a0ull, 0x5cda31b8865c5c6dull, 0xf8933fed6bf8f8c7ull, 0x8644a411c2868622ull | |||
}; | |||
static const uint64_t C6[] = | |||
{ 0x6018c07830d81818ull, 0x8c2305af46262323ull, 0x3fc67ef991b8c6c6ull, 0x87e8136fcdfbe8e8ull, 0x26874ca113cb8787ull, 0xdab8a9626d11b8b8ull, 0x0401080502090101ull, 0x214f426e9e0d4f4full, | |||
0xd836adee6c9b3636ull, 0xa2a6590451ffa6a6ull, 0x6fd2debdb90cd2d2ull, 0xf3f5fb06f70ef5f5ull, 0xf979ef80f2967979ull, 0xa16f5fcede306f6full, 0x7e91fcef3f6d9191ull, 0x5552aa07a4f85252ull, | |||
0x9d6027fdc0476060ull, 0xcabc89766535bcbcull, 0x569baccd2b379b9bull, 0x028e048c018a8e8eull, 0xb6a371155bd2a3a3ull, 0x300c603c186c0c0cull, 0xf17bff8af6847b7bull, 0xd435b5e16a803535ull, | |||
0x741de8693af51d1dull, 0xa7e05347ddb3e0e0ull, 0x7bd7f6acb321d7d7ull, 0x2fc25eed999cc2c2ull, 0xb82e6d965c432e2eull, 0x314b627a96294b4bull, 0xdffea321e15dfefeull, 0x41578216aed55757ull, | |||
0x5415a8412abd1515ull, 0xc1779fb6eee87777ull, 0xdc37a5eb6e923737ull, 0xb3e57b56d79ee5e5ull, 0x469f8cd923139f9full, 0xe7f0d317fd23f0f0ull, 0x354a6a7f94204a4aull, 0x4fda9e95a944dadaull, | |||
0x7d58fa25b0a25858ull, 0x03c906ca8fcfc9c9ull, 0xa429558d527c2929ull, 0x280a5022145a0a0aull, 0xfeb1e14f7f50b1b1ull, 0xbaa0691a5dc9a0a0ull, 0xb16b7fdad6146b6bull, 0x2e855cab17d98585ull, | |||
0xcebd8173673cbdbdull, 0x695dd234ba8f5d5dull, 0x4010805020901010ull, 0xf7f4f303f507f4f4ull, 0x0bcb16c08bddcbcbull, 0xf83eedc67cd33e3eull, 0x140528110a2d0505ull, 0x81671fe6ce786767ull, | |||
0xb7e47353d597e4e4ull, 0x9c2725bb4e022727ull, 0x1941325882734141ull, 0x168b2c9d0ba78b8bull, 0xa6a7510153f6a7a7ull, 0xe97dcf94fab27d7dull, 0x6e95dcfb37499595ull, 0x47d88e9fad56d8d8ull, | |||
0xcbfb8b30eb70fbfbull, 0x9fee2371c1cdeeeeull, 0xed7cc791f8bb7c7cull, 0x856617e3cc716666ull, 0x53dda68ea77bddddull, 0x5c17b84b2eaf1717ull, 0x014702468e454747ull, 0x429e84dc211a9e9eull, | |||
0x0fca1ec589d4cacaull, 0xb42d75995a582d2dull, 0xc6bf9179632ebfbfull, 0x1c07381b0e3f0707ull, 0x8ead012347acadadull, 0x755aea2fb4b05a5aull, 0x36836cb51bef8383ull, 0xcc3385ff66b63333ull, | |||
0x91633ff2c65c6363ull, 0x0802100a04120202ull, 0x92aa39384993aaaaull, 0xd971afa8e2de7171ull, 0x07c80ecf8dc6c8c8ull, 0x6419c87d32d11919ull, 0x39497270923b4949ull, 0x43d9869aaf5fd9d9ull, | |||
0xeff2c31df931f2f2ull, 0xabe34b48dba8e3e3ull, 0x715be22ab6b95b5bull, 0x1a8834920dbc8888ull, 0x529aa4c8293e9a9aull, 0x98262dbe4c0b2626ull, 0xc8328dfa64bf3232ull, 0xfab0e94a7d59b0b0ull, | |||
0x83e91b6acff2e9e9ull, 0x3c0f78331e770f0full, 0x73d5e6a6b733d5d5ull, 0x3a8074ba1df48080ull, 0xc2be997c6127bebeull, 0x13cd26de87ebcdcdull, 0xd034bde468893434ull, 0x3d487a7590324848ull, | |||
0xdbffab24e354ffffull, 0xf57af78ff48d7a7aull, 0x7a90f4ea3d649090ull, 0x615fc23ebe9d5f5full, 0x80201da0403d2020ull, 0xbd6867d5d00f6868ull, 0x681ad07234ca1a1aull, 0x82ae192c41b7aeaeull, | |||
0xeab4c95e757db4b4ull, 0x4d549a19a8ce5454ull, 0x7693ece53b7f9393ull, 0x88220daa442f2222ull, 0x8d6407e9c8636464ull, 0xe3f1db12ff2af1f1ull, 0xd173bfa2e6cc7373ull, 0x4812905a24821212ull, | |||
0x1d403a5d807a4040ull, 0x2008402810480808ull, 0x2bc356e89b95c3c3ull, 0x97ec337bc5dfececull, 0x4bdb9690ab4ddbdbull, 0xbea1611f5fc0a1a1ull, 0x0e8d1c8307918d8dull, 0xf43df5c97ac83d3dull, | |||
0x6697ccf1335b9797ull, 0x0000000000000000ull, 0x1bcf36d483f9cfcfull, 0xac2b4587566e2b2bull, 0xc57697b3ece17676ull, 0x328264b019e68282ull, 0x7fd6fea9b128d6d6ull, 0x6c1bd87736c31b1bull, | |||
0xeeb5c15b7774b5b5ull, 0x86af112943beafafull, 0xb56a77dfd41d6a6aull, 0x5d50ba0da0ea5050ull, 0x0945124c8a574545ull, 0xebf3cb18fb38f3f3ull, 0xc0309df060ad3030ull, 0x9bef2b74c3c4efefull, | |||
0xfc3fe5c37eda3f3full, 0x4955921caac75555ull, 0xb2a2791059dba2a2ull, 0x8fea0365c9e9eaeaull, 0x89650fecca6a6565ull, 0xd2bab9686903babaull, 0xbc2f65935e4a2f2full, 0x27c04ee79d8ec0c0ull, | |||
0x5fdebe81a160dedeull, 0x701ce06c38fc1c1cull, 0xd3fdbb2ee746fdfdull, 0x294d52649a1f4d4dull, 0x7292e4e039769292ull, 0xc9758fbceafa7575ull, 0x1806301e0c360606ull, 0x128a249809ae8a8aull, | |||
0xf2b2f940794bb2b2ull, 0xbfe66359d185e6e6ull, 0x380e70361c7e0e0eull, 0x7c1ff8633ee71f1full, 0x956237f7c4556262ull, 0x77d4eea3b53ad4d4ull, 0x9aa829324d81a8a8ull, 0x6296c4f431529696ull, | |||
0xc3f99b3aef62f9f9ull, 0x33c566f697a3c5c5ull, 0x942535b14a102525ull, 0x7959f220b2ab5959ull, 0x2a8454ae15d08484ull, 0xd572b7a7e4c57272ull, 0xe439d5dd72ec3939ull, 0x2d4c5a6198164c4cull, | |||
0x655eca3bbc945e5eull, 0xfd78e785f09f7878ull, 0xe038ddd870e53838ull, 0x0a8c148605988c8cull, 0x63d1c6b2bf17d1d1ull, 0xaea5410b57e4a5a5ull, 0xafe2434dd9a1e2e2ull, 0x99612ff8c24e6161ull, | |||
0xf6b3f1457b42b3b3ull, 0x842115a542342121ull, 0x4a9c94d625089c9cull, 0x781ef0663cee1e1eull, 0x1143225286614343ull, 0x3bc776fc93b1c7c7ull, 0xd7fcb32be54ffcfcull, 0x1004201408240404ull, | |||
0x5951b208a2e35151ull, 0x5e99bcc72f259999ull, 0xa96d4fc4da226d6dull, 0x340d68391a650d0dull, 0xcffa8335e979fafaull, 0x5bdfb684a369dfdfull, 0xe57ed79bfca97e7eull, 0x90243db448192424ull, | |||
0xec3bc5d776fe3b3bull, 0x96ab313d4b9aababull, 0x1fce3ed181f0ceceull, 0x4411885522991111ull, 0x068f0c8903838f8full, 0x254e4a6b9c044e4eull, 0xe6b7d1517366b7b7ull, 0x8beb0b60cbe0ebebull, | |||
0xf03cfdcc78c13c3cull, 0x3e817cbf1ffd8181ull, 0x6a94d4fe35409494ull, 0xfbf7eb0cf31cf7f7ull, 0xdeb9a1676f18b9b9ull, 0x4c13985f268b1313ull, 0xb02c7d9c58512c2cull, 0x6bd3d6b8bb05d3d3ull, | |||
0xbbe76b5cd38ce7e7ull, 0xa56e57cbdc396e6eull, 0x37c46ef395aac4c4ull, 0x0c03180f061b0303ull, 0x45568a13acdc5656ull, 0x0d441a49885e4444ull, 0xe17fdf9efea07f7full, 0x9ea921374f88a9a9ull, | |||
0xa82a4d8254672a2aull, 0xd6bbb16d6b0abbbbull, 0x23c146e29f87c1c1ull, 0x5153a202a6f15353ull, 0x57dcae8ba572dcdcull, 0x2c0b582716530b0bull, 0x4e9d9cd327019d9dull, 0xad6c47c1d82b6c6cull, | |||
0xc43195f562a43131ull, 0xcd7487b9e8f37474ull, 0xfff6e309f115f6f6ull, 0x05460a438c4c4646ull, 0x8aac092645a5acacull, 0x1e893c970fb58989ull, 0x5014a04428b41414ull, 0xa3e15b42dfbae1e1ull, | |||
0x5816b04e2ca61616ull, 0xe83acdd274f73a3aull, 0xb9696fd0d2066969ull, 0x2409482d12410909ull, 0xdd70a7ade0d77070ull, 0xe2b6d954716fb6b6ull, 0x67d0ceb7bd1ed0d0ull, 0x93ed3b7ec7d6ededull, | |||
0x17cc2edb85e2ccccull, 0x15422a5784684242ull, 0x5a98b4c22d2c9898ull, 0xaaa4490e55eda4a4ull, 0xa0285d8850752828ull, 0x6d5cda31b8865c5cull, 0xc7f8933fed6bf8f8ull, 0x228644a411c28686ull | |||
}; | |||
static const uint64_t C7[] = | |||
{ 0x186018c07830d818ull, 0x238c2305af462623ull, 0xc63fc67ef991b8c6ull, 0xe887e8136fcdfbe8ull, 0x8726874ca113cb87ull, 0xb8dab8a9626d11b8ull, 0x0104010805020901ull, 0x4f214f426e9e0d4full, | |||
0x36d836adee6c9b36ull, 0xa6a2a6590451ffa6ull, 0xd26fd2debdb90cd2ull, 0xf5f3f5fb06f70ef5ull, 0x79f979ef80f29679ull, 0x6fa16f5fcede306full, 0x917e91fcef3f6d91ull, 0x525552aa07a4f852ull, | |||
0x609d6027fdc04760ull, 0xbccabc89766535bcull, 0x9b569baccd2b379bull, 0x8e028e048c018a8eull, 0xa3b6a371155bd2a3ull, 0x0c300c603c186c0cull, 0x7bf17bff8af6847bull, 0x35d435b5e16a8035ull, | |||
0x1d741de8693af51dull, 0xe0a7e05347ddb3e0ull, 0xd77bd7f6acb321d7ull, 0xc22fc25eed999cc2ull, 0x2eb82e6d965c432eull, 0x4b314b627a96294bull, 0xfedffea321e15dfeull, 0x5741578216aed557ull, | |||
0x155415a8412abd15ull, 0x77c1779fb6eee877ull, 0x37dc37a5eb6e9237ull, 0xe5b3e57b56d79ee5ull, 0x9f469f8cd923139full, 0xf0e7f0d317fd23f0ull, 0x4a354a6a7f94204aull, 0xda4fda9e95a944daull, | |||
0x587d58fa25b0a258ull, 0xc903c906ca8fcfc9ull, 0x29a429558d527c29ull, 0x0a280a5022145a0aull, 0xb1feb1e14f7f50b1ull, 0xa0baa0691a5dc9a0ull, 0x6bb16b7fdad6146bull, 0x852e855cab17d985ull, | |||
0xbdcebd8173673cbdull, 0x5d695dd234ba8f5dull, 0x1040108050209010ull, 0xf4f7f4f303f507f4ull, 0xcb0bcb16c08bddcbull, 0x3ef83eedc67cd33eull, 0x05140528110a2d05ull, 0x6781671fe6ce7867ull, | |||
0xe4b7e47353d597e4ull, 0x279c2725bb4e0227ull, 0x4119413258827341ull, 0x8b168b2c9d0ba78bull, 0xa7a6a7510153f6a7ull, 0x7de97dcf94fab27dull, 0x956e95dcfb374995ull, 0xd847d88e9fad56d8ull, | |||
0xfbcbfb8b30eb70fbull, 0xee9fee2371c1cdeeull, 0x7ced7cc791f8bb7cull, 0x66856617e3cc7166ull, 0xdd53dda68ea77bddull, 0x175c17b84b2eaf17ull, 0x47014702468e4547ull, 0x9e429e84dc211a9eull, | |||
0xca0fca1ec589d4caull, 0x2db42d75995a582dull, 0xbfc6bf9179632ebfull, 0x071c07381b0e3f07ull, 0xad8ead012347acadull, 0x5a755aea2fb4b05aull, 0x8336836cb51bef83ull, 0x33cc3385ff66b633ull, | |||
0x6391633ff2c65c63ull, 0x020802100a041202ull, 0xaa92aa39384993aaull, 0x71d971afa8e2de71ull, 0xc807c80ecf8dc6c8ull, 0x196419c87d32d119ull, 0x4939497270923b49ull, 0xd943d9869aaf5fd9ull, | |||
0xf2eff2c31df931f2ull, 0xe3abe34b48dba8e3ull, 0x5b715be22ab6b95bull, 0x881a8834920dbc88ull, 0x9a529aa4c8293e9aull, 0x2698262dbe4c0b26ull, 0x32c8328dfa64bf32ull, 0xb0fab0e94a7d59b0ull, | |||
0xe983e91b6acff2e9ull, 0x0f3c0f78331e770full, 0xd573d5e6a6b733d5ull, 0x803a8074ba1df480ull, 0xbec2be997c6127beull, 0xcd13cd26de87ebcdull, 0x34d034bde4688934ull, 0x483d487a75903248ull, | |||
0xffdbffab24e354ffull, 0x7af57af78ff48d7aull, 0x907a90f4ea3d6490ull, 0x5f615fc23ebe9d5full, 0x2080201da0403d20ull, 0x68bd6867d5d00f68ull, 0x1a681ad07234ca1aull, 0xae82ae192c41b7aeull, | |||
0xb4eab4c95e757db4ull, 0x544d549a19a8ce54ull, 0x937693ece53b7f93ull, 0x2288220daa442f22ull, 0x648d6407e9c86364ull, 0xf1e3f1db12ff2af1ull, 0x73d173bfa2e6cc73ull, 0x124812905a248212ull, | |||
0x401d403a5d807a40ull, 0x0820084028104808ull, 0xc32bc356e89b95c3ull, 0xec97ec337bc5dfecull, 0xdb4bdb9690ab4ddbull, 0xa1bea1611f5fc0a1ull, 0x8d0e8d1c8307918dull, 0x3df43df5c97ac83dull, | |||
0x976697ccf1335b97ull, 0x0000000000000000ull, 0xcf1bcf36d483f9cfull, 0x2bac2b4587566e2bull, 0x76c57697b3ece176ull, 0x82328264b019e682ull, 0xd67fd6fea9b128d6ull, 0x1b6c1bd87736c31bull, | |||
0xb5eeb5c15b7774b5ull, 0xaf86af112943beafull, 0x6ab56a77dfd41d6aull, 0x505d50ba0da0ea50ull, 0x450945124c8a5745ull, 0xf3ebf3cb18fb38f3ull, 0x30c0309df060ad30ull, 0xef9bef2b74c3c4efull, | |||
0x3ffc3fe5c37eda3full, 0x554955921caac755ull, 0xa2b2a2791059dba2ull, 0xea8fea0365c9e9eaull, 0x6589650fecca6a65ull, 0xbad2bab9686903baull, 0x2fbc2f65935e4a2full, 0xc027c04ee79d8ec0ull, | |||
0xde5fdebe81a160deull, 0x1c701ce06c38fc1cull, 0xfdd3fdbb2ee746fdull, 0x4d294d52649a1f4dull, 0x927292e4e0397692ull, 0x75c9758fbceafa75ull, 0x061806301e0c3606ull, 0x8a128a249809ae8aull, | |||
0xb2f2b2f940794bb2ull, 0xe6bfe66359d185e6ull, 0x0e380e70361c7e0eull, 0x1f7c1ff8633ee71full, 0x62956237f7c45562ull, 0xd477d4eea3b53ad4ull, 0xa89aa829324d81a8ull, 0x966296c4f4315296ull, | |||
0xf9c3f99b3aef62f9ull, 0xc533c566f697a3c5ull, 0x25942535b14a1025ull, 0x597959f220b2ab59ull, 0x842a8454ae15d084ull, 0x72d572b7a7e4c572ull, 0x39e439d5dd72ec39ull, 0x4c2d4c5a6198164cull, | |||
0x5e655eca3bbc945eull, 0x78fd78e785f09f78ull, 0x38e038ddd870e538ull, 0x8c0a8c148605988cull, 0xd163d1c6b2bf17d1ull, 0xa5aea5410b57e4a5ull, 0xe2afe2434dd9a1e2ull, 0x6199612ff8c24e61ull, | |||
0xb3f6b3f1457b42b3ull, 0x21842115a5423421ull, 0x9c4a9c94d625089cull, 0x1e781ef0663cee1eull, 0x4311432252866143ull, 0xc73bc776fc93b1c7ull, 0xfcd7fcb32be54ffcull, 0x0410042014082404ull, | |||
0x515951b208a2e351ull, 0x995e99bcc72f2599ull, 0x6da96d4fc4da226dull, 0x0d340d68391a650dull, 0xfacffa8335e979faull, 0xdf5bdfb684a369dfull, 0x7ee57ed79bfca97eull, 0x2490243db4481924ull, | |||
0x3bec3bc5d776fe3bull, 0xab96ab313d4b9aabull, 0xce1fce3ed181f0ceull, 0x1144118855229911ull, 0x8f068f0c8903838full, 0x4e254e4a6b9c044eull, 0xb7e6b7d1517366b7ull, 0xeb8beb0b60cbe0ebull, | |||
0x3cf03cfdcc78c13cull, 0x813e817cbf1ffd81ull, 0x946a94d4fe354094ull, 0xf7fbf7eb0cf31cf7ull, 0xb9deb9a1676f18b9ull, 0x134c13985f268b13ull, 0x2cb02c7d9c58512cull, 0xd36bd3d6b8bb05d3ull, | |||
0xe7bbe76b5cd38ce7ull, 0x6ea56e57cbdc396eull, 0xc437c46ef395aac4ull, 0x030c03180f061b03ull, 0x5645568a13acdc56ull, 0x440d441a49885e44ull, 0x7fe17fdf9efea07full, 0xa99ea921374f88a9ull, | |||
0x2aa82a4d8254672aull, 0xbbd6bbb16d6b0abbull, 0xc123c146e29f87c1ull, 0x535153a202a6f153ull, 0xdc57dcae8ba572dcull, 0x0b2c0b582716530bull, 0x9d4e9d9cd327019dull, 0x6cad6c47c1d82b6cull, | |||
0x31c43195f562a431ull, 0x74cd7487b9e8f374ull, 0xf6fff6e309f115f6ull, 0x4605460a438c4c46ull, 0xac8aac092645a5acull, 0x891e893c970fb589ull, 0x145014a04428b414ull, 0xe1a3e15b42dfbae1ull, | |||
0x165816b04e2ca616ull, 0x3ae83acdd274f73aull, 0x69b9696fd0d20669ull, 0x092409482d124109ull, 0x70dd70a7ade0d770ull, 0xb6e2b6d954716fb6ull, 0xd067d0ceb7bd1ed0ull, 0xed93ed3b7ec7d6edull, | |||
0xcc17cc2edb85e2ccull, 0x4215422a57846842ull, 0x985a98b4c22d2c98ull, 0xa4aaa4490e55eda4ull, 0x28a0285d88507528ull, 0x5c6d5cda31b8865cull, 0xf8c7f8933fed6bf8ull, 0x86228644a411c286ull | |||
}; | |||
uint64_t block[8]; | |||
const uint8_t* b = buffer; | |||
for (int i = 0; i < 8; ++i, b += 8) | |||
block[i] = (((uint64_t) b[0] ) << 56) | |||
^ (((uint64_t) b[1] & 0xff) << 48) | |||
^ (((uint64_t) b[2] & 0xff) << 40) | |||
^ (((uint64_t) b[3] & 0xff) << 32) | |||
^ (((uint64_t) b[4] & 0xff) << 24) | |||
^ (((uint64_t) b[5] & 0xff) << 16) | |||
^ (((uint64_t) b[6] & 0xff) << 8) | |||
^ (((uint64_t) b[7] & 0xff)); | |||
uint64_t state[8], K[8]; | |||
state[0] = block[0] ^ (K[0] = hash[0]); | |||
state[1] = block[1] ^ (K[1] = hash[1]); | |||
state[2] = block[2] ^ (K[2] = hash[2]); | |||
state[3] = block[3] ^ (K[3] = hash[3]); | |||
state[4] = block[4] ^ (K[4] = hash[4]); | |||
state[5] = block[5] ^ (K[5] = hash[5]); | |||
state[6] = block[6] ^ (K[6] = hash[6]); | |||
state[7] = block[7] ^ (K[7] = hash[7]); | |||
for (int i = 0; i < 10; ++i) | |||
{ | |||
uint64_t L[8]; | |||
L[0] = C0[(int) (K[0] >> 56)] ^ C1[(int) (K[7] >> 48) & 0xff] ^ C2[(int) (K[6] >> 40) & 0xff] ^ C3[(int) (K[5] >> 32) & 0xff] ^ C4[(int) (K[4] >> 24) & 0xff] ^ C5[(int) (K[3] >> 16) & 0xff] ^ C6[(int) (K[2] >> 8) & 0xff] ^ C7[(int) (K[1]) & 0xff] ^ rc[i]; | |||
L[1] = C0[(int) (K[1] >> 56)] ^ C1[(int) (K[0] >> 48) & 0xff] ^ C2[(int) (K[7] >> 40) & 0xff] ^ C3[(int) (K[6] >> 32) & 0xff] ^ C4[(int) (K[5] >> 24) & 0xff] ^ C5[(int) (K[4] >> 16) & 0xff] ^ C6[(int) (K[3] >> 8) & 0xff] ^ C7[(int) (K[2]) & 0xff]; | |||
L[2] = C0[(int) (K[2] >> 56)] ^ C1[(int) (K[1] >> 48) & 0xff] ^ C2[(int) (K[0] >> 40) & 0xff] ^ C3[(int) (K[7] >> 32) & 0xff] ^ C4[(int) (K[6] >> 24) & 0xff] ^ C5[(int) (K[5] >> 16) & 0xff] ^ C6[(int) (K[4] >> 8) & 0xff] ^ C7[(int) (K[3]) & 0xff]; | |||
L[3] = C0[(int) (K[3] >> 56)] ^ C1[(int) (K[2] >> 48) & 0xff] ^ C2[(int) (K[1] >> 40) & 0xff] ^ C3[(int) (K[0] >> 32) & 0xff] ^ C4[(int) (K[7] >> 24) & 0xff] ^ C5[(int) (K[6] >> 16) & 0xff] ^ C6[(int) (K[5] >> 8) & 0xff] ^ C7[(int) (K[4]) & 0xff]; | |||
L[4] = C0[(int) (K[4] >> 56)] ^ C1[(int) (K[3] >> 48) & 0xff] ^ C2[(int) (K[2] >> 40) & 0xff] ^ C3[(int) (K[1] >> 32) & 0xff] ^ C4[(int) (K[0] >> 24) & 0xff] ^ C5[(int) (K[7] >> 16) & 0xff] ^ C6[(int) (K[6] >> 8) & 0xff] ^ C7[(int) (K[5]) & 0xff]; | |||
L[5] = C0[(int) (K[5] >> 56)] ^ C1[(int) (K[4] >> 48) & 0xff] ^ C2[(int) (K[3] >> 40) & 0xff] ^ C3[(int) (K[2] >> 32) & 0xff] ^ C4[(int) (K[1] >> 24) & 0xff] ^ C5[(int) (K[0] >> 16) & 0xff] ^ C6[(int) (K[7] >> 8) & 0xff] ^ C7[(int) (K[6]) & 0xff]; | |||
L[6] = C0[(int) (K[6] >> 56)] ^ C1[(int) (K[5] >> 48) & 0xff] ^ C2[(int) (K[4] >> 40) & 0xff] ^ C3[(int) (K[3] >> 32) & 0xff] ^ C4[(int) (K[2] >> 24) & 0xff] ^ C5[(int) (K[1] >> 16) & 0xff] ^ C6[(int) (K[0] >> 8) & 0xff] ^ C7[(int) (K[7]) & 0xff]; | |||
L[7] = C0[(int) (K[7] >> 56)] ^ C1[(int) (K[6] >> 48) & 0xff] ^ C2[(int) (K[5] >> 40) & 0xff] ^ C3[(int) (K[4] >> 32) & 0xff] ^ C4[(int) (K[3] >> 24) & 0xff] ^ C5[(int) (K[2] >> 16) & 0xff] ^ C6[(int) (K[1] >> 8) & 0xff] ^ C7[(int) (K[0]) & 0xff]; | |||
K[0] = L[0]; | |||
K[1] = L[1]; | |||
K[2] = L[2]; | |||
K[3] = L[3]; | |||
K[4] = L[4]; | |||
K[5] = L[5]; | |||
K[6] = L[6]; | |||
K[7] = L[7]; | |||
// apply the i-th round transformation | |||
L[0] = C0[(int) (state[0] >> 56)] ^ C1[(int) (state[7] >> 48) & 0xff] ^ C2[(int) (state[6] >> 40) & 0xff] ^ C3[(int) (state[5] >> 32) & 0xff] ^ C4[(int) (state[4] >> 24) & 0xff] ^ C5[(int) (state[3] >> 16) & 0xff] ^ C6[(int) (state[2] >> 8) & 0xff] ^ C7[(int) (state[1]) & 0xff] ^ K[0]; | |||
L[1] = C0[(int) (state[1] >> 56)] ^ C1[(int) (state[0] >> 48) & 0xff] ^ C2[(int) (state[7] >> 40) & 0xff] ^ C3[(int) (state[6] >> 32) & 0xff] ^ C4[(int) (state[5] >> 24) & 0xff] ^ C5[(int) (state[4] >> 16) & 0xff] ^ C6[(int) (state[3] >> 8) & 0xff] ^ C7[(int) (state[2]) & 0xff] ^ K[1]; | |||
L[2] = C0[(int) (state[2] >> 56)] ^ C1[(int) (state[1] >> 48) & 0xff] ^ C2[(int) (state[0] >> 40) & 0xff] ^ C3[(int) (state[7] >> 32) & 0xff] ^ C4[(int) (state[6] >> 24) & 0xff] ^ C5[(int) (state[5] >> 16) & 0xff] ^ C6[(int) (state[4] >> 8) & 0xff] ^ C7[(int) (state[3]) & 0xff] ^ K[2]; | |||
L[3] = C0[(int) (state[3] >> 56)] ^ C1[(int) (state[2] >> 48) & 0xff] ^ C2[(int) (state[1] >> 40) & 0xff] ^ C3[(int) (state[0] >> 32) & 0xff] ^ C4[(int) (state[7] >> 24) & 0xff] ^ C5[(int) (state[6] >> 16) & 0xff] ^ C6[(int) (state[5] >> 8) & 0xff] ^ C7[(int) (state[4]) & 0xff] ^ K[3]; | |||
L[4] = C0[(int) (state[4] >> 56)] ^ C1[(int) (state[3] >> 48) & 0xff] ^ C2[(int) (state[2] >> 40) & 0xff] ^ C3[(int) (state[1] >> 32) & 0xff] ^ C4[(int) (state[0] >> 24) & 0xff] ^ C5[(int) (state[7] >> 16) & 0xff] ^ C6[(int) (state[6] >> 8) & 0xff] ^ C7[(int) (state[5]) & 0xff] ^ K[4]; | |||
L[5] = C0[(int) (state[5] >> 56)] ^ C1[(int) (state[4] >> 48) & 0xff] ^ C2[(int) (state[3] >> 40) & 0xff] ^ C3[(int) (state[2] >> 32) & 0xff] ^ C4[(int) (state[1] >> 24) & 0xff] ^ C5[(int) (state[0] >> 16) & 0xff] ^ C6[(int) (state[7] >> 8) & 0xff] ^ C7[(int) (state[6]) & 0xff] ^ K[5]; | |||
L[6] = C0[(int) (state[6] >> 56)] ^ C1[(int) (state[5] >> 48) & 0xff] ^ C2[(int) (state[4] >> 40) & 0xff] ^ C3[(int) (state[3] >> 32) & 0xff] ^ C4[(int) (state[2] >> 24) & 0xff] ^ C5[(int) (state[1] >> 16) & 0xff] ^ C6[(int) (state[0] >> 8) & 0xff] ^ C7[(int) (state[7]) & 0xff] ^ K[6]; | |||
L[7] = C0[(int) (state[7] >> 56)] ^ C1[(int) (state[6] >> 48) & 0xff] ^ C2[(int) (state[5] >> 40) & 0xff] ^ C3[(int) (state[4] >> 32) & 0xff] ^ C4[(int) (state[3] >> 24) & 0xff] ^ C5[(int) (state[2] >> 16) & 0xff] ^ C6[(int) (state[1] >> 8) & 0xff] ^ C7[(int) (state[0]) & 0xff] ^ K[7]; | |||
state[0] = L[0]; | |||
state[1] = L[1]; | |||
state[2] = L[2]; | |||
state[3] = L[3]; | |||
state[4] = L[4]; | |||
state[5] = L[5]; | |||
state[6] = L[6]; | |||
state[7] = L[7]; | |||
} | |||
// apply the Miyaguchi-Preneel compression function | |||
hash[0] ^= state[0] ^ block[0]; | |||
hash[1] ^= state[1] ^ block[1]; | |||
hash[2] ^= state[2] ^ block[2]; | |||
hash[3] ^= state[3] ^ block[3]; | |||
hash[4] ^= state[4] ^ block[4]; | |||
hash[5] ^= state[5] ^ block[5]; | |||
hash[6] ^= state[6] ^ block[6]; | |||
hash[7] ^= state[7] ^ block[7]; | |||
} | |||
}; | |||
//============================================================================== | |||
Whirlpool::Whirlpool() noexcept | |||
{ | |||
zerostruct (result); | |||
} | |||
Whirlpool::~Whirlpool() noexcept {} | |||
Whirlpool::Whirlpool (const Whirlpool& other) noexcept | |||
{ | |||
memcpy (result, other.result, sizeof (result)); | |||
} | |||
Whirlpool& Whirlpool::operator= (const Whirlpool& other) noexcept | |||
{ | |||
memcpy (result, other.result, sizeof (result)); | |||
return *this; | |||
} | |||
Whirlpool::Whirlpool (const MemoryBlock& data) | |||
{ | |||
process (data.getData(), data.getSize()); | |||
} | |||
Whirlpool::Whirlpool (const void* data, size_t numBytes) | |||
{ | |||
process (data, numBytes); | |||
} | |||
Whirlpool::Whirlpool (InputStream& input, int64 numBytesToRead) | |||
{ | |||
WhirlpoolProcessor processor; | |||
processor.processStream (input, numBytesToRead, result); | |||
} | |||
Whirlpool::Whirlpool (const File& file) | |||
{ | |||
FileInputStream fin (file); | |||
if (fin.getStatus().wasOk()) | |||
{ | |||
WhirlpoolProcessor processor; | |||
processor.processStream (fin, -1, result); | |||
} | |||
else | |||
{ | |||
zerostruct (result); | |||
} | |||
} | |||
Whirlpool::Whirlpool (CharPointer_UTF8 utf8) noexcept | |||
{ | |||
jassert (utf8.getAddress() != nullptr); | |||
process (utf8.getAddress(), utf8.sizeInBytes() - 1); | |||
} | |||
void Whirlpool::process (const void* data, size_t numBytes) | |||
{ | |||
MemoryInputStream m (data, numBytes, false); | |||
WhirlpoolProcessor processor; | |||
processor.processStream (m, -1, result); | |||
} | |||
MemoryBlock Whirlpool::getRawData() const | |||
{ | |||
return MemoryBlock (result, sizeof (result)); | |||
} | |||
String Whirlpool::toHexString() const | |||
{ | |||
return String::toHexString (result, sizeof (result), 0); | |||
} | |||
bool Whirlpool::operator== (const Whirlpool& other) const noexcept { return memcmp (result, other.result, sizeof (result)) == 0; } | |||
bool Whirlpool::operator!= (const Whirlpool& other) const noexcept { return ! operator== (other); } | |||
//============================================================================== | |||
//============================================================================== | |||
#if JUCE_UNIT_TESTS | |||
class WhirlpoolTests : public UnitTest | |||
{ | |||
public: | |||
WhirlpoolTests() | |||
: UnitTest ("Whirlpool", UnitTestCategories::cryptography) | |||
{} | |||
void test (const char* input, const char* expected) | |||
{ | |||
{ | |||
Whirlpool hash (input, strlen (input)); | |||
expectEquals (hash.toHexString(), String (expected)); | |||
} | |||
{ | |||
CharPointer_UTF8 utf8 (input); | |||
Whirlpool hash (utf8); | |||
expectEquals (hash.toHexString(), String (expected)); | |||
} | |||
{ | |||
MemoryInputStream m (input, strlen (input), false); | |||
Whirlpool hash (m); | |||
expectEquals (hash.toHexString(), String (expected)); | |||
} | |||
} | |||
void runTest() override | |||
{ | |||
beginTest ("Whirlpool"); | |||
test ("", "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3"); | |||
test ("The quick brown fox jumps over the lazy dog", "b97de512e91e3828b40d2b0fdce9ceb3c4a71f9bea8d88e75c4fa854df36725fd2b52eb6544edcacd6f8beddfea403cb55ae31f03ad62a5ef54e42ee82c3fb35"); | |||
test ("The quick brown fox jumps over the lazy dog.", "87a7ff096082e3ffeb86db10feb91c5af36c2c71bc426fe310ce662e0338223e217def0eab0b02b80eecf875657802bc5965e48f5c0a05467756f0d3f396faba"); | |||
} | |||
}; | |||
static WhirlpoolTests whirlpoolUnitTests; | |||
#endif | |||
} // namespace juce |
@@ -0,0 +1,114 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
namespace juce | |||
{ | |||
//============================================================================== | |||
/** | |||
Whirlpool hash class. | |||
The Whirlpool algorithm was developed by | |||
<a href="mailto:pbarreto@scopus.com.br">Paulo S. L. M. Barreto</a> and | |||
<a href="mailto:vincent.rijmen@cryptomathic.com">Vincent Rijmen</a>. | |||
See | |||
P.S.L.M. Barreto, V. Rijmen, | |||
"The Whirlpool hashing function" | |||
NESSIE submission, 2000 (tweaked version, 2001), | |||
https://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/whirlpool.zip | |||
@see SHA256, MD5 | |||
@tags{Cryptography} | |||
*/ | |||
class JUCE_API Whirlpool | |||
{ | |||
public: | |||
//============================================================================== | |||
/** Creates an empty Whirlpool object. | |||
The default constructor just creates a hash filled with zeros. (This is not | |||
equal to the hash of an empty block of data). | |||
*/ | |||
Whirlpool() noexcept; | |||
/** Destructor. */ | |||
~Whirlpool() noexcept; | |||
/** Creates a copy of another Whirlpool. */ | |||
Whirlpool (const Whirlpool& other) noexcept; | |||
/** Copies another Whirlpool. */ | |||
Whirlpool& operator= (const Whirlpool& other) noexcept; | |||
//============================================================================== | |||
/** Creates a hash from a block of raw data. */ | |||
explicit Whirlpool (const MemoryBlock&); | |||
/** Creates a hash from a block of raw data. */ | |||
Whirlpool (const void* data, size_t numBytes); | |||
/** Creates a hash from the contents of a stream. | |||
This will read from the stream until the stream is exhausted, or until | |||
maxBytesToRead bytes have been read. If maxBytesToRead is negative, the entire | |||
stream will be read. | |||
*/ | |||
Whirlpool (InputStream& input, int64 maxBytesToRead = -1); | |||
/** Reads a file and generates the hash of its contents. | |||
If the file can't be opened, the hash will be left uninitialised | |||
(i.e. full of zeros). | |||
*/ | |||
explicit Whirlpool (const File& file); | |||
/** Creates a checksum from a UTF-8 buffer. | |||
E.g. | |||
@code Whirlpool checksum (myString.toUTF8()); | |||
@endcode | |||
*/ | |||
explicit Whirlpool (CharPointer_UTF8 utf8Text) noexcept; | |||
//============================================================================== | |||
/** Returns the hash as a 64-byte block of data. */ | |||
MemoryBlock getRawData() const; | |||
/** Returns the checksum as a 128-digit hex string. */ | |||
String toHexString() const; | |||
//============================================================================== | |||
bool operator== (const Whirlpool&) const noexcept; | |||
bool operator!= (const Whirlpool&) const noexcept; | |||
private: | |||
//============================================================================== | |||
uint8 result [64]; | |||
void process (const void*, size_t); | |||
JUCE_LEAK_DETECTOR (Whirlpool) | |||
}; | |||
} // namespace juce |
@@ -0,0 +1,42 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
#ifdef JUCE_CRYPTOGRAPHY_H_INCLUDED | |||
/* When you add this cpp file to your project, you mustn't include it in a file where you've | |||
already included any other headers - just put it inside a file on its own, possibly with your config | |||
flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix | |||
header files that the compiler may be using. | |||
*/ | |||
#error "Incorrect use of JUCE cpp file" | |||
#endif | |||
#include "juce_cryptography.h" | |||
#include "encryption/juce_BlowFish.cpp" | |||
#include "encryption/juce_Primes.cpp" | |||
#include "encryption/juce_RSAKey.cpp" | |||
#include "hashing/juce_MD5.cpp" | |||
#include "hashing/juce_SHA256.cpp" | |||
#include "hashing/juce_Whirlpool.cpp" |
@@ -0,0 +1,62 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
/******************************************************************************* | |||
The block below describes the properties of this module, and is read by | |||
the Projucer to automatically generate project code that uses it. | |||
For details about the syntax and how to create or use a module, see the | |||
JUCE Module Format.md file. | |||
BEGIN_JUCE_MODULE_DECLARATION | |||
ID: juce_cryptography | |||
vendor: juce | |||
version: 6.0.0 | |||
name: JUCE cryptography classes | |||
description: Classes for various basic cryptography functions, including RSA, Blowfish, MD5, SHA, etc. | |||
website: http://www.juce.com/juce | |||
license: GPL/Commercial | |||
dependencies: juce_core | |||
END_JUCE_MODULE_DECLARATION | |||
*******************************************************************************/ | |||
#pragma once | |||
#define JUCE_CRYPTOGRAPHY_H_INCLUDED | |||
//============================================================================== | |||
#include <juce_core/juce_core.h> | |||
#include "encryption/juce_BlowFish.h" | |||
#include "encryption/juce_Primes.h" | |||
#include "encryption/juce_RSAKey.h" | |||
#include "hashing/juce_MD5.h" | |||
#include "hashing/juce_SHA256.h" | |||
#include "hashing/juce_Whirlpool.h" |
@@ -0,0 +1,26 @@ | |||
/* | |||
============================================================================== | |||
This file is part of the JUCE library. | |||
Copyright (c) 2020 - Raw Material Software Limited | |||
JUCE is an open source library subject to commercial or open-source | |||
licensing. | |||
By using JUCE, you agree to the terms of both the JUCE 6 End-User License | |||
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). | |||
End User License Agreement: www.juce.com/juce-6-licence | |||
Privacy Policy: www.juce.com/juce-privacy-policy | |||
Or: You may also use this code under the terms of the GPL v3 (see | |||
www.gnu.org/licenses). | |||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER | |||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE | |||
DISCLAIMED. | |||
============================================================================== | |||
*/ | |||
#include "juce_cryptography.cpp" |
@@ -2,6 +2,7 @@ | |||
subdir('drowaudio') | |||
subdir('juced') | |||
subdir('juce-current') | |||
subdir('juce-legacy') | |||
subdir('lv2-ttl-generator') | |||