ruby_olm 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/ruby_olm/ext_lib_olm/ext_account.c +274 -0
- data/ext/ruby_olm/ext_lib_olm/ext_lib_olm.c +51 -0
- data/ext/ruby_olm/ext_lib_olm/ext_lib_olm.h +13 -0
- data/ext/ruby_olm/ext_lib_olm/ext_session.c +363 -0
- data/ext/ruby_olm/ext_lib_olm/ext_utility.c +69 -0
- data/ext/ruby_olm/ext_lib_olm/extconf.rb +69 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_account.cpp +695 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_account.h +56 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_inbound_group_session.cpp +654 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_inbound_group_session.h +51 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni.h +81 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni_helper.cpp +224 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni_helper.h +30 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_manager.cpp +35 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_manager.h +36 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_outbound_group_session.cpp +563 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_outbound_group_session.h +49 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_pk.cpp +716 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_pk.h +48 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_session.cpp +977 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_session.h +59 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_utility.cpp +236 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_utility.h +40 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_decode_message.cpp +14 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_decrypt.cpp +65 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_group_decrypt.cpp +73 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_unpickle_account.cpp +14 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_unpickle_session.cpp +14 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/include/fuzzing.hh +82 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/account.hh +160 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/base64.h +77 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/base64.hh +63 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/cipher.h +138 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/crypto.h +202 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/error.h +72 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/inbound_group_session.h +235 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/list.hh +119 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/megolm.h +95 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/memory.h +41 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/memory.hh +90 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/message.h +93 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/message.hh +138 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/olm.h +451 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/olm.hh +4 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/outbound_group_session.h +181 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle.h +90 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle.hh +149 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle_encoding.h +76 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pk.h +214 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/ratchet.hh +184 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/session.hh +156 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/utility.hh +61 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes.c +1073 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes.h +123 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes_test.c +276 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour.c +45 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour.h +30 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour_test.c +47 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64.c +135 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64.h +27 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64_test.c +54 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish.c +269 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish.h +32 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish_test.c +68 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des.c +269 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des.h +37 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des_test.c +83 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2.c +104 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2.h +33 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2_test.c +58 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5.c +189 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5.h +34 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5_test.c +60 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13.c +35 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13.h +20 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13_test.c +44 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1.c +149 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1.h +35 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1_test.c +58 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256.c +159 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256.h +34 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256_test.c +61 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/contrib/Curve25519Donna.c +118 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/contrib/Curve25519Donna.h +53 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/curve25519-donna-c64.c +449 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/curve25519-donna.c +860 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/python-src/curve25519/curve25519module.c +105 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/speed-curve25519.c +50 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-curve25519.c +54 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-noncanon.c +39 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-sc-curve25519.c +72 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna.h +18 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/add_scalar.c +56 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ed25519.h +38 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fe.c +1493 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fe.h +41 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fixedint.h +72 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ge.c +467 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ge.h +74 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/key_exchange.c +79 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/keypair.c +16 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/precomp_data.h +1391 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sc.c +814 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sc.h +12 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/seed.c +40 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sha512.c +275 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sha512.h +21 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sign.c +31 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/verify.c +77 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/test.c +150 -0
- data/ext/ruby_olm/ext_lib_olm/olm/python/dummy/stddef.h +0 -0
- data/ext/ruby_olm/ext_lib_olm/olm/python/dummy/stdint.h +0 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/account.cpp +380 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/base64.cpp +167 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/cipher.cpp +152 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/crypto.cpp +299 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/ed25519.c +22 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/error.c +44 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/inbound_group_session.c +524 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/megolm.c +150 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/memory.cpp +45 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/message.cpp +401 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/olm.cpp +738 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/outbound_group_session.c +363 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/pickle.cpp +242 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/pickle_encoding.c +92 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/pk.cpp +412 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/ratchet.cpp +625 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/session.cpp +462 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/utility.cpp +57 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/include/unittest.hh +107 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_base64.cpp +70 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_crypto.cpp +246 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_group_session.cpp +329 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_list.cpp +92 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_megolm.cpp +134 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_message.cpp +112 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm.cpp +405 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_decrypt.cpp +90 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_sha256.cpp +20 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_signature.cpp +81 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_using_malloc.cpp +210 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_pk.cpp +166 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_ratchet.cpp +221 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_session.cpp +144 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMAccount.h +51 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMAccount_Private.h +25 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMInboundGroupSession.h +38 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMKit.h +37 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMMessage.h +38 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMOutboundGroupSession.h +32 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkDecryption.h +71 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkEncryption.h +42 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkMessage.h +31 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSerializable.h +29 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSession.h +44 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSession_Private.h +26 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMUtility.h +49 -0
- data/ext/ruby_olm/ext_lib_olm/staging/account.cpp +380 -0
- data/ext/ruby_olm/ext_lib_olm/staging/aes.c +1073 -0
- data/ext/ruby_olm/ext_lib_olm/staging/base64.cpp +167 -0
- data/ext/ruby_olm/ext_lib_olm/staging/cipher.cpp +152 -0
- data/ext/ruby_olm/ext_lib_olm/staging/crypto.cpp +299 -0
- data/ext/ruby_olm/ext_lib_olm/staging/curve25519-donna.c +860 -0
- data/ext/ruby_olm/ext_lib_olm/staging/ed25519.c +22 -0
- data/ext/ruby_olm/ext_lib_olm/staging/error.c +44 -0
- data/ext/ruby_olm/ext_lib_olm/staging/inbound_group_session.c +524 -0
- data/ext/ruby_olm/ext_lib_olm/staging/megolm.c +150 -0
- data/ext/ruby_olm/ext_lib_olm/staging/memory.cpp +45 -0
- data/ext/ruby_olm/ext_lib_olm/staging/message.cpp +401 -0
- data/ext/ruby_olm/ext_lib_olm/staging/olm.cpp +738 -0
- data/ext/ruby_olm/ext_lib_olm/staging/outbound_group_session.c +363 -0
- data/ext/ruby_olm/ext_lib_olm/staging/pickle.cpp +242 -0
- data/ext/ruby_olm/ext_lib_olm/staging/pickle_encoding.c +92 -0
- data/ext/ruby_olm/ext_lib_olm/staging/pk.cpp +412 -0
- data/ext/ruby_olm/ext_lib_olm/staging/ratchet.cpp +625 -0
- data/ext/ruby_olm/ext_lib_olm/staging/session.cpp +461 -0
- data/ext/ruby_olm/ext_lib_olm/staging/sha256.c +159 -0
- data/ext/ruby_olm/ext_lib_olm/staging/utility.cpp +57 -0
- data/lib/ruby_olm/account.rb +42 -0
- data/lib/ruby_olm/message.rb +6 -0
- data/lib/ruby_olm/olm_error.rb +70 -0
- data/lib/ruby_olm/olm_message.rb +25 -0
- data/lib/ruby_olm/pre_key_message.rb +6 -0
- data/lib/ruby_olm/session.rb +16 -0
- data/lib/ruby_olm/version.rb +5 -0
- data/lib/ruby_olm.rb +10 -0
- data/rakefile +18 -0
- data/test/examples/test_bob_no_answer.rb +62 -0
- data/test/examples/test_exchange.rb +60 -0
- data/test/spec/test_account.rb +152 -0
- data/test/unit/test_account_methods.rb +85 -0
- metadata +282 -0
data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/python-src/curve25519/curve25519module.c
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
/* tell python that PyArg_ParseTuple(t#) means Py_ssize_t, not int */
|
2
|
+
#define PY_SSIZE_T_CLEAN
|
3
|
+
#include <Python.h>
|
4
|
+
#if (PY_VERSION_HEX < 0x02050000)
|
5
|
+
typedef int Py_ssize_t;
|
6
|
+
#endif
|
7
|
+
|
8
|
+
/* This is required for compatibility with Python 2. */
|
9
|
+
#if PY_MAJOR_VERSION >= 3
|
10
|
+
#include <bytesobject.h>
|
11
|
+
#define y "y"
|
12
|
+
#else
|
13
|
+
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
|
14
|
+
#define y "t"
|
15
|
+
#endif
|
16
|
+
|
17
|
+
int curve25519_donna(char *mypublic,
|
18
|
+
const char *secret, const char *basepoint);
|
19
|
+
|
20
|
+
static PyObject *
|
21
|
+
pycurve25519_makeprivate(PyObject *self, PyObject *args)
|
22
|
+
{
|
23
|
+
char *in1;
|
24
|
+
Py_ssize_t in1len;
|
25
|
+
if (!PyArg_ParseTuple(args, y"#:clamp", &in1, &in1len))
|
26
|
+
return NULL;
|
27
|
+
if (in1len != 32) {
|
28
|
+
PyErr_SetString(PyExc_ValueError, "input must be 32-byte string");
|
29
|
+
return NULL;
|
30
|
+
}
|
31
|
+
in1[0] &= 248;
|
32
|
+
in1[31] &= 127;
|
33
|
+
in1[31] |= 64;
|
34
|
+
return PyBytes_FromStringAndSize((char *)in1, 32);
|
35
|
+
}
|
36
|
+
|
37
|
+
static PyObject *
|
38
|
+
pycurve25519_makepublic(PyObject *self, PyObject *args)
|
39
|
+
{
|
40
|
+
const char *private;
|
41
|
+
char mypublic[32];
|
42
|
+
char basepoint[32] = {9};
|
43
|
+
Py_ssize_t privatelen;
|
44
|
+
if (!PyArg_ParseTuple(args, y"#:makepublic", &private, &privatelen))
|
45
|
+
return NULL;
|
46
|
+
if (privatelen != 32) {
|
47
|
+
PyErr_SetString(PyExc_ValueError, "input must be 32-byte string");
|
48
|
+
return NULL;
|
49
|
+
}
|
50
|
+
curve25519_donna(mypublic, private, basepoint);
|
51
|
+
return PyBytes_FromStringAndSize((char *)mypublic, 32);
|
52
|
+
}
|
53
|
+
|
54
|
+
static PyObject *
|
55
|
+
pycurve25519_makeshared(PyObject *self, PyObject *args)
|
56
|
+
{
|
57
|
+
const char *myprivate, *theirpublic;
|
58
|
+
char shared_key[32];
|
59
|
+
Py_ssize_t myprivatelen, theirpubliclen;
|
60
|
+
if (!PyArg_ParseTuple(args, y"#"y"#:generate",
|
61
|
+
&myprivate, &myprivatelen, &theirpublic, &theirpubliclen))
|
62
|
+
return NULL;
|
63
|
+
if (myprivatelen != 32) {
|
64
|
+
PyErr_SetString(PyExc_ValueError, "input must be 32-byte string");
|
65
|
+
return NULL;
|
66
|
+
}
|
67
|
+
if (theirpubliclen != 32) {
|
68
|
+
PyErr_SetString(PyExc_ValueError, "input must be 32-byte string");
|
69
|
+
return NULL;
|
70
|
+
}
|
71
|
+
curve25519_donna(shared_key, myprivate, theirpublic);
|
72
|
+
return PyBytes_FromStringAndSize((char *)shared_key, 32);
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
static PyMethodDef
|
77
|
+
curve25519_functions[] = {
|
78
|
+
{"make_private", pycurve25519_makeprivate, METH_VARARGS, "data->private"},
|
79
|
+
{"make_public", pycurve25519_makepublic, METH_VARARGS, "private->public"},
|
80
|
+
{"make_shared", pycurve25519_makeshared, METH_VARARGS, "private+public->shared"},
|
81
|
+
{NULL, NULL, 0, NULL},
|
82
|
+
};
|
83
|
+
|
84
|
+
#if PY_MAJOR_VERSION >= 3
|
85
|
+
static struct PyModuleDef
|
86
|
+
curve25519_module = {
|
87
|
+
PyModuleDef_HEAD_INIT,
|
88
|
+
"_curve25519",
|
89
|
+
NULL,
|
90
|
+
NULL,
|
91
|
+
curve25519_functions,
|
92
|
+
};
|
93
|
+
|
94
|
+
PyObject *
|
95
|
+
PyInit__curve25519(void)
|
96
|
+
{
|
97
|
+
return PyModule_Create(&curve25519_module);
|
98
|
+
}
|
99
|
+
#else
|
100
|
+
PyMODINIT_FUNC
|
101
|
+
init_curve25519(void)
|
102
|
+
{
|
103
|
+
(void)Py_InitModule("_curve25519", curve25519_functions);
|
104
|
+
}
|
105
|
+
#endif
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <string.h>
|
3
|
+
#include <sys/time.h>
|
4
|
+
#include <time.h>
|
5
|
+
#include <stdint.h>
|
6
|
+
|
7
|
+
typedef uint8_t u8;
|
8
|
+
|
9
|
+
extern void curve25519_donna(u8 *output, const u8 *secret, const u8 *bp);
|
10
|
+
|
11
|
+
static uint64_t
|
12
|
+
time_now() {
|
13
|
+
struct timeval tv;
|
14
|
+
uint64_t ret;
|
15
|
+
|
16
|
+
gettimeofday(&tv, NULL);
|
17
|
+
ret = tv.tv_sec;
|
18
|
+
ret *= 1000000;
|
19
|
+
ret += tv.tv_usec;
|
20
|
+
|
21
|
+
return ret;
|
22
|
+
}
|
23
|
+
|
24
|
+
int
|
25
|
+
main() {
|
26
|
+
static const unsigned char basepoint[32] = {9};
|
27
|
+
unsigned char mysecret[32], mypublic[32];
|
28
|
+
unsigned i;
|
29
|
+
uint64_t start, end;
|
30
|
+
|
31
|
+
memset(mysecret, 42, 32);
|
32
|
+
mysecret[0] &= 248;
|
33
|
+
mysecret[31] &= 127;
|
34
|
+
mysecret[31] |= 64;
|
35
|
+
|
36
|
+
// Load the caches
|
37
|
+
for (i = 0; i < 1000; ++i) {
|
38
|
+
curve25519_donna(mypublic, mysecret, basepoint);
|
39
|
+
}
|
40
|
+
|
41
|
+
start = time_now();
|
42
|
+
for (i = 0; i < 30000; ++i) {
|
43
|
+
curve25519_donna(mypublic, mysecret, basepoint);
|
44
|
+
}
|
45
|
+
end = time_now();
|
46
|
+
|
47
|
+
printf("%luus\n", (unsigned long) ((end - start) / 30000));
|
48
|
+
|
49
|
+
return 0;
|
50
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/*
|
2
|
+
test-curve25519 version 20050915
|
3
|
+
D. J. Bernstein
|
4
|
+
Public domain.
|
5
|
+
|
6
|
+
Tiny modifications by agl
|
7
|
+
*/
|
8
|
+
|
9
|
+
#include <stdio.h>
|
10
|
+
|
11
|
+
extern void curve25519_donna(unsigned char *output, const unsigned char *a,
|
12
|
+
const unsigned char *b);
|
13
|
+
void doit(unsigned char *ek,unsigned char *e,unsigned char *k);
|
14
|
+
|
15
|
+
void doit(unsigned char *ek,unsigned char *e,unsigned char *k)
|
16
|
+
{
|
17
|
+
int i;
|
18
|
+
|
19
|
+
for (i = 0;i < 32;++i) printf("%02x",(unsigned int) e[i]); printf(" ");
|
20
|
+
for (i = 0;i < 32;++i) printf("%02x",(unsigned int) k[i]); printf(" ");
|
21
|
+
curve25519_donna(ek,e,k);
|
22
|
+
for (i = 0;i < 32;++i) printf("%02x",(unsigned int) ek[i]); printf("\n");
|
23
|
+
}
|
24
|
+
|
25
|
+
unsigned char e1k[32];
|
26
|
+
unsigned char e2k[32];
|
27
|
+
unsigned char e1e2k[32];
|
28
|
+
unsigned char e2e1k[32];
|
29
|
+
unsigned char e1[32] = {3};
|
30
|
+
unsigned char e2[32] = {5};
|
31
|
+
unsigned char k[32] = {9};
|
32
|
+
|
33
|
+
int
|
34
|
+
main()
|
35
|
+
{
|
36
|
+
int loop;
|
37
|
+
int i;
|
38
|
+
|
39
|
+
for (loop = 0;loop < 10000;++loop) {
|
40
|
+
doit(e1k,e1,k);
|
41
|
+
doit(e2e1k,e2,e1k);
|
42
|
+
doit(e2k,e2,k);
|
43
|
+
doit(e1e2k,e1,e2k);
|
44
|
+
for (i = 0;i < 32;++i) if (e1e2k[i] != e2e1k[i]) {
|
45
|
+
printf("fail\n");
|
46
|
+
return 1;
|
47
|
+
}
|
48
|
+
for (i = 0;i < 32;++i) e1[i] ^= e2k[i];
|
49
|
+
for (i = 0;i < 32;++i) e2[i] ^= e1k[i];
|
50
|
+
for (i = 0;i < 32;++i) k[i] ^= e1e2k[i];
|
51
|
+
}
|
52
|
+
|
53
|
+
return 0;
|
54
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/* This file can be used to test whether the code handles non-canonical curve
|
2
|
+
* points (i.e. points with the 256th bit set) in the same way as the reference
|
3
|
+
* implementation. */
|
4
|
+
|
5
|
+
#include <stdint.h>
|
6
|
+
#include <stdio.h>
|
7
|
+
#include <string.h>
|
8
|
+
|
9
|
+
extern void curve25519_donna(unsigned char *output, const unsigned char *a,
|
10
|
+
const unsigned char *b);
|
11
|
+
int
|
12
|
+
main()
|
13
|
+
{
|
14
|
+
static const uint8_t point1[32] = {
|
15
|
+
0x25,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
16
|
+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
17
|
+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
18
|
+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
19
|
+
};
|
20
|
+
static const uint8_t point2[32] = {
|
21
|
+
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
22
|
+
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
23
|
+
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
24
|
+
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
25
|
+
};
|
26
|
+
static const uint8_t scalar[32] = { 1 };
|
27
|
+
uint8_t out1[32], out2[32];
|
28
|
+
|
29
|
+
curve25519_donna(out1, scalar, point1);
|
30
|
+
curve25519_donna(out2, scalar, point2);
|
31
|
+
|
32
|
+
if (0 == memcmp(out1, out2, sizeof(out1))) {
|
33
|
+
fprintf(stderr, "Top bit not ignored.\n");
|
34
|
+
return 1;
|
35
|
+
}
|
36
|
+
|
37
|
+
fprintf(stderr, "Top bit correctly ignored.\n");
|
38
|
+
return 0;
|
39
|
+
}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#define _GNU_SOURCE
|
2
|
+
|
3
|
+
#include <stdio.h>
|
4
|
+
#include <string.h>
|
5
|
+
#include <stdint.h>
|
6
|
+
#include <math.h>
|
7
|
+
|
8
|
+
extern void curve25519_donna(uint8_t *, const uint8_t *, const uint8_t *);
|
9
|
+
extern uint64_t tsc_read();
|
10
|
+
|
11
|
+
int
|
12
|
+
main(int argc, char **argv) {
|
13
|
+
uint8_t private_key[32], public[32], peer1[32], peer2[32], output[32];
|
14
|
+
static const uint8_t basepoint[32] = {9};
|
15
|
+
unsigned i;
|
16
|
+
uint64_t sum = 0, sum_squares = 0, skipped = 0, mean;
|
17
|
+
static const unsigned count = 200000;
|
18
|
+
|
19
|
+
memset(private_key, 42, sizeof(private_key));
|
20
|
+
|
21
|
+
private_key[0] &= 248;
|
22
|
+
private_key[31] &= 127;
|
23
|
+
private_key[31] |= 64;
|
24
|
+
|
25
|
+
curve25519_donna(public, private_key, basepoint);
|
26
|
+
memset(peer1, 0, sizeof(peer1));
|
27
|
+
memset(peer2, 255, sizeof(peer2));
|
28
|
+
|
29
|
+
for (i = 0; i < count; ++i) {
|
30
|
+
const uint64_t start = tsc_read();
|
31
|
+
curve25519_donna(output, peer1, public);
|
32
|
+
const uint64_t end = tsc_read();
|
33
|
+
const uint64_t delta = end - start;
|
34
|
+
if (delta > 650000) {
|
35
|
+
// something terrible happened (task switch etc)
|
36
|
+
skipped++;
|
37
|
+
continue;
|
38
|
+
}
|
39
|
+
sum += delta;
|
40
|
+
sum_squares += (delta * delta);
|
41
|
+
}
|
42
|
+
|
43
|
+
mean = sum / ((uint64_t) count);
|
44
|
+
printf("all 0: mean:%lu sd:%f skipped:%lu\n",
|
45
|
+
mean,
|
46
|
+
sqrt((double)(sum_squares/((uint64_t) count) - mean*mean)),
|
47
|
+
skipped);
|
48
|
+
|
49
|
+
sum = sum_squares = skipped = 0;
|
50
|
+
|
51
|
+
for (i = 0; i < count; ++i) {
|
52
|
+
const uint64_t start = tsc_read();
|
53
|
+
curve25519_donna(output, peer2, public);
|
54
|
+
const uint64_t end = tsc_read();
|
55
|
+
const uint64_t delta = end - start;
|
56
|
+
if (delta > 650000) {
|
57
|
+
// something terrible happened (task switch etc)
|
58
|
+
skipped++;
|
59
|
+
continue;
|
60
|
+
}
|
61
|
+
sum += delta;
|
62
|
+
sum_squares += (delta * delta);
|
63
|
+
}
|
64
|
+
|
65
|
+
mean = sum / ((uint64_t) count);
|
66
|
+
printf("all 1: mean:%lu sd:%f skipped:%lu\n",
|
67
|
+
mean,
|
68
|
+
sqrt((double)(sum_squares/((uint64_t) count) - mean*mean)),
|
69
|
+
skipped);
|
70
|
+
|
71
|
+
return 0;
|
72
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/* header file for the curve25519-donna implementation, because the
|
2
|
+
* authors of that project don't supply one.
|
3
|
+
*/
|
4
|
+
#ifndef CURVE25519_DONNA_H
|
5
|
+
#define CURVE25519_DONNA_H
|
6
|
+
|
7
|
+
#ifdef __cplusplus
|
8
|
+
extern "C" {
|
9
|
+
#endif
|
10
|
+
|
11
|
+
extern int curve25519_donna(unsigned char *output, const unsigned char *a,
|
12
|
+
const unsigned char *b);
|
13
|
+
|
14
|
+
#ifdef __cplusplus
|
15
|
+
}
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#endif
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#include "ed25519.h"
|
2
|
+
#include "ge.h"
|
3
|
+
#include "sc.h"
|
4
|
+
|
5
|
+
|
6
|
+
/* see http://crypto.stackexchange.com/a/6215/4697 */
|
7
|
+
void ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar) {
|
8
|
+
const unsigned char SC_1[32] = {1}; /* scalar with value 1 */
|
9
|
+
|
10
|
+
unsigned char n[32];
|
11
|
+
ge_p3 nB;
|
12
|
+
ge_p1p1 A_p1p1;
|
13
|
+
ge_p3 A;
|
14
|
+
ge_p3 public_key_unpacked;
|
15
|
+
ge_cached T;
|
16
|
+
|
17
|
+
int i;
|
18
|
+
|
19
|
+
/* copy the scalar and clear highest bit */
|
20
|
+
for (i = 0; i < 31; ++i) {
|
21
|
+
n[i] = scalar[i];
|
22
|
+
}
|
23
|
+
n[31] = scalar[31] & 127;
|
24
|
+
|
25
|
+
/* private key: a = n + t */
|
26
|
+
if (private_key) {
|
27
|
+
sc_muladd(private_key, SC_1, n, private_key);
|
28
|
+
}
|
29
|
+
|
30
|
+
/* public key: A = nB + T */
|
31
|
+
if (public_key) {
|
32
|
+
/* if we know the private key we don't need a point addition, which is faster */
|
33
|
+
/* using a "timing attack" you could find out wether or not we know the private
|
34
|
+
key, but this information seems rather useless - if this is important pass
|
35
|
+
public_key and private_key seperately in 2 function calls */
|
36
|
+
if (private_key) {
|
37
|
+
ge_scalarmult_base(&A, private_key);
|
38
|
+
} else {
|
39
|
+
/* unpack public key into T */
|
40
|
+
ge_frombytes_negate_vartime(&public_key_unpacked, public_key);
|
41
|
+
fe_neg(public_key_unpacked.X, public_key_unpacked.X); /* undo negate */
|
42
|
+
fe_neg(public_key_unpacked.T, public_key_unpacked.T); /* undo negate */
|
43
|
+
ge_p3_to_cached(&T, &public_key_unpacked);
|
44
|
+
|
45
|
+
/* calculate n*B */
|
46
|
+
ge_scalarmult_base(&nB, n);
|
47
|
+
|
48
|
+
/* A = n*B + T */
|
49
|
+
ge_add(&A_p1p1, &nB, &T);
|
50
|
+
ge_p1p1_to_p3(&A, &A_p1p1);
|
51
|
+
}
|
52
|
+
|
53
|
+
/* pack public key */
|
54
|
+
ge_p3_tobytes(public_key, &A);
|
55
|
+
}
|
56
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#ifndef ED25519_H
|
2
|
+
#define ED25519_H
|
3
|
+
|
4
|
+
#include <stddef.h>
|
5
|
+
|
6
|
+
#if defined(_WIN32)
|
7
|
+
#if defined(ED25519_BUILD_DLL)
|
8
|
+
#define ED25519_DECLSPEC __declspec(dllexport)
|
9
|
+
#elif defined(ED25519_DLL)
|
10
|
+
#define ED25519_DECLSPEC __declspec(dllimport)
|
11
|
+
#else
|
12
|
+
#define ED25519_DECLSPEC
|
13
|
+
#endif
|
14
|
+
#else
|
15
|
+
#define ED25519_DECLSPEC
|
16
|
+
#endif
|
17
|
+
|
18
|
+
|
19
|
+
#ifdef __cplusplus
|
20
|
+
extern "C" {
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#ifndef ED25519_NO_SEED
|
24
|
+
int ED25519_DECLSPEC ed25519_create_seed(unsigned char *seed);
|
25
|
+
#endif
|
26
|
+
|
27
|
+
void ED25519_DECLSPEC ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed);
|
28
|
+
void ED25519_DECLSPEC ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key);
|
29
|
+
int ED25519_DECLSPEC ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key);
|
30
|
+
void ED25519_DECLSPEC ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar);
|
31
|
+
void ED25519_DECLSPEC ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key);
|
32
|
+
|
33
|
+
|
34
|
+
#ifdef __cplusplus
|
35
|
+
}
|
36
|
+
#endif
|
37
|
+
|
38
|
+
#endif
|