├── src └── pycryptopp │ ├── bench │ ├── __init__.py │ ├── bench_algs.py │ ├── bench_ciphers.py │ ├── bench_hashes.py │ └── common.py │ ├── test │ ├── __init__.py │ ├── test_from_Nikratio.py │ ├── test_ed25519_kat.py │ └── test_aes.py │ ├── hash │ ├── __init__.py │ ├── sha256module.hpp │ └── sha256.py │ ├── cipher │ ├── __init__.py │ ├── aesmodule.hpp │ ├── xsalsa20module.hpp │ ├── xsalsa20.py │ └── aes.py │ ├── publickey │ ├── __init__.py │ ├── rsa.py │ ├── ecdsa.py │ ├── ecdsamodule.hpp │ ├── ed25519 │ │ ├── __init__.py │ │ ├── _version.py │ │ └── keys.py │ └── rsamodule.hpp │ ├── __init__.py │ ├── testvectors │ └── KAT_AES │ │ ├── ECBGFSbox256e.txt │ │ ├── ECBGFSbox128e.txt │ │ ├── ECBKeySbox256e.txt │ │ └── ECBKeySbox128e.txt │ └── _pycryptoppmodule.cpp ├── .gitattributes ├── src-cryptopp ├── cryptopp.rc ├── TestVectors │ ├── blake2.txt │ ├── seed.txt │ ├── sosemanuk.txt │ ├── all.txt │ ├── ttmac.txt │ ├── cmac.txt │ ├── whrlpool.txt │ ├── vmac.txt │ ├── mars.txt │ ├── sha.txt │ ├── eax.txt │ ├── panama.txt │ ├── Readme.txt │ └── rsa_pkcs1_1_5.txt ├── aes.h ├── pch.h ├── tiger.h ├── adhoc.cpp.proto ├── trdlocal.h ├── modexppc.h ├── hex.cpp ├── dsa.cpp ├── oaep.h ├── dsa.h ├── serpent.h ├── cbcmac.h ├── hex.h ├── sosemanuk.h ├── stdcpp.h ├── randpool.cpp ├── dll.h ├── hmac.cpp ├── hrtimer.h ├── skipjack.h ├── cmac.h ├── algparam.cpp ├── License.txt ├── emsa2.h ├── fltrimpl.h ├── words.h ├── hmac.h ├── fips140.cpp ├── randpool.h ├── authenc.h ├── rijndael.h ├── sha.h ├── oaep.cpp ├── serpent.cpp ├── salsa.h ├── eprecomp.h ├── pkcspad.h ├── mqueue.h ├── chacha.h ├── eprecomp.cpp ├── pssr.h ├── rng.h ├── rw.h └── ccm.h ├── pycryptopp.egg-info └── stdeb.cfg ├── src-ed25519 └── supercop-ref │ ├── api.h │ ├── crypto_int32.h │ ├── crypto_uint32.h │ ├── crypto_verify_32.h │ ├── Makefile │ ├── sha512.h │ ├── crypto_sign.h │ ├── verify.c │ ├── test.c │ ├── ge25519.h │ ├── sha512-hash.c │ ├── fe25519.h │ ├── sc25519.h │ └── ed25519.c ├── misc ├── dependencies │ └── setuptools-0.6c14dev.egg └── build_helpers │ ├── _build-wheels.sh │ └── build-manylinux-wheels.sh ├── COPYING.SPL.txt ├── MANIFEST.in ├── .travis.yml ├── setup.cfg ├── .gitignore ├── COPYING.MIT.txt ├── _doubleloadtester.cpp ├── NEWS.rst └── README.rst /src/pycryptopp/bench/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/pycryptopp/test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | pycryptopp/_version.py export-subst 2 | -------------------------------------------------------------------------------- /src/pycryptopp/hash/__init__.py: -------------------------------------------------------------------------------- 1 | import sha256 2 | 3 | quiet_pyflakes=[sha256] 4 | -------------------------------------------------------------------------------- /src-cryptopp/cryptopp.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tahoe-lafs/pycryptopp/HEAD/src-cryptopp/cryptopp.rc -------------------------------------------------------------------------------- /src/pycryptopp/cipher/__init__.py: -------------------------------------------------------------------------------- 1 | import aes 2 | import xsalsa20 3 | 4 | quiet_pyflakes=[aes, xsalsa20] 5 | -------------------------------------------------------------------------------- /src/pycryptopp/publickey/__init__.py: -------------------------------------------------------------------------------- 1 | import ecdsa, rsa, ed25519 2 | 3 | quiet_pyflakes=[ecdsa, rsa, ed25519] 4 | -------------------------------------------------------------------------------- /pycryptopp.egg-info/stdeb.cfg: -------------------------------------------------------------------------------- 1 | [pycryptopp] 2 | Copyright-File: copyright 3 | Setup-Env-Vars: PYCRYPTOPP_DISABLE_EMBEDDED_CRYPTOPP=1 4 | -------------------------------------------------------------------------------- /src-ed25519/supercop-ref/api.h: -------------------------------------------------------------------------------- 1 | #define CRYPTO_SECRETKEYBYTES 64 2 | #define CRYPTO_PUBLICKEYBYTES 32 3 | #define CRYPTO_BYTES 64 4 | 5 | -------------------------------------------------------------------------------- /misc/dependencies/setuptools-0.6c14dev.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tahoe-lafs/pycryptopp/HEAD/misc/dependencies/setuptools-0.6c14dev.egg -------------------------------------------------------------------------------- /src-ed25519/supercop-ref/crypto_int32.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_int32_h 2 | #define crypto_int32_h 3 | 4 | typedef int crypto_int32; 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/pycryptopp/publickey/rsa.py: -------------------------------------------------------------------------------- 1 | from pycryptopp import _import_my_names 2 | 3 | _import_my_names(globals(), "rsa_") 4 | 5 | del _import_my_names 6 | -------------------------------------------------------------------------------- /src-ed25519/supercop-ref/crypto_uint32.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_uint32_h 2 | #define crypto_uint32_h 3 | 4 | typedef unsigned int crypto_uint32; 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/pycryptopp/publickey/ecdsa.py: -------------------------------------------------------------------------------- 1 | from pycryptopp import _import_my_names 2 | 3 | _import_my_names(globals(), "ecdsa_") 4 | 5 | del _import_my_names 6 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/blake2.txt: -------------------------------------------------------------------------------- 1 | AlgorithmType: FileList 2 | Name: blake2.txt collection 3 | Test: TestVectors/blake2s.txt 4 | Test: TestVectors/blake2b.txt 5 | -------------------------------------------------------------------------------- /src/pycryptopp/cipher/aesmodule.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __INCL_AESMODULE_HPP 2 | #define __INCL_AESMODULE_HPP 3 | 4 | extern void 5 | init_aes(PyObject* module); 6 | 7 | #endif /* #ifndef __INCL_AESMODULE_HPP */ 8 | -------------------------------------------------------------------------------- /src/pycryptopp/publickey/ecdsamodule.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __INCL_ECDSAMODULE_HPP 2 | #define __INCL_ECDSAMODULE_HPP 3 | 4 | void 5 | init_ecdsa(PyObject* module); 6 | 7 | #endif /* #ifndef __INCL_ECDSAMODULE_HPP */ 8 | -------------------------------------------------------------------------------- /src/pycryptopp/hash/sha256module.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __INCL_SHA256MODULE_HPP 2 | #define __INCL_SHA256MODULE_HPP 3 | 4 | extern void 5 | init_sha256(PyObject* module); 6 | 7 | #endif /* #ifndef __INCL_SHA256MODULE_HPP */ 8 | -------------------------------------------------------------------------------- /COPYING.SPL.txt: -------------------------------------------------------------------------------- 1 | Permission is hereby granted to any person obtaining a copy of this work to 2 | deal in this work without restriction (including the rights to use, modify, 3 | distribute, sublicense, and/or sell copies). 4 | -------------------------------------------------------------------------------- /src/pycryptopp/cipher/xsalsa20module.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __INCL_XSALSA20MODULE_HPP 2 | #define __INCL_XSALSA20MODULE_HPP 3 | 4 | extern void init_xsalsa20(PyObject* module); 5 | 6 | #endif; /*#ifndef __INCL_XSALSA20MODULE_HPP*/ 7 | -------------------------------------------------------------------------------- /src-ed25519/supercop-ref/crypto_verify_32.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_verify_32_H 2 | #define crypto_verify_32_H 3 | 4 | #define crypto_verify_32_ref_BYTES 32 5 | extern int crypto_verify_32(const unsigned char *,const unsigned char *); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /src-ed25519/supercop-ref/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CC=gcc 3 | CFLAGS=-O2 -Wall 4 | 5 | OBJS= fe25519.o ge25519.o sc25519.o sha512-blocks.o sha512-hash.o ed25519.o randombytes.o verify.o 6 | test: test.o $(OBJS) 7 | gcc -o $@ $^ 8 | 9 | clean: 10 | rm -f *.o test 11 | -------------------------------------------------------------------------------- /src/pycryptopp/bench/bench_algs.py: -------------------------------------------------------------------------------- 1 | import bench_sigs, bench_ciphers, bench_hashes 2 | 3 | def bench(MAXTIME=10.0): 4 | bench_sigs.bench(MAXTIME) 5 | bench_ciphers.bench(MAXTIME) 6 | bench_hashes.bench(MAXTIME) 7 | 8 | if __name__ == '__main__': 9 | bench() 10 | -------------------------------------------------------------------------------- /src-ed25519/supercop-ref/sha512.h: -------------------------------------------------------------------------------- 1 | extern int crypto_hashblocks(unsigned char *statebytes,const unsigned char *in,unsigned long long inlen); 2 | extern int crypto_hash_sha512(unsigned char *out,const unsigned char *in,unsigned long long inlen); 3 | 4 | #define crypto_hash_sha512_BYTES 64 5 | -------------------------------------------------------------------------------- /src/pycryptopp/publickey/ed25519/__init__.py: -------------------------------------------------------------------------------- 1 | from keys import (BadSignatureError, SigningKey, VerifyingKey, __doc__) 2 | 3 | (BadSignatureError, SigningKey, VerifyingKey, __doc__) # hush pyflakes 4 | 5 | from _version import get_versions 6 | __version__ = get_versions()['version'] 7 | del get_versions 8 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include copyright COPYING.GPL COPYING.TGPPL.rst COPYING.MIT.txt COPYING.SPL.txt NEWS.rst README.rst 2 | include README.ed25519.rst 3 | include MANIFEST.in 4 | include versioneer.py 5 | include _doubleloadtester.cpp 6 | 7 | graft src/pycryptopp 8 | graft src-cryptopp 9 | graft src-ed25519 10 | graft misc 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.7" 4 | - "2.6" 5 | before_install: 6 | - sh -c set 7 | install: true 8 | script: python setup.py test 9 | notifications: 10 | email: false 11 | irc: 12 | channels: "chat.freenode.net#tahoe-lafs" 13 | on_success: always # for testing 14 | on_failure: always 15 | template: 16 | - "%{repository}#%{build_number} [%{branch}: %{commit} by %{author}] %{message}" 17 | - "Changes: %{compare_url} | Details: %{build_url}" 18 | -------------------------------------------------------------------------------- /src/pycryptopp/publickey/ed25519/_version.py: -------------------------------------------------------------------------------- 1 | 2 | # This file was generated by 'versioneer.py' (0.7) from 3 | # revision-control system data, or from the parent directory name of an 4 | # unpacked source archive. Distribution tarballs contain a pre-generated copy 5 | # of this file. 6 | 7 | version_version = '1.0' 8 | version_full = '519b740ca2c67f0ba4c2758ed1c17f11df561ee7' 9 | def get_versions(default={}, verbose=False): 10 | return {'version': version_version, 'full': version_full} 11 | 12 | -------------------------------------------------------------------------------- /misc/build_helpers/_build-wheels.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Based on https://github.com/pypa/python-manylinux-demo 4 | 5 | set -e -x 6 | 7 | # Compile wheels 8 | for PYBIN in /opt/python/cp2*/bin; do 9 | "${PYBIN}/pip" wheel --no-index --find-links file:///io/wheelhouse/ /io/ -w /wheelhouse/ 10 | done 11 | 12 | # Bundle external shared libraries into the wheels and write them to their 13 | # final location. 14 | for whl in /wheelhouse/pycryptopp-*.whl; do 15 | auditwheel repair "$whl" -w /io/wheelhouse/ 16 | done 17 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [easy_install] 2 | # pycryptopp actually does work at least as well as any package 3 | # works when zipped, but zipping eggs causes various problems 4 | # (http://bugs.python.org/setuptools/issue33 ), and generally makes it 5 | # harder for people to get at the source code, and doesn't actually 6 | # provide any benefits that I am aware of. 7 | zip_ok=False 8 | 9 | [aliases] 10 | build = build 11 | test = build test 12 | sdist = build sdist 13 | install = build install 14 | bdist_egg = build bdist_egg 15 | trial = build trial 16 | sdist_dsc = build sdist_dsc 17 | -------------------------------------------------------------------------------- /src-cryptopp/aes.h: -------------------------------------------------------------------------------- 1 | // aes.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file 4 | //! \brief Class file for the AES cipher (Rijndael) 5 | 6 | #ifndef CRYPTOPP_AES_H 7 | #define CRYPTOPP_AES_H 8 | 9 | #include "rijndael.h" 10 | 11 | NAMESPACE_BEGIN(CryptoPP) 12 | 13 | //! \class AES 14 | //! \brief AES block cipher (Rijndael) 15 | //! \sa AES winner, announced on 10/2/2000 16 | DOCUMENTED_TYPEDEF(Rijndael, AES); 17 | 18 | typedef RijndaelEncryption AESEncryption; 19 | typedef RijndaelDecryption AESDecryption; 20 | 21 | NAMESPACE_END 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /build/ 3 | /dist/ 4 | 5 | # extraversion.h is generated at build time, and never checked in 6 | /src-cryptopp/extraversion.h 7 | /src/pycryptopp/_version.py 8 | 9 | # the .egg-info is mostly generated during 'setup.py bdist_egg' .. 10 | /pycryptopp.egg-info/ 11 | # .. but stdeb.cfg is persistent, and tracked in version-control 12 | !/pycryptopp.egg-info/stdeb.cfg 13 | 14 | # if setup.py needs to install plugins from eggs to satisfy setup_requires: 15 | /setuptools_darcs*.egg 16 | /darcsver*.egg 17 | /pyutil*.egg 18 | 19 | # if ez_setup.py needs to build setuptools, that goes here 20 | /setuptools-*.egg 21 | /ez_setup.pyc 22 | /MANIFEST 23 | -------------------------------------------------------------------------------- /src-ed25519/supercop-ref/crypto_sign.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_sign_edwards25519sha512batch_H 2 | #define crypto_sign_edwards25519sha512batch_H 3 | 4 | #define SECRETKEYBYTES 64 5 | #define PUBLICKEYBYTES 32 6 | #define SIGNATUREBYTES 64 7 | 8 | extern int crypto_sign(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *); 9 | extern int crypto_sign_open(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *); 10 | extern int crypto_sign_keypair(unsigned char *,unsigned char *); 11 | extern int crypto_sign_publickey(unsigned char *pk, unsigned char *sk, unsigned char *seed); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src-ed25519/supercop-ref/verify.c: -------------------------------------------------------------------------------- 1 | #include "crypto_verify_32.h" 2 | 3 | int crypto_verify_32(const unsigned char *x,const unsigned char *y) 4 | { 5 | unsigned int differentbits = 0; 6 | #define F(i) differentbits |= x[i] ^ y[i]; 7 | F(0) 8 | F(1) 9 | F(2) 10 | F(3) 11 | F(4) 12 | F(5) 13 | F(6) 14 | F(7) 15 | F(8) 16 | F(9) 17 | F(10) 18 | F(11) 19 | F(12) 20 | F(13) 21 | F(14) 22 | F(15) 23 | F(16) 24 | F(17) 25 | F(18) 26 | F(19) 27 | F(20) 28 | F(21) 29 | F(22) 30 | F(23) 31 | F(24) 32 | F(25) 33 | F(26) 34 | F(27) 35 | F(28) 36 | F(29) 37 | F(30) 38 | F(31) 39 | return (1 & ((differentbits - 1) >> 8)) - 1; 40 | } 41 | -------------------------------------------------------------------------------- /src/pycryptopp/publickey/rsamodule.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __INCL_RSAMODULE_HPP 2 | #define __INCL_RSAMODULE_HPP 3 | 4 | void 5 | init_rsa(PyObject* module); 6 | 7 | extern PyMethodDef rsa_functions[]; 8 | 9 | extern PyObject * 10 | rsa_generate(PyObject *dummy, PyObject *args, PyObject *kwdict); 11 | extern const char*const rsa_generate__doc__; 12 | 13 | extern PyObject * 14 | rsa_create_verifying_key_from_string(PyObject *dummy, PyObject *args, PyObject *kwdict); 15 | extern const char*const rsa_create_verifying_key_from_string__doc__; 16 | 17 | extern PyObject * 18 | rsa_create_signing_key_from_string(PyObject *dummy, PyObject *args, PyObject *kwdict); 19 | extern const char*const rsa_create_signing_key_from_string__doc__; 20 | 21 | #endif /* #ifndef __INCL_RSAMODULE_HPP */ 22 | -------------------------------------------------------------------------------- /src-cryptopp/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \headerfile pch.h 4 | //! \brief Precompiled header file 5 | 6 | #ifndef CRYPTOPP_PCH_H 7 | #define CRYPTOPP_PCH_H 8 | 9 | # ifdef CRYPTOPP_GENERATE_X64_MASM 10 | #include "cpu.h" 11 | 12 | # else 13 | #include "config.h" 14 | 15 | #ifdef USE_PRECOMPILED_HEADERS 16 | #include "simple.h" 17 | #include "secblock.h" 18 | #include "misc.h" 19 | #include "smartptr.h" 20 | #include "stdcpp.h" 21 | #endif 22 | # endif 23 | 24 | // Enable file and line numbers, if available. 25 | // #if defined(_MSC_VER) && defined(_DEBUG) && defined(USE_PRECOMPILED_HEADERS) 26 | // # define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 27 | // # define new DEBUG_NEW 28 | // #endif 29 | 30 | #endif // CRYPTOPP_PCH_H 31 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/seed.txt: -------------------------------------------------------------------------------- 1 | AlgorithmType: SymmetricCipher 2 | Name: SEED/ECB 3 | Source: RFC 4269 4 | Key: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5 | Plaintext: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 6 | Ciphertext: 5E BA C6 E0 05 4E 16 68 19 AF F1 CC 6D 34 6C DB 7 | Test: Encrypt 8 | Key: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 9 | Plaintext: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 | Ciphertext: C1 1F 22 F2 01 40 50 50 84 48 35 97 E4 37 0F 43 11 | Test: Encrypt 12 | Key: 47 06 48 08 51 E6 1B E8 5D 74 BF B3 FD 95 61 85 13 | Plaintext: 83 A2 F8 A2 88 64 1F B9 A4 E9 A5 CC 2F 13 1C 7D 14 | Ciphertext: EE 54 D1 3E BC AE 70 6D 22 6B C3 14 2C D4 0D 4A 15 | Test: Encrypt 16 | Key: 28 DB C3 BC 49 FF D8 7D CF A5 09 B1 1D 42 2B E7 17 | Plaintext: B4 1E 6B E2 EB A8 4A 14 8E 2E ED 84 59 3C 5E C7 18 | Ciphertext: 9B 9B 7B FC D1 81 3C B9 5D 0B 36 18 F4 0F 51 22 19 | Test: Encrypt 20 | -------------------------------------------------------------------------------- /src-cryptopp/tiger.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_TIGER_H 2 | #define CRYPTOPP_TIGER_H 3 | 4 | #include "config.h" 5 | #include "iterhash.h" 6 | 7 | // Clang 3.3 integrated assembler crash on Linux 8 | // http://github.com/weidai11/cryptopp/issues/264 9 | #if defined(CRYPTOPP_LLVM_CLANG_VERSION) && (CRYPTOPP_LLVM_CLANG_VERSION < 30400) 10 | # define CRYPTOPP_DISABLE_TIGER_ASM 11 | #endif 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | /// Tiger 16 | class Tiger : public IteratedHashWithStaticTransform 17 | { 18 | public: 19 | static void InitState(HashWordType *state); 20 | static void Transform(word64 *digest, const word64 *data); 21 | void TruncatedFinal(byte *hash, size_t size); 22 | CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Tiger";} 23 | 24 | protected: 25 | static const word64 table[4*256+3]; 26 | }; 27 | 28 | NAMESPACE_END 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/pycryptopp/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | pycryptopp - Python wrappers for Crypto++ 3 | """ 4 | 5 | # we import our glue .so here, and then other modules use the copy in 6 | # sys.modules. 7 | 8 | import _pycryptopp 9 | __doc__ = _pycryptopp.__doc__ 10 | 11 | __version__ = "unknown" 12 | try: 13 | import _version 14 | except ImportError: 15 | # We're running in a tree that hasn't run "python ./setup.py 16 | # update_version", and didn't come with a _version.py, so we don't know 17 | # what our version is. This should not happen very often. 18 | pass 19 | else: 20 | __version__ = _version.__version__ 21 | 22 | def _import_my_names(thismodule, prefix): 23 | for name in dir(_pycryptopp): 24 | if name.startswith(prefix): 25 | myname = name[len(prefix):] 26 | thismodule[myname] = getattr(_pycryptopp, name) 27 | 28 | import publickey, hash, cipher 29 | 30 | quiet_pyflakes=[__version__, publickey, hash, cipher, _pycryptopp, __doc__, _import_my_names] 31 | del quiet_pyflakes 32 | -------------------------------------------------------------------------------- /src/pycryptopp/testvectors/KAT_AES/ECBGFSbox256e.txt: -------------------------------------------------------------------------------- 1 | [ENCRYPT] 2 | 3 | COUNT = 0 4 | KEY = 0000000000000000000000000000000000000000000000000000000000000000 5 | PLAINTEXT = 014730f80ac625fe84f026c60bfd547d 6 | CIPHERTEXT = 5c9d844ed46f9885085e5d6a4f94c7d7 7 | 8 | COUNT = 1 9 | KEY = 0000000000000000000000000000000000000000000000000000000000000000 10 | PLAINTEXT = 0b24af36193ce4665f2825d7b4749c98 11 | CIPHERTEXT = a9ff75bd7cf6613d3731c77c3b6d0c04 12 | 13 | COUNT = 2 14 | KEY = 0000000000000000000000000000000000000000000000000000000000000000 15 | PLAINTEXT = 761c1fe41a18acf20d241650611d90f1 16 | CIPHERTEXT = 623a52fcea5d443e48d9181ab32c7421 17 | 18 | COUNT = 3 19 | KEY = 0000000000000000000000000000000000000000000000000000000000000000 20 | PLAINTEXT = 8a560769d605868ad80d819bdba03771 21 | CIPHERTEXT = 38f2c7ae10612415d27ca190d27da8b4 22 | 23 | COUNT = 4 24 | KEY = 0000000000000000000000000000000000000000000000000000000000000000 25 | PLAINTEXT = 91fbef2d15a97816060bee1feaa49afe 26 | CIPHERTEXT = 1bc704f1bce135ceb810341b216d7abe 27 | -------------------------------------------------------------------------------- /src-cryptopp/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) 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 | -------------------------------------------------------------------------------- /src-cryptopp/trdlocal.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_TRDLOCAL_H 2 | #define CRYPTOPP_TRDLOCAL_H 3 | 4 | #include "config.h" 5 | 6 | #if !defined(NO_OS_DEPENDENCE) && defined(THREADS_AVAILABLE) 7 | 8 | #include "misc.h" 9 | 10 | #ifdef HAS_WINTHREADS 11 | typedef unsigned long ThreadLocalIndexType; 12 | #else 13 | #include 14 | typedef pthread_key_t ThreadLocalIndexType; 15 | #endif 16 | 17 | NAMESPACE_BEGIN(CryptoPP) 18 | 19 | //! thread local storage 20 | class CRYPTOPP_DLL ThreadLocalStorage : public NotCopyable 21 | { 22 | public: 23 | //! exception thrown by ThreadLocalStorage class 24 | class Err : public OS_Error 25 | { 26 | public: 27 | Err(const std::string& operation, int error); 28 | }; 29 | 30 | ThreadLocalStorage(); 31 | ~ThreadLocalStorage() CRYPTOPP_THROW; 32 | 33 | void SetValue(void *value); 34 | void *GetValue() const; 35 | 36 | private: 37 | ThreadLocalIndexType m_index; 38 | }; 39 | 40 | NAMESPACE_END 41 | 42 | #endif // THREADS_AVAILABLE 43 | 44 | #endif // CRYPTOPP_TRDLOCAL_H 45 | -------------------------------------------------------------------------------- /COPYING.MIT.txt: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person 2 | obtaining a copy of this software and associated documentation 3 | files (the "Software"), to deal in the Software without 4 | restriction, including without limitation the rights to use, 5 | copy, modify, merge, publish, distribute, sublicense, and/or sell 6 | copies of the Software, and to permit persons to whom the 7 | Software is furnished to do so, subject to the following 8 | conditions: 9 | 10 | The above copyright notice and this permission notice shall be 11 | included in all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 14 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 15 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 17 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /_doubleloadtester.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | PyDoc_STRVAR(_doubleloadtester__doc__, 5 | "_doubleloadtester -- just for testing ticket #9 per ticket #44\n\ 6 | "); 7 | 8 | static PyMethodDef _doubleloadtester_functions[] = { 9 | {NULL, NULL, 0, NULL} /* sentinel */ 10 | }; 11 | 12 | /* from Crypto++ */ 13 | #ifdef DISABLE_EMBEDDED_CRYPTOPP 14 | #include 15 | #else 16 | #include 17 | #endif 18 | 19 | #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ 20 | #define PyMODINIT_FUNC void 21 | #endif 22 | PyMODINIT_FUNC 23 | init_doubleloadtester(void) { 24 | const CryptoPP::NameValuePairs &my_nullNameValuePairs = CryptoPP::g_nullNameValuePairs; 25 | PyObject *module; 26 | 27 | 28 | printf("HELLO WORLD i'm doubleloadtester\n"); 29 | printf("%d\n", my_nullNameValuePairs.GetVoidValue("anything", typeid(0), NULL)); 30 | printf("GOODBYE i'm doubleloadtester\n"); 31 | 32 | module = Py_InitModule3("_doubleloadtester", _doubleloadtester_functions, _doubleloadtester__doc__); 33 | if (!module) 34 | return; 35 | } 36 | -------------------------------------------------------------------------------- /src/pycryptopp/test/test_from_Nikratio.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | # This was reported as triggering a "Use of uninitialised value of 4 | # size 4" under valgrind by Nikratio in pycryptopp-0.5.17 and Crypto++ 5 | # 5.6.0. See https://tahoe-lafs.org/trac/pycryptopp/ticket/67 6 | 7 | class T(unittest.TestCase): 8 | def test_t(self): 9 | import hmac 10 | import pycryptopp 11 | try: 12 | import hashlib 13 | except ImportError: 14 | # Oh nevermind. 15 | return 16 | import struct 17 | 18 | def encrypt(buf, passphrase, nonce): 19 | 20 | key = hashlib.sha256(passphrase + nonce).digest() 21 | cipher = pycryptopp.cipher.aes.AES(key) 22 | hmac_ = hmac.new(key, digestmod=hashlib.sha256) 23 | 24 | hmac_.update(buf) 25 | buf = cipher.process(buf) 26 | hash_ = cipher.process(hmac_.digest()) 27 | 28 | return ''.join( 29 | (struct.pack(' 3 | #include 4 | #include 5 | #include "crypto_sign.h" 6 | 7 | char *msg = "Hello World"; 8 | 9 | int main(int argc, char *argv[]) { 10 | unsigned char sk[SECRETKEYBYTES], vk[PUBLICKEYBYTES]; 11 | unsigned char *sigmsg, *newmsg; 12 | unsigned long long sigmsglen, newmsglen; 13 | int ret; 14 | crypto_sign_keypair(vk, sk); 15 | printf("got keypair\n"); 16 | sigmsg = malloc(strlen(msg)+1+BYTES); 17 | if (!sigmsg) 18 | return 1; 19 | crypto_sign(sigmsg, &sigmsglen, (unsigned char *)msg, strlen(msg)+1, sk); 20 | printf("got signature\n"); 21 | if (sigmsglen != strlen(msg)+1+BYTES) 22 | return 2; 23 | newmsg = malloc(sigmsglen); 24 | if (!newmsg) 25 | return 3; 26 | ret = crypto_sign_open(newmsg, &newmsglen, sigmsg, sigmsglen, vk); 27 | printf("verified signature\n"); 28 | if (ret == 0) 29 | printf("good!\n"); 30 | else 31 | printf("bad\n"); 32 | sigmsg[0] ^= 0x01; 33 | ret = crypto_sign_open(newmsg, &newmsglen, sigmsg, sigmsglen, vk); 34 | if (ret == 0) 35 | printf("bad: failed to detect simple corruption\n"); 36 | else 37 | printf("good: detected simple corruption\n"); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /src-ed25519/supercop-ref/ge25519.h: -------------------------------------------------------------------------------- 1 | #ifndef GE25519_H 2 | #define GE25519_H 3 | 4 | #include "fe25519.h" 5 | #include "sc25519.h" 6 | 7 | #define ge25519 crypto_sign_ed25519_ref_ge25519 8 | #define ge25519_base crypto_sign_ed25519_ref_ge25519_base 9 | #define ge25519_unpackneg_vartime crypto_sign_ed25519_ref_unpackneg_vartime 10 | #define ge25519_pack crypto_sign_ed25519_ref_pack 11 | #define ge25519_isneutral_vartime crypto_sign_ed25519_ref_isneutral_vartime 12 | #define ge25519_double_scalarmult_vartime crypto_sign_ed25519_ref_double_scalarmult_vartime 13 | #define ge25519_scalarmult_base crypto_sign_ed25519_ref_scalarmult_base 14 | 15 | typedef struct 16 | { 17 | fe25519 x; 18 | fe25519 y; 19 | fe25519 z; 20 | fe25519 t; 21 | } ge25519; 22 | 23 | extern const ge25519 ge25519_base; 24 | 25 | int ge25519_unpackneg_vartime(ge25519 *r, const unsigned char p[32]); 26 | 27 | void ge25519_pack(unsigned char r[32], const ge25519 *p); 28 | 29 | int ge25519_isneutral_vartime(const ge25519 *p); 30 | 31 | void ge25519_double_scalarmult_vartime(ge25519 *r, const ge25519 *p1, const sc25519 *s1, const ge25519 *p2, const sc25519 *s2); 32 | 33 | void ge25519_scalarmult_base(ge25519 *r, const sc25519 *s); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src-cryptopp/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 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | CRYPTOPP_DLL_TEMPLATE_CLASS DL_FixedBasePrecomputationImpl; 15 | 16 | class ModExpPrecomputation : public DL_GroupPrecomputation 17 | { 18 | public: 19 | // DL_GroupPrecomputation 20 | bool NeedConversions() const {return true;} 21 | Element ConvertIn(const Element &v) const {return m_mr->ConvertIn(v);} 22 | virtual Element ConvertOut(const Element &v) const {return m_mr->ConvertOut(v);} 23 | const AbstractGroup & GetGroup() const {return m_mr->MultiplicativeGroup();} 24 | Element BERDecodeElement(BufferedTransformation &bt) const {return Integer(bt);} 25 | void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {v.DEREncode(bt);} 26 | 27 | // non-inherited 28 | void SetModulus(const Integer &v) {m_mr.reset(new MontgomeryRepresentation(v));} 29 | const Integer & GetModulus() const {return m_mr->GetModulus();} 30 | 31 | private: 32 | value_ptr m_mr; 33 | }; 34 | 35 | NAMESPACE_END 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/sosemanuk.txt: -------------------------------------------------------------------------------- 1 | AlgorithmType: SymmetricCipher 2 | Source: Sosemanuk reference implementation, compiled with -DSOSEMANUK_VECTOR 3 | Key: A7C083FEB7 4 | IV: 00112233445566778899AABBCCDDEEFF 5 | Name: Sosemanuk 6 | Plaintext: r160 00 7 | Ciphertext: \ 8 | FE 81 D2 16 2C 9A 10 0D 04 89 5C 45 4A 77 51 5B\ 9 | BE 6A 43 1A 93 5C B9 0E 22 21 EB B7 EF 50 23 28\ 10 | 94 35 39 49 2E FF 63 10 C8 71 05 4C 28 89 CC 72\ 11 | 8F 82 E8 6B 1A FF F4 33 4B 61 27 A1 3A 15 5C 75\ 12 | 15 16 30 BD 48 2E B6 73 FF 5D B4 77 FA 6C 53 EB\ 13 | E1 A4 EC 38 C2 3C 54 00 C3 15 45 5D 93 A2 AC ED\ 14 | 95 98 60 47 27 FA 34 0D 5F 2A 8B D7 57 B7 78 33\ 15 | F7 4B D2 BC 04 93 13 C8 06 16 B4 A0 62 68 AE 35\ 16 | 0D B9 2E EC 4F A5 6C 17 13 74 A6 7A 80 C0 06 D0\ 17 | EA D0 48 CE 7B 64 0F 17 D3 D5 A6 2D 1F 25 1C 21 18 | Test: Encrypt 19 | Source: http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/ecrypt/trunk/submissions/sosemanuk/unverified.test-vectors?rev=189&view=auto 20 | Comment: Set 6, vector# 3 21 | Key: 0F62B5085BAE0154A7FA4DA0F34699EC3F92E5388BDE3184D72A7DD02376C91C 22 | IV: 288FF65DC42B92F960C72E95FC63CA31 23 | Plaintext: r131072 00 24 | CiphertextXorDigest: CC09FB7405DD54BBF09407B1D2033FBBAC53F388DD387A46F2B8FCFF692A7838353523A621A55D08DA0CA5348AE96D8B0D6A028F309982EF6628054D01B9A368 25 | Test: EncryptXorDigest 26 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/all.txt: -------------------------------------------------------------------------------- 1 | AlgorithmType: FileList 2 | Name: all.txt collection 3 | Test: TestVectors/tea.txt 4 | Test: TestVectors/wake.txt 5 | Test: TestVectors/camellia.txt 6 | Test: TestVectors/shacal2.txt 7 | Test: TestVectors/ttmac.txt 8 | Test: TestVectors/whrlpool.txt 9 | Test: TestVectors/dlies.txt 10 | Test: TestVectors/dsa.txt 11 | Test: TestVectors/dsa_1363.txt 12 | Test: TestVectors/dsa_rfc6979.txt 13 | #Test: TestVectors/ecdsa_rfc6979.txt 14 | Test: TestVectors/esign.txt 15 | Test: TestVectors/hmac.txt 16 | Test: TestVectors/nr.txt 17 | Test: TestVectors/rsa_oaep.txt 18 | Test: TestVectors/rsa_pkcs1_1_5.txt 19 | Test: TestVectors/rsa_pss.txt 20 | Test: TestVectors/rw.txt 21 | Test: TestVectors/seal.txt 22 | Test: TestVectors/sha.txt 23 | Test: TestVectors/keccak.txt 24 | Test: TestVectors/sha3_fips_202.txt 25 | Test: TestVectors/panama.txt 26 | Test: TestVectors/aes.txt 27 | Test: TestVectors/salsa.txt 28 | Test: TestVectors/chacha.txt 29 | #Test: TestVectors/tls_chacha.txt 30 | Test: TestVectors/vmac.txt 31 | Test: TestVectors/sosemanuk.txt 32 | Test: TestVectors/ccm.txt 33 | Test: TestVectors/gcm.txt 34 | Test: TestVectors/cmac.txt 35 | Test: TestVectors/eax.txt 36 | Test: TestVectors/mars.txt 37 | Test: TestVectors/blake2s.txt 38 | Test: TestVectors/blake2b.txt 39 | Test: TestVectors/hkdf.txt 40 | -------------------------------------------------------------------------------- /src/pycryptopp/bench/bench_ciphers.py: -------------------------------------------------------------------------------- 1 | from pycryptopp.cipher import aes, xsalsa20 2 | 3 | from common import insecurerandstr, rep_bench 4 | 5 | UNITS_PER_SECOND = 10**9 6 | 7 | class BenchCrypt(object): 8 | def __init__(self, klass, keysize): 9 | self.klass = klass 10 | self.keysize = keysize 11 | 12 | def __repr__(self): 13 | return "<%s-%d>" % (self.klass.__name__, self.keysize*8) 14 | 15 | def crypt_init(self, N): 16 | self.msg = insecurerandstr(N) 17 | self.key = insecurerandstr(self.keysize) 18 | 19 | def crypt(self, N): 20 | cryptor = self.klass(self.key) 21 | cryptor.process(self.msg) 22 | 23 | def bench_ciphers(MAXTIME): 24 | for (klass, keysize) in [ 25 | (aes.AES, 16), 26 | (aes.AES, 32), 27 | (xsalsa20.XSalsa20, 32), 28 | ]: 29 | ob = BenchCrypt(klass, keysize) 30 | print ob 31 | for (legend, size) in [ 32 | ("large (%d B)", 10**7), 33 | ]: 34 | print legend % size 35 | rep_bench(ob.crypt, size, UNITS_PER_SECOND=UNITS_PER_SECOND, MAXTIME=MAXTIME, MAXREPS=100, initfunc=ob.crypt_init) 36 | print 37 | 38 | print "nanoseconds per byte crypted" 39 | print 40 | 41 | def bench(MAXTIME=10.0): 42 | bench_ciphers(MAXTIME) 43 | 44 | if __name__ == '__main__': 45 | bench() 46 | -------------------------------------------------------------------------------- /src-cryptopp/hex.cpp: -------------------------------------------------------------------------------- 1 | // hex.cpp - 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 | 11 | namespace 12 | { 13 | const byte s_vecUpper[] = "0123456789ABCDEF"; 14 | const byte s_vecLower[] = "0123456789abcdef"; 15 | } 16 | 17 | void HexEncoder::IsolatedInitialize(const NameValuePairs ¶meters) 18 | { 19 | bool uppercase = parameters.GetValueWithDefault(Name::Uppercase(), true); 20 | m_filter->Initialize(CombinedNameValuePairs( 21 | parameters, 22 | MakeParameters(Name::EncodingLookupArray(), uppercase ? &s_vecUpper[0] : &s_vecLower[0], false)(Name::Log2Base(), 4, true))); 23 | } 24 | 25 | void HexDecoder::IsolatedInitialize(const NameValuePairs ¶meters) 26 | { 27 | BaseN_Decoder::IsolatedInitialize(CombinedNameValuePairs( 28 | parameters, 29 | MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 4, true))); 30 | } 31 | 32 | const int *HexDecoder::GetDefaultDecodingLookupArray() 33 | { 34 | static volatile bool s_initialized = false; 35 | static int s_array[256]; 36 | 37 | if (!s_initialized) 38 | { 39 | InitializeDecodingLookupArray(s_array, s_vecUpper, 16, true); 40 | s_initialized = true; 41 | } 42 | return s_array; 43 | } 44 | 45 | NAMESPACE_END 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/ttmac.txt: -------------------------------------------------------------------------------- 1 | AlgorithmType: MAC 2 | Name: Two-Track-MAC 3 | Source: NESSIE submission 4 | Comment: Key for all test cases 5 | Key: 00112233445566778899aabbccddeeff01234567 6 | Comment: Test Case 1 7 | Message: "" 8 | MAC: 2dec8ed4a0fd712ed9fbf2ab466ec2df21215e4a 9 | Test: Verify 10 | Comment: Test Case 2 11 | Message: "a" 12 | MAC: 5893e3e6e306704dd77ad6e6ed432cde321a7756 13 | Test: Verify 14 | Comment: Test Case 3 15 | Message: "abc" 16 | MAC: 70bfd1029797a5c16da5b557a1f0b2779b78497e 17 | Test: Verify 18 | Comment: Test Case 4 19 | Message: "message digest" 20 | MAC: 8289f4f19ffe4f2af737de4bd71c829d93a972fa 21 | Test: Verify 22 | Comment: Test Case 5 23 | Message: "abcdefghijklmnopqrstuvwxyz" 24 | MAC: 2186ca09c5533198b7371f245273504ca92bae60 25 | Test: Verify 26 | Comment: Test Case 6 27 | Message: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 28 | MAC: 8a7bf77aef62a2578497a27c0d6518a429e7c14d 29 | Test: Verify 30 | Comment: Test Case 7 31 | Message: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" 32 | MAC: 54bac392a886806d169556fcbb6789b54fb364fb 33 | Test: Verify 34 | Comment: Test Case 8 35 | Message: r8 "1234567890" 36 | MAC: 0ced2c9f8f0d9d03981ab5c8184bac43dd54c484 37 | Test: Verify 38 | Comment: Test Case 9 39 | Message: r15625 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 40 | MAC: 27b3aedb5df8b629f0142194daa3846e1895f3d2 41 | -------------------------------------------------------------------------------- /src/pycryptopp/bench/bench_hashes.py: -------------------------------------------------------------------------------- 1 | from pycryptopp.hash import sha256 2 | 3 | from common import insecurerandstr, rep_bench 4 | 5 | UNITS_PER_SECOND = 10**9 6 | 7 | class SHA256(object): 8 | def proc_init(self, N): 9 | self.msg = insecurerandstr(N) 10 | 11 | def proc(self, N): 12 | h = sha256.SHA256() 13 | h.update(self.msg) 14 | h.digest() 15 | 16 | def generate_hash_benchers(): 17 | try: 18 | import hashlib 19 | except ImportError: 20 | return [SHA256] 21 | else: 22 | class hashlibSHA256(object): 23 | def proc_init(self, N): 24 | self.msg = insecurerandstr(N) 25 | 26 | def proc(self, N): 27 | h = hashlib.sha256() 28 | h.update(self.msg) 29 | h.digest() 30 | 31 | return [SHA256, hashlibSHA256] 32 | 33 | def bench_hashes(MAXTIME): 34 | for klass in generate_hash_benchers(): 35 | print klass 36 | ob = klass() 37 | for (legend, size) in [ 38 | ("large (%d B)", 10**7), 39 | ]: 40 | print legend % size 41 | rep_bench(ob.proc, size, UNITS_PER_SECOND=UNITS_PER_SECOND, MAXTIME=MAXTIME, MAXREPS=100, initfunc=ob.proc_init) 42 | print 43 | 44 | print "nanoseconds per byte hashed" 45 | print 46 | 47 | 48 | def bench(MAXTIME=10.0): 49 | bench_hashes(MAXTIME) 50 | 51 | if __name__ == '__main__': 52 | bench() 53 | -------------------------------------------------------------------------------- /NEWS.rst: -------------------------------------------------------------------------------- 1 | 2016-02-03 Zooko Wilcox 2 | 3 | • release pycryptopp-0.7.1 4 | • disable optimized assembly implementations by default (#85) 5 | • tweaks to the benchmarking scripts 6 | 7 | 2012-03-13 Zooko Wilcox-O'Hearn 8 | 9 | • src/pycryptopp/_version.py: release pycryptopp-0.6.0 10 | • add Ed25519 signatures (#75) 11 | • add XSalsa20 cipher (#40) 12 | • switch from darcs to git for revision control 13 | • pycryptopp version numbers now include a decimal encoding of the 14 | git revid 15 | • reorganize the source tree and the version number generation 16 | • aesmodule.cpp: validate size of IV and throw exception if it is not 16 (#70) 17 | • fixed compile errors with gcc-4.7.0 (#78) 18 | • fixed compile errors concerning "CryptoPP::g_nullNameValuePairs" (#77) 19 | • suppress warnings from valgrind with new OpenSSL 1.0.1 on Fedora (#82) 20 | • raise Python exception instead of uncaught C++ exception 21 | (resulting in abort) when deserializing malformed RSA keys (#83) 22 | 23 | 2009-09-15 Zooko Wilcox-O'Hearn 24 | 25 | • release pycryptopp-0.5.17 26 | • publickey/rsamodule.cpp, publickey/ecdsamodule.cpp, 27 | hash/sha256module.cpp, cipher/aesmodule.cpp: fix a segfault bug 28 | when sizeof(size_t) > sizeof(int) (not exploitable); thanks Nathan 29 | Wilcox and Brian Warner. (#19) 30 | 31 | 2009-07-27 Zooko Wilcox-O'Hearn 32 | 33 | • release pycryptopp-0.5.16 34 | • setup.py, misc/: a few improvements to the build/packaging 35 | -------------------------------------------------------------------------------- /src-cryptopp/dsa.cpp: -------------------------------------------------------------------------------- 1 | // dsa.cpp - 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 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/cmac.txt: -------------------------------------------------------------------------------- 1 | AlgorithmType: MAC 2 | Name: CMAC(AES) 3 | Source: RFC 4493 4 | Key: 2b7e1516 28aed2a6 abf71588 09cf4f3c 5 | Message: 6 | MAC: bb1d6929 e9593728 7fa37d12 9b756746 7 | Test: Verify 8 | Message: 6bc1bee2 2e409f96 e93d7e11 7393172a 9 | MAC: 070a16b4 6b4d4144 f79bdd9d d04a287c 10 | Test: Verify 11 | Message: 6bc1bee2 2e409f96 e93d7e11 7393172a ae2d8a57 1e03ac9c 9eb76fac 45af8e51 30c81c46 a35ce411 12 | MAC: dfa66747 de9ae630 30ca3261 1497c827 13 | Test: Verify 14 | Message: 6bc1bee2 2e409f96 e93d7e11 7393172a ae2d8a57 1e03ac9c 9eb76fac 45af8e51 30c81c46 a35ce411 e5fbc119 1a0a52ef f69f2445 df4f9b17 ad2b417b e66c3710 15 | MAC: 51f0bebf 7e3b9d92 fc497417 79363cfe 16 | Test: Verify 17 | MAC: 51f0bebf 7e3b9d92 fc497417 79363cff 18 | Test: NotVerify 19 | 20 | AlgorithmType: MAC 21 | Name: CMAC(DES-EDE3) 22 | Source: http://csrc.nist.gov/groups/STM/cavp/documents/mac/cmactestvectors.zip 23 | Key: f8fba7b9b3e9d68a 2f70bfd304d32a15 9e13453e0d16928a 24 | Message: 25 | MAC: eb61515b 26 | Test: VerifyTruncated 27 | Key: 344a6732dc5e5431 e98a4f7c323dc1c4 6b0275dc150e68e9 28 | Message: 25db0710fb165d316e7c32dd25648ed0 29 | MAC: 862f0e2b 30 | Test: VerifyTruncated 31 | Key: 20ae32c49bab3bf8 f86bb66173fb54d5 3e700868c46bc291 32 | Message: 582bd9c8c36ec815d0a9 33 | MAC: 0d62f14f 34 | Test: VerifyTruncated 35 | Key: 62232501b9e9c1b5 54209d7c075d2c31 73a2f289a84c49ce 36 | Message: adaf4bfffab79ffb60b94647faac634929c56e694052881881e60b1149b6 37 | MAC: a05674f2c905d153 38 | Test: Verify 39 | -------------------------------------------------------------------------------- /src-cryptopp/oaep.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_OAEP_H 2 | #define CRYPTOPP_OAEP_H 3 | 4 | #include "cryptlib.h" 5 | #include "pubkey.h" 6 | #include "sha.h" 7 | 8 | NAMESPACE_BEGIN(CryptoPP) 9 | 10 | //! _ 11 | class CRYPTOPP_DLL OAEP_Base : public PK_EncryptionMessageEncodingMethod 12 | { 13 | public: 14 | bool ParameterSupported(const char *name) const {return strcmp(name, Name::EncodingParameters()) == 0;} 15 | size_t MaxUnpaddedLength(size_t paddedLength) const; 16 | void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs ¶meters) const; 17 | DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs ¶meters) const; 18 | 19 | protected: 20 | virtual unsigned int DigestSize() const =0; 21 | virtual HashTransformation * NewHash() const =0; 22 | virtual MaskGeneratingFunction * NewMGF() const =0; 23 | }; 24 | 25 | //! EME-OAEP, for use with classes derived from TF_ES 26 | template 27 | class OAEP : public OAEP_Base, public EncryptionStandard 28 | { 29 | public: 30 | static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string("OAEP-") + MGF::StaticAlgorithmName() + "(" + H::StaticAlgorithmName() + ")";} 31 | typedef OAEP EncryptionMessageEncodingMethod; 32 | 33 | protected: 34 | unsigned int DigestSize() const {return H::DIGESTSIZE;} 35 | HashTransformation * NewHash() const {return new H;} 36 | MaskGeneratingFunction * NewMGF() const {return new MGF;} 37 | }; 38 | 39 | CRYPTOPP_DLL_TEMPLATE_CLASS OAEP; 40 | 41 | NAMESPACE_END 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src-cryptopp/dsa.h: -------------------------------------------------------------------------------- 1 | // dsa.h - 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 | //! Java nad .Net use the DER format, and OpenPGP uses the OpenPGP format. 17 | enum DSASignatureFormat { 18 | //! \brief Crypto++ native signature encoding format 19 | DSA_P1363, 20 | //! \brief signature encoding format used by Java and .Net 21 | DSA_DER, 22 | //! \brief OpenPGP signature encoding format 23 | DSA_OPENPGP 24 | }; 25 | 26 | //! \brief Converts between signature encoding formats 27 | //! \param buffer byte buffer for the converted signature encoding 28 | //! \param bufferSize the length of the converted signature encoding buffer 29 | //! \param toFormat the source signature format 30 | //! \param signature byte buffer for the existing signature encoding 31 | //! \param signatureLen the length of the existing signature encoding buffer 32 | //! \param fromFormat the source signature format 33 | //! \details This function converts between these formats, and returns length 34 | //! of signature in the target format. If toFormat == DSA_P1363, then 35 | //! bufferSize must equal publicKey.SignatureLength() 36 | size_t DSAConvertSignatureFormat(byte *buffer, size_t bufferSize, DSASignatureFormat toFormat, 37 | const byte *signature, size_t signatureLen, DSASignatureFormat fromFormat); 38 | 39 | NAMESPACE_END 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src-cryptopp/serpent.h: -------------------------------------------------------------------------------- 1 | // serpent.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file serpent.h 4 | //! \brief Classes for the Serpent block cipher 5 | 6 | #ifndef CRYPTOPP_SERPENT_H 7 | #define CRYPTOPP_SERPENT_H 8 | 9 | #include "seckey.h" 10 | #include "secblock.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | //! \class Serpent_Info 15 | //! \brief Serpent block cipher information 16 | struct Serpent_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8>, public FixedRounds<32> 17 | { 18 | CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Serpent";} 19 | }; 20 | 21 | //! \class Serpent 22 | //! \brief Serpent block cipher 23 | /// \sa Serpent 24 | class Serpent : public Serpent_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_key; 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 | }; 40 | 41 | class CRYPTOPP_NO_VTABLE Dec : public Base 42 | { 43 | public: 44 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 45 | }; 46 | 47 | public: 48 | typedef BlockCipherFinal Encryption; 49 | typedef BlockCipherFinal Decryption; 50 | }; 51 | 52 | typedef Serpent::Encryption SerpentEncryption; 53 | typedef Serpent::Decryption SerpentDecryption; 54 | 55 | NAMESPACE_END 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src-cryptopp/cbcmac.h: -------------------------------------------------------------------------------- 1 | // cbcmac.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file 4 | //! \headerfile cbcmac.h 5 | //! \brief Classes for CBC MAC 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 | //! _ 16 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_MAC_Base : public MessageAuthenticationCode 17 | { 18 | public: 19 | CBC_MAC_Base() : m_counter(0) {} 20 | 21 | void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); 22 | void Update(const byte *input, size_t length); 23 | void TruncatedFinal(byte *mac, size_t size); 24 | unsigned int DigestSize() const {return const_cast(this)->AccessCipher().BlockSize();} 25 | 26 | protected: 27 | virtual BlockCipher & AccessCipher() =0; 28 | 29 | private: 30 | void ProcessBuf(); 31 | SecByteBlock m_reg; 32 | unsigned int m_counter; 33 | }; 34 | 35 | //! CBC-MAC 36 | /*! Compatible with FIPS 113. T should be a class derived from BlockCipherDocumentation. 37 | Secure only for fixed length messages. For variable length messages use CMAC or DMAC. 38 | */ 39 | template 40 | class CBC_MAC : public MessageAuthenticationCodeImpl >, public SameKeyLengthAs 41 | { 42 | public: 43 | CBC_MAC() {} 44 | CBC_MAC(const byte *key, size_t length=SameKeyLengthAs::DEFAULT_KEYLENGTH) 45 | {this->SetKey(key, length);} 46 | 47 | static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";} 48 | 49 | private: 50 | BlockCipher & AccessCipher() {return m_cipher;} 51 | typename T::Encryption m_cipher; 52 | }; 53 | 54 | NAMESPACE_END 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/pycryptopp/bench/common.py: -------------------------------------------------------------------------------- 1 | msg = "crypto libraries should come with benchmarks" 2 | 3 | try: 4 | import pyutil.benchutil 5 | rep_bench = pyutil.benchutil.rep_bench 6 | except (ImportError, AttributeError): 7 | import platform, time 8 | if 'windows' in platform.system().lower(): 9 | clock = time.clock 10 | else: 11 | clock = time.time 12 | 13 | def this_rep_bench(func, N, UNITS_PER_SECOND, MAXTIME, MAXREPS, initfunc=None): 14 | tt = time.time 15 | 16 | if initfunc is not None: 17 | initfunc(N) 18 | 19 | meanc = 0 20 | MAXREPS = 100 21 | 22 | timeout = tt() + MAXTIME 23 | 24 | for i in range(MAXREPS): 25 | startc = clock() 26 | 27 | func(N) 28 | 29 | stopc = clock() 30 | 31 | deltac = stopc - startc 32 | if deltac <= 0: 33 | print "clock jump backward or wrapped -- ignoring this sample. startc: %s, stopc: %s, deltac: %s" % (startc, stopc, deltac,) 34 | else: 35 | meanc += deltac 36 | 37 | if time.time() >= timeout: 38 | break 39 | 40 | num = i+1 41 | meanc *= UNITS_PER_SECOND 42 | meanc /= num 43 | meanc /= N 44 | 45 | res = { 46 | 'meanc': meanc, 47 | 'num': num 48 | } 49 | print "mean: %(meanc)#8.03e (of %(num)6d)" % res 50 | rep_bench = this_rep_bench 51 | 52 | import random as insecurerandom 53 | def insecurerandstr(n): 54 | return ''.join(map(chr, map(insecurerandom.randrange, [0]*n, [256]*n))) 55 | 56 | def calib_clock(): 57 | interval = 1.0 58 | 59 | import time 60 | tc = time.clock 61 | tt = time.time 62 | 63 | def measure_sleep(x, clock): 64 | st = clock() 65 | time.sleep(x) 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/pycryptopp/hash/sha256.py: -------------------------------------------------------------------------------- 1 | from pycryptopp import _import_my_names 2 | 3 | # These initializations to None are just to pacify pyflakes, which 4 | # doesn't understand that we have to do some funky import trickery 5 | # below in _import_my_names() in order to get sensible namespaces. 6 | SHA256=None 7 | Error=None 8 | 9 | _import_my_names(globals(), "sha256_") 10 | 11 | del _import_my_names 12 | 13 | def start_up_self_test(): 14 | """ 15 | This is a quick test intended to detect major errors such as the library being 16 | miscompiled and segfaulting or returning incorrect answers. We've had problems 17 | of that kind many times, thus justifying running this self-test on import. 18 | This idea was suggested to me by the second edition of "Practical 19 | Cryptography" by Ferguson, Schneier, and Kohno. 20 | This test was copied from pycryptopp/test/test_sha256.py on 2010-09-04. 21 | 22 | This test takes up to 1.5 milliseconds on a VirtualBox instance on 23 | my Macbook Pro (fast 64-bit Intel dual-core). 24 | 25 | Test that updating a hasher with various sized inputs yields 26 | the expected answer. This is somewhat redundant with 27 | test_chunksize(), but that's okay. This one exercises some 28 | slightly different situations (such as finalizing a hash after 29 | different length inputs.) This one is recursive so that there 30 | is a single fixed result that we expect. 31 | """ 32 | hx = SHA256() 33 | s = ''.join([ chr(c) for c in range(65) ]) 34 | for i in range(0, 65): 35 | hy = SHA256(s[:i]).digest() 36 | hx.update(hy) 37 | for i in range(0, 65): 38 | hx.update(chr(0xFE)) 39 | hx.update(s[:64]) 40 | if hx.hexdigest().lower() != '5191c7841dd4e16aa454d40af924585dffc67157ffdbfd0236acddd07901629d': 41 | raise Error("pycryptopp failed startup self-test. Please run pycryptopp unit tests.") 42 | 43 | start_up_self_test() 44 | -------------------------------------------------------------------------------- /src-cryptopp/hex.h: -------------------------------------------------------------------------------- 1 | // hex.h - 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 | //! \class HexEncoder 15 | //! \brief Converts given data to base 16 16 | class CRYPTOPP_DLL HexEncoder : public SimpleProxyFilter 17 | { 18 | public: 19 | //! \brief Construct a HexEncoder 20 | //! \param attachment a BufferedTrasformation to attach to this object 21 | //! \param uppercase a flag indicating uppercase output 22 | //! \param groupSize the size of the output grouping 23 | //! \param separator the separator to use between groups 24 | //! \param terminator the terminator append after processing 25 | HexEncoder(BufferedTransformation *attachment = NULL, bool uppercase = true, int groupSize = 0, const std::string &separator = ":", const std::string &terminator = "") 26 | : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment) 27 | { 28 | IsolatedInitialize(MakeParameters(Name::Uppercase(), uppercase)(Name::GroupSize(), groupSize)(Name::Separator(), ConstByteArrayParameter(separator))(Name::Terminator(), ConstByteArrayParameter(terminator))); 29 | } 30 | 31 | void IsolatedInitialize(const NameValuePairs ¶meters); 32 | }; 33 | 34 | //! \class HexDecoder 35 | //! \brief Decode base 16 data back to bytes 36 | class CRYPTOPP_DLL HexDecoder : public BaseN_Decoder 37 | { 38 | public: 39 | //! \brief Construct a HexDecoder 40 | //! \param attachment a BufferedTrasformation to attach to this object 41 | HexDecoder(BufferedTransformation *attachment = NULL) 42 | : BaseN_Decoder(GetDefaultDecodingLookupArray(), 4, attachment) {} 43 | 44 | void IsolatedInitialize(const NameValuePairs ¶meters); 45 | 46 | private: 47 | static const int * CRYPTOPP_API GetDefaultDecodingLookupArray(); 48 | }; 49 | 50 | NAMESPACE_END 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src-cryptopp/sosemanuk.h: -------------------------------------------------------------------------------- 1 | // sosemanuk.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file sosemanuk.h 4 | //! \brief Classes for Sosemanuk stream cipher 5 | 6 | #ifndef CRYPTOPP_SOSEMANUK_H 7 | #define CRYPTOPP_SOSEMANUK_H 8 | 9 | #include "strciphr.h" 10 | #include "secblock.h" 11 | 12 | // Clang due to "Inline assembly operands don't work with .intel_syntax" 13 | // https://llvm.org/bugs/show_bug.cgi?id=24232 14 | #if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) 15 | # define CRYPTOPP_DISABLE_SOSEMANUK_ASM 16 | #endif 17 | 18 | NAMESPACE_BEGIN(CryptoPP) 19 | 20 | //! algorithm info 21 | struct SosemanukInfo : public VariableKeyLength<16, 1, 32, 1, SimpleKeyingInterface::UNIQUE_IV, 16> 22 | { 23 | CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Sosemanuk";} 24 | }; 25 | 26 | //! _ 27 | class SosemanukPolicy : public AdditiveCipherConcretePolicy, public SosemanukInfo 28 | { 29 | protected: 30 | void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); 31 | void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); 32 | void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length); 33 | bool CipherIsRandomAccess() const {return false;} 34 | #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) && !defined(CRYPTOPP_DISABLE_SOSEMANUK_ASM) 35 | unsigned int GetAlignment() const; 36 | unsigned int GetOptimalBlockSize() const; 37 | #endif 38 | 39 | FixedSizeSecBlock m_key; 40 | FixedSizeAlignedSecBlock m_state; 41 | }; 42 | 43 | //! Sosemanuk 44 | struct Sosemanuk : public SosemanukInfo, public SymmetricCipherDocumentation 45 | { 46 | typedef SymmetricCipherFinal >, SosemanukInfo> Encryption; 47 | typedef Encryption Decryption; 48 | }; 49 | 50 | NAMESPACE_END 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/whrlpool.txt: -------------------------------------------------------------------------------- 1 | AlgorithmType: MessageDigest 2 | Name: Whirlpool 3 | Source: ISO test vectors in http://planeta.terra.com.br/informatica/paulobarreto/whirlpool.zip 4 | Message: "" 5 | Digest: 19FA61D75522A466 9B44E39C1D2E1726 C530232130D407F8 9AFEE0964997F7A7\ 6 | 3E83BE698B288FEB CF88E3E03C4F0757 EA8964E59B63D937 08B138CC42A66EB3 7 | Test: Verify 8 | Message: "a" 9 | Digest: 8ACA2602792AEC6F 11A67206531FB7D7 F0DFF59413145E69 73C45001D0087B42\ 10 | D11BC645413AEFF6 3A42391A39145A59 1A92200D560195E5 3B478584FDAE231A 11 | Test: Verify 12 | Message: "abc" 13 | Digest: 4E2448A4C6F486BB 16B6562C73B4020B F3043E3A731BCE72 1AE1B303D97E6D4C\ 14 | 7181EEBDB6C57E27 7D0E34957114CBD6 C797FC9D95D8B582 D225292076D4EEF5 15 | Test: Verify 16 | Message: "message digest" 17 | Digest: 378C84A4126E2DC6 E56DCC7458377AAC 838D00032230F53C E1F5700C0FFB4D3B\ 18 | 8421557659EF55C1 06B4B52AC5A4AAA6 92ED920052838F33 62E86DBD37A8903E 19 | Test: Verify 20 | Message: "abcdefghijklmnopqrstuvwxyz" 21 | Digest: F1D754662636FFE9 2C82EBB9212A484A 8D38631EAD4238F5 442EE13B8054E41B\ 22 | 08BF2A9251C30B6A 0B8AAE86177AB4A6 F68F673E7207865D 5D9819A3DBA4EB3B 23 | Test: Verify 24 | Message: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" 25 | Digest: DC37E008CF9EE69B F11F00ED9ABA2690 1DD7C28CDEC066CC 6AF42E40F82F3A1E\ 26 | 08EBA26629129D8F B7CB57211B9281A6 5517CC879D7B9621 42C65F5A7AF01467 27 | Test: Verify 28 | Message: r8 "1234567890" 29 | Digest: 466EF18BABB0154D 25B9D38A6414F5C0 8784372BCCB204D6 549C4AFADB601429\ 30 | 4D5BD8DF2A6C44E5 38CD047B2681A51A 2C60481E88C5A20B 2C2A80CF3A9A083B 31 | Test: Verify 32 | Message: "abcdbcdecdefdefgefghfghighijhijk" 33 | Digest: 2A987EA40F917061 F5D6F0A0E4644F48 8A7A5A52DEEE6562 07C562F988E95C69\ 34 | 16BDC8031BC5BE1B 7B947639FE050B56 939BAAA0ADFF9AE6 745B7B181C3BE3FD 35 | Test: Verify 36 | Message: r1000000 "a" 37 | Digest: 0C99005BEB57EFF5 0A7CF005560DDF5D 29057FD86B20BFD6 2DECA0F1CCEA4AF5\ 38 | 1FC15490EDDC47AF 32BB2B66C34FF9AD 8C6008AD677F7712 6953B226E4ED8B01 39 | Test: Verify 40 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/vmac.txt: -------------------------------------------------------------------------------- 1 | AlgorithmType: MAC 2 | Name: VMAC(AES)-64 3 | Source: http://www.fastcrypto.org/vmac/draft-krovetz-vmac-01.txt 4 | Key: "abcdefghijklmnop" 5 | IV: "bcdefghi" 6 | Message: "" 7 | MAC: 2576BE1C56D8B81B 8 | Test: Verify 9 | Message: "abc" 10 | MAC: 2D376CF5B1813CE5 11 | Test: Verify 12 | Message: r16 "abc" 13 | MAC: E8421F61D573D298 14 | Test: Verify 15 | Message: r100 "abc" 16 | MAC: 4492DF6C5CAC1BBE 17 | Test: Verify 18 | Message: r1000000 "abc" 19 | MAC: 09BA597DD7601113 20 | Test: Verify 21 | Message: r42 "abc" "ab" 22 | MAC: D638B73921F184DE 23 | Test: Verify 24 | Message: r170 "abc" "ab" 25 | MAC: 9DA310281E6FD0A0 26 | Test: Verify 27 | Message: r65 "a" 28 | MAC: 90 ea 57 cb 51 bc 92 a3 29 | Test: Verify 30 | Message: r129 "a" 31 | MAC: 86 34 83 87 d1 3d 82 33 32 | Test: Verify 33 | Message: r65 "abc" 34 | MAC: E86A86EC77A8BF61 35 | Test: Verify 36 | Message: "abc" 37 | MAC: 2D376CF5B1813CE0 38 | Test: NotVerify 39 | 40 | AlgorithmType: MAC 41 | Name: VMAC(AES)-128 42 | Source: http://www.fastcrypto.org/vmac/draft-krovetz-vmac-01.txt 43 | Key: "abcdefghijklmnop" 44 | IV: "bcdefghi" 45 | Message: "" 46 | MAC: 472766C70F74ED23481D6D7DE4E80DAC 47 | Test: Verify 48 | Message: "abc" 49 | MAC: 4EE815A06A1D71EDD36FC75D51188A42 50 | Test: Verify 51 | Message: r16 "abc" 52 | MAC: 09F2C80C8E1007A0C12FAE19FE4504AE 53 | Test: Verify 54 | Message: r100 "abc" 55 | MAC: 66438817154850C61D8A412164803BCB 56 | Test: Verify 57 | Message: r1000000 "abc" 58 | MAC: 2B6B02288FFC461B75485DE893C629DC 59 | Test: Verify 60 | Message: r42 "abc" "ab" 61 | MAC: F7E95FE3DA8DB9E6BB973E65D0B4CEA5 62 | Test: Verify 63 | Message: r170 "abc" "ab" 64 | MAC: BF53B8D2D70C05A85880C2E21CAF1299 65 | Test: Verify 66 | Message: r65 "a" 67 | MAC: b2 9b 00 76 0a 58 c7 ab 92 d6 60 24 d6 9c 1b 92 68 | Test: Verify 69 | Message: r129 "a" 70 | MAC: a7 e5 2c 32 89 d9 b7 3b 53 57 6f 05 95 85 ee 79 71 | Test: Verify 72 | Message: r65 "abc" 73 | MAC: 0A1B2F973044F469F405917E45010334 74 | Test: Verify 75 | Message: "abc" 76 | MAC: 4EE815A06A1D71EDD36FC75D51188A40 77 | Test: NotVerify 78 | -------------------------------------------------------------------------------- /src-ed25519/supercop-ref/sha512-hash.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20080913 3 | D. J. Bernstein 4 | Public domain. 5 | */ 6 | 7 | #include "sha512.h" 8 | 9 | extern int crypto_hashblocks(unsigned char *statebytes,const unsigned char *in,unsigned long long inlen); 10 | 11 | #define blocks crypto_hashblocks 12 | 13 | static const unsigned char iv[64] = { 14 | 0x6a,0x09,0xe6,0x67,0xf3,0xbc,0xc9,0x08, 15 | 0xbb,0x67,0xae,0x85,0x84,0xca,0xa7,0x3b, 16 | 0x3c,0x6e,0xf3,0x72,0xfe,0x94,0xf8,0x2b, 17 | 0xa5,0x4f,0xf5,0x3a,0x5f,0x1d,0x36,0xf1, 18 | 0x51,0x0e,0x52,0x7f,0xad,0xe6,0x82,0xd1, 19 | 0x9b,0x05,0x68,0x8c,0x2b,0x3e,0x6c,0x1f, 20 | 0x1f,0x83,0xd9,0xab,0xfb,0x41,0xbd,0x6b, 21 | 0x5b,0xe0,0xcd,0x19,0x13,0x7e,0x21,0x79 22 | } ; 23 | 24 | typedef unsigned long long uint64; 25 | 26 | int crypto_hash_sha512(unsigned char *out,const unsigned char *in,unsigned long long inlen) 27 | { 28 | unsigned char h[64]; 29 | unsigned char padded[256]; 30 | int i; 31 | unsigned long long bytes = inlen; 32 | 33 | for (i = 0;i < 64;++i) h[i] = iv[i]; 34 | 35 | blocks(h,in,inlen); 36 | in += inlen; 37 | inlen &= 127; 38 | in -= inlen; 39 | 40 | for (i = 0;i < inlen;++i) padded[i] = in[i]; 41 | padded[inlen] = 0x80; 42 | 43 | if (inlen < 112) { 44 | for (i = inlen + 1;i < 119;++i) padded[i] = 0; 45 | padded[119] = bytes >> 61; 46 | padded[120] = bytes >> 53; 47 | padded[121] = bytes >> 45; 48 | padded[122] = bytes >> 37; 49 | padded[123] = bytes >> 29; 50 | padded[124] = bytes >> 21; 51 | padded[125] = bytes >> 13; 52 | padded[126] = bytes >> 5; 53 | padded[127] = bytes << 3; 54 | blocks(h,padded,128); 55 | } else { 56 | for (i = inlen + 1;i < 247;++i) padded[i] = 0; 57 | padded[247] = bytes >> 61; 58 | padded[248] = bytes >> 53; 59 | padded[249] = bytes >> 45; 60 | padded[250] = bytes >> 37; 61 | padded[251] = bytes >> 29; 62 | padded[252] = bytes >> 21; 63 | padded[253] = bytes >> 13; 64 | padded[254] = bytes >> 5; 65 | padded[255] = bytes << 3; 66 | blocks(h,padded,256); 67 | } 68 | 69 | for (i = 0;i < 64;++i) out[i] = h[i]; 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /src/pycryptopp/test/test_ed25519_kat.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from pkg_resources import resource_string 3 | from binascii import hexlify, unhexlify 4 | from pycryptopp.publickey import ed25519 5 | 6 | class KnownAnswerTests(unittest.TestCase): 7 | def test_short(self): 8 | # kat-ed25519.txt comes from "sign.input" on ed25519.cr.yp.to . The 9 | # pure-python ed25519.py in the same distribution uses a very 10 | # different key format than the one used by NaCl. 11 | shortkat = resource_string('pycryptopp', 12 | 'testvectors/kat-ed25519-short.txt') 13 | for i,line in enumerate(shortkat.splitlines()): 14 | x = line.split(":") 15 | A,B,C,D = [unhexlify(i) for i in x[:4]] 16 | # A[:32] is the 32 byte seed (the entropy input to H()) 17 | # A[32:] == B == the public point (pubkey) 18 | # C is the message 19 | # D is 64 bytes of signature (R+S) prepended to the message 20 | 21 | seed = A[:32] 22 | vk_s = B 23 | # the NaCl signature is R+S, which happens to be the same as ours 24 | msg = C 25 | sig = D[:64] 26 | # note that R depends only upon the second half of H(seed). S 27 | # depends upon both the first half (the exponent) and the second 28 | # half 29 | 30 | #if len(msg) % 16 == 1: 31 | # print "msg len = %d" % len(msg), time.time() 32 | 33 | sk = ed25519.SigningKey(seed) 34 | vkbs = sk.get_verifying_key_bytes() 35 | self.failUnlessEqual(vkbs, vk_s) 36 | vk = ed25519.VerifyingKey(vkbs) 37 | vk2 = ed25519.VerifyingKey(vk_s) 38 | self.failUnlessEqual(vk2, vk) # objects should compare equal 39 | newsig = sk.sign(msg) 40 | sig_R,sig_S = sig[:32],sig[32:] 41 | newsig_R,newsig_S = newsig[:32],newsig[32:] 42 | self.failUnlessEqual(hexlify(newsig), hexlify(sig)) # deterministic sigs 43 | self.failUnlessEqual(vk.verify(sig, msg), None) # no exception 44 | 45 | 46 | if __name__ == '__main__': 47 | unittest.main() 48 | -------------------------------------------------------------------------------- /src-cryptopp/stdcpp.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_STDCPP_H 2 | #define CRYPTOPP_STDCPP_H 3 | 4 | #if _MSC_VER >= 1500 5 | #define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY 6 | #include 7 | #endif 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | // http://connect.microsoft.com/VisualStudio/feedback/details/1600701/type-info-does-not-compile-with-has-exceptions-0 24 | #if defined(_MSC_VER) && (_MSC_VER < 1900) && defined(_HAS_EXCEPTIONS) && (_HAS_EXCEPTIONS == 0) 25 | namespace std { 26 | using ::type_info; 27 | } 28 | #endif 29 | 30 | // make_unchecked_array_iterator 31 | #if _MSC_VER >= 1600 32 | #include 33 | #endif 34 | 35 | #if defined(CRYPTOPP_CXX11_ATOMICS) 36 | #include 37 | #endif 38 | 39 | #if defined(CRYPTOPP_CXX11_SYNCHRONIZATION) 40 | #include 41 | #endif 42 | 43 | #if defined(CRYPTOPP_CXX11_RVALUES) 44 | # include 45 | #endif 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | // uintptr_t and ptrdiff_t 53 | #if (__cplusplus < 201103L) && (!defined(_MSC_VER) || (_MSC_VER >= 1700)) 54 | # include 55 | #elif defined(_MSC_VER) && (_MSC_VER < 1700) 56 | # include 57 | #endif 58 | 59 | // workaround needed on Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21 60 | #ifdef CRYPTOPP_INCLUDE_VECTOR_CC 61 | # include 62 | #endif 63 | 64 | // for alloca 65 | #if defined(CRYPTOPP_BSD_AVAILABLE) 66 | # include 67 | #elif defined(CRYPTOPP_UNIX_AVAILABLE) || defined(__sun) || defined(QNX) 68 | # include 69 | #elif defined(CRYPTOPP_WIN32_AVAILABLE) || defined(__MINGW32__) || defined(__BORLANDC__) 70 | # include 71 | #endif 72 | 73 | #ifdef _MSC_VER 74 | # pragma warning(disable: 4231) // re-disable this 75 | # ifdef _CRTAPI1 76 | # define CRYPTOPP_MSVCRT6 77 | # endif 78 | #endif 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src-cryptopp/randpool.cpp: -------------------------------------------------------------------------------- 1 | // randpool.cpp - written and placed in the public domain by Wei Dai 2 | // RandomPool used to follow the design of randpool in PGP 2.6.x, 3 | // but as of version 5.5 it has been redesigned to reduce the risk 4 | // of reusing random numbers after state rollback (which may occur 5 | // when running in a virtual machine like VMware). 6 | 7 | #include "pch.h" 8 | 9 | #ifndef CRYPTOPP_IMPORTS 10 | 11 | #include "randpool.h" 12 | #include "aes.h" 13 | #include "sha.h" 14 | #include "hrtimer.h" 15 | #include 16 | 17 | NAMESPACE_BEGIN(CryptoPP) 18 | 19 | RandomPool::RandomPool() 20 | : m_pCipher(new AES::Encryption), m_keySet(false) 21 | { 22 | memset(m_key, 0, m_key.SizeInBytes()); 23 | memset(m_seed, 0, m_seed.SizeInBytes()); 24 | } 25 | 26 | void RandomPool::IncorporateEntropy(const byte *input, size_t length) 27 | { 28 | SHA256 hash; 29 | hash.Update(m_key, 32); 30 | hash.Update(input, length); 31 | hash.Final(m_key); 32 | m_keySet = false; 33 | } 34 | 35 | void RandomPool::GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size) 36 | { 37 | if (size > 0) 38 | { 39 | if (!m_keySet) 40 | m_pCipher->SetKey(m_key, 32); 41 | 42 | CRYPTOPP_COMPILE_ASSERT(sizeof(TimerWord) <= 16); 43 | CRYPTOPP_COMPILE_ASSERT(sizeof(time_t) <= 8); 44 | 45 | Timer timer; 46 | TimerWord tw = timer.GetCurrentTimerValue(); 47 | 48 | *(TimerWord *)(void*)m_seed.data() += tw; 49 | time_t t = time(NULL); 50 | 51 | // UBsan finding: signed integer overflow: 1876017710 + 1446085457 cannot be represented in type 'long int' 52 | // *(time_t *)(m_seed.data()+8) += t; 53 | word64 tt1 = 0, tt2 = (word64)t; 54 | memcpy(&tt1, m_seed.data()+8, 8); 55 | memcpy(m_seed.data()+8, &(tt2 += tt1), 8); 56 | 57 | // Wipe the intermediates 58 | *((volatile TimerWord*)&tw) = 0; 59 | *((volatile word64*)&tt1) = 0; 60 | *((volatile word64*)&tt2) = 0; 61 | 62 | do 63 | { 64 | m_pCipher->ProcessBlock(m_seed); 65 | size_t len = UnsignedMin(16, size); 66 | target.ChannelPut(channel, m_seed, len); 67 | size -= len; 68 | } while (size > 0); 69 | } 70 | } 71 | 72 | NAMESPACE_END 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /src-cryptopp/dll.h: -------------------------------------------------------------------------------- 1 | // dll.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file 4 | //! \headerfile dll.h 5 | //! \brief Functions and definitions required for building the FIPS-140 DLL on Windows 6 | 7 | #ifndef CRYPTOPP_DLL_H 8 | #define CRYPTOPP_DLL_H 9 | 10 | #if !defined(CRYPTOPP_IMPORTS) && !defined(CRYPTOPP_EXPORTS) && !defined(CRYPTOPP_DEFAULT_NO_DLL) 11 | #ifdef CRYPTOPP_CONFIG_H 12 | #error To use the DLL version of Crypto++, this file must be included before any other Crypto++ header files. 13 | #endif 14 | #define CRYPTOPP_IMPORTS 15 | #endif 16 | 17 | #include "aes.h" 18 | #include "cbcmac.h" 19 | #include "ccm.h" 20 | #include "cmac.h" 21 | #include "channels.h" 22 | #include "des.h" 23 | #include "dh.h" 24 | #include "dsa.h" 25 | #include "ec2n.h" 26 | #include "eccrypto.h" 27 | #include "ecp.h" 28 | #include "files.h" 29 | #include "fips140.h" 30 | #include "gcm.h" 31 | #include "hex.h" 32 | #include "hmac.h" 33 | #include "modes.h" 34 | #include "mqueue.h" 35 | #include "nbtheory.h" 36 | #include "osrng.h" 37 | #include "pkcspad.h" 38 | #include "pssr.h" 39 | #include "randpool.h" 40 | #include "rsa.h" 41 | #include "rw.h" 42 | #include "sha.h" 43 | #include "skipjack.h" 44 | #include "trdlocal.h" 45 | 46 | #ifdef CRYPTOPP_IMPORTS 47 | 48 | #ifdef _DLL 49 | // cause CRT DLL to be initialized before Crypto++ so that we can use malloc and free during DllMain() 50 | #ifdef CRYPTOPP_DEBUG 51 | # pragma comment(lib, "msvcrtd") 52 | # pragma comment(lib, "cryptopp") 53 | #else 54 | # pragma comment(lib, "msvcrt") 55 | # pragma comment(lib, "cryptopp") 56 | #endif 57 | #endif 58 | 59 | #endif // #ifdef CRYPTOPP_IMPORTS 60 | 61 | #include // for new_handler 62 | 63 | NAMESPACE_BEGIN(CryptoPP) 64 | 65 | #if !(defined(_MSC_VER) && (_MSC_VER < 1300)) 66 | using std::new_handler; 67 | #endif 68 | 69 | typedef void * (CRYPTOPP_API * PNew)(size_t); 70 | typedef void (CRYPTOPP_API * PDelete)(void *); 71 | typedef void (CRYPTOPP_API * PGetNewAndDelete)(PNew &, PDelete &); 72 | typedef new_handler (CRYPTOPP_API * PSetNewHandler)(new_handler); 73 | typedef void (CRYPTOPP_API * PSetNewAndDelete)(PNew, PDelete, PSetNewHandler); 74 | 75 | NAMESPACE_END 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /src-cryptopp/hmac.cpp: -------------------------------------------------------------------------------- 1 | // hmac.cpp - 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 | memcpy(AccessIpad(), userKey, keylength); 27 | else 28 | { 29 | AccessHash().CalculateDigest(AccessIpad(), userKey, keylength); 30 | keylength = hash.DigestSize(); 31 | } 32 | 33 | CRYPTOPP_ASSERT(keylength <= blockSize); 34 | memset(AccessIpad()+keylength, 0, blockSize-keylength); 35 | 36 | for (unsigned int i=0; i 8 | #endif 9 | 10 | NAMESPACE_BEGIN(CryptoPP) 11 | 12 | #ifdef HIGHRES_TIMER_AVAILABLE 13 | typedef word64 TimerWord; 14 | #else 15 | typedef clock_t TimerWord; 16 | #endif 17 | 18 | //! \class TimerBase 19 | //! \brief Base class for timers 20 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TimerBase 21 | { 22 | public: 23 | enum Unit {SECONDS = 0, MILLISECONDS, MICROSECONDS, NANOSECONDS}; 24 | TimerBase(Unit unit, bool stuckAtZero) 25 | : m_timerUnit(unit), m_stuckAtZero(stuckAtZero), m_started(false) 26 | , m_start(0), m_last(0) {} 27 | 28 | virtual TimerWord GetCurrentTimerValue() =0; // GetCurrentTime is a macro in MSVC 6.0 29 | virtual TimerWord TicksPerSecond() =0; // this is not the resolution, just a conversion factor into seconds 30 | 31 | void StartTimer(); 32 | double ElapsedTimeAsDouble(); 33 | unsigned long ElapsedTime(); 34 | 35 | private: 36 | double ConvertTo(TimerWord t, Unit unit); 37 | 38 | Unit m_timerUnit; // HPUX workaround: m_unit is a system macro on HPUX 39 | bool m_stuckAtZero, m_started; 40 | TimerWord m_start, m_last; 41 | }; 42 | 43 | //! \class ThreadUserTimer 44 | //! \brief Measure CPU time spent executing instructions of this thread (if supported by OS) 45 | //! \note ThreadUserTimer only works correctly on Windows NT or later desktops and servers. 46 | //! On Unix-based it reports process time. On Windows Phone and Windows Store it reports wall 47 | //! clock time with performance counter precision. On all others it reports wall clock time. 48 | class ThreadUserTimer : public TimerBase 49 | { 50 | public: 51 | ThreadUserTimer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {} 52 | TimerWord GetCurrentTimerValue(); 53 | TimerWord TicksPerSecond(); 54 | }; 55 | 56 | //! high resolution timer 57 | class CRYPTOPP_DLL Timer : public TimerBase 58 | { 59 | public: 60 | Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {} 61 | TimerWord GetCurrentTimerValue(); 62 | TimerWord TicksPerSecond(); 63 | }; 64 | 65 | NAMESPACE_END 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src-cryptopp/skipjack.h: -------------------------------------------------------------------------------- 1 | // skipjack.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file skipjack.h 4 | //! \brief Classes for the SKIPJACK block cipher 5 | 6 | #ifndef CRYPTOPP_SKIPJACK_H 7 | #define CRYPTOPP_SKIPJACK_H 8 | 9 | #include "seckey.h" 10 | #include "secblock.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | //! \class SKIPJACK_Info 15 | //! \brief SKIPJACK block cipher information 16 | struct SKIPJACK_Info : public FixedBlockSize<8>, public FixedKeyLength<10> 17 | { 18 | CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "SKIPJACK";} 19 | }; 20 | 21 | //! \class SKIPJACK 22 | //! \brief SKIPJACK block cipher 23 | //! \sa SKIPJACK 24 | class SKIPJACK : public SKIPJACK_Info, public BlockCipherDocumentation 25 | { 26 | //! \class Base 27 | //! \brief SKIPJACK block cipher default operation 28 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl 29 | { 30 | public: 31 | void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 32 | unsigned int OptimalDataAlignment() const {return GetAlignmentOf();} 33 | 34 | protected: 35 | static const byte fTable[256]; 36 | 37 | FixedSizeSecBlock tab; 38 | }; 39 | 40 | //! \class Enc 41 | //! \brief SKIPJACK block cipher encryption operation 42 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Enc : public Base 43 | { 44 | public: 45 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 46 | private: 47 | static const byte Se[256]; 48 | static const word32 Te[4][256]; 49 | }; 50 | 51 | //! \class Dec 52 | //! \brief SKIPJACK block cipher decryption operation 53 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Dec : public Base 54 | { 55 | public: 56 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 57 | private: 58 | static const byte Sd[256]; 59 | static const word32 Td[4][256]; 60 | }; 61 | 62 | public: 63 | typedef BlockCipherFinal Encryption; 64 | typedef BlockCipherFinal Decryption; 65 | }; 66 | 67 | typedef SKIPJACK::Encryption SKIPJACKEncryption; 68 | typedef SKIPJACK::Decryption SKIPJACKDecryption; 69 | 70 | NAMESPACE_END 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src-cryptopp/cmac.h: -------------------------------------------------------------------------------- 1 | // cmac.h - 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 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | //! \class CMAC_Base 16 | //! \brief CMAC base implementation 17 | //! \since Crypto++ 5.6.0 18 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CMAC_Base : public MessageAuthenticationCode 19 | { 20 | public: 21 | CMAC_Base() : m_counter(0) {} 22 | 23 | void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); 24 | void Update(const byte *input, size_t length); 25 | void TruncatedFinal(byte *mac, size_t size); 26 | unsigned int DigestSize() const {return GetCipher().BlockSize();} 27 | unsigned int OptimalBlockSize() const {return GetCipher().BlockSize();} 28 | unsigned int OptimalDataAlignment() const {return GetCipher().OptimalDataAlignment();} 29 | 30 | protected: 31 | friend class EAX_Base; 32 | 33 | const BlockCipher & GetCipher() const {return const_cast(this)->AccessCipher();} 34 | virtual BlockCipher & AccessCipher() =0; 35 | 36 | void ProcessBuf(); 37 | SecByteBlock m_reg; 38 | unsigned int m_counter; 39 | }; 40 | 41 | //! \brief CMAC message authentication code 42 | //! \tparam T block cipher 43 | //! \details Template parameter T should be a class derived from BlockCipherDocumentation, for example AES, with a block size of 8, 16, or 32. 44 | //! \sa CMAC 45 | //! \since Crypto++ 5.6.0 46 | template 47 | class CMAC : public MessageAuthenticationCodeImpl >, public SameKeyLengthAs 48 | { 49 | public: 50 | //! \brief Construct a CMAC 51 | CMAC() {} 52 | //! \brief Construct a CMAC 53 | //! \param key the MAC key 54 | //! \param length the key size, in bytes 55 | CMAC(const byte *key, size_t length=SameKeyLengthAs::DEFAULT_KEYLENGTH) 56 | {this->SetKey(key, length);} 57 | 58 | static std::string StaticAlgorithmName() {return std::string("CMAC(") + T::StaticAlgorithmName() + ")";} 59 | 60 | private: 61 | BlockCipher & AccessCipher() {return m_cipher;} 62 | typename T::Encryption m_cipher; 63 | }; 64 | 65 | NAMESPACE_END 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src-ed25519/supercop-ref/fe25519.h: -------------------------------------------------------------------------------- 1 | #ifndef FE25519_H 2 | #define FE25519_H 3 | 4 | #include "crypto_int32.h" 5 | #include "crypto_uint32.h" 6 | 7 | #define fe25519 crypto_sign_ed25519_ref_fe25519 8 | #define fe25519_freeze crypto_sign_ed25519_ref_fe25519_freeze 9 | #define fe25519_unpack crypto_sign_ed25519_ref_fe25519_unpack 10 | #define fe25519_pack crypto_sign_ed25519_ref_fe25519_pack 11 | #define fe25519_iszero crypto_sign_ed25519_ref_fe25519_iszero 12 | #define fe25519_iseq_vartime crypto_sign_ed25519_ref_fe25519_iseq_vartime 13 | #define fe25519_cmov crypto_sign_ed25519_ref_fe25519_cmov 14 | #define fe25519_setone crypto_sign_ed25519_ref_fe25519_setone 15 | #define fe25519_setzero crypto_sign_ed25519_ref_fe25519_setzero 16 | #define fe25519_neg crypto_sign_ed25519_ref_fe25519_neg 17 | #define fe25519_getparity crypto_sign_ed25519_ref_fe25519_getparity 18 | #define fe25519_add crypto_sign_ed25519_ref_fe25519_add 19 | #define fe25519_sub crypto_sign_ed25519_ref_fe25519_sub 20 | #define fe25519_mul crypto_sign_ed25519_ref_fe25519_mul 21 | #define fe25519_square crypto_sign_ed25519_ref_fe25519_square 22 | #define fe25519_invert crypto_sign_ed25519_ref_fe25519_invert 23 | #define fe25519_pow2523 crypto_sign_ed25519_ref_fe25519_pow2523 24 | 25 | typedef struct 26 | { 27 | crypto_uint32 v[32]; 28 | } 29 | fe25519; 30 | 31 | void fe25519_freeze(fe25519 *r); 32 | 33 | void fe25519_unpack(fe25519 *r, const unsigned char x[32]); 34 | 35 | void fe25519_pack(unsigned char r[32], const fe25519 *x); 36 | 37 | int fe25519_iszero(const fe25519 *x); 38 | 39 | int fe25519_iseq_vartime(const fe25519 *x, const fe25519 *y); 40 | 41 | void fe25519_cmov(fe25519 *r, const fe25519 *x, unsigned char b); 42 | 43 | void fe25519_setone(fe25519 *r); 44 | 45 | void fe25519_setzero(fe25519 *r); 46 | 47 | void fe25519_neg(fe25519 *r, const fe25519 *x); 48 | 49 | unsigned char fe25519_getparity(const fe25519 *x); 50 | 51 | void fe25519_add(fe25519 *r, const fe25519 *x, const fe25519 *y); 52 | 53 | void fe25519_sub(fe25519 *r, const fe25519 *x, const fe25519 *y); 54 | 55 | void fe25519_mul(fe25519 *r, const fe25519 *x, const fe25519 *y); 56 | 57 | void fe25519_square(fe25519 *r, const fe25519 *x); 58 | 59 | void fe25519_invert(fe25519 *r, const fe25519 *x); 60 | 61 | void fe25519_pow2523(fe25519 *r, const fe25519 *x); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src-cryptopp/algparam.cpp: -------------------------------------------------------------------------------- 1 | // algparam.cpp - 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 | PAssignIntToInteger g_pAssignIntToInteger = NULL; 13 | 14 | bool CombinedNameValuePairs::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const 15 | { 16 | if (strcmp(name, "ValueNames") == 0) 17 | return m_pairs1.GetVoidValue(name, valueType, pValue) && m_pairs2.GetVoidValue(name, valueType, pValue); 18 | else 19 | return m_pairs1.GetVoidValue(name, valueType, pValue) || m_pairs2.GetVoidValue(name, valueType, pValue); 20 | } 21 | 22 | void AlgorithmParametersBase::operator=(const AlgorithmParametersBase &rhs) 23 | { 24 | CRYPTOPP_UNUSED(rhs); 25 | CRYPTOPP_ASSERT(false); 26 | } 27 | 28 | bool AlgorithmParametersBase::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const 29 | { 30 | if (strcmp(name, "ValueNames") == 0) 31 | { 32 | NameValuePairs::ThrowIfTypeMismatch(name, typeid(std::string), valueType); 33 | if (m_next.get()) 34 | m_next->GetVoidValue(name, valueType, pValue); 35 | (*reinterpret_cast(pValue) += m_name) += ";"; 36 | return true; 37 | } 38 | else if (strcmp(name, m_name) == 0) 39 | { 40 | AssignValue(name, valueType, pValue); 41 | m_used = true; 42 | return true; 43 | } 44 | else if (m_next.get()) 45 | return m_next->GetVoidValue(name, valueType, pValue); 46 | else 47 | return false; 48 | } 49 | 50 | AlgorithmParameters::AlgorithmParameters() 51 | : m_defaultThrowIfNotUsed(true) 52 | { 53 | } 54 | 55 | AlgorithmParameters::AlgorithmParameters(const AlgorithmParameters &x) 56 | : m_defaultThrowIfNotUsed(x.m_defaultThrowIfNotUsed) 57 | { 58 | m_next.reset(const_cast(x).m_next.release()); 59 | } 60 | 61 | AlgorithmParameters & AlgorithmParameters::operator=(const AlgorithmParameters &x) 62 | { 63 | m_next.reset(const_cast(x).m_next.release()); 64 | return *this; 65 | } 66 | 67 | bool AlgorithmParameters::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const 68 | { 69 | if (m_next.get()) 70 | return m_next->GetVoidValue(name, valueType, pValue); 71 | else 72 | return false; 73 | } 74 | 75 | NAMESPACE_END 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /misc/build_helpers/build-manylinux-wheels.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -ex 2 | 3 | # This runs in the container to actually build the wheels. 4 | BUILDER="/io/misc/build_helpers/_build-wheels.sh" 5 | 6 | # Create a scratch path where a bunch of intermediate build state can be 7 | # dumped. 8 | BASE="$(mktemp -d)" 9 | 10 | # Put a virtualenv in there 11 | ENV="${BASE}/env" 12 | virtualenv "${ENV}" 13 | 14 | # Create a directory where we can dump wheels that the build depends on. 15 | WHEELHOUSE="${BASE}/wheelhouse" 16 | mkdir -p "${WHEELHOUSE}" 17 | 18 | # Helpers to run programs from the virtualenv - instead of "activating" it and 19 | # changing what "pip" and "python" mean for everything in the script. 20 | PYTHON="${ENV}/bin/python" 21 | PIP="${ENV}/bin/pip" 22 | 23 | 24 | # Get a new, good version of pip (who knows what version came with the 25 | # virtualenv on the system?) 26 | "${PIP}" install --upgrade pip 27 | 28 | # Dump the requirements into a pip-readable format. 29 | "${PYTHON}" setup.py egg_info 30 | 31 | # Get wheels for all of the requirements and dump them into the directory we 32 | # created for that purpose. 33 | "${PIP}" wheel \ 34 | --requirement pycryptopp.egg-info/requires.txt \ 35 | --wheel-dir "${WHEELHOUSE}" 36 | 37 | # This image can build x86_64 (64 bit) manylinux wheels. 38 | DOCKER_IMAGE="quay.io/pypa/manylinux1_x86_64" 39 | docker pull "${DOCKER_IMAGE}" 40 | 41 | # Build all the x86_64 bit wheels. Give this image access to our working 42 | # directory (the root of the pycryptopp source tree). Also give it access to 43 | # the wheelhouse we populated with our requirements above. Also give it no 44 | # network access at all. The image is (intentionally) full of super old 45 | # software that's riddled with vulnerabilities. Cutting it off from the 46 | # network limits the attack surface to something a bit less terrifying. 47 | docker run \ 48 | --rm \ 49 | --network none \ 50 | --volume "${PWD}:/io" \ 51 | --volume "${WHEELHOUSE}:/io/wheelhouse" \ 52 | "${DOCKER_IMAGE}" \ 53 | "${BUILDER}" 54 | 55 | # As above, but for the i686 (32 bit) builds. 56 | DOCKER_IMAGE="quay.io/pypa/manylinux1_i686" 57 | docker pull "${DOCKER_IMAGE}" 58 | docker run \ 59 | --rm \ 60 | --network none \ 61 | --volume "${PWD}:/io" \ 62 | --volume "${WHEELHOUSE}:/io/wheelhouse" \ 63 | "${DOCKER_IMAGE}" \ 64 | linux32 "${BUILDER}" 65 | 66 | # Get the pycryptopp wheels from the place they were dumped. 67 | mkdir -p wheelhouse 68 | cp -v "${WHEELHOUSE}"/pycryptopp-*.whl wheelhouse/ 69 | sha256sum wheelhouse/*.whl 70 | -------------------------------------------------------------------------------- /src-cryptopp/License.txt: -------------------------------------------------------------------------------- 1 | Compilation Copyright (c) 1995-2016 by Wei Dai. All rights reserved. 2 | This copyright applies only to this software distribution package 3 | as a compilation, and does not imply a copyright on any particular 4 | file in the package. 5 | 6 | All individual files in this compilation are placed in the public domain by 7 | Wei Dai and other contributors. 8 | 9 | I would like to thank the following authors for placing their works into 10 | the public domain: 11 | 12 | Joan Daemen - 3way.cpp 13 | Leonard Janke - cast.cpp, seal.cpp 14 | Steve Reid - cast.cpp 15 | Phil Karn - des.cpp 16 | Andrew M. Kuchling - md2.cpp, md4.cpp 17 | Colin Plumb - md5.cpp 18 | Seal Woods - rc6.cpp 19 | Chris Morgan - rijndael.cpp 20 | Paulo Baretto - rijndael.cpp, skipjack.cpp, square.cpp 21 | Richard De Moliner - safer.cpp 22 | Matthew Skala - twofish.cpp 23 | Kevin Springle - camellia.cpp, shacal2.cpp, ttmac.cpp, whrlpool.cpp, ripemd.cpp 24 | Ronny Van Keer - sha3.cpp 25 | 26 | The Crypto++ Library (as a compilation) is currently licensed under the Boost 27 | Software License 1.0 (http://www.boost.org/users/license.html). 28 | 29 | Boost Software License - Version 1.0 - August 17th, 2003 30 | 31 | Permission is hereby granted, free of charge, to any person or organization 32 | obtaining a copy of the software and accompanying documentation covered by 33 | this license (the "Software") to use, reproduce, display, distribute, 34 | execute, and transmit the Software, and to prepare derivative works of the 35 | Software, and to permit third-parties to whom the Software is furnished to 36 | do so, all subject to the following: 37 | 38 | The copyright notices in the Software and this entire statement, including 39 | the above license grant, this restriction and the following disclaimer, 40 | must be included in all copies of the Software, in whole or in part, and 41 | all derivative works of the Software, unless such copies or derivative 42 | works are solely in the form of machine-executable object code generated by 43 | a source language processor. 44 | 45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 48 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 49 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 50 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 51 | DEALINGS IN THE SOFTWARE. 52 | -------------------------------------------------------------------------------- /src-cryptopp/emsa2.h: -------------------------------------------------------------------------------- 1 | // emsa2.h - 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 "misc.h" 12 | 13 | #ifdef CRYPTOPP_IS_DLL 14 | # include "sha.h" 15 | #endif 16 | 17 | NAMESPACE_BEGIN(CryptoPP) 18 | 19 | template class EMSA2HashId 20 | { 21 | public: 22 | static const byte id; 23 | }; 24 | 25 | template 26 | class EMSA2HashIdLookup : public BASE 27 | { 28 | public: 29 | struct HashIdentifierLookup 30 | { 31 | template struct HashIdentifierLookup2 32 | { 33 | static HashIdentifier Lookup() 34 | { 35 | return HashIdentifier(&EMSA2HashId::id, 1); 36 | } 37 | }; 38 | }; 39 | }; 40 | 41 | // EMSA2HashId can be instantiated with the following classes. 42 | class SHA1; 43 | class SHA224; 44 | class SHA256; 45 | class SHA384; 46 | class SHA512; 47 | class RIPEMD128; 48 | class RIPEMD160; 49 | class Whirlpool; 50 | // end of list 51 | 52 | #ifdef CRYPTOPP_IS_DLL 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 | CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; 58 | #endif 59 | 60 | //! _ 61 | class CRYPTOPP_DLL EMSA2Pad : public EMSA2HashIdLookup 62 | { 63 | public: 64 | CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA2";} 65 | 66 | size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const 67 | {CRYPTOPP_UNUSED(hashIdentifierLength); return 8*digestLength + 31;} 68 | 69 | void ComputeMessageRepresentative(RandomNumberGenerator &rng, 70 | const byte *recoverableMessage, size_t recoverableMessageLength, 71 | HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, 72 | byte *representative, size_t representativeBitLength) const; 73 | }; 74 | 75 | //! EMSA2, for use with RWSS and RSA_ISO 76 | /*! Only the following hash functions are supported by this signature standard: 77 | \dontinclude emsa2.h 78 | \skip EMSA2HashId can be instantiated 79 | \until end of list 80 | */ 81 | struct P1363_EMSA2 : public SignatureStandard 82 | { 83 | typedef EMSA2Pad SignatureMessageEncodingMethod; 84 | }; 85 | 86 | NAMESPACE_END 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src-cryptopp/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, NULL, 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 | case site: \ 58 | statement; \ 59 | if (OutputModifiable(site, output, length, messageEnd, blocking)) \ 60 | return STDMAX(size_t(1), length-m_inputPosition);\ 61 | } 62 | 63 | #define FILTER_OUTPUT_MODIFIABLE(site, output, length, messageEnd) \ 64 | FILTER_OUTPUT2_MODIFIABLE(site, 0, output, length, messageEnd) 65 | 66 | #define FILTER_OUTPUT2_MAYBE_MODIFIABLE(site, statement, output, length, messageEnd, modifiable) \ 67 | {\ 68 | case site: \ 69 | statement; \ 70 | if (modifiable ? OutputModifiable(site, output, length, messageEnd, blocking) : Output(site, output, length, messageEnd, blocking)) \ 71 | return STDMAX(size_t(1), length-m_inputPosition);\ 72 | } 73 | 74 | #define FILTER_OUTPUT_MAYBE_MODIFIABLE(site, output, length, messageEnd, modifiable) \ 75 | FILTER_OUTPUT2_MAYBE_MODIFIABLE(site, 0, output, length, messageEnd, modifiable) 76 | 77 | #if CRYPTOPP_MSC_VERSION 78 | # pragma warning(pop) 79 | #endif 80 | 81 | #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 82 | # pragma GCC diagnostic pop 83 | #endif 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /src-cryptopp/words.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_WORDS_H 2 | #define CRYPTOPP_WORDS_H 3 | 4 | #include "config.h" 5 | #include "misc.h" 6 | 7 | NAMESPACE_BEGIN(CryptoPP) 8 | 9 | inline size_t CountWords(const word *X, size_t N) 10 | { 11 | while (N && X[N-1]==0) 12 | N--; 13 | return N; 14 | } 15 | 16 | inline void SetWords(word *r, word a, size_t n) 17 | { 18 | for (size_t i=0; i> (WORD_BITS-shiftBits); 66 | } 67 | return carry; 68 | } 69 | 70 | inline word ShiftWordsRightByBits(word *r, size_t n, unsigned int shiftBits) 71 | { 72 | CRYPTOPP_ASSERT (shiftBits0; i--) 76 | { 77 | u = r[i-1]; 78 | r[i-1] = (u >> shiftBits) | carry; 79 | carry = u << (WORD_BITS-shiftBits); 80 | } 81 | return carry; 82 | } 83 | 84 | inline void ShiftWordsLeftByWords(word *r, size_t n, size_t shiftWords) 85 | { 86 | shiftWords = STDMIN(shiftWords, n); 87 | if (shiftWords) 88 | { 89 | for (size_t i=n-1; i>=shiftWords; i--) 90 | r[i] = r[i-shiftWords]; 91 | SetWords(r, 0, shiftWords); 92 | } 93 | } 94 | 95 | inline void ShiftWordsRightByWords(word *r, size_t n, size_t shiftWords) 96 | { 97 | shiftWords = STDMIN(shiftWords, n); 98 | if (shiftWords) 99 | { 100 | for (size_t i=0; i+shiftWords, public MessageAuthenticationCode 18 | { 19 | public: 20 | //! \brief Construct a HMAC_Base 21 | HMAC_Base() : m_innerHashKeyed(false) {} 22 | void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms); 23 | 24 | void Restart(); 25 | void Update(const byte *input, size_t length); 26 | void TruncatedFinal(byte *mac, size_t size); 27 | unsigned int OptimalBlockSize() const {return const_cast(this)->AccessHash().OptimalBlockSize();} 28 | unsigned int DigestSize() const {return const_cast(this)->AccessHash().DigestSize();} 29 | 30 | protected: 31 | virtual HashTransformation & AccessHash() =0; 32 | byte * AccessIpad() {return m_buf;} 33 | byte * AccessOpad() {return m_buf + AccessHash().BlockSize();} 34 | byte * AccessInnerHash() {return m_buf + 2*AccessHash().BlockSize();} 35 | 36 | private: 37 | void KeyInnerHash(); 38 | 39 | SecByteBlock m_buf; 40 | bool m_innerHashKeyed; 41 | }; 42 | 43 | //! \class HMAC 44 | //! \brief HMAC 45 | //! \tparam T HashTransformation derived class 46 | //! \details HMAC derives from MessageAuthenticationCodeImpl. It calculates the HMAC using 47 | //! HMAC(K, text) = H(K XOR opad, H(K XOR ipad, text)). 48 | //! \sa HMAC 49 | template 50 | class HMAC : public MessageAuthenticationCodeImpl > 51 | { 52 | public: 53 | CRYPTOPP_CONSTANT(DIGESTSIZE=T::DIGESTSIZE) 54 | CRYPTOPP_CONSTANT(BLOCKSIZE=T::BLOCKSIZE) 55 | 56 | //! \brief Construct a HMAC 57 | HMAC() {} 58 | //! \brief Construct a HMAC 59 | //! \param key the HMAC key 60 | //! \param length the size of the HMAC key 61 | HMAC(const byte *key, size_t length=HMAC_Base::DEFAULT_KEYLENGTH) 62 | {this->SetKey(key, length);} 63 | 64 | static std::string StaticAlgorithmName() {return std::string("HMAC(") + T::StaticAlgorithmName() + ")";} 65 | std::string AlgorithmName() const {return std::string("HMAC(") + m_hash.AlgorithmName() + ")";} 66 | 67 | private: 68 | HashTransformation & AccessHash() {return m_hash;} 69 | 70 | T m_hash; 71 | }; 72 | 73 | NAMESPACE_END 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/mars.txt: -------------------------------------------------------------------------------- 1 | AlgorithmType: SymmetricCipher 2 | Name: MARS/ECB 3 | Key: 80000000000000000000000000000000 4 | Plaintext: 00000000000000000000000000000000 5 | Ciphertext: B3E2AD5608AC1B6733A7CB4FDF8F9952 6 | Test: Encrypt 7 | Key: 00000000000000000000000000000000 8 | Plaintext: 00000000000000000000000000000000 9 | Ciphertext: DCC07B8DFB0738D6E30A22DFCF27E886 10 | Test: Encrypt 11 | Key: 00000000000000000000000000000000 12 | Plaintext: DCC07B8DFB0738D6E30A22DFCF27E886 13 | Ciphertext: 33CAFFBDDC7F1DDA0F9C15FA2F30E2FF 14 | Test: Encrypt 15 | Key: CB14A1776ABBC1CDAFE7243DEF2CEA02 16 | Plaintext: F94512A9B42D034EC4792204D708A69B 17 | Ciphertext: 225DA2CB64B73F79069F21A5E3CB8522 18 | Test: Encrypt 19 | Key: 86EDF4DA31824CABEF6A4637C40B0BAB 20 | Plaintext: 4DF955AD5B398D66408D620A2B27E1A9 21 | Ciphertext: A4B737340AE6D2CAFD930BA97D86129F 22 | Test: Encrypt 23 | Key: 000000000000000000000000000000000000000000000000 24 | Plaintext: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 25 | Ciphertext: 97778747D60E425C2B4202599DB856FB 26 | Test: Encrypt 27 | Key: D158860838874D9500000000000000000000000000000000 28 | Plaintext: 93A953A82C10411DD158860838874D95 29 | Ciphertext: 4FA0E5F64893131712F01408D233E9F7 30 | Test: Encrypt 31 | Key: 791739A58B04581A93A953A82C10411DD158860838874D95 32 | Plaintext: 6761C42D3E6142D2A84FBFADB383158F 33 | Ciphertext: F706BC0FD97E28B6F1AF4E17D8755FFF 34 | Test: Encrypt 35 | Key: 0000000000000000000000000000000000000000000000000000000000000000 36 | Plaintext: 62E45B4CF3477F1DD65063729D9ABA8F 37 | Ciphertext: 0F4B897EA014D21FBC20F1054A42F719 38 | Test: Encrypt 39 | Key: FBA167983E7AEF22317CE28C02AAE1A3E8E5CC3CEDBEA82A99DBC39AD65E7227 40 | Plaintext: 1344ABA4D3C44708A8A72116D4F49384 41 | Ciphertext: 458335D95EA42A9F4DCCD41AECC2390D 42 | Test: Encrypt 43 | Key: 00000000000000000000000000000000 44 | Plaintext: 00000000000000000000000000000000 45 | Ciphertext: 3FE24DC09173D15F4616A849D396F7E3 46 | Test: EncryptionMCT 47 | Key: 00000000000000000000000000000000 48 | Plaintext: 24BD3D2FC6FEE152D1D64545E2230584 49 | Ciphertext: 00000000000000000000000000000000 50 | Test: DecryptionMCT 51 | Key: 000000000000000000000000000000000000000000000000 52 | Plaintext: 00000000000000000000000000000000 53 | Ciphertext: 34EC834E2F30741ECB476DA7E9662BBD 54 | Test: EncryptionMCT 55 | Key: 000000000000000000000000000000000000000000000000 56 | Plaintext: 7F27C3397A8CEEF1BDF859459690FEA8 57 | Ciphertext: 00000000000000000000000000000000 58 | Test: DecryptionMCT 59 | Key: 0000000000000000000000000000000000000000000000000000000000000000 60 | Plaintext: 00000000000000000000000000000000 61 | Ciphertext: EDE145C10E279501D921C5E3B04420A6 62 | Test: EncryptionMCT 63 | Key: 0000000000000000000000000000000000000000000000000000000000000000 64 | Plaintext: 95615ADB0DDF6613A5E84F849AC8C00D 65 | Ciphertext: 00000000000000000000000000000000 66 | Test: DecryptionMCT 67 | -------------------------------------------------------------------------------- /src-cryptopp/fips140.cpp: -------------------------------------------------------------------------------- 1 | // fips140.cpp - 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 | #include "trdlocal.h" // needs to be included last for cygwin 10 | 11 | NAMESPACE_BEGIN(CryptoPP) 12 | 13 | // Define this to 1 to turn on FIPS 140-2 compliance features, including additional tests during 14 | // startup, random number generation, and key generation. These tests may affect performance. 15 | #ifndef CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 16 | #define CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 0 17 | #endif 18 | 19 | #if (CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 && !defined(THREADS_AVAILABLE)) 20 | #error FIPS 140-2 compliance requires the availability of thread local storage. 21 | #endif 22 | 23 | #if (CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 && !defined(OS_RNG_AVAILABLE)) 24 | #error FIPS 140-2 compliance requires the availability of OS provided RNG. 25 | #endif 26 | 27 | PowerUpSelfTestStatus g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_NOT_DONE; 28 | 29 | bool FIPS_140_2_ComplianceEnabled() 30 | { 31 | return CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2; 32 | } 33 | 34 | void SimulatePowerUpSelfTestFailure() 35 | { 36 | g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_FAILED; 37 | } 38 | 39 | PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus() 40 | { 41 | return g_powerUpSelfTestStatus; 42 | } 43 | 44 | #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 45 | ThreadLocalStorage & AccessPowerUpSelfTestInProgress() 46 | { 47 | static ThreadLocalStorage selfTestInProgress; 48 | return selfTestInProgress; 49 | } 50 | #endif 51 | 52 | bool PowerUpSelfTestInProgressOnThisThread() 53 | { 54 | #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 55 | return AccessPowerUpSelfTestInProgress().GetValue() != NULL; 56 | #else 57 | CRYPTOPP_ASSERT(false); // should not be called 58 | return false; 59 | #endif 60 | } 61 | 62 | void SetPowerUpSelfTestInProgressOnThisThread(bool inProgress) 63 | { 64 | CRYPTOPP_UNUSED(inProgress); 65 | #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 66 | AccessPowerUpSelfTestInProgress().SetValue((void *)inProgress); 67 | #endif 68 | } 69 | 70 | void EncryptionPairwiseConsistencyTest_FIPS_140_Only(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor) 71 | { 72 | CRYPTOPP_UNUSED(encryptor), CRYPTOPP_UNUSED(decryptor); 73 | #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 74 | EncryptionPairwiseConsistencyTest(encryptor, decryptor); 75 | #endif 76 | } 77 | 78 | void SignaturePairwiseConsistencyTest_FIPS_140_Only(const PK_Signer &signer, const PK_Verifier &verifier) 79 | { 80 | CRYPTOPP_UNUSED(signer), CRYPTOPP_UNUSED(verifier); 81 | #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 82 | SignaturePairwiseConsistencyTest(signer, verifier); 83 | #endif 84 | } 85 | 86 | NAMESPACE_END 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/sha.txt: -------------------------------------------------------------------------------- 1 | AlgorithmType: MessageDigest 2 | Name: SHA-1 3 | Message: "abc" 4 | Digest: A9993E364706816ABA3E25717850C26C9CD0D89D 5 | Test: Verify 6 | Message: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 7 | Digest: 84983E441C3BD26EBAAE4AA1F95129E5E54670F1 8 | Test: Verify 9 | Message: r15625 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 10 | Digest: 34AA973CD4C4DAA4F61EEB2BDBAD27316534016F 11 | Test: Verify 12 | 13 | AlgorithmType: MessageDigest 14 | Name: SHA-224 15 | Message: "abc" 16 | Digest: 23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7 17 | Test: Verify 18 | Message: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 19 | Digest: 75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525 20 | Test: Verify 21 | Message: r15625 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 22 | Digest: 20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67 23 | Test: Verify 24 | 25 | AlgorithmType: MessageDigest 26 | Name: SHA-256 27 | Message: "abc" 28 | Digest: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad 29 | Test: Verify 30 | Message: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 31 | Digest: 248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1 32 | Test: Verify 33 | Message: r15625 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 34 | Digest: cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0 35 | Test: Verify 36 | 37 | AlgorithmType: MessageDigest 38 | Name: SHA-384 39 | Message: "abc" 40 | Digest: cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7 41 | Test: Verify 42 | Message: "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" 43 | Digest: 09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039 44 | Test: Verify 45 | Message: r15625 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 46 | Digest: 9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985 47 | Test: Verify 48 | 49 | AlgorithmType: MessageDigest 50 | Name: SHA-512 51 | Message: "abc" 52 | Digest: ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f 53 | Test: Verify 54 | Message: "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" 55 | Digest: 8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909 56 | Test: Verify 57 | Message: r15625 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 58 | Digest: e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b 59 | Test: Verify 60 | -------------------------------------------------------------------------------- /src/pycryptopp/_pycryptoppmodule.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "publickey/ecdsamodule.hpp" 4 | #include "publickey/rsamodule.hpp" 5 | #include "hash/sha256module.hpp" 6 | #include "cipher/aesmodule.hpp" 7 | #include "cipher/xsalsa20module.hpp" 8 | 9 | /* from Crypto++ */ 10 | #ifdef DISABLE_EMBEDDED_CRYPTOPP 11 | #include 12 | #else 13 | #include 14 | #endif 15 | 16 | PyDoc_STRVAR(_pycryptopp__doc__, 17 | "_pycryptopp -- Python wrappers for a few algorithms from Crypto++\n\ 18 | \n\ 19 | from pycryptopp import publickey\n\ 20 | from pycryptopp.publickey import ecdsa\n\ 21 | from pycryptopp.publickey import rsa\n\ 22 | from pycryptopp import cipher\n\ 23 | from pycryptopp.cipher import aes\n\ 24 | from pycryptopp.cipher import xsalsa20\n\ 25 | from pycryptopp import hash\n\ 26 | from pycryptopp.hash import sha256"); 27 | 28 | static PyMethodDef _pycryptopp_functions[] = { 29 | {"rsa_generate", reinterpret_cast(rsa_generate), METH_KEYWORDS, const_cast(rsa_generate__doc__)}, 30 | {"rsa_create_verifying_key_from_string", reinterpret_cast(rsa_create_verifying_key_from_string), METH_KEYWORDS, const_cast(rsa_create_verifying_key_from_string__doc__)}, 31 | {"rsa_create_signing_key_from_string", reinterpret_cast(rsa_create_signing_key_from_string), METH_KEYWORDS, const_cast(rsa_create_signing_key_from_string__doc__)}, 32 | {NULL, NULL, 0, NULL} /* sentinel */ 33 | }; 34 | 35 | #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ 36 | #define PyMODINIT_FUNC void 37 | #endif 38 | PyMODINIT_FUNC 39 | init_pycryptopp(void) { 40 | PyObject *module; 41 | 42 | module = Py_InitModule3("_pycryptopp", _pycryptopp_functions, _pycryptopp__doc__); 43 | if (!module) 44 | return; 45 | 46 | PyObject* version; 47 | 48 | /* a tuple of (Crypto++ version, extra-version) */ 49 | #ifndef DISABLE_EMBEDDED_CRYPTOPP 50 | /* In the version of Crypto++ which is included in pycryptopp, there is a 51 | symbol named `cryptopp_extra_version' which is declared (external 52 | variable) in config.h and defined in cryptlib.cpp. Of course it is 53 | possible that the header file we've #include'd is from the 54 | embedded-in-pycryptopp version of Crypto++ but the dynamically linked 55 | library that we load is from an older version which doesn't have this 56 | symbol. In that case, the load will fail before we get this far. */ 57 | version = Py_BuildValue("is", CRYPTOPP_VERSION, cryptopp_extra_version); 58 | #else 59 | version = Py_BuildValue("iO", CRYPTOPP_VERSION, Py_None); 60 | #endif 61 | 62 | int succ = PyModule_AddObject(module, "cryptopp_version", version); 63 | if (succ != 0) 64 | return; 65 | 66 | 67 | init_ecdsa(module); 68 | init_rsa(module); 69 | init_sha256(module); 70 | init_aes(module); 71 | init_xsalsa20(module); 72 | } 73 | -------------------------------------------------------------------------------- /src-ed25519/supercop-ref/sc25519.h: -------------------------------------------------------------------------------- 1 | #ifndef SC25519_H 2 | #define SC25519_H 3 | 4 | #include "crypto_int32.h" 5 | #include "crypto_uint32.h" 6 | 7 | #define sc25519 crypto_sign_ed25519_ref_sc25519 8 | #define shortsc25519 crypto_sign_ed25519_ref_shortsc25519 9 | #define sc25519_from32bytes crypto_sign_ed25519_ref_sc25519_from32bytes 10 | #define shortsc25519_from16bytes crypto_sign_ed25519_ref_shortsc25519_from16bytes 11 | #define sc25519_from64bytes crypto_sign_ed25519_ref_sc25519_from64bytes 12 | #define sc25519_from_shortsc crypto_sign_ed25519_ref_sc25519_from_shortsc 13 | #define sc25519_to32bytes crypto_sign_ed25519_ref_sc25519_to32bytes 14 | #define sc25519_iszero_vartime crypto_sign_ed25519_ref_sc25519_iszero_vartime 15 | #define sc25519_isshort_vartime crypto_sign_ed25519_ref_sc25519_isshort_vartime 16 | #define sc25519_lt_vartime crypto_sign_ed25519_ref_sc25519_lt_vartime 17 | #define sc25519_add crypto_sign_ed25519_ref_sc25519_add 18 | #define sc25519_sub_nored crypto_sign_ed25519_ref_sc25519_sub_nored 19 | #define sc25519_mul crypto_sign_ed25519_ref_sc25519_mul 20 | #define sc25519_mul_shortsc crypto_sign_ed25519_ref_sc25519_mul_shortsc 21 | #define sc25519_window3 crypto_sign_ed25519_ref_sc25519_window3 22 | #define sc25519_window5 crypto_sign_ed25519_ref_sc25519_window5 23 | #define sc25519_2interleave2 crypto_sign_ed25519_ref_sc25519_2interleave2 24 | 25 | typedef struct 26 | { 27 | crypto_uint32 v[32]; 28 | } 29 | sc25519; 30 | 31 | typedef struct 32 | { 33 | crypto_uint32 v[16]; 34 | } 35 | shortsc25519; 36 | 37 | void sc25519_from32bytes(sc25519 *r, const unsigned char x[32]); 38 | 39 | void shortsc25519_from16bytes(shortsc25519 *r, const unsigned char x[16]); 40 | 41 | void sc25519_from64bytes(sc25519 *r, const unsigned char x[64]); 42 | 43 | void sc25519_from_shortsc(sc25519 *r, const shortsc25519 *x); 44 | 45 | void sc25519_to32bytes(unsigned char r[32], const sc25519 *x); 46 | 47 | int sc25519_iszero_vartime(const sc25519 *x); 48 | 49 | int sc25519_isshort_vartime(const sc25519 *x); 50 | 51 | int sc25519_lt_vartime(const sc25519 *x, const sc25519 *y); 52 | 53 | void sc25519_add(sc25519 *r, const sc25519 *x, const sc25519 *y); 54 | 55 | void sc25519_sub_nored(sc25519 *r, const sc25519 *x, const sc25519 *y); 56 | 57 | void sc25519_mul(sc25519 *r, const sc25519 *x, const sc25519 *y); 58 | 59 | void sc25519_mul_shortsc(sc25519 *r, const sc25519 *x, const shortsc25519 *y); 60 | 61 | /* Convert s into a representation of the form \sum_{i=0}^{84}r[i]2^3 62 | * with r[i] in {-4,...,3} 63 | */ 64 | void sc25519_window3(signed char r[85], const sc25519 *s); 65 | 66 | /* Convert s into a representation of the form \sum_{i=0}^{50}r[i]2^5 67 | * with r[i] in {-16,...,15} 68 | */ 69 | void sc25519_window5(signed char r[51], const sc25519 *s); 70 | 71 | void sc25519_2interleave2(unsigned char r[127], const sc25519 *s1, const sc25519 *s2); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/eax.txt: -------------------------------------------------------------------------------- 1 | AlgorithmType: AuthenticatedSymmetricCipher 2 | Name: AES/EAX 3 | Source: http://www.cs.ucdavis.edu/~rogaway/papers/eax.pdf 4 | Plaintext: 5 | Key: 233952DEE4D5ED5F9B9C6D6FF80FF478 6 | IV: 62EC67F9C3A4A407FCB2A8C49031A8B3 7 | Header: 6BFB914FD07EAE6B 8 | Ciphertext: E037830E8389F27B025A2D6527E79D01 9 | Test: Encrypt 10 | Plaintext: F7FB 11 | Key: 91945D3F4DCBEE0BF45EF52255F095A4 12 | IV: BECAF043B0A23D843194BA972C66DEBD 13 | Header: FA3BFD4806EB53FA 14 | Ciphertext: 19DD5C4C9331049D0BDAB0277408F67967E5 15 | Test: Encrypt 16 | Plaintext: 1A47CB4933 17 | Key: 01F74AD64077F2E704C0F60ADA3DD523 18 | IV: 70C3DB4F0D26368400A10ED05D2BFF5E 19 | Header: 234A3463C1264AC6 20 | Ciphertext: D851D5BAE03A59F238A23E39199DC9266626C40F80 21 | Test: Encrypt 22 | Plaintext: 481C9E39B1 23 | Key: D07CF6CBB7F313BDDE66B727AFD3C5E8 24 | IV: 8408DFFF3C1A2B1292DC199E46B7D617 25 | Header: 33CCE2EABFF5A79D 26 | Ciphertext: 632A9D131AD4C168A4225D8E1FF755939974A7BEDE 27 | Test: Encrypt 28 | Plaintext: 40D0C07DA5E4 29 | Key: 35B6D0580005BBC12B0587124557D2C2 30 | IV: FDB6B06676EEDC5C61D74276E1F8E816 31 | Header: AEB96EAEBE2970E9 32 | Ciphertext: 071DFE16C675CB0677E536F73AFE6A14B74EE49844DD 33 | Test: Encrypt 34 | Plaintext: 4DE3B35C3FC039245BD1FB7D 35 | Key: BD8E6E11475E60B268784C38C62FEB22 36 | IV: 6EAC5C93072D8E8513F750935E46DA1B 37 | Header: D4482D1CA78DCE0F 38 | Ciphertext: 835BB4F15D743E350E728414ABB8644FD6CCB86947C5E10590210A4F 39 | Test: Encrypt 40 | Plaintext: 8B0A79306C9CE7ED99DAE4F87F8DD61636 41 | Key: 7C77D6E813BED5AC98BAA417477A2E7D 42 | IV: 1A8C98DCD73D38393B2BF1569DEEFC19 43 | Header: 65D2017990D62528 44 | Ciphertext: 02083E3979DA014812F59F11D52630DA30137327D10649B0AA6E1C181DB617D7F2 45 | Test: Encrypt 46 | Plaintext: 1BDA122BCE8A8DBAF1877D962B8592DD2D56 47 | Key: 5FFF20CAFAB119CA2FC73549E20F5B0D 48 | IV: DDE59B97D722156D4D9AFF2BC7559826 49 | Header: 54B9F04E6A09189A 50 | Ciphertext: 2EC47B2C4954A489AFC7BA4897EDCDAE8CC33B60450599BD02C96382902AEF7F832A 51 | Test: Encrypt 52 | Plaintext: 6CF36720872B8513F6EAB1A8A44438D5EF11 53 | Key: A4A4782BCFFD3EC5E7EF6D8C34A56123 54 | IV: B781FCF2F75FA5A8DE97A9CA48E522EC 55 | Header: 899A175897561D7E 56 | Ciphertext: 0DE18FD0FDD91E7AF19F1D8EE8733938B1E8E7F6D2231618102FDB7FE55FF1991700 57 | Test: Encrypt 58 | Plaintext: CA40D7446E545FFAED3BD12A740A659FFBBB3CEAB7 59 | Key: 8395FCF1E95BEBD697BD010BC766AAC3 60 | IV: 22E7ADD93CFC6393C57EC0B3C17D6B44 61 | Header: 126735FCC320D25A 62 | Ciphertext: CB8920F87A6C75CFF39627B56E3ED197C552D295A7CFC46AFC253B4652B1AF3795B124AB6E 63 | Test: Encrypt 64 | Plaintext: CA40D7446E545FFAED3BD12A740A659FFBBB3CEAB7 65 | Key: 8395FCF1E95BEBD697BD010BC766AAC3 66 | IV: 22E7ADD93CFC6393C57EC0B3C17D6B44 67 | Header: 126735FCC320D25A 68 | Ciphertext: CB8920F87A6C75CFF39627B56E3ED197C552D295A7CFC46AFC253B4652B1AF3795B124AB6E 69 | Test: Encrypt 70 | Plaintext: CA40D7446E545FFAED3BD12A740A659FFBBB3CEAB7 71 | Key: 8395FCF1E95BEBD697BD010BC766AAC3 72 | IV: 22E7ADD93CFC6393C57EC0B3C17D6B44 73 | Header: 126735FCC320D25A 74 | Ciphertext: 0B8920F87A6C75CFF39627B56E3ED197C552D295A7CFC46AFC253B4652B1AF3795B124AB6E 75 | Test: NotVerify 76 | -------------------------------------------------------------------------------- /src/pycryptopp/testvectors/KAT_AES/ECBKeySbox256e.txt: -------------------------------------------------------------------------------- 1 | [ENCRYPT] 2 | 3 | COUNT = 0 4 | KEY = c47b0294dbbbee0fec4757f22ffeee3587ca4730c3d33b691df38bab076bc558 5 | PLAINTEXT = 00000000000000000000000000000000 6 | CIPHERTEXT = 46f2fb342d6f0ab477476fc501242c5f 7 | 8 | COUNT = 1 9 | KEY = 28d46cffa158533194214a91e712fc2b45b518076675affd910edeca5f41ac64 10 | PLAINTEXT = 00000000000000000000000000000000 11 | CIPHERTEXT = 4bf3b0a69aeb6657794f2901b1440ad4 12 | 13 | COUNT = 2 14 | KEY = c1cc358b449909a19436cfbb3f852ef8bcb5ed12ac7058325f56e6099aab1a1c 15 | PLAINTEXT = 00000000000000000000000000000000 16 | CIPHERTEXT = 352065272169abf9856843927d0674fd 17 | 18 | COUNT = 3 19 | KEY = 984ca75f4ee8d706f46c2d98c0bf4a45f5b00d791c2dfeb191b5ed8e420fd627 20 | PLAINTEXT = 00000000000000000000000000000000 21 | CIPHERTEXT = 4307456a9e67813b452e15fa8fffe398 22 | 23 | COUNT = 4 24 | KEY = b43d08a447ac8609baadae4ff12918b9f68fc1653f1269222f123981ded7a92f 25 | PLAINTEXT = 00000000000000000000000000000000 26 | CIPHERTEXT = 4663446607354989477a5c6f0f007ef4 27 | 28 | COUNT = 5 29 | KEY = 1d85a181b54cde51f0e098095b2962fdc93b51fe9b88602b3f54130bf76a5bd9 30 | PLAINTEXT = 00000000000000000000000000000000 31 | CIPHERTEXT = 531c2c38344578b84d50b3c917bbb6e1 32 | 33 | COUNT = 6 34 | KEY = dc0eba1f2232a7879ded34ed8428eeb8769b056bbaf8ad77cb65c3541430b4cf 35 | PLAINTEXT = 00000000000000000000000000000000 36 | CIPHERTEXT = fc6aec906323480005c58e7e1ab004ad 37 | 38 | COUNT = 7 39 | KEY = f8be9ba615c5a952cabbca24f68f8593039624d524c816acda2c9183bd917cb9 40 | PLAINTEXT = 00000000000000000000000000000000 41 | CIPHERTEXT = a3944b95ca0b52043584ef02151926a8 42 | 43 | COUNT = 8 44 | KEY = 797f8b3d176dac5b7e34a2d539c4ef367a16f8635f6264737591c5c07bf57a3e 45 | PLAINTEXT = 00000000000000000000000000000000 46 | CIPHERTEXT = a74289fe73a4c123ca189ea1e1b49ad5 47 | 48 | COUNT = 9 49 | KEY = 6838d40caf927749c13f0329d331f448e202c73ef52c5f73a37ca635d4c47707 50 | PLAINTEXT = 00000000000000000000000000000000 51 | CIPHERTEXT = b91d4ea4488644b56cf0812fa7fcf5fc 52 | 53 | COUNT = 10 54 | KEY = ccd1bc3c659cd3c59bc437484e3c5c724441da8d6e90ce556cd57d0752663bbc 55 | PLAINTEXT = 00000000000000000000000000000000 56 | CIPHERTEXT = 304f81ab61a80c2e743b94d5002a126b 57 | 58 | COUNT = 11 59 | KEY = 13428b5e4c005e0636dd338405d173ab135dec2a25c22c5df0722d69dcc43887 60 | PLAINTEXT = 00000000000000000000000000000000 61 | CIPHERTEXT = 649a71545378c783e368c9ade7114f6c 62 | 63 | COUNT = 12 64 | KEY = 07eb03a08d291d1b07408bf3512ab40c91097ac77461aad4bb859647f74f00ee 65 | PLAINTEXT = 00000000000000000000000000000000 66 | CIPHERTEXT = 47cb030da2ab051dfc6c4bf6910d12bb 67 | 68 | COUNT = 13 69 | KEY = 90143ae20cd78c5d8ebdd6cb9dc1762427a96c78c639bccc41a61424564eafe1 70 | PLAINTEXT = 00000000000000000000000000000000 71 | CIPHERTEXT = 798c7c005dee432b2c8ea5dfa381ecc3 72 | 73 | COUNT = 14 74 | KEY = b7a5794d52737475d53d5a377200849be0260a67a2b22ced8bbef12882270d07 75 | PLAINTEXT = 00000000000000000000000000000000 76 | CIPHERTEXT = 637c31dc2591a07636f646b72daabbe7 77 | 78 | COUNT = 15 79 | KEY = fca02f3d5011cfc5c1e23165d413a049d4526a991827424d896fe3435e0bf68e 80 | PLAINTEXT = 00000000000000000000000000000000 81 | CIPHERTEXT = 179a49c712154bbffbe6e7a84a18e220 82 | -------------------------------------------------------------------------------- /src-cryptopp/randpool.h: -------------------------------------------------------------------------------- 1 | // randpool.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file randpool.h 4 | //! \brief Class file for Randomness Pool 5 | //! \details RandomPool can be used to generate cryptographic quality pseudorandom bytes 6 | //! after seeding the pool with IncorporateEntropy(). Internally, the generator uses 7 | //! AES-256 to produce the stream. Entropy is stirred in using SHA-256. 8 | //! \details RandomPool used to follow the design of randpool in PGP 2.6.x. At version 5.5 9 | //! RandomPool was redesigned to reduce the risk of reusing random numbers after state 10 | //! rollback (which may occur when running in a virtual machine like VMware or a hosted 11 | //! environment). 12 | //! \details If you need the pre-Crypto++ 5.5 generator then you can find it with: 13 | //!
14 | //!    $ git clone https://github.com/weidai11/cryptopp cryptopp-ancient
15 | //!    $ cryptopp-ancient
16 | //!
17 | //!    # Checkout the RandomPool change
18 | //!    $ git checkout f41245df6fb9b85574260eca9cd32777e8ab5136
19 | //!
20 | //!    # Go back one more
21 | //!    git checkout HEAD~1
22 | //!
23 | //!    $ grep 'MDC' *.h *.cpp
24 | //!    randpool.cpp:typedef MDC RandomPoolCipher;
25 | //! 
26 | //! \since Crypto++ 4.0 (PGP 2.6.x style), Crypto++ 5.5 (AES-256 based) 27 | 28 | #ifndef CRYPTOPP_RANDPOOL_H 29 | #define CRYPTOPP_RANDPOOL_H 30 | 31 | #include "cryptlib.h" 32 | #include "filters.h" 33 | #include "secblock.h" 34 | #include "smartptr.h" 35 | #include "aes.h" 36 | 37 | NAMESPACE_BEGIN(CryptoPP) 38 | 39 | //! \class RandomPool 40 | //! \brief Randomness Pool based on AES-256 41 | //! \details RandomPool can be used to generate cryptographic quality pseudorandom bytes 42 | //! after seeding the pool with IncorporateEntropy(). Internally, the generator uses 43 | //! AES-256 to produce the stream. Entropy is stirred in using SHA-256. 44 | //! \details RandomPool used to follow the design of randpool in PGP 2.6.x. At version 5.5 45 | //! RandomPool was redesigned to reduce the risk of reusing random numbers after state 46 | //! rollback (which may occur when running in a virtual machine like VMware or a hosted 47 | //! environment). 48 | //! \since Crypto++ 4.0 (PGP 2.6.x style), Crypto++ 5.5 (AES-256 based) 49 | class CRYPTOPP_DLL RandomPool : public RandomNumberGenerator, public NotCopyable 50 | { 51 | public: 52 | //! \brief Construct a RandomPool 53 | RandomPool(); 54 | 55 | bool CanIncorporateEntropy() const {return true;} 56 | void IncorporateEntropy(const byte *input, size_t length); 57 | void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size); 58 | 59 | // for backwards compatibility. use RandomNumberSource, RandomNumberStore, and RandomNumberSink for other BufferTransformation functionality 60 | void Put(const byte *input, size_t length) {IncorporateEntropy(input, length);} 61 | 62 | private: 63 | FixedSizeAlignedSecBlock m_seed; 64 | FixedSizeAlignedSecBlock m_key; 65 | member_ptr m_pCipher; 66 | bool m_keySet; 67 | }; 68 | 69 | NAMESPACE_END 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src-cryptopp/authenc.h: -------------------------------------------------------------------------------- 1 | // authenc.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file 4 | //! \headerfile authenc.h 5 | //! \brief Base classes for working with authenticated encryption modes of encryption 6 | //! \since Crypto++ 5.6.0 7 | 8 | #ifndef CRYPTOPP_AUTHENC_H 9 | #define CRYPTOPP_AUTHENC_H 10 | 11 | #include "cryptlib.h" 12 | #include "secblock.h" 13 | 14 | NAMESPACE_BEGIN(CryptoPP) 15 | 16 | //! \class AuthenticatedSymmetricCipherBase 17 | //! \brief Base implementation for one direction (encryption or decryption) of a stream cipher or block cipher mode with authentication 18 | //! \since Crypto++ 5.6.0 19 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipherBase : public AuthenticatedSymmetricCipher 20 | { 21 | public: 22 | AuthenticatedSymmetricCipherBase() : m_state(State_Start), m_bufferedDataLength(0), 23 | m_totalHeaderLength(0), m_totalMessageLength(0), m_totalFooterLength(0) {} 24 | 25 | bool IsRandomAccess() const {return false;} 26 | bool IsSelfInverting() const {return true;} 27 | 28 | //! \brief Sets the key for this object without performing parameter validation 29 | //! \param key a byte buffer used to key the cipher 30 | //! \param length the length of the byte buffer 31 | //! \param params additional parameters passed as NameValuePairs 32 | //! \details key must be at least DEFAULT_KEYLENGTH in length. 33 | void UncheckedSetKey(const byte * key, unsigned int length,const CryptoPP::NameValuePairs ¶ms) 34 | {CRYPTOPP_UNUSED(key), CRYPTOPP_UNUSED(length), CRYPTOPP_UNUSED(params); CRYPTOPP_ASSERT(false);} 35 | 36 | void SetKey(const byte *userKey, size_t keylength, const NameValuePairs ¶ms); 37 | void Restart() {if (m_state > State_KeySet) m_state = State_KeySet;} 38 | void Resynchronize(const byte *iv, int length=-1); 39 | void Update(const byte *input, size_t length); 40 | void ProcessData(byte *outString, const byte *inString, size_t length); 41 | void TruncatedFinal(byte *mac, size_t macSize); 42 | 43 | protected: 44 | void AuthenticateData(const byte *data, size_t len); 45 | const SymmetricCipher & GetSymmetricCipher() const {return const_cast(this)->AccessSymmetricCipher();}; 46 | 47 | virtual SymmetricCipher & AccessSymmetricCipher() =0; 48 | virtual bool AuthenticationIsOnPlaintext() const =0; 49 | virtual unsigned int AuthenticationBlockSize() const =0; 50 | virtual void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) =0; 51 | virtual void Resync(const byte *iv, size_t len) =0; 52 | virtual size_t AuthenticateBlocks(const byte *data, size_t len) =0; 53 | virtual void AuthenticateLastHeaderBlock() =0; 54 | virtual void AuthenticateLastConfidentialBlock() {} 55 | virtual void AuthenticateLastFooterBlock(byte *mac, size_t macSize) =0; 56 | 57 | enum State {State_Start, State_KeySet, State_IVSet, State_AuthUntransformed, State_AuthTransformed, State_AuthFooter}; 58 | State m_state; 59 | unsigned int m_bufferedDataLength; 60 | lword m_totalHeaderLength, m_totalMessageLength, m_totalFooterLength; 61 | AlignedSecByteBlock m_buffer; 62 | }; 63 | 64 | NAMESPACE_END 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/panama.txt: -------------------------------------------------------------------------------- 1 | AlgorithmType: MessageDigest 2 | Name: Panama-LE 3 | Source: Panama reference implementation 4 | Message: "" 5 | Digest: aa0cc954d757d7ac7779ca3342334ca471abd47d5952ac91ed837ecd5b16922b 6 | Test: Verify 7 | Message: "The quick brown fox jumps over the lazy dog" 8 | Digest: 5f5ca355b90ac622b0aa7e654ef5f27e9e75111415b48b8afe3add1c6b89cba1 9 | Test: Verify 10 | Source: generated by Crypto++ 5.2.1 11 | Message: r15625 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 12 | Digest: af9c66fb6058e2232a5dfba063ee14b0f86f0e334e165812559435464dd9bb60 13 | Test: Verify 14 | 15 | AlgorithmType: MessageDigest 16 | Name: Panama-BE 17 | Source: Panama reference implementation 18 | Message: "" 19 | Digest: e81aa04523532dd7267e5c5bc3ba0e289837a62ba032350351980e960a84b0af 20 | Test: Verify 21 | Message: "The quick brown fox jumps over the lazy dog" 22 | Digest: 8fa7dadce0110f979a0b795e76b2c25628d8bda88747758149c42e3bc13f85bc 23 | Test: Verify 24 | Source: generated by Crypto++ 5.2.1 25 | Message: r15625 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 26 | Digest: cb34f0937e8d870d3bd7ff6311765f2c229a6c2154e4db119538db5159437cab 27 | Test: Verify 28 | 29 | AlgorithmType: MAC 30 | Name: Panama-LE 31 | Source: modified from Panama hash test vectors 32 | Key: "" 33 | Message: "" 34 | MAC: aa0cc954d757d7ac7779ca3342334ca471abd47d5952ac91ed837ecd5b16922b 35 | Test: Verify 36 | Message: "The quick brown fox jumps over the lazy dog" 37 | MAC: 5f5ca355b90ac622b0aa7e654ef5f27e9e75111415b48b8afe3add1c6b89cba1 38 | Test: Verify 39 | Message: r15625 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 40 | MAC: af9c66fb6058e2232a5dfba063ee14b0f86f0e334e165812559435464dd9bb60 41 | Test: Verify 42 | Key: "The " 43 | Message: "quick brown fox jumps over the lazy dog" 44 | MAC: 5f5ca355b90ac622b0aa7e654ef5f27e9e75111415b48b8afe3add1c6b89cba1 45 | Test: Verify 46 | 47 | AlgorithmType: MAC 48 | Name: Panama-BE 49 | Source: modified from Panama hash test vectors 50 | Key: "" 51 | Message: "" 52 | MAC: e81aa04523532dd7267e5c5bc3ba0e289837a62ba032350351980e960a84b0af 53 | Test: Verify 54 | Message: "The quick brown fox jumps over the lazy dog" 55 | MAC: 8fa7dadce0110f979a0b795e76b2c25628d8bda88747758149c42e3bc13f85bc 56 | Test: Verify 57 | Message: r15625 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 58 | MAC: cb34f0937e8d870d3bd7ff6311765f2c229a6c2154e4db119538db5159437cab 59 | Test: Verify 60 | Key: "The " 61 | Message: "quick brown fox jumps over the lazy dog" 62 | MAC: 8fa7dadce0110f979a0b795e76b2c25628d8bda88747758149c42e3bc13f85bc 63 | Test: Verify 64 | 65 | AlgorithmType: SymmetricCipher 66 | Source: generated by Crypto++ 5.2.1 67 | Key: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 68 | IV: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 69 | Name: Panama-LE 70 | Plaintext: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 71 | Ciphertext: F07F5FF2CCD01A0A7D44ACD6D239C2AF0DA1FF35275BAF5DFA6E09411B79D8B9 72 | Test: Encrypt 73 | Name: Panama-BE 74 | Plaintext: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 75 | Ciphertext: E12E2F6BA41AE832D888DA9FA6863BC37C0E996F190A1711330322D37BD98CA4 76 | Test: Encrypt 77 | -------------------------------------------------------------------------------- /src-cryptopp/rijndael.h: -------------------------------------------------------------------------------- 1 | // rijndael.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file rijndael.h 4 | //! \brief Classes for Rijndael encryption algorithm 5 | //! \details All key sizes are supported. The library only provides Rijndael with 128-bit blocks, 6 | //! and not 192-bit or 256-bit blocks 7 | 8 | #ifndef CRYPTOPP_RIJNDAEL_H 9 | #define CRYPTOPP_RIJNDAEL_H 10 | 11 | #include "seckey.h" 12 | #include "secblock.h" 13 | 14 | // Clang 3.3 integrated assembler crash on Linux 15 | #if CRYPTOPP_BOOL_X32 || (defined(CRYPTOPP_LLVM_CLANG_VERSION) && (CRYPTOPP_LLVM_CLANG_VERSION < 30400)) 16 | # define CRYPTOPP_DISABLE_RIJNDAEL_ASM 17 | #endif 18 | 19 | NAMESPACE_BEGIN(CryptoPP) 20 | 21 | //! \brief Rijndael block cipher information 22 | struct Rijndael_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8> 23 | { 24 | CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return CRYPTOPP_RIJNDAEL_NAME;} 25 | }; 26 | 27 | //! \brief Rijndael block cipher implementation details 28 | //! \sa Rijndael 29 | class CRYPTOPP_DLL Rijndael : public Rijndael_Info, public BlockCipherDocumentation 30 | { 31 | //! \brief Rijndael block cipher data processing functionss 32 | //! \details Provides implementation common to encryption and decryption 33 | class CRYPTOPP_DLL 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 | static void FillEncTable(); 40 | static void FillDecTable(); 41 | 42 | // VS2005 workaround: have to put these on seperate lines, or error C2487 is triggered in DLL build 43 | static const byte Se[256]; 44 | static const byte Sd[256]; 45 | 46 | static const word32 rcon[]; 47 | 48 | unsigned int m_rounds; 49 | FixedSizeAlignedSecBlock m_key; 50 | }; 51 | 52 | //! \brief Rijndael block cipher data processing functions 53 | //! \details Provides implementation for encryption transformation 54 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Enc : public Base 55 | { 56 | public: 57 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 58 | #if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86 59 | Enc(); 60 | size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const; 61 | private: 62 | SecByteBlock m_aliasBlock; 63 | #endif 64 | }; 65 | 66 | //! \brief Rijndael block cipher data processing functions 67 | //! \details Provides implementation for decryption transformation 68 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Dec : public Base 69 | { 70 | public: 71 | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 72 | #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE 73 | size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const; 74 | #endif 75 | }; 76 | 77 | public: 78 | typedef BlockCipherFinal Encryption; 79 | typedef BlockCipherFinal Decryption; 80 | }; 81 | 82 | typedef Rijndael::Encryption RijndaelEncryption; 83 | typedef Rijndael::Decryption RijndaelDecryption; 84 | 85 | NAMESPACE_END 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src-cryptopp/sha.h: -------------------------------------------------------------------------------- 1 | // sha.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file 4 | //! \headerfile sha.h 5 | //! \brief Classes for SHA-1 and SHA-2 family of message digests 6 | 7 | #ifndef CRYPTOPP_SHA_H 8 | #define CRYPTOPP_SHA_H 9 | 10 | #include "config.h" 11 | #include "iterhash.h" 12 | 13 | // Clang 3.3 integrated assembler crash on Linux 14 | // http://github.com/weidai11/cryptopp/issues/264 15 | #if defined(CRYPTOPP_LLVM_CLANG_VERSION) && (CRYPTOPP_LLVM_CLANG_VERSION < 30400) 16 | # define CRYPTOPP_DISABLE_SHA_ASM 17 | #endif 18 | 19 | NAMESPACE_BEGIN(CryptoPP) 20 | 21 | /// SHA-1 22 | class CRYPTOPP_DLL SHA1 : public IteratedHashWithStaticTransform 23 | { 24 | public: 25 | static void CRYPTOPP_API InitState(HashWordType *state); 26 | static void CRYPTOPP_API Transform(word32 *digest, const word32 *data); 27 | CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-1";} 28 | }; 29 | 30 | typedef SHA1 SHA; // for backwards compatibility 31 | 32 | //! implements the SHA-256 standard 33 | class CRYPTOPP_DLL SHA256 : public IteratedHashWithStaticTransform 34 | { 35 | public: 36 | #if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM) 37 | size_t HashMultipleBlocks(const word32 *input, size_t length); 38 | #endif 39 | static void CRYPTOPP_API InitState(HashWordType *state); 40 | static void CRYPTOPP_API Transform(word32 *digest, const word32 *data); 41 | CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";} 42 | }; 43 | 44 | //! implements the SHA-224 standard 45 | class CRYPTOPP_DLL SHA224 : public IteratedHashWithStaticTransform 46 | { 47 | public: 48 | #if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM) 49 | size_t HashMultipleBlocks(const word32 *input, size_t length); 50 | #endif 51 | static void CRYPTOPP_API InitState(HashWordType *state); 52 | static void CRYPTOPP_API Transform(word32 *digest, const word32 *data) {SHA256::Transform(digest, data);} 53 | CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";} 54 | }; 55 | 56 | //! implements the SHA-512 standard 57 | class CRYPTOPP_DLL SHA512 : public IteratedHashWithStaticTransform 58 | { 59 | public: 60 | static void CRYPTOPP_API InitState(HashWordType *state); 61 | static void CRYPTOPP_API Transform(word64 *digest, const word64 *data); 62 | CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-512";} 63 | }; 64 | 65 | //! implements the SHA-384 standard 66 | class CRYPTOPP_DLL SHA384 : public IteratedHashWithStaticTransform 67 | { 68 | public: 69 | static void CRYPTOPP_API InitState(HashWordType *state); 70 | static void CRYPTOPP_API Transform(word64 *digest, const word64 *data) {SHA512::Transform(digest, data);} 71 | CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-384";} 72 | }; 73 | 74 | NAMESPACE_END 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/pycryptopp/testvectors/KAT_AES/ECBKeySbox128e.txt: -------------------------------------------------------------------------------- 1 | [ENCRYPT] 2 | 3 | COUNT = 0 4 | KEY = 10a58869d74be5a374cf867cfb473859 5 | PLAINTEXT = 00000000000000000000000000000000 6 | CIPHERTEXT = 6d251e6944b051e04eaa6fb4dbf78465 7 | 8 | COUNT = 1 9 | KEY = caea65cdbb75e9169ecd22ebe6e54675 10 | PLAINTEXT = 00000000000000000000000000000000 11 | CIPHERTEXT = 6e29201190152df4ee058139def610bb 12 | 13 | COUNT = 2 14 | KEY = a2e2fa9baf7d20822ca9f0542f764a41 15 | PLAINTEXT = 00000000000000000000000000000000 16 | CIPHERTEXT = c3b44b95d9d2f25670eee9a0de099fa3 17 | 18 | COUNT = 3 19 | KEY = b6364ac4e1de1e285eaf144a2415f7a0 20 | PLAINTEXT = 00000000000000000000000000000000 21 | CIPHERTEXT = 5d9b05578fc944b3cf1ccf0e746cd581 22 | 23 | COUNT = 4 24 | KEY = 64cf9c7abc50b888af65f49d521944b2 25 | PLAINTEXT = 00000000000000000000000000000000 26 | CIPHERTEXT = f7efc89d5dba578104016ce5ad659c05 27 | 28 | COUNT = 5 29 | KEY = 47d6742eefcc0465dc96355e851b64d9 30 | PLAINTEXT = 00000000000000000000000000000000 31 | CIPHERTEXT = 0306194f666d183624aa230a8b264ae7 32 | 33 | COUNT = 6 34 | KEY = 3eb39790678c56bee34bbcdeccf6cdb5 35 | PLAINTEXT = 00000000000000000000000000000000 36 | CIPHERTEXT = 858075d536d79ccee571f7d7204b1f67 37 | 38 | COUNT = 7 39 | KEY = 64110a924f0743d500ccadae72c13427 40 | PLAINTEXT = 00000000000000000000000000000000 41 | CIPHERTEXT = 35870c6a57e9e92314bcb8087cde72ce 42 | 43 | COUNT = 8 44 | KEY = 18d8126516f8a12ab1a36d9f04d68e51 45 | PLAINTEXT = 00000000000000000000000000000000 46 | CIPHERTEXT = 6c68e9be5ec41e22c825b7c7affb4363 47 | 48 | COUNT = 9 49 | KEY = f530357968578480b398a3c251cd1093 50 | PLAINTEXT = 00000000000000000000000000000000 51 | CIPHERTEXT = f5df39990fc688f1b07224cc03e86cea 52 | 53 | COUNT = 10 54 | KEY = da84367f325d42d601b4326964802e8e 55 | PLAINTEXT = 00000000000000000000000000000000 56 | CIPHERTEXT = bba071bcb470f8f6586e5d3add18bc66 57 | 58 | COUNT = 11 59 | KEY = e37b1c6aa2846f6fdb413f238b089f23 60 | PLAINTEXT = 00000000000000000000000000000000 61 | CIPHERTEXT = 43c9f7e62f5d288bb27aa40ef8fe1ea8 62 | 63 | COUNT = 12 64 | KEY = 6c002b682483e0cabcc731c253be5674 65 | PLAINTEXT = 00000000000000000000000000000000 66 | CIPHERTEXT = 3580d19cff44f1014a7c966a69059de5 67 | 68 | COUNT = 13 69 | KEY = 143ae8ed6555aba96110ab58893a8ae1 70 | PLAINTEXT = 00000000000000000000000000000000 71 | CIPHERTEXT = 806da864dd29d48deafbe764f8202aef 72 | 73 | COUNT = 14 74 | KEY = b69418a85332240dc82492353956ae0c 75 | PLAINTEXT = 00000000000000000000000000000000 76 | CIPHERTEXT = a303d940ded8f0baff6f75414cac5243 77 | 78 | COUNT = 15 79 | KEY = 71b5c08a1993e1362e4d0ce9b22b78d5 80 | PLAINTEXT = 00000000000000000000000000000000 81 | CIPHERTEXT = c2dabd117f8a3ecabfbb11d12194d9d0 82 | 83 | COUNT = 16 84 | KEY = e234cdca2606b81f29408d5f6da21206 85 | PLAINTEXT = 00000000000000000000000000000000 86 | CIPHERTEXT = fff60a4740086b3b9c56195b98d91a7b 87 | 88 | COUNT = 17 89 | KEY = 13237c49074a3da078dc1d828bb78c6f 90 | PLAINTEXT = 00000000000000000000000000000000 91 | CIPHERTEXT = 8146a08e2357f0caa30ca8c94d1a0544 92 | 93 | COUNT = 18 94 | KEY = 3071a2a48fe6cbd04f1a129098e308f8 95 | PLAINTEXT = 00000000000000000000000000000000 96 | CIPHERTEXT = 4b98e06d356deb07ebb824e5713f7be3 97 | 98 | COUNT = 19 99 | KEY = 90f42ec0f68385f2ffc5dfc03a654dce 100 | PLAINTEXT = 00000000000000000000000000000000 101 | CIPHERTEXT = 7a20a53d460fc9ce0423a7a0764c6cf2 102 | 103 | COUNT = 20 104 | KEY = febd9a24d8b65c1c787d50a4ed3619a9 105 | PLAINTEXT = 00000000000000000000000000000000 106 | CIPHERTEXT = f4a70d8af877f9b02b4c40df57d45b17 107 | -------------------------------------------------------------------------------- /src-cryptopp/oaep.cpp: -------------------------------------------------------------------------------- 1 | // oaep.cpp - written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | 5 | #ifndef CRYPTOPP_IMPORTS 6 | 7 | #include "oaep.h" 8 | #include "stdcpp.h" 9 | #include "smartptr.h" 10 | 11 | NAMESPACE_BEGIN(CryptoPP) 12 | 13 | // ******************************************************** 14 | 15 | size_t OAEP_Base::MaxUnpaddedLength(size_t paddedLength) const 16 | { 17 | return SaturatingSubtract(paddedLength/8, 1+2*DigestSize()); 18 | } 19 | 20 | void OAEP_Base::Pad(RandomNumberGenerator &rng, const byte *input, size_t inputLength, byte *oaepBlock, size_t oaepBlockLen, const NameValuePairs ¶meters) const 21 | { 22 | CRYPTOPP_ASSERT (inputLength <= MaxUnpaddedLength(oaepBlockLen)); 23 | 24 | // convert from bit length to byte length 25 | if (oaepBlockLen % 8 != 0) 26 | { 27 | oaepBlock[0] = 0; 28 | oaepBlock++; 29 | } 30 | oaepBlockLen /= 8; 31 | 32 | member_ptr pHash(NewHash()); 33 | const size_t hLen = pHash->DigestSize(); 34 | const size_t seedLen = hLen, dbLen = oaepBlockLen-seedLen; 35 | byte *const maskedSeed = oaepBlock; 36 | byte *const maskedDB = oaepBlock+seedLen; 37 | 38 | ConstByteArrayParameter encodingParameters; 39 | parameters.GetValue(Name::EncodingParameters(), encodingParameters); 40 | 41 | // DB = pHash || 00 ... || 01 || M 42 | pHash->CalculateDigest(maskedDB, encodingParameters.begin(), encodingParameters.size()); 43 | memset(maskedDB+hLen, 0, dbLen-hLen-inputLength-1); 44 | maskedDB[dbLen-inputLength-1] = 0x01; 45 | memcpy(maskedDB+dbLen-inputLength, input, inputLength); 46 | 47 | rng.GenerateBlock(maskedSeed, seedLen); 48 | member_ptr pMGF(NewMGF()); 49 | pMGF->GenerateAndMask(*pHash, maskedDB, dbLen, maskedSeed, seedLen); 50 | pMGF->GenerateAndMask(*pHash, maskedSeed, seedLen, maskedDB, dbLen); 51 | } 52 | 53 | DecodingResult OAEP_Base::Unpad(const byte *oaepBlock, size_t oaepBlockLen, byte *output, const NameValuePairs ¶meters) const 54 | { 55 | bool invalid = false; 56 | 57 | // convert from bit length to byte length 58 | if (oaepBlockLen % 8 != 0) 59 | { 60 | invalid = (oaepBlock[0] != 0) || invalid; 61 | oaepBlock++; 62 | } 63 | oaepBlockLen /= 8; 64 | 65 | member_ptr pHash(NewHash()); 66 | const size_t hLen = pHash->DigestSize(); 67 | const size_t seedLen = hLen, dbLen = oaepBlockLen-seedLen; 68 | 69 | invalid = (oaepBlockLen < 2*hLen+1) || invalid; 70 | 71 | SecByteBlock t(oaepBlock, oaepBlockLen); 72 | byte *const maskedSeed = t; 73 | byte *const maskedDB = t+seedLen; 74 | 75 | member_ptr pMGF(NewMGF()); 76 | pMGF->GenerateAndMask(*pHash, maskedSeed, seedLen, maskedDB, dbLen); 77 | pMGF->GenerateAndMask(*pHash, maskedDB, dbLen, maskedSeed, seedLen); 78 | 79 | ConstByteArrayParameter encodingParameters; 80 | parameters.GetValue(Name::EncodingParameters(), encodingParameters); 81 | 82 | // DB = pHash' || 00 ... || 01 || M 83 | byte *M = std::find(maskedDB+hLen, maskedDB+dbLen, 0x01); 84 | invalid = (M == maskedDB+dbLen) || invalid; 85 | invalid = (std::find_if(maskedDB+hLen, M, std::bind2nd(std::not_equal_to(), byte(0))) != M) || invalid; 86 | invalid = !pHash->VerifyDigest(maskedDB, encodingParameters.begin(), encodingParameters.size()) || invalid; 87 | 88 | if (invalid) 89 | return DecodingResult(); 90 | 91 | M++; 92 | memcpy(output, M, maskedDB+dbLen-M); 93 | return DecodingResult(maskedDB+dbLen-M); 94 | } 95 | 96 | NAMESPACE_END 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /src-cryptopp/serpent.cpp: -------------------------------------------------------------------------------- 1 | // serpent.cpp - written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | 5 | #include "serpent.h" 6 | #include "secblock.h" 7 | #include "misc.h" 8 | 9 | #include "serpentp.h" 10 | 11 | NAMESPACE_BEGIN(CryptoPP) 12 | 13 | void Serpent_KeySchedule(word32 *k, unsigned int rounds, const byte *userKey, size_t keylen) 14 | { 15 | FixedSizeSecBlock k0; 16 | GetUserKey(LITTLE_ENDIAN_ORDER, k0.begin(), 8, userKey, keylen); 17 | if (keylen < 32) 18 | k0[keylen/4] |= word32(1) << ((keylen%4)*8); 19 | 20 | word32 t = k0[7]; 21 | unsigned int i; 22 | for (i = 0; i < 8; ++i) 23 | k[i] = k0[i] = t = rotlFixed(k0[i] ^ k0[(i+3)%8] ^ k0[(i+5)%8] ^ t ^ 0x9e3779b9 ^ i, 11); 24 | for (i = 8; i < 4*(rounds+1); ++i) 25 | k[i] = t = rotlFixed(k[i-8] ^ k[i-5] ^ k[i-3] ^ t ^ 0x9e3779b9 ^ i, 11); 26 | k -= 20; 27 | 28 | word32 a,b,c,d,e; 29 | for (i=0; i Block; 51 | 52 | void Serpent::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const 53 | { 54 | word32 a, b, c, d, e; 55 | 56 | Block::Get(inBlock)(a)(b)(c)(d); 57 | 58 | const word32 *k = m_key; 59 | unsigned int i=1; 60 | 61 | do 62 | { 63 | beforeS0(KX); beforeS0(S0); afterS0(LT); 64 | afterS0(KX); afterS0(S1); afterS1(LT); 65 | afterS1(KX); afterS1(S2); afterS2(LT); 66 | afterS2(KX); afterS2(S3); afterS3(LT); 67 | afterS3(KX); afterS3(S4); afterS4(LT); 68 | afterS4(KX); afterS4(S5); afterS5(LT); 69 | afterS5(KX); afterS5(S6); afterS6(LT); 70 | afterS6(KX); afterS6(S7); 71 | 72 | if (i == 4) 73 | break; 74 | 75 | ++i; 76 | c = b; 77 | b = e; 78 | e = d; 79 | d = a; 80 | a = e; 81 | k += 32; 82 | beforeS0(LT); 83 | } 84 | while (true); 85 | 86 | afterS7(KX); 87 | 88 | Block::Put(xorBlock, outBlock)(d)(e)(b)(a); 89 | } 90 | 91 | void Serpent::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const 92 | { 93 | word32 a, b, c, d, e; 94 | 95 | Block::Get(inBlock)(a)(b)(c)(d); 96 | 97 | const word32 *k = m_key + 96; 98 | unsigned int i=4; 99 | 100 | beforeI7(KX); 101 | goto start; 102 | 103 | do 104 | { 105 | c = b; 106 | b = d; 107 | d = e; 108 | k -= 32; 109 | beforeI7(ILT); 110 | start: 111 | beforeI7(I7); afterI7(KX); 112 | afterI7(ILT); afterI7(I6); afterI6(KX); 113 | afterI6(ILT); afterI6(I5); afterI5(KX); 114 | afterI5(ILT); afterI5(I4); afterI4(KX); 115 | afterI4(ILT); afterI4(I3); afterI3(KX); 116 | afterI3(ILT); afterI3(I2); afterI2(KX); 117 | afterI2(ILT); afterI2(I1); afterI1(KX); 118 | afterI1(ILT); afterI1(I0); afterI0(KX); 119 | } 120 | while (--i != 0); 121 | 122 | Block::Put(xorBlock, outBlock)(a)(d)(b)(e); 123 | } 124 | 125 | NAMESPACE_END 126 | -------------------------------------------------------------------------------- /src/pycryptopp/publickey/ed25519/keys.py: -------------------------------------------------------------------------------- 1 | import _ed25519 2 | BadSignatureError = _ed25519.BadSignatureError 3 | 4 | __doc__ = """\ 5 | ed25519 -- Ed25519 public-key signatures 6 | 7 | To create a new Ed25519 signing key, create a 32-byte unguessable bytestring, 8 | with keybytes=os.urandom(32), and pass it to the SigningKey(keybytes) 9 | constructor. To create the same key in the future, call the constructor with 10 | the same string. 11 | 12 | To get a verifying key from a signing key, first get the verifying key bytes 13 | with verfbytes=sk.get_verifying_key_bytes(), then construct the VerifyingKey 14 | instance with VerifyingKey(verfbytes). 15 | 16 | To sign a message, use sig=sk.sign(msg), which returns the signature as a 17 | 64-byte binary bytestring. To verify a signature, use vk.verify(sig, msg), 18 | which either returns None or raises BadSignatureError. 19 | """ 20 | 21 | class SigningKey(object): 22 | # this is how all keys are created 23 | def __init__(self, sk_bytes): 24 | if not isinstance(sk_bytes, type("")): 25 | raise TypeError("must be bytes, not %s" % type(sk_bytes)) 26 | if len(sk_bytes) != 32: 27 | raise ValueError("must be exactly 32 bytes") 28 | vk_bytes, sk_and_vk = _ed25519.publickey(sk_bytes) 29 | assert sk_and_vk[:32] == sk_bytes 30 | assert vk_bytes == sk_and_vk[32:] 31 | self.vk_bytes = vk_bytes 32 | self.sk_and_vk = sk_and_vk 33 | 34 | def __eq__(self, them): 35 | if not isinstance(them, object): return False 36 | return (them.__class__ == self.__class__ 37 | and them.sk_and_vk == self.sk_and_vk) 38 | 39 | def get_verifying_key_bytes(self): 40 | return self.vk_bytes 41 | 42 | def sign(self, msg): 43 | sig_and_msg = _ed25519.sign(msg, self.sk_and_vk) 44 | # the response is R+S+msg 45 | sig_R = sig_and_msg[0:32] 46 | sig_S = sig_and_msg[32:64] 47 | msg_out = sig_and_msg[64:] 48 | sig_out = sig_R + sig_S 49 | assert msg_out == msg 50 | return sig_out 51 | 52 | class VerifyingKey(object): 53 | def __init__(self, vk_bytes): 54 | if not isinstance(vk_bytes, type("")): 55 | raise TypeError("must be bytes, not %s" % type(vk_bytes)) 56 | if len(vk_bytes) != 32: 57 | raise ValueError("must be exactly 32 bytes") 58 | self.vk_bytes = vk_bytes 59 | 60 | def __eq__(self, them): 61 | if not isinstance(them, object): return False 62 | return (them.__class__ == self.__class__ 63 | and them.vk_bytes == self.vk_bytes) 64 | 65 | def verify(self, sig, msg): 66 | assert isinstance(sig, type("")) # string, really bytes 67 | assert len(sig) == 64 68 | sig_R = sig[:32] 69 | sig_S = sig[32:] 70 | sig_and_msg = sig_R + sig_S + msg 71 | # this might raise BadSignatureError 72 | msg2 = _ed25519.open(sig_and_msg, self.vk_bytes) 73 | assert msg2 == msg 74 | 75 | def selftest(): 76 | from binascii import unhexlify 77 | message = "crypto libraries should always test themselves at powerup" 78 | sk_bytes = unhexlify("548b1f9f938519ad3d527d8c47a1e6ec1439fbec61710b245363865c6f234899") 79 | sk = SigningKey(sk_bytes) 80 | vk_bytes = unhexlify("787162d9ad1ad571237681560c1ad653fb7df9e09e637e6a8072e4520fd288ca") 81 | vk = VerifyingKey(vk_bytes) 82 | assert sk.get_verifying_key_bytes() == vk_bytes 83 | sig = sk.sign(message) 84 | assert sig == "13f42bc2d485e76c7cfaad25e1a840ede25b44a73befb0a528d836d7b434cf87e260c09d980388fab4cb564885857ea4dc3fb04107ca74960cc5a4d415fbf50d".decode('hex'), sig 85 | vk.verify(sig, message) 86 | 87 | selftest() 88 | -------------------------------------------------------------------------------- /src-ed25519/supercop-ref/ed25519.c: -------------------------------------------------------------------------------- 1 | #include "crypto_sign.h" 2 | 3 | #include "crypto_verify_32.h" 4 | #include "sha512.h" 5 | 6 | #include "ge25519.h" 7 | 8 | static void get_hram(unsigned char *hram, const unsigned char *sm, const unsigned char *pk, unsigned char *playground, unsigned long long smlen) 9 | { 10 | unsigned long long i; 11 | 12 | for (i = 0;i < 32;++i) playground[i] = sm[i]; 13 | for (i = 32;i < 64;++i) playground[i] = pk[i-32]; 14 | for (i = 64;i < smlen;++i) playground[i] = sm[i]; 15 | 16 | crypto_hash_sha512(hram,playground,smlen); 17 | } 18 | 19 | 20 | int crypto_sign_publickey( 21 | unsigned char *pk, // write 32 bytes into this 22 | unsigned char *sk, // write 64 bytes into this (seed+pubkey) 23 | unsigned char *seed // 32 bytes 24 | ) 25 | { 26 | sc25519 scsk; 27 | ge25519 gepk; 28 | int i; 29 | 30 | crypto_hash_sha512(sk, seed, 32); 31 | sk[0] &= 248; 32 | sk[31] &= 127; 33 | sk[31] |= 64; 34 | 35 | sc25519_from32bytes(&scsk,sk); 36 | 37 | ge25519_scalarmult_base(&gepk, &scsk); 38 | ge25519_pack(pk, &gepk); 39 | for(i=0;i<32;i++) 40 | sk[32 + i] = pk[i]; 41 | for(i=0;i<32;i++) 42 | sk[i] = seed[i]; 43 | return 0; 44 | } 45 | 46 | int crypto_sign( 47 | unsigned char *sm,unsigned long long *smlen, 48 | const unsigned char *m,unsigned long long mlen, 49 | const unsigned char *sk 50 | ) 51 | { 52 | sc25519 sck, scs, scsk; 53 | ge25519 ger; 54 | unsigned char r[32]; 55 | unsigned char s[32]; 56 | unsigned char extsk[64]; 57 | unsigned long long i; 58 | unsigned char hmg[crypto_hash_sha512_BYTES]; 59 | unsigned char hram[crypto_hash_sha512_BYTES]; 60 | 61 | crypto_hash_sha512(extsk, sk, 32); 62 | extsk[0] &= 248; 63 | extsk[31] &= 127; 64 | extsk[31] |= 64; 65 | 66 | *smlen = mlen+64; 67 | for(i=0;i= 40800) 16 | # define CRYPTOPP_DISABLE_SALSA_ASM 17 | #endif 18 | 19 | NAMESPACE_BEGIN(CryptoPP) 20 | 21 | //! \class Salsa20_Info 22 | //! \brief Salsa20 stream cipher information 23 | struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8> 24 | { 25 | CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Salsa20";} 26 | }; 27 | 28 | //! \class Salsa20_Policy 29 | //! \brief Salsa20 stream cipher operation 30 | class CRYPTOPP_NO_VTABLE Salsa20_Policy : public AdditiveCipherConcretePolicy 31 | { 32 | protected: 33 | void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); 34 | void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); 35 | void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length); 36 | bool CipherIsRandomAccess() const {return true;} 37 | void SeekToIteration(lword iterationCount); 38 | #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) && !defined(CRYPTOPP_DISABLE_SALSA_ASM) 39 | unsigned int GetAlignment() const; 40 | unsigned int GetOptimalBlockSize() const; 41 | #endif 42 | 43 | FixedSizeAlignedSecBlock m_state; 44 | int m_rounds; 45 | }; 46 | 47 | //! \class Salsa20 48 | //! \brief Salsa20 stream cipher 49 | //! \details Salsa20 provides a variable number of rounds: 8, 12 or 20. The default number of rounds is 20. 50 | //! \sa XSalsa20 51 | struct Salsa20 : public Salsa20_Info, public SymmetricCipherDocumentation 52 | { 53 | typedef SymmetricCipherFinal >, Salsa20_Info> Encryption; 54 | typedef Encryption Decryption; 55 | }; 56 | 57 | //! \class XSalsa20_Info 58 | //! \brief XSalsa20 stream cipher information 59 | struct XSalsa20_Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 24> 60 | { 61 | CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "XSalsa20";} 62 | }; 63 | 64 | //! \class XSalsa20_Policy 65 | //! \brief XSalsa20 stream cipher operation 66 | class CRYPTOPP_NO_VTABLE XSalsa20_Policy : public Salsa20_Policy 67 | { 68 | public: 69 | void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); 70 | void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length); 71 | 72 | protected: 73 | FixedSizeSecBlock m_key; 74 | }; 75 | 76 | //! \class XSalsa20 77 | //! \brief XSalsa20 stream cipher 78 | //! \details XSalsa20 provides a variable number of rounds: 8, 12 or 20. The default number of rounds is 20. 79 | //! \sa XSalsa20 80 | struct XSalsa20 : public XSalsa20_Info, public SymmetricCipherDocumentation 81 | { 82 | typedef SymmetricCipherFinal >, XSalsa20_Info> Encryption; 83 | typedef Encryption Decryption; 84 | }; 85 | 86 | NAMESPACE_END 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/Readme.txt: -------------------------------------------------------------------------------- 1 | Test Data Format 2 | ================ 3 | 4 | A test data file is an ASCII text file composed of sections separated by 5 | blank lines. Each section is stand-alone and independent of other 6 | sections that may be in the same file, and contains one or more tests. 7 | 8 | A section is composed of a sequence of fields. Each field is one or more 9 | lines composed of a field name, followed by a colon (":"), followed by a 10 | field body. All but the last line of a field must end with a backslash 11 | ("\"). If any line contains a hash mark ("#"), the hash mark and 12 | everything after it on the same line is not considered part of the field 13 | body. 14 | 15 | Each section must contain fields named AlgorithmType, Name, Source, and 16 | Test. The presence and semantics of other fields depend on the algorithm 17 | being tested and the tests to be run. 18 | 19 | Each section may contain more than one test and therefore more than one 20 | field named Test. In that case the order of the fields is significant. A 21 | test should always use the last field with any given name that occurs 22 | before the Test field. 23 | 24 | Data Types 25 | ========== 26 | 27 | int - small integer (less than 2^32) in decimal representation 28 | string - human readable string 29 | encoded string - can be one of the following 30 | - quoted string: "message" means "message" without the quotes 31 | or terminating '\0' 32 | - hex encoded string: 0x74657374 or 74657374 means "test" 33 | - repeated string: r100 "message" to repeat "message" 100 times, or 34 | r256 0x0011 to repeat 0x0011 256 times 35 | 36 | Field Types 37 | =========== 38 | 39 | AlgorithmType - string, for example "Signature", "AsymmetricCipher", 40 | "SymmetricCipher", "MAC", "MessageDigest", or "KeyFactory" 41 | Name - string, an algorithm name from SCAN 42 | Test - string, identifies the test to run 43 | Source - string, text explaining where the test data came from 44 | Comment - string, other comments about the test data 45 | KeyFormat - string, specifies the key format. "Component" here means 46 | each component of the key or key pair is specified separately as a name, 47 | value pair, with the names depending on the algorithm being tested. 48 | Otherwise the value names "Key", or "PublicKey" and "PrivateKey" are 49 | used. 50 | Key - encoded string 51 | PublicKey - encoded string 52 | PrivateKey - encoded string 53 | Modulus - the modulus when KeyFormat=Component 54 | SubgroupOrder - the subgroup order when KeyFormat=Component 55 | SubgroupGenerator - the subgroup generator when KeyFormat=Component 56 | PublicElement - the public element when KeyFormat=Component 57 | PrivateExponent - the private exponent when KeyFormat=Component 58 | Message - encoded string, message to be signed or verified 59 | Signature - encoded string, signature to be verified or compared with 60 | Plaintext - encoded string 61 | Ciphertext - encoded string 62 | Header - encoded string 63 | Footer - encoded string 64 | DerivedKey - encoded string 65 | DerivedLength - encoded string 66 | Digest - encoded string 67 | TruncatedSize - int, size of truncated digest in bytes 68 | Seek - int, seek location for random access ciphers 69 | (more to come here) 70 | 71 | Possible Tests 72 | ============== 73 | 74 | KeyPairValidAndConsistent - public and private keys are both valid and 75 | consistent with each other 76 | PublicKeyInvalid - public key validation should not pass 77 | PrivateKeyInvalid - private key validation should not pass 78 | Verify - signature/digest/MAC verification should pass 79 | VerifyTruncated - truncated digest/MAC verification should pass 80 | NotVerify - signature/digest/MAC verification should not pass 81 | DeterministicSign - sign message using given seed, and the resulting 82 | signature should be equal to the given signature 83 | DecryptMatch - ciphertext decrypts to plaintext 84 | 85 | (more to come here) 86 | -------------------------------------------------------------------------------- /src-cryptopp/eprecomp.h: -------------------------------------------------------------------------------- 1 | // eprecomp.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file eprecomp.h 4 | //! \brief Classes for precomputation in a group 5 | 6 | #ifndef CRYPTOPP_EPRECOMP_H 7 | #define CRYPTOPP_EPRECOMP_H 8 | 9 | #include "cryptlib.h" 10 | #include "integer.h" 11 | #include "algebra.h" 12 | #include "stdcpp.h" 13 | 14 | NAMESPACE_BEGIN(CryptoPP) 15 | 16 | template 17 | class DL_GroupPrecomputation 18 | { 19 | public: 20 | typedef T Element; 21 | 22 | virtual bool NeedConversions() const {return false;} 23 | virtual Element ConvertIn(const Element &v) const {return v;} 24 | virtual Element ConvertOut(const Element &v) const {return v;} 25 | virtual const AbstractGroup & GetGroup() const =0; 26 | virtual Element BERDecodeElement(BufferedTransformation &bt) const =0; 27 | virtual void DEREncodeElement(BufferedTransformation &bt, const Element &P) const =0; 28 | 29 | #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 30 | virtual ~DL_GroupPrecomputation() {} 31 | #endif 32 | }; 33 | 34 | template 35 | class DL_FixedBasePrecomputation 36 | { 37 | public: 38 | typedef T Element; 39 | 40 | virtual bool IsInitialized() const =0; 41 | virtual void SetBase(const DL_GroupPrecomputation &group, const Element &base) =0; 42 | virtual const Element & GetBase(const DL_GroupPrecomputation &group) const =0; 43 | virtual void Precompute(const DL_GroupPrecomputation &group, unsigned int maxExpBits, unsigned int storage) =0; 44 | virtual void Load(const DL_GroupPrecomputation &group, BufferedTransformation &storedPrecomputation) =0; 45 | virtual void Save(const DL_GroupPrecomputation &group, BufferedTransformation &storedPrecomputation) const =0; 46 | virtual Element Exponentiate(const DL_GroupPrecomputation &group, const Integer &exponent) const =0; 47 | virtual Element CascadeExponentiate(const DL_GroupPrecomputation &group, const Integer &exponent, const DL_FixedBasePrecomputation &pc2, const Integer &exponent2) const =0; 48 | 49 | #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 50 | virtual ~DL_FixedBasePrecomputation() {} 51 | #endif 52 | }; 53 | 54 | template 55 | class DL_FixedBasePrecomputationImpl : public DL_FixedBasePrecomputation 56 | { 57 | public: 58 | typedef T Element; 59 | 60 | DL_FixedBasePrecomputationImpl() : m_windowSize(0) {} 61 | 62 | // DL_FixedBasePrecomputation 63 | bool IsInitialized() const 64 | {return !m_bases.empty();} 65 | void SetBase(const DL_GroupPrecomputation &group, const Element &base); 66 | const Element & GetBase(const DL_GroupPrecomputation &group) const 67 | {return group.NeedConversions() ? m_base : m_bases[0];} 68 | void Precompute(const DL_GroupPrecomputation &group, unsigned int maxExpBits, unsigned int storage); 69 | void Load(const DL_GroupPrecomputation &group, BufferedTransformation &storedPrecomputation); 70 | void Save(const DL_GroupPrecomputation &group, BufferedTransformation &storedPrecomputation) const; 71 | Element Exponentiate(const DL_GroupPrecomputation &group, const Integer &exponent) const; 72 | Element CascadeExponentiate(const DL_GroupPrecomputation &group, const Integer &exponent, const DL_FixedBasePrecomputation &pc2, const Integer &exponent2) const; 73 | 74 | #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 75 | virtual ~DL_FixedBasePrecomputationImpl() {} 76 | #endif 77 | 78 | private: 79 | void PrepareCascade(const DL_GroupPrecomputation &group, std::vector > &eb, const Integer &exponent) const; 80 | 81 | Element m_base; 82 | unsigned int m_windowSize; 83 | Integer m_exponentBase; // what base to represent the exponent in 84 | std::vector m_bases; // precalculated bases 85 | }; 86 | 87 | NAMESPACE_END 88 | 89 | #ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES 90 | #include "eprecomp.cpp" 91 | #endif 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /src-cryptopp/pkcspad.h: -------------------------------------------------------------------------------- 1 | // pkcspad.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file pkcspad.h 4 | //! \brief Classes for PKCS padding schemes 5 | //! \details PKCS#1 v1.5, v2.0 and P1363a allow MD2, MD5, SHA1, SHA224, SHA256, SHA384, SHA512, Tiger and RipeMd-160 to be instantiated. 6 | 7 | #ifndef CRYPTOPP_PKCSPAD_H 8 | #define CRYPTOPP_PKCSPAD_H 9 | 10 | #include "cryptlib.h" 11 | #include "pubkey.h" 12 | 13 | #ifdef CRYPTOPP_IS_DLL 14 | #include "sha.h" 15 | #endif 16 | 17 | NAMESPACE_BEGIN(CryptoPP) 18 | 19 | //! \class PKCS_EncryptionPaddingScheme 20 | //! \brief PKCS#1 v1.5 Encryption Padding Scheme 21 | //! \sa EME-PKCS1-v1_5 22 | class PKCS_EncryptionPaddingScheme : public PK_EncryptionMessageEncodingMethod 23 | { 24 | public: 25 | CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "EME-PKCS1-v1_5";} 26 | 27 | size_t MaxUnpaddedLength(size_t paddedLength) const; 28 | void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs ¶meters) const; 29 | DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs ¶meters) const; 30 | }; 31 | 32 | //! \class PKCS_DigestDecoration 33 | //! \brief PKCS#1 decoration data structure 34 | template class PKCS_DigestDecoration 35 | { 36 | public: 37 | static const byte decoration[]; 38 | static const unsigned int length; 39 | }; 40 | 41 | // PKCS_DigestDecoration can be instantiated with the following 42 | // classes as specified in PKCS#1 v2.0 and P1363a 43 | class SHA1; 44 | class SHA224; 45 | class SHA256; 46 | class SHA384; 47 | class SHA512; 48 | class Tiger; 49 | class RIPEMD160; 50 | namespace Weak1 { 51 | class MD2; 52 | class MD5; 53 | } 54 | // end of list 55 | 56 | #ifdef CRYPTOPP_IS_DLL 57 | CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; 58 | CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; 59 | CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; 60 | CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; 61 | CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; 62 | #endif 63 | 64 | //! \class PKCS1v15_SignatureMessageEncodingMethod 65 | //! \brief PKCS#1 v1.5 Signature Encoding Scheme 66 | //! \sa EMSA-PKCS1-v1_5 67 | class CRYPTOPP_DLL PKCS1v15_SignatureMessageEncodingMethod : public PK_DeterministicSignatureMessageEncodingMethod 68 | { 69 | public: 70 | CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";} 71 | 72 | size_t MinRepresentativeBitLength(size_t hashIdentifierSize, size_t digestSize) const 73 | {return 8 * (digestSize + hashIdentifierSize + 10);} 74 | 75 | void ComputeMessageRepresentative(RandomNumberGenerator &rng, 76 | const byte *recoverableMessage, size_t recoverableMessageLength, 77 | HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, 78 | byte *representative, size_t representativeBitLength) const; 79 | 80 | struct HashIdentifierLookup 81 | { 82 | template struct HashIdentifierLookup2 83 | { 84 | static HashIdentifier Lookup() 85 | { 86 | return HashIdentifier(PKCS_DigestDecoration::decoration, PKCS_DigestDecoration::length); 87 | } 88 | }; 89 | }; 90 | }; 91 | 92 | //! PKCS #1 version 1.5, for use with RSAES and RSASS 93 | /*! Only the following hash functions are supported by this signature standard: 94 | \dontinclude pkcspad.h 95 | \skip can be instantiated 96 | \until end of list 97 | */ 98 | struct PKCS1v15 : public SignatureStandard, public EncryptionStandard 99 | { 100 | typedef PKCS_EncryptionPaddingScheme EncryptionMessageEncodingMethod; 101 | typedef PKCS1v15_SignatureMessageEncodingMethod SignatureMessageEncodingMethod; 102 | }; 103 | 104 | NAMESPACE_END 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /src-cryptopp/mqueue.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTOPP_MQUEUE_H 2 | #define CRYPTOPP_MQUEUE_H 3 | 4 | #include "cryptlib.h" 5 | #include "queue.h" 6 | #include "filters.h" 7 | #include "misc.h" 8 | 9 | #include 10 | 11 | NAMESPACE_BEGIN(CryptoPP) 12 | 13 | //! Message Queue 14 | class CRYPTOPP_DLL MessageQueue : public AutoSignaling 15 | { 16 | public: 17 | MessageQueue(unsigned int nodeSize=256); 18 | 19 | void IsolatedInitialize(const NameValuePairs ¶meters) 20 | {m_queue.IsolatedInitialize(parameters); m_lengths.assign(1, 0U); m_messageCounts.assign(1, 0U);} 21 | size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking) 22 | { 23 | CRYPTOPP_UNUSED(blocking); 24 | m_queue.Put(begin, length); 25 | m_lengths.back() += length; 26 | if (messageEnd) 27 | { 28 | m_lengths.push_back(0); 29 | m_messageCounts.back()++; 30 | } 31 | return 0; 32 | } 33 | bool IsolatedFlush(bool hardFlush, bool blocking) 34 | {CRYPTOPP_UNUSED(hardFlush), CRYPTOPP_UNUSED(blocking); return false;} 35 | bool IsolatedMessageSeriesEnd(bool blocking) 36 | {CRYPTOPP_UNUSED(blocking); m_messageCounts.push_back(0); return false;} 37 | 38 | lword MaxRetrievable() const 39 | {return m_lengths.front();} 40 | bool AnyRetrievable() const 41 | {return m_lengths.front() > 0;} 42 | 43 | size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); 44 | size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const; 45 | 46 | lword TotalBytesRetrievable() const 47 | {return m_queue.MaxRetrievable();} 48 | unsigned int NumberOfMessages() const 49 | {return (unsigned int)m_lengths.size()-1;} 50 | bool GetNextMessage(); 51 | 52 | unsigned int NumberOfMessagesInThisSeries() const 53 | {return m_messageCounts[0];} 54 | unsigned int NumberOfMessageSeries() const 55 | {return (unsigned int)m_messageCounts.size()-1;} 56 | 57 | unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const; 58 | 59 | const byte * Spy(size_t &contiguousSize) const; 60 | 61 | void swap(MessageQueue &rhs); 62 | 63 | private: 64 | ByteQueue m_queue; 65 | std::deque m_lengths; 66 | std::deque m_messageCounts; 67 | }; 68 | 69 | 70 | //! A filter that checks messages on two channels for equality 71 | class CRYPTOPP_DLL EqualityComparisonFilter : public Unflushable > 72 | { 73 | public: 74 | struct MismatchDetected : public Exception {MismatchDetected() : Exception(DATA_INTEGRITY_CHECK_FAILED, "EqualityComparisonFilter: did not receive the same data on two channels") {}}; 75 | 76 | /*! if throwIfNotEqual is false, this filter will output a '\\0' byte when it detects a mismatch, '\\1' otherwise */ 77 | EqualityComparisonFilter(BufferedTransformation *attachment=NULL, bool throwIfNotEqual=true, const std::string &firstChannel="0", const std::string &secondChannel="1") 78 | : m_throwIfNotEqual(throwIfNotEqual), m_mismatchDetected(false) 79 | , m_firstChannel(firstChannel), m_secondChannel(secondChannel) 80 | {Detach(attachment);} 81 | 82 | size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking); 83 | bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true); 84 | 85 | private: 86 | unsigned int MapChannel(const std::string &channel) const; 87 | bool HandleMismatchDetected(bool blocking); 88 | 89 | bool m_throwIfNotEqual, m_mismatchDetected; 90 | std::string m_firstChannel, m_secondChannel; 91 | MessageQueue m_q[2]; 92 | }; 93 | 94 | NAMESPACE_END 95 | 96 | #ifndef __BORLANDC__ 97 | NAMESPACE_BEGIN(std) 98 | template<> inline void swap(CryptoPP::MessageQueue &a, CryptoPP::MessageQueue &b) 99 | { 100 | a.swap(b); 101 | } 102 | NAMESPACE_END 103 | #endif 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | 2 | 3 | =========================================================== 4 | pycryptopp: a small number of good cryptography algorithms 5 | =========================================================== 6 | 7 | Introduction and Licence 8 | ======================== 9 | 10 | Pycryptopp is a collection of Python interfaces to a few good crypto 11 | algorithms. It lives at https://tahoe-lafs.org/trac/pycryptopp 12 | 13 | RECOMMENDED algorithms: 14 | 15 | • XSalsa20 ; from the Crypto++ library ; see pycryptopp.cipher.xsalsa20 16 | • Ed25519 ; from the supercop library ; see pycryptopp.publickey.ed25519 17 | 18 | DEPRECATED algorithms: 19 | 20 | The maintainers of pycryptopp intend to stop supporting these soon. Please 21 | migrate away from depending on pycryptopp's implementation of these 22 | algorithms, or else write to us and offer some inducement to continue 23 | supporting them. 24 | 25 | • RSA from the Crypto++ library ; see pycryptopp.publickey.rsa ; deprecated 26 | in favor of Ed25519 27 | • Ecdsa from the Crypto++ library ; see pycryptopp.publickey.ecdsa ; 28 | deprecated in favor of Ed25519 29 | • SHA-256 from the Crypto++ library ; see pycryptopp.hash.sha256 ; deprecated 30 | in favor of the Python Standard Library's hashlib module 31 | 32 | LICENCE 33 | ------- 34 | 35 | You may use this package under the GNU General Public License, version 2 or, 36 | at your option, any later version. You may use this package under the 37 | Transitive Grace Period Public Licence, version 1.0 or, at your option, any 38 | later version. You may use this package under the MIT License. You may use 39 | this package under the Simple Permissive Licence. 40 | 41 | (You may choose to use this package under the terms of any of these licences, 42 | at your option.) 43 | 44 | See the file COPYING.GPL for the terms of the GNU General Public License, 45 | version 2. See the file COPYING.TGPPL.rst for the terms of the Transitive 46 | Grace Period Public Licence, version 1.0. See the file COPYING.MIT.txt for 47 | the terms of the MIT License. See the file COPYING.SPL.txt for the terms of 48 | the Simple Permissive Licence. 49 | 50 | BUILDING 51 | -------- 52 | 53 | To build it run "python setup.py build". To test it run "python setup.py 54 | test". To install it into your system run "python setup.py install". To 55 | create a binary package run "python setup.py bdist_egg". 56 | 57 | If "python setup.py test" doesn't print out "PASSED" and exit with exit 58 | code 0 then there is something seriously wrong. Do not use this build of 59 | pycryptopp. Please report the error to the tahoe-dev mailing list ²_. 60 | 61 | To see some simple benchmarks run "python setup.py bench". If the "pyutil" 62 | library is installed then the benchmarks will include mean, best, worst, and 63 | quartiles of wall-clock time, else they will just report the mean wall-clock 64 | time per operation. 65 | 66 | DOCUMENTATION 67 | ------------- 68 | 69 | The documentation is in the docstrings. From a command-line, use "pydoc 70 | pycryptopp", "pydoc pycryptopp.cipher", and so on. From within a Python 71 | interpreter use "help(pycryptopp)", "help(pycryptopp.cipher)", 72 | "help(pycryptopp.cipher.aes)" and so on. 73 | 74 | The documentation for pycryptopp.publickey.ed25519 is in README.ed25519.rst, 75 | adapted from the upstream python-ed25519 library. 76 | 77 | CONTACT 78 | ------- 79 | 80 | Please post to the tahoe-dev mailing list ²_ with comments about this 81 | package. 82 | 83 | BOOK REVIEW 84 | ----------- 85 | 86 | If you are not already acquainted with how to use modern cryptography, read 87 | Ferguson, Schneier, and Kohno “Cryptography Engineering”. It is easy going 88 | and will increase your understanding greatly. 89 | 90 | ACKNOWLEDGEMENTS 91 | ---------------- 92 | 93 | Thanks to Wei Dai, Jeffrey Walton, and the other contributors to 94 | Crypto++, Andrew M. Kuchling for his "pycrypto" library which inspired 95 | this one, Brian Warner for help on Python packaging questions, 96 | python-Ed25519, inspiration, and a million other things besides, Greg 97 | Hazel and Samuel Neves for Windows porting and fixing bugs, Daira 98 | Hopwood for helping maintain pycryptopp, and Daniel J. Bernstein for 99 | Ed25519. 100 | 101 | 102 | Zooko Wilcox 103 | 104 | Berlin, Germany 105 | 106 | 2016-01-03 107 | 108 | 109 | .. _¹: https://github.com/warner/python-ed25519 110 | .. _²: https://tahoe-lafs.org/cgi-bin/mailman/listinfo/tahoe-dev 111 | -------------------------------------------------------------------------------- /src-cryptopp/chacha.h: -------------------------------------------------------------------------------- 1 | // chacha.h - written and placed in the public domain by Jeffrey Walton. 2 | // Copyright assigned to the Crypto++ project. 3 | // Based on Wei Dai's Salsa20 and Bernstein's reference ChaCha 4 | // family implementation at http://cr.yp.to/chacha.html. 5 | 6 | //! \file chacha.h 7 | //! \brief Classes for ChaCha8, ChaCha12 and ChaCha20 stream ciphers 8 | //! \details Crypto++ provides Bernstein and ECRYPT's ChaCha from ChaCha, 9 | //! a variant of Salsa20 (2008.01.28). Bernstein's implementation is _slightly_ different from the TLS working group's 10 | //! implementation for cipher suites TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, 11 | //! TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, and TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256. 12 | //! \since Crypto++ 5.6.4 13 | 14 | #ifndef CRYPTOPP_CHACHA_H 15 | #define CRYPTOPP_CHACHA_H 16 | 17 | #include "strciphr.h" 18 | #include "secblock.h" 19 | 20 | NAMESPACE_BEGIN(CryptoPP) 21 | 22 | //! \class ChaCha_Info 23 | //! \brief ChaCha stream cipher information 24 | //! \since Crypto++ 5.6.4 25 | template 26 | struct ChaCha_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>, public FixedRounds 27 | { 28 | CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() { 29 | return (R==8?"ChaCha8":(R==12?"ChaCha12":(R==20?"ChaCha20":"ChaCha"))); 30 | } 31 | }; 32 | 33 | //! \class ChaCha_Policy 34 | //! \brief ChaCha stream cipher implementation 35 | //! \since Crypto++ 5.6.4 36 | template 37 | class CRYPTOPP_NO_VTABLE ChaCha_Policy : public AdditiveCipherConcretePolicy 38 | { 39 | protected: 40 | CRYPTOPP_CONSTANT(ROUNDS=FixedRounds::ROUNDS) 41 | 42 | void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); 43 | void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); 44 | void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length); 45 | bool CipherIsRandomAccess() const {return false;} // TODO 46 | void SeekToIteration(lword iterationCount); 47 | unsigned int GetAlignment() const; 48 | unsigned int GetOptimalBlockSize() const; 49 | 50 | FixedSizeAlignedSecBlock m_state; 51 | }; 52 | 53 | //! \class ChaCha8 54 | //! \brief ChaCha8 stream cipher 55 | //! \sa ChaCha, a variant of Salsa20 (2008.01.28). 56 | //! \since Crypto++ 5.6.4 57 | struct ChaCha8 : public ChaCha_Info<8>, public SymmetricCipherDocumentation 58 | { 59 | typedef SymmetricCipherFinal, AdditiveCipherTemplate<> >, ChaCha_Info<8> > Encryption; 60 | typedef Encryption Decryption; 61 | }; 62 | 63 | //! \class ChaCha12 64 | //! \brief ChaCha12 stream cipher 65 | //! \details Bernstein and ECRYPT's ChaCha is _slightly_ different from the TLS working group's implementation for 66 | //! cipher suites TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, 67 | //! TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, and TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256. 68 | //! \sa ChaCha, a variant of Salsa20 (2008.01.28). 69 | //! \since Crypto++ 5.6.4 70 | struct ChaCha12 : public ChaCha_Info<12>, public SymmetricCipherDocumentation 71 | { 72 | typedef SymmetricCipherFinal, AdditiveCipherTemplate<> >, ChaCha_Info<12> > Encryption; 73 | typedef Encryption Decryption; 74 | }; 75 | 76 | //! \class ChaCha20 77 | //! \brief ChaCha20 stream cipher 78 | //! \sa ChaCha, a variant of Salsa20 (2008.01.28). 79 | //! \details Bernstein and ECRYPT's ChaCha is _slightly_ different from the TLS working group's implementation for 80 | //! cipher suites TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, 81 | //! TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, and TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256. 82 | //! \since Crypto++ 5.6.4 83 | struct ChaCha20 : public ChaCha_Info<20>, public SymmetricCipherDocumentation 84 | { 85 | typedef SymmetricCipherFinal, AdditiveCipherTemplate<> >, ChaCha_Info<20> > Encryption; 86 | typedef Encryption Decryption; 87 | }; 88 | 89 | NAMESPACE_END 90 | 91 | #endif // CRYPTOPP_CHACHA_H 92 | -------------------------------------------------------------------------------- /src-cryptopp/eprecomp.cpp: -------------------------------------------------------------------------------- 1 | // eprecomp.cpp - written and placed in the public domain by Wei Dai 2 | 3 | #include "pch.h" 4 | 5 | #ifndef CRYPTOPP_IMPORTS 6 | 7 | #include "eprecomp.h" 8 | #include "integer.h" 9 | #include "algebra.h" 10 | #include "asn.h" 11 | 12 | NAMESPACE_BEGIN(CryptoPP) 13 | 14 | template void DL_FixedBasePrecomputationImpl::SetBase(const DL_GroupPrecomputation &group, const Element &i_base) 15 | { 16 | m_base = group.NeedConversions() ? group.ConvertIn(i_base) : i_base; 17 | 18 | if (m_bases.empty() || !(m_base == m_bases[0])) 19 | { 20 | m_bases.resize(1); 21 | m_bases[0] = m_base; 22 | } 23 | 24 | if (group.NeedConversions()) 25 | m_base = i_base; 26 | } 27 | 28 | template void DL_FixedBasePrecomputationImpl::Precompute(const DL_GroupPrecomputation &group, unsigned int maxExpBits, unsigned int storage) 29 | { 30 | CRYPTOPP_ASSERT(m_bases.size() > 0); 31 | CRYPTOPP_ASSERT(storage <= maxExpBits); 32 | 33 | if (storage > 1) 34 | { 35 | m_windowSize = (maxExpBits+storage-1)/storage; 36 | m_exponentBase = Integer::Power2(m_windowSize); 37 | } 38 | 39 | m_bases.resize(storage); 40 | for (unsigned i=1; i void DL_FixedBasePrecomputationImpl::Load(const DL_GroupPrecomputation &group, BufferedTransformation &bt) 45 | { 46 | BERSequenceDecoder seq(bt); 47 | word32 version; 48 | BERDecodeUnsigned(seq, version, INTEGER, 1, 1); 49 | m_exponentBase.BERDecode(seq); 50 | m_windowSize = m_exponentBase.BitCount() - 1; 51 | m_bases.clear(); 52 | while (!seq.EndReached()) 53 | m_bases.push_back(group.BERDecodeElement(seq)); 54 | if (!m_bases.empty() && group.NeedConversions()) 55 | m_base = group.ConvertOut(m_bases[0]); 56 | seq.MessageEnd(); 57 | } 58 | 59 | template void DL_FixedBasePrecomputationImpl::Save(const DL_GroupPrecomputation &group, BufferedTransformation &bt) const 60 | { 61 | DERSequenceEncoder seq(bt); 62 | DEREncodeUnsigned(seq, 1); // version 63 | m_exponentBase.DEREncode(seq); 64 | for (unsigned i=0; i void DL_FixedBasePrecomputationImpl::PrepareCascade(const DL_GroupPrecomputation &i_group, std::vector > &eb, const Integer &exponent) const 70 | { 71 | const AbstractGroup &group = i_group.GetGroup(); 72 | 73 | Integer r, q, e = exponent; 74 | bool fastNegate = group.InversionIsFast() && m_windowSize > 1; 75 | unsigned int i; 76 | 77 | for (i=0; i+1(group.Inverse(m_bases[i]), m_exponentBase - r)); 85 | } 86 | else 87 | eb.push_back(BaseAndExponent(m_bases[i], r)); 88 | } 89 | eb.push_back(BaseAndExponent(m_bases[i], e)); 90 | } 91 | 92 | template T DL_FixedBasePrecomputationImpl::Exponentiate(const DL_GroupPrecomputation &group, const Integer &exponent) const 93 | { 94 | std::vector > eb; // array of segments of the exponent and precalculated bases 95 | eb.reserve(m_bases.size()); 96 | PrepareCascade(group, eb, exponent); 97 | return group.ConvertOut(GeneralCascadeMultiplication(group.GetGroup(), eb.begin(), eb.end())); 98 | } 99 | 100 | template T 101 | DL_FixedBasePrecomputationImpl::CascadeExponentiate(const DL_GroupPrecomputation &group, const Integer &exponent, 102 | const DL_FixedBasePrecomputation &i_pc2, const Integer &exponent2) const 103 | { 104 | std::vector > eb; // array of segments of the exponent and precalculated bases 105 | const DL_FixedBasePrecomputationImpl &pc2 = static_cast &>(i_pc2); 106 | eb.reserve(m_bases.size() + pc2.m_bases.size()); 107 | PrepareCascade(group, eb, exponent); 108 | pc2.PrepareCascade(group, eb, exponent2); 109 | return group.ConvertOut(GeneralCascadeMultiplication(group.GetGroup(), eb.begin(), eb.end())); 110 | } 111 | 112 | NAMESPACE_END 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /src/pycryptopp/test/test_aes.py: -------------------------------------------------------------------------------- 1 | import random, re 2 | 3 | import unittest 4 | 5 | from binascii import a2b_hex, b2a_hex 6 | 7 | global VERBOSE 8 | VERBOSE=False 9 | 10 | from pycryptopp.cipher import aes 11 | 12 | from pkg_resources import resource_string, resource_listdir 13 | 14 | from base64 import b32encode 15 | def ab(x): # debuggery 16 | if len(x) >= 3: 17 | return "%s:%s" % (len(x), b32encode(x[-3:]),) 18 | elif len(x) == 2: 19 | return "%s:%s" % (len(x), b32encode(x[-2:]),) 20 | elif len(x) == 1: 21 | return "%s:%s" % (len(x), b32encode(x[-1:]),) 22 | elif len(x) == 0: 23 | return "%s:%s" % (len(x), "--empty--",) 24 | 25 | def randstr(n): 26 | return ''.join(map(chr, map(random.randrange, [0]*n, [256]*n))) 27 | 28 | class AES256(unittest.TestCase): 29 | enc0 = "dc95c078a2408989ad48a21492842087530f8afbc74536b9a963b4f1c4cb738b" 30 | 31 | def test_encrypt_zeroes(self): 32 | cryptor = aes.AES(key="\x00"*32) 33 | ct = cryptor.process("\x00"*32) 34 | self.failUnlessEqual(self.enc0, b2a_hex(ct)) 35 | 36 | def test_init_type_check(self): 37 | self.failUnlessRaises(TypeError, aes.AES, None) 38 | self.failUnlessRaises(aes.Error, aes.AES, "a"*1) # too short 39 | self.failUnlessRaises(aes.Error, aes.AES, "a"*17) # not one of the valid key sizes for AES (16, 24, 32) 40 | 41 | def test_encrypt_zeroes_in_two_parts(self): 42 | cryptor = aes.AES(key="\x00"*32) 43 | ct1 = cryptor.process("\x00"*15) 44 | ct2 = cryptor.process("\x00"*17) 45 | self.failUnlessEqual(self.enc0, b2a_hex(ct1+ct2)) 46 | 47 | class AES128(unittest.TestCase): 48 | enc0 = "66e94bd4ef8a2c3b884cfa59ca342b2e" 49 | 50 | def test_encrypt_zeroes(self): 51 | cryptor = aes.AES(key="\x00"*16) 52 | ct = cryptor.process("\x00"*16) 53 | self.failUnlessEqual(self.enc0, b2a_hex(ct)) 54 | 55 | def test_init_type_check(self): 56 | self.failUnlessRaises(TypeError, aes.AES, None) 57 | self.failUnlessRaises(aes.Error, aes.AES, "a") # too short 58 | 59 | def test_encrypt_zeroes_in_two_parts(self): 60 | cryptor = aes.AES(key="\x00"*16) 61 | ct1 = cryptor.process("\x00"*8) 62 | ct2 = cryptor.process("\x00"*8) 63 | self.failUnlessEqual(self.enc0, b2a_hex(ct1+ct2)) 64 | 65 | def fake_ecb_using_ctr(k, p): 66 | return aes.AES(key=k, iv=p).process('\x00'*16) 67 | 68 | NIST_KAT_VECTS_RE=re.compile("\nCOUNT = ([0-9]+)\nKEY = ([0-9a-f]+)\nPLAINTEXT = ([0-9a-f]+)\nCIPHERTEXT = ([0-9a-f]+)") 69 | 70 | class AES_from_NIST_KAT(unittest.TestCase): 71 | def test_NIST_KAT(self): 72 | for vectname in resource_listdir('pycryptopp', 'testvectors/KAT_AES'): 73 | self._test_KAT_file(resource_string('pycryptopp', '/'.join(['testvectors/KAT_AES', vectname]))) 74 | 75 | def _test_KAT_file(self, vects_str): 76 | for mo in NIST_KAT_VECTS_RE.finditer(vects_str): 77 | key = a2b_hex(mo.group(2)) 78 | plaintext = a2b_hex(mo.group(3)) 79 | ciphertext = a2b_hex(mo.group(4)) 80 | 81 | computedciphertext = fake_ecb_using_ctr(key, plaintext) 82 | self.failUnlessEqual(computedciphertext, ciphertext, "computedciphertext: %s, ciphertext: %s, key: %s, plaintext: %s" % (b2a_hex(computedciphertext), b2a_hex(ciphertext), b2a_hex(key), b2a_hex(plaintext))) 83 | 84 | class AES_from_Niels_Ferguson(unittest.TestCase): 85 | # http://blogs.msdn.com/si_team/archive/2006/05/19/aes-test-vectors.aspx 86 | def _test_from_Niels_AES(self, keysize, result): 87 | E = fake_ecb_using_ctr 88 | b = 16 89 | k = keysize 90 | S = '\x00' * (k+b) 91 | for i in range(1000): 92 | K = S[-k:] 93 | P = S[-k-b:-k] 94 | S += E(K, E(K, P)) 95 | 96 | self.failUnlessEqual(S[-b:], a2b_hex(result)) 97 | 98 | def test_from_Niels_AES128(self): 99 | return self._test_from_Niels_AES(16, 'bd883f01035e58f42f9d812f2dacbcd8') 100 | 101 | def test_from_Niels_AES256(self): 102 | return self._test_from_Niels_AES(32, 'c84b0f3a2c76dd9871900b07f09bdd3e') 103 | 104 | class PartialIV(unittest.TestCase): 105 | def test_partial(self): 106 | k = "k"*16 107 | for iv_len in range(0, 16)+range(17,70): # all are wrong, 16 is right 108 | self.failUnlessRaises(aes.Error, 109 | aes.AES, k, iv="i"*iv_len) 110 | 111 | if __name__ == "__main__": 112 | unittest.main() 113 | -------------------------------------------------------------------------------- /src-cryptopp/pssr.h: -------------------------------------------------------------------------------- 1 | // pssr.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file pssr.h 4 | //! \brief Classes for probablistic signature schemes 5 | 6 | #ifndef CRYPTOPP_PSSR_H 7 | #define CRYPTOPP_PSSR_H 8 | 9 | #include "cryptlib.h" 10 | #include "pubkey.h" 11 | #include "emsa2.h" 12 | 13 | #ifdef CRYPTOPP_IS_DLL 14 | #include "sha.h" 15 | #endif 16 | 17 | NAMESPACE_BEGIN(CryptoPP) 18 | 19 | //! \brief PSSR Message Encoding Method interface 20 | class CRYPTOPP_DLL PSSR_MEM_Base : public PK_RecoverableSignatureMessageEncodingMethod 21 | { 22 | public: 23 | #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 24 | virtual ~PSSR_MEM_Base() {} 25 | #endif 26 | 27 | private: 28 | virtual bool AllowRecovery() const =0; 29 | virtual size_t SaltLen(size_t hashLen) const =0; 30 | virtual size_t MinPadLen(size_t hashLen) const =0; 31 | virtual const MaskGeneratingFunction & GetMGF() const =0; 32 | 33 | public: 34 | size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const; 35 | size_t MaxRecoverableLength(size_t representativeBitLength, size_t hashIdentifierLength, size_t digestLength) const; 36 | bool IsProbabilistic() const; 37 | bool AllowNonrecoverablePart() const; 38 | bool RecoverablePartFirst() const; 39 | void ComputeMessageRepresentative(RandomNumberGenerator &rng, 40 | const byte *recoverableMessage, size_t recoverableMessageLength, 41 | HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, 42 | byte *representative, size_t representativeBitLength) const; 43 | DecodingResult RecoverMessageFromRepresentative( 44 | HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, 45 | byte *representative, size_t representativeBitLength, 46 | byte *recoverableMessage) const; 47 | }; 48 | 49 | //! \brief PSSR Message Encoding Method with Hash Identifier 50 | //! \tparam USE_HASH_ID flag indicating whether the HashId is used 51 | template class PSSR_MEM_BaseWithHashId; 52 | 53 | //! \brief PSSR Message Encoding Method with Hash Identifier 54 | //! \tparam true flag indicating HashId is used 55 | template<> class PSSR_MEM_BaseWithHashId : public EMSA2HashIdLookup {}; 56 | 57 | //! \brief PSSR Message Encoding Method without Hash Identifier 58 | //! \tparam false flag indicating HashId is not used 59 | template<> class PSSR_MEM_BaseWithHashId : public PSSR_MEM_Base {}; 60 | 61 | //! \brief PSSR Message Encoding Method 62 | //! \tparam ALLOW_RECOVERY flag indicating whether the scheme provides message recovery 63 | //! \tparam MGF mask generation function 64 | //! \tparam SALT_LEN length of the salt 65 | //! \tparam MIN_PAD_LEN minimum length of the pad 66 | //! \tparam USE_HASH_ID flag indicating whether the HashId is used 67 | //! \details If ALLOW_RECOVERY is true, the the signature scheme provides message recovery. If 68 | //! ALLOW_RECOVERY is false, the the signature scheme is appendix, and the message must be 69 | //! provided during verification. 70 | template 71 | class PSSR_MEM : public PSSR_MEM_BaseWithHashId 72 | { 73 | virtual bool AllowRecovery() const {return ALLOW_RECOVERY;} 74 | virtual size_t SaltLen(size_t hashLen) const {return SALT_LEN < 0 ? hashLen : SALT_LEN;} 75 | virtual size_t MinPadLen(size_t hashLen) const {return MIN_PAD_LEN < 0 ? hashLen : MIN_PAD_LEN;} 76 | virtual const MaskGeneratingFunction & GetMGF() const {static MGF mgf; return mgf;} 77 | 78 | public: 79 | static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string(ALLOW_RECOVERY ? "PSSR-" : "PSS-") + MGF::StaticAlgorithmName();} 80 | }; 81 | 82 | //! \brief Probabilistic Signature Scheme with Recovery 83 | //! \details Signature Schemes with Recovery encode the message with the signature. 84 | //! \sa PSSR-MGF1 85 | struct PSSR : public SignatureStandard 86 | { 87 | typedef PSSR_MEM SignatureMessageEncodingMethod; 88 | }; 89 | 90 | //! \brief Probabilistic Signature Scheme with Appendix 91 | //! \details Signature Schemes with Appendix require the message to be provided during verification. 92 | //! \sa PSS-MGF1 93 | struct PSS : public SignatureStandard 94 | { 95 | typedef PSSR_MEM SignatureMessageEncodingMethod; 96 | }; 97 | 98 | NAMESPACE_END 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /src-cryptopp/rng.h: -------------------------------------------------------------------------------- 1 | // rng.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file rng.h 4 | //! \brief Miscellaneous classes for RNGs 5 | //! \details This file contains miscellaneous classes for RNGs, including LC_RNG(), 6 | //! X917RNG() and MaurerRandomnessTest() 7 | //! \sa osrng.h, randpool.h 8 | 9 | #ifndef CRYPTOPP_RNG_H 10 | #define CRYPTOPP_RNG_H 11 | 12 | #include "cryptlib.h" 13 | #include "filters.h" 14 | #include "smartptr.h" 15 | 16 | NAMESPACE_BEGIN(CryptoPP) 17 | 18 | //! \brief Linear Congruential Generator (LCG) 19 | //! \details Originally propsed by William S. England. 20 | //! \warning LC_RNG is suitable for simulations, where uniformaly distrubuted numbers are 21 | //! required quickly. It should not be used for cryptographic purposes. 22 | class LC_RNG : public RandomNumberGenerator 23 | { 24 | public: 25 | //! \brief Construct a Linear Congruential Generator (LCG) 26 | //! \param init_seed the initial value for the generator 27 | LC_RNG(word32 init_seed) 28 | : seed(init_seed) {} 29 | 30 | void GenerateBlock(byte *output, size_t size); 31 | 32 | word32 GetSeed() {return seed;} 33 | 34 | private: 35 | word32 seed; 36 | 37 | static const word32 m; 38 | static const word32 q; 39 | static const word16 a; 40 | static const word16 r; 41 | }; 42 | 43 | //! \class X917RNG 44 | //! \brief ANSI X9.17 RNG 45 | //! \details X917RNG is from ANSI X9.17 Appendix C, and it uses a 64-bit block cipher, like TripleDES. 46 | //! If you use a 128-bit block cipher, like AES, then you are effectively using an ANSI X9.31 generator. 47 | //! \sa AutoSeededX917RNG, DefaultAutoSeededRNG 48 | class CRYPTOPP_DLL X917RNG : public RandomNumberGenerator, public NotCopyable 49 | { 50 | public: 51 | //! \brief Construct a X917RNG 52 | //! \param cipher the block cipher to use for the generator 53 | //! \param seed a byte buffer to use as a seed 54 | //! \param deterministicTimeVector additional entropy 55 | //! \details cipher will be deleted by the destructor. seed must be at least 56 | //! BlockSize() in length. deterministicTimeVector = 0 means obtain time vector 57 | //! from the system. 58 | //! \details When constructing a X917RNG, the generator must be keyed or an access 59 | //! violation will occur because the time vector is encrypted using the block cipher. 60 | //! To key the generator during constructions, perform the following: 61 | //!
 62 | 	//!   SecByteBlock key(AES::DEFAULT_KEYLENGTH), seed(AES::BLOCKSIZE);
 63 | 	//!   OS_GenerateRandomBlock(false, key, key.size());
 64 | 	//!   OS_GenerateRandomBlock(false, seed, seed.size());
 65 | 	//!   X917RNG prng(new AES::Encryption(key, AES::DEFAULT_KEYLENGTH), seed, NULL);
66 | //! \sa AutoSeededX917RNG 67 | X917RNG(BlockTransformation *cipher, const byte *seed, const byte *deterministicTimeVector = 0); 68 | 69 | void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size); 70 | 71 | private: 72 | member_ptr m_cipher; 73 | const unsigned int m_size; // S, blocksize of cipher 74 | SecByteBlock m_datetime; // DT, buffer for enciphered timestamp 75 | SecByteBlock m_randseed, m_lastBlock, m_deterministicTimeVector; 76 | }; 77 | 78 | //! \class MaurerRandomnessTest 79 | //! \brief Maurer's Universal Statistical Test for Random Bit Generators 80 | //! \details This class implements Maurer's Universal Statistical Test for 81 | //! Random Bit Generators. It is intended for measuring the randomness of 82 | //! *PHYSICAL* RNGs. 83 | //! \details For more details see Maurer's paper in Journal of Cryptology, 1992. 84 | class MaurerRandomnessTest : public Bufferless 85 | { 86 | public: 87 | //! \brief Contruct a MaurerRandomnessTest 88 | MaurerRandomnessTest(); 89 | 90 | size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking); 91 | 92 | //! \brief Provides the number of bytes of input is needed by the test 93 | //! \returns how many more bytes of input is needed by the test 94 | // BytesNeeded() returns how many more bytes of input is needed by the test 95 | // GetTestValue() should not be called before BytesNeeded()==0 96 | unsigned int BytesNeeded() const {return n >= (Q+K) ? 0 : Q+K-n;} 97 | 98 | // returns a number between 0.0 and 1.0, describing the quality of the 99 | // random numbers entered 100 | double GetTestValue() const; 101 | 102 | private: 103 | enum {L=8, V=256, Q=2000, K=2000}; 104 | double sum; 105 | unsigned int n; 106 | unsigned int tab[V]; 107 | }; 108 | 109 | NAMESPACE_END 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /src-cryptopp/TestVectors/rsa_pkcs1_1_5.txt: -------------------------------------------------------------------------------- 1 | AlgorithmType: Signature 2 | Name: RSA/PKCS1-1.5(MD2) 3 | KeyFormat: DER 4 | Source: http://www.rsasecurity.com/rsalabs/pkcs/index.html, \ 5 | Some Examples of the PKCS Standards 6 | PrivateKey: \ 7 | 30 82 01 50\ 8 | 02 01 00 #version = 0\ 9 | 30 0d #privateKeyAlgorithmIdentifier\ 10 | 06 09 #algorithm = rsaEncryption\ 11 | 2a 86 48 86 f7 0d 01 01 01\ 12 | 05 00 #parameters = NULL\ 13 | 04 82 01 3a #privateKey = RSAPrivateKey encoding\ 14 | 30 82 01 36\ 15 | 02 01 00 #version = 0\ 16 | 02 40 #modulus = n\ 17 | 0a 66 79 1d c6 98 81 68 de 7a b7 74 19 bb 7f b0\ 18 | c0 01 c6 27 10 27 00 75 14 29 42 e1 9a 8d 8c 51\ 19 | d0 53 b3 e3 78 2a 1d e5 dc 5a f4 eb e9 94 68 17\ 20 | 01 14 a1 df e6 7c dc 9a 9a f5 5d 65 56 20 bb ab\ 21 | 02 03 01 00 01 #publicExponent = e\ 22 | 02 40 #privateExponent = d\ 23 | 01 23 c5 b6 1b a3 6e db 1d 36 79 90 41 99 a8 9e\ 24 | a8 0c 09 b9 12 2e 14 00 c0 9a dc f7 78 46 76 d0\ 25 | 1d 23 35 6a 7d 44 d6 bd 8b d5 0e 94 bf c7 23 fa\ 26 | 87 d8 86 2b 75 17 76 91 c1 1d 75 76 92 df 88 81\ 27 | 02 20 #prime1 = p\ 28 | 33 d4 84 45 c8 59 e5 23 40 de 70 4b cd da 06 5f\ 29 | bb 40 58 d7 40 bd 1d 67 d2 9e 9c 14 6c 11 cf 61\ 30 | 02 20 #prime2 = q\ 31 | 33 5e 84 08 86 6b 0f d3 8d c7 00 2d 3f 97 2c 67\ 32 | 38 9a 65 d5 d8 30 65 66 d5 c4 f2 a5 aa 52 62 8b\ 33 | 02 20 #exponent1 = d mod p-1\ 34 | 04 5e c9 00 71 52 53 25 d3 d4 6d b7 96 95 e9 af\ 35 | ac c4 52 39 64 36 0e 02 b1 19 ba a3 66 31 62 41\ 36 | 02 20 #exponent2 = d mod q-1\ 37 | 15 eb 32 73 60 c7 b6 0d 12 e5 e2 d1 6b dc d9 79\ 38 | 81 d1 7f ba 6b 70 db 13 b2 0b 43 6e 24 ea da 59\ 39 | 02 20 #coefficient = q-1 mod p\ 40 | 2c a6 36 6d 72 78 1d fa 24 d3 4a 9a 24 cb c2 ae\ 41 | 92 7a 99 58 af 42 65 63 ff 63 fb 11 65 8a 46 1d 42 | PublicKey: \ 43 | 30 5b #subjectPublicKeyInfo\ 44 | 30 0d #algorithm\ 45 | 06 09 #algorithm = rsaEncryption\ 46 | 2a 86 48 86 f7 0d 01 01 01\ 47 | 05 00 #parameters = NULL\ 48 | 03 4a #subjectPublicKey = RSAPublicKey encoding\ 49 | 00\ 50 | 30 47\ 51 | 02 40 #modulus = n\ 52 | 0a 66 79 1d c6 98 81 68 de 7a b7 74 19 bb 7f b0\ 53 | c0 01 c6 27 10 27 00 75 14 29 42 e1 9a 8d 8c 51\ 54 | d0 53 b3 e3 78 2a 1d e5 dc 5a f4 eb e9 94 68 17\ 55 | 01 14 a1 df e6 7c dc 9a 9a f5 5d 65 56 20 bb ab\ 56 | 02 03 01 00 01 #publicExponent = e 57 | Test: KeyPairValidAndConsistent 58 | Message: # "Everyone gets Friday off."\ 59 | 45 76 65 72 79 6f 6e 65 20 67 65 74 73 20 46 72 69 64 61 79 20 6f 66 66 2e 60 | Signature: \ 61 | 05fa6a812fc7df8bf4f2542509e03e84\ 62 | 6e11b9c620be2009efb440efbcc66921\ 63 | 6994ac04f341b57d05202d428fb2a27b\ 64 | 5c77dfd9b15bfc3d559353503410c1e1 65 | Test: Verify 66 | Name: RSA/PKCS1-1.5(SHA-1) 67 | Source: generated by Wei Dai using Crypto++ 5.0 68 | Signature: 0610761F95FFD1B8F29DA34212947EC2AA0E358866A722F03CC3C41487ADC604A48FF54F5C6BEDB9FB7BD59F82D6E55D8F3174BA361B2214B2D74E8825E04E81 69 | Test: Verify 70 | Message: 00 71 | Test: NotVerify 72 | 73 | AlgorithmType: Signature 74 | Name: RSA/PKCS1-1.5(SHA-1) 75 | Source: http://islab.oregonstate.edu/emails/pkcs-tng-02/0152 76 | KeyFormat: Component 77 | Modulus: A885B6F851A8079AB8A281DB0297148511EE0D8C07C0D4AE6D6FED461488E0D41E3FF8F281B06A3240B5007A5C2AB4FB6BE8AF88F119DB998368DDDC9710ABED 78 | PublicExponent: 010001 79 | PrivateExponent: 2B259D2CA3DF851EE891F6F4678BDDFD9A131C95D3305C63D2723B4A5B9C960F5EC8BB7DCDDBEBD8B6A38767D64AD451E9383E0891E4EE7506100481F2B49323 80 | Prime1: D7103CD676E39824E2BE50B8E6533FE7CB7484348E283802AD2B8D00C80D19DF 81 | Prime2: C89996DC169CEB3F227958275968804D4BE9FC4012C3219662F1A438C9950BB3 82 | ModPrime1PrivateExponent: 5D8EA4C8AF83A70634D5920C3DB66D908AC3AF57A597FD75BC9BBB856181C185 83 | ModPrime2PrivateExponent: C598E54DAEC8ABC1E907769A6C2BD01653ED0C9960E1EDB7E186FDA922883A99 84 | MultiplicativeInverseOfPrime2ModPrime1: 7C6F27B5B51B78AD80FB36E700990CF307866F2943124CBD93D97C137794C104 85 | Test: KeyPairValidAndConsistent 86 | Source: generated by Wei Dai using Crypto++ 5.0 87 | Message: 74657374 # "test" 88 | Signature: A7E00CE4391F914D82158D9B732759808E25A1C6383FE87A5199157650D4296CF612E9FF809E686A0AF328238306E79965F6D0138138829D9A1A22764306F6CE 89 | Test: Verify 90 | -------------------------------------------------------------------------------- /src-cryptopp/rw.h: -------------------------------------------------------------------------------- 1 | // rw.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file rw.h 4 | //! \brief Classes for Rabin-Williams signature scheme 5 | //! \details The implementation provides Rabin-Williams signature schemes as defined in 6 | //! IEEE P1363. It uses Bernstein's tweaked square roots in place of square roots to 7 | //! speedup calculations. 8 | //! \sa RSA signatures and Rabin–Williams 9 | //! signatures: the state of the art (20080131), Section 6, The tweaks e and f. 10 | 11 | #ifndef CRYPTOPP_RW_H 12 | #define CRYPTOPP_RW_H 13 | 14 | #include "cryptlib.h" 15 | #include "pubkey.h" 16 | #include "integer.h" 17 | 18 | NAMESPACE_BEGIN(CryptoPP) 19 | 20 | //! \class RWFunction 21 | //! \brief Rabin-Williams trapdoor function using the public key 22 | class CRYPTOPP_DLL RWFunction : public TrapdoorFunction, public PublicKey 23 | { 24 | typedef RWFunction ThisClass; 25 | 26 | public: 27 | void Initialize(const Integer &n) 28 | {m_n = n;} 29 | 30 | void BERDecode(BufferedTransformation &bt); 31 | void DEREncode(BufferedTransformation &bt) const; 32 | 33 | void Save(BufferedTransformation &bt) const 34 | {DEREncode(bt);} 35 | void Load(BufferedTransformation &bt) 36 | {BERDecode(bt);} 37 | 38 | Integer ApplyFunction(const Integer &x) const; 39 | Integer PreimageBound() const {return ++(m_n>>1);} 40 | Integer ImageBound() const {return m_n;} 41 | 42 | bool Validate(RandomNumberGenerator &rng, unsigned int level) const; 43 | bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; 44 | void AssignFrom(const NameValuePairs &source); 45 | 46 | const Integer& GetModulus() const {return m_n;} 47 | void SetModulus(const Integer &n) {m_n = n;} 48 | 49 | protected: 50 | Integer m_n; 51 | }; 52 | 53 | //! \class InvertibleRWFunction 54 | //! \brief Rabin-Williams trapdoor function using the private key 55 | //! \since Tweaked roots using e and f since Crypto++ 5.6.4 56 | class CRYPTOPP_DLL InvertibleRWFunction : public RWFunction, public TrapdoorFunctionInverse, public PrivateKey 57 | { 58 | typedef InvertibleRWFunction ThisClass; 59 | 60 | public: 61 | InvertibleRWFunction() : m_precompute(false) {} 62 | 63 | void Initialize(const Integer &n, const Integer &p, const Integer &q, const Integer &u); 64 | // generate a random private key 65 | void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits) 66 | {GenerateRandomWithKeySize(rng, modulusBits);} 67 | 68 | void BERDecode(BufferedTransformation &bt); 69 | void DEREncode(BufferedTransformation &bt) const; 70 | 71 | void Save(BufferedTransformation &bt) const 72 | {DEREncode(bt);} 73 | void Load(BufferedTransformation &bt) 74 | {BERDecode(bt);} 75 | 76 | Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const; 77 | 78 | // GeneratibleCryptoMaterial 79 | bool Validate(RandomNumberGenerator &rng, unsigned int level) const; 80 | bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; 81 | void AssignFrom(const NameValuePairs &source); 82 | /*! parameters: (ModulusSize) */ 83 | void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg); 84 | 85 | const Integer& GetPrime1() const {return m_p;} 86 | const Integer& GetPrime2() const {return m_q;} 87 | const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;} 88 | 89 | void SetPrime1(const Integer &p) {m_p = p;} 90 | void SetPrime2(const Integer &q) {m_q = q;} 91 | void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;} 92 | 93 | virtual bool SupportsPrecomputation() const {return true;} 94 | virtual void Precompute(unsigned int unused = 0) {CRYPTOPP_UNUSED(unused); PrecomputeTweakedRoots();} 95 | virtual void Precompute(unsigned int unused = 0) const {CRYPTOPP_UNUSED(unused); PrecomputeTweakedRoots();} 96 | 97 | virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation); 98 | virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const; 99 | 100 | protected: 101 | void PrecomputeTweakedRoots() const; 102 | 103 | protected: 104 | Integer m_p, m_q, m_u; 105 | 106 | mutable Integer m_pre_2_9p, m_pre_2_3q, m_pre_q_p; 107 | mutable bool m_precompute; 108 | }; 109 | 110 | //! \class RW 111 | //! \brief Rabin-Williams algorithm 112 | struct RW 113 | { 114 | static std::string StaticAlgorithmName() {return "RW";} 115 | typedef RWFunction PublicKey; 116 | typedef InvertibleRWFunction PrivateKey; 117 | }; 118 | 119 | //! \class RWSS 120 | //! \brief Rabin-Williams signature scheme 121 | template 122 | struct RWSS : public TF_SS 123 | { 124 | }; 125 | 126 | NAMESPACE_END 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /src-cryptopp/ccm.h: -------------------------------------------------------------------------------- 1 | // ccm.h - written and placed in the public domain by Wei Dai 2 | 3 | //! \file ccm.h 4 | //! \brief CCM block cipher mode of operation 5 | //! \since Crypto++ 5.6.0 6 | 7 | #ifndef CRYPTOPP_CCM_H 8 | #define CRYPTOPP_CCM_H 9 | 10 | #include "authenc.h" 11 | #include "modes.h" 12 | 13 | NAMESPACE_BEGIN(CryptoPP) 14 | 15 | //! \class CCM_Base 16 | //! \brief CCM block cipher base implementation 17 | //! \details Base implementation of the AuthenticatedSymmetricCipher interface 18 | //! \since Crypto++ 5.6.0 19 | class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CCM_Base : public AuthenticatedSymmetricCipherBase 20 | { 21 | public: 22 | CCM_Base() 23 | : m_digestSize(0), m_L(0), m_messageLength(0), m_aadLength(0) {} 24 | 25 | // AuthenticatedSymmetricCipher 26 | std::string AlgorithmName() const 27 | {return GetBlockCipher().AlgorithmName() + std::string("/CCM");} 28 | size_t MinKeyLength() const 29 | {return GetBlockCipher().MinKeyLength();} 30 | size_t MaxKeyLength() const 31 | {return GetBlockCipher().MaxKeyLength();} 32 | size_t DefaultKeyLength() const 33 | {return GetBlockCipher().DefaultKeyLength();} 34 | size_t GetValidKeyLength(size_t n) const 35 | {return GetBlockCipher().GetValidKeyLength(n);} 36 | bool IsValidKeyLength(size_t n) const 37 | {return GetBlockCipher().IsValidKeyLength(n);} 38 | unsigned int OptimalDataAlignment() const 39 | {return GetBlockCipher().OptimalDataAlignment();} 40 | IV_Requirement IVRequirement() const 41 | {return UNIQUE_IV;} 42 | unsigned int IVSize() const 43 | {return 8;} 44 | unsigned int MinIVLength() const 45 | {return 7;} 46 | unsigned int MaxIVLength() const 47 | {return 13;} 48 | unsigned int DigestSize() const 49 | {return m_digestSize;} 50 | lword MaxHeaderLength() const 51 | {return W64LIT(0)-1;} 52 | lword MaxMessageLength() const 53 | {return m_L<8 ? (W64LIT(1)<<(8*m_L))-1 : W64LIT(0)-1;} 54 | bool NeedsPrespecifiedDataLengths() const 55 | {return true;} 56 | void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength); 57 | 58 | protected: 59 | // AuthenticatedSymmetricCipherBase 60 | bool AuthenticationIsOnPlaintext() const 61 | {return true;} 62 | unsigned int AuthenticationBlockSize() const 63 | {return GetBlockCipher().BlockSize();} 64 | void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms); 65 | void Resync(const byte *iv, size_t len); 66 | size_t AuthenticateBlocks(const byte *data, size_t len); 67 | void AuthenticateLastHeaderBlock(); 68 | void AuthenticateLastConfidentialBlock(); 69 | void AuthenticateLastFooterBlock(byte *mac, size_t macSize); 70 | SymmetricCipher & AccessSymmetricCipher() {return m_ctr;} 71 | 72 | virtual BlockCipher & AccessBlockCipher() =0; 73 | virtual int DefaultDigestSize() const =0; 74 | 75 | const BlockCipher & GetBlockCipher() const {return const_cast(this)->AccessBlockCipher();}; 76 | byte *CBC_Buffer() {return m_buffer+REQUIRED_BLOCKSIZE;} 77 | 78 | enum {REQUIRED_BLOCKSIZE = 16}; 79 | int m_digestSize, m_L; 80 | word64 m_messageLength, m_aadLength; 81 | CTR_Mode_ExternalCipher::Encryption m_ctr; 82 | }; 83 | 84 | //! \class CCM_Final 85 | //! \brief CCM block cipher final implementation 86 | //! \tparam T_BlockCipher block cipher 87 | //! \tparam T_DefaultDigestSize default digest size, in bytes 88 | //! \tparam T_IsEncryption direction in which to operate the cipher 89 | //! \since Crypto++ 5.6.0 90 | template 91 | class CCM_Final : public CCM_Base 92 | { 93 | public: 94 | static std::string StaticAlgorithmName() 95 | {return T_BlockCipher::StaticAlgorithmName() + std::string("/CCM");} 96 | bool IsForwardTransformation() const 97 | {return T_IsEncryption;} 98 | 99 | private: 100 | BlockCipher & AccessBlockCipher() {return m_cipher;} 101 | int DefaultDigestSize() const {return T_DefaultDigestSize;} 102 | typename T_BlockCipher::Encryption m_cipher; 103 | }; 104 | 105 | //! \class CCM 106 | //! \brief CCM block cipher mode of operation 107 | //! \tparam T_BlockCipher block cipher 108 | //! \tparam T_DefaultDigestSize default digest size, in bytes 109 | //! \details \p CCM provides the \p Encryption and \p Decryption typedef. See GCM_Base 110 | //! and GCM_Final for the AuthenticatedSymmetricCipher implementation. 111 | //! \sa CCM at the Crypto Lounge 112 | //! \since Crypto++ 5.6.0 113 | template 114 | struct CCM : public AuthenticatedSymmetricCipherDocumentation 115 | { 116 | typedef CCM_Final Encryption; 117 | typedef CCM_Final Decryption; 118 | }; 119 | 120 | NAMESPACE_END 121 | 122 | #endif 123 | --------------------------------------------------------------------------------