├── README.md ├── _build.bat ├── cdmapi_src ├── bind.cpp ├── codelift.cpp ├── codelift.h ├── cryptlib.lib └── wasm │ ├── algebra.h │ ├── algparam.h │ ├── allocate.h │ ├── config.h │ ├── config_align.h │ ├── config_asm.h │ ├── config_cpu.h │ ├── config_cxx.h │ ├── config_dll.h │ ├── config_int.h │ ├── config_misc.h │ ├── config_ns.h │ ├── config_os.h │ ├── config_ver.h │ ├── cpu.h │ ├── cryptlib.h │ ├── filters.h │ ├── integer.h │ ├── longconsts.h │ ├── misc.h │ ├── modarith.h │ ├── nbtheory.h │ ├── pch.h │ ├── queue.h │ ├── secblock.h │ ├── secblockfwd.h │ ├── simple.h │ ├── smartptr.h │ ├── stdcpp.h │ ├── trap.h │ └── words.h ├── cryptlib_src ├── cryptlib.sln ├── cryptopp850 │ ├── 3way.cpp │ ├── 3way.h │ ├── Doxyfile │ ├── Filelist.txt │ ├── GNUmakefile │ ├── GNUmakefile-cross │ ├── History.txt │ ├── Install.txt │ ├── License.txt │ ├── Readme.txt │ ├── adhoc.cpp │ ├── adhoc.cpp.copied │ ├── adhoc.cpp.proto │ ├── adler32.cpp │ ├── adler32.h │ ├── adv_simd.h │ ├── aes.h │ ├── aes_armv4.S │ ├── aes_armv4.h │ ├── algebra.cpp │ ├── algebra.h │ ├── algparam.cpp │ ├── algparam.h │ ├── allocate.cpp │ ├── allocate.h │ ├── arc4.cpp │ ├── arc4.h │ ├── argnames.h │ ├── aria.cpp │ ├── aria.h │ ├── aria_simd.cpp │ ├── ariatab.cpp │ ├── arm_simd.h │ ├── asn.cpp │ ├── asn.h │ ├── authenc.cpp │ ├── authenc.h │ ├── base32.cpp │ ├── base32.h │ ├── base64.cpp │ ├── base64.h │ ├── basecode.cpp │ ├── basecode.h │ ├── bench.h │ ├── bench1.cpp │ ├── bench2.cpp │ ├── bench3.cpp │ ├── bfinit.cpp │ ├── blake2.cpp │ ├── blake2.h │ ├── blake2b_simd.cpp │ ├── blake2s_simd.cpp │ ├── blowfish.cpp │ ├── blowfish.h │ ├── blumshub.cpp │ ├── blumshub.h │ ├── camellia.cpp │ ├── camellia.h │ ├── cast.cpp │ ├── cast.h │ ├── casts.cpp │ ├── cbcmac.cpp │ ├── cbcmac.h │ ├── ccm.cpp │ ├── ccm.h │ ├── chacha.cpp │ ├── chacha.h │ ├── chacha_avx.cpp │ ├── chacha_simd.cpp │ ├── chachapoly.cpp │ ├── chachapoly.h │ ├── cham.cpp │ ├── cham.h │ ├── cham_simd.cpp │ ├── channels.cpp │ ├── channels.h │ ├── cmac.cpp │ ├── cmac.h │ ├── config.h │ ├── config_align.h │ ├── config_asm.h │ ├── config_cpu.h │ ├── config_cxx.h │ ├── config_dll.h │ ├── config_int.h │ ├── config_misc.h │ ├── config_ns.h │ ├── config_os.h │ ├── config_ver.h │ ├── cpu.cpp │ ├── cpu.h │ ├── crc.cpp │ ├── crc.h │ ├── crc_simd.cpp │ ├── cryptest.nmake │ ├── cryptest.vcxproj.user │ ├── cryptlib.cpp │ ├── cryptlib.h │ ├── cryptlib.vcxproj │ ├── cryptlib.vcxproj.filters │ ├── cryptlib.vcxproj.user │ ├── cryptopp.rc │ ├── cryptopp.supp │ ├── darn.cpp │ ├── darn.h │ ├── datatest.cpp │ ├── default.cpp │ ├── default.h │ ├── des.cpp │ ├── des.h │ ├── dessp.cpp │ ├── dh.cpp │ ├── dh.h │ ├── dh2.cpp │ ├── dh2.h │ ├── dll.cpp │ ├── dll.h │ ├── dlltest.cpp │ ├── dmac.h │ ├── donna.h │ ├── donna_32.cpp │ ├── donna_32.h │ ├── donna_64.cpp │ ├── donna_64.h │ ├── donna_sse.cpp │ ├── donna_sse.h │ ├── drbg.h │ ├── dsa.cpp │ ├── dsa.h │ ├── eax.cpp │ ├── eax.h │ ├── ec2n.cpp │ ├── ec2n.h │ ├── eccrypto.cpp │ ├── eccrypto.h │ ├── ecp.cpp │ ├── ecp.h │ ├── ecpoint.h │ ├── elgamal.cpp │ ├── elgamal.h │ ├── emsa2.cpp │ ├── emsa2.h │ ├── eprecomp.cpp │ ├── eprecomp.h │ ├── esign.cpp │ ├── esign.h │ ├── factory.h │ ├── fhmqv.h │ ├── files.cpp │ ├── files.h │ ├── filters.cpp │ ├── filters.h │ ├── fips140.cpp │ ├── fips140.h │ ├── fipsalgt.cpp │ ├── fipstest.cpp │ ├── fltrimpl.h │ ├── gcm.cpp │ ├── gcm.h │ ├── gcm_simd.cpp │ ├── gf256.cpp │ ├── gf256.h │ ├── gf2_32.cpp │ ├── gf2_32.h │ ├── gf2n.cpp │ ├── gf2n.h │ ├── gf2n_simd.cpp │ ├── gfpcrypt.cpp │ ├── gfpcrypt.h │ ├── gost.cpp │ ├── gost.h │ ├── gzip.cpp │ ├── gzip.h │ ├── hashfwd.h │ ├── hc128.cpp │ ├── hc128.h │ ├── hc256.cpp │ ├── hc256.h │ ├── hex.cpp │ ├── hex.h │ ├── hight.cpp │ ├── hight.h │ ├── hkdf.h │ ├── hmac.cpp │ ├── hmac.h │ ├── hmqv.h │ ├── hrtimer.cpp │ ├── hrtimer.h │ ├── ida.cpp │ ├── ida.h │ ├── idea.cpp │ ├── idea.h │ ├── integer.cpp │ ├── integer.h │ ├── iterhash.cpp │ ├── iterhash.h │ ├── kalyna.cpp │ ├── kalyna.h │ ├── kalynatab.cpp │ ├── keccak.cpp │ ├── keccak.h │ ├── keccak_core.cpp │ ├── keccak_simd.cpp │ ├── lea.cpp │ ├── lea.h │ ├── lea_simd.cpp │ ├── lubyrack.h │ ├── luc.cpp │ ├── luc.h │ ├── mars.cpp │ ├── mars.h │ ├── marss.cpp │ ├── md2.cpp │ ├── md2.h │ ├── md4.cpp │ ├── md4.h │ ├── md5.cpp │ ├── md5.h │ ├── mdc.h │ ├── mersenne.h │ ├── misc.cpp │ ├── misc.h │ ├── modarith.h │ ├── modes.cpp │ ├── modes.h │ ├── modexppc.h │ ├── mqueue.cpp │ ├── mqueue.h │ ├── mqv.cpp │ ├── mqv.h │ ├── naclite.h │ ├── nbtheory.cpp │ ├── nbtheory.h │ ├── neon_simd.cpp │ ├── nr.h │ ├── oaep.cpp │ ├── oaep.h │ ├── oids.h │ ├── osrng.cpp │ ├── osrng.h │ ├── ossig.h │ ├── padlkrng.cpp │ ├── padlkrng.h │ ├── panama.cpp │ ├── panama.h │ ├── pch.cpp │ ├── pch.h │ ├── pkcspad.cpp │ ├── pkcspad.h │ ├── poly1305.cpp │ ├── poly1305.h │ ├── polynomi.cpp │ ├── polynomi.h │ ├── ppc_power7.cpp │ ├── ppc_power8.cpp │ ├── ppc_power9.cpp │ ├── ppc_simd.cpp │ ├── ppc_simd.h │ ├── pssr.cpp │ ├── pssr.h │ ├── pubkey.cpp │ ├── pubkey.h │ ├── pwdbased.h │ ├── queue.cpp │ ├── queue.h │ ├── rabbit.cpp │ ├── rabbit.h │ ├── rabin.cpp │ ├── rabin.h │ ├── randpool.cpp │ ├── randpool.h │ ├── rc2.cpp │ ├── rc2.h │ ├── rc5.cpp │ ├── rc5.h │ ├── rc6.cpp │ ├── rc6.h │ ├── rdrand.asm │ ├── rdrand.cpp │ ├── rdrand.h │ ├── rdseed.asm │ ├── rdtables.cpp │ ├── regtest1.cpp │ ├── regtest2.cpp │ ├── regtest3.cpp │ ├── regtest4.cpp │ ├── resource.h │ ├── rijndael.cpp │ ├── rijndael.h │ ├── rijndael_simd.cpp │ ├── ripemd.cpp │ ├── ripemd.h │ ├── rng.cpp │ ├── rng.h │ ├── rsa.cpp │ ├── rsa.h │ ├── rw.cpp │ ├── rw.h │ ├── safer.cpp │ ├── safer.h │ ├── salsa.cpp │ ├── salsa.h │ ├── scrypt.cpp │ ├── scrypt.h │ ├── seal.cpp │ ├── seal.h │ ├── secblock.h │ ├── secblockfwd.h │ ├── seckey.h │ ├── seed.cpp │ ├── seed.h │ ├── serpent.cpp │ ├── serpent.h │ ├── serpentp.h │ ├── sha.cpp │ ├── sha.h │ ├── sha1_armv4.S │ ├── sha1_armv4.h │ ├── sha256_armv4.S │ ├── sha256_armv4.h │ ├── sha3.cpp │ ├── sha3.h │ ├── sha512_armv4.S │ ├── sha512_armv4.h │ ├── sha_simd.cpp │ ├── shacal2.cpp │ ├── shacal2.h │ ├── shacal2_simd.cpp │ ├── shake.cpp │ ├── shake.h │ ├── shark.cpp │ ├── shark.h │ ├── sharkbox.cpp │ ├── simeck.cpp │ ├── simeck.h │ ├── simon.cpp │ ├── simon.h │ ├── simon128_simd.cpp │ ├── simple.cpp │ ├── simple.h │ ├── siphash.h │ ├── skipjack.cpp │ ├── skipjack.h │ ├── sm3.cpp │ ├── sm3.h │ ├── sm4.cpp │ ├── sm4.h │ ├── sm4_simd.cpp │ ├── smartptr.h │ ├── sosemanuk.cpp │ ├── sosemanuk.h │ ├── speck.cpp │ ├── speck.h │ ├── speck128_simd.cpp │ ├── square.cpp │ ├── square.h │ ├── squaretb.cpp │ ├── sse_simd.cpp │ ├── stdcpp.h │ ├── strciphr.cpp │ ├── strciphr.h │ ├── tea.cpp │ ├── tea.h │ ├── test.cpp │ ├── tftables.cpp │ ├── threefish.cpp │ ├── threefish.h │ ├── tiger.cpp │ ├── tiger.h │ ├── tigertab.cpp │ ├── trap.h │ ├── trunhash.h │ ├── ttmac.cpp │ ├── ttmac.h │ ├── tweetnacl.cpp │ ├── tweetnacl.h │ ├── twofish.cpp │ ├── twofish.h │ ├── validat0.cpp │ ├── validat1.cpp │ ├── validat10.cpp │ ├── validat2.cpp │ ├── validat3.cpp │ ├── validat4.cpp │ ├── validat5.cpp │ ├── validat6.cpp │ ├── validat7.cpp │ ├── validat8.cpp │ ├── validat9.cpp │ ├── validate.h │ ├── vmac.cpp │ ├── vmac.h │ ├── wake.cpp │ ├── wake.h │ ├── whrlpool.cpp │ ├── whrlpool.h │ ├── words.h │ ├── x64dll.asm │ ├── x64masm.asm │ ├── xed25519.cpp │ ├── xed25519.h │ ├── xtr.cpp │ ├── xtr.h │ ├── xtrcrypt.cpp │ ├── xtrcrypt.h │ ├── xts.cpp │ ├── xts.h │ ├── zdeflate.cpp │ ├── zdeflate.h │ ├── zinflate.cpp │ ├── zinflate.h │ ├── zlib.cpp │ └── zlib.h └── settings.png └── setup.py /README.md: -------------------------------------------------------------------------------- 1 | # CHROME CDMAPI SRC 2 | 3 | # NOTE: 4 | # CHROME CDM 2209 IS ALREADY REVOKED since 2021-12-06. THIS IS NO LONGER WORKING 5 | 6 | - Ready to build 7 | - Compatible from python 3.6 to 3.10 (Can be set the minimum version in bat file, --py-limited-api=cp36) 8 | - cryptopp850 src included for building **cryptlib.lib** 9 | - Build cdmapi.pyd and wheel (see _build.bat) 10 | --- 11 | 12 | ## References 13 | - https://github.com/T3rry7f/NoDRM/tree/master/PywidevineX/cdmapi-python-extension-src 14 | - https://github.com/T3rry7f/NoDRM/issues/20#issuecomment-905451827 15 | - http://python3porting.com/cextensions.html 16 | - https://gist.github.com/physacco/2e1b52415f3a964ad2a542a99bebed8f 17 | 18 | - For building cryptlib.lib: 19 | - https://cryptopp.com/cryptopp850.zip 20 | - https://github.com/xhlove/WVClient3/tree/main/cdmapi-python-extension-src 21 | -------------------------------------------------------------------------------- /_build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM build pyd 3 | py setup.py build_ext --inplace 4 | echo. 5 | REM build wheel 6 | py setup.py bdist_wheel --py-limited-api=cp36 7 | pause -------------------------------------------------------------------------------- /cdmapi_src/bind.cpp: -------------------------------------------------------------------------------- 1 | #include "codelift.h" 2 | 3 | char encryptfunc_docs[] = "RSA decrypt/encrypt with private key"; 4 | char decryptfunc_docs[] = "RSA-OEAP decrypt with private key"; 5 | 6 | 7 | PyMethodDef cdmapi_funcs[] = { 8 | { 9 | "decrypt", 10 | (PyCFunction)_decrypt, 11 | METH_VARARGS, 12 | decryptfunc_docs 13 | },{ 14 | "encrypt", 15 | (PyCFunction)_encrypt, 16 | METH_VARARGS, 17 | decryptfunc_docs}, 18 | { NULL} 19 | }; 20 | 21 | char cdmapimod_docs[] = "CMD API module for chrome 2209."; 22 | char cdmapimod_name[] = "cdmapi"; 23 | 24 | #if PY_MAJOR_VERSION >= 3 25 | 26 | PyModuleDef cdmapi_mod = { 27 | PyModuleDef_HEAD_INIT, 28 | cdmapimod_name, 29 | cdmapimod_docs, 30 | -1, 31 | cdmapi_funcs, 32 | NULL, 33 | NULL, 34 | NULL, 35 | NULL 36 | }; 37 | 38 | extern "C" { 39 | PyMODINIT_FUNC PyInit_cdmapi(void) 40 | { 41 | return PyModule_Create(&cdmapi_mod); 42 | } 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /cdmapi_src/codelift.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __LIBMYPY_H__ 3 | #define __LIBMYPY_H__ 4 | 5 | #include 6 | extern "C" { 7 | PyObject * _decrypt(PyObject *, PyObject *); 8 | PyObject * _encrypt(PyObject *, PyObject *); 9 | } 10 | #endif -------------------------------------------------------------------------------- /cdmapi_src/cryptlib.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zackmark29/Chrome2209-CDM-API/e3a306cb42bd3999eb1f68c6548a67eb54dda8a8/cdmapi_src/cryptlib.lib -------------------------------------------------------------------------------- /cdmapi_src/wasm/config.h: -------------------------------------------------------------------------------- 1 | // config.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file config.h 4 | /// \brief Library configuration file 5 | /// \details config.h was split into components in May 2019 to better 6 | /// integrate with Autoconf and its feature tests. The splitting occurred so 7 | /// users could continue to include config.h while allowing Autoconf 8 | /// to write new config_asm.h and new config_cxx.h using 9 | /// its feature tests. 10 | /// \sa Issue 835, 11 | /// Make config.h more autoconf friendly, 12 | /// Configure.sh script 13 | /// on the Crypto++ wiki 14 | /// \since Crypto++ 8.3 15 | 16 | /// \file config.h 17 | /// \brief Library configuration file 18 | 19 | #ifndef CRYPTOPP_CONFIG_H 20 | #define CRYPTOPP_CONFIG_H 21 | 22 | #include "config_align.h" 23 | #include "config_asm.h" 24 | #include "config_cpu.h" 25 | #include "config_cxx.h" 26 | #include "config_dll.h" 27 | #include "config_int.h" 28 | #include "config_misc.h" 29 | #include "config_ns.h" 30 | #include "config_os.h" 31 | #include "config_ver.h" 32 | 33 | #endif // CRYPTOPP_CONFIG_H 34 | -------------------------------------------------------------------------------- /cdmapi_src/wasm/config_ns.h: -------------------------------------------------------------------------------- 1 | // config_ns.h - written and placed in public domain by Jeffrey Walton 2 | // the bits that make up this source file are from the 3 | // library's monolithic config.h. 4 | 5 | /// \file config_ns.h 6 | /// \brief Library configuration file 7 | /// \details config_ns.h provides defines for C++ and library 8 | /// namespaces. 9 | /// \details config.h was split into components in May 2019 to better 10 | /// integrate with Autoconf and its feature tests. The splitting occurred so 11 | /// users could continue to include config.h while allowing Autoconf 12 | /// to write new config_asm.h and new config_cxx.h using 13 | /// its feature tests. 14 | /// \note You should include config.h rather than config_ns.h 15 | /// directly. 16 | /// \sa Issue 835, 17 | /// Make config.h more autoconf friendly, 18 | /// Configure.sh script 19 | /// on the Crypto++ wiki 20 | /// \since Crypto++ 8.3 21 | 22 | #ifndef CRYPTOPP_CONFIG_NAMESPACE_H 23 | #define CRYPTOPP_CONFIG_NAMESPACE_H 24 | 25 | // namespace support is now required 26 | #ifdef NO_NAMESPACE 27 | # error namespace support is now required 28 | #endif 29 | 30 | #ifdef CRYPTOPP_DOXYGEN_PROCESSING 31 | 32 | /// \namespace CryptoPP 33 | /// \brief Crypto++ library namespace 34 | /// \details Nearly all classes are located in the CryptoPP namespace. Within 35 | /// the namespace, there are four additional namespaces. 36 | /// 47 | /// \since Crypto++ 3.0 48 | namespace CryptoPP { } 49 | 50 | // Bring in the symbols found in the weak namespace; and fold Weak1 into Weak 51 | #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 52 | #define Weak1 Weak 53 | // Avoid putting "CryptoPP::" in front of everything in Doxygen output 54 | #define CryptoPP 55 | #define NAMESPACE_BEGIN(x) 56 | #define NAMESPACE_END 57 | // Get Doxygen to generate better documentation for these typedefs 58 | #define DOCUMENTED_TYPEDEF(x, y) class y : public x {} 59 | // Make "protected" "private" so the functions and members are not documented 60 | #define protected private 61 | 62 | #else 63 | // Not Doxygen 64 | #define NAMESPACE_BEGIN(x) namespace x { 65 | #define NAMESPACE_END } 66 | #define DOCUMENTED_TYPEDEF(x, y) typedef x y 67 | 68 | #endif // CRYPTOPP_DOXYGEN_PROCESSING 69 | 70 | #define ANONYMOUS_NAMESPACE_BEGIN namespace { 71 | #define ANONYMOUS_NAMESPACE_END } 72 | #define USING_NAMESPACE(x) using namespace x; 73 | #define DOCUMENTED_NAMESPACE_BEGIN(x) namespace x { 74 | #define DOCUMENTED_NAMESPACE_END } 75 | 76 | #endif // CRYPTOPP_CONFIG_NAMESPACE_H 77 | -------------------------------------------------------------------------------- /cdmapi_src/wasm/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file pch.h 4 | /// \brief Precompiled header file 5 | /// \details The precompiled header files are used Windows. 6 | 7 | #ifndef CRYPTOPP_PCH_H 8 | #define CRYPTOPP_PCH_H 9 | 10 | # ifdef CRYPTOPP_GENERATE_X64_MASM 11 | #include "cpu.h" 12 | 13 | # else 14 | #include "config.h" 15 | 16 | #ifdef USE_PRECOMPILED_HEADERS 17 | #include "simple.h" 18 | #include "secblock.h" 19 | #include "misc.h" 20 | #include "smartptr.h" 21 | #include "stdcpp.h" 22 | #endif 23 | # endif 24 | 25 | // Enable file and line numbers, if available. 26 | // #if defined(_MSC_VER) && defined(_DEBUG) && defined(USE_PRECOMPILED_HEADERS) 27 | // # define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 28 | // # define new DEBUG_NEW 29 | // #endif 30 | 31 | #endif // CRYPTOPP_PCH_H 32 | -------------------------------------------------------------------------------- /cdmapi_src/wasm/secblockfwd.h: -------------------------------------------------------------------------------- 1 | // secblockfwd.h - written and placed in the public domain by Jeffrey Walton 2 | 3 | /// \file secblockfwd.h 4 | /// \brief Forward declarations for SecBlock 5 | /// \details secblock.h and misc.h have a circular dependency. secblockfwd.h 6 | /// allows the library to sidestep the circular dependency, and reference 7 | /// SecBlock classes without the full implementation. 8 | /// \since Crypto++ 8.3 9 | 10 | #ifndef CRYPTOPP_SECBLOCKFWD_H 11 | #define CRYPTOPP_SECBLOCKFWD_H 12 | 13 | #include "config.h" 14 | 15 | NAMESPACE_BEGIN(CryptoPP) 16 | 17 | template 18 | class SecBlock; 19 | 20 | template 21 | class AllocatorWithCleanup; 22 | 23 | typedef SecBlock > SecByteBlock; 24 | typedef SecBlock > SecWordBlock; 25 | typedef SecBlock > AlignedSecByteBlock; 26 | 27 | NAMESPACE_END 28 | 29 | #endif // CRYPTOPP_SECBLOCKFWD_H 30 | -------------------------------------------------------------------------------- /cdmapi_src/wasm/stdcpp.h: -------------------------------------------------------------------------------- 1 | // stdcpp.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file stdcpp.h 4 | /// \brief Common C++ header files 5 | 6 | #ifndef CRYPTOPP_STDCPP_H 7 | #define CRYPTOPP_STDCPP_H 8 | 9 | #if _MSC_VER >= 1500 10 | #define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY 11 | #include 12 | #endif 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | // http://connect.microsoft.com/VisualStudio/feedback/details/1600701/type-info-does-not-compile-with-has-exceptions-0 29 | #if defined(_MSC_VER) && (_MSC_VER < 1900) && defined(_HAS_EXCEPTIONS) && (_HAS_EXCEPTIONS == 0) 30 | namespace std { 31 | using ::type_info; 32 | } 33 | #endif 34 | 35 | // workaround needed for IBM XLC and debug heaps on AIX 36 | #if defined(_AIX) && (defined(__xlc__) || defined(__xlC__) || defined(__ibmxl__)) 37 | # if defined(__DEBUG_ALLOC__) 38 | namespace std { 39 | using ::_debug_memset; 40 | using ::_debug_memcpy; 41 | } 42 | # endif 43 | #endif 44 | 45 | // make_unchecked_array_iterator 46 | #if _MSC_VER >= 1600 47 | #include 48 | #endif 49 | 50 | #if defined(CRYPTOPP_CXX11_ATOMIC) 51 | #include 52 | #endif 53 | 54 | #if defined(CRYPTOPP_CXX11_SYNCHRONIZATION) 55 | #include 56 | #endif 57 | 58 | #if defined(CRYPTOPP_CXX11_RVALUES) 59 | # include 60 | #endif 61 | 62 | #include 63 | #include 64 | #include 65 | #include 66 | 67 | // It is 2019 and VS2017/Win10 still can't compile a 68 | // program that includes without making users 69 | // do something special. "Epic fail" comes to mind. 70 | // Also see https://github.com/weidai11/cryptopp/issues/781 71 | #ifndef _MSC_VER 72 | # include 73 | #endif 74 | 75 | // uintptr_t and ptrdiff_t 76 | #if defined(__SUNPRO_CC) 77 | # if (__SUNPRO_CC >= 0x5100) 78 | # include 79 | # endif 80 | #elif defined(_MSC_VER) 81 | # if (_MSC_VER >= 1700) 82 | # include 83 | # else 84 | # include 85 | # endif 86 | #elif (__cplusplus < 201103L) 87 | # include 88 | #endif 89 | 90 | // workaround needed on Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21 91 | #ifdef CRYPTOPP_INCLUDE_VECTOR_CC 92 | # include 93 | #endif 94 | 95 | // C++Builder's standard library (Dinkumware) do not have C's global log() function 96 | // https://github.com/weidai11/cryptopp/issues/520 97 | #ifdef __BORLANDC__ 98 | using std::log; 99 | #endif 100 | 101 | #endif // CRYPTOPP_STDCPP_H 102 | -------------------------------------------------------------------------------- /cryptlib_src/cryptlib.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31702.278 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cryptlib", "cryptopp850\cryptlib.vcxproj", "{C39F4B46-6E89-4074-902E-CA57073044D2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | DLL-Import Debug|x64 = DLL-Import Debug|x64 13 | DLL-Import Debug|x86 = DLL-Import Debug|x86 14 | DLL-Import Release|x64 = DLL-Import Release|x64 15 | DLL-Import Release|x86 = DLL-Import Release|x86 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {C39F4B46-6E89-4074-902E-CA57073044D2}.Debug|x64.ActiveCfg = Debug|x64 21 | {C39F4B46-6E89-4074-902E-CA57073044D2}.Debug|x64.Build.0 = Debug|x64 22 | {C39F4B46-6E89-4074-902E-CA57073044D2}.Debug|x86.ActiveCfg = Debug|Win32 23 | {C39F4B46-6E89-4074-902E-CA57073044D2}.Debug|x86.Build.0 = Debug|Win32 24 | {C39F4B46-6E89-4074-902E-CA57073044D2}.DLL-Import Debug|x64.ActiveCfg = DLL-Import Debug|x64 25 | {C39F4B46-6E89-4074-902E-CA57073044D2}.DLL-Import Debug|x64.Build.0 = DLL-Import Debug|x64 26 | {C39F4B46-6E89-4074-902E-CA57073044D2}.DLL-Import Debug|x86.ActiveCfg = DLL-Import Debug|Win32 27 | {C39F4B46-6E89-4074-902E-CA57073044D2}.DLL-Import Debug|x86.Build.0 = DLL-Import Debug|Win32 28 | {C39F4B46-6E89-4074-902E-CA57073044D2}.DLL-Import Release|x64.ActiveCfg = DLL-Import Release|x64 29 | {C39F4B46-6E89-4074-902E-CA57073044D2}.DLL-Import Release|x64.Build.0 = DLL-Import Release|x64 30 | {C39F4B46-6E89-4074-902E-CA57073044D2}.DLL-Import Release|x86.ActiveCfg = DLL-Import Release|Win32 31 | {C39F4B46-6E89-4074-902E-CA57073044D2}.DLL-Import Release|x86.Build.0 = DLL-Import Release|Win32 32 | {C39F4B46-6E89-4074-902E-CA57073044D2}.Release|x64.ActiveCfg = Release|x64 33 | {C39F4B46-6E89-4074-902E-CA57073044D2}.Release|x64.Build.0 = Release|x64 34 | {C39F4B46-6E89-4074-902E-CA57073044D2}.Release|x86.ActiveCfg = Release|Win32 35 | {C39F4B46-6E89-4074-902E-CA57073044D2}.Release|x86.Build.0 = Release|Win32 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {AC2DFFE7-1A97-4A56-B06C-D090CED6F0FB} 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/3way.h: -------------------------------------------------------------------------------- 1 | // 3way.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file 3way.h 4 | /// \brief Classes for the 3-Way block cipher 5 | 6 | #ifndef CRYPTOPP_THREEWAY_H 7 | #define CRYPTOPP_THREEWAY_H 8 | 9 | #include "config.h" 10 | #include "seckey.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief ThreeWay block cipher information 16 | struct ThreeWay_Info : public FixedBlockSize<12>, public FixedKeyLength<12>, public VariableRounds<11> 17 | { 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "3-Way";} 19 | }; 20 | 21 | /// \brief ThreeWay block cipher 22 | /// \sa 3-Way 23 | class ThreeWay : public ThreeWay_Info, public BlockCipherDocumentation 24 | { 25 | /// \brief Class specific implementation and overrides used to operate the cipher. 26 | /// \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions 27 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 28 | { 29 | public: 30 | void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); 31 | 32 | protected: 33 | unsigned int m_rounds; 34 | FixedSizeSecBlock m_k; 35 | }; 36 | 37 | /// \brief Class specific methods used to operate the cipher in the forward direction. 38 | /// \details Implementations and overrides in \p Enc apply to \p ENCRYPTION. 39 | class CRYPTOPP_NO_VTABLE Enc : public Base 40 | { 41 | public: 42 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 43 | }; 44 | 45 | /// \brief Class specific methods used to operate the cipher in the reverse direction. 46 | /// \details Implementations and overrides in \p Dec apply to \p DECRYPTION. 47 | class CRYPTOPP_NO_VTABLE Dec : public Base 48 | { 49 | public: 50 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 51 | }; 52 | 53 | public: 54 | typedef BlockCipherFinal Encryption; 55 | typedef BlockCipherFinal Decryption; 56 | }; 57 | 58 | typedef ThreeWay::Encryption ThreeWayEncryption; 59 | typedef ThreeWay::Decryption ThreeWayDecryption; 60 | 61 | NAMESPACE_END 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/adhoc.cpp: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | #if CRYPTOPP_MSC_VERSION 6 | # pragma warning(disable: 4100 4189 4996) 7 | #endif 8 | 9 | #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 10 | # pragma GCC diagnostic ignored "-Wunused-variable" 11 | #endif 12 | 13 | USING_NAMESPACE(CryptoPP) 14 | USING_NAMESPACE(std) 15 | 16 | #ifndef CRYPTOPP_UNUSED 17 | # define CRYPTOPP_UNUSED(x) (void(x)) 18 | #endif 19 | 20 | // Used for testing the compiler and linker in cryptest.sh 21 | #if defined(CRYPTOPP_ADHOC_MAIN) || defined(ADHOC_MAIN) 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | CRYPTOPP_UNUSED(argc), CRYPTOPP_UNUSED(argv); 26 | return 0; 27 | } 28 | 29 | // Classic use of adhoc to setup calling convention 30 | #else 31 | 32 | extern int (*AdhocTest)(int argc, char *argv[]); 33 | 34 | int MyAdhocTest(int argc, char *argv[]) 35 | { 36 | CRYPTOPP_UNUSED(argc), CRYPTOPP_UNUSED(argv); 37 | return 0; 38 | } 39 | 40 | static int s_i = (AdhocTest = &MyAdhocTest, 0); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/adhoc.cpp.copied: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/adhoc.cpp.proto: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | #if CRYPTOPP_MSC_VERSION 6 | # pragma warning(disable: 4100 4189 4996) 7 | #endif 8 | 9 | #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 10 | # pragma GCC diagnostic ignored "-Wunused-variable" 11 | #endif 12 | 13 | USING_NAMESPACE(CryptoPP) 14 | USING_NAMESPACE(std) 15 | 16 | #ifndef CRYPTOPP_UNUSED 17 | # define CRYPTOPP_UNUSED(x) (void(x)) 18 | #endif 19 | 20 | // Used for testing the compiler and linker in cryptest.sh 21 | #if defined(CRYPTOPP_ADHOC_MAIN) || defined(ADHOC_MAIN) 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | CRYPTOPP_UNUSED(argc), CRYPTOPP_UNUSED(argv); 26 | return 0; 27 | } 28 | 29 | // Classic use of adhoc to setup calling convention 30 | #else 31 | 32 | extern int (*AdhocTest)(int argc, char *argv[]); 33 | 34 | int MyAdhocTest(int argc, char *argv[]) 35 | { 36 | CRYPTOPP_UNUSED(argc), CRYPTOPP_UNUSED(argv); 37 | return 0; 38 | } 39 | 40 | static int s_i = (AdhocTest = &MyAdhocTest, 0); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/adler32.cpp: -------------------------------------------------------------------------------- 1 | // adler32.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | #include "adler32.h" 5 | 6 | NAMESPACE_BEGIN(CryptoPP) 7 | 8 | void Adler32::Update(const byte *input, size_t length) 9 | { 10 | const unsigned long BASE = 65521; 11 | 12 | unsigned long s1 = m_s1; 13 | unsigned long s2 = m_s2; 14 | 15 | if (length % 8 != 0) 16 | { 17 | do 18 | { 19 | s1 += *input++; 20 | s2 += s1; 21 | length--; 22 | } while (length % 8 != 0); 23 | 24 | if (s1 >= BASE) 25 | s1 -= BASE; 26 | s2 %= BASE; 27 | } 28 | 29 | while (length > 0) 30 | { 31 | s1 += input[0]; s2 += s1; 32 | s1 += input[1]; s2 += s1; 33 | s1 += input[2]; s2 += s1; 34 | s1 += input[3]; s2 += s1; 35 | s1 += input[4]; s2 += s1; 36 | s1 += input[5]; s2 += s1; 37 | s1 += input[6]; s2 += s1; 38 | s1 += input[7]; s2 += s1; 39 | 40 | length -= 8; 41 | input += 8; 42 | 43 | if (s1 >= BASE) 44 | s1 -= BASE; 45 | if (length % 0x8000 == 0) 46 | s2 %= BASE; 47 | } 48 | 49 | CRYPTOPP_ASSERT(s1 < BASE); 50 | CRYPTOPP_ASSERT(s2 < BASE); 51 | 52 | m_s1 = (word16)s1; 53 | m_s2 = (word16)s2; 54 | } 55 | 56 | void Adler32::TruncatedFinal(byte *hash, size_t size) 57 | { 58 | ThrowIfInvalidTruncatedSize(size); 59 | 60 | switch (size) 61 | { 62 | default: 63 | hash[3] = byte(m_s1); 64 | // fall through 65 | case 3: 66 | hash[2] = byte(m_s1 >> 8); 67 | // fall through 68 | case 2: 69 | hash[1] = byte(m_s2); 70 | // fall through 71 | case 1: 72 | hash[0] = byte(m_s2 >> 8); 73 | // fall through 74 | case 0: 75 | ; 76 | // fall through 77 | } 78 | 79 | Reset(); 80 | } 81 | 82 | NAMESPACE_END 83 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/adler32.h: -------------------------------------------------------------------------------- 1 | // adler32.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file adler32.h 4 | /// \brief Class file for ADLER-32 checksum calculations 5 | 6 | #ifndef CRYPTOPP_ADLER32_H 7 | #define CRYPTOPP_ADLER32_H 8 | 9 | #include "cryptlib.h" 10 | 11 | NAMESPACE_BEGIN(CryptoPP) 12 | 13 | /// ADLER-32 checksum calculations 14 | class Adler32 : public HashTransformation 15 | { 16 | public: 17 | CRYPTOPP_CONSTANT(DIGESTSIZE = 4); 18 | Adler32() {Reset();} 19 | void Update(const byte *input, size_t length); 20 | void TruncatedFinal(byte *hash, size_t size); 21 | unsigned int DigestSize() const {return DIGESTSIZE;} 22 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Adler32";} 23 | std::string AlgorithmName() const {return StaticAlgorithmName();} 24 | 25 | private: 26 | void Reset() {m_s1 = 1; m_s2 = 0;} 27 | 28 | word16 m_s1, m_s2; 29 | }; 30 | 31 | NAMESPACE_END 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/aes.h: -------------------------------------------------------------------------------- 1 | // aes.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file 4 | /// \brief Class file for the AES cipher (Rijndael) 5 | /// \details AES is a typdef for Rijndael classes. All key sizes are supported. 6 | /// The library only provides Rijndael with 128-bit blocks, and not 192-bit or 256-bit blocks 7 | /// \since Rijndael since Crypto++ 3.1, Intel AES-NI since Crypto++ 5.6.1, ARMv8 AES since Crypto++ 6.0, 8 | /// Power8 AES since Crypto++ 6.0 9 | 10 | #ifndef CRYPTOPP_AES_H 11 | #define CRYPTOPP_AES_H 12 | 13 | #include "rijndael.h" 14 | 15 | NAMESPACE_BEGIN(CryptoPP) 16 | 17 | /// \brief AES block cipher (Rijndael) 18 | /// \details AES is a typdef for Rijndael classes. All key sizes are supported. 19 | /// The library only provides Rijndael with 128-bit blocks, and not 192-bit or 256-bit blocks 20 | /// \sa AES winner, announced on 10/2/2000 21 | /// \since Rijndael since Crypto++ 3.1, Intel AES-NI since Crypto++ 5.6.1, ARMv8 AES since Crypto++ 6.0, 22 | /// Power8 AES since Crypto++ 6.0 23 | DOCUMENTED_TYPEDEF(Rijndael, AES); 24 | 25 | typedef RijndaelEncryption AESEncryption; 26 | typedef RijndaelDecryption AESDecryption; 27 | 28 | NAMESPACE_END 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/aes_armv4.h: -------------------------------------------------------------------------------- 1 | /* Header file for use with Cryptogam's ARMv4 AES. */ 2 | /* Also see http://www.openssl.org/~appro/cryptogams/ and */ 3 | /* https://wiki.openssl.org/index.php?title=Cryptogams_AES */ 4 | 5 | #ifndef CRYPTOGAMS_AES_ARMV4_H 6 | #define CRYPTOGAMS_AES_ARMV4_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | //#define AES_MAXNR 14 13 | //typedef struct AES_KEY_st { 14 | // unsigned int rd_key[4 * (AES_MAXNR + 1)]; 15 | // int rounds; 16 | //} AES_KEY; 17 | 18 | // Instead of AES_KEY we use a 'word32 rkey[4*15+4]'. It has space for 19 | // both the AES_MAXNR round keys and the number of rounds in the tail. 20 | 21 | int cryptogams_AES_set_encrypt_key(const unsigned char *userKey, const int bits, unsigned int *rkey); 22 | int cryptogams_AES_set_decrypt_key(const unsigned char *userKey, const int bits, unsigned int *rkey); 23 | void cryptogams_AES_encrypt_block(const unsigned char *in, unsigned char *out, const unsigned int *rkey); 24 | void cryptogams_AES_decrypt_block(const unsigned char *in, unsigned char *out, const unsigned int *rkey); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* CRYPTOGAMS_AES_ARMV4_H */ 31 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/algparam.cpp: -------------------------------------------------------------------------------- 1 | // algparam.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | 5 | #ifndef CRYPTOPP_IMPORTS 6 | 7 | #include "algparam.h" 8 | #include "integer.h" 9 | 10 | NAMESPACE_BEGIN(CryptoPP) 11 | 12 | bool CombinedNameValuePairs::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const 13 | { 14 | if (strcmp(name, "ValueNames") == 0) 15 | return m_pairs1.GetVoidValue(name, valueType, pValue) && m_pairs2.GetVoidValue(name, valueType, pValue); 16 | else 17 | return m_pairs1.GetVoidValue(name, valueType, pValue) || m_pairs2.GetVoidValue(name, valueType, pValue); 18 | } 19 | 20 | void AlgorithmParametersBase::operator=(const AlgorithmParametersBase &rhs) 21 | { 22 | CRYPTOPP_UNUSED(rhs); 23 | CRYPTOPP_ASSERT(false); 24 | } 25 | 26 | bool AlgorithmParametersBase::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const 27 | { 28 | if (strcmp(name, "ValueNames") == 0) 29 | { 30 | NameValuePairs::ThrowIfTypeMismatch(name, typeid(std::string), valueType); 31 | if (m_next.get()) 32 | m_next->GetVoidValue(name, valueType, pValue); 33 | (*reinterpret_cast(pValue) += m_name) += ";"; 34 | return true; 35 | } 36 | else if (strcmp(name, m_name) == 0) 37 | { 38 | AssignValue(name, valueType, pValue); 39 | m_used = true; 40 | return true; 41 | } 42 | else if (m_next.get()) 43 | return m_next->GetVoidValue(name, valueType, pValue); 44 | else 45 | return false; 46 | } 47 | 48 | AlgorithmParameters::AlgorithmParameters() 49 | : m_defaultThrowIfNotUsed(true) 50 | { 51 | } 52 | 53 | AlgorithmParameters::AlgorithmParameters(const AlgorithmParameters &x) 54 | : m_defaultThrowIfNotUsed(x.m_defaultThrowIfNotUsed) 55 | { 56 | m_next.reset(const_cast(x).m_next.release()); 57 | } 58 | 59 | AlgorithmParameters & AlgorithmParameters::operator=(const AlgorithmParameters &x) 60 | { 61 | m_next.reset(const_cast(x).m_next.release()); 62 | return *this; 63 | } 64 | 65 | bool AlgorithmParameters::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const 66 | { 67 | if (m_next.get()) 68 | return m_next->GetVoidValue(name, valueType, pValue); 69 | else 70 | return false; 71 | } 72 | 73 | NAMESPACE_END 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/allocate.cpp: -------------------------------------------------------------------------------- 1 | // allocate.cpp - written and placed in the public domain by Jeffrey Walton 2 | 3 | // The functions in allocate.h and allocate.cpp were originally in misc.h 4 | // and misc.cpp. They were extracted in September 2019 to sidestep a circular 5 | // dependency with misc.h and secblock.h. 6 | 7 | #include "pch.h" 8 | #include "config.h" 9 | 10 | #ifndef CRYPTOPP_IMPORTS 11 | 12 | #include "allocate.h" 13 | #include "stdcpp.h" 14 | #include "misc.h" 15 | #include "trap.h" 16 | 17 | // for memalign 18 | #if defined(CRYPTOPP_MEMALIGN_AVAILABLE) || defined(CRYPTOPP_MM_MALLOC_AVAILABLE) || defined(QNX) 19 | # include 20 | #endif 21 | // for posix_memalign 22 | #if defined(CRYPTOPP_POSIX_MEMALIGN_AVAILABLE) 23 | # include 24 | #endif 25 | 26 | NAMESPACE_BEGIN(CryptoPP) 27 | 28 | void CallNewHandler() 29 | { 30 | using std::new_handler; 31 | using std::set_new_handler; 32 | 33 | new_handler newHandler = set_new_handler(NULLPTR); 34 | if (newHandler) 35 | set_new_handler(newHandler); 36 | 37 | if (newHandler) 38 | newHandler(); 39 | else 40 | throw std::bad_alloc(); 41 | } 42 | 43 | void * AlignedAllocate(size_t size) 44 | { 45 | byte *p; 46 | #if defined(CRYPTOPP_MM_MALLOC_AVAILABLE) 47 | while ((p = (byte *)_mm_malloc(size, 16)) == NULLPTR) 48 | #elif defined(CRYPTOPP_MEMALIGN_AVAILABLE) 49 | while ((p = (byte *)memalign(16, size)) == NULLPTR) 50 | #elif defined(CRYPTOPP_MALLOC_ALIGNMENT_IS_16) 51 | while ((p = (byte *)malloc(size)) == NULLPTR) 52 | #elif defined(CRYPTOPP_POSIX_MEMALIGN_AVAILABLE) 53 | while (posix_memalign(reinterpret_cast(&p), 16, size) != 0) 54 | #else 55 | while ((p = (byte *)malloc(size + 16)) == NULLPTR) 56 | #endif 57 | CallNewHandler(); 58 | 59 | #ifdef CRYPTOPP_NO_ALIGNED_ALLOC 60 | size_t adjustment = 16-((size_t)p%16); 61 | CRYPTOPP_ASSERT(adjustment > 0); 62 | p += adjustment; 63 | p[-1] = (byte)adjustment; 64 | #endif 65 | 66 | // If this assert fires then there are problems that need 67 | // to be fixed. Please open a bug report. 68 | CRYPTOPP_ASSERT(IsAlignedOn(p, 16)); 69 | return p; 70 | } 71 | 72 | void AlignedDeallocate(void *p) 73 | { 74 | // Guard pointer due to crash on AIX when CRYPTOPP_NO_ALIGNED_ALLOC 75 | // is in effect. The guard was previously in place in SecBlock, 76 | // but it was removed at f4d68353ca7c as part of GH #875. 77 | CRYPTOPP_ASSERT(p); 78 | 79 | if (p != NULLPTR) 80 | { 81 | #ifdef CRYPTOPP_MM_MALLOC_AVAILABLE 82 | _mm_free(p); 83 | #elif defined(CRYPTOPP_NO_ALIGNED_ALLOC) 84 | p = (byte *)p - ((byte *)p)[-1]; 85 | free(p); 86 | #else 87 | free(p); 88 | #endif 89 | } 90 | } 91 | 92 | void * UnalignedAllocate(size_t size) 93 | { 94 | void *p; 95 | while ((p = malloc(size)) == NULLPTR) 96 | CallNewHandler(); 97 | return p; 98 | } 99 | 100 | void UnalignedDeallocate(void *p) 101 | { 102 | free(p); 103 | } 104 | 105 | NAMESPACE_END 106 | 107 | #endif // CRYPTOPP_IMPORTS 108 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/arc4.cpp: -------------------------------------------------------------------------------- 1 | // arc4.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | // The ARC4 algorithm was first revealed in an anonymous email to the 4 | // cypherpunks mailing list. This file originally contained some 5 | // code copied from this email. The code has since been rewritten in order 6 | // to clarify the copyright status of this file. It should now be 7 | // completely in the public domain. 8 | 9 | #include "pch.h" 10 | #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 11 | #include "arc4.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | namespace Weak1 { 15 | 16 | #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) 17 | void ARC4_TestInstantiations() 18 | { 19 | ARC4 x; 20 | } 21 | #endif 22 | 23 | ARC4_Base::~ARC4_Base() 24 | { 25 | m_x = m_y = 0; 26 | } 27 | 28 | void ARC4_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) 29 | { 30 | AssertValidKeyLength(length); 31 | 32 | m_x = 1; 33 | m_y = 0; 34 | 35 | unsigned int i; 36 | for (i=0; i<256; i++) 37 | m_state[i] = byte(i); 38 | 39 | unsigned int keyIndex = 0, stateIndex = 0; 40 | for (i=0; i<256; i++) 41 | { 42 | unsigned int a = m_state[i]; 43 | stateIndex += key[keyIndex] + a; 44 | stateIndex &= 0xff; 45 | m_state[i] = m_state[stateIndex]; 46 | m_state[stateIndex] = byte(a); 47 | if (++keyIndex >= length) 48 | keyIndex = 0; 49 | } 50 | 51 | int discardBytes = params.GetIntValueWithDefault("DiscardBytes", GetDefaultDiscardBytes()); 52 | DiscardBytes(discardBytes); 53 | } 54 | 55 | template 56 | static inline unsigned int MakeByte(T &x, T &y, byte *s) 57 | { 58 | unsigned int a = s[x]; 59 | y = byte((y+a) & 0xff); 60 | unsigned int b = s[y]; 61 | s[x] = byte(b); 62 | s[y] = byte(a); 63 | x = byte((x+1) & 0xff); 64 | return s[(a+b) & 0xff]; 65 | } 66 | 67 | void ARC4_Base::GenerateBlock(byte *output, size_t size) 68 | { 69 | while (size--) 70 | *output++ = static_cast(MakeByte(m_x, m_y, m_state)); 71 | } 72 | 73 | void ARC4_Base::ProcessData(byte *outString, const byte *inString, size_t length) 74 | { 75 | if (length == 0) 76 | return; 77 | 78 | byte *const s = m_state; 79 | unsigned int x = m_x; 80 | unsigned int y = m_y; 81 | 82 | if (inString == outString) 83 | { 84 | do 85 | { 86 | *outString++ ^= MakeByte(x, y, s); 87 | } while (--length); 88 | } 89 | else 90 | { 91 | do 92 | { 93 | *outString++ = *inString++ ^ byte(MakeByte(x, y, s)); 94 | } 95 | while(--length); 96 | } 97 | 98 | m_x = byte(x); 99 | m_y = byte(y); 100 | } 101 | 102 | void ARC4_Base::DiscardBytes(size_t n) 103 | { 104 | if (n == 0) 105 | return; 106 | 107 | byte *const s = m_state; 108 | unsigned int x = m_x; 109 | unsigned int y = m_y; 110 | 111 | do 112 | { 113 | MakeByte(x, y, s); 114 | } 115 | while(--n); 116 | 117 | m_x = byte(x); 118 | m_y = byte(y); 119 | } 120 | 121 | } 122 | NAMESPACE_END 123 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/aria.h: -------------------------------------------------------------------------------- 1 | // aria.h - written and placed in the public domain by Jeffrey Walton 2 | 3 | /// \file aria.h 4 | /// \brief Classes for the ARIA block cipher 5 | /// \details The Crypto++ ARIA implementation is based on the 32-bit implementation by Aaram Yun 6 | /// from the National Security Research Institute, KOREA. Aaram Yun's implementation is based on 7 | /// the 8-bit implementation by Jin Hong. The source files are available in ARIA.zip from the Korea 8 | /// Internet & Security Agency website. 9 | /// \sa RFC 5794, A Description of the ARIA Encryption Algorithm, 10 | /// Korea 11 | /// Internet & Security Agency homepage 12 | 13 | #ifndef CRYPTOPP_ARIA_H 14 | #define CRYPTOPP_ARIA_H 15 | 16 | #include "config.h" 17 | #include "seckey.h" 18 | #include "secblock.h" 19 | 20 | NAMESPACE_BEGIN(CryptoPP) 21 | 22 | /// \brief ARIA block cipher information 23 | /// \since Crypto++ 6.0 24 | struct ARIA_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8> 25 | { 26 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "ARIA";} 27 | }; 28 | 29 | /// \brief ARIA block cipher 30 | /// \details The Crypto++ ARIA implementation is based on the 32-bit implementation by Aaram Yun 31 | /// from the National Security Research Institute, KOREA. Aaram Yun's implementation is based on 32 | /// the 8-bit implementation by Jin Hong. The source files are available in ARIA.zip from the Korea 33 | /// Internet & Security Agency website. 34 | /// \sa RFC 5794, A Description of the ARIA Encryption Algorithm, 35 | /// Korea 36 | /// Internet & Security Agency homepage 37 | /// \sa ARIA 38 | /// \since Crypto++ 6.0 39 | class ARIA : public ARIA_Info, public BlockCipherDocumentation 40 | { 41 | public: 42 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 43 | { 44 | public: 45 | Base() : m_rounds(0) {} 46 | 47 | protected: 48 | void UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs ¶ms); 49 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 50 | 51 | private: 52 | // Reference implementation allocates a table of 17 round keys. 53 | typedef SecBlock > AlignedByteBlock; 54 | typedef SecBlock > AlignedWordBlock; 55 | 56 | AlignedByteBlock m_rk; // round keys 57 | AlignedWordBlock m_w; // w0, w1, w2, w3, t and u 58 | unsigned int m_rounds; 59 | }; 60 | 61 | public: 62 | typedef BlockCipherFinal Encryption; 63 | typedef BlockCipherFinal Decryption; 64 | }; 65 | 66 | typedef ARIA::Encryption ARIAEncryption; 67 | typedef ARIA::Decryption ARIADecryption; 68 | 69 | NAMESPACE_END 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/blowfish.cpp: -------------------------------------------------------------------------------- 1 | // blowfish.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | #include "blowfish.h" 5 | #include "misc.h" 6 | 7 | NAMESPACE_BEGIN(CryptoPP) 8 | 9 | void Blowfish::Base::UncheckedSetKey(const byte *key_string, unsigned int keylength, const NameValuePairs &) 10 | { 11 | AssertValidKeyLength(keylength); 12 | 13 | unsigned i, j=0, k; 14 | word32 data, dspace[2] = {0, 0}; 15 | 16 | memcpy(pbox, p_init, sizeof(p_init)); 17 | memcpy(sbox, s_init, sizeof(s_init)); 18 | 19 | // Xor key string into encryption key vector 20 | for (i=0 ; i Block; 74 | 75 | word32 left, right; 76 | Block::Get(inBlock)(left)(right); 77 | 78 | const word32 *const s=sbox; 79 | const word32 *p=pbox; 80 | 81 | left ^= p[0]; 82 | 83 | for (unsigned i=0; i, public VariableKeyLength<16, 4, 56>, public FixedRounds<16> 16 | { 17 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Blowfish";} 18 | }; 19 | 20 | // Blowfish 21 | 22 | /// \brief Blowfish block cipher 23 | /// \since Crypto++ 1.0 24 | class Blowfish : public Blowfish_Info, public BlockCipherDocumentation 25 | { 26 | /// \brief Class specific implementation and overrides used to operate the cipher. 27 | /// \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions 28 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 29 | { 30 | public: 31 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 32 | void UncheckedSetKey(const byte *key_string, unsigned int keylength, const NameValuePairs ¶ms); 33 | 34 | private: 35 | void crypt_block(const word32 in[2], word32 out[2]) const; 36 | 37 | static const word32 p_init[ROUNDS+2]; 38 | static const word32 s_init[4*256]; 39 | 40 | FixedSizeSecBlock pbox; 41 | FixedSizeSecBlock sbox; 42 | }; 43 | 44 | public: 45 | typedef BlockCipherFinal Encryption; 46 | typedef BlockCipherFinal Decryption; 47 | }; 48 | 49 | typedef Blowfish::Encryption BlowfishEncryption; 50 | typedef Blowfish::Decryption BlowfishDecryption; 51 | 52 | NAMESPACE_END 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/blumshub.cpp: -------------------------------------------------------------------------------- 1 | // blumshub.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | #include "blumshub.h" 5 | #include "integer.h" 6 | 7 | NAMESPACE_BEGIN(CryptoPP) 8 | 9 | PublicBlumBlumShub::PublicBlumBlumShub(const Integer &n, const Integer &seed) 10 | : modn(n), 11 | current(modn.Square(modn.Square(seed))), 12 | maxBits(BitPrecision(n.BitCount())-1), 13 | bitsLeft(maxBits) 14 | { 15 | } 16 | 17 | unsigned int PublicBlumBlumShub::GenerateBit() 18 | { 19 | if (bitsLeft==0) 20 | { 21 | current = modn.Square(current); 22 | bitsLeft = maxBits; 23 | } 24 | 25 | return static_cast(current.GetBit(--bitsLeft)); 26 | } 27 | 28 | byte PublicBlumBlumShub::GenerateByte() 29 | { 30 | byte b=0; 31 | for (int i=0; i<8; i++) 32 | b = byte((b << 1) | PublicBlumBlumShub::GenerateBit()); 33 | return b; 34 | } 35 | 36 | void PublicBlumBlumShub::GenerateBlock(byte *output, size_t size) 37 | { 38 | while (size--) 39 | *output++ = PublicBlumBlumShub::GenerateByte(); 40 | } 41 | 42 | void PublicBlumBlumShub::ProcessData(byte *outString, const byte *inString, size_t length) 43 | { 44 | while (length--) 45 | *outString++ = *inString++ ^ PublicBlumBlumShub::GenerateByte(); 46 | } 47 | 48 | BlumBlumShub::BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed) 49 | : PublicBlumBlumShub(p*q, seed), 50 | p(p), q(q), 51 | x0(modn.Square(seed)) 52 | { 53 | } 54 | 55 | void BlumBlumShub::Seek(lword index) 56 | { 57 | Integer i(Integer::POSITIVE, index); 58 | i *= 8; 59 | Integer e = a_exp_b_mod_c (2, i / maxBits + 1, (p-1)*(q-1)); 60 | current = modn.Exponentiate(x0, e); 61 | bitsLeft = maxBits - i % maxBits; 62 | } 63 | 64 | NAMESPACE_END 65 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/blumshub.h: -------------------------------------------------------------------------------- 1 | // blumshub.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file blumshub.h 4 | /// \brief Classes for Blum Blum Shub generator 5 | 6 | #ifndef CRYPTOPP_BLUMSHUB_H 7 | #define CRYPTOPP_BLUMSHUB_H 8 | 9 | #include "cryptlib.h" 10 | #include "modarith.h" 11 | #include "integer.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief BlumBlumShub without factorization of the modulus 16 | /// \details You should reseed the generator after a fork() to avoid multiple generators 17 | /// with the same internal state. 18 | class PublicBlumBlumShub : public RandomNumberGenerator, 19 | public StreamTransformation 20 | { 21 | public: 22 | virtual ~PublicBlumBlumShub() {} 23 | 24 | /// \brief Construct a PublicBlumBlumShub 25 | /// \param n the modulus 26 | /// \param seed the seed for the generator 27 | /// \details seed is the secret key and should be about as large as n. 28 | PublicBlumBlumShub(const Integer &n, const Integer &seed); 29 | 30 | unsigned int GenerateBit(); 31 | byte GenerateByte(); 32 | void GenerateBlock(byte *output, size_t size); 33 | void ProcessData(byte *outString, const byte *inString, size_t length); 34 | 35 | bool IsSelfInverting() const {return true;} 36 | bool IsForwardTransformation() const {return true;} 37 | 38 | protected: 39 | ModularArithmetic modn; 40 | Integer current; 41 | word maxBits, bitsLeft; 42 | }; 43 | 44 | /// \brief BlumBlumShub with factorization of the modulus 45 | /// \details You should reseed the generator after a fork() to avoid multiple generators 46 | /// with the same internal state. 47 | class BlumBlumShub : public PublicBlumBlumShub 48 | { 49 | public: 50 | virtual ~BlumBlumShub() {} 51 | 52 | /// \brief Construct a BlumBlumShub 53 | /// \param p the first prime factor 54 | /// \param q the second prime factor 55 | /// \param seed the seed for the generator 56 | /// \details Esure p and q are both primes congruent to 3 mod 4 and at least 512 bits long. 57 | /// seed is the secret key and should be about as large as p*q. 58 | BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed); 59 | 60 | bool IsRandomAccess() const {return true;} 61 | void Seek(lword index); 62 | 63 | protected: 64 | const Integer p, q; 65 | const Integer x0; 66 | }; 67 | 68 | NAMESPACE_END 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/camellia.h: -------------------------------------------------------------------------------- 1 | // camellia.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file camellia.h 4 | /// \brief Classes for the Camellia block cipher 5 | 6 | #ifndef CRYPTOPP_CAMELLIA_H 7 | #define CRYPTOPP_CAMELLIA_H 8 | 9 | #include "config.h" 10 | #include "seckey.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief Camellia block cipher information 16 | struct Camellia_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8> 17 | { 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Camellia";} 19 | }; 20 | 21 | /// \brief Camellia block cipher 22 | /// \sa Camellia 23 | class Camellia : public Camellia_Info, public BlockCipherDocumentation 24 | { 25 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 26 | { 27 | public: 28 | void UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs ¶ms); 29 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 30 | 31 | protected: 32 | CRYPTOPP_ALIGN_DATA(4) static const byte s1[256]; 33 | static const word32 SP[4][256]; 34 | 35 | unsigned int m_rounds; 36 | SecBlock m_key; 37 | }; 38 | 39 | public: 40 | typedef BlockCipherFinal Encryption; 41 | typedef BlockCipherFinal Decryption; 42 | }; 43 | 44 | typedef Camellia::Encryption CamelliaEncryption; 45 | typedef Camellia::Decryption CamelliaDecryption; 46 | 47 | NAMESPACE_END 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/cbcmac.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | 3 | #ifndef CRYPTOPP_IMPORTS 4 | 5 | #include "cbcmac.h" 6 | 7 | NAMESPACE_BEGIN(CryptoPP) 8 | 9 | void CBC_MAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) 10 | { 11 | AccessCipher().SetKey(key, length, params); 12 | m_reg.CleanNew(AccessCipher().BlockSize()); 13 | m_counter = 0; 14 | } 15 | 16 | void CBC_MAC_Base::Update(const byte *input, size_t length) 17 | { 18 | unsigned int blockSize = AccessCipher().BlockSize(); 19 | 20 | while (m_counter && length) 21 | { 22 | m_reg[m_counter++] ^= *input++; 23 | if (m_counter == blockSize) 24 | ProcessBuf(); 25 | length--; 26 | } 27 | 28 | if (length >= blockSize) 29 | { 30 | size_t leftOver = AccessCipher().AdvancedProcessBlocks(m_reg, input, m_reg, length, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput); 31 | input += (length - leftOver); 32 | length = leftOver; 33 | } 34 | 35 | while (length--) 36 | { 37 | m_reg[m_counter++] ^= *input++; 38 | if (m_counter == blockSize) 39 | ProcessBuf(); 40 | } 41 | } 42 | 43 | void CBC_MAC_Base::TruncatedFinal(byte *mac, size_t size) 44 | { 45 | ThrowIfInvalidTruncatedSize(size); 46 | 47 | if (m_counter) 48 | ProcessBuf(); 49 | 50 | memcpy(mac, m_reg, size); 51 | memset(m_reg, 0, AccessCipher().BlockSize()); 52 | } 53 | 54 | void CBC_MAC_Base::ProcessBuf() 55 | { 56 | AccessCipher().ProcessBlock(m_reg); 57 | m_counter = 0; 58 | } 59 | 60 | NAMESPACE_END 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/cbcmac.h: -------------------------------------------------------------------------------- 1 | // cbcmac.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file 4 | /// \brief Classes for CBC MAC 5 | /// \since Crypto++ 3.1 6 | 7 | #ifndef CRYPTOPP_CBCMAC_H 8 | #define CRYPTOPP_CBCMAC_H 9 | 10 | #include "seckey.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief CBC-MAC base class 16 | /// \since Crypto++ 3.1 17 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_MAC_Base : public MessageAuthenticationCode 18 | { 19 | public: 20 | CBC_MAC_Base() : m_counter(0) {} 21 | 22 | void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); 23 | void Update(const byte *input, size_t length); 24 | void TruncatedFinal(byte *mac, size_t size); 25 | unsigned int DigestSize() const {return const_cast(this)->AccessCipher().BlockSize();} 26 | 27 | protected: 28 | virtual BlockCipher & AccessCipher() =0; 29 | 30 | private: 31 | void ProcessBuf(); 32 | SecByteBlock m_reg; 33 | unsigned int m_counter; 34 | }; 35 | 36 | /// \brief CBC-MAC 37 | /// \tparam T BlockCipherDocumentation derived class 38 | /// \details CBC-MAC is compatible with FIPS 113. The MAC is secure only for fixed 39 | /// length messages. For variable length messages use CMAC or DMAC. 40 | /// \sa CBC-MAC 41 | /// \since Crypto++ 3.1 42 | template 43 | class CBC_MAC : public MessageAuthenticationCodeImpl >, public SameKeyLengthAs 44 | { 45 | public: 46 | CBC_MAC() {} 47 | CBC_MAC(const byte *key, size_t length=SameKeyLengthAs::DEFAULT_KEYLENGTH) 48 | {this->SetKey(key, length);} 49 | 50 | static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";} 51 | 52 | private: 53 | BlockCipher & AccessCipher() {return m_cipher;} 54 | typename T::Encryption m_cipher; 55 | }; 56 | 57 | NAMESPACE_END 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/cmac.h: -------------------------------------------------------------------------------- 1 | // cmac.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file cmac.h 4 | /// \brief Classes for CMAC message authentication code 5 | /// \since Crypto++ 5.6.0 6 | 7 | #ifndef CRYPTOPP_CMAC_H 8 | #define CRYPTOPP_CMAC_H 9 | 10 | #include "seckey.h" 11 | #include "secblock.h" 12 | 13 | /// \brief Enable CMAC and wide block ciphers 14 | /// \details CMAC is only defined for AES. The library can support wide 15 | /// block ciphers like Kaylna and Threefish since we know the polynomials. 16 | #ifndef CRYPTOPP_CMAC_WIDE_BLOCK_CIPHERS 17 | # define CRYPTOPP_CMAC_WIDE_BLOCK_CIPHERS 1 18 | #endif // CRYPTOPP_CMAC_WIDE_BLOCK_CIPHERS 19 | 20 | NAMESPACE_BEGIN(CryptoPP) 21 | 22 | /// \brief CMAC base implementation 23 | /// \since Crypto++ 5.6.0 24 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CMAC_Base : public MessageAuthenticationCode 25 | { 26 | public: 27 | 28 | virtual ~CMAC_Base() {} 29 | CMAC_Base() : m_counter(0) {} 30 | 31 | void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); 32 | void Update(const byte *input, size_t length); 33 | void TruncatedFinal(byte *mac, size_t size); 34 | unsigned int DigestSize() const {return GetCipher().BlockSize();} 35 | unsigned int OptimalBlockSize() const {return GetCipher().BlockSize();} 36 | unsigned int OptimalDataAlignment() const {return GetCipher().OptimalDataAlignment();} 37 | std::string AlgorithmProvider() const {return GetCipher().AlgorithmProvider();} 38 | 39 | protected: 40 | friend class EAX_Base; 41 | 42 | const BlockCipher & GetCipher() const {return const_cast(this)->AccessCipher();} 43 | virtual BlockCipher & AccessCipher() =0; 44 | 45 | void ProcessBuf(); 46 | SecByteBlock m_reg; 47 | unsigned int m_counter; 48 | }; 49 | 50 | /// \brief CMAC message authentication code 51 | /// \tparam T block cipher 52 | /// \details Template parameter T should be a class derived from BlockCipherDocumentation, for example AES, with a block size of 8, 16, or 32. 53 | /// \sa CMAC 54 | /// \since Crypto++ 5.6.0 55 | template 56 | class CMAC : public MessageAuthenticationCodeImpl >, public SameKeyLengthAs 57 | { 58 | public: 59 | /// \brief Construct a CMAC 60 | CMAC() {} 61 | /// \brief Construct a CMAC 62 | /// \param key the MAC key 63 | /// \param length the key size, in bytes 64 | CMAC(const byte *key, size_t length=SameKeyLengthAs::DEFAULT_KEYLENGTH) 65 | {this->SetKey(key, length);} 66 | 67 | static std::string StaticAlgorithmName() {return std::string("CMAC(") + T::StaticAlgorithmName() + ")";} 68 | 69 | private: 70 | BlockCipher & AccessCipher() {return m_cipher;} 71 | typename T::Encryption m_cipher; 72 | }; 73 | 74 | NAMESPACE_END 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/config.h: -------------------------------------------------------------------------------- 1 | // config.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file config.h 4 | /// \brief Library configuration file 5 | /// \details config.h was split into components in May 2019 to better 6 | /// integrate with Autoconf and its feature tests. The splitting occurred so 7 | /// users could continue to include config.h while allowing Autoconf 8 | /// to write new config_asm.h and new config_cxx.h using 9 | /// its feature tests. 10 | /// \sa Issue 835, 11 | /// Make config.h more autoconf friendly, 12 | /// Configure.sh script 13 | /// on the Crypto++ wiki 14 | /// \since Crypto++ 8.3 15 | 16 | /// \file config.h 17 | /// \brief Library configuration file 18 | 19 | #ifndef CRYPTOPP_CONFIG_H 20 | #define CRYPTOPP_CONFIG_H 21 | 22 | #include "config_align.h" 23 | #include "config_asm.h" 24 | #include "config_cpu.h" 25 | #include "config_cxx.h" 26 | #include "config_dll.h" 27 | #include "config_int.h" 28 | #include "config_misc.h" 29 | #include "config_ns.h" 30 | #include "config_os.h" 31 | #include "config_ver.h" 32 | 33 | #endif // CRYPTOPP_CONFIG_H 34 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/config_ns.h: -------------------------------------------------------------------------------- 1 | // config_ns.h - written and placed in public domain by Jeffrey Walton 2 | // the bits that make up this source file are from the 3 | // library's monolithic config.h. 4 | 5 | /// \file config_ns.h 6 | /// \brief Library configuration file 7 | /// \details config_ns.h provides defines for C++ and library 8 | /// namespaces. 9 | /// \details config.h was split into components in May 2019 to better 10 | /// integrate with Autoconf and its feature tests. The splitting occurred so 11 | /// users could continue to include config.h while allowing Autoconf 12 | /// to write new config_asm.h and new config_cxx.h using 13 | /// its feature tests. 14 | /// \note You should include config.h rather than config_ns.h 15 | /// directly. 16 | /// \sa Issue 835, 17 | /// Make config.h more autoconf friendly, 18 | /// Configure.sh script 19 | /// on the Crypto++ wiki 20 | /// \since Crypto++ 8.3 21 | 22 | #ifndef CRYPTOPP_CONFIG_NAMESPACE_H 23 | #define CRYPTOPP_CONFIG_NAMESPACE_H 24 | 25 | // namespace support is now required 26 | #ifdef NO_NAMESPACE 27 | # error namespace support is now required 28 | #endif 29 | 30 | #ifdef CRYPTOPP_DOXYGEN_PROCESSING 31 | 32 | /// \namespace CryptoPP 33 | /// \brief Crypto++ library namespace 34 | /// \details Nearly all classes are located in the CryptoPP namespace. Within 35 | /// the namespace, there are four additional namespaces. 36 | ///
    37 | ///
  • Name - namespace for names used with NameValuePairs and documented 38 | /// in argnames.h 39 | ///
  • NaCl - namespace for NaCl test functions like crypto_box, 40 | /// crypto_box_open, crypto_sign, and crypto_sign_open 41 | ///
  • Donna - namespace for curve25519 library operations. The name was 42 | /// selected due to use of Langley and Moon's curve25519-donna. 43 | ///
  • Test - namespace for testing and benchmarks classes 44 | ///
  • Weak - namespace for weak and wounded algorithms, like ARC4, MD5 45 | /// and Pananma 46 | ///
47 | /// \since Crypto++ 3.0 48 | namespace CryptoPP { } 49 | 50 | // Bring in the symbols found in the weak namespace; and fold Weak1 into Weak 51 | #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 52 | #define Weak1 Weak 53 | // Avoid putting "CryptoPP::" in front of everything in Doxygen output 54 | #define CryptoPP 55 | #define NAMESPACE_BEGIN(x) 56 | #define NAMESPACE_END 57 | // Get Doxygen to generate better documentation for these typedefs 58 | #define DOCUMENTED_TYPEDEF(x, y) class y : public x {} 59 | // Make "protected" "private" so the functions and members are not documented 60 | #define protected private 61 | 62 | #else 63 | // Not Doxygen 64 | #define NAMESPACE_BEGIN(x) namespace x { 65 | #define NAMESPACE_END } 66 | #define DOCUMENTED_TYPEDEF(x, y) typedef x y 67 | 68 | #endif // CRYPTOPP_DOXYGEN_PROCESSING 69 | 70 | #define ANONYMOUS_NAMESPACE_BEGIN namespace { 71 | #define ANONYMOUS_NAMESPACE_END } 72 | #define USING_NAMESPACE(x) using namespace x; 73 | #define DOCUMENTED_NAMESPACE_BEGIN(x) namespace x { 74 | #define DOCUMENTED_NAMESPACE_END } 75 | 76 | #endif // CRYPTOPP_CONFIG_NAMESPACE_H 77 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/crc.h: -------------------------------------------------------------------------------- 1 | // crc.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file crc.h 4 | /// \brief Classes for CRC-32 and CRC-32C checksum algorithm 5 | 6 | #ifndef CRYPTOPP_CRC32_H 7 | #define CRYPTOPP_CRC32_H 8 | 9 | #include "cryptlib.h" 10 | 11 | NAMESPACE_BEGIN(CryptoPP) 12 | 13 | const word32 CRC32_NEGL = 0xffffffffL; 14 | 15 | #if (CRYPTOPP_LITTLE_ENDIAN) 16 | #define CRC32_INDEX(c) (c & 0xff) 17 | #define CRC32_SHIFTED(c) (c >> 8) 18 | #else 19 | #define CRC32_INDEX(c) (c >> 24) 20 | #define CRC32_SHIFTED(c) (c << 8) 21 | #endif 22 | 23 | /// \brief CRC-32 Checksum Calculation 24 | /// \details Uses CRC polynomial 0xEDB88320 25 | class CRC32 : public HashTransformation 26 | { 27 | public: 28 | CRYPTOPP_CONSTANT(DIGESTSIZE = 4); 29 | CRC32(); 30 | void Update(const byte *input, size_t length); 31 | void TruncatedFinal(byte *hash, size_t size); 32 | unsigned int DigestSize() const {return DIGESTSIZE;} 33 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "CRC32";} 34 | std::string AlgorithmName() const {return StaticAlgorithmName();} 35 | 36 | void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);} 37 | byte GetCrcByte(size_t i) const {return reinterpret_cast(&m_crc)[i];} 38 | 39 | std::string AlgorithmProvider() const; 40 | 41 | protected: 42 | void Reset() {m_crc = CRC32_NEGL;} 43 | 44 | private: 45 | static const word32 m_tab[256]; 46 | word32 m_crc; 47 | }; 48 | 49 | /// \brief CRC-32C Checksum Calculation 50 | /// \details Uses CRC polynomial 0x82F63B78 51 | /// \since Crypto++ 5.6.4 52 | class CRC32C : public HashTransformation 53 | { 54 | public: 55 | CRYPTOPP_CONSTANT(DIGESTSIZE = 4); 56 | CRC32C(); 57 | void Update(const byte *input, size_t length); 58 | void TruncatedFinal(byte *hash, size_t size); 59 | unsigned int DigestSize() const {return DIGESTSIZE;} 60 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "CRC32C";} 61 | std::string AlgorithmName() const {return StaticAlgorithmName();} 62 | 63 | void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);} 64 | byte GetCrcByte(size_t i) const {return reinterpret_cast(&m_crc)[i];} 65 | 66 | std::string AlgorithmProvider() const; 67 | 68 | protected: 69 | void Reset() {m_crc = CRC32_NEGL;} 70 | 71 | private: 72 | static const word32 m_tab[256]; 73 | word32 m_crc; 74 | }; 75 | 76 | NAMESPACE_END 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/cryptest.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | v 5 | 6 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/cryptlib.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/cryptopp.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zackmark29/Chrome2209-CDM-API/e3a306cb42bd3999eb1f68c6548a67eb54dda8a8/cryptlib_src/cryptopp850/cryptopp.rc -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/cryptopp.supp: -------------------------------------------------------------------------------- 1 | # Valgrind suppression file 2 | 3 | { 4 | # https://github.com/weidai11/cryptopp/issues/543 5 | __memcmp_sse4_1 6 | Memcheck:Cond 7 | fun:__memcmp_sse4_1 8 | } 9 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/dh.cpp: -------------------------------------------------------------------------------- 1 | // dh.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | 5 | #ifndef CRYPTOPP_IMPORTS 6 | 7 | #include "dh.h" 8 | 9 | NAMESPACE_BEGIN(CryptoPP) 10 | 11 | #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) 12 | void DH_TestInstantiations() 13 | { 14 | DH dh1; 15 | DH dh2(NullRNG(), 10); 16 | } 17 | #endif 18 | 19 | NAMESPACE_END 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/dh2.cpp: -------------------------------------------------------------------------------- 1 | // dh2.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | #include "cryptlib.h" 5 | #include "misc.h" 6 | #include "dh2.h" 7 | 8 | NAMESPACE_BEGIN(CryptoPP) 9 | 10 | #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) 11 | struct NullCryptoParameters : public CryptoParameters 12 | { 13 | void AssignFrom(const NameValuePairs &source) { 14 | CRYPTOPP_UNUSED(source); 15 | } 16 | bool Validate(RandomNumberGenerator &rng, unsigned int level) const { 17 | CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(level); 18 | return false; 19 | } 20 | bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const { 21 | CRYPTOPP_UNUSED(name); CRYPTOPP_UNUSED(valueType); CRYPTOPP_UNUSED(pValue); 22 | return false; 23 | } 24 | }; 25 | 26 | struct NullSimpleKeyAgreementDomain : public TwoBases 27 | { 28 | CryptoParameters & AccessCryptoParameters() { 29 | return *this; 30 | } 31 | unsigned int AgreedValueLength() const { 32 | return 1; 33 | } 34 | unsigned int PrivateKeyLength() const { 35 | return 1; 36 | } 37 | unsigned int PublicKeyLength() const { 38 | return 1; 39 | } 40 | void GeneratePrivateKey(RandomNumberGenerator &rng, byte *privateKey) const { 41 | CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(privateKey); 42 | } 43 | void GeneratePublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const { 44 | CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(privateKey); CRYPTOPP_UNUSED(publicKey); 45 | } 46 | bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const { 47 | CRYPTOPP_UNUSED(agreedValue); CRYPTOPP_UNUSED(privateKey); 48 | CRYPTOPP_UNUSED(otherPublicKey); CRYPTOPP_UNUSED(validateOtherPublicKey); 49 | return false; 50 | } 51 | }; 52 | 53 | void DH2_TestInstantiations() 54 | { 55 | NullSimpleKeyAgreementDomain dom; 56 | DH2 dh(dom); 57 | } 58 | #endif 59 | 60 | bool DH2::Agree(byte *agreedValue, 61 | const byte *staticSecretKey, const byte *ephemeralSecretKey, 62 | const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey, 63 | bool validateStaticOtherPublicKey) const 64 | { 65 | return d1.Agree(agreedValue, staticSecretKey, staticOtherPublicKey, validateStaticOtherPublicKey) 66 | && d2.Agree(agreedValue+d1.AgreedValueLength(), ephemeralSecretKey, ephemeralOtherPublicKey, true); 67 | } 68 | 69 | NAMESPACE_END 70 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/dh2.h: -------------------------------------------------------------------------------- 1 | // dh2.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file dh2.h 4 | /// \brief Classes for Unified Diffie-Hellman key exchange 5 | /// \since Crypto++ 3.0 6 | 7 | #ifndef CRYPTOPP_DH2_H 8 | #define CRYPTOPP_DH2_H 9 | 10 | #include "cryptlib.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | /// \brief Unified Diffie-Hellman in GF(p) 15 | /// \details A Diffie-Hellman domain is a set of parameters that must be shared 16 | /// by two parties in a key agreement protocol, along with the algorithms 17 | /// for generating key pairs and deriving agreed values. 18 | /// \sa AuthenticatedKeyAgreementDomain, Unified Diffie-Hellman 19 | /// \since Crypto++ 3.0 20 | class DH2 : public AuthenticatedKeyAgreementDomain 21 | { 22 | public: 23 | virtual ~DH2() {} 24 | 25 | /// \brief Construct a DH2 26 | DH2(SimpleKeyAgreementDomain &domain) 27 | : d1(domain), d2(domain) {} 28 | /// \brief Construct a DH2 29 | DH2(SimpleKeyAgreementDomain &staticDomain, SimpleKeyAgreementDomain &ephemeralDomain) 30 | : d1(staticDomain), d2(ephemeralDomain) {} 31 | 32 | CryptoParameters & AccessCryptoParameters() {return d1.AccessCryptoParameters();} 33 | 34 | unsigned int AgreedValueLength() const 35 | {return d1.AgreedValueLength() + d2.AgreedValueLength();} 36 | 37 | unsigned int StaticPrivateKeyLength() const 38 | {return d1.PrivateKeyLength();} 39 | unsigned int StaticPublicKeyLength() const 40 | {return d1.PublicKeyLength();} 41 | void GenerateStaticPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const 42 | {d1.GeneratePrivateKey(rng, privateKey);} 43 | void GenerateStaticPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const 44 | {d1.GeneratePublicKey(rng, privateKey, publicKey);} 45 | void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const 46 | {d1.GenerateKeyPair(rng, privateKey, publicKey);} 47 | 48 | unsigned int EphemeralPrivateKeyLength() const 49 | {return d2.PrivateKeyLength();} 50 | unsigned int EphemeralPublicKeyLength() const 51 | {return d2.PublicKeyLength();} 52 | void GenerateEphemeralPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const 53 | {d2.GeneratePrivateKey(rng, privateKey);} 54 | void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const 55 | {d2.GeneratePublicKey(rng, privateKey, publicKey);} 56 | void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const 57 | {d2.GenerateKeyPair(rng, privateKey, publicKey);} 58 | 59 | bool Agree(byte *agreedValue, 60 | const byte *staticPrivateKey, const byte *ephemeralPrivateKey, 61 | const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey, 62 | bool validateStaticOtherPublicKey=true) const; 63 | 64 | protected: 65 | SimpleKeyAgreementDomain &d1, &d2; 66 | }; 67 | 68 | NAMESPACE_END 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/dll.h: -------------------------------------------------------------------------------- 1 | // dll.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file dll.h 4 | /// \brief Functions and definitions required for building the FIPS-140 DLL on Windows 5 | 6 | #ifndef CRYPTOPP_DLL_H 7 | #define CRYPTOPP_DLL_H 8 | 9 | #if !defined(CRYPTOPP_IMPORTS) && !defined(CRYPTOPP_EXPORTS) && !defined(CRYPTOPP_DEFAULT_NO_DLL) 10 | #ifdef CRYPTOPP_CONFIG_H 11 | #error To use the DLL version of Crypto++, this file must be included before any other Crypto++ header files. 12 | #endif 13 | #define CRYPTOPP_IMPORTS 14 | #endif 15 | 16 | #include "aes.h" 17 | #include "cbcmac.h" 18 | #include "ccm.h" 19 | #include "cmac.h" 20 | #include "channels.h" 21 | #include "des.h" 22 | #include "dh.h" 23 | #include "dsa.h" 24 | #include "ec2n.h" 25 | #include "eccrypto.h" 26 | #include "ecp.h" 27 | #include "files.h" 28 | #include "fips140.h" 29 | #include "gcm.h" 30 | #include "hex.h" 31 | #include "hmac.h" 32 | #include "modes.h" 33 | #include "mqueue.h" 34 | #include "nbtheory.h" 35 | #include "osrng.h" 36 | #include "pkcspad.h" 37 | #include "pssr.h" 38 | #include "randpool.h" 39 | #include "rsa.h" 40 | #include "rw.h" 41 | #include "sha.h" 42 | #include "skipjack.h" 43 | 44 | #ifdef CRYPTOPP_IMPORTS 45 | 46 | #ifdef _DLL 47 | // cause CRT DLL to be initialized before Crypto++ so that we can use malloc and free during DllMain() 48 | #ifdef CRYPTOPP_DEBUG 49 | # pragma comment(lib, "msvcrtd") 50 | # pragma comment(lib, "cryptopp") 51 | #else 52 | # pragma comment(lib, "msvcrt") 53 | # pragma comment(lib, "cryptopp") 54 | #endif 55 | #endif 56 | 57 | #endif // #ifdef CRYPTOPP_IMPORTS 58 | 59 | #include // for new_handler 60 | 61 | NAMESPACE_BEGIN(CryptoPP) 62 | 63 | typedef void * (CRYPTOPP_API * PNew)(size_t); 64 | typedef void (CRYPTOPP_API * PDelete)(void *); 65 | typedef void (CRYPTOPP_API * PGetNewAndDelete)(PNew &, PDelete &); 66 | typedef std::new_handler (CRYPTOPP_API * PSetNewHandler)(std::new_handler); 67 | typedef void (CRYPTOPP_API * PSetNewAndDelete)(PNew, PDelete, PSetNewHandler); 68 | 69 | NAMESPACE_END 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/donna_sse.h: -------------------------------------------------------------------------------- 1 | // donna_sse.h - written and placed in public domain by Jeffrey Walton 2 | // Crypto++ specific implementation wrapped around Andrew 3 | // Moon's public domain curve25519-donna and ed25519-donna, 4 | // https://github.com/floodyberry/curve25519-donna and 5 | // https://github.com/floodyberry/ed25519-donna. 6 | 7 | // This source file multiplexes two different repos using namespaces. This 8 | // was a little easier from a project management standpoint. We only need 9 | // two files per architecture at the expense of namespaces and bloat. 10 | 11 | #ifndef CRYPTOPP_DONNA_SSE_H 12 | #define CRYPTOPP_DONNA_SSE_H 13 | #ifndef CRYPTOPP_DOXYGEN_PROCESSING 14 | 15 | #include "config.h" 16 | #include 17 | 18 | NAMESPACE_BEGIN(CryptoPP) 19 | NAMESPACE_BEGIN(Donna) 20 | NAMESPACE_BEGIN(ArchSSE) 21 | 22 | using CryptoPP::byte; 23 | using CryptoPP::word32; 24 | 25 | typedef __m128i xmmi; 26 | #define ALIGN(n) CRYPTOPP_ALIGN_DATA(n) 27 | 28 | typedef union packedelem8_t { 29 | byte u[16]; 30 | xmmi v; 31 | } packedelem8; 32 | 33 | typedef union packedelem32_t { 34 | word32 u[4]; 35 | xmmi v; 36 | } packedelem32; 37 | 38 | typedef union packedelem64_t { 39 | word64 u[2]; 40 | xmmi v; 41 | } packedelem64; 42 | 43 | /* 10 elements + an extra 2 to fit in 3 xmm registers */ 44 | typedef word32 bignum25519[12]; 45 | typedef packedelem32 packed32bignum25519[5]; 46 | typedef packedelem64 packed64bignum25519[10]; 47 | 48 | const word32 reduce_mask_26 = (1 << 26) - 1; 49 | const word32 reduce_mask_25 = (1 << 25) - 1; 50 | 51 | const packedelem32 sse2_bot32bitmask = {{0xffffffff, 0x00000000, 0xffffffff, 0x00000000}}; 52 | const packedelem32 sse2_top32bitmask = {{0x00000000, 0xffffffff, 0x00000000, 0xffffffff}}; 53 | const packedelem32 sse2_top64bitmask = {{0x00000000, 0x00000000, 0xffffffff, 0xffffffff}}; 54 | const packedelem32 sse2_bot64bitmask = {{0xffffffff, 0xffffffff, 0x00000000, 0x00000000}}; 55 | 56 | /* reduction masks */ 57 | const packedelem64 packedmask26 = {{0x03ffffff, 0x03ffffff}}; 58 | const packedelem64 packedmask25 = {{0x01ffffff, 0x01ffffff}}; 59 | const packedelem32 packedmask2625 = {{0x3ffffff,0,0x1ffffff,0}}; 60 | const packedelem32 packedmask26262626 = {{0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff}}; 61 | const packedelem32 packedmask25252525 = {{0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff}}; 62 | 63 | /* multipliers */ 64 | const packedelem64 packednineteen = {{19, 19}}; 65 | const packedelem64 packednineteenone = {{19, 1}}; 66 | const packedelem64 packedthirtyeight = {{38, 38}}; 67 | const packedelem64 packed3819 = {{19*2,19}}; 68 | const packedelem64 packed9638 = {{19*4,19*2}}; 69 | 70 | /* 121666,121665 */ 71 | const packedelem64 packed121666121665 = {{121666, 121665}}; 72 | 73 | /* 2*(2^255 - 19) = 0 mod p */ 74 | const packedelem32 packed2p0 = {{0x7ffffda,0x3fffffe,0x7fffffe,0x3fffffe}}; 75 | const packedelem32 packed2p1 = {{0x7fffffe,0x3fffffe,0x7fffffe,0x3fffffe}}; 76 | const packedelem32 packed2p2 = {{0x7fffffe,0x3fffffe,0x0000000,0x0000000}}; 77 | 78 | const packedelem32 packed32zeromodp0 = {{0x7ffffda,0x7ffffda,0x3fffffe,0x3fffffe}}; 79 | const packedelem32 packed32zeromodp1 = {{0x7fffffe,0x7fffffe,0x3fffffe,0x3fffffe}}; 80 | 81 | NAMESPACE_END // ArchSSE 82 | NAMESPACE_END // Donna 83 | NAMESPACE_END // CryptoPP 84 | 85 | #endif // CRYPTOPP_DOXYGEN_PROCESSING 86 | #endif // CRYPTOPP_DONNA_SSE_H 87 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/dsa.cpp: -------------------------------------------------------------------------------- 1 | // dsa.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | 5 | #ifndef CRYPTOPP_IMPORTS 6 | 7 | #include "dsa.h" 8 | #include "asn.h" 9 | #include "integer.h" 10 | #include "filters.h" 11 | #include "nbtheory.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | size_t DSAConvertSignatureFormat(byte *buffer, size_t bufferSize, DSASignatureFormat toFormat, const byte *signature, size_t signatureLen, DSASignatureFormat fromFormat) 16 | { 17 | Integer r, s; 18 | StringStore store(signature, signatureLen); 19 | ArraySink sink(buffer, bufferSize); 20 | 21 | switch (fromFormat) 22 | { 23 | case DSA_P1363: 24 | r.Decode(store, signatureLen/2); 25 | s.Decode(store, signatureLen/2); 26 | break; 27 | case DSA_DER: 28 | { 29 | BERSequenceDecoder seq(store); 30 | r.BERDecode(seq); 31 | s.BERDecode(seq); 32 | seq.MessageEnd(); 33 | break; 34 | } 35 | case DSA_OPENPGP: 36 | r.OpenPGPDecode(store); 37 | s.OpenPGPDecode(store); 38 | break; 39 | } 40 | 41 | switch (toFormat) 42 | { 43 | case DSA_P1363: 44 | r.Encode(sink, bufferSize/2); 45 | s.Encode(sink, bufferSize/2); 46 | break; 47 | case DSA_DER: 48 | { 49 | DERSequenceEncoder seq(sink); 50 | r.DEREncode(seq); 51 | s.DEREncode(seq); 52 | seq.MessageEnd(); 53 | break; 54 | } 55 | case DSA_OPENPGP: 56 | r.OpenPGPEncode(sink); 57 | s.OpenPGPEncode(sink); 58 | break; 59 | } 60 | 61 | return (size_t)sink.TotalPutLength(); 62 | } 63 | 64 | NAMESPACE_END 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/dsa.h: -------------------------------------------------------------------------------- 1 | // dsa.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file dsa.h 4 | /// \brief Classes for the DSA signature algorithm 5 | 6 | #ifndef CRYPTOPP_DSA_H 7 | #define CRYPTOPP_DSA_H 8 | 9 | #include "cryptlib.h" 10 | #include "gfpcrypt.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | /// \brief DSA Signature Format 15 | /// \details The DSA signature format used by Crypto++ is as defined by IEEE P1363. 16 | /// OpenSSL, Java and .Net use the DER format, and OpenPGP uses the OpenPGP format. 17 | /// \sa DSAConvertSignatureFormat 18 | /// on the Crypto++ wiki. 19 | /// \since Crypto++ 1.0 20 | enum DSASignatureFormat { 21 | /// \brief Crypto++ native signature encoding format 22 | DSA_P1363, 23 | /// \brief signature encoding format used by OpenSSL, Java and .Net 24 | DSA_DER, 25 | /// \brief OpenPGP signature encoding format 26 | DSA_OPENPGP 27 | }; 28 | 29 | /// \brief Converts between signature encoding formats 30 | /// \param buffer byte buffer for the converted signature encoding 31 | /// \param bufferSize the length of the converted signature encoding buffer 32 | /// \param toFormat the source signature format 33 | /// \param signature byte buffer for the existing signature encoding 34 | /// \param signatureLen the length of the existing signature encoding buffer 35 | /// \param fromFormat the source signature format 36 | /// \return the number of bytes written during encoding 37 | /// \details This function converts between these formats, and returns length 38 | /// of signature in the target format. If toFormat == DSA_P1363, then 39 | /// bufferSize must equal publicKey.SignatureLength() or 40 | /// verifier.SignatureLength(). 41 | /// \details If the destination buffer is too small then the output of the 42 | /// encoded r and s will be truncated. Be sure to provide 43 | /// an adequately sized buffer and check the return value for the number of 44 | /// bytes written. 45 | /// \sa DSAConvertSignatureFormat 46 | /// on the Crypto++ wiki. 47 | /// \since Crypto++ 1.0 48 | size_t DSAConvertSignatureFormat(byte *buffer, size_t bufferSize, DSASignatureFormat toFormat, 49 | const byte *signature, size_t signatureLen, DSASignatureFormat fromFormat); 50 | 51 | NAMESPACE_END 52 | 53 | #endif // CRYPTOPP_DSA_H 54 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/eax.cpp: -------------------------------------------------------------------------------- 1 | // eax.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | #include "eax.h" 5 | 6 | NAMESPACE_BEGIN(CryptoPP) 7 | 8 | void EAX_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) 9 | { 10 | AccessMAC().SetKey(userKey, keylength, params); 11 | m_buffer.New(2*AccessMAC().TagSize()); 12 | } 13 | 14 | void EAX_Base::Resync(const byte *iv, size_t len) 15 | { 16 | MessageAuthenticationCode &mac = AccessMAC(); 17 | unsigned int blockSize = mac.TagSize(); 18 | 19 | memset(m_buffer, 0, blockSize); 20 | mac.Update(m_buffer, blockSize); 21 | mac.CalculateDigest(m_buffer+blockSize, iv, len); 22 | 23 | m_buffer[blockSize-1] = 1; 24 | mac.Update(m_buffer, blockSize); 25 | 26 | m_ctr.SetCipherWithIV(AccessMAC().AccessCipher(), m_buffer+blockSize, blockSize); 27 | } 28 | 29 | size_t EAX_Base::AuthenticateBlocks(const byte *data, size_t len) 30 | { 31 | AccessMAC().Update(data, len); 32 | return 0; 33 | } 34 | 35 | void EAX_Base::AuthenticateLastHeaderBlock() 36 | { 37 | CRYPTOPP_ASSERT(m_bufferedDataLength == 0); 38 | MessageAuthenticationCode &mac = AccessMAC(); 39 | const unsigned int blockSize = mac.TagSize(); 40 | 41 | mac.Final(m_buffer); 42 | xorbuf(m_buffer+blockSize, m_buffer, blockSize); 43 | 44 | memset(m_buffer, 0, blockSize); 45 | m_buffer[blockSize-1] = 2; 46 | mac.Update(m_buffer, blockSize); 47 | } 48 | 49 | void EAX_Base::AuthenticateLastFooterBlock(byte *tag, size_t macSize) 50 | { 51 | CRYPTOPP_ASSERT(m_bufferedDataLength == 0); 52 | MessageAuthenticationCode &mac = AccessMAC(); 53 | unsigned int blockSize = mac.TagSize(); 54 | 55 | mac.TruncatedFinal(m_buffer, macSize); 56 | xorbuf(tag, m_buffer, m_buffer+blockSize, macSize); 57 | } 58 | 59 | NAMESPACE_END 60 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/elgamal.cpp: -------------------------------------------------------------------------------- 1 | // elgamal.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | #include "elgamal.h" 5 | #include "asn.h" 6 | #include "nbtheory.h" 7 | 8 | // Squash MS LNK4221 and libtool warnings 9 | extern const char ELGAMAL_FNAME[] = __FILE__; 10 | 11 | NAMESPACE_BEGIN(CryptoPP) 12 | 13 | #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) 14 | void ElGamal_TestInstantiations() 15 | { 16 | ElGamalEncryptor test1(1, 1, 1); 17 | ElGamalDecryptor test2(NullRNG(), 123); 18 | ElGamalEncryptor test3(test2); 19 | } 20 | #endif 21 | 22 | NAMESPACE_END 23 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/emsa2.cpp: -------------------------------------------------------------------------------- 1 | // emsa2.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | #include "emsa2.h" 5 | 6 | #ifndef CRYPTOPP_IMPORTS 7 | 8 | NAMESPACE_BEGIN(CryptoPP) 9 | 10 | // Inclusion based on DLL due to Clang, http://github.com/weidai11/cryptopp/issues/300 11 | #ifndef CRYPTOPP_IS_DLL 12 | template<> const byte EMSA2HashId::id = 0x33; 13 | template<> const byte EMSA2HashId::id = 0x38; 14 | template<> const byte EMSA2HashId::id = 0x34; 15 | template<> const byte EMSA2HashId::id = 0x36; 16 | template<> const byte EMSA2HashId::id = 0x35; 17 | #endif 18 | 19 | void EMSA2Pad::ComputeMessageRepresentative(RandomNumberGenerator& /*rng*/, 20 | const byte* recoverableMessage, size_t recoverableMessageLength, 21 | HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, 22 | byte *representative, size_t representativeBitLength) const 23 | { 24 | CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(recoverableMessageLength), CRYPTOPP_UNUSED(representativeBitLength); 25 | CRYPTOPP_ASSERT(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize())); 26 | 27 | if (representativeBitLength % 8 != 7) 28 | throw PK_SignatureScheme::InvalidKeyLength("EMSA2: EMSA2 requires a key length that is a multiple of 8"); 29 | 30 | size_t digestSize = hash.DigestSize(); 31 | size_t representativeByteLength = BitsToBytes(representativeBitLength); 32 | 33 | representative[0] = messageEmpty ? 0x4b : 0x6b; 34 | memset(representative+1, 0xbb, representativeByteLength-digestSize-4); // pad with 0xbb 35 | byte *afterP2 = representative+representativeByteLength-digestSize-3; 36 | afterP2[0] = 0xba; 37 | hash.Final(afterP2+1); 38 | representative[representativeByteLength-2] = *hashIdentifier.first; 39 | representative[representativeByteLength-1] = 0xcc; 40 | } 41 | 42 | NAMESPACE_END 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/emsa2.h: -------------------------------------------------------------------------------- 1 | // emsa2.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file emsa2.h 4 | /// \brief Classes and functions for various padding schemes used in public key algorithms 5 | 6 | #ifndef CRYPTOPP_EMSA2_H 7 | #define CRYPTOPP_EMSA2_H 8 | 9 | #include "cryptlib.h" 10 | #include "pubkey.h" 11 | #include "hashfwd.h" 12 | #include "misc.h" 13 | 14 | #ifdef CRYPTOPP_IS_DLL 15 | # include "sha.h" 16 | #endif 17 | 18 | NAMESPACE_BEGIN(CryptoPP) 19 | 20 | /// \brief EMSA2 hash identifier 21 | /// \tparam H HashTransformation derived class 22 | /// \since Crypto++ 5.0 23 | template class EMSA2HashId 24 | { 25 | public: 26 | static const byte id; 27 | }; 28 | 29 | /// \brief EMSA2 padding method 30 | /// \tparam BASE Message encoding method 31 | /// \since Crypto++ 5.0 32 | template 33 | class EMSA2HashIdLookup : public BASE 34 | { 35 | public: 36 | struct HashIdentifierLookup 37 | { 38 | template struct HashIdentifierLookup2 39 | { 40 | static HashIdentifier Lookup() 41 | { 42 | return HashIdentifier(&EMSA2HashId::id, 1); 43 | } 44 | }; 45 | }; 46 | }; 47 | 48 | // EMSA2HashId can be instantiated with the following classes. 49 | // SHA1, SHA224, SHA256, SHA384, SHA512, RIPEMD128, RIPEMD160, Whirlpool 50 | 51 | #ifdef CRYPTOPP_IS_DLL 52 | CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; 53 | CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; 54 | CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; 55 | CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; 56 | CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; 57 | #endif 58 | 59 | // https://github.com/weidai11/cryptopp/issues/300 and 60 | // https://github.com/weidai11/cryptopp/issues/533 61 | #if defined(__clang__) 62 | template<> const byte EMSA2HashId::id; 63 | template<> const byte EMSA2HashId::id; 64 | template<> const byte EMSA2HashId::id; 65 | template<> const byte EMSA2HashId::id; 66 | template<> const byte EMSA2HashId::id; 67 | #endif 68 | 69 | /// \brief EMSA2 padding method 70 | /// \since Crypto++ 5.0 71 | class CRYPTOPP_DLL EMSA2Pad : public EMSA2HashIdLookup 72 | { 73 | public: 74 | CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "EMSA2";} 75 | 76 | size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const 77 | {CRYPTOPP_UNUSED(hashIdentifierLength); return 8*digestLength + 31;} 78 | 79 | void ComputeMessageRepresentative(RandomNumberGenerator &rng, 80 | const byte *recoverableMessage, size_t recoverableMessageLength, 81 | HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, 82 | byte *representative, size_t representativeBitLength) const; 83 | }; 84 | 85 | // EMSA2, for use with RWSS and RSA_ISO 86 | // Only the following hash functions are supported by this signature standard: 87 | // \dontinclude emsa2.h 88 | // \skip EMSA2HashId can be instantiated 89 | // \until end of list 90 | 91 | /// \brief EMSA2/P1363 padding method 92 | /// \details Use with RWSS and RSA_ISO 93 | /// \since Crypto++ 5.0 94 | struct P1363_EMSA2 : public SignatureStandard 95 | { 96 | typedef EMSA2Pad SignatureMessageEncodingMethod; 97 | }; 98 | 99 | NAMESPACE_END 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/fips140.cpp: -------------------------------------------------------------------------------- 1 | // fips140.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | 5 | #ifndef CRYPTOPP_IMPORTS 6 | 7 | #include "fips140.h" 8 | #include "misc.h" 9 | 10 | NAMESPACE_BEGIN(CryptoPP) 11 | 12 | // Define this to 1 to turn on FIPS 140-2 compliance features, including additional tests during 13 | // startup, random number generation, and key generation. These tests may affect performance. 14 | #ifndef CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 15 | #define CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 0 16 | #endif 17 | 18 | #if (CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 && !defined(OS_RNG_AVAILABLE)) 19 | #error FIPS 140-2 compliance requires the availability of OS provided RNG. 20 | #endif 21 | 22 | PowerUpSelfTestStatus g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_NOT_DONE; 23 | 24 | bool FIPS_140_2_ComplianceEnabled() 25 | { 26 | return CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2; 27 | } 28 | 29 | void SimulatePowerUpSelfTestFailure() 30 | { 31 | g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_FAILED; 32 | } 33 | 34 | PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus() 35 | { 36 | return g_powerUpSelfTestStatus; 37 | } 38 | 39 | #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 40 | // One variable for all threads for compatibility. Previously this 41 | // was a ThreadLocalStorage variable, which is per-thread. Also see 42 | // https://github.com/weidai11/cryptopp/issues/208 43 | static bool s_inProgress = false; 44 | #endif 45 | 46 | bool PowerUpSelfTestInProgressOnThisThread() 47 | { 48 | #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 49 | return s_inProgress; 50 | #else 51 | return false; 52 | #endif 53 | } 54 | 55 | void SetPowerUpSelfTestInProgressOnThisThread(bool inProgress) 56 | { 57 | #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 58 | s_inProgress = inProgress; 59 | #else 60 | CRYPTOPP_UNUSED(inProgress); 61 | #endif 62 | } 63 | 64 | void EncryptionPairwiseConsistencyTest_FIPS_140_Only(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor) 65 | { 66 | #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 67 | EncryptionPairwiseConsistencyTest(encryptor, decryptor); 68 | #else 69 | CRYPTOPP_UNUSED(encryptor), CRYPTOPP_UNUSED(decryptor); 70 | #endif 71 | } 72 | 73 | void SignaturePairwiseConsistencyTest_FIPS_140_Only(const PK_Signer &signer, const PK_Verifier &verifier) 74 | { 75 | #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 76 | SignaturePairwiseConsistencyTest(signer, verifier); 77 | #else 78 | CRYPTOPP_UNUSED(signer), CRYPTOPP_UNUSED(verifier); 79 | #endif 80 | } 81 | 82 | NAMESPACE_END 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/fltrimpl.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_FLTRIMPL_H 2 | #define CRYPTOPP_FLTRIMPL_H 3 | 4 | #if CRYPTOPP_MSC_VERSION 5 | # pragma warning(push) 6 | # pragma warning(disable: 4100) 7 | #endif 8 | 9 | #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 10 | # pragma GCC diagnostic push 11 | # pragma GCC diagnostic ignored "-Wunused-value" 12 | #endif 13 | 14 | #define FILTER_BEGIN \ 15 | switch (m_continueAt) \ 16 | { \ 17 | case 0: \ 18 | m_inputPosition = 0; 19 | 20 | #define FILTER_END_NO_MESSAGE_END_NO_RETURN \ 21 | break; \ 22 | default: \ 23 | CRYPTOPP_ASSERT(false); \ 24 | } 25 | 26 | #define FILTER_END_NO_MESSAGE_END \ 27 | FILTER_END_NO_MESSAGE_END_NO_RETURN \ 28 | return 0; 29 | 30 | /* 31 | #define FILTER_END \ 32 | case -1: \ 33 | if (messageEnd && Output(-1, NULLPTR, 0, messageEnd, blocking)) \ 34 | return 1; \ 35 | FILTER_END_NO_MESSAGE_END 36 | */ 37 | 38 | #define FILTER_OUTPUT3(site, statement, output, length, messageEnd, channel) \ 39 | {\ 40 | case site: \ 41 | statement; \ 42 | if (Output(site, output, length, messageEnd, blocking, channel)) \ 43 | return STDMAX(size_t(1), length-m_inputPosition);\ 44 | } 45 | 46 | #define FILTER_OUTPUT2(site, statement, output, length, messageEnd) \ 47 | FILTER_OUTPUT3(site, statement, output, length, messageEnd, DEFAULT_CHANNEL) 48 | 49 | #define FILTER_OUTPUT(site, output, length, messageEnd) \ 50 | FILTER_OUTPUT2(site, 0, output, length, messageEnd) 51 | 52 | #define FILTER_OUTPUT_BYTE(site, output) \ 53 | FILTER_OUTPUT(site, &(const byte &)(byte)output, 1, 0) 54 | 55 | #define FILTER_OUTPUT2_MODIFIABLE(site, statement, output, length, messageEnd) \ 56 | {\ 57 | /* fall through */ \ 58 | case site: \ 59 | statement; \ 60 | if (OutputModifiable(site, output, length, messageEnd, blocking)) \ 61 | return STDMAX(size_t(1), length-m_inputPosition);\ 62 | } 63 | 64 | #define FILTER_OUTPUT_MODIFIABLE(site, output, length, messageEnd) \ 65 | FILTER_OUTPUT2_MODIFIABLE(site, 0, output, length, messageEnd) 66 | 67 | #define FILTER_OUTPUT2_MAYBE_MODIFIABLE(site, statement, output, length, messageEnd, modifiable) \ 68 | {\ 69 | /* fall through */ \ 70 | case site: \ 71 | statement; \ 72 | if (modifiable ? OutputModifiable(site, output, length, messageEnd, blocking) : Output(site, output, length, messageEnd, blocking)) \ 73 | return STDMAX(size_t(1), length-m_inputPosition);\ 74 | } 75 | 76 | #define FILTER_OUTPUT_MAYBE_MODIFIABLE(site, output, length, messageEnd, modifiable) \ 77 | FILTER_OUTPUT2_MAYBE_MODIFIABLE(site, 0, output, length, messageEnd, modifiable) 78 | 79 | #if CRYPTOPP_MSC_VERSION 80 | # pragma warning(pop) 81 | #endif 82 | 83 | #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 84 | # pragma GCC diagnostic pop 85 | #endif 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/gf256.cpp: -------------------------------------------------------------------------------- 1 | // gf256.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | #include "gf256.h" 5 | 6 | NAMESPACE_BEGIN(CryptoPP) 7 | 8 | GF256::Element GF256::Multiply(Element a, Element b) const 9 | { 10 | word result = 0, t = b; 11 | 12 | for (unsigned int i=0; i<8; i++) 13 | { 14 | result <<= 1; 15 | if (result & 0x100) 16 | result ^= m_modulus; 17 | 18 | t <<= 1; 19 | if (t & 0x100) 20 | result ^= a; 21 | } 22 | 23 | return (GF256::Element) result; 24 | } 25 | 26 | GF256::Element GF256::MultiplicativeInverse(Element a) const 27 | { 28 | Element result = a; 29 | for (int i=1; i<7; i++) 30 | result = Multiply(Square(result), a); 31 | return Square(result); 32 | } 33 | 34 | NAMESPACE_END 35 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/gf256.h: -------------------------------------------------------------------------------- 1 | // gf256.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file gf256.h 4 | /// \brief Classes and functions for schemes over GF(256) 5 | 6 | #ifndef CRYPTOPP_GF256_H 7 | #define CRYPTOPP_GF256_H 8 | 9 | #include "cryptlib.h" 10 | #include "misc.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | /// \brief GF(256) with polynomial basis 15 | class GF256 16 | { 17 | public: 18 | typedef byte Element; 19 | typedef int RandomizationParameter; 20 | 21 | GF256(byte modulus) : m_modulus(modulus) {} 22 | 23 | Element RandomElement(RandomNumberGenerator &rng, int ignored = 0) const 24 | {CRYPTOPP_UNUSED(ignored); return rng.GenerateByte();} 25 | 26 | bool Equal(Element a, Element b) const 27 | {return a==b;} 28 | 29 | Element Zero() const 30 | {return 0;} 31 | 32 | Element Add(Element a, Element b) const 33 | {return a^b;} 34 | 35 | Element& Accumulate(Element &a, Element b) const 36 | {return a^=b;} 37 | 38 | Element Inverse(Element a) const 39 | {return a;} 40 | 41 | Element Subtract(Element a, Element b) const 42 | {return a^b;} 43 | 44 | Element& Reduce(Element &a, Element b) const 45 | {return a^=b;} 46 | 47 | Element Double(Element a) const 48 | {CRYPTOPP_UNUSED(a); return 0;} 49 | 50 | Element One() const 51 | {return 1;} 52 | 53 | Element Multiply(Element a, Element b) const; 54 | 55 | Element Square(Element a) const 56 | {return Multiply(a, a);} 57 | 58 | bool IsUnit(Element a) const 59 | {return a != 0;} 60 | 61 | Element MultiplicativeInverse(Element a) const; 62 | 63 | Element Divide(Element a, Element b) const 64 | {return Multiply(a, MultiplicativeInverse(b));} 65 | 66 | private: 67 | word m_modulus; 68 | }; 69 | 70 | NAMESPACE_END 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/gf2_32.cpp: -------------------------------------------------------------------------------- 1 | // gf2_32.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | #include "misc.h" 5 | #include "gf2_32.h" 6 | 7 | NAMESPACE_BEGIN(CryptoPP) 8 | 9 | GF2_32::Element GF2_32::Multiply(Element a, Element b) const 10 | { 11 | word32 table[4]; 12 | table[0] = 0; 13 | table[1] = m_modulus; 14 | if (a & 0x80000000) 15 | { 16 | table[2] = m_modulus ^ (a<<1); 17 | table[3] = a<<1; 18 | } 19 | else 20 | { 21 | table[2] = a<<1; 22 | table[3] = m_modulus ^ (a<<1); 23 | } 24 | 25 | #if CRYPTOPP_FAST_ROTATE(32) 26 | b = rotrConstant<30>(b); 27 | word32 result = table[b&2]; 28 | 29 | for (int i=29; i>=0; --i) 30 | { 31 | b = rotlConstant<1>(b); 32 | result = (result<<1) ^ table[(b&2) + (result>>31)]; 33 | } 34 | 35 | return (b&1) ? result ^ a : result; 36 | #else 37 | word32 result = table[(b>>30) & 2]; 38 | 39 | for (int i=29; i>=0; --i) 40 | result = (result<<1) ^ table[((b>>i)&2) + (result>>31)]; 41 | 42 | return (b&1) ? result ^ a : result; 43 | #endif 44 | } 45 | 46 | GF2_32::Element GF2_32::MultiplicativeInverse(Element a) const 47 | { 48 | if (a <= 1) // 1 is a special case 49 | return a; 50 | 51 | // warning - don't try to adapt this algorithm for another situation 52 | word32 g0=m_modulus, g1=a, g2=a; 53 | word32 v0=0, v1=1, v2=1; 54 | 55 | CRYPTOPP_ASSERT(g1); 56 | 57 | while (!(g2 & 0x80000000)) 58 | { 59 | g2 <<= 1; 60 | v2 <<= 1; 61 | } 62 | 63 | g2 <<= 1; 64 | v2 <<= 1; 65 | 66 | g0 ^= g2; 67 | v0 ^= v2; 68 | 69 | while (g0 != 1) 70 | { 71 | if (g1 < g0 || ((g0^g1) < g0 && (g0^g1) < g1)) 72 | { 73 | CRYPTOPP_ASSERT(BitPrecision(g1) <= BitPrecision(g0)); 74 | g2 = g1; 75 | v2 = v1; 76 | } 77 | else 78 | { 79 | CRYPTOPP_ASSERT(BitPrecision(g1) > BitPrecision(g0)); 80 | g2 = g0; g0 = g1; g1 = g2; 81 | v2 = v0; v0 = v1; v1 = v2; 82 | } 83 | 84 | while ((g0^g2) >= g2) 85 | { 86 | CRYPTOPP_ASSERT(BitPrecision(g0) > BitPrecision(g2)); 87 | g2 <<= 1; 88 | v2 <<= 1; 89 | } 90 | 91 | CRYPTOPP_ASSERT(BitPrecision(g0) == BitPrecision(g2)); 92 | g0 ^= g2; 93 | v0 ^= v2; 94 | } 95 | 96 | return v0; 97 | } 98 | 99 | NAMESPACE_END 100 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/gf2_32.h: -------------------------------------------------------------------------------- 1 | // gf2_32.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file gf2_32.h 4 | /// \brief Classes and functions for schemes over GF(2^32) 5 | 6 | #ifndef CRYPTOPP_GF2_32_H 7 | #define CRYPTOPP_GF2_32_H 8 | 9 | #include "cryptlib.h" 10 | #include "secblock.h" 11 | #include "misc.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief GF(2^32) with polynomial basis 16 | class GF2_32 17 | { 18 | public: 19 | typedef word32 Element; 20 | typedef int RandomizationParameter; 21 | 22 | GF2_32(word32 modulus=0x0000008D) : m_modulus(modulus) {} 23 | 24 | Element RandomElement(RandomNumberGenerator &rng, int ignored = 0) const 25 | {CRYPTOPP_UNUSED(ignored); return rng.GenerateWord32();} 26 | 27 | bool Equal(Element a, Element b) const 28 | {return a==b;} 29 | 30 | Element Identity() const 31 | {return 0;} 32 | 33 | Element Add(Element a, Element b) const 34 | {return a^b;} 35 | 36 | Element& Accumulate(Element &a, Element b) const 37 | {return a^=b;} 38 | 39 | Element Inverse(Element a) const 40 | {return a;} 41 | 42 | Element Subtract(Element a, Element b) const 43 | {return a^b;} 44 | 45 | Element& Reduce(Element &a, Element b) const 46 | {return a^=b;} 47 | 48 | Element Double(Element a) const 49 | {CRYPTOPP_UNUSED(a); return 0;} 50 | 51 | Element MultiplicativeIdentity() const 52 | {return 1;} 53 | 54 | Element Multiply(Element a, Element b) const; 55 | 56 | Element Square(Element a) const 57 | {return Multiply(a, a);} 58 | 59 | bool IsUnit(Element a) const 60 | {return a != 0;} 61 | 62 | Element MultiplicativeInverse(Element a) const; 63 | 64 | Element Divide(Element a, Element b) const 65 | {return Multiply(a, MultiplicativeInverse(b));} 66 | 67 | private: 68 | word32 m_modulus; 69 | }; 70 | 71 | NAMESPACE_END 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/gost.h: -------------------------------------------------------------------------------- 1 | // gost.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file gost.h 4 | /// \brief Classes for the GIST block cipher 5 | 6 | #ifndef CRYPTOPP_GOST_H 7 | #define CRYPTOPP_GOST_H 8 | 9 | #include "seckey.h" 10 | #include "secblock.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | /// \brief GOST block cipher information 15 | /// \since Crypto++ 2.1 16 | struct GOST_Info : public FixedBlockSize<8>, public FixedKeyLength<32> 17 | { 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "GOST";} 19 | }; 20 | 21 | /// \brief GOST block cipher 22 | /// \sa GOST 23 | /// \since Crypto++ 2.1 24 | class GOST : public GOST_Info, public BlockCipherDocumentation 25 | { 26 | /// \brief GOST block cipher default operation 27 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 28 | { 29 | public: 30 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 31 | 32 | protected: 33 | static void PrecalculateSTable(); 34 | 35 | static const byte sBox[8][16]; 36 | static volatile bool sTableCalculated; 37 | static word32 sTable[4][256]; 38 | 39 | FixedSizeSecBlock m_key; 40 | }; 41 | 42 | /// \brief GOST block cipher encryption operation 43 | class CRYPTOPP_NO_VTABLE Enc : public Base 44 | { 45 | public: 46 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 47 | }; 48 | 49 | /// \brief GOST block cipher decryption operation 50 | class CRYPTOPP_NO_VTABLE Dec : public Base 51 | { 52 | public: 53 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 54 | }; 55 | 56 | public: 57 | typedef BlockCipherFinal Encryption; 58 | typedef BlockCipherFinal Decryption; 59 | }; 60 | 61 | typedef GOST::Encryption GOSTEncryption; 62 | typedef GOST::Decryption GOSTDecryption; 63 | 64 | NAMESPACE_END 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/hashfwd.h: -------------------------------------------------------------------------------- 1 | // hashfwd.h - written and placed in the public domain by Jeffrey Walton 2 | 3 | /// \file hashfwd.h 4 | /// \brief Forward declarations for hash functions used in signature encoding methods 5 | 6 | #ifndef CRYPTOPP_HASHFWD_H 7 | #define CRYPTOPP_HASHFWD_H 8 | 9 | #include "config.h" 10 | 11 | NAMESPACE_BEGIN(CryptoPP) 12 | 13 | class SHA1; 14 | class SHA224; 15 | class SHA256; 16 | class SHA384; 17 | class SHA512; 18 | 19 | class SHA3_256; 20 | class SHA3_384; 21 | class SHA3_512; 22 | 23 | class SHAKE128; 24 | class SHAKE256; 25 | 26 | class Tiger; 27 | class RIPEMD128; 28 | class RIPEMD160; 29 | class Whirlpool; 30 | 31 | namespace Weak1 { 32 | class MD2; 33 | class MD5; 34 | } 35 | 36 | NAMESPACE_END 37 | 38 | #endif // CRYPTOPP_HASHFWD_H 39 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/hc128.h: -------------------------------------------------------------------------------- 1 | // hc128.h - written and placed in the public domain by Jeffrey Walton 2 | // based on public domain code by Hongjun Wu. 3 | // 4 | // The reference materials and source files are available at 5 | // The eSTREAM Project, http://www.ecrypt.eu.org/stream/e2-hc128.html. 6 | 7 | /// \file hc128.h 8 | /// \brief Classes for HC-128 stream cipher 9 | /// \sa The 10 | /// eSTREAM Project | HC-128 and 11 | /// Crypto++ Wiki | HC-128. 12 | /// \since Crypto++ 8.0 13 | 14 | #ifndef CRYPTOPP_HC128_H 15 | #define CRYPTOPP_HC128_H 16 | 17 | #include "strciphr.h" 18 | #include "secblock.h" 19 | 20 | NAMESPACE_BEGIN(CryptoPP) 21 | 22 | /// \brief HC-128 stream cipher information 23 | /// \since Crypto++ 8.0 24 | struct HC128Info : public FixedKeyLength<16, SimpleKeyingInterface::UNIQUE_IV, 16> 25 | { 26 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "HC-128"; } 27 | }; 28 | 29 | /// \brief HC-128 stream cipher implementation 30 | /// \since Crypto++ 8.0 31 | class HC128Policy : public AdditiveCipherConcretePolicy, public HC128Info 32 | { 33 | protected: 34 | void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); 35 | void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); 36 | void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length); 37 | bool CanOperateKeystream() const { return true; } 38 | bool CipherIsRandomAccess() const { return false; } 39 | 40 | void GenerateKeystream(word32* keystream); 41 | void SetupUpdate(); 42 | 43 | private: 44 | FixedSizeSecBlock m_X; 45 | FixedSizeSecBlock m_Y; 46 | FixedSizeSecBlock m_key; 47 | FixedSizeSecBlock m_iv; 48 | word32 m_T[1024]; 49 | word32 m_ctr; 50 | }; 51 | 52 | /// \brief HC-128 stream cipher 53 | /// \details HC-128 is a stream cipher developed by Hongjun Wu. HC-128 is one of the 54 | /// final four Profile 1 (software) ciphers selected for the eSTREAM portfolio. 55 | /// \sa The 56 | /// eSTREAM Project | HC-128 and 57 | /// Crypto++ Wiki | HC-128. 58 | /// \since Crypto++ 8.0 59 | struct HC128 : public HC128Info, public SymmetricCipherDocumentation 60 | { 61 | typedef SymmetricCipherFinal >, HC128Info> Encryption; 62 | typedef Encryption Decryption; 63 | }; 64 | 65 | NAMESPACE_END 66 | 67 | #endif // CRYPTOPP_HC128_H 68 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/hc256.h: -------------------------------------------------------------------------------- 1 | // hc256.h - written and placed in the public domain by Jeffrey Walton 2 | // based on public domain code by Hongjun Wu. 3 | // 4 | // The reference materials and source files are available at 5 | // The eSTREAM Project, http://www.ecrypt.eu.org/stream/hc256.html. 6 | 7 | /// \file hc256.h 8 | /// \brief Classes for HC-256 stream cipher 9 | /// \sa The 10 | /// eSTREAM Project | HC-256 and 11 | /// Crypto++ Wiki | HC-128. 12 | /// \since Crypto++ 8.0 13 | 14 | #ifndef CRYPTOPP_HC256_H 15 | #define CRYPTOPP_HC256_H 16 | 17 | #include "strciphr.h" 18 | #include "secblock.h" 19 | 20 | NAMESPACE_BEGIN(CryptoPP) 21 | 22 | /// \brief HC-256 stream cipher information 23 | /// \since Crypto++ 8.0 24 | struct HC256Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 32> 25 | { 26 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "HC-256"; } 27 | }; 28 | 29 | /// \brief HC-256 stream cipher implementation 30 | /// \since Crypto++ 8.0 31 | class HC256Policy : public AdditiveCipherConcretePolicy, public HC256Info 32 | { 33 | protected: 34 | void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); 35 | void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); 36 | void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length); 37 | bool CanOperateKeystream() const { return true; } 38 | bool CipherIsRandomAccess() const { return false; } 39 | 40 | word32 H1(word32 u); 41 | word32 H2(word32 u); 42 | word32 Generate(); 43 | 44 | private: 45 | FixedSizeSecBlock m_key; 46 | FixedSizeSecBlock m_iv; 47 | word32 m_P[1024]; 48 | word32 m_Q[1024]; 49 | word32 m_ctr; 50 | }; 51 | 52 | /// \brief HC-256 stream cipher 53 | /// \details HC-256 is a stream cipher developed by Hongjun Wu. HC-256 is the 54 | /// successor to HC-128 from the eSTREAM project. 55 | /// \sa The 56 | /// eSTREAM Project | HC-256 and 57 | /// Crypto++ Wiki | HC-128. 58 | /// \since Crypto++ 8.0 59 | struct HC256 : public HC256Info, public SymmetricCipherDocumentation 60 | { 61 | typedef SymmetricCipherFinal >, HC256Info> Encryption; 62 | typedef Encryption Decryption; 63 | }; 64 | 65 | NAMESPACE_END 66 | 67 | #endif // CRYPTOPP_HC256_H 68 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/hex.cpp: -------------------------------------------------------------------------------- 1 | // hex.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | 5 | #ifndef CRYPTOPP_IMPORTS 6 | 7 | #include "hex.h" 8 | 9 | NAMESPACE_BEGIN(CryptoPP) 10 | ANONYMOUS_NAMESPACE_BEGIN 11 | 12 | const byte s_vecUpper[] = "0123456789ABCDEF"; 13 | const byte s_vecLower[] = "0123456789abcdef"; 14 | const int s_array[256] = { 15 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 16 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 17 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 18 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, 19 | -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, 20 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 21 | -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 23 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 25 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 27 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 28 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 29 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 30 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 31 | }; 32 | 33 | ANONYMOUS_NAMESPACE_END 34 | 35 | void HexEncoder::IsolatedInitialize(const NameValuePairs ¶meters) 36 | { 37 | bool uppercase = parameters.GetValueWithDefault(Name::Uppercase(), true); 38 | m_filter->Initialize(CombinedNameValuePairs( 39 | parameters, 40 | MakeParameters(Name::EncodingLookupArray(), uppercase ? &s_vecUpper[0] : &s_vecLower[0], false)(Name::Log2Base(), 4, true))); 41 | } 42 | 43 | void HexDecoder::IsolatedInitialize(const NameValuePairs ¶meters) 44 | { 45 | BaseN_Decoder::IsolatedInitialize(CombinedNameValuePairs( 46 | parameters, 47 | MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 4, true))); 48 | } 49 | 50 | // Unrolled initialization, http://github.com/weidai11/cryptopp/issues/376 51 | const int *HexDecoder::GetDefaultDecodingLookupArray() 52 | { 53 | return s_array; 54 | } 55 | 56 | NAMESPACE_END 57 | 58 | #endif // CRYPTOPP_IMPORTS 59 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/hex.h: -------------------------------------------------------------------------------- 1 | // hex.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file hex.h 4 | /// \brief Classes for HexEncoder and HexDecoder 5 | 6 | #ifndef CRYPTOPP_HEX_H 7 | #define CRYPTOPP_HEX_H 8 | 9 | #include "cryptlib.h" 10 | #include "basecode.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | /// \brief Converts given data to base 16 15 | class CRYPTOPP_DLL HexEncoder : public SimpleProxyFilter 16 | { 17 | public: 18 | /// \brief Construct a HexEncoder 19 | /// \param attachment a BufferedTrasformation to attach to this object 20 | /// \param uppercase a flag indicating uppercase output 21 | /// \param groupSize the size of the output grouping 22 | /// \param separator the separator to use between groups 23 | /// \param terminator the terminator append after processing 24 | HexEncoder(BufferedTransformation *attachment = NULLPTR, bool uppercase = true, int groupSize = 0, const std::string &separator = ":", const std::string &terminator = "") 25 | : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment) 26 | { 27 | IsolatedInitialize(MakeParameters(Name::Uppercase(), uppercase)(Name::GroupSize(), groupSize)(Name::Separator(), ConstByteArrayParameter(separator))(Name::Terminator(), ConstByteArrayParameter(terminator))); 28 | } 29 | 30 | void IsolatedInitialize(const NameValuePairs ¶meters); 31 | }; 32 | 33 | /// \brief Decode base 16 data back to bytes 34 | class CRYPTOPP_DLL HexDecoder : public BaseN_Decoder 35 | { 36 | public: 37 | /// \brief Construct a HexDecoder 38 | /// \param attachment a BufferedTrasformation to attach to this object 39 | HexDecoder(BufferedTransformation *attachment = NULLPTR) 40 | : BaseN_Decoder(GetDefaultDecodingLookupArray(), 4, attachment) {} 41 | 42 | void IsolatedInitialize(const NameValuePairs ¶meters); 43 | 44 | private: 45 | static const int * CRYPTOPP_API GetDefaultDecodingLookupArray(); 46 | }; 47 | 48 | NAMESPACE_END 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/hight.h: -------------------------------------------------------------------------------- 1 | // hight.h - written and placed in the public domain by Kim Sung Hee and Jeffrey Walton 2 | // Based on "HIGHT: A New Block Cipher Suitable for Low-Resource Device" 3 | // by Deukjo Hong, Jaechul Sung, Seokhie Hong, Jongin Lim, Sangjin Lee, 4 | // Bon-Seok Koo, Changhoon Lee, Donghoon Chang, Jesang Lee, Kitae Jeong, 5 | // Hyun Kim, Jongsung Kim, and Seongtaek Chee 6 | 7 | /// \file hight.h 8 | /// \brief Classes for the HIGHT block cipher 9 | /// \since Crypto++ 8.0 10 | 11 | #ifndef CRYPTOPP_HIGHT_H 12 | #define CRYPTOPP_HIGHT_H 13 | 14 | #include "config.h" 15 | #include "seckey.h" 16 | #include "secblock.h" 17 | #include "algparam.h" 18 | 19 | NAMESPACE_BEGIN(CryptoPP) 20 | 21 | /// \brief HIGHT block cipher information 22 | /// \since Crypto++ 8.0 23 | struct HIGHT_Info : public FixedBlockSize<8>, public FixedKeyLength<16> 24 | { 25 | static const std::string StaticAlgorithmName() 26 | { 27 | // Format is Cipher-Blocksize 28 | return "HIGHT"; 29 | } 30 | }; 31 | 32 | /// \brief HIGHT 64-bit block cipher 33 | /// \details HIGHT provides 64-bit block size. The valid key size is 128-bits. 34 | /// \note Crypto++ provides a byte oriented implementation 35 | /// \sa HIGHT, 36 | /// Korea Internet & Security 37 | /// Agency website 38 | /// \since Crypto++ 8.0 39 | class CRYPTOPP_NO_VTABLE HIGHT : public HIGHT_Info, public BlockCipherDocumentation 40 | { 41 | public: 42 | /// \brief HIGHT block cipher transformation functions 43 | /// \details Provides implementation common to encryption and decryption 44 | /// \since Crypto++ 8.0 45 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 46 | { 47 | protected: 48 | void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms); 49 | 50 | FixedSizeSecBlock m_rkey; 51 | mutable FixedSizeSecBlock m_xx; 52 | }; 53 | 54 | /// \brief Encryption transformation 55 | /// \details Enc provides implementation for encryption transformation. 56 | /// \since Crypto++ 8.0 57 | class CRYPTOPP_NO_VTABLE Enc : public Base 58 | { 59 | public: 60 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 61 | }; 62 | 63 | /// \brief Decryption transformation 64 | /// \details Dec provides implementation for decryption transformation. 65 | /// \since Crypto++ 8.0 66 | class CRYPTOPP_NO_VTABLE Dec : public Base 67 | { 68 | public: 69 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 70 | }; 71 | 72 | typedef BlockCipherFinal Encryption; 73 | typedef BlockCipherFinal Decryption; 74 | }; 75 | 76 | typedef HIGHT::Encryption HIGHTEncryption; 77 | typedef HIGHT::Decryption HIGHTDecryption; 78 | 79 | NAMESPACE_END 80 | 81 | #endif // CRYPTOPP_HIGHT_H 82 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/hmac.cpp: -------------------------------------------------------------------------------- 1 | // hmac.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | 5 | #ifndef CRYPTOPP_IMPORTS 6 | 7 | #include "hmac.h" 8 | 9 | NAMESPACE_BEGIN(CryptoPP) 10 | 11 | void HMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &) 12 | { 13 | AssertValidKeyLength(keylength); 14 | 15 | Restart(); 16 | 17 | HashTransformation &hash = AccessHash(); 18 | unsigned int blockSize = hash.BlockSize(); 19 | 20 | if (!blockSize) 21 | throw InvalidArgument("HMAC: can only be used with a block-based hash function"); 22 | 23 | m_buf.resize(2*AccessHash().BlockSize() + AccessHash().DigestSize()); 24 | 25 | if (keylength <= blockSize) 26 | { 27 | // hmac.cpp:26:9: runtime error: null pointer passed as argument 2 28 | if (AccessIpad() && userKey && keylength) 29 | memcpy(AccessIpad(), userKey, keylength); 30 | } 31 | else 32 | { 33 | AccessHash().CalculateDigest(AccessIpad(), userKey, keylength); 34 | keylength = hash.DigestSize(); 35 | } 36 | 37 | CRYPTOPP_ASSERT(keylength <= blockSize); 38 | memset(AccessIpad()+keylength, 0, blockSize-keylength); 39 | 40 | for (unsigned int i=0; i, public MessageAuthenticationCode 18 | { 19 | public: 20 | virtual ~HMAC_Base() {} 21 | 22 | /// \brief Construct a HMAC_Base 23 | HMAC_Base() : m_innerHashKeyed(false) {} 24 | void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms); 25 | 26 | void Restart(); 27 | void Update(const byte *input, size_t length); 28 | void TruncatedFinal(byte *mac, size_t size); 29 | unsigned int OptimalBlockSize() const {return const_cast(this)->AccessHash().OptimalBlockSize();} 30 | unsigned int DigestSize() const {return const_cast(this)->AccessHash().DigestSize();} 31 | 32 | protected: 33 | virtual HashTransformation & AccessHash() =0; 34 | byte * AccessIpad() {return m_buf;} 35 | byte * AccessOpad() {return m_buf + AccessHash().BlockSize();} 36 | byte * AccessInnerHash() {return m_buf + 2*AccessHash().BlockSize();} 37 | 38 | private: 39 | void KeyInnerHash(); 40 | 41 | SecByteBlock m_buf; 42 | bool m_innerHashKeyed; 43 | }; 44 | 45 | /// \brief HMAC 46 | /// \tparam T HashTransformation derived class 47 | /// \details HMAC derives from MessageAuthenticationCodeImpl. It calculates the HMAC using 48 | /// HMAC(K, text) = H(K XOR opad, H(K XOR ipad, text)). 49 | /// \sa HMAC 50 | /// \since Crypto++ 2.1 51 | template 52 | class HMAC : public MessageAuthenticationCodeImpl > 53 | { 54 | public: 55 | CRYPTOPP_CONSTANT(DIGESTSIZE=T::DIGESTSIZE); 56 | CRYPTOPP_CONSTANT(BLOCKSIZE=T::BLOCKSIZE); 57 | 58 | virtual ~HMAC() {} 59 | 60 | /// \brief Construct a HMAC 61 | HMAC() {} 62 | /// \brief Construct a HMAC 63 | /// \param key the HMAC key 64 | /// \param length the size of the HMAC key 65 | HMAC(const byte *key, size_t length=HMAC_Base::DEFAULT_KEYLENGTH) 66 | {this->SetKey(key, length);} 67 | 68 | static std::string StaticAlgorithmName() {return std::string("HMAC(") + T::StaticAlgorithmName() + ")";} 69 | std::string AlgorithmName() const {return std::string("HMAC(") + m_hash.AlgorithmName() + ")";} 70 | std::string AlgorithmProvider() const {return m_hash.AlgorithmProvider();} 71 | 72 | private: 73 | HashTransformation & AccessHash() {return m_hash;} 74 | 75 | T m_hash; 76 | }; 77 | 78 | NAMESPACE_END 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/idea.h: -------------------------------------------------------------------------------- 1 | // idea.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file idea.h 4 | /// \brief Classes for the IDEA block cipher 5 | 6 | #ifndef CRYPTOPP_IDEA_H 7 | #define CRYPTOPP_IDEA_H 8 | 9 | #include "seckey.h" 10 | #include "secblock.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | /// \brief IDEA block cipher information 15 | /// \since Crypto++ 1.0 16 | struct IDEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public FixedRounds<8> 17 | { 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "IDEA";} 19 | }; 20 | 21 | /// \brief IDEA block cipher 22 | /// \sa IDEA 23 | /// \since Crypto++ 1.0 24 | class IDEA : public IDEA_Info, public BlockCipherDocumentation 25 | { 26 | public: // made public for internal purposes 27 | #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE 28 | typedef word Word; 29 | #else 30 | typedef hword Word; 31 | #endif 32 | 33 | private: 34 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 35 | { 36 | public: 37 | unsigned int OptimalDataAlignment() const {return 2;} 38 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 39 | 40 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 41 | 42 | private: 43 | void EnKey(const byte *); 44 | void DeKey(); 45 | FixedSizeSecBlock m_key; 46 | 47 | #ifdef IDEA_LARGECACHE 48 | static inline void LookupMUL(word &a, word b); 49 | void LookupKeyLogs(); 50 | static void BuildLogTables(); 51 | static volatile bool tablesBuilt; 52 | static word16 log[0x10000], antilog[0x10000]; 53 | #endif 54 | }; 55 | 56 | public: 57 | typedef BlockCipherFinal Encryption; 58 | typedef BlockCipherFinal Decryption; 59 | }; 60 | 61 | typedef IDEA::Encryption IDEAEncryption; 62 | typedef IDEA::Decryption IDEADecryption; 63 | 64 | NAMESPACE_END 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/keccak.cpp: -------------------------------------------------------------------------------- 1 | // keccak.cpp - modified by Wei Dai from Ronny Van Keer's public domain 2 | // sha3-simple.c. All modifications here are placed in the 3 | // public domain by Wei Dai. 4 | // Keccack core function moved to keccakc.cpp in AUG 2018 5 | // by Jeffrey Walton. Separating the core file allows both 6 | // SHA3 and Keccack to share the core implementation. 7 | 8 | /* 9 | The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, 10 | Michael Peeters and Gilles Van Assche. For more information, feedback or 11 | questions, please refer to our website: http://keccak.noekeon.org/ 12 | 13 | Implementation by Ronny Van Keer, hereby denoted as "the implementer". 14 | 15 | To the extent possible under law, the implementer has waived all copyright 16 | and related or neighboring rights to the source code in this file. 17 | http://creativecommons.org/publicdomain/zero/1.0/ 18 | */ 19 | 20 | #include "pch.h" 21 | #include "keccak.h" 22 | 23 | NAMESPACE_BEGIN(CryptoPP) 24 | 25 | // The Keccak core function 26 | extern void KeccakF1600(word64 *state); 27 | 28 | void Keccak::Update(const byte *input, size_t length) 29 | { 30 | CRYPTOPP_ASSERT(!(input == NULLPTR && length != 0)); 31 | if (length == 0) { return; } 32 | 33 | size_t spaceLeft; 34 | while (length >= (spaceLeft = r() - m_counter)) 35 | { 36 | if (spaceLeft) 37 | xorbuf(m_state.BytePtr() + m_counter, input, spaceLeft); 38 | KeccakF1600(m_state); 39 | input += spaceLeft; 40 | length -= spaceLeft; 41 | m_counter = 0; 42 | } 43 | 44 | if (length) 45 | xorbuf(m_state.BytePtr() + m_counter, input, length); 46 | m_counter += (unsigned int)length; 47 | } 48 | 49 | void Keccak::Restart() 50 | { 51 | memset(m_state, 0, m_state.SizeInBytes()); 52 | m_counter = 0; 53 | } 54 | 55 | void Keccak::TruncatedFinal(byte *hash, size_t size) 56 | { 57 | CRYPTOPP_ASSERT(hash != NULLPTR); 58 | ThrowIfInvalidTruncatedSize(size); 59 | 60 | m_state.BytePtr()[m_counter] ^= 0x01; 61 | m_state.BytePtr()[r()-1] ^= 0x80; 62 | KeccakF1600(m_state); 63 | std::memcpy(hash, m_state, size); 64 | Restart(); 65 | } 66 | 67 | NAMESPACE_END 68 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/mars.h: -------------------------------------------------------------------------------- 1 | // mars.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file mars.h 4 | /// \brief Classes for the MARS block cipher (IBM AES submission) 5 | /// \since Crypto++ 3.0 6 | 7 | #ifndef CRYPTOPP_MARS_H 8 | #define CRYPTOPP_MARS_H 9 | 10 | #include "seckey.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief MARS block cipher information 16 | /// \since Crypto++ 3.0 17 | struct MARS_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 56, 8> 18 | { 19 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "MARS";} 20 | }; 21 | 22 | /// \brief MARS block cipher 23 | /// \sa MARS 24 | /// \since Crypto++ 3.0 25 | class MARS : public MARS_Info, public BlockCipherDocumentation 26 | { 27 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 28 | { 29 | public: 30 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 31 | 32 | protected: 33 | static const word32 Sbox[512]; 34 | 35 | FixedSizeSecBlock m_k; 36 | }; 37 | 38 | class CRYPTOPP_NO_VTABLE Enc : public Base 39 | { 40 | public: 41 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 42 | }; 43 | 44 | class CRYPTOPP_NO_VTABLE Dec : public Base 45 | { 46 | public: 47 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 48 | }; 49 | 50 | public: 51 | typedef BlockCipherFinal Encryption; 52 | typedef BlockCipherFinal Decryption; 53 | }; 54 | 55 | typedef MARS::Encryption MARSEncryption; 56 | typedef MARS::Decryption MARSDecryption; 57 | 58 | NAMESPACE_END 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/md2.h: -------------------------------------------------------------------------------- 1 | // md2.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file md2.h 4 | /// \brief Classes for the MD2 message digest 5 | /// \since Crypto++ 3.0 6 | 7 | #ifndef CRYPTOPP_MD2_H 8 | #define CRYPTOPP_MD2_H 9 | 10 | #include "cryptlib.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | namespace Weak1 { 16 | 17 | /// \brief MD2 message digest 18 | /// \sa MD2 19 | /// \since Crypto++ 3.0 20 | class MD2 : public HashTransformation 21 | { 22 | public: 23 | MD2(); 24 | void Update(const byte *input, size_t length); 25 | void TruncatedFinal(byte *hash, size_t size); 26 | unsigned int DigestSize() const {return DIGESTSIZE;} 27 | unsigned int BlockSize() const {return BLOCKSIZE;} 28 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "MD2";} 29 | 30 | CRYPTOPP_CONSTANT(DIGESTSIZE = 16); 31 | CRYPTOPP_CONSTANT(BLOCKSIZE = 16); 32 | 33 | private: 34 | void Transform(); 35 | void Init(); 36 | SecByteBlock m_X, m_C, m_buf; 37 | unsigned int m_count; 38 | }; 39 | 40 | } 41 | #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1 42 | namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak 43 | #else 44 | using namespace Weak1; // import Weak1 into CryptoPP with warning 45 | #ifdef __GNUC__ 46 | #warning "You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning." 47 | #else 48 | #pragma message("You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning.") 49 | #endif 50 | #endif 51 | 52 | NAMESPACE_END 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/md4.cpp: -------------------------------------------------------------------------------- 1 | // md4.cpp - modified by Wei Dai from Andrew M. Kuchling's md4.c 2 | // The original code and all modifications are in the public domain. 3 | 4 | // This is the original introductory comment: 5 | 6 | /* 7 | * md4.c : MD4 hash algorithm. 8 | * 9 | * Part of the Python Cryptography Toolkit, version 1.1 10 | * 11 | * Distribute and use freely; there are no restrictions on further 12 | * dissemination and usage except those imposed by the laws of your 13 | * country of residence. 14 | * 15 | */ 16 | 17 | #include "pch.h" 18 | #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 19 | #include "md4.h" 20 | #include "misc.h" 21 | 22 | NAMESPACE_BEGIN(CryptoPP) 23 | namespace Weak1 { 24 | 25 | void MD4::InitState(HashWordType *state) 26 | { 27 | state[0] = 0x67452301L; 28 | state[1] = 0xefcdab89L; 29 | state[2] = 0x98badcfeL; 30 | state[3] = 0x10325476L; 31 | } 32 | 33 | void MD4::Transform (word32 *digest, const word32 *in) 34 | { 35 | // #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 36 | #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) 37 | #define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) 38 | #define H(x, y, z) ((x) ^ (y) ^ (z)) 39 | 40 | word32 A, B, C, D; 41 | 42 | A=digest[0]; 43 | B=digest[1]; 44 | C=digest[2]; 45 | D=digest[3]; 46 | 47 | #define function(a,b,c,d,k,s) a=rotlVariable(a+F(b,c,d)+in[k],s); 48 | function(A,B,C,D, 0, 3); 49 | function(D,A,B,C, 1, 7); 50 | function(C,D,A,B, 2,11); 51 | function(B,C,D,A, 3,19); 52 | function(A,B,C,D, 4, 3); 53 | function(D,A,B,C, 5, 7); 54 | function(C,D,A,B, 6,11); 55 | function(B,C,D,A, 7,19); 56 | function(A,B,C,D, 8, 3); 57 | function(D,A,B,C, 9, 7); 58 | function(C,D,A,B,10,11); 59 | function(B,C,D,A,11,19); 60 | function(A,B,C,D,12, 3); 61 | function(D,A,B,C,13, 7); 62 | function(C,D,A,B,14,11); 63 | function(B,C,D,A,15,19); 64 | 65 | #undef function 66 | #define function(a,b,c,d,k,s) a=rotlVariable(a+G(b,c,d)+in[k]+0x5a827999,s); 67 | function(A,B,C,D, 0, 3); 68 | function(D,A,B,C, 4, 5); 69 | function(C,D,A,B, 8, 9); 70 | function(B,C,D,A,12,13); 71 | function(A,B,C,D, 1, 3); 72 | function(D,A,B,C, 5, 5); 73 | function(C,D,A,B, 9, 9); 74 | function(B,C,D,A,13,13); 75 | function(A,B,C,D, 2, 3); 76 | function(D,A,B,C, 6, 5); 77 | function(C,D,A,B,10, 9); 78 | function(B,C,D,A,14,13); 79 | function(A,B,C,D, 3, 3); 80 | function(D,A,B,C, 7, 5); 81 | function(C,D,A,B,11, 9); 82 | function(B,C,D,A,15,13); 83 | 84 | #undef function 85 | #define function(a,b,c,d,k,s) a=rotlVariable(a+H(b,c,d)+in[k]+0x6ed9eba1,s); 86 | function(A,B,C,D, 0, 3); 87 | function(D,A,B,C, 8, 9); 88 | function(C,D,A,B, 4,11); 89 | function(B,C,D,A,12,15); 90 | function(A,B,C,D, 2, 3); 91 | function(D,A,B,C,10, 9); 92 | function(C,D,A,B, 6,11); 93 | function(B,C,D,A,14,15); 94 | function(A,B,C,D, 1, 3); 95 | function(D,A,B,C, 9, 9); 96 | function(C,D,A,B, 5,11); 97 | function(B,C,D,A,13,15); 98 | function(A,B,C,D, 3, 3); 99 | function(D,A,B,C,11, 9); 100 | function(C,D,A,B, 7,11); 101 | function(B,C,D,A,15,15); 102 | 103 | digest[0]+=A; 104 | digest[1]+=B; 105 | digest[2]+=C; 106 | digest[3]+=D; 107 | } 108 | 109 | } 110 | NAMESPACE_END 111 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/md4.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_MD4_H 2 | #define CRYPTOPP_MD4_H 3 | 4 | #include "iterhash.h" 5 | 6 | NAMESPACE_BEGIN(CryptoPP) 7 | 8 | namespace Weak1 { 9 | 10 | /// MD4 11 | /*! \warning MD4 is considered insecure, and should not be used 12 | unless you absolutely need it for compatibility. */ 13 | class MD4 : public IteratedHashWithStaticTransform 14 | { 15 | public: 16 | static void InitState(HashWordType *state); 17 | static void Transform(word32 *digest, const word32 *data); 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "MD4";} 19 | }; 20 | 21 | } 22 | #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1 23 | namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak 24 | #else 25 | using namespace Weak1; // import Weak1 into CryptoPP with warning 26 | #ifdef __GNUC__ 27 | #warning "You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning." 28 | #else 29 | #pragma message("You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning.") 30 | #endif 31 | #endif 32 | 33 | NAMESPACE_END 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/md5.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_MD5_H 2 | #define CRYPTOPP_MD5_H 3 | 4 | #include "iterhash.h" 5 | 6 | NAMESPACE_BEGIN(CryptoPP) 7 | 8 | namespace Weak1 { 9 | 10 | /// \brief MD5 message digest 11 | /// \sa MD5 12 | /// \since Crypto++ 1.0 13 | class MD5 : public IteratedHashWithStaticTransform 14 | { 15 | public: 16 | static void InitState(HashWordType *state); 17 | static void Transform(word32 *digest, const word32 *data); 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "MD5";} 19 | }; 20 | 21 | } 22 | #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1 23 | namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak 24 | #else 25 | using namespace Weak1; // import Weak1 into CryptoPP with warning 26 | #ifdef __GNUC__ 27 | #warning "You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning." 28 | #else 29 | #pragma message("You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning.") 30 | #endif 31 | #endif 32 | 33 | NAMESPACE_END 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/mdc.h: -------------------------------------------------------------------------------- 1 | // mdc.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file mdc.h 4 | /// \brief Classes for the MDC message digest 5 | 6 | #ifndef CRYPTOPP_MDC_H 7 | #define CRYPTOPP_MDC_H 8 | 9 | #include "seckey.h" 10 | #include "secblock.h" 11 | #include "misc.h" 12 | 13 | // GCC cast warning 14 | #define HashWordPtr(x) ((HashWordType*)(void*)(x)) 15 | #define ConstHashWordPtr(x) ((const HashWordType*)(const void*)(x)) 16 | 17 | NAMESPACE_BEGIN(CryptoPP) 18 | 19 | /// \tparam B BlockCipher derived class 20 | /// \brief MDC_Info cipher information 21 | template 22 | struct MDC_Info : public FixedBlockSize, public FixedKeyLength 23 | { 24 | static std::string StaticAlgorithmName() {return std::string("MDC/")+B::StaticAlgorithmName();} 25 | }; 26 | 27 | /// \brief MDC cipher 28 | /// \tparam H HashTransformation derived class 29 | /// \details MDC() is a construction by Peter Gutmann to turn an iterated hash function into a PRF 30 | /// \sa MDC 31 | template 32 | class MDC : public MDC_Info 33 | { 34 | /// \brief MDC cipher encryption operation 35 | class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl > 36 | { 37 | typedef typename H::HashWordType HashWordType; 38 | 39 | public: 40 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms) 41 | { 42 | CRYPTOPP_UNUSED(params); 43 | this->AssertValidKeyLength(length); 44 | ConditionalByteReverse(BIG_ENDIAN_ORDER, Key(), ConstHashWordPtr(userKey), this->KEYLENGTH); 45 | } 46 | 47 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const 48 | { 49 | ConditionalByteReverse(BIG_ENDIAN_ORDER, Buffer(), ConstHashWordPtr(inBlock), this->BLOCKSIZE); 50 | H::Transform(Buffer(), Key()); 51 | 52 | if (xorBlock) 53 | { 54 | ConditionalByteReverse(BIG_ENDIAN_ORDER, Buffer(), Buffer(), this->BLOCKSIZE); 55 | xorbuf(outBlock, xorBlock, m_buffer, this->BLOCKSIZE); 56 | } 57 | else 58 | { 59 | ConditionalByteReverse(BIG_ENDIAN_ORDER, HashWordPtr(outBlock), Buffer(), this->BLOCKSIZE); 60 | } 61 | } 62 | 63 | bool IsPermutation() const {return false;} 64 | 65 | unsigned int OptimalDataAlignment() const {return sizeof(HashWordType);} 66 | 67 | private: 68 | HashWordType *Key() {return HashWordPtr(m_key.data());} 69 | const HashWordType *Key() const {return ConstHashWordPtr(m_key.data());} 70 | HashWordType *Buffer() const {return HashWordPtr(m_buffer.data());} 71 | 72 | // VC60 workaround: bug triggered if using FixedSizeAllocatorWithCleanup 73 | FixedSizeSecBlock::KEYLENGTH, AllocatorWithCleanup > m_key; 74 | mutable FixedSizeSecBlock::BLOCKSIZE, AllocatorWithCleanup > m_buffer; 75 | }; 76 | 77 | public: 78 | // use BlockCipher interface 79 | typedef BlockCipherFinal Encryption; 80 | }; 81 | 82 | NAMESPACE_END 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/modexppc.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_MODEXPPC_H 2 | #define CRYPTOPP_MODEXPPC_H 3 | 4 | #include "cryptlib.h" 5 | #include "modarith.h" 6 | #include "integer.h" 7 | #include "algebra.h" 8 | #include "eprecomp.h" 9 | #include "smartptr.h" 10 | #include "pubkey.h" 11 | 12 | #if CRYPTOPP_MSC_VERSION 13 | # pragma warning(push) 14 | # pragma warning(disable: 4231 4275) 15 | #endif 16 | 17 | NAMESPACE_BEGIN(CryptoPP) 18 | 19 | CRYPTOPP_DLL_TEMPLATE_CLASS DL_FixedBasePrecomputationImpl; 20 | 21 | class ModExpPrecomputation : public DL_GroupPrecomputation 22 | { 23 | public: 24 | virtual ~ModExpPrecomputation() {} 25 | 26 | // DL_GroupPrecomputation 27 | bool NeedConversions() const {return true;} 28 | Element ConvertIn(const Element &v) const {return m_mr->ConvertIn(v);} 29 | virtual Element ConvertOut(const Element &v) const {return m_mr->ConvertOut(v);} 30 | const AbstractGroup & GetGroup() const {return m_mr->MultiplicativeGroup();} 31 | Element BERDecodeElement(BufferedTransformation &bt) const {return Integer(bt);} 32 | void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {v.DEREncode(bt);} 33 | 34 | // non-inherited 35 | void SetModulus(const Integer &v) {m_mr.reset(new MontgomeryRepresentation(v));} 36 | const Integer & GetModulus() const {return m_mr->GetModulus();} 37 | 38 | private: 39 | value_ptr m_mr; 40 | }; 41 | 42 | NAMESPACE_END 43 | 44 | #if CRYPTOPP_MSC_VERSION 45 | # pragma warning(pop) 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/mqv.cpp: -------------------------------------------------------------------------------- 1 | // mqv.cpp - originally written and placed in the public domain by Wei Dai 2 | // HMQV provided by Jeffrey Walton, Ray Clayton and Uri Blumenthal. 3 | // FHMQV provided by Uri Blumenthal. 4 | 5 | #include "pch.h" 6 | #include "config.h" 7 | #include "mqv.h" 8 | #include "hmqv.h" 9 | #include "fhmqv.h" 10 | #include "eccrypto.h" 11 | 12 | // Squash MS LNK4221 and libtool warnings 13 | extern const char MQV_FNAME[] = __FILE__; 14 | 15 | NAMESPACE_BEGIN(CryptoPP) 16 | 17 | #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) 18 | void TestInstantiations_MQV() 19 | { 20 | MQV mqv; 21 | ECMQV ecmqv; 22 | 23 | CRYPTOPP_UNUSED(mqv); 24 | CRYPTOPP_UNUSED(ecmqv); 25 | } 26 | 27 | void TestInstantiations_HMQV() 28 | { 29 | HMQV hmqv; 30 | ECHMQV echmqv; 31 | 32 | CRYPTOPP_UNUSED(hmqv); 33 | CRYPTOPP_UNUSED(echmqv); 34 | } 35 | 36 | void TestInstantiations_FHMQV() 37 | { 38 | FHMQV fhmqv; 39 | ECFHMQV ecfhmqv; 40 | 41 | CRYPTOPP_UNUSED(fhmqv); 42 | CRYPTOPP_UNUSED(ecfhmqv); 43 | } 44 | #endif 45 | 46 | NAMESPACE_END 47 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/nr.h: -------------------------------------------------------------------------------- 1 | // nr.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file nr.h 4 | /// \brief Classes for Nyberg-Rueppel signature scheme 5 | 6 | #ifndef CRYPTOPP_NR_H 7 | #define CRYPTOPP_NR_H 8 | 9 | #include "gfpcrypt.h" 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/oaep.h: -------------------------------------------------------------------------------- 1 | // oaep.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file oaep.h 4 | /// \brief Classes for optimal asymmetric encryption padding 5 | /// \since Crypto++ 2.1 6 | 7 | #ifndef CRYPTOPP_OAEP_H 8 | #define CRYPTOPP_OAEP_H 9 | 10 | #include "cryptlib.h" 11 | #include "pubkey.h" 12 | #include "sha.h" 13 | 14 | NAMESPACE_BEGIN(CryptoPP) 15 | 16 | /// \brief OAEP padding base class 17 | /// \since Crypto++ 2.1 18 | class CRYPTOPP_DLL OAEP_Base : public PK_EncryptionMessageEncodingMethod 19 | { 20 | public: 21 | bool ParameterSupported(const char *name) const {return strcmp(name, Name::EncodingParameters()) == 0;} 22 | size_t MaxUnpaddedLength(size_t paddedLength) const; 23 | void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs ¶meters) const; 24 | DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs ¶meters) const; 25 | 26 | protected: 27 | virtual unsigned int DigestSize() const =0; 28 | virtual HashTransformation * NewHash() const =0; 29 | virtual MaskGeneratingFunction * NewMGF() const =0; 30 | }; 31 | 32 | /// \brief OAEP padding 33 | /// \tparam H HashTransformation derived class 34 | /// \tparam MGF MaskGeneratingFunction derived class 35 | /// \sa EME-OAEP, for use with classes derived from TF_ES 36 | /// \since Crypto++ 2.1 37 | template 38 | class OAEP : public OAEP_Base, public EncryptionStandard 39 | { 40 | public: 41 | static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string("OAEP-") + MGF::StaticAlgorithmName() + "(" + H::StaticAlgorithmName() + ")";} 42 | typedef OAEP EncryptionMessageEncodingMethod; 43 | 44 | protected: 45 | unsigned int DigestSize() const {return H::DIGESTSIZE;} 46 | HashTransformation * NewHash() const {return new H;} 47 | MaskGeneratingFunction * NewMGF() const {return new MGF;} 48 | }; 49 | 50 | CRYPTOPP_DLL_TEMPLATE_CLASS OAEP; 51 | 52 | NAMESPACE_END 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/padlkrng.cpp: -------------------------------------------------------------------------------- 1 | // via-rng.cpp - written and placed in public domain by Jeffrey Walton and Uri Blumenthal. 2 | 3 | #include "pch.h" 4 | #include "config.h" 5 | #include "cryptlib.h" 6 | #include "secblock.h" 7 | #include "padlkrng.h" 8 | #include "cpu.h" 9 | 10 | // The Padlock Security Engine RNG has a few items to be aware of. You can 11 | // find copies of the Programmer's manual, Cryptography Research Inc audit 12 | // report, and other goodies at http://www.cryptopp.com/wiki/VIA_Padlock. 13 | 14 | #if CRYPTOPP_MSC_VERSION 15 | # pragma warning(disable: 4702) 16 | #endif 17 | 18 | NAMESPACE_BEGIN(CryptoPP) 19 | 20 | std::string PadlockRNG::AlgorithmProvider() const 21 | { 22 | return "Padlock"; 23 | } 24 | 25 | PadlockRNG::PadlockRNG(word32 divisor) 26 | : m_divisor(DivisorHelper(divisor)), m_msr(0) 27 | { 28 | #if defined(CRYPTOPP_X86_ASM_AVAILABLE) 29 | if (!HasPadlockRNG()) 30 | #endif 31 | throw PadlockRNG_Err("PadlockRNG", "PadlockRNG generator not available"); 32 | } 33 | 34 | void PadlockRNG::GenerateBlock(byte *output, size_t size) 35 | { 36 | CRYPTOPP_UNUSED(output); CRYPTOPP_UNUSED(size); 37 | #if defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(__GNUC__) 38 | while (size) 39 | { 40 | __asm__ __volatile__ 41 | ( 42 | #if (CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) 43 | "mov %1, %%rdi ;\n" 44 | "movl %2, %%edx ;\n" 45 | #else 46 | "mov %1, %%edi ;\n" 47 | "movl %2, %%edx ;\n" 48 | #endif 49 | 50 | // xstore-rng 51 | ".byte 0x0f, 0xa7, 0xc0 ;\n" 52 | "movl %%eax, %0 ;\n" 53 | 54 | : "=g" (m_msr) : "g" (m_buffer.data()), "g" (m_divisor) 55 | #if (CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) 56 | : "rax", "rdx", "rdi", "cc" 57 | #else 58 | : "eax", "edx", "edi", "cc" 59 | #endif 60 | ); 61 | 62 | const size_t ret = m_msr & 0x1f; 63 | const size_t rem = STDMIN(ret, STDMIN(size, 16U /*buffer size*/)); 64 | std::memcpy(output, m_buffer, rem); 65 | size -= rem; output += rem; 66 | } 67 | #elif defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(_MSC_VER) && defined(_M_IX86) 68 | while (size) 69 | { 70 | word32 result, divisor = m_divisor; 71 | byte *buffer = reinterpret_cast(m_buffer.data()); 72 | __asm { 73 | mov edi, buffer 74 | mov edx, divisor 75 | _emit 0x0f 76 | _emit 0xa7 77 | _emit 0xc0 78 | mov result, eax 79 | } 80 | 81 | const size_t ret = (m_msr = result) & 0x1f; 82 | const size_t rem = STDMIN(ret, STDMIN(size, 16U /*buffer size*/)); 83 | std::memcpy(output, buffer, rem); 84 | size -= rem; output += rem; 85 | } 86 | #else 87 | throw PadlockRNG_Err("GenerateBlock", "PadlockRNG generator not available"); 88 | #endif // CRYPTOPP_X86_ASM_AVAILABLE 89 | } 90 | 91 | void PadlockRNG::DiscardBytes(size_t n) 92 | { 93 | FixedSizeSecBlock discard; 94 | n = RoundUpToMultipleOf(n, sizeof(word32)); 95 | 96 | size_t count = STDMIN(n, discard.SizeInBytes()); 97 | while (count) 98 | { 99 | GenerateBlock(discard.BytePtr(), count); 100 | n -= count; 101 | count = STDMIN(n, discard.SizeInBytes()); 102 | } 103 | } 104 | 105 | NAMESPACE_END 106 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/pch.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file pch.h 4 | /// \brief Precompiled header file 5 | /// \details The precompiled header files are used Windows. 6 | 7 | #ifndef CRYPTOPP_PCH_H 8 | #define CRYPTOPP_PCH_H 9 | 10 | # ifdef CRYPTOPP_GENERATE_X64_MASM 11 | #include "cpu.h" 12 | 13 | # else 14 | #include "config.h" 15 | 16 | #ifdef USE_PRECOMPILED_HEADERS 17 | #include "simple.h" 18 | #include "secblock.h" 19 | #include "misc.h" 20 | #include "smartptr.h" 21 | #include "stdcpp.h" 22 | #endif 23 | # endif 24 | 25 | // Enable file and line numbers, if available. 26 | // #if defined(_MSC_VER) && defined(_DEBUG) && defined(USE_PRECOMPILED_HEADERS) 27 | // # define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 28 | // # define new DEBUG_NEW 29 | // #endif 30 | 31 | #endif // CRYPTOPP_PCH_H 32 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/ppc_power7.cpp: -------------------------------------------------------------------------------- 1 | // ppc_power7.cpp - written and placed in the public domain by 2 | // Jeffrey Walton, Uri Blumenthal and Marcel Raad. 3 | // 4 | // This source file uses intrinsics and built-ins to gain access to 5 | // Power7 instructions. A separate source file is needed because 6 | // additional CXXFLAGS are required to enable the appropriate 7 | // instructions sets in some build configurations. 8 | 9 | #include "pch.h" 10 | #include "config.h" 11 | 12 | #ifdef CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY 13 | # include 14 | # include 15 | #endif 16 | 17 | #if defined(__ALTIVEC__) || defined(_ARCH_PWR7) 18 | # include "ppc_simd.h" 19 | #endif 20 | 21 | // Squash MS LNK4221 and libtool warnings 22 | extern const char PPC_POWER7_FNAME[] = __FILE__; 23 | 24 | NAMESPACE_BEGIN(CryptoPP) 25 | 26 | // ************************* Feature Probes ************************* // 27 | 28 | #ifdef CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY 29 | extern "C" { 30 | typedef void (*SigHandler)(int); 31 | 32 | static jmp_buf s_jmpSIGILL; 33 | static void SigIllHandler(int) 34 | { 35 | longjmp(s_jmpSIGILL, 1); 36 | } 37 | } 38 | #endif // CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY 39 | 40 | #if (CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64) 41 | bool CPU_ProbePower7() 42 | { 43 | #if defined(CRYPTOPP_NO_CPU_FEATURE_PROBES) 44 | return false; 45 | #elif defined(CRYPTOPP_POWER7_AVAILABLE) 46 | # if defined(CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY) 47 | 48 | // longjmp and clobber warnings. Volatile is required. 49 | // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854 50 | volatile int result = false; 51 | 52 | volatile SigHandler oldHandler = signal(SIGILL, SigIllHandler); 53 | if (oldHandler == SIG_ERR) 54 | return false; 55 | 56 | volatile sigset_t oldMask; 57 | if (sigprocmask(0, NULLPTR, (sigset_t*)&oldMask)) 58 | { 59 | signal(SIGILL, oldHandler); 60 | return false; 61 | } 62 | 63 | if (setjmp(s_jmpSIGILL)) 64 | result = false; 65 | else 66 | { 67 | // POWER7 added unaligned loads and store operations 68 | byte b1[19] = {255, 255, 255, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, b2[17]; 69 | 70 | // See comments in ppc_simd.h for some of these defines. 71 | #if defined(_AIX) && defined(_ARCH_PWR7) && ((__xlC__ & 0xff00) == 0x0c00) 72 | vec_xstw4(vec_xlw4(0, (unsigned int*)(b1+3)), 0, (unsigned int*)(b2+1)); 73 | result = (0 == std::memcmp(b1+3, b2+1, 16)); 74 | #elif defined(_ARCH_PWR7) && defined(__VSX__) 75 | vec_xst(vec_xl(0, (unsigned int*)(b1+3)), 0, (unsigned int*)(b2+1)); 76 | result = (0 == std::memcmp(b1+3, b2+1, 16)); 77 | #else 78 | result = false; 79 | #endif 80 | } 81 | 82 | sigprocmask(SIG_SETMASK, (sigset_t*)&oldMask, NULLPTR); 83 | signal(SIGILL, oldHandler); 84 | return result; 85 | # endif 86 | #else 87 | return false; 88 | #endif // _ARCH_PWR7 89 | } 90 | 91 | #endif // PPC32 or PPC64 92 | 93 | NAMESPACE_END 94 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/ppc_simd.cpp: -------------------------------------------------------------------------------- 1 | // ppc_simd.cpp - written and placed in the public domain by 2 | // Jeffrey Walton, Uri Blumenthal and Marcel Raad. 3 | // 4 | // This source file uses intrinsics to gain access to AltiVec, 5 | // Power8 and in-core crypto instructions. A separate source file 6 | // is needed because additional CXXFLAGS are required to enable the 7 | // appropriate instructions sets in some build configurations. 8 | 9 | #include "pch.h" 10 | #include "config.h" 11 | #include "stdcpp.h" 12 | 13 | #if defined(CRYPTOPP_ALTIVEC_AVAILABLE) 14 | # include "ppc_simd.h" 15 | #endif 16 | 17 | #ifdef CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY 18 | # include 19 | # include 20 | #endif 21 | 22 | #ifndef EXCEPTION_EXECUTE_HANDLER 23 | # define EXCEPTION_EXECUTE_HANDLER 1 24 | #endif 25 | 26 | // Squash MS LNK4221 and libtool warnings 27 | extern const char PPC_SIMD_FNAME[] = __FILE__; 28 | 29 | NAMESPACE_BEGIN(CryptoPP) 30 | 31 | #ifdef CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY 32 | extern "C" { 33 | typedef void (*SigHandler)(int); 34 | 35 | static jmp_buf s_jmpSIGILL; 36 | static void SigIllHandler(int) 37 | { 38 | longjmp(s_jmpSIGILL, 1); 39 | } 40 | } 41 | #endif // Not CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY 42 | 43 | #if (CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64) 44 | bool CPU_ProbeAltivec() 45 | { 46 | #if defined(CRYPTOPP_NO_CPU_FEATURE_PROBES) 47 | return false; 48 | #elif (_ARCH_PWR3) && (CRYPTOPP_ALTIVEC_AVAILABLE) 49 | # if defined(CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY) 50 | 51 | // longjmp and clobber warnings. Volatile is required. 52 | // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854 53 | volatile int result = true; 54 | 55 | volatile SigHandler oldHandler = signal(SIGILL, SigIllHandler); 56 | if (oldHandler == SIG_ERR) 57 | return false; 58 | 59 | volatile sigset_t oldMask; 60 | if (sigprocmask(0, NULLPTR, (sigset_t*)&oldMask)) 61 | { 62 | signal(SIGILL, oldHandler); 63 | return false; 64 | } 65 | 66 | if (setjmp(s_jmpSIGILL)) 67 | result = false; 68 | else 69 | { 70 | CRYPTOPP_ALIGN_DATA(16) 71 | const byte b1[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 72 | CRYPTOPP_ALIGN_DATA(16) 73 | const byte b2[16] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; 74 | CRYPTOPP_ALIGN_DATA(16) byte b3[16]; 75 | 76 | // Specifically call the Altivec loads and stores 77 | const uint8x16_p v1 = (uint8x16_p)vec_ld(0, (byte*)b1); 78 | const uint8x16_p v2 = (uint8x16_p)vec_ld(0, (byte*)b2); 79 | const uint8x16_p v3 = (uint8x16_p)VecXor(v1, v2); 80 | vec_st(v3, 0, b3); 81 | 82 | result = (0 == std::memcmp(b2, b3, 16)); 83 | } 84 | 85 | sigprocmask(SIG_SETMASK, (sigset_t*)&oldMask, NULLPTR); 86 | signal(SIGILL, oldHandler); 87 | return result; 88 | # endif 89 | #else 90 | return false; 91 | #endif // CRYPTOPP_ALTIVEC_AVAILABLE 92 | } 93 | 94 | # endif // CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64 95 | 96 | NAMESPACE_END 97 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/rc5.cpp: -------------------------------------------------------------------------------- 1 | // rc5.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | #include "rc5.h" 5 | #include "misc.h" 6 | #include "secblock.h" 7 | 8 | NAMESPACE_BEGIN(CryptoPP) 9 | 10 | void RC5::Base::UncheckedSetKey(const byte *k, unsigned int keylen, const NameValuePairs ¶ms) 11 | { 12 | AssertValidKeyLength(keylen); 13 | 14 | r = GetRoundsAndThrowIfInvalid(params, this); 15 | sTable.New(2*(r+1)); 16 | 17 | static const RC5_WORD MAGIC_P = 0xb7e15163L; // magic constant P for wordsize 18 | static const RC5_WORD MAGIC_Q = 0x9e3779b9L; // magic constant Q for wordsize 19 | static const int U=sizeof(RC5_WORD); 20 | 21 | const unsigned int c = STDMAX((keylen+U-1)/U, 1U); // RC6 paper says c=1 if keylen==0 22 | SecBlock l(c); 23 | 24 | GetUserKey(LITTLE_ENDIAN_ORDER, l.begin(), c, k, keylen); 25 | 26 | sTable[0] = MAGIC_P; 27 | for (unsigned j=1; j((sTable[h % sTable.size()] + a + b)); 36 | b = l[h % c] = rotlMod((l[h % c] + a + b), (a+b)); 37 | } 38 | } 39 | 40 | typedef BlockGetAndPut Block; 41 | 42 | void RC5::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const 43 | { 44 | const RC5_WORD *sptr = sTable; 45 | RC5_WORD a, b; 46 | 47 | Block::Get(inBlock)(a)(b); 48 | a += sptr[0]; 49 | b += sptr[1]; 50 | sptr += 2; 51 | 52 | for(unsigned i=0; i, public VariableKeyLength<16, 0, 255>, public VariableRounds<16> 17 | { 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "RC5";} 19 | typedef word32 RC5_WORD; 20 | }; 21 | 22 | /// \brief RC5 block cipher 23 | /// \sa RC5 24 | /// \since Crypto++ 1.0 25 | class RC5 : public RC5_Info, public BlockCipherDocumentation 26 | { 27 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 28 | { 29 | public: 30 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 31 | 32 | protected: 33 | unsigned int r; // number of rounds 34 | SecBlock sTable; // expanded key table 35 | }; 36 | 37 | class CRYPTOPP_NO_VTABLE Enc : public Base 38 | { 39 | public: 40 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 41 | }; 42 | 43 | class CRYPTOPP_NO_VTABLE Dec : public Base 44 | { 45 | public: 46 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 47 | }; 48 | 49 | public: 50 | typedef BlockCipherFinal Encryption; 51 | typedef BlockCipherFinal Decryption; 52 | }; 53 | 54 | typedef RC5::Encryption RC5Encryption; 55 | typedef RC5::Decryption RC5Decryption; 56 | 57 | NAMESPACE_END 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/rc6.cpp: -------------------------------------------------------------------------------- 1 | // rc6.cpp - written and placed in the public domain by Sean Woods 2 | // based on Wei Dai's RC5 code. 3 | 4 | #include "pch.h" 5 | #include "rc6.h" 6 | #include "misc.h" 7 | #include "secblock.h" 8 | 9 | NAMESPACE_BEGIN(CryptoPP) 10 | 11 | void RC6::Base::UncheckedSetKey(const byte *k, unsigned int keylen, const NameValuePairs ¶ms) 12 | { 13 | AssertValidKeyLength(keylen); 14 | 15 | r = GetRoundsAndThrowIfInvalid(params, this); 16 | sTable.New(2*(r+2)); 17 | 18 | static const RC6_WORD MAGIC_P = 0xb7e15163L; // magic constant P for wordsize 19 | static const RC6_WORD MAGIC_Q = 0x9e3779b9L; // magic constant Q for wordsize 20 | static const int U=sizeof(RC6_WORD); 21 | 22 | const unsigned int c = STDMAX((keylen+U-1)/U, 1U); // RC6 paper says c=1 if keylen==0 23 | SecBlock l(c); 24 | 25 | GetUserKey(LITTLE_ENDIAN_ORDER, l.begin(), c, k, keylen); 26 | 27 | sTable[0] = MAGIC_P; 28 | for (unsigned j=1; j((sTable[h % sTable.size()] + a + b)); 37 | b = l[h % c] = rotlMod((l[h % c] + a + b), (a+b)); 38 | } 39 | } 40 | 41 | typedef BlockGetAndPut Block; 42 | 43 | void RC6::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const 44 | { 45 | const RC6_WORD *sptr = sTable; 46 | RC6_WORD a, b, c, d, t, u; 47 | 48 | Block::Get(inBlock)(a)(b)(c)(d); 49 | b += sptr[0]; 50 | d += sptr[1]; 51 | sptr += 2; 52 | 53 | for(unsigned i=0; i(b*(2*b+1)); 56 | u = rotlConstant<5>(d*(2*d+1)); 57 | a = rotlMod(a^t,u) + sptr[0]; 58 | c = rotlMod(c^u,t) + sptr[1]; 59 | t = a; a = b; b = c; c = d; d = t; 60 | sptr += 2; 61 | } 62 | 63 | a += sptr[0]; 64 | c += sptr[1]; 65 | 66 | Block::Put(xorBlock, outBlock)(a)(b)(c)(d); 67 | } 68 | 69 | void RC6::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const 70 | { 71 | const RC6_WORD *sptr = sTable.end(); 72 | RC6_WORD a, b, c, d, t, u; 73 | 74 | Block::Get(inBlock)(a)(b)(c)(d); 75 | 76 | sptr -= 2; 77 | c -= sptr[1]; 78 | a -= sptr[0]; 79 | 80 | for (unsigned i=0; i < r; i++) 81 | { 82 | sptr -= 2; 83 | t = a; a = d; d = c; c = b; b = t; 84 | u = rotlConstant<5>(d*(2 * d + 1)); 85 | t = rotlConstant<5>(b*(2 * b + 1)); 86 | c = rotrMod(c-sptr[1], t) ^ u; 87 | a = rotrMod(a-sptr[0], u) ^ t; 88 | } 89 | 90 | d -= sTable[1]; 91 | b -= sTable[0]; 92 | 93 | Block::Put(xorBlock, outBlock)(a)(b)(c)(d); 94 | } 95 | 96 | NAMESPACE_END 97 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/rc6.h: -------------------------------------------------------------------------------- 1 | // rc6.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file rc6.h 4 | /// \brief Classes for the RC6 block cipher 5 | /// \since Crypto++ 3.0 6 | 7 | #ifndef CRYPTOPP_RC6_H 8 | #define CRYPTOPP_RC6_H 9 | 10 | #include "seckey.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief RC6 block cipher information 16 | /// \since Crypto++ 3.0 17 | struct RC6_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8>, public VariableRounds<20> 18 | { 19 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "RC6";} 20 | typedef word32 RC6_WORD; 21 | }; 22 | 23 | /// \brief RC6 block cipher 24 | /// \sa RC6 25 | /// \since Crypto++ 3.0 26 | class RC6 : public RC6_Info, public BlockCipherDocumentation 27 | { 28 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 29 | { 30 | public: 31 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 32 | 33 | protected: 34 | unsigned int r; // number of rounds 35 | SecBlock sTable; // expanded key table 36 | }; 37 | 38 | class CRYPTOPP_NO_VTABLE Enc : public Base 39 | { 40 | public: 41 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 42 | }; 43 | 44 | class CRYPTOPP_NO_VTABLE Dec : public Base 45 | { 46 | public: 47 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 48 | }; 49 | 50 | public: 51 | typedef BlockCipherFinal Encryption; 52 | typedef BlockCipherFinal Decryption; 53 | }; 54 | 55 | typedef RC6::Encryption RC6Encryption; 56 | typedef RC6::Decryption RC6Decryption; 57 | 58 | NAMESPACE_END 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/regtest4.cpp: -------------------------------------------------------------------------------- 1 | // regtest4.cpp - originally written and placed in the public domain by Wei Dai 2 | // regtest.cpp split into 3 files due to OOM kills by JW 3 | // in April 2017. A second split occurred in July 2018. 4 | 5 | #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 6 | 7 | #include "cryptlib.h" 8 | #include "factory.h" 9 | #include "bench.h" 10 | #include "cpu.h" 11 | 12 | #include "dh.h" 13 | #include "nr.h" 14 | #include "rw.h" 15 | #include "rsa.h" 16 | #include "dsa.h" 17 | #include "pssr.h" 18 | #include "esign.h" 19 | 20 | // Hashes 21 | #include "md2.h" 22 | #include "md5.h" 23 | #include "sha.h" 24 | 25 | // Aggressive stack checking with VS2005 SP1 and above. 26 | #if (_MSC_FULL_VER >= 140050727) 27 | # pragma strict_gs_check (on) 28 | #endif 29 | 30 | #if CRYPTOPP_MSC_VERSION 31 | # pragma warning(disable: 4505 4355) 32 | #endif 33 | 34 | USING_NAMESPACE(CryptoPP) 35 | 36 | void RegisterFactories5() 37 | { 38 | RegisterDefaultFactoryFor(); 39 | RegisterAsymmetricCipherDefaultFactories > >("RSA/OAEP-MGF1(SHA-1)"); 40 | RegisterAsymmetricCipherDefaultFactories >("DLIES(NoCofactorMultiplication, KDF2(SHA-1), XOR, HMAC(SHA-1), DHAES)"); 41 | RegisterSignatureSchemeDefaultFactories(); 42 | RegisterSignatureSchemeDefaultFactories >(); 43 | RegisterSignatureSchemeDefaultFactories >(); 44 | RegisterSignatureSchemeDefaultFactories >(); 45 | RegisterSignatureSchemeDefaultFactories >(); 46 | RegisterSignatureSchemeDefaultFactories >(); 47 | RegisterSignatureSchemeDefaultFactories >(); 48 | RegisterSignatureSchemeDefaultFactories >(); 49 | RegisterSignatureSchemeDefaultFactories >(); 50 | RegisterSignatureSchemeDefaultFactories >(); 51 | RegisterSignatureSchemeDefaultFactories >("NR(1363)/EMSA1(SHA-1)"); 52 | RegisterSignatureSchemeDefaultFactories >("DSA-1363/EMSA1(SHA-1)"); 53 | RegisterSignatureSchemeDefaultFactories >("RSA/PKCS1-1.5(MD2)"); 54 | RegisterSignatureSchemeDefaultFactories >("RSA/PKCS1-1.5(SHA-1)"); 55 | RegisterSignatureSchemeDefaultFactories >("ESIGN/EMSA5-MGF1(SHA-1)"); 56 | RegisterSignatureSchemeDefaultFactories >("RW/EMSA2(SHA-1)"); 57 | RegisterSignatureSchemeDefaultFactories >("RSA/PSS-MGF1(SHA-1)"); 58 | } 59 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by cryptopp.rc 4 | // 5 | 6 | // Next default values for new objects 7 | // 8 | #ifdef APSTUDIO_INVOKED 9 | #ifndef APSTUDIO_READONLY_SYMBOLS 10 | #define _APS_NEXT_RESOURCE_VALUE 101 11 | #define _APS_NEXT_COMMAND_VALUE 40001 12 | #define _APS_NEXT_CONTROL_VALUE 1000 13 | #define _APS_NEXT_SYMED_VALUE 101 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/ripemd.h: -------------------------------------------------------------------------------- 1 | // ripemd.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file 4 | /// \brief Classes for RIPEMD message digest 5 | 6 | #ifndef CRYPTOPP_RIPEMD_H 7 | #define CRYPTOPP_RIPEMD_H 8 | 9 | #include "iterhash.h" 10 | 11 | NAMESPACE_BEGIN(CryptoPP) 12 | 13 | /// \brief RIPEMD-160 message digest 14 | /// \details Digest size is 160-bits. 15 | /// \sa RIPEMD-160 16 | /// \since Crypto++ 2.1 17 | class RIPEMD160 : public IteratedHashWithStaticTransform 18 | { 19 | public: 20 | static void InitState(HashWordType *state); 21 | static void Transform(word32 *digest, const word32 *data); 22 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "RIPEMD-160";} 23 | }; 24 | 25 | /// \brief RIPEMD-320 message digest 26 | /// \details Digest size is 320-bits. 27 | /// \sa RIPEMD-320 28 | /// \since Crypto++ 2.1 29 | class RIPEMD320 : public IteratedHashWithStaticTransform 30 | { 31 | public: 32 | static void InitState(HashWordType *state); 33 | static void Transform(word32 *digest, const word32 *data); 34 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "RIPEMD-320";} 35 | }; 36 | 37 | /// \brief RIPEMD-128 message digest 38 | /// \details Digest size is 128-bits. 39 | /// \warning RIPEMD-128 is considered insecure, and should not be used unless you absolutely need it for compatibility. 40 | /// \sa RIPEMD-128 41 | /// \since Crypto++ 2.1 42 | class RIPEMD128 : public IteratedHashWithStaticTransform 43 | { 44 | public: 45 | static void InitState(HashWordType *state); 46 | static void Transform(word32 *digest, const word32 *data); 47 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "RIPEMD-128";} 48 | }; 49 | 50 | /// \brief RIPEMD-256 message digest 51 | /// \details Digest size is 256-bits. 52 | /// \warning RIPEMD-256 is considered insecure, and should not be used unless you absolutely need it for compatibility. 53 | /// \sa RIPEMD-256 54 | /// \since Crypto++ 2.1 55 | class RIPEMD256 : public IteratedHashWithStaticTransform 56 | { 57 | public: 58 | static void InitState(HashWordType *state); 59 | static void Transform(word32 *digest, const word32 *data); 60 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "RIPEMD-256";} 61 | }; 62 | 63 | NAMESPACE_END 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/seal.h: -------------------------------------------------------------------------------- 1 | // seal.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file seal.h 4 | /// \brief Classes for SEAL stream cipher 5 | /// \since Crypto++ 2.2 6 | 7 | #ifndef CRYPTOPP_SEAL_H 8 | #define CRYPTOPP_SEAL_H 9 | 10 | #include "strciphr.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief SEAL stream cipher information 16 | /// \tparam B Endianness of the stream cipher 17 | /// \since Crypto++ 2.2 18 | template 19 | struct SEAL_Info : public FixedKeyLength<20, SimpleKeyingInterface::INTERNALLY_GENERATED_IV, 4> 20 | { 21 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return B::ToEnum() == LITTLE_ENDIAN_ORDER ? "SEAL-3.0-LE" : "SEAL-3.0-BE";} 22 | }; 23 | 24 | /// \brief SEAL stream cipher operation 25 | /// \tparam B Endianness of the stream cipher 26 | /// \since Crypto++ 2.2 27 | template 28 | class CRYPTOPP_NO_VTABLE SEAL_Policy : public AdditiveCipherConcretePolicy, public SEAL_Info 29 | { 30 | protected: 31 | void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); 32 | void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); 33 | void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length); 34 | bool CipherIsRandomAccess() const {return true;} 35 | void SeekToIteration(lword iterationCount); 36 | 37 | private: 38 | FixedSizeSecBlock m_T; 39 | FixedSizeSecBlock m_S; 40 | SecBlock m_R; 41 | 42 | word32 m_startCount, m_iterationsPerCount; 43 | word32 m_outsideCounter, m_insideCounter; 44 | }; 45 | 46 | /// \brief SEAL stream cipher 47 | /// \tparam B Endianness of the stream cipher 48 | /// \sa SEAL 49 | /// \since Crypto++ 2.2 50 | template 51 | struct SEAL : public SEAL_Info, public SymmetricCipherDocumentation 52 | { 53 | typedef SymmetricCipherFinal, AdditiveCipherTemplate<> >, SEAL_Info > Encryption; 54 | typedef Encryption Decryption; 55 | }; 56 | 57 | NAMESPACE_END 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/secblockfwd.h: -------------------------------------------------------------------------------- 1 | // secblockfwd.h - written and placed in the public domain by Jeffrey Walton 2 | 3 | /// \file secblockfwd.h 4 | /// \brief Forward declarations for SecBlock 5 | /// \details secblock.h and misc.h have a circular dependency. secblockfwd.h 6 | /// allows the library to sidestep the circular dependency, and reference 7 | /// SecBlock classes without the full implementation. 8 | /// \since Crypto++ 8.3 9 | 10 | #ifndef CRYPTOPP_SECBLOCKFWD_H 11 | #define CRYPTOPP_SECBLOCKFWD_H 12 | 13 | #include "config.h" 14 | 15 | NAMESPACE_BEGIN(CryptoPP) 16 | 17 | template 18 | class SecBlock; 19 | 20 | template 21 | class AllocatorWithCleanup; 22 | 23 | typedef SecBlock > SecByteBlock; 24 | typedef SecBlock > SecWordBlock; 25 | typedef SecBlock > AlignedSecByteBlock; 26 | 27 | NAMESPACE_END 28 | 29 | #endif // CRYPTOPP_SECBLOCKFWD_H 30 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/seed.h: -------------------------------------------------------------------------------- 1 | // seed.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file seed.h 4 | /// \brief Classes for the SEED block cipher 5 | /// \since Crypto++ 5.6.0 6 | 7 | #ifndef CRYPTOPP_SEED_H 8 | #define CRYPTOPP_SEED_H 9 | 10 | #include "seckey.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief SEED block cipher information 16 | /// \since Crypto++ 5.6.0 17 | struct SEED_Info : public FixedBlockSize<16>, public FixedKeyLength<16>, public FixedRounds<16> 18 | { 19 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "SEED";} 20 | }; 21 | 22 | /// \brief SEED block cipher 23 | /// \sa SEED 24 | /// \since Crypto++ 5.6.0 25 | class SEED : public SEED_Info, public BlockCipherDocumentation 26 | { 27 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 28 | { 29 | public: 30 | void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); 31 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 32 | 33 | protected: 34 | FixedSizeSecBlock m_k; 35 | }; 36 | 37 | public: 38 | typedef BlockCipherFinal Encryption; 39 | typedef BlockCipherFinal Decryption; 40 | }; 41 | 42 | NAMESPACE_END 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/serpent.h: -------------------------------------------------------------------------------- 1 | // serpent.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file serpent.h 4 | /// \brief Classes for the Serpent block cipher 5 | /// \sa A 6 | /// Candidate Block Cipher for the Advanced Encryption Standard 7 | 8 | #ifndef CRYPTOPP_SERPENT_H 9 | #define CRYPTOPP_SERPENT_H 10 | 11 | #include "seckey.h" 12 | #include "secblock.h" 13 | 14 | NAMESPACE_BEGIN(CryptoPP) 15 | 16 | /// \brief Serpent block cipher information 17 | /// \since Crypto++ 3.1 18 | struct Serpent_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8>, public FixedRounds<32> 19 | { 20 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Serpent";} 21 | }; 22 | 23 | /// \brief Serpent block cipher 24 | /// \sa Serpent on the 25 | /// Crypto++ wiki, A 26 | /// Candidate Block Cipher for the Advanced Encryption Standard 27 | /// \since Crypto++ 3.1 28 | class Serpent : public Serpent_Info, public BlockCipherDocumentation 29 | { 30 | /// \brief Serpen block cipher base implementation 31 | /// \details Provides implementation common to encryption and decryption 32 | /// \since Crypto++ 3.1 33 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 34 | { 35 | public: 36 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 37 | 38 | protected: 39 | FixedSizeSecBlock m_key; 40 | }; 41 | 42 | /// \brief Serpent encryption transformation 43 | /// \details Enc provides the encryption transformation. 44 | /// All key sizes are supported. 45 | /// \since Crypto++ 3.1 46 | class CRYPTOPP_NO_VTABLE Enc : public Base 47 | { 48 | public: 49 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 50 | }; 51 | 52 | /// \brief Serpent decryption transformation 53 | /// \details Dec provides the decryption transformation. 54 | /// All key sizes are supported. 55 | /// \since Crypto++ 3.1 56 | class CRYPTOPP_NO_VTABLE Dec : public Base 57 | { 58 | public: 59 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 60 | }; 61 | 62 | public: 63 | typedef BlockCipherFinal Encryption; 64 | typedef BlockCipherFinal Decryption; 65 | }; 66 | 67 | typedef Serpent::Encryption SerpentEncryption; 68 | typedef Serpent::Decryption SerpentDecryption; 69 | 70 | NAMESPACE_END 71 | 72 | #endif // CRYPTOPP_SERPENT_H 73 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/sha1_armv4.h: -------------------------------------------------------------------------------- 1 | /* Header file for use with Cryptogam's ARMv4 SHA1. */ 2 | /* Also see http://www.openssl.org/~appro/cryptogams/ */ 3 | /* https://wiki.openssl.org/index.php/Cryptogams_SHA. */ 4 | 5 | #ifndef CRYPTOGAMS_SHA1_ARMV4_H 6 | #define CRYPTOGAMS_SHA1_ARMV4_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Crypto++ modified sha1_block_data_order to pass caps as a parameter. */ 13 | /* Also see https://github.com/weidai11/cryptopp/issues/846. */ 14 | void cryptogams_sha1_block_data_order(void *state, const void *data, size_t blocks); 15 | 16 | /* Cryptogams arm caps */ 17 | #define CRYPTOGAMS_ARMV7_NEON (1<<0) 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /* CRYPTOGAMS_SHA1_ARMV4_H */ 24 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/sha256_armv4.h: -------------------------------------------------------------------------------- 1 | /* Header file for use with Cryptogam's ARMv4 SHA1. */ 2 | /* Also see http://www.openssl.org/~appro/cryptogams/ */ 3 | /* https://wiki.openssl.org/index.php/Cryptogams_SHA. */ 4 | 5 | #ifndef CRYPTOGAMS_SHA256_ARMV4_H 6 | #define CRYPTOGAMS_SHA256_ARMV4_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Crypto++ modified cryptogams_sha256_block_data_order to pass caps as a parameter. */ 13 | /* Also see https://github.com/weidai11/cryptopp/issues/846. */ 14 | void cryptogams_sha256_block_data_order(void *state, const void *data, size_t blocks); 15 | 16 | /* Cryptogams arm caps */ 17 | #define CRYPTOGAMS_ARMV7_NEON (1<<0) 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /* CRYPTOGAMS_SHA256_ARMV4_H */ 24 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/sha3.cpp: -------------------------------------------------------------------------------- 1 | // sha3.cpp - modified by Wei Dai from Ronny Van Keer's public domain 2 | // Keccak-simple.c. All modifications here are placed in the 3 | // public domain by Wei Dai. 4 | // Keccack core function moved to keccakc.cpp in AUG 2018 5 | // by Jeffrey Walton. Separating the core file allows both 6 | // SHA3 and Keccack to share the core implementation. 7 | 8 | /* 9 | The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, 10 | Michael Peeters and Gilles Van Assche. For more information, feedback or 11 | questions, please refer to our website: http://keccak.noekeon.org/ 12 | 13 | Implementation by Ronny Van Keer, hereby denoted as "the implementer". 14 | 15 | To the extent possible under law, the implementer has waived all copyright 16 | and related or neighboring rights to the source code in this file. 17 | http://creativecommons.org/publicdomain/zero/1.0/ 18 | */ 19 | 20 | #include "pch.h" 21 | #include "sha3.h" 22 | 23 | NAMESPACE_BEGIN(CryptoPP) 24 | 25 | // The Keccak core function 26 | extern void KeccakF1600(word64 *state); 27 | 28 | NAMESPACE_END 29 | 30 | NAMESPACE_BEGIN(CryptoPP) 31 | 32 | void SHA3::Update(const byte *input, size_t length) 33 | { 34 | CRYPTOPP_ASSERT(!(input == NULLPTR && length != 0)); 35 | if (length == 0) { return; } 36 | 37 | size_t spaceLeft; 38 | while (length >= (spaceLeft = r() - m_counter)) 39 | { 40 | if (spaceLeft) 41 | xorbuf(m_state.BytePtr() + m_counter, input, spaceLeft); 42 | KeccakF1600(m_state); 43 | input += spaceLeft; 44 | length -= spaceLeft; 45 | m_counter = 0; 46 | } 47 | 48 | if (length) 49 | xorbuf(m_state.BytePtr() + m_counter, input, length); 50 | m_counter += (unsigned int)length; 51 | } 52 | 53 | void SHA3::Restart() 54 | { 55 | memset(m_state, 0, m_state.SizeInBytes()); 56 | m_counter = 0; 57 | } 58 | 59 | void SHA3::TruncatedFinal(byte *hash, size_t size) 60 | { 61 | CRYPTOPP_ASSERT(hash != NULLPTR); 62 | ThrowIfInvalidTruncatedSize(size); 63 | 64 | m_state.BytePtr()[m_counter] ^= 0x06; 65 | m_state.BytePtr()[r()-1] ^= 0x80; 66 | KeccakF1600(m_state); 67 | std::memcpy(hash, m_state, size); 68 | Restart(); 69 | } 70 | 71 | NAMESPACE_END 72 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/sha512_armv4.h: -------------------------------------------------------------------------------- 1 | /* Header file for use with Cryptogam's ARMv4 SHA512. */ 2 | /* Also see http://www.openssl.org/~appro/cryptogams/ */ 3 | /* https://wiki.openssl.org/index.php/Cryptogams_SHA. */ 4 | 5 | #ifndef CRYPTOGAMS_SHA512_ARMV4_H 6 | #define CRYPTOGAMS_SHA512_ARMV4_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Crypto++ modified cryptogams_sha512_block_data_order to pass caps as a parameter. */ 13 | /* Also see https://github.com/weidai11/cryptopp/issues/846. */ 14 | void cryptogams_sha512_block_data_order(void *state, const void *data, size_t blocks); 15 | 16 | /* Cryptogams arm caps */ 17 | #define CRYPTOGAMS_ARMV7_NEON (1<<0) 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /* CRYPTOGAMS_SHA512_ARMV4_H */ 24 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/shacal2.h: -------------------------------------------------------------------------------- 1 | // shacal.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file shacal2.h 4 | /// \brief Classes for the SHACAL-2 block cipher 5 | /// \since Crypto++ 5.2, Intel SHA since Crypto++ 6.0 6 | 7 | #ifndef CRYPTOPP_SHACAL2_H 8 | #define CRYPTOPP_SHACAL2_H 9 | 10 | #include "seckey.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief SHACAL2 block cipher information 16 | struct SHACAL2_Info : public FixedBlockSize<32>, public VariableKeyLength<16, 16, 64> 17 | { 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "SHACAL-2";} 19 | }; 20 | 21 | /// \brief SHACAL2 block cipher 22 | /// \since Crypto++ 5.2, Intel SHA since Crypto++ 6.0 23 | /// \sa SHACAL-2 24 | class SHACAL2 : public SHACAL2_Info, public BlockCipherDocumentation 25 | { 26 | /// \brief SHACAL2 block cipher transformation functions 27 | /// \details Provides implementation common to encryption and decryption 28 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 29 | { 30 | public: 31 | std::string AlgorithmProvider() const; 32 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 33 | 34 | protected: 35 | FixedSizeAlignedSecBlock m_key; 36 | 37 | static const word32 K[64]; 38 | }; 39 | 40 | /// \brief SHACAL2 block cipher transformation functions 41 | /// \details Encryption transformation 42 | class CRYPTOPP_NO_VTABLE Enc : public Base 43 | { 44 | public: 45 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 46 | }; 47 | 48 | /// \brief SHACAL2 block cipher transformation functions 49 | /// \details Decryption transformation 50 | class CRYPTOPP_NO_VTABLE Dec : public Base 51 | { 52 | public: 53 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 54 | }; 55 | 56 | public: 57 | typedef BlockCipherFinal Encryption; 58 | typedef BlockCipherFinal Decryption; 59 | }; 60 | 61 | typedef SHACAL2::Encryption SHACAL2Encryption; 62 | typedef SHACAL2::Decryption SHACAL2Decryption; 63 | 64 | NAMESPACE_END 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/shake.cpp: -------------------------------------------------------------------------------- 1 | // shake.cpp - modified by Wei Dai from Ronny Van Keer's public domain 2 | // sha3-simple.c. All modifications here are placed in the 3 | // public domain by Wei Dai. 4 | // Keccack core function moved to keccakc.cpp in AUG 2018 5 | // by Jeffrey Walton. Separating the core file allows both 6 | // SHA3 and Keccack to share the core implementation. 7 | 8 | /* 9 | The SHAKE sponge function, designed by Guido Bertoni, Joan Daemen, 10 | Michael Peeters and Gilles Van Assche. For more information, feedback or 11 | questions, please refer to our website: http://keccak.noekeon.org/ 12 | 13 | Implementation by Ronny Van Keer, hereby denoted as "the implementer". 14 | 15 | To the extent possible under law, the implementer has waived all copyright 16 | and related or neighboring rights to the source code in this file. 17 | http://creativecommons.org/publicdomain/zero/1.0/ 18 | */ 19 | 20 | #include "pch.h" 21 | #include "shake.h" 22 | 23 | NAMESPACE_BEGIN(CryptoPP) 24 | 25 | // The Keccak core function 26 | extern void KeccakF1600(word64 *state); 27 | 28 | void SHAKE::Update(const byte *input, size_t length) 29 | { 30 | CRYPTOPP_ASSERT(!(input == NULLPTR && length != 0)); 31 | if (length == 0) { return; } 32 | 33 | size_t spaceLeft; 34 | while (length >= (spaceLeft = r() - m_counter)) 35 | { 36 | if (spaceLeft) 37 | xorbuf(m_state.BytePtr() + m_counter, input, spaceLeft); 38 | KeccakF1600(m_state); 39 | input += spaceLeft; 40 | length -= spaceLeft; 41 | m_counter = 0; 42 | } 43 | 44 | if (length) 45 | xorbuf(m_state.BytePtr() + m_counter, input, length); 46 | m_counter += (unsigned int)length; 47 | } 48 | 49 | void SHAKE::Restart() 50 | { 51 | memset(m_state, 0, m_state.SizeInBytes()); 52 | m_counter = 0; 53 | } 54 | 55 | void SHAKE::ThrowIfInvalidTruncatedSize(size_t size) const 56 | { 57 | if (size > UINT_MAX) 58 | throw InvalidArgument(std::string("HashTransformation: can't truncate a ") + 59 | IntToString(UINT_MAX) + " byte digest to " + IntToString(size) + " bytes"); 60 | } 61 | 62 | void SHAKE::TruncatedFinal(byte *hash, size_t size) 63 | { 64 | CRYPTOPP_ASSERT(hash != NULLPTR); 65 | ThrowIfInvalidTruncatedSize(size); 66 | 67 | m_state.BytePtr()[m_counter] ^= 0x1F; 68 | m_state.BytePtr()[r()-1] ^= 0x80; 69 | 70 | // FIPS 202, Algorithm 8, pp 18-19. 71 | while (size > 0) 72 | { 73 | KeccakF1600(m_state); 74 | 75 | const size_t segmentLen = STDMIN(size, (size_t)BlockSize()); 76 | std::memcpy(hash, m_state, segmentLen); 77 | 78 | hash += segmentLen; 79 | size -= segmentLen; 80 | } 81 | 82 | Restart(); 83 | } 84 | 85 | NAMESPACE_END 86 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/shark.h: -------------------------------------------------------------------------------- 1 | // shark.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file shark.h 4 | /// \brief Classes for the SHARK block cipher 5 | /// \since Crypto++ 2.1 6 | 7 | #ifndef CRYPTOPP_SHARK_H 8 | #define CRYPTOPP_SHARK_H 9 | 10 | #include "config.h" 11 | #include "seckey.h" 12 | #include "secblock.h" 13 | 14 | NAMESPACE_BEGIN(CryptoPP) 15 | 16 | /// \brief SHARK block cipher information 17 | /// \since Crypto++ 2.1 18 | struct SHARK_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<6, 2> 19 | { 20 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "SHARK-E";} 21 | }; 22 | 23 | /// \brief SHARK block cipher 24 | /// SHARK-E 25 | /// \since Crypto++ 2.1 26 | class SHARK : public SHARK_Info, public BlockCipherDocumentation 27 | { 28 | /// \brief SHARK block cipher default operation 29 | /// \since Crypto++ 2.1 30 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 31 | { 32 | public: 33 | void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶m); 34 | 35 | protected: 36 | unsigned int m_rounds; 37 | SecBlock m_roundKeys; 38 | }; 39 | 40 | /// \brief SHARK block cipher encryption operation 41 | /// \since Crypto++ 2.1 42 | class CRYPTOPP_NO_VTABLE Enc : public Base 43 | { 44 | public: 45 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 46 | 47 | // used by Base to do key setup 48 | void InitForKeySetup(); 49 | 50 | private: 51 | static const byte sbox[256]; 52 | static const word64 cbox[8][256]; 53 | }; 54 | 55 | /// \brief SHARK block cipher decryption operation 56 | /// \since Crypto++ 2.1 57 | class CRYPTOPP_NO_VTABLE Dec : public Base 58 | { 59 | public: 60 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 61 | 62 | private: 63 | static const byte sbox[256]; 64 | static const word64 cbox[8][256]; 65 | }; 66 | 67 | public: 68 | typedef BlockCipherFinal Encryption; 69 | typedef BlockCipherFinal Decryption; 70 | }; 71 | 72 | typedef SHARK::Encryption SHARKEncryption; 73 | typedef SHARK::Decryption SHARKDecryption; 74 | 75 | NAMESPACE_END 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/simple.cpp: -------------------------------------------------------------------------------- 1 | // simple.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | 5 | #ifndef CRYPTOPP_IMPORTS 6 | 7 | #include "simple.h" 8 | 9 | NAMESPACE_BEGIN(CryptoPP) 10 | 11 | NAMESPACE_END 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/skipjack.h: -------------------------------------------------------------------------------- 1 | // skipjack.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file skipjack.h 4 | /// \brief Classes for the SKIPJACK block cipher 5 | /// \details The Crypto++ implementation conforms to SKIPJACK and KEA 6 | /// Algorithm Specifications published by NIST in May 1998. The library passes 7 | /// known answer tests available in NIST SP800-17, Table 6, pp. 140-42. 8 | /// \sa SKIPJACK 9 | /// and KEA Algorithm Specifications (May 1998), 10 | /// SKIPJACK on the 11 | // Crypto++ wiki 12 | 13 | #ifndef CRYPTOPP_SKIPJACK_H 14 | #define CRYPTOPP_SKIPJACK_H 15 | 16 | #include "seckey.h" 17 | #include "secblock.h" 18 | 19 | NAMESPACE_BEGIN(CryptoPP) 20 | 21 | /// \brief SKIPJACK block cipher information 22 | struct SKIPJACK_Info : public FixedBlockSize<8>, public FixedKeyLength<10> 23 | { 24 | CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "SKIPJACK";} 25 | }; 26 | 27 | /// \brief SKIPJACK block cipher 28 | /// \details The Crypto++ implementation conforms to SKIPJACK and KEA 29 | /// Algorithm Specifications published by NIST in May 1998. The library passes 30 | /// known answer tests available in NIST SP800-17, Table 6, pp. 140-42. 31 | /// \sa SKIPJACK 32 | /// and KEA Algorithm Specifications (May 1998), 33 | /// SKIPJACK on the 34 | /// Crypto++ wiki 35 | class SKIPJACK : public SKIPJACK_Info, public BlockCipherDocumentation 36 | { 37 | /// \brief SKIPJACK block cipher default operation 38 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 39 | { 40 | public: 41 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 42 | unsigned int OptimalDataAlignment() const {return GetAlignmentOf();} 43 | 44 | protected: 45 | static const byte fTable[256]; 46 | 47 | FixedSizeSecBlock tab; 48 | }; 49 | 50 | /// \brief SKIPJACK block cipher encryption operation 51 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Enc : public Base 52 | { 53 | public: 54 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 55 | private: 56 | static const byte Se[256]; 57 | static const word32 Te[4][256]; 58 | }; 59 | 60 | /// \brief SKIPJACK block cipher decryption operation 61 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Dec : public Base 62 | { 63 | public: 64 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 65 | private: 66 | static const byte Sd[256]; 67 | static const word32 Td[4][256]; 68 | }; 69 | 70 | public: 71 | typedef BlockCipherFinal Encryption; 72 | typedef BlockCipherFinal Decryption; 73 | }; 74 | 75 | typedef SKIPJACK::Encryption SKIPJACKEncryption; 76 | typedef SKIPJACK::Decryption SKIPJACKDecryption; 77 | 78 | NAMESPACE_END 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/sm3.h: -------------------------------------------------------------------------------- 1 | // sm3.h - written and placed in the public domain by Jeffrey Walton and Han Lulu 2 | // Based on the specification provided by Sean Shen and Xiaodong Lee. 3 | // Based on code by Krzysztof Kwiatkowski and Jack Lloyd. 4 | // Also see https://tools.ietf.org/html/draft-shen-sm3-hash. 5 | 6 | /// \file sm3.h 7 | /// \brief Classes for the SM3 hash function 8 | /// \details SM3 is a hash function designed by Xiaoyun Wang, et al. The hash is part of the 9 | /// Chinese State Cryptography Administration portfolio. 10 | /// \sa SM3 Hash Function and 11 | /// Reference implementation using OpenSSL. 12 | /// \since Crypto++ 6.0 13 | 14 | #ifndef CRYPTOPP_SM3_H 15 | #define CRYPTOPP_SM3_H 16 | 17 | #include "config.h" 18 | #include "iterhash.h" 19 | 20 | NAMESPACE_BEGIN(CryptoPP) 21 | 22 | /// \brief SM3 hash function 23 | /// \details SM3 is a hash function designed by Xiaoyun Wang, et al. The hash is part of the 24 | /// Chinese State Cryptography Administration portfolio. 25 | /// \sa SM3 Hash Function 26 | /// \since Crypto++ 6.0 27 | class SM3 : public IteratedHashWithStaticTransform 28 | { 29 | public: 30 | /// \brief Initialize state array 31 | /// \param state the state of the hash 32 | /// \details InitState sets a state array to SHA256 initial values 33 | /// \details Hashes which derive from IteratedHashWithStaticTransform provide static 34 | /// member functions InitState() and Transform(). External classes, like SEAL and MDC, 35 | /// can initialize state with a user provided key and operate the hash on the data 36 | /// with the user supplied state. 37 | static void InitState(HashWordType *state); 38 | 39 | /// \brief Operate the hash 40 | /// \param digest the state of the hash 41 | /// \param data the data to be digested 42 | /// \details Transform() operates the hash on data. When the call is invoked 43 | /// digest holds initial or current state. Upon return digest holds 44 | /// the hash or updated state. 45 | /// \details Hashes which derive from IteratedHashWithStaticTransform provide static 46 | /// member functions InitState() and Transform(). External classes, like SEAL and MDC, 47 | /// can initialize state with a user provided key and operate the hash on the data 48 | /// with the user supplied state. 49 | static void Transform(HashWordType *digest, const HashWordType *data); 50 | 51 | /// \brief The algorithm name 52 | /// \return C-style string "SM3" 53 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "SM3"; } 54 | 55 | protected: 56 | size_t HashMultipleBlocks(const HashWordType *input, size_t length); 57 | }; 58 | 59 | NAMESPACE_END 60 | 61 | #endif // CRYPTOPP_SM3_H 62 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/sosemanuk.h: -------------------------------------------------------------------------------- 1 | // sosemanuk.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file sosemanuk.h 4 | /// \brief Classes for Sosemanuk stream cipher 5 | /// \since Crypto++ 5.5 6 | 7 | #ifndef CRYPTOPP_SOSEMANUK_H 8 | #define CRYPTOPP_SOSEMANUK_H 9 | 10 | #include "strciphr.h" 11 | #include "secblock.h" 12 | 13 | // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler 14 | // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232 15 | #if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) 16 | # define CRYPTOPP_DISABLE_SOSEMANUK_ASM 1 17 | #endif 18 | 19 | NAMESPACE_BEGIN(CryptoPP) 20 | 21 | /// \brief Sosemanuk stream cipher information 22 | /// \since Crypto++ 5.5 23 | struct SosemanukInfo : public VariableKeyLength<16, 1, 32, 1, SimpleKeyingInterface::UNIQUE_IV, 16> 24 | { 25 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Sosemanuk";} 26 | }; 27 | 28 | /// \brief Sosemanuk stream cipher implementation 29 | /// \since Crypto++ 5.5 30 | class SosemanukPolicy : public AdditiveCipherConcretePolicy, public SosemanukInfo 31 | { 32 | protected: 33 | std::string AlgorithmProvider() const; 34 | void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); 35 | void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); 36 | void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length); 37 | bool CipherIsRandomAccess() const {return false;} 38 | #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) 39 | unsigned int GetAlignment() const; 40 | unsigned int GetOptimalBlockSize() const; 41 | #endif 42 | 43 | FixedSizeSecBlock m_key; 44 | FixedSizeAlignedSecBlock m_state; 45 | }; 46 | 47 | /// \brief Sosemanuk stream cipher 48 | /// \details is a stream cipher developed by Come Berbain, Olivier Billet, Anne Canteaut, Nicolas Courtois, 49 | /// Henri Gilbert, Louis Goubin, Aline Gouget, Louis Granboulan, Cédric Lauradoux, Marine Minier, Thomas 50 | /// Pornin and Hervé Sibert. Sosemanuk is one of the final four Profile 1 (software) ciphers selected for 51 | /// the eSTREAM Portfolio. 52 | /// \sa Sosemanuk 53 | /// \since Crypto++ 5.5 54 | struct Sosemanuk : public SosemanukInfo, public SymmetricCipherDocumentation 55 | { 56 | typedef SymmetricCipherFinal >, SosemanukInfo> Encryption; 57 | typedef Encryption Decryption; 58 | }; 59 | 60 | NAMESPACE_END 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/square.h: -------------------------------------------------------------------------------- 1 | // square.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file square.h 4 | /// \brief Classes for the Square block cipher 5 | 6 | #ifndef CRYPTOPP_SQUARE_H 7 | #define CRYPTOPP_SQUARE_H 8 | 9 | #include "seckey.h" 10 | #include "secblock.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | /// \brief Square block cipher information 15 | /// \since Crypto++ 2.2 16 | struct Square_Info : public FixedBlockSize<16>, public FixedKeyLength<16>, FixedRounds<8> 17 | { 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Square";} 19 | }; 20 | 21 | /// \brief Square block cipher 22 | /// \sa Square 23 | /// \since Crypto++ 2.2 24 | class Square : public Square_Info, public BlockCipherDocumentation 25 | { 26 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 27 | { 28 | public: 29 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 30 | 31 | protected: 32 | FixedSizeSecBlock m_roundkeys; 33 | }; 34 | 35 | class CRYPTOPP_NO_VTABLE Enc : public Base 36 | { 37 | public: 38 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 39 | private: 40 | static const byte Se[256]; 41 | static const word32 Te[4][256]; 42 | }; 43 | 44 | class CRYPTOPP_NO_VTABLE Dec : public Base 45 | { 46 | public: 47 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 48 | private: 49 | static const byte Sd[256]; 50 | static const word32 Td[4][256]; 51 | }; 52 | 53 | public: 54 | typedef BlockCipherFinal Encryption; 55 | typedef BlockCipherFinal Decryption; 56 | }; 57 | 58 | typedef Square::Encryption SquareEncryption; 59 | typedef Square::Decryption SquareDecryption; 60 | 61 | NAMESPACE_END 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/stdcpp.h: -------------------------------------------------------------------------------- 1 | // stdcpp.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file stdcpp.h 4 | /// \brief Common C++ header files 5 | 6 | #ifndef CRYPTOPP_STDCPP_H 7 | #define CRYPTOPP_STDCPP_H 8 | 9 | #if _MSC_VER >= 1500 10 | #define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY 11 | #include 12 | #endif 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | // http://connect.microsoft.com/VisualStudio/feedback/details/1600701/type-info-does-not-compile-with-has-exceptions-0 29 | #if defined(_MSC_VER) && (_MSC_VER < 1900) && defined(_HAS_EXCEPTIONS) && (_HAS_EXCEPTIONS == 0) 30 | namespace std { 31 | using ::type_info; 32 | } 33 | #endif 34 | 35 | // workaround needed for IBM XLC and debug heaps on AIX 36 | #if defined(_AIX) && (defined(__xlc__) || defined(__xlC__) || defined(__ibmxl__)) 37 | # if defined(__DEBUG_ALLOC__) 38 | namespace std { 39 | using ::_debug_memset; 40 | using ::_debug_memcpy; 41 | } 42 | # endif 43 | #endif 44 | 45 | // make_unchecked_array_iterator 46 | #if _MSC_VER >= 1600 47 | #include 48 | #endif 49 | 50 | #if defined(CRYPTOPP_CXX11_ATOMIC) 51 | #include 52 | #endif 53 | 54 | #if defined(CRYPTOPP_CXX11_SYNCHRONIZATION) 55 | #include 56 | #endif 57 | 58 | #if defined(CRYPTOPP_CXX11_RVALUES) 59 | # include 60 | #endif 61 | 62 | #include 63 | #include 64 | #include 65 | #include 66 | 67 | // It is 2019 and VS2017/Win10 still can't compile a 68 | // program that includes without making users 69 | // do something special. "Epic fail" comes to mind. 70 | // Also see https://github.com/weidai11/cryptopp/issues/781 71 | #ifndef _MSC_VER 72 | # include 73 | #endif 74 | 75 | // uintptr_t and ptrdiff_t 76 | #if defined(__SUNPRO_CC) 77 | # if (__SUNPRO_CC >= 0x5100) 78 | # include 79 | # endif 80 | #elif defined(_MSC_VER) 81 | # if (_MSC_VER >= 1700) 82 | # include 83 | # else 84 | # include 85 | # endif 86 | #elif (__cplusplus < 201103L) 87 | # include 88 | #endif 89 | 90 | // workaround needed on Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21 91 | #ifdef CRYPTOPP_INCLUDE_VECTOR_CC 92 | # include 93 | #endif 94 | 95 | // C++Builder's standard library (Dinkumware) do not have C's global log() function 96 | // https://github.com/weidai11/cryptopp/issues/520 97 | #ifdef __BORLANDC__ 98 | using std::log; 99 | #endif 100 | 101 | #endif // CRYPTOPP_STDCPP_H 102 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/tiger.h: -------------------------------------------------------------------------------- 1 | // tiger.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file tiger.h 4 | /// \brief Classes for the Tiger message digest 5 | /// \details Crypto++ provides the original Tiger hash that was 6 | /// submitted to the NESSIE project. The implementation is different 7 | /// from the revised Tiger2 hash. 8 | /// \sa Tiger and 9 | /// Tiger: 10 | /// A Fast New Cryptographic Hash Function 11 | /// \since Crypto++ 2.1 12 | 13 | #ifndef CRYPTOPP_TIGER_H 14 | #define CRYPTOPP_TIGER_H 15 | 16 | #include "config.h" 17 | #include "iterhash.h" 18 | 19 | // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler 20 | // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232 21 | #if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) 22 | # define CRYPTOPP_DISABLE_TIGER_ASM 1 23 | #endif 24 | 25 | NAMESPACE_BEGIN(CryptoPP) 26 | 27 | /// \brief Tiger message digest 28 | /// \details Crypto++ provides the original Tiger hash that was 29 | /// submitted to the NESSIE project. The implementation is different 30 | /// from the revised Tiger2 hash. 31 | /// \sa Tiger and 32 | /// Tiger: 33 | /// A Fast New Cryptographic Hash Function 34 | /// \since Crypto++ 2.1 35 | class Tiger : public IteratedHashWithStaticTransform 36 | { 37 | public: 38 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Tiger";} 39 | std::string AlgorithmProvider() const; 40 | 41 | /// \brief Initialize state array 42 | /// \param state the state of the hash 43 | static void InitState(HashWordType *state); 44 | /// \brief Operate the hash 45 | /// \param digest the state of the hash 46 | /// \param data the data to be digested 47 | static void Transform(word64 *digest, const word64 *data); 48 | /// \brief Computes the hash of the current message 49 | /// \param digest a pointer to the buffer to receive the hash 50 | /// \param digestSize the size of the truncated digest, in bytes 51 | /// \details TruncatedFinal() call Final() and then copies digestSize bytes to digest. 52 | /// The hash is restarted the hash for the next message. 53 | void TruncatedFinal(byte *digest, size_t digestSize); 54 | 55 | protected: 56 | static const word64 table[4*256+3]; 57 | }; 58 | 59 | NAMESPACE_END 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/trunhash.h: -------------------------------------------------------------------------------- 1 | // trunhash.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file trunhash.h 4 | /// \brief Classes for truncated hashes 5 | 6 | #ifndef CRYPTOPP_TRUNHASH_H 7 | #define CRYPTOPP_TRUNHASH_H 8 | 9 | #include "cryptlib.h" 10 | 11 | NAMESPACE_BEGIN(CryptoPP) 12 | 13 | /// \brief Null hash 14 | /// \details A null hash that conforms to HashTransformation interface 15 | class NullHash : public HashTransformation 16 | { 17 | public: 18 | void Update(const byte *input, size_t length) 19 | {CRYPTOPP_UNUSED(input);CRYPTOPP_UNUSED(length);} 20 | unsigned int DigestSize() const 21 | {return 0;} 22 | void TruncatedFinal(byte *digest, size_t digestSize) 23 | {CRYPTOPP_UNUSED(digest);CRYPTOPP_UNUSED(digestSize);} 24 | bool TruncatedVerify(const byte *digest, size_t digestLength) 25 | {CRYPTOPP_UNUSED(digest);CRYPTOPP_UNUSED(digestLength);return true;} 26 | }; 27 | 28 | /// \brief Construct new HashModule with smaller digest size from an existing one 29 | /// \tparam T HashTransformation derived class 30 | template 31 | class TruncatedHashTemplate : public HashTransformation 32 | { 33 | public: 34 | /// \brief Construct a TruncatedHashTemplate 35 | TruncatedHashTemplate(T hm, unsigned int digestSize) 36 | : m_hm(hm), m_digestSize(digestSize) {} 37 | /// \brief Construct a TruncatedHashTemplate 38 | TruncatedHashTemplate(const byte *key, size_t keyLength, unsigned int digestSize) 39 | : m_hm(key, keyLength), m_digestSize(digestSize) {} 40 | /// \brief Construct a TruncatedHashTemplate 41 | TruncatedHashTemplate(size_t digestSize) 42 | : m_digestSize(digestSize) {} 43 | 44 | void Restart() 45 | {m_hm.Restart();} 46 | void Update(const byte *input, size_t length) 47 | {m_hm.Update(input, length);} 48 | unsigned int DigestSize() const {return m_digestSize;} 49 | void TruncatedFinal(byte *digest, size_t digestSize) 50 | {m_hm.TruncatedFinal(digest, digestSize);} 51 | bool TruncatedVerify(const byte *digest, size_t digestLength) 52 | {return m_hm.TruncatedVerify(digest, digestLength);} 53 | 54 | private: 55 | T m_hm; 56 | unsigned int m_digestSize; 57 | }; 58 | 59 | typedef TruncatedHashTemplate TruncatedHashModule; 60 | 61 | NAMESPACE_END 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/ttmac.h: -------------------------------------------------------------------------------- 1 | // ttmac.h - written and placed in the public domain by Kevin Springle 2 | 3 | /// \file ttmac.h 4 | /// \brief Classes for the TTMAC message authentication code 5 | 6 | #ifndef CRYPTOPP_TTMAC_H 7 | #define CRYPTOPP_TTMAC_H 8 | 9 | #include "seckey.h" 10 | #include "iterhash.h" 11 | #include "secblock.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief TTMAC message authentication code information 16 | class CRYPTOPP_NO_VTABLE TTMAC_Base : public FixedKeyLength<20>, public IteratedHash 17 | { 18 | public: 19 | static std::string StaticAlgorithmName() {return std::string("Two-Track-MAC");} 20 | CRYPTOPP_CONSTANT(DIGESTSIZE=20); 21 | 22 | unsigned int DigestSize() const {return DIGESTSIZE;}; 23 | void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms); 24 | void TruncatedFinal(byte *mac, size_t size); 25 | 26 | protected: 27 | static void Transform (word32 *digest, const word32 *X, bool last); 28 | void HashEndianCorrectedBlock(const word32 *data) {Transform(m_digest, data, false);} 29 | void Init(); 30 | word32* StateBuf() {return m_digest;} 31 | 32 | FixedSizeSecBlock m_digest; 33 | FixedSizeSecBlock m_key; 34 | }; 35 | 36 | /// \brief Two-Track-MAC message authentication code 37 | /// \tparam T HashTransformation class 38 | /// \details 160-bit MAC with 160-bit key 39 | /// \sa MessageAuthenticationCode(), Two-Track-MAC 40 | DOCUMENTED_TYPEDEF(MessageAuthenticationCodeFinal, TTMAC); 41 | 42 | NAMESPACE_END 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/twofish.h: -------------------------------------------------------------------------------- 1 | // twofish.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file twofish.h 4 | /// \brief Classes for the Twofish block cipher 5 | 6 | #ifndef CRYPTOPP_TWOFISH_H 7 | #define CRYPTOPP_TWOFISH_H 8 | 9 | #include "seckey.h" 10 | #include "secblock.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | /// \brief Twofish block cipher information 15 | /// \since Crypto++ 3.1 16 | struct Twofish_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8>, FixedRounds<16> 17 | { 18 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Twofish";} 19 | }; 20 | 21 | /// \brief Twofish block cipher 22 | /// \sa Twofish 23 | /// \since Crypto++ 3.1 24 | class Twofish : public Twofish_Info, public BlockCipherDocumentation 25 | { 26 | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 27 | { 28 | public: 29 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 30 | 31 | protected: 32 | static word32 h0(word32 x, const word32 *key, unsigned int kLen); 33 | static word32 h(word32 x, const word32 *key, unsigned int kLen); 34 | 35 | static const byte q[2][256]; 36 | static const word32 mds[4][256]; 37 | 38 | FixedSizeSecBlock m_k; 39 | FixedSizeSecBlock m_s; 40 | }; 41 | 42 | class CRYPTOPP_NO_VTABLE Enc : public Base 43 | { 44 | public: 45 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 46 | }; 47 | 48 | class CRYPTOPP_NO_VTABLE Dec : public Base 49 | { 50 | public: 51 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 52 | }; 53 | 54 | public: 55 | typedef BlockCipherFinal Encryption; 56 | typedef BlockCipherFinal Decryption; 57 | }; 58 | 59 | typedef Twofish::Encryption TwofishEncryption; 60 | typedef Twofish::Decryption TwofishDecryption; 61 | 62 | NAMESPACE_END 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/wake.cpp: -------------------------------------------------------------------------------- 1 | // wake.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | 5 | #include "wake.h" 6 | #include "smartptr.h" 7 | 8 | ANONYMOUS_NAMESPACE_BEGIN 9 | 10 | const unsigned int TT[8]= { 11 | 0x726a8f3b, 0xe69a3b5c, 0xd3c71fe5, 0xab3c73d2, 12 | 0x4d3a8eb3, 0x0396d6e8, 0x3d4c2f7a, 0x9ee27cf3 13 | } ; 14 | 15 | ANONYMOUS_NAMESPACE_END 16 | 17 | NAMESPACE_BEGIN(CryptoPP) 18 | 19 | #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) 20 | void WAKE_TestInstantiations() 21 | { 22 | WAKE_OFB<>::Encryption x2; 23 | WAKE_OFB<>::Decryption x4; 24 | } 25 | #endif 26 | 27 | inline word32 WAKE_Base::M(word32 x, word32 y) 28 | { 29 | word32 w = x+y; 30 | return (w>>8) ^ t[w & 0xff]; 31 | } 32 | 33 | void WAKE_Base::GenKey(word32 k0, word32 k1, word32 k2, word32 k3) 34 | { 35 | // this code is mostly copied from David Wheeler's paper "A Bulk Data Encryption Algorithm" 36 | signed int x, z, p; 37 | 38 | t[0] = k0; 39 | t[1] = k1; 40 | t[2] = k2; 41 | t[3] = k3; 42 | for (p=4 ; p<256 ; p++) 43 | { 44 | x=t[p-4]+t[p-1] ; // fill t 45 | t[p]= (x>>3) ^ TT[x&7] ; 46 | } 47 | 48 | for (p=0 ; p<23 ; p++) 49 | t[p]+=t[p+89] ; // mix first entries 50 | x=t[33] ; z=t[59] | 0x01000001 ; 51 | z=z&0xff7fffff ; 52 | for (p=0 ; p<256 ; p++) { //change top byte to 53 | x=(x&0xff7fffff)+z ; // a permutation etc 54 | t[p]=(t[p] & 0x00ffffff) ^ x ; } 55 | 56 | t[256]=t[0] ; 57 | byte y=byte(x); 58 | for (p=0 ; p<256 ; p++) { // further change perm. 59 | t[p]=t[y=byte(t[p^y]^y)] ; // and other digits 60 | t[y]=t[p+1] ; } 61 | } 62 | 63 | template 64 | void WAKE_Policy::CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length) 65 | { 66 | CRYPTOPP_UNUSED(params); CRYPTOPP_UNUSED(key); CRYPTOPP_UNUSED(length); 67 | word32 k0, k1, k2, k3; 68 | BlockGetAndPut::Get(key)(r3)(r4)(r5)(r6)(k0)(k1)(k2)(k3); 69 | GenKey(k0, k1, k2, k3); 70 | } 71 | 72 | // OFB 73 | template 74 | void WAKE_Policy::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount) 75 | { 76 | #define WAKE_OUTPUT(x)\ 77 | while (iterationCount--)\ 78 | {\ 79 | CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 0, r6);\ 80 | r3 = M(r3, r6);\ 81 | r4 = M(r4, r3);\ 82 | r5 = M(r5, r4);\ 83 | r6 = M(r6, r5);\ 84 | output += 4;\ 85 | if (!(x & INPUT_NULL))\ 86 | input += 4;\ 87 | } 88 | 89 | typedef word32 WordType; 90 | CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(WAKE_OUTPUT, 0); 91 | } 92 | /* 93 | template 94 | void WAKE_ROFB_Policy::Iterate(KeystreamOperation operation, byte *output, const byte *input, unsigned int iterationCount) 95 | { 96 | KeystreamOutput keystreamOperation(operation, output, input); 97 | 98 | while (iterationCount--) 99 | { 100 | keystreamOperation(r6); 101 | r3 = M(r3, r6); 102 | r4 = M(r4, r3); 103 | r5 = M(r5, r4); 104 | r6 = M(r6, r5); 105 | } 106 | } 107 | */ 108 | template class WAKE_Policy; 109 | template class WAKE_Policy; 110 | 111 | NAMESPACE_END 112 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/wake.h: -------------------------------------------------------------------------------- 1 | // wake.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file wake.h 4 | /// \brief Classes for WAKE stream cipher 5 | 6 | #ifndef CRYPTOPP_WAKE_H 7 | #define CRYPTOPP_WAKE_H 8 | 9 | #include "seckey.h" 10 | #include "secblock.h" 11 | #include "strciphr.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// \brief WAKE stream cipher information 16 | /// \tparam B Endianness of the stream cipher 17 | /// \since Crypto++ 1.0 18 | template 19 | struct WAKE_OFB_Info : public FixedKeyLength<32> 20 | { 21 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return B::ToEnum() == LITTLE_ENDIAN_ORDER ? "WAKE-OFB-LE" : "WAKE-OFB-BE";} 22 | }; 23 | 24 | class CRYPTOPP_NO_VTABLE WAKE_Base 25 | { 26 | protected: 27 | word32 M(word32 x, word32 y); 28 | void GenKey(word32 k0, word32 k1, word32 k2, word32 k3); 29 | 30 | word32 t[257]; 31 | word32 r3, r4, r5, r6; 32 | }; 33 | 34 | /// \brief WAKE stream cipher operation 35 | /// \tparam B Endianness of the stream cipher 36 | /// \since Crypto++ 1.0 37 | template 38 | class CRYPTOPP_NO_VTABLE WAKE_Policy : public AdditiveCipherConcretePolicy, protected WAKE_Base 39 | { 40 | protected: 41 | void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); 42 | // OFB 43 | void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); 44 | bool CipherIsRandomAccess() const {return false;} 45 | }; 46 | 47 | /// \brief WAKE stream cipher 48 | /// \tparam B Endianness of the stream cipher 49 | /// \since Crypto++ 1.0 50 | template 51 | struct WAKE_OFB : public WAKE_OFB_Info, public SymmetricCipherDocumentation 52 | { 53 | typedef SymmetricCipherFinal, AdditiveCipherTemplate<> >, WAKE_OFB_Info > Encryption; 54 | typedef Encryption Decryption; 55 | }; 56 | 57 | NAMESPACE_END 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/whrlpool.h: -------------------------------------------------------------------------------- 1 | // whrlpool.h - originally modified by Kevin Springle from Paulo Barreto and Vincent Rijmen's 2 | // public domain code, whirlpool.c. Updated to Whirlpool version 3.0, optimized 3 | // and SSE version added by WD. All modifications are placed in the public domain. 4 | 5 | #ifndef CRYPTOPP_WHIRLPOOL_H 6 | #define CRYPTOPP_WHIRLPOOL_H 7 | 8 | /// \file whrlpool.h 9 | /// \brief Classes for the Whirlpool message digest 10 | /// \details Crypto++ provides version 3.0 of the Whirlpool algorithm. 11 | /// This version of the algorithm was submitted for ISO standardization. 12 | 13 | #include "config.h" 14 | #include "iterhash.h" 15 | 16 | // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler 17 | // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232 18 | #if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) 19 | # define CRYPTOPP_DISABLE_WHIRLPOOL_ASM 1 20 | #endif 21 | 22 | NAMESPACE_BEGIN(CryptoPP) 23 | 24 | /// \brief Whirlpool message digest 25 | /// \details Crypto++ provides version 3.0 of the Whirlpool algorithm. 26 | /// This version of the algorithm was submitted for ISO standardization. 27 | /// \since Crypto++ 5.2 28 | /// \sa Whirlpool 29 | class Whirlpool : public IteratedHashWithStaticTransform 30 | { 31 | public: 32 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Whirlpool";} 33 | std::string AlgorithmProvider() const; 34 | 35 | static void InitState(HashWordType *state); 36 | static void Transform(word64 *digest, const word64 *data); 37 | void TruncatedFinal(byte *hash, size_t size); 38 | }; 39 | 40 | NAMESPACE_END 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/xtrcrypt.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_XTRCRYPT_H 2 | #define CRYPTOPP_XTRCRYPT_H 3 | 4 | /// \file 5 | /// \brief XTR public key system 6 | /// \sa "The XTR public key system" by Arjen K. Lenstra and Eric R. Verheul 7 | 8 | #include "cryptlib.h" 9 | #include "xtr.h" 10 | #include "integer.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | /// \brief XTR-DH with key validation 15 | class XTR_DH : public SimpleKeyAgreementDomain, public CryptoParameters 16 | { 17 | typedef XTR_DH ThisClass; 18 | 19 | public: 20 | XTR_DH(const Integer &p, const Integer &q, const GFP2Element &g); 21 | XTR_DH(RandomNumberGenerator &rng, unsigned int pbits, unsigned int qbits); 22 | XTR_DH(BufferedTransformation &domainParams); 23 | 24 | void DEREncode(BufferedTransformation &domainParams) const; 25 | 26 | bool Validate(RandomNumberGenerator &rng, unsigned int level) const; 27 | bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; 28 | void AssignFrom(const NameValuePairs &source); 29 | CryptoParameters & AccessCryptoParameters() {return *this;} 30 | unsigned int AgreedValueLength() const {return 2*m_p.ByteCount();} 31 | unsigned int PrivateKeyLength() const {return m_q.ByteCount();} 32 | unsigned int PublicKeyLength() const {return 2*m_p.ByteCount();} 33 | 34 | void GeneratePrivateKey(RandomNumberGenerator &rng, byte *privateKey) const; 35 | void GeneratePublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const; 36 | bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const; 37 | 38 | const Integer &GetModulus() const {return m_p;} 39 | const Integer &GetSubgroupOrder() const {return m_q;} 40 | const GFP2Element &GetSubgroupGenerator() const {return m_g;} 41 | 42 | void SetModulus(const Integer &p) {m_p = p;} 43 | void SetSubgroupOrder(const Integer &q) {m_q = q;} 44 | void SetSubgroupGenerator(const GFP2Element &g) {m_g = g;} 45 | 46 | private: 47 | unsigned int ExponentBitLength() const; 48 | 49 | Integer m_p, m_q; 50 | GFP2Element m_g; 51 | }; 52 | 53 | NAMESPACE_END 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/zlib.cpp: -------------------------------------------------------------------------------- 1 | // zlib.cpp - originally written and placed in the public domain by Wei Dai 2 | 3 | // "zlib" is the name of a well known C language compression library 4 | // (http://www.zlib.org) and also the name of a compression format 5 | // (RFC 1950) that the library implements. This file is part of a 6 | // complete reimplementation of the zlib compression format. 7 | 8 | #include "pch.h" 9 | #include "zlib.h" 10 | #include "zdeflate.h" 11 | #include "zinflate.h" 12 | #include "secblock.h" 13 | 14 | NAMESPACE_BEGIN(CryptoPP) 15 | 16 | static const byte DEFLATE_METHOD = 8; 17 | static const byte FDICT_FLAG = (1 << 5); 18 | 19 | // ************************************************************* 20 | 21 | void ZlibCompressor::WritePrestreamHeader() 22 | { 23 | m_adler32.Restart(); 24 | CRYPTOPP_ASSERT(((GetLog2WindowSize()-8) << 4) <= 255); 25 | byte cmf = byte(DEFLATE_METHOD | ((GetLog2WindowSize()-8) << 4)); 26 | CRYPTOPP_ASSERT((GetCompressionLevel() << 6) <= 255); 27 | byte flags = byte(GetCompressionLevel() << 6); 28 | AttachedTransformation()->PutWord16(RoundUpToMultipleOf(word16(cmf*256+flags), word16(31))); 29 | } 30 | 31 | void ZlibCompressor::ProcessUncompressedData(const byte *inString, size_t length) 32 | { 33 | m_adler32.Update(inString, length); 34 | } 35 | 36 | void ZlibCompressor::WritePoststreamTail() 37 | { 38 | FixedSizeSecBlock adler32; 39 | m_adler32.Final(adler32); 40 | AttachedTransformation()->Put(adler32, 4); 41 | } 42 | 43 | unsigned int ZlibCompressor::GetCompressionLevel() const 44 | { 45 | static const unsigned int deflateToCompressionLevel[] = {0, 1, 1, 1, 2, 2, 2, 2, 2, 3}; 46 | return deflateToCompressionLevel[GetDeflateLevel()]; 47 | } 48 | 49 | // ************************************************************* 50 | 51 | ZlibDecompressor::ZlibDecompressor(BufferedTransformation *attachment, bool repeat, int propagation) 52 | : Inflator(attachment, repeat, propagation), m_log2WindowSize(0) 53 | { 54 | } 55 | 56 | void ZlibDecompressor::ProcessPrestreamHeader() 57 | { 58 | m_adler32.Restart(); 59 | 60 | byte cmf; 61 | byte flags; 62 | 63 | if (!m_inQueue.Get(cmf) || !m_inQueue.Get(flags)) 64 | throw HeaderErr(); 65 | 66 | if ((cmf*256+flags) % 31 != 0) 67 | throw HeaderErr(); // if you hit this exception, you're probably trying to decompress invalid data 68 | 69 | if ((cmf & 0xf) != DEFLATE_METHOD) 70 | throw UnsupportedAlgorithm(); 71 | 72 | if (flags & FDICT_FLAG) 73 | throw UnsupportedPresetDictionary(); 74 | 75 | m_log2WindowSize = 8 + (cmf >> 4); 76 | } 77 | 78 | void ZlibDecompressor::ProcessDecompressedData(const byte *inString, size_t length) 79 | { 80 | AttachedTransformation()->Put(inString, length); 81 | m_adler32.Update(inString, length); 82 | } 83 | 84 | void ZlibDecompressor::ProcessPoststreamTail() 85 | { 86 | FixedSizeSecBlock adler32; 87 | if (m_inQueue.Get(adler32, 4) != 4) 88 | throw Adler32Err(); 89 | if (!m_adler32.Verify(adler32)) 90 | throw Adler32Err(); 91 | } 92 | 93 | NAMESPACE_END 94 | -------------------------------------------------------------------------------- /cryptlib_src/cryptopp850/zlib.h: -------------------------------------------------------------------------------- 1 | // zlib.h - originally written and placed in the public domain by Wei Dai 2 | 3 | /// \file zlib.h 4 | /// \brief ZLIB compression and decompression (RFC 1950) 5 | 6 | #ifndef CRYPTOPP_ZLIB_H 7 | #define CRYPTOPP_ZLIB_H 8 | 9 | #include "cryptlib.h" 10 | #include "adler32.h" 11 | #include "zdeflate.h" 12 | #include "zinflate.h" 13 | 14 | NAMESPACE_BEGIN(CryptoPP) 15 | 16 | /// ZLIB Compressor (RFC 1950) 17 | class ZlibCompressor : public Deflator 18 | { 19 | public: 20 | ZlibCompressor(BufferedTransformation *attachment=NULLPTR, unsigned int deflateLevel=DEFAULT_DEFLATE_LEVEL, unsigned int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE, bool detectUncompressible=true) 21 | : Deflator(attachment, deflateLevel, log2WindowSize, detectUncompressible) {} 22 | ZlibCompressor(const NameValuePairs ¶meters, BufferedTransformation *attachment=NULLPTR) 23 | : Deflator(parameters, attachment) {} 24 | 25 | unsigned int GetCompressionLevel() const; 26 | 27 | protected: 28 | void WritePrestreamHeader(); 29 | void ProcessUncompressedData(const byte *string, size_t length); 30 | void WritePoststreamTail(); 31 | 32 | Adler32 m_adler32; 33 | }; 34 | 35 | /// ZLIB Decompressor (RFC 1950) 36 | class ZlibDecompressor : public Inflator 37 | { 38 | public: 39 | typedef Inflator::Err Err; 40 | class HeaderErr : public Err {public: HeaderErr() : Err(INVALID_DATA_FORMAT, "ZlibDecompressor: header decoding error") {}}; 41 | class Adler32Err : public Err {public: Adler32Err() : Err(DATA_INTEGRITY_CHECK_FAILED, "ZlibDecompressor: ADLER32 check error") {}}; 42 | class UnsupportedAlgorithm : public Err {public: UnsupportedAlgorithm() : Err(INVALID_DATA_FORMAT, "ZlibDecompressor: unsupported algorithm") {}}; 43 | class UnsupportedPresetDictionary : public Err {public: UnsupportedPresetDictionary() : Err(INVALID_DATA_FORMAT, "ZlibDecompressor: unsupported preset dictionary") {}}; 44 | 45 | /// \brief Construct a ZlibDecompressor 46 | /// \param attachment a \ BufferedTransformation to attach to this object 47 | /// \param repeat decompress multiple compressed streams in series 48 | /// \param autoSignalPropagation 0 to turn off MessageEnd signal 49 | ZlibDecompressor(BufferedTransformation *attachment = NULLPTR, bool repeat = false, int autoSignalPropagation = -1); 50 | unsigned int GetLog2WindowSize() const {return m_log2WindowSize;} 51 | 52 | private: 53 | unsigned int MaxPrestreamHeaderSize() const {return 2;} 54 | void ProcessPrestreamHeader(); 55 | void ProcessDecompressedData(const byte *string, size_t length); 56 | unsigned int MaxPoststreamTailSize() const {return 4;} 57 | void ProcessPoststreamTail(); 58 | 59 | unsigned int m_log2WindowSize; 60 | Adler32 m_adler32; 61 | }; 62 | 63 | NAMESPACE_END 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /cryptlib_src/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zackmark29/Chrome2209-CDM-API/e3a306cb42bd3999eb1f68c6548a67eb54dda8a8/cryptlib_src/settings.png -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import shutil 2 | from pathlib import Path 3 | from setuptools import setup, Extension 4 | 5 | name = 'cdmapi' 6 | src = 'cdmapi_src' 7 | setup( 8 | name=name, 9 | version="1.0.0", 10 | ext_modules=[ 11 | Extension( 12 | name=name, 13 | sources=[ 14 | f'{src}/bind.cpp', 15 | f'{src}/codelift.cpp' 16 | ], 17 | extra_objects=[f'{src}/cryptlib.lib'], 18 | 19 | # to use for any python version 20 | py_limited_api=True, 21 | define_macros=[('Py_LIMITED_API', None)] 22 | ) 23 | ] 24 | ) 25 | 26 | 27 | for folder in ('build', 'cdmapi.egg-info'): 28 | if Path(folder).exists(): 29 | print(f'Deleting {folder} folder and files') 30 | shutil.rmtree(folder) 31 | 32 | 33 | dist = Path('dist') 34 | if dist.exists(): 35 | try: 36 | whl = next(dist.glob('*.whl')) 37 | whl.rename(whl.name) 38 | dist.rmdir() 39 | except StopIteration: 40 | pass 41 | --------------------------------------------------------------------------------