ruby_olm 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. checksums.yaml +7 -0
  2. data/ext/ruby_olm/ext_lib_olm/ext_account.c +274 -0
  3. data/ext/ruby_olm/ext_lib_olm/ext_lib_olm.c +51 -0
  4. data/ext/ruby_olm/ext_lib_olm/ext_lib_olm.h +13 -0
  5. data/ext/ruby_olm/ext_lib_olm/ext_session.c +363 -0
  6. data/ext/ruby_olm/ext_lib_olm/ext_utility.c +69 -0
  7. data/ext/ruby_olm/ext_lib_olm/extconf.rb +69 -0
  8. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_account.cpp +695 -0
  9. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_account.h +56 -0
  10. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_inbound_group_session.cpp +654 -0
  11. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_inbound_group_session.h +51 -0
  12. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni.h +81 -0
  13. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni_helper.cpp +224 -0
  14. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni_helper.h +30 -0
  15. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_manager.cpp +35 -0
  16. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_manager.h +36 -0
  17. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_outbound_group_session.cpp +563 -0
  18. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_outbound_group_session.h +49 -0
  19. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_pk.cpp +716 -0
  20. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_pk.h +48 -0
  21. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_session.cpp +977 -0
  22. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_session.h +59 -0
  23. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_utility.cpp +236 -0
  24. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_utility.h +40 -0
  25. data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_decode_message.cpp +14 -0
  26. data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_decrypt.cpp +65 -0
  27. data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_group_decrypt.cpp +73 -0
  28. data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_unpickle_account.cpp +14 -0
  29. data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_unpickle_session.cpp +14 -0
  30. data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/include/fuzzing.hh +82 -0
  31. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/account.hh +160 -0
  32. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/base64.h +77 -0
  33. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/base64.hh +63 -0
  34. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/cipher.h +138 -0
  35. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/crypto.h +202 -0
  36. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/error.h +72 -0
  37. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/inbound_group_session.h +235 -0
  38. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/list.hh +119 -0
  39. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/megolm.h +95 -0
  40. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/memory.h +41 -0
  41. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/memory.hh +90 -0
  42. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/message.h +93 -0
  43. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/message.hh +138 -0
  44. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/olm.h +451 -0
  45. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/olm.hh +4 -0
  46. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/outbound_group_session.h +181 -0
  47. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle.h +90 -0
  48. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle.hh +149 -0
  49. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle_encoding.h +76 -0
  50. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pk.h +214 -0
  51. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/ratchet.hh +184 -0
  52. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/session.hh +156 -0
  53. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/utility.hh +61 -0
  54. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes.c +1073 -0
  55. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes.h +123 -0
  56. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes_test.c +276 -0
  57. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour.c +45 -0
  58. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour.h +30 -0
  59. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour_test.c +47 -0
  60. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64.c +135 -0
  61. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64.h +27 -0
  62. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64_test.c +54 -0
  63. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish.c +269 -0
  64. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish.h +32 -0
  65. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish_test.c +68 -0
  66. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des.c +269 -0
  67. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des.h +37 -0
  68. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des_test.c +83 -0
  69. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2.c +104 -0
  70. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2.h +33 -0
  71. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2_test.c +58 -0
  72. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5.c +189 -0
  73. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5.h +34 -0
  74. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5_test.c +60 -0
  75. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13.c +35 -0
  76. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13.h +20 -0
  77. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13_test.c +44 -0
  78. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1.c +149 -0
  79. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1.h +35 -0
  80. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1_test.c +58 -0
  81. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256.c +159 -0
  82. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256.h +34 -0
  83. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256_test.c +61 -0
  84. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/contrib/Curve25519Donna.c +118 -0
  85. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/contrib/Curve25519Donna.h +53 -0
  86. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/curve25519-donna-c64.c +449 -0
  87. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/curve25519-donna.c +860 -0
  88. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/python-src/curve25519/curve25519module.c +105 -0
  89. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/speed-curve25519.c +50 -0
  90. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-curve25519.c +54 -0
  91. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-noncanon.c +39 -0
  92. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-sc-curve25519.c +72 -0
  93. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna.h +18 -0
  94. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/add_scalar.c +56 -0
  95. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ed25519.h +38 -0
  96. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fe.c +1493 -0
  97. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fe.h +41 -0
  98. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fixedint.h +72 -0
  99. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ge.c +467 -0
  100. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ge.h +74 -0
  101. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/key_exchange.c +79 -0
  102. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/keypair.c +16 -0
  103. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/precomp_data.h +1391 -0
  104. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sc.c +814 -0
  105. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sc.h +12 -0
  106. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/seed.c +40 -0
  107. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sha512.c +275 -0
  108. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sha512.h +21 -0
  109. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sign.c +31 -0
  110. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/verify.c +77 -0
  111. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/test.c +150 -0
  112. data/ext/ruby_olm/ext_lib_olm/olm/python/dummy/stddef.h +0 -0
  113. data/ext/ruby_olm/ext_lib_olm/olm/python/dummy/stdint.h +0 -0
  114. data/ext/ruby_olm/ext_lib_olm/olm/src/account.cpp +380 -0
  115. data/ext/ruby_olm/ext_lib_olm/olm/src/base64.cpp +167 -0
  116. data/ext/ruby_olm/ext_lib_olm/olm/src/cipher.cpp +152 -0
  117. data/ext/ruby_olm/ext_lib_olm/olm/src/crypto.cpp +299 -0
  118. data/ext/ruby_olm/ext_lib_olm/olm/src/ed25519.c +22 -0
  119. data/ext/ruby_olm/ext_lib_olm/olm/src/error.c +44 -0
  120. data/ext/ruby_olm/ext_lib_olm/olm/src/inbound_group_session.c +524 -0
  121. data/ext/ruby_olm/ext_lib_olm/olm/src/megolm.c +150 -0
  122. data/ext/ruby_olm/ext_lib_olm/olm/src/memory.cpp +45 -0
  123. data/ext/ruby_olm/ext_lib_olm/olm/src/message.cpp +401 -0
  124. data/ext/ruby_olm/ext_lib_olm/olm/src/olm.cpp +738 -0
  125. data/ext/ruby_olm/ext_lib_olm/olm/src/outbound_group_session.c +363 -0
  126. data/ext/ruby_olm/ext_lib_olm/olm/src/pickle.cpp +242 -0
  127. data/ext/ruby_olm/ext_lib_olm/olm/src/pickle_encoding.c +92 -0
  128. data/ext/ruby_olm/ext_lib_olm/olm/src/pk.cpp +412 -0
  129. data/ext/ruby_olm/ext_lib_olm/olm/src/ratchet.cpp +625 -0
  130. data/ext/ruby_olm/ext_lib_olm/olm/src/session.cpp +462 -0
  131. data/ext/ruby_olm/ext_lib_olm/olm/src/utility.cpp +57 -0
  132. data/ext/ruby_olm/ext_lib_olm/olm/tests/include/unittest.hh +107 -0
  133. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_base64.cpp +70 -0
  134. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_crypto.cpp +246 -0
  135. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_group_session.cpp +329 -0
  136. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_list.cpp +92 -0
  137. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_megolm.cpp +134 -0
  138. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_message.cpp +112 -0
  139. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm.cpp +405 -0
  140. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_decrypt.cpp +90 -0
  141. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_sha256.cpp +20 -0
  142. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_signature.cpp +81 -0
  143. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_using_malloc.cpp +210 -0
  144. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_pk.cpp +166 -0
  145. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_ratchet.cpp +221 -0
  146. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_session.cpp +144 -0
  147. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMAccount.h +51 -0
  148. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMAccount_Private.h +25 -0
  149. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMInboundGroupSession.h +38 -0
  150. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMKit.h +37 -0
  151. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMMessage.h +38 -0
  152. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMOutboundGroupSession.h +32 -0
  153. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkDecryption.h +71 -0
  154. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkEncryption.h +42 -0
  155. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkMessage.h +31 -0
  156. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSerializable.h +29 -0
  157. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSession.h +44 -0
  158. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSession_Private.h +26 -0
  159. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMUtility.h +49 -0
  160. data/ext/ruby_olm/ext_lib_olm/staging/account.cpp +380 -0
  161. data/ext/ruby_olm/ext_lib_olm/staging/aes.c +1073 -0
  162. data/ext/ruby_olm/ext_lib_olm/staging/base64.cpp +167 -0
  163. data/ext/ruby_olm/ext_lib_olm/staging/cipher.cpp +152 -0
  164. data/ext/ruby_olm/ext_lib_olm/staging/crypto.cpp +299 -0
  165. data/ext/ruby_olm/ext_lib_olm/staging/curve25519-donna.c +860 -0
  166. data/ext/ruby_olm/ext_lib_olm/staging/ed25519.c +22 -0
  167. data/ext/ruby_olm/ext_lib_olm/staging/error.c +44 -0
  168. data/ext/ruby_olm/ext_lib_olm/staging/inbound_group_session.c +524 -0
  169. data/ext/ruby_olm/ext_lib_olm/staging/megolm.c +150 -0
  170. data/ext/ruby_olm/ext_lib_olm/staging/memory.cpp +45 -0
  171. data/ext/ruby_olm/ext_lib_olm/staging/message.cpp +401 -0
  172. data/ext/ruby_olm/ext_lib_olm/staging/olm.cpp +738 -0
  173. data/ext/ruby_olm/ext_lib_olm/staging/outbound_group_session.c +363 -0
  174. data/ext/ruby_olm/ext_lib_olm/staging/pickle.cpp +242 -0
  175. data/ext/ruby_olm/ext_lib_olm/staging/pickle_encoding.c +92 -0
  176. data/ext/ruby_olm/ext_lib_olm/staging/pk.cpp +412 -0
  177. data/ext/ruby_olm/ext_lib_olm/staging/ratchet.cpp +625 -0
  178. data/ext/ruby_olm/ext_lib_olm/staging/session.cpp +461 -0
  179. data/ext/ruby_olm/ext_lib_olm/staging/sha256.c +159 -0
  180. data/ext/ruby_olm/ext_lib_olm/staging/utility.cpp +57 -0
  181. data/lib/ruby_olm/account.rb +42 -0
  182. data/lib/ruby_olm/message.rb +6 -0
  183. data/lib/ruby_olm/olm_error.rb +70 -0
  184. data/lib/ruby_olm/olm_message.rb +25 -0
  185. data/lib/ruby_olm/pre_key_message.rb +6 -0
  186. data/lib/ruby_olm/session.rb +16 -0
  187. data/lib/ruby_olm/version.rb +5 -0
  188. data/lib/ruby_olm.rb +10 -0
  189. data/rakefile +18 -0
  190. data/test/examples/test_bob_no_answer.rb +62 -0
  191. data/test/examples/test_exchange.rb +60 -0
  192. data/test/spec/test_account.rb +152 -0
  193. data/test/unit/test_account_methods.rb +85 -0
  194. metadata +282 -0
@@ -0,0 +1,41 @@
1
+ #ifndef FE_H
2
+ #define FE_H
3
+
4
+ #include "fixedint.h"
5
+
6
+
7
+ /*
8
+ fe means field element.
9
+ Here the field is \Z/(2^255-19).
10
+ An element t, entries t[0]...t[9], represents the integer
11
+ t[0]+2^26 t[1]+2^51 t[2]+2^77 t[3]+2^102 t[4]+...+2^230 t[9].
12
+ Bounds on each t[i] vary depending on context.
13
+ */
14
+
15
+
16
+ typedef int32_t fe[10];
17
+
18
+
19
+ void fe_0(fe h);
20
+ void fe_1(fe h);
21
+
22
+ void fe_frombytes(fe h, const unsigned char *s);
23
+ void fe_tobytes(unsigned char *s, const fe h);
24
+
25
+ void fe_copy(fe h, const fe f);
26
+ int fe_isnegative(const fe f);
27
+ int fe_isnonzero(const fe f);
28
+ void fe_cmov(fe f, const fe g, unsigned int b);
29
+ void fe_cswap(fe f, fe g, unsigned int b);
30
+
31
+ void fe_neg(fe h, const fe f);
32
+ void fe_add(fe h, const fe f, const fe g);
33
+ void fe_invert(fe out, const fe z);
34
+ void fe_sq(fe h, const fe f);
35
+ void fe_sq2(fe h, const fe f);
36
+ void fe_mul(fe h, const fe f, const fe g);
37
+ void fe_mul121666(fe h, fe f);
38
+ void fe_pow22523(fe out, const fe z);
39
+ void fe_sub(fe h, const fe f, const fe g);
40
+
41
+ #endif
@@ -0,0 +1,72 @@
1
+ /*
2
+ Portable header to provide the 32 and 64 bits type.
3
+
4
+ Not a compatible replacement for <stdint.h>, do not blindly use it as such.
5
+ */
6
+
7
+ #if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__WATCOMC__) && (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined(__UINT_FAST64_TYPE__)) )) && !defined(FIXEDINT_H_INCLUDED)
8
+ #include <stdint.h>
9
+ #define FIXEDINT_H_INCLUDED
10
+
11
+ #if defined(__WATCOMC__) && __WATCOMC__ >= 1250 && !defined(UINT64_C)
12
+ #include <limits.h>
13
+ #define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
14
+ #endif
15
+ #endif
16
+
17
+
18
+ #ifndef FIXEDINT_H_INCLUDED
19
+ #define FIXEDINT_H_INCLUDED
20
+
21
+ #include <limits.h>
22
+
23
+ /* (u)int32_t */
24
+ #ifndef uint32_t
25
+ #if (ULONG_MAX == 0xffffffffUL)
26
+ typedef unsigned long uint32_t;
27
+ #elif (UINT_MAX == 0xffffffffUL)
28
+ typedef unsigned int uint32_t;
29
+ #elif (USHRT_MAX == 0xffffffffUL)
30
+ typedef unsigned short uint32_t;
31
+ #endif
32
+ #endif
33
+
34
+
35
+ #ifndef int32_t
36
+ #if (LONG_MAX == 0x7fffffffL)
37
+ typedef signed long int32_t;
38
+ #elif (INT_MAX == 0x7fffffffL)
39
+ typedef signed int int32_t;
40
+ #elif (SHRT_MAX == 0x7fffffffL)
41
+ typedef signed short int32_t;
42
+ #endif
43
+ #endif
44
+
45
+
46
+ /* (u)int64_t */
47
+ #if (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC__ && __STDC_VERSION__ >= 199901L)
48
+ typedef long long int64_t;
49
+ typedef unsigned long long uint64_t;
50
+
51
+ #define UINT64_C(v) v ##ULL
52
+ #define INT64_C(v) v ##LL
53
+ #elif defined(__GNUC__)
54
+ __extension__ typedef long long int64_t;
55
+ __extension__ typedef unsigned long long uint64_t;
56
+
57
+ #define UINT64_C(v) v ##ULL
58
+ #define INT64_C(v) v ##LL
59
+ #elif defined(__MWERKS__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__APPLE_CC__) || defined(_LONG_LONG) || defined(_CRAYC)
60
+ typedef long long int64_t;
61
+ typedef unsigned long long uint64_t;
62
+
63
+ #define UINT64_C(v) v ##ULL
64
+ #define INT64_C(v) v ##LL
65
+ #elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined(__BORLANDC__) && __BORLANDC__ > 0x460) || defined(__alpha) || defined(__DECC)
66
+ typedef __int64 int64_t;
67
+ typedef unsigned __int64 uint64_t;
68
+
69
+ #define UINT64_C(v) v ##UI64
70
+ #define INT64_C(v) v ##I64
71
+ #endif
72
+ #endif
@@ -0,0 +1,467 @@
1
+ #include "ge.h"
2
+ #include "precomp_data.h"
3
+
4
+
5
+ /*
6
+ r = p + q
7
+ */
8
+
9
+ void ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
10
+ fe t0;
11
+ fe_add(r->X, p->Y, p->X);
12
+ fe_sub(r->Y, p->Y, p->X);
13
+ fe_mul(r->Z, r->X, q->YplusX);
14
+ fe_mul(r->Y, r->Y, q->YminusX);
15
+ fe_mul(r->T, q->T2d, p->T);
16
+ fe_mul(r->X, p->Z, q->Z);
17
+ fe_add(t0, r->X, r->X);
18
+ fe_sub(r->X, r->Z, r->Y);
19
+ fe_add(r->Y, r->Z, r->Y);
20
+ fe_add(r->Z, t0, r->T);
21
+ fe_sub(r->T, t0, r->T);
22
+ }
23
+
24
+
25
+ static void slide(signed char *r, const unsigned char *a) {
26
+ int i;
27
+ int b;
28
+ int k;
29
+
30
+ for (i = 0; i < 256; ++i) {
31
+ r[i] = 1 & (a[i >> 3] >> (i & 7));
32
+ }
33
+
34
+ for (i = 0; i < 256; ++i)
35
+ if (r[i]) {
36
+ for (b = 1; b <= 6 && i + b < 256; ++b) {
37
+ if (r[i + b]) {
38
+ if (r[i] + (r[i + b] << b) <= 15) {
39
+ r[i] += r[i + b] << b;
40
+ r[i + b] = 0;
41
+ } else if (r[i] - (r[i + b] << b) >= -15) {
42
+ r[i] -= r[i + b] << b;
43
+
44
+ for (k = i + b; k < 256; ++k) {
45
+ if (!r[k]) {
46
+ r[k] = 1;
47
+ break;
48
+ }
49
+
50
+ r[k] = 0;
51
+ }
52
+ } else {
53
+ break;
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ /*
61
+ r = a * A + b * B
62
+ where a = a[0]+256*a[1]+...+256^31 a[31].
63
+ and b = b[0]+256*b[1]+...+256^31 b[31].
64
+ B is the Ed25519 base point (x,4/5) with x positive.
65
+ */
66
+
67
+ void ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 *A, const unsigned char *b) {
68
+ signed char aslide[256];
69
+ signed char bslide[256];
70
+ ge_cached Ai[8]; /* A,3A,5A,7A,9A,11A,13A,15A */
71
+ ge_p1p1 t;
72
+ ge_p3 u;
73
+ ge_p3 A2;
74
+ int i;
75
+ slide(aslide, a);
76
+ slide(bslide, b);
77
+ ge_p3_to_cached(&Ai[0], A);
78
+ ge_p3_dbl(&t, A);
79
+ ge_p1p1_to_p3(&A2, &t);
80
+ ge_add(&t, &A2, &Ai[0]);
81
+ ge_p1p1_to_p3(&u, &t);
82
+ ge_p3_to_cached(&Ai[1], &u);
83
+ ge_add(&t, &A2, &Ai[1]);
84
+ ge_p1p1_to_p3(&u, &t);
85
+ ge_p3_to_cached(&Ai[2], &u);
86
+ ge_add(&t, &A2, &Ai[2]);
87
+ ge_p1p1_to_p3(&u, &t);
88
+ ge_p3_to_cached(&Ai[3], &u);
89
+ ge_add(&t, &A2, &Ai[3]);
90
+ ge_p1p1_to_p3(&u, &t);
91
+ ge_p3_to_cached(&Ai[4], &u);
92
+ ge_add(&t, &A2, &Ai[4]);
93
+ ge_p1p1_to_p3(&u, &t);
94
+ ge_p3_to_cached(&Ai[5], &u);
95
+ ge_add(&t, &A2, &Ai[5]);
96
+ ge_p1p1_to_p3(&u, &t);
97
+ ge_p3_to_cached(&Ai[6], &u);
98
+ ge_add(&t, &A2, &Ai[6]);
99
+ ge_p1p1_to_p3(&u, &t);
100
+ ge_p3_to_cached(&Ai[7], &u);
101
+ ge_p2_0(r);
102
+
103
+ for (i = 255; i >= 0; --i) {
104
+ if (aslide[i] || bslide[i]) {
105
+ break;
106
+ }
107
+ }
108
+
109
+ for (; i >= 0; --i) {
110
+ ge_p2_dbl(&t, r);
111
+
112
+ if (aslide[i] > 0) {
113
+ ge_p1p1_to_p3(&u, &t);
114
+ ge_add(&t, &u, &Ai[aslide[i] / 2]);
115
+ } else if (aslide[i] < 0) {
116
+ ge_p1p1_to_p3(&u, &t);
117
+ ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]);
118
+ }
119
+
120
+ if (bslide[i] > 0) {
121
+ ge_p1p1_to_p3(&u, &t);
122
+ ge_madd(&t, &u, &Bi[bslide[i] / 2]);
123
+ } else if (bslide[i] < 0) {
124
+ ge_p1p1_to_p3(&u, &t);
125
+ ge_msub(&t, &u, &Bi[(-bslide[i]) / 2]);
126
+ }
127
+
128
+ ge_p1p1_to_p2(r, &t);
129
+ }
130
+ }
131
+
132
+
133
+ static const fe d = {
134
+ -10913610, 13857413, -15372611, 6949391, 114729, -8787816, -6275908, -3247719, -18696448, -12055116
135
+ };
136
+
137
+ static const fe sqrtm1 = {
138
+ -32595792, -7943725, 9377950, 3500415, 12389472, -272473, -25146209, -2005654, 326686, 11406482
139
+ };
140
+
141
+ int ge_frombytes_negate_vartime(ge_p3 *h, const unsigned char *s) {
142
+ fe u;
143
+ fe v;
144
+ fe v3;
145
+ fe vxx;
146
+ fe check;
147
+ fe_frombytes(h->Y, s);
148
+ fe_1(h->Z);
149
+ fe_sq(u, h->Y);
150
+ fe_mul(v, u, d);
151
+ fe_sub(u, u, h->Z); /* u = y^2-1 */
152
+ fe_add(v, v, h->Z); /* v = dy^2+1 */
153
+ fe_sq(v3, v);
154
+ fe_mul(v3, v3, v); /* v3 = v^3 */
155
+ fe_sq(h->X, v3);
156
+ fe_mul(h->X, h->X, v);
157
+ fe_mul(h->X, h->X, u); /* x = uv^7 */
158
+ fe_pow22523(h->X, h->X); /* x = (uv^7)^((q-5)/8) */
159
+ fe_mul(h->X, h->X, v3);
160
+ fe_mul(h->X, h->X, u); /* x = uv^3(uv^7)^((q-5)/8) */
161
+ fe_sq(vxx, h->X);
162
+ fe_mul(vxx, vxx, v);
163
+ fe_sub(check, vxx, u); /* vx^2-u */
164
+
165
+ if (fe_isnonzero(check)) {
166
+ fe_add(check, vxx, u); /* vx^2+u */
167
+
168
+ if (fe_isnonzero(check)) {
169
+ return -1;
170
+ }
171
+
172
+ fe_mul(h->X, h->X, sqrtm1);
173
+ }
174
+
175
+ if (fe_isnegative(h->X) == (s[31] >> 7)) {
176
+ fe_neg(h->X, h->X);
177
+ }
178
+
179
+ fe_mul(h->T, h->X, h->Y);
180
+ return 0;
181
+ }
182
+
183
+
184
+ /*
185
+ r = p + q
186
+ */
187
+
188
+ void ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) {
189
+ fe t0;
190
+ fe_add(r->X, p->Y, p->X);
191
+ fe_sub(r->Y, p->Y, p->X);
192
+ fe_mul(r->Z, r->X, q->yplusx);
193
+ fe_mul(r->Y, r->Y, q->yminusx);
194
+ fe_mul(r->T, q->xy2d, p->T);
195
+ fe_add(t0, p->Z, p->Z);
196
+ fe_sub(r->X, r->Z, r->Y);
197
+ fe_add(r->Y, r->Z, r->Y);
198
+ fe_add(r->Z, t0, r->T);
199
+ fe_sub(r->T, t0, r->T);
200
+ }
201
+
202
+
203
+ /*
204
+ r = p - q
205
+ */
206
+
207
+ void ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) {
208
+ fe t0;
209
+
210
+ fe_add(r->X, p->Y, p->X);
211
+ fe_sub(r->Y, p->Y, p->X);
212
+ fe_mul(r->Z, r->X, q->yminusx);
213
+ fe_mul(r->Y, r->Y, q->yplusx);
214
+ fe_mul(r->T, q->xy2d, p->T);
215
+ fe_add(t0, p->Z, p->Z);
216
+ fe_sub(r->X, r->Z, r->Y);
217
+ fe_add(r->Y, r->Z, r->Y);
218
+ fe_sub(r->Z, t0, r->T);
219
+ fe_add(r->T, t0, r->T);
220
+ }
221
+
222
+
223
+ /*
224
+ r = p
225
+ */
226
+
227
+ void ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p) {
228
+ fe_mul(r->X, p->X, p->T);
229
+ fe_mul(r->Y, p->Y, p->Z);
230
+ fe_mul(r->Z, p->Z, p->T);
231
+ }
232
+
233
+
234
+
235
+ /*
236
+ r = p
237
+ */
238
+
239
+ void ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p) {
240
+ fe_mul(r->X, p->X, p->T);
241
+ fe_mul(r->Y, p->Y, p->Z);
242
+ fe_mul(r->Z, p->Z, p->T);
243
+ fe_mul(r->T, p->X, p->Y);
244
+ }
245
+
246
+
247
+ void ge_p2_0(ge_p2 *h) {
248
+ fe_0(h->X);
249
+ fe_1(h->Y);
250
+ fe_1(h->Z);
251
+ }
252
+
253
+
254
+
255
+ /*
256
+ r = 2 * p
257
+ */
258
+
259
+ void ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p) {
260
+ fe t0;
261
+
262
+ fe_sq(r->X, p->X);
263
+ fe_sq(r->Z, p->Y);
264
+ fe_sq2(r->T, p->Z);
265
+ fe_add(r->Y, p->X, p->Y);
266
+ fe_sq(t0, r->Y);
267
+ fe_add(r->Y, r->Z, r->X);
268
+ fe_sub(r->Z, r->Z, r->X);
269
+ fe_sub(r->X, t0, r->Y);
270
+ fe_sub(r->T, r->T, r->Z);
271
+ }
272
+
273
+
274
+ void ge_p3_0(ge_p3 *h) {
275
+ fe_0(h->X);
276
+ fe_1(h->Y);
277
+ fe_1(h->Z);
278
+ fe_0(h->T);
279
+ }
280
+
281
+
282
+ /*
283
+ r = 2 * p
284
+ */
285
+
286
+ void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p) {
287
+ ge_p2 q;
288
+ ge_p3_to_p2(&q, p);
289
+ ge_p2_dbl(r, &q);
290
+ }
291
+
292
+
293
+
294
+ /*
295
+ r = p
296
+ */
297
+
298
+ static const fe d2 = {
299
+ -21827239, -5839606, -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199
300
+ };
301
+
302
+ void ge_p3_to_cached(ge_cached *r, const ge_p3 *p) {
303
+ fe_add(r->YplusX, p->Y, p->X);
304
+ fe_sub(r->YminusX, p->Y, p->X);
305
+ fe_copy(r->Z, p->Z);
306
+ fe_mul(r->T2d, p->T, d2);
307
+ }
308
+
309
+
310
+ /*
311
+ r = p
312
+ */
313
+
314
+ void ge_p3_to_p2(ge_p2 *r, const ge_p3 *p) {
315
+ fe_copy(r->X, p->X);
316
+ fe_copy(r->Y, p->Y);
317
+ fe_copy(r->Z, p->Z);
318
+ }
319
+
320
+
321
+ void ge_p3_tobytes(unsigned char *s, const ge_p3 *h) {
322
+ fe recip;
323
+ fe x;
324
+ fe y;
325
+ fe_invert(recip, h->Z);
326
+ fe_mul(x, h->X, recip);
327
+ fe_mul(y, h->Y, recip);
328
+ fe_tobytes(s, y);
329
+ s[31] ^= fe_isnegative(x) << 7;
330
+ }
331
+
332
+
333
+ static unsigned char equal(signed char b, signed char c) {
334
+ unsigned char ub = b;
335
+ unsigned char uc = c;
336
+ unsigned char x = ub ^ uc; /* 0: yes; 1..255: no */
337
+ uint64_t y = x; /* 0: yes; 1..255: no */
338
+ y -= 1; /* large: yes; 0..254: no */
339
+ y >>= 63; /* 1: yes; 0: no */
340
+ return (unsigned char) y;
341
+ }
342
+
343
+ static unsigned char negative(signed char b) {
344
+ uint64_t x = b; /* 18446744073709551361..18446744073709551615: yes; 0..255: no */
345
+ x >>= 63; /* 1: yes; 0: no */
346
+ return (unsigned char) x;
347
+ }
348
+
349
+ static void cmov(ge_precomp *t, ge_precomp *u, unsigned char b) {
350
+ fe_cmov(t->yplusx, u->yplusx, b);
351
+ fe_cmov(t->yminusx, u->yminusx, b);
352
+ fe_cmov(t->xy2d, u->xy2d, b);
353
+ }
354
+
355
+
356
+ static void select(ge_precomp *t, int pos, signed char b) {
357
+ ge_precomp minust;
358
+ unsigned char bnegative = negative(b);
359
+ unsigned char babs = b - (((-bnegative) & b) << 1);
360
+ fe_1(t->yplusx);
361
+ fe_1(t->yminusx);
362
+ fe_0(t->xy2d);
363
+ cmov(t, &base[pos][0], equal(babs, 1));
364
+ cmov(t, &base[pos][1], equal(babs, 2));
365
+ cmov(t, &base[pos][2], equal(babs, 3));
366
+ cmov(t, &base[pos][3], equal(babs, 4));
367
+ cmov(t, &base[pos][4], equal(babs, 5));
368
+ cmov(t, &base[pos][5], equal(babs, 6));
369
+ cmov(t, &base[pos][6], equal(babs, 7));
370
+ cmov(t, &base[pos][7], equal(babs, 8));
371
+ fe_copy(minust.yplusx, t->yminusx);
372
+ fe_copy(minust.yminusx, t->yplusx);
373
+ fe_neg(minust.xy2d, t->xy2d);
374
+ cmov(t, &minust, bnegative);
375
+ }
376
+
377
+ /*
378
+ h = a * B
379
+ where a = a[0]+256*a[1]+...+256^31 a[31]
380
+ B is the Ed25519 base point (x,4/5) with x positive.
381
+
382
+ Preconditions:
383
+ a[31] <= 127
384
+ */
385
+
386
+ void ge_scalarmult_base(ge_p3 *h, const unsigned char *a) {
387
+ signed char e[64];
388
+ signed char carry;
389
+ ge_p1p1 r;
390
+ ge_p2 s;
391
+ ge_precomp t;
392
+ int i;
393
+
394
+ for (i = 0; i < 32; ++i) {
395
+ e[2 * i + 0] = (a[i] >> 0) & 15;
396
+ e[2 * i + 1] = (a[i] >> 4) & 15;
397
+ }
398
+
399
+ /* each e[i] is between 0 and 15 */
400
+ /* e[63] is between 0 and 7 */
401
+ carry = 0;
402
+
403
+ for (i = 0; i < 63; ++i) {
404
+ e[i] += carry;
405
+ carry = e[i] + 8;
406
+ carry >>= 4;
407
+ e[i] -= carry << 4;
408
+ }
409
+
410
+ e[63] += carry;
411
+ /* each e[i] is between -8 and 8 */
412
+ ge_p3_0(h);
413
+
414
+ for (i = 1; i < 64; i += 2) {
415
+ select(&t, i / 2, e[i]);
416
+ ge_madd(&r, h, &t);
417
+ ge_p1p1_to_p3(h, &r);
418
+ }
419
+
420
+ ge_p3_dbl(&r, h);
421
+ ge_p1p1_to_p2(&s, &r);
422
+ ge_p2_dbl(&r, &s);
423
+ ge_p1p1_to_p2(&s, &r);
424
+ ge_p2_dbl(&r, &s);
425
+ ge_p1p1_to_p2(&s, &r);
426
+ ge_p2_dbl(&r, &s);
427
+ ge_p1p1_to_p3(h, &r);
428
+
429
+ for (i = 0; i < 64; i += 2) {
430
+ select(&t, i / 2, e[i]);
431
+ ge_madd(&r, h, &t);
432
+ ge_p1p1_to_p3(h, &r);
433
+ }
434
+ }
435
+
436
+
437
+ /*
438
+ r = p - q
439
+ */
440
+
441
+ void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
442
+ fe t0;
443
+
444
+ fe_add(r->X, p->Y, p->X);
445
+ fe_sub(r->Y, p->Y, p->X);
446
+ fe_mul(r->Z, r->X, q->YminusX);
447
+ fe_mul(r->Y, r->Y, q->YplusX);
448
+ fe_mul(r->T, q->T2d, p->T);
449
+ fe_mul(r->X, p->Z, q->Z);
450
+ fe_add(t0, r->X, r->X);
451
+ fe_sub(r->X, r->Z, r->Y);
452
+ fe_add(r->Y, r->Z, r->Y);
453
+ fe_sub(r->Z, t0, r->T);
454
+ fe_add(r->T, t0, r->T);
455
+ }
456
+
457
+
458
+ void ge_tobytes(unsigned char *s, const ge_p2 *h) {
459
+ fe recip;
460
+ fe x;
461
+ fe y;
462
+ fe_invert(recip, h->Z);
463
+ fe_mul(x, h->X, recip);
464
+ fe_mul(y, h->Y, recip);
465
+ fe_tobytes(s, y);
466
+ s[31] ^= fe_isnegative(x) << 7;
467
+ }
@@ -0,0 +1,74 @@
1
+ #ifndef GE_H
2
+ #define GE_H
3
+
4
+ #include "fe.h"
5
+
6
+
7
+ /*
8
+ ge means group element.
9
+
10
+ Here the group is the set of pairs (x,y) of field elements (see fe.h)
11
+ satisfying -x^2 + y^2 = 1 + d x^2y^2
12
+ where d = -121665/121666.
13
+
14
+ Representations:
15
+ ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
16
+ ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
17
+ ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
18
+ ge_precomp (Duif): (y+x,y-x,2dxy)
19
+ */
20
+
21
+ typedef struct {
22
+ fe X;
23
+ fe Y;
24
+ fe Z;
25
+ } ge_p2;
26
+
27
+ typedef struct {
28
+ fe X;
29
+ fe Y;
30
+ fe Z;
31
+ fe T;
32
+ } ge_p3;
33
+
34
+ typedef struct {
35
+ fe X;
36
+ fe Y;
37
+ fe Z;
38
+ fe T;
39
+ } ge_p1p1;
40
+
41
+ typedef struct {
42
+ fe yplusx;
43
+ fe yminusx;
44
+ fe xy2d;
45
+ } ge_precomp;
46
+
47
+ typedef struct {
48
+ fe YplusX;
49
+ fe YminusX;
50
+ fe Z;
51
+ fe T2d;
52
+ } ge_cached;
53
+
54
+ void ge_p3_tobytes(unsigned char *s, const ge_p3 *h);
55
+ void ge_tobytes(unsigned char *s, const ge_p2 *h);
56
+ int ge_frombytes_negate_vartime(ge_p3 *h, const unsigned char *s);
57
+
58
+ void ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
59
+ void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
60
+ void ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 *A, const unsigned char *b);
61
+ void ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q);
62
+ void ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q);
63
+ void ge_scalarmult_base(ge_p3 *h, const unsigned char *a);
64
+
65
+ void ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p);
66
+ void ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p);
67
+ void ge_p2_0(ge_p2 *h);
68
+ void ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p);
69
+ void ge_p3_0(ge_p3 *h);
70
+ void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p);
71
+ void ge_p3_to_cached(ge_cached *r, const ge_p3 *p);
72
+ void ge_p3_to_p2(ge_p2 *r, const ge_p3 *p);
73
+
74
+ #endif