charm-crypto-framework 0.61.1__cp313-cp313-macosx_10_13_universal2.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- charm/__init__.py +5 -0
- charm/adapters/__init__.py +0 -0
- charm/adapters/abenc_adapt_hybrid.py +90 -0
- charm/adapters/dabenc_adapt_hybrid.py +145 -0
- charm/adapters/ibenc_adapt_hybrid.py +72 -0
- charm/adapters/ibenc_adapt_identityhash.py +80 -0
- charm/adapters/kpabenc_adapt_hybrid.py +91 -0
- charm/adapters/pkenc_adapt_bchk05.py +121 -0
- charm/adapters/pkenc_adapt_chk04.py +91 -0
- charm/adapters/pkenc_adapt_hybrid.py +98 -0
- charm/adapters/pksig_adapt_naor01.py +89 -0
- charm/config.py +7 -0
- charm/core/__init__.py +0 -0
- charm/core/benchmark/benchmark_util.c +353 -0
- charm/core/benchmark/benchmark_util.h +61 -0
- charm/core/benchmark/benchmarkmodule.c +476 -0
- charm/core/benchmark/benchmarkmodule.h +162 -0
- charm/core/benchmark.cpython-313-darwin.so +0 -0
- charm/core/crypto/AES/AES.c +1464 -0
- charm/core/crypto/AES.cpython-313-darwin.so +0 -0
- charm/core/crypto/DES/DES.c +113 -0
- charm/core/crypto/DES.cpython-313-darwin.so +0 -0
- charm/core/crypto/DES3/DES3.c +26 -0
- charm/core/crypto/DES3.cpython-313-darwin.so +0 -0
- charm/core/crypto/__init__.py +0 -0
- charm/core/crypto/cryptobase/XOR.c +80 -0
- charm/core/crypto/cryptobase/_counter.c +496 -0
- charm/core/crypto/cryptobase/_counter.h +54 -0
- charm/core/crypto/cryptobase/block_template.c +900 -0
- charm/core/crypto/cryptobase/block_template.h +69 -0
- charm/core/crypto/cryptobase/cryptobasemodule.c +220 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt.h +90 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_argchk.h +44 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_cfg.h +186 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_cipher.h +941 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_custom.h +556 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_des.c +1912 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_hash.h +407 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_mac.h +496 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_macros.h +435 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_math.h +534 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_misc.h +103 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_pk.h +653 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_pkcs.h +90 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_prng.h +199 -0
- charm/core/crypto/cryptobase/stream_template.c +271 -0
- charm/core/crypto/cryptobase/strxor.c +229 -0
- charm/core/crypto/cryptobase.cpython-313-darwin.so +0 -0
- charm/core/engine/__init__.py +5 -0
- charm/core/engine/protocol.py +293 -0
- charm/core/engine/util.py +174 -0
- charm/core/math/__init__.py +0 -0
- charm/core/math/elliptic_curve/ecmodule.c +1986 -0
- charm/core/math/elliptic_curve/ecmodule.h +230 -0
- charm/core/math/elliptic_curve.cpython-313-darwin.so +0 -0
- charm/core/math/elliptic_curve.pyi +63 -0
- charm/core/math/integer/integermodule.c +2539 -0
- charm/core/math/integer/integermodule.h +145 -0
- charm/core/math/integer.cpython-313-darwin.so +0 -0
- charm/core/math/integer.pyi +76 -0
- charm/core/math/pairing/miracl/miracl_config.h +37 -0
- charm/core/math/pairing/miracl/miracl_interface.h +118 -0
- charm/core/math/pairing/miracl/miracl_interface2.h +126 -0
- charm/core/math/pairing/miracl/pairingmodule2.c +2094 -0
- charm/core/math/pairing/miracl/pairingmodule2.h +307 -0
- charm/core/math/pairing/pairingmodule.c +2230 -0
- charm/core/math/pairing/pairingmodule.h +241 -0
- charm/core/math/pairing/relic/pairingmodule3.c +1853 -0
- charm/core/math/pairing/relic/pairingmodule3.h +233 -0
- charm/core/math/pairing/relic/relic_interface.c +1337 -0
- charm/core/math/pairing/relic/relic_interface.h +217 -0
- charm/core/math/pairing/relic/test_relic.c +171 -0
- charm/core/math/pairing.cpython-313-darwin.so +0 -0
- charm/core/math/pairing.pyi +69 -0
- charm/core/utilities/base64.c +248 -0
- charm/core/utilities/base64.h +15 -0
- charm/schemes/__init__.py +0 -0
- charm/schemes/abenc/__init__.py +0 -0
- charm/schemes/abenc/abenc_accountability_jyjxgd20.py +647 -0
- charm/schemes/abenc/abenc_bsw07.py +146 -0
- charm/schemes/abenc/abenc_ca_cpabe_ar17.py +684 -0
- charm/schemes/abenc/abenc_dacmacs_yj14.py +298 -0
- charm/schemes/abenc/abenc_lsw08.py +159 -0
- charm/schemes/abenc/abenc_maabe_rw15.py +236 -0
- charm/schemes/abenc/abenc_maabe_yj14.py +297 -0
- charm/schemes/abenc/abenc_tbpre_lww14.py +309 -0
- charm/schemes/abenc/abenc_unmcpabe_yahk14.py +223 -0
- charm/schemes/abenc/abenc_waters09.py +144 -0
- charm/schemes/abenc/abenc_yct14.py +208 -0
- charm/schemes/abenc/abenc_yllc15.py +178 -0
- charm/schemes/abenc/ac17.py +248 -0
- charm/schemes/abenc/bsw07.py +141 -0
- charm/schemes/abenc/cgw15.py +277 -0
- charm/schemes/abenc/dabe_aw11.py +204 -0
- charm/schemes/abenc/dfa_fe12.py +144 -0
- charm/schemes/abenc/pk_hve08.py +179 -0
- charm/schemes/abenc/waters11.py +143 -0
- charm/schemes/aggrsign_MuSig.py +150 -0
- charm/schemes/aggrsign_bls.py +267 -0
- charm/schemes/blindsig_ps16.py +654 -0
- charm/schemes/chamhash_adm05.py +113 -0
- charm/schemes/chamhash_rsa_hw09.py +100 -0
- charm/schemes/commit/__init__.py +0 -0
- charm/schemes/commit/commit_gs08.py +77 -0
- charm/schemes/commit/commit_pedersen92.py +53 -0
- charm/schemes/encap_bchk05.py +62 -0
- charm/schemes/grpsig/__init__.py +0 -0
- charm/schemes/grpsig/groupsig_bgls04.py +114 -0
- charm/schemes/grpsig/groupsig_bgls04_var.py +115 -0
- charm/schemes/hibenc/__init__.py +0 -0
- charm/schemes/hibenc/hibenc_bb04.py +105 -0
- charm/schemes/hibenc/hibenc_lew11.py +193 -0
- charm/schemes/ibenc/__init__.py +0 -0
- charm/schemes/ibenc/clpkc_rp03.py +119 -0
- charm/schemes/ibenc/ibenc_CW13_z.py +168 -0
- charm/schemes/ibenc/ibenc_bb03.py +94 -0
- charm/schemes/ibenc/ibenc_bf01.py +121 -0
- charm/schemes/ibenc/ibenc_ckrs09.py +120 -0
- charm/schemes/ibenc/ibenc_cllww12_z.py +172 -0
- charm/schemes/ibenc/ibenc_lsw08.py +120 -0
- charm/schemes/ibenc/ibenc_sw05.py +238 -0
- charm/schemes/ibenc/ibenc_waters05.py +144 -0
- charm/schemes/ibenc/ibenc_waters05_z.py +164 -0
- charm/schemes/ibenc/ibenc_waters09.py +107 -0
- charm/schemes/ibenc/ibenc_waters09_z.py +147 -0
- charm/schemes/joye_scheme.py +106 -0
- charm/schemes/lem_scheme.py +207 -0
- charm/schemes/pk_fre_ccv11.py +107 -0
- charm/schemes/pk_vrf.py +127 -0
- charm/schemes/pkenc/__init__.py +0 -0
- charm/schemes/pkenc/pkenc_cs98.py +108 -0
- charm/schemes/pkenc/pkenc_elgamal85.py +122 -0
- charm/schemes/pkenc/pkenc_gm82.py +98 -0
- charm/schemes/pkenc/pkenc_paillier99.py +118 -0
- charm/schemes/pkenc/pkenc_rabin.py +254 -0
- charm/schemes/pkenc/pkenc_rsa.py +186 -0
- charm/schemes/pksig/__init__.py +0 -0
- charm/schemes/pksig/pksig_CW13_z.py +135 -0
- charm/schemes/pksig/pksig_bls04.py +87 -0
- charm/schemes/pksig/pksig_boyen.py +156 -0
- charm/schemes/pksig/pksig_chch.py +97 -0
- charm/schemes/pksig/pksig_chp.py +70 -0
- charm/schemes/pksig/pksig_cl03.py +150 -0
- charm/schemes/pksig/pksig_cl04.py +87 -0
- charm/schemes/pksig/pksig_cllww12_z.py +142 -0
- charm/schemes/pksig/pksig_cyh.py +132 -0
- charm/schemes/pksig/pksig_dsa.py +76 -0
- charm/schemes/pksig/pksig_ecdsa.py +71 -0
- charm/schemes/pksig/pksig_hess.py +104 -0
- charm/schemes/pksig/pksig_hw.py +110 -0
- charm/schemes/pksig/pksig_lamport.py +63 -0
- charm/schemes/pksig/pksig_ps01.py +135 -0
- charm/schemes/pksig/pksig_ps02.py +124 -0
- charm/schemes/pksig/pksig_ps03.py +119 -0
- charm/schemes/pksig/pksig_rsa_hw09.py +206 -0
- charm/schemes/pksig/pksig_schnorr91.py +77 -0
- charm/schemes/pksig/pksig_waters.py +115 -0
- charm/schemes/pksig/pksig_waters05.py +121 -0
- charm/schemes/pksig/pksig_waters09.py +121 -0
- charm/schemes/pre_mg07.py +150 -0
- charm/schemes/prenc/pre_afgh06.py +126 -0
- charm/schemes/prenc/pre_bbs98.py +123 -0
- charm/schemes/prenc/pre_nal16.py +216 -0
- charm/schemes/protocol_a01.py +272 -0
- charm/schemes/protocol_ao00.py +215 -0
- charm/schemes/protocol_cns07.py +274 -0
- charm/schemes/protocol_schnorr91.py +125 -0
- charm/schemes/sigma1.py +64 -0
- charm/schemes/sigma2.py +129 -0
- charm/schemes/sigma3.py +126 -0
- charm/schemes/threshold/__init__.py +59 -0
- charm/schemes/threshold/dkls23_dkg.py +556 -0
- charm/schemes/threshold/dkls23_presign.py +1089 -0
- charm/schemes/threshold/dkls23_sign.py +761 -0
- charm/schemes/threshold/xrpl_wallet.py +967 -0
- charm/test/__init__.py +0 -0
- charm/test/adapters/__init__.py +0 -0
- charm/test/adapters/abenc_adapt_hybrid_test.py +29 -0
- charm/test/adapters/dabenc_adapt_hybrid_test.py +56 -0
- charm/test/adapters/ibenc_adapt_hybrid_test.py +36 -0
- charm/test/adapters/ibenc_adapt_identityhash_test.py +32 -0
- charm/test/adapters/kpabenc_adapt_hybrid_test.py +30 -0
- charm/test/benchmark/abenc_yllc15_bench.py +92 -0
- charm/test/benchmark/benchmark_test.py +148 -0
- charm/test/benchmark_threshold.py +260 -0
- charm/test/conftest.py +38 -0
- charm/test/fuzz/__init__.py +1 -0
- charm/test/fuzz/conftest.py +5 -0
- charm/test/fuzz/fuzz_policy_parser.py +76 -0
- charm/test/fuzz/fuzz_serialization.py +83 -0
- charm/test/schemes/__init__.py +0 -0
- charm/test/schemes/abenc/__init__.py +0 -0
- charm/test/schemes/abenc/abenc_bsw07_test.py +39 -0
- charm/test/schemes/abenc/abenc_dacmacs_yj14_test.py +16 -0
- charm/test/schemes/abenc/abenc_lsw08_test.py +33 -0
- charm/test/schemes/abenc/abenc_maabe_yj14_test.py +16 -0
- charm/test/schemes/abenc/abenc_tbpre_lww14_test.py +16 -0
- charm/test/schemes/abenc/abenc_waters09_test.py +38 -0
- charm/test/schemes/abenc/abenc_yllc15_test.py +74 -0
- charm/test/schemes/chamhash_adm05_test.py +31 -0
- charm/test/schemes/chamhash_rsa_hw09_test.py +29 -0
- charm/test/schemes/commit/__init__.py +0 -0
- charm/test/schemes/commit/commit_gs08_test.py +24 -0
- charm/test/schemes/commit/commit_pedersen92_test.py +26 -0
- charm/test/schemes/dabe_aw11_test.py +45 -0
- charm/test/schemes/encap_bchk05_test.py +21 -0
- charm/test/schemes/grpsig/__init__.py +0 -0
- charm/test/schemes/grpsig/groupsig_bgls04_test.py +35 -0
- charm/test/schemes/grpsig/groupsig_bgls04_var_test.py +39 -0
- charm/test/schemes/hibenc/__init__.py +0 -0
- charm/test/schemes/hibenc/hibenc_bb04_test.py +28 -0
- charm/test/schemes/ibenc/__init__.py +0 -0
- charm/test/schemes/ibenc/ibenc_bb03_test.py +26 -0
- charm/test/schemes/ibenc/ibenc_bf01_test.py +24 -0
- charm/test/schemes/ibenc/ibenc_ckrs09_test.py +25 -0
- charm/test/schemes/ibenc/ibenc_lsw08_test.py +31 -0
- charm/test/schemes/ibenc/ibenc_sw05_test.py +32 -0
- charm/test/schemes/ibenc/ibenc_waters05_test.py +31 -0
- charm/test/schemes/ibenc/ibenc_waters09_test.py +27 -0
- charm/test/schemes/pk_vrf_test.py +29 -0
- charm/test/schemes/pkenc/__init__.py +0 -0
- charm/test/schemes/pkenc_test.py +255 -0
- charm/test/schemes/pksig/__init__.py +0 -0
- charm/test/schemes/pksig_test.py +376 -0
- charm/test/schemes/rsa_alg_test.py +340 -0
- charm/test/schemes/threshold_test.py +1792 -0
- charm/test/serialize/__init__.py +0 -0
- charm/test/serialize/serialize_test.py +40 -0
- charm/test/toolbox/__init__.py +0 -0
- charm/test/toolbox/conversion_test.py +30 -0
- charm/test/toolbox/ecgroup_test.py +53 -0
- charm/test/toolbox/integer_arithmetic_test.py +441 -0
- charm/test/toolbox/paddingschemes_test.py +238 -0
- charm/test/toolbox/policy_parser_stress_test.py +969 -0
- charm/test/toolbox/secretshare_test.py +28 -0
- charm/test/toolbox/symcrypto_test.py +108 -0
- charm/test/toolbox/test_policy_expression.py +16 -0
- charm/test/vectors/__init__.py +1 -0
- charm/test/vectors/test_bls_vectors.py +289 -0
- charm/test/vectors/test_pedersen_vectors.py +315 -0
- charm/test/vectors/test_schnorr_vectors.py +368 -0
- charm/test/zkp_compiler/__init__.py +9 -0
- charm/test/zkp_compiler/benchmark_zkp.py +258 -0
- charm/test/zkp_compiler/test_and_proof.py +240 -0
- charm/test/zkp_compiler/test_batch_verify.py +248 -0
- charm/test/zkp_compiler/test_dleq_proof.py +264 -0
- charm/test/zkp_compiler/test_or_proof.py +231 -0
- charm/test/zkp_compiler/test_proof_serialization.py +121 -0
- charm/test/zkp_compiler/test_range_proof.py +241 -0
- charm/test/zkp_compiler/test_representation_proof.py +325 -0
- charm/test/zkp_compiler/test_schnorr_proof.py +221 -0
- charm/test/zkp_compiler/test_thread_safety.py +169 -0
- charm/test/zkp_compiler/test_zkp_parser.py +139 -0
- charm/toolbox/ABEnc.py +26 -0
- charm/toolbox/ABEncMultiAuth.py +66 -0
- charm/toolbox/ABEnumeric.py +800 -0
- charm/toolbox/Commit.py +24 -0
- charm/toolbox/DFA.py +89 -0
- charm/toolbox/FSA.py +1254 -0
- charm/toolbox/Hash.py +39 -0
- charm/toolbox/IBEnc.py +62 -0
- charm/toolbox/IBSig.py +64 -0
- charm/toolbox/PKEnc.py +66 -0
- charm/toolbox/PKSig.py +56 -0
- charm/toolbox/PREnc.py +32 -0
- charm/toolbox/ZKProof.py +289 -0
- charm/toolbox/__init__.py +0 -0
- charm/toolbox/bitstring.py +49 -0
- charm/toolbox/broadcast.py +220 -0
- charm/toolbox/conversion.py +100 -0
- charm/toolbox/eccurve.py +149 -0
- charm/toolbox/ecgroup.py +143 -0
- charm/toolbox/enum.py +60 -0
- charm/toolbox/hash_module.py +91 -0
- charm/toolbox/integergroup.py +323 -0
- charm/toolbox/iterate.py +22 -0
- charm/toolbox/matrixops.py +76 -0
- charm/toolbox/mpc_utils.py +296 -0
- charm/toolbox/msp.py +175 -0
- charm/toolbox/mta.py +985 -0
- charm/toolbox/node.py +120 -0
- charm/toolbox/ot/__init__.py +22 -0
- charm/toolbox/ot/base_ot.py +374 -0
- charm/toolbox/ot/dpf.py +642 -0
- charm/toolbox/ot/mpfss.py +228 -0
- charm/toolbox/ot/ot_extension.py +589 -0
- charm/toolbox/ot/silent_ot.py +378 -0
- charm/toolbox/paddingschemes.py +423 -0
- charm/toolbox/paddingschemes_test.py +238 -0
- charm/toolbox/pairingcurves.py +85 -0
- charm/toolbox/pairinggroup.py +186 -0
- charm/toolbox/policy_expression_spec.py +70 -0
- charm/toolbox/policytree.py +189 -0
- charm/toolbox/reCompiler.py +346 -0
- charm/toolbox/redundancyschemes.py +65 -0
- charm/toolbox/schemebase.py +188 -0
- charm/toolbox/secretshare.py +104 -0
- charm/toolbox/secretutil.py +174 -0
- charm/toolbox/securerandom.py +73 -0
- charm/toolbox/sigmaprotocol.py +46 -0
- charm/toolbox/specialprimes.py +45 -0
- charm/toolbox/symcrypto.py +279 -0
- charm/toolbox/threshold_sharing.py +553 -0
- charm/toolbox/xmlserialize.py +94 -0
- charm/toolbox/zknode.py +105 -0
- charm/zkp_compiler/__init__.py +89 -0
- charm/zkp_compiler/and_proof.py +460 -0
- charm/zkp_compiler/batch_verify.py +324 -0
- charm/zkp_compiler/dleq_proof.py +423 -0
- charm/zkp_compiler/or_proof.py +305 -0
- charm/zkp_compiler/range_proof.py +417 -0
- charm/zkp_compiler/representation_proof.py +466 -0
- charm/zkp_compiler/schnorr_proof.py +273 -0
- charm/zkp_compiler/thread_safe.py +150 -0
- charm/zkp_compiler/zk_demo.py +489 -0
- charm/zkp_compiler/zkp_factory.py +330 -0
- charm/zkp_compiler/zkp_generator.py +370 -0
- charm/zkp_compiler/zkparser.py +269 -0
- charm_crypto_framework-0.61.1.dist-info/METADATA +337 -0
- charm_crypto_framework-0.61.1.dist-info/RECORD +323 -0
- charm_crypto_framework-0.61.1.dist-info/WHEEL +5 -0
- charm_crypto_framework-0.61.1.dist-info/licenses/LICENSE.txt +165 -0
- charm_crypto_framework-0.61.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
#ifndef BLOCK_TEMPLATE_H
|
|
4
|
+
#define BLOCK_TEMPLATE_H
|
|
5
|
+
|
|
6
|
+
#ifdef HAVE_CONFIG_H
|
|
7
|
+
#include "config.h"
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
#ifdef _HAVE_STDC_HEADERS
|
|
11
|
+
#include <string.h>
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
#ifndef PY_SSIZE_T_CLEAN
|
|
15
|
+
#define PY_SSIZE_T_CLEAN
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
#include <Python.h>
|
|
19
|
+
#include <structmember.h>
|
|
20
|
+
#include "modsupport.h"
|
|
21
|
+
#include "_counter.h"
|
|
22
|
+
|
|
23
|
+
/* Python 3.14+ compatibility - PyUnicode_GET_SIZE was removed */
|
|
24
|
+
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 14
|
|
25
|
+
#define PyUnicode_GET_SIZE(o) PyUnicode_GetLength(o)
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
#define TRUE 1
|
|
29
|
+
#define FALSE 0
|
|
30
|
+
|
|
31
|
+
/* Cipher operation modes */
|
|
32
|
+
#define MODE_ECB 1
|
|
33
|
+
#define MODE_CBC 2
|
|
34
|
+
#define MODE_CFB 3
|
|
35
|
+
#define MODE_PGP 4
|
|
36
|
+
#define MODE_OFB 5
|
|
37
|
+
#define MODE_CTR 6
|
|
38
|
+
|
|
39
|
+
#define _STR(x) #x
|
|
40
|
+
#define _XSTR(x) _STR(x)
|
|
41
|
+
#define _PASTE(x,y) x##y
|
|
42
|
+
#define _PASTE2(x,y) _PASTE(x,y)
|
|
43
|
+
#define _MODULE_STRING _XSTR(MODULE_NAME)
|
|
44
|
+
|
|
45
|
+
#if PY_MAJOR_VERSION >= 3
|
|
46
|
+
#define _MODULE_NAME _PASTE2(PyInit_, MODULE_NAME)
|
|
47
|
+
#else
|
|
48
|
+
#define _MODULE_NAME _PASTE2(init,MODULE_NAME)
|
|
49
|
+
#endif
|
|
50
|
+
|
|
51
|
+
typedef struct
|
|
52
|
+
{
|
|
53
|
+
PyObject_HEAD
|
|
54
|
+
Py_ssize_t mode, count, segment_size, prf_mode;
|
|
55
|
+
unsigned char IV[BLOCK_SIZE], oldCipher[BLOCK_SIZE];
|
|
56
|
+
PyObject *counter;
|
|
57
|
+
int counter_shortcut;
|
|
58
|
+
block_state st;
|
|
59
|
+
} ALGobject;
|
|
60
|
+
|
|
61
|
+
// staticforward PyTypeObject ALGtype;
|
|
62
|
+
static PyTypeObject ALGtype;
|
|
63
|
+
|
|
64
|
+
#define is_ALGobject(v) ((v)->ob_type == &ALGtype)
|
|
65
|
+
|
|
66
|
+
PyMemberDef ALGmembers[];
|
|
67
|
+
PyMethodDef ALGmethods[];
|
|
68
|
+
|
|
69
|
+
#endif
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
#ifndef PY_SSIZE_T_CLEAN
|
|
2
|
+
#define PY_SSIZE_T_CLEAN
|
|
3
|
+
#endif
|
|
4
|
+
#include <Python.h>
|
|
5
|
+
#include <structmember.h>
|
|
6
|
+
|
|
7
|
+
static PyTypeObject BaseType;
|
|
8
|
+
static PyObject *BaseError;
|
|
9
|
+
#define PyBase_Check(obj) PyObject_TypeCheck(obj, &BaseType)
|
|
10
|
+
#define TRUE 1
|
|
11
|
+
#define FALSE 0
|
|
12
|
+
#define PKG "charm.core.crypto."
|
|
13
|
+
enum MOP {NONE = 0, MODE_ECB, MODE_CBC, MODE_CFB, MODE_PGP, MODE_OFB, MODE_CTR};
|
|
14
|
+
enum ALG {AES, DES, DES3};
|
|
15
|
+
|
|
16
|
+
typedef struct {
|
|
17
|
+
PyObject_HEAD
|
|
18
|
+
int initialized;
|
|
19
|
+
} Base;
|
|
20
|
+
|
|
21
|
+
// define functions here
|
|
22
|
+
/* Description: an example of inputs cryptobase.selectPRF(AES, ('This is a key 456', MODE_ECB))
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
static PyObject *selectPRF(Base *self, PyObject *args) {
|
|
26
|
+
PyObject *tuple, *module, *module_dict, *new_func, *prf;
|
|
27
|
+
int alg;
|
|
28
|
+
char *ALG = NULL;
|
|
29
|
+
|
|
30
|
+
if(!PyArg_ParseTuple(args, "iO", &alg, &tuple)) {
|
|
31
|
+
PyErr_SetString(BaseError, "1st argument is algorithm and 2nd is tuple of arguments.");
|
|
32
|
+
return NULL;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
switch(alg) {
|
|
36
|
+
case AES: ALG = PKG"AES"; break;
|
|
37
|
+
case DES: ALG = PKG"DES"; break;
|
|
38
|
+
case DES3: ALG = PKG"DES3"; break;
|
|
39
|
+
default: ALG = PKG"AES"; break; /* default */
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module = PyImport_ImportModule(ALG);
|
|
43
|
+
if (!module) {
|
|
44
|
+
Py_XDECREF (module);
|
|
45
|
+
return NULL;
|
|
46
|
+
}
|
|
47
|
+
// printf("module ptr => %p\n", module);
|
|
48
|
+
module_dict = PyModule_GetDict (module);
|
|
49
|
+
Py_DECREF (module);
|
|
50
|
+
new_func = PyDict_GetItemString(module_dict, "new");
|
|
51
|
+
// printf("new_func ptr => %p\n", new_func);
|
|
52
|
+
if (!PyCallable_Check(new_func))
|
|
53
|
+
{
|
|
54
|
+
PyErr_SetString(BaseError, "ALG.new is not callable.");
|
|
55
|
+
return NULL;
|
|
56
|
+
}
|
|
57
|
+
prf = PyObject_CallObject(new_func, tuple);
|
|
58
|
+
PyObject *ret = PyObject_CallMethod(prf, "setMode", "i", TRUE);
|
|
59
|
+
if(ret == NULL) {
|
|
60
|
+
// return error
|
|
61
|
+
PyErr_SetString(BaseError, "Could not call setMode on ALG object.");
|
|
62
|
+
Py_DECREF(prf);
|
|
63
|
+
return NULL;
|
|
64
|
+
}
|
|
65
|
+
Py_DECREF(ret);
|
|
66
|
+
return prf;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static PyObject *selectPRP(Base *self, PyObject *args) {
|
|
70
|
+
PyObject *tuple, *module, *module_dict, *new_func, *prp;
|
|
71
|
+
int alg;
|
|
72
|
+
char *ALG = NULL;
|
|
73
|
+
|
|
74
|
+
if(!PyArg_ParseTuple(args, "iO", &alg, &tuple)) {
|
|
75
|
+
PyErr_SetString(BaseError, "1st argument is algorithm and 2nd is tuple of arguments.");
|
|
76
|
+
return NULL;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
switch(alg) {
|
|
80
|
+
case AES: ALG = PKG"AES"; break;
|
|
81
|
+
case DES: ALG = PKG"DES"; break;
|
|
82
|
+
case DES3: ALG = PKG"DES3"; break;
|
|
83
|
+
default: ALG = PKG"AES"; break; /* default */
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module = PyImport_ImportModule(ALG);
|
|
87
|
+
if (!module) {
|
|
88
|
+
Py_XDECREF (module);
|
|
89
|
+
return NULL;
|
|
90
|
+
}
|
|
91
|
+
module_dict = PyModule_GetDict (module);
|
|
92
|
+
Py_DECREF (module);
|
|
93
|
+
new_func = PyDict_GetItemString(module_dict, "new");
|
|
94
|
+
|
|
95
|
+
if (!PyCallable_Check(new_func))
|
|
96
|
+
{
|
|
97
|
+
PyErr_SetString(BaseError, "ALG.new is not callable.");
|
|
98
|
+
return NULL;
|
|
99
|
+
}
|
|
100
|
+
prp = PyObject_CallObject(new_func, tuple);
|
|
101
|
+
return prp;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//static PyObject *selectHash(Base *self, PyObject *args) {
|
|
105
|
+
// return NULL;
|
|
106
|
+
//}
|
|
107
|
+
|
|
108
|
+
static PyTypeObject BaseType = {
|
|
109
|
+
PyVarObject_HEAD_INIT(NULL, 0)
|
|
110
|
+
"crypto.Base", /*tp_name*/
|
|
111
|
+
sizeof(Base), /*tp_basicsize*/
|
|
112
|
+
0, /*tp_itemsize*/
|
|
113
|
+
0, /*tp_dealloc*/
|
|
114
|
+
0, /*tp_print*/
|
|
115
|
+
0, /*tp_getattr*/
|
|
116
|
+
0, /*tp_setattr*/
|
|
117
|
+
0, /*tp_compare*/
|
|
118
|
+
0, /*tp_repr*/
|
|
119
|
+
0, /*tp_as_number*/
|
|
120
|
+
0, /*tp_as_sequence*/
|
|
121
|
+
0, /*tp_as_mapping*/
|
|
122
|
+
0, /*tp_hash */
|
|
123
|
+
0, // (ternaryfunc) Base_call, /*tp_call*/
|
|
124
|
+
0, // (reprfunc) Base_print, /*tp_str*/
|
|
125
|
+
0, /*tp_getattro*/
|
|
126
|
+
0, /*tp_setattro*/
|
|
127
|
+
0, /*tp_as_buffer*/
|
|
128
|
+
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
|
129
|
+
"Crypto Base modular objects", /* tp_doc */
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
struct module_state {
|
|
133
|
+
PyObject *error;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
#if PY_MAJOR_VERSION >= 3
|
|
137
|
+
#define GETSTATE(m) ((struct module_state *) PyModule_GetState(m))
|
|
138
|
+
#else
|
|
139
|
+
#define GETSTATE(m) (&_state)
|
|
140
|
+
static struct module_state _state;
|
|
141
|
+
#endif
|
|
142
|
+
|
|
143
|
+
static PyMethodDef module_methods[] = {
|
|
144
|
+
{"selectPRF", (PyCFunction)selectPRF, METH_VARARGS, "selects a Pseudo-random Function given specific requirements."},
|
|
145
|
+
{"selectPRP", (PyCFunction)selectPRP, METH_VARARGS, "selects a Pseudo-random Permutation given specific requirements."},
|
|
146
|
+
// may need adapter functions here as well?
|
|
147
|
+
{NULL}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
#if PY_MAJOR_VERSION >= 3
|
|
151
|
+
static int base_traverse(PyObject *m, visitproc visit, void *arg) {
|
|
152
|
+
Py_VISIT(GETSTATE(m)->error);
|
|
153
|
+
return 0;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
static int base_clear(PyObject *m) {
|
|
157
|
+
Py_CLEAR(GETSTATE(m)->error);
|
|
158
|
+
Py_XDECREF(BaseError);
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
static struct PyModuleDef moduledef = {
|
|
163
|
+
PyModuleDef_HEAD_INIT,
|
|
164
|
+
"cryptobase",
|
|
165
|
+
NULL,
|
|
166
|
+
sizeof(struct module_state),
|
|
167
|
+
module_methods,
|
|
168
|
+
NULL,
|
|
169
|
+
base_traverse,
|
|
170
|
+
base_clear,
|
|
171
|
+
NULL
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
#define INITERROR return NULL
|
|
175
|
+
PyMODINIT_FUNC
|
|
176
|
+
PyInit_cryptobase(void) {
|
|
177
|
+
#else
|
|
178
|
+
#define INITERROR return
|
|
179
|
+
void initcryptobase(void) {
|
|
180
|
+
#endif
|
|
181
|
+
PyObject *m;
|
|
182
|
+
if(PyType_Ready(&BaseType) < 0) INITERROR;
|
|
183
|
+
|
|
184
|
+
// initialize module
|
|
185
|
+
#if PY_MAJOR_VERSION >= 3
|
|
186
|
+
m = PyModule_Create(&moduledef);
|
|
187
|
+
#else
|
|
188
|
+
m = Py_InitModule("cryptobase", module_methods);
|
|
189
|
+
#endif
|
|
190
|
+
// add integer type to module
|
|
191
|
+
if(m == NULL) INITERROR;
|
|
192
|
+
Py_INCREF(&BaseType);
|
|
193
|
+
PyModule_AddObject(m, "cryptobase", (PyObject *)&BaseType);
|
|
194
|
+
// algorithms
|
|
195
|
+
PyModule_AddIntConstant(m, "AES", AES);
|
|
196
|
+
PyModule_AddIntConstant(m, "DES", DES);
|
|
197
|
+
PyModule_AddIntConstant(m, "DES3", DES3);
|
|
198
|
+
|
|
199
|
+
// mode of operation
|
|
200
|
+
PyModule_AddIntConstant(m, "MODE_ECB", MODE_ECB);
|
|
201
|
+
PyModule_AddIntConstant(m, "MODE_CBC", MODE_CBC);
|
|
202
|
+
PyModule_AddIntConstant(m, "MODE_CFB", MODE_CFB);
|
|
203
|
+
PyModule_AddIntConstant(m, "MODE_PGP", MODE_PGP);
|
|
204
|
+
PyModule_AddIntConstant(m, "MODE_OFB", MODE_OFB);
|
|
205
|
+
PyModule_AddIntConstant(m, "MODE_CTR", MODE_CTR);
|
|
206
|
+
|
|
207
|
+
// add integer error to module
|
|
208
|
+
struct module_state *st = GETSTATE(m);
|
|
209
|
+
st->error = PyErr_NewException("base.Error", NULL, NULL);
|
|
210
|
+
if(st->error == NULL) {
|
|
211
|
+
Py_DECREF(m);
|
|
212
|
+
INITERROR;
|
|
213
|
+
}
|
|
214
|
+
BaseError = st->error;
|
|
215
|
+
Py_INCREF(BaseError);
|
|
216
|
+
// PyModule_AddObject(m, "base.error", BaseError);
|
|
217
|
+
#if PY_MAJOR_VERSION >= 3
|
|
218
|
+
return m;
|
|
219
|
+
#endif
|
|
220
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#ifndef TOMCRYPT_H_
|
|
2
|
+
#define TOMCRYPT_H_
|
|
3
|
+
#include <assert.h>
|
|
4
|
+
#include <stdio.h>
|
|
5
|
+
#include <string.h>
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
#include <stddef.h>
|
|
8
|
+
#include <time.h>
|
|
9
|
+
#include <ctype.h>
|
|
10
|
+
#include <limits.h>
|
|
11
|
+
|
|
12
|
+
/* use configuration data */
|
|
13
|
+
#include <tomcrypt_custom.h>
|
|
14
|
+
|
|
15
|
+
#ifdef __cplusplus
|
|
16
|
+
extern "C" {
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
/* version */
|
|
20
|
+
#define CRYPT 0x0117
|
|
21
|
+
#define SCRYPT "1.17"
|
|
22
|
+
|
|
23
|
+
/* max size of either a cipher/hash block or symmetric key [largest of the two] */
|
|
24
|
+
#define MAXBLOCKSIZE 128
|
|
25
|
+
|
|
26
|
+
/* descriptor table size */
|
|
27
|
+
#define TAB_SIZE 32
|
|
28
|
+
|
|
29
|
+
/* error codes [will be expanded in future releases] */
|
|
30
|
+
enum {
|
|
31
|
+
CRYPT_OK=0, /* Result OK */
|
|
32
|
+
CRYPT_ERROR, /* Generic Error */
|
|
33
|
+
CRYPT_NOP, /* Not a failure but no operation was performed */
|
|
34
|
+
|
|
35
|
+
CRYPT_INVALID_KEYSIZE, /* Invalid key size given */
|
|
36
|
+
CRYPT_INVALID_ROUNDS, /* Invalid number of rounds */
|
|
37
|
+
CRYPT_FAIL_TESTVECTOR, /* Algorithm failed test vectors */
|
|
38
|
+
|
|
39
|
+
CRYPT_BUFFER_OVERFLOW, /* Not enough space for output */
|
|
40
|
+
CRYPT_INVALID_PACKET, /* Invalid input packet given */
|
|
41
|
+
|
|
42
|
+
CRYPT_INVALID_PRNGSIZE, /* Invalid number of bits for a PRNG */
|
|
43
|
+
CRYPT_ERROR_READPRNG, /* Could not read enough from PRNG */
|
|
44
|
+
|
|
45
|
+
CRYPT_INVALID_CIPHER, /* Invalid cipher specified */
|
|
46
|
+
CRYPT_INVALID_HASH, /* Invalid hash specified */
|
|
47
|
+
CRYPT_INVALID_PRNG, /* Invalid PRNG specified */
|
|
48
|
+
|
|
49
|
+
CRYPT_MEM, /* Out of memory */
|
|
50
|
+
|
|
51
|
+
CRYPT_PK_TYPE_MISMATCH, /* Not equivalent types of PK keys */
|
|
52
|
+
CRYPT_PK_NOT_PRIVATE, /* Requires a private PK key */
|
|
53
|
+
|
|
54
|
+
CRYPT_INVALID_ARG, /* Generic invalid argument */
|
|
55
|
+
CRYPT_FILE_NOTFOUND, /* File Not Found */
|
|
56
|
+
|
|
57
|
+
CRYPT_PK_INVALID_TYPE, /* Invalid type of PK key */
|
|
58
|
+
CRYPT_PK_INVALID_SYSTEM,/* Invalid PK system specified */
|
|
59
|
+
CRYPT_PK_DUP, /* Duplicate key already in key ring */
|
|
60
|
+
CRYPT_PK_NOT_FOUND, /* Key not found in keyring */
|
|
61
|
+
CRYPT_PK_INVALID_SIZE, /* Invalid size input for PK parameters */
|
|
62
|
+
|
|
63
|
+
CRYPT_INVALID_PRIME_SIZE,/* Invalid size of prime requested */
|
|
64
|
+
CRYPT_PK_INVALID_PADDING, /* Invalid padding on input */
|
|
65
|
+
|
|
66
|
+
CRYPT_HASH_OVERFLOW /* Hash applied to too many bits */
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
#include <tomcrypt_cfg.h>
|
|
70
|
+
#include <tomcrypt_macros.h>
|
|
71
|
+
#include <tomcrypt_cipher.h>
|
|
72
|
+
#include <tomcrypt_hash.h>
|
|
73
|
+
#include <tomcrypt_mac.h>
|
|
74
|
+
#include <tomcrypt_prng.h>
|
|
75
|
+
#include <tomcrypt_pk.h>
|
|
76
|
+
#include <tomcrypt_math.h>
|
|
77
|
+
#include <tomcrypt_misc.h>
|
|
78
|
+
#include <tomcrypt_argchk.h>
|
|
79
|
+
#include <tomcrypt_pkcs.h>
|
|
80
|
+
|
|
81
|
+
#ifdef __cplusplus
|
|
82
|
+
}
|
|
83
|
+
#endif
|
|
84
|
+
|
|
85
|
+
#endif /* TOMCRYPT_H_ */
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
/* $Source$ */
|
|
89
|
+
/* $Revision$ */
|
|
90
|
+
/* $Date$ */
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* Defines the LTC_ARGCHK macro used within the library */
|
|
2
|
+
/* ARGTYPE is defined in tomcrypt_cfg.h */
|
|
3
|
+
#if ARGTYPE == 0
|
|
4
|
+
|
|
5
|
+
#include <signal.h>
|
|
6
|
+
|
|
7
|
+
/* this is the default LibTomCrypt macro */
|
|
8
|
+
#if defined(__clang__) || defined(__GNUC_MINOR__)
|
|
9
|
+
#define NORETURN __attribute__ ((noreturn))
|
|
10
|
+
#else
|
|
11
|
+
#define NORETURN
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
void crypt_argchk(char *v, char *s, int d) NORETURN;
|
|
15
|
+
#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
|
|
16
|
+
#define LTC_ARGCHKVD(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
|
|
17
|
+
|
|
18
|
+
#elif ARGTYPE == 1
|
|
19
|
+
|
|
20
|
+
/* fatal type of error */
|
|
21
|
+
#define LTC_ARGCHK(x) assert((x))
|
|
22
|
+
#define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
|
|
23
|
+
|
|
24
|
+
#elif ARGTYPE == 2
|
|
25
|
+
|
|
26
|
+
#define LTC_ARGCHK(x) if (!(x)) { fprintf(stderr, "\nwarning: ARGCHK failed at %s:%d\n", __FILE__, __LINE__); }
|
|
27
|
+
#define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
|
|
28
|
+
|
|
29
|
+
#elif ARGTYPE == 3
|
|
30
|
+
|
|
31
|
+
#define LTC_ARGCHK(x)
|
|
32
|
+
#define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
|
|
33
|
+
|
|
34
|
+
#elif ARGTYPE == 4
|
|
35
|
+
|
|
36
|
+
#define LTC_ARGCHK(x) if (!(x)) return CRYPT_INVALID_ARG;
|
|
37
|
+
#define LTC_ARGCHKVD(x) if (!(x)) return;
|
|
38
|
+
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/* $Source$ */
|
|
43
|
+
/* $Revision$ */
|
|
44
|
+
/* $Date$ */
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/* This is the build config file.
|
|
2
|
+
*
|
|
3
|
+
* With this you can setup what to inlcude/exclude automatically during any build. Just comment
|
|
4
|
+
* out the line that #define's the word for the thing you want to remove. phew!
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#ifndef TOMCRYPT_CFG_H
|
|
8
|
+
#define TOMCRYPT_CFG_H
|
|
9
|
+
|
|
10
|
+
#if defined(_WIN32) || defined(_MSC_VER)
|
|
11
|
+
#define LTC_CALL __cdecl
|
|
12
|
+
#else
|
|
13
|
+
#ifndef LTC_CALL
|
|
14
|
+
#define LTC_CALL
|
|
15
|
+
#endif
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
#ifndef LTC_EXPORT
|
|
19
|
+
#define LTC_EXPORT
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
/* certain platforms use macros for these, making the prototypes broken */
|
|
23
|
+
#ifndef LTC_NO_PROTOTYPES
|
|
24
|
+
|
|
25
|
+
/* you can change how memory allocation works ... */
|
|
26
|
+
LTC_EXPORT void * LTC_CALL XMALLOC(size_t n);
|
|
27
|
+
LTC_EXPORT void * LTC_CALL XREALLOC(void *p, size_t n);
|
|
28
|
+
LTC_EXPORT void * LTC_CALL XCALLOC(size_t n, size_t s);
|
|
29
|
+
LTC_EXPORT void LTC_CALL XFREE(void *p);
|
|
30
|
+
|
|
31
|
+
LTC_EXPORT void LTC_CALL XQSORT(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/* change the clock function too */
|
|
35
|
+
LTC_EXPORT clock_t LTC_CALL XCLOCK(void);
|
|
36
|
+
|
|
37
|
+
/* various other functions */
|
|
38
|
+
LTC_EXPORT void * LTC_CALL XMEMCPY(void *dest, const void *src, size_t n);
|
|
39
|
+
LTC_EXPORT int LTC_CALL XMEMCMP(const void *s1, const void *s2, size_t n);
|
|
40
|
+
LTC_EXPORT void * LTC_CALL XMEMSET(void *s, int c, size_t n);
|
|
41
|
+
|
|
42
|
+
LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2);
|
|
43
|
+
|
|
44
|
+
#endif
|
|
45
|
+
|
|
46
|
+
/* type of argument checking, 0=default, 1=fatal and 2=error+continue, 3=nothing */
|
|
47
|
+
#ifndef ARGTYPE
|
|
48
|
+
#define ARGTYPE 0
|
|
49
|
+
#endif
|
|
50
|
+
|
|
51
|
+
/* Controls endianess and size of registers. Leave uncommented to get platform neutral [slower] code
|
|
52
|
+
*
|
|
53
|
+
* Note: in order to use the optimized macros your platform must support unaligned 32 and 64 bit read/writes.
|
|
54
|
+
* The x86 platforms allow this but some others [ARM for instance] do not. On those platforms you **MUST**
|
|
55
|
+
* use the portable [slower] macros.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/* detect x86-32 machines somewhat */
|
|
59
|
+
#if !defined(__STRICT_ANSI__) && !defined(__x86_64__) && !defined(_WIN64) && ((defined(_MSC_VER) && defined(WIN32)) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__))))
|
|
60
|
+
#define ENDIAN_LITTLE
|
|
61
|
+
#define ENDIAN_32BITWORD
|
|
62
|
+
#define LTC_FAST
|
|
63
|
+
#endif
|
|
64
|
+
|
|
65
|
+
/* detects MIPS R5900 processors (PS2) */
|
|
66
|
+
#if (defined(__R5900) || defined(R5900) || defined(__R5900__)) && (defined(_mips) || defined(__mips__) || defined(mips))
|
|
67
|
+
#define ENDIAN_LITTLE
|
|
68
|
+
#define ENDIAN_64BITWORD
|
|
69
|
+
#endif
|
|
70
|
+
|
|
71
|
+
/* detect amd64 */
|
|
72
|
+
#if !defined(__STRICT_ANSI__) && defined(__x86_64__)
|
|
73
|
+
#define ENDIAN_LITTLE
|
|
74
|
+
#define ENDIAN_64BITWORD
|
|
75
|
+
#define LTC_FAST
|
|
76
|
+
#endif
|
|
77
|
+
|
|
78
|
+
/* detect PPC32 */
|
|
79
|
+
#if !defined(__STRICT_ANSI__) && defined(LTC_PPC32)
|
|
80
|
+
#define ENDIAN_BIG
|
|
81
|
+
#define ENDIAN_32BITWORD
|
|
82
|
+
#define LTC_FAST
|
|
83
|
+
#endif
|
|
84
|
+
|
|
85
|
+
/* fix for MSVC ...evil! */
|
|
86
|
+
#ifdef _MSC_VER
|
|
87
|
+
#define CONST64(n) n ## ui64
|
|
88
|
+
typedef unsigned __int64 ulong64;
|
|
89
|
+
#else
|
|
90
|
+
#define CONST64(n) n ## ULL
|
|
91
|
+
typedef unsigned long long ulong64;
|
|
92
|
+
#endif
|
|
93
|
+
|
|
94
|
+
/* this is the "32-bit at least" data type
|
|
95
|
+
* Re-define it to suit your platform but it must be at least 32-bits
|
|
96
|
+
*/
|
|
97
|
+
#if defined(__x86_64__) || (defined(__sparc__) && defined(__arch64__))
|
|
98
|
+
typedef unsigned ulong32;
|
|
99
|
+
#else
|
|
100
|
+
typedef unsigned long ulong32;
|
|
101
|
+
#endif
|
|
102
|
+
|
|
103
|
+
#ifdef LTC_NO_FAST
|
|
104
|
+
#undef LTC_FAST
|
|
105
|
+
#endif
|
|
106
|
+
|
|
107
|
+
#ifdef LTC_FAST
|
|
108
|
+
#if __GNUC__ < 4 /* if the compiler does not support gnu extensions, i.e. its neither clang nor gcc nor icc */
|
|
109
|
+
#error the LTC_FAST hack is only available on compilers that support __attribute__((may_alias)) - disable it for your compiler, and dont worry, it won`t buy you much anyway
|
|
110
|
+
#else
|
|
111
|
+
#ifdef ENDIAN_64BITWORD
|
|
112
|
+
typedef ulong64 __attribute__((__may_alias__)) LTC_FAST_TYPE;
|
|
113
|
+
#else
|
|
114
|
+
typedef ulong32 __attribute__((__may_alias__)) LTC_FAST_TYPE;
|
|
115
|
+
#endif
|
|
116
|
+
#endif
|
|
117
|
+
#endif /* LTC_FAST */
|
|
118
|
+
|
|
119
|
+
/* detect sparc and sparc64 */
|
|
120
|
+
#if defined(__sparc__)
|
|
121
|
+
#define ENDIAN_BIG
|
|
122
|
+
#if defined(__arch64__)
|
|
123
|
+
#define ENDIAN_64BITWORD
|
|
124
|
+
#else
|
|
125
|
+
#define ENDIAN_32BITWORD
|
|
126
|
+
#endif
|
|
127
|
+
#endif
|
|
128
|
+
|
|
129
|
+
#ifdef ENDIAN_64BITWORD
|
|
130
|
+
typedef ulong64 ltc_mp_digit;
|
|
131
|
+
#else
|
|
132
|
+
typedef ulong32 ltc_mp_digit;
|
|
133
|
+
#endif
|
|
134
|
+
|
|
135
|
+
/* No asm is a quick way to disable anything "not portable" */
|
|
136
|
+
#ifdef LTC_NO_ASM
|
|
137
|
+
#undef ENDIAN_LITTLE
|
|
138
|
+
#undef ENDIAN_BIG
|
|
139
|
+
#undef ENDIAN_32BITWORD
|
|
140
|
+
#undef ENDIAN_64BITWORD
|
|
141
|
+
#undef LTC_FAST
|
|
142
|
+
#undef LTC_FAST_TYPE
|
|
143
|
+
#define LTC_NO_ROLC
|
|
144
|
+
#define LTC_NO_BSWAP
|
|
145
|
+
#endif
|
|
146
|
+
|
|
147
|
+
/* #define ENDIAN_LITTLE */
|
|
148
|
+
/* #define ENDIAN_BIG */
|
|
149
|
+
|
|
150
|
+
/* #define ENDIAN_32BITWORD */
|
|
151
|
+
/* #define ENDIAN_64BITWORD */
|
|
152
|
+
|
|
153
|
+
#if (defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE)) && !(defined(ENDIAN_32BITWORD) || defined(ENDIAN_64BITWORD))
|
|
154
|
+
#error You must specify a word size as well as endianess in tomcrypt_cfg.h
|
|
155
|
+
#endif
|
|
156
|
+
|
|
157
|
+
#if !(defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE))
|
|
158
|
+
#define ENDIAN_NEUTRAL
|
|
159
|
+
#endif
|
|
160
|
+
|
|
161
|
+
#if (defined(ENDIAN_32BITWORD) && defined(ENDIAN_64BITWORD))
|
|
162
|
+
#error Can not be 32 and 64 bit words...
|
|
163
|
+
#endif
|
|
164
|
+
|
|
165
|
+
/* gcc 4.3 and up has a bswap builtin; detect it by gcc version.
|
|
166
|
+
* clang also supports the bswap builtin, and although clang pretends
|
|
167
|
+
* to be gcc (macro-wise, anyway), clang pretends to be a version
|
|
168
|
+
* prior to gcc 4.3, so we can't detect bswap that way. Instead,
|
|
169
|
+
* clang has a __has_builtin mechanism that can be used to check
|
|
170
|
+
* for builtins:
|
|
171
|
+
* http://clang.llvm.org/docs/LanguageExtensions.html#feature_check */
|
|
172
|
+
#ifndef __has_builtin
|
|
173
|
+
#define __has_builtin(x) 0
|
|
174
|
+
#endif
|
|
175
|
+
#if !defined(LTC_NO_BSWAP) && defined(__GNUC__) && \
|
|
176
|
+
((__GNUC__ * 100 + __GNUC_MINOR__ >= 403) || \
|
|
177
|
+
(__has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)))
|
|
178
|
+
#define LTC_HAVE_BSWAP_BUILTIN
|
|
179
|
+
#endif
|
|
180
|
+
|
|
181
|
+
#endif
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
/* $Source$ */
|
|
185
|
+
/* $Revision$ */
|
|
186
|
+
/* $Date$ */
|