ruby_olm 0.1.1

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.
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,72 @@
1
+ /* Copyright 2015-2016 OpenMarket Ltd
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ #ifndef OLM_ERROR_H_
16
+ #define OLM_ERROR_H_
17
+
18
+ #ifdef __cplusplus
19
+ extern "C" {
20
+ #endif
21
+
22
+ enum OlmErrorCode {
23
+ OLM_SUCCESS = 0, /*!< There wasn't an error */
24
+ OLM_NOT_ENOUGH_RANDOM = 1, /*!< Not enough entropy was supplied */
25
+ OLM_OUTPUT_BUFFER_TOO_SMALL = 2, /*!< Supplied output buffer is too small */
26
+ OLM_BAD_MESSAGE_VERSION = 3, /*!< The message version is unsupported */
27
+ OLM_BAD_MESSAGE_FORMAT = 4, /*!< The message couldn't be decoded */
28
+ OLM_BAD_MESSAGE_MAC = 5, /*!< The message couldn't be decrypted */
29
+ OLM_BAD_MESSAGE_KEY_ID = 6, /*!< The message references an unknown key id */
30
+ OLM_INVALID_BASE64 = 7, /*!< The input base64 was invalid */
31
+ OLM_BAD_ACCOUNT_KEY = 8, /*!< The supplied account key is invalid */
32
+ OLM_UNKNOWN_PICKLE_VERSION = 9, /*!< The pickled object is too new */
33
+ OLM_CORRUPTED_PICKLE = 10, /*!< The pickled object couldn't be decoded */
34
+
35
+ OLM_BAD_SESSION_KEY = 11, /*!< Attempt to initialise an inbound group
36
+ session from an invalid session key */
37
+ OLM_UNKNOWN_MESSAGE_INDEX = 12, /*!< Attempt to decode a message whose
38
+ * index is earlier than our earliest
39
+ * known session key.
40
+ */
41
+
42
+ /**
43
+ * Attempt to unpickle an account which uses pickle version 1 (which did
44
+ * not save enough space for the Ed25519 key; the key should be considered
45
+ * compromised. We don't let the user reload the account.
46
+ */
47
+ OLM_BAD_LEGACY_ACCOUNT_PICKLE = 13,
48
+
49
+ /**
50
+ * Received message had a bad signature
51
+ */
52
+ OLM_BAD_SIGNATURE = 14,
53
+
54
+ OLM_INPUT_BUFFER_TOO_SMALL = 15,
55
+
56
+ // Not an error code, just here to pad out the enum past 16 because
57
+ // otherwise the compiler warns about a redunant check. If you're
58
+ // adding an error code, replace this one!
59
+ OLM_ERROR_NOT_INVENTED_YET = 16,
60
+
61
+ /* remember to update the list of string constants in error.c when updating
62
+ * this list. */
63
+ };
64
+
65
+ /** get a string representation of the given error code. */
66
+ const char * _olm_error_to_string(enum OlmErrorCode error);
67
+
68
+ #ifdef __cplusplus
69
+ } // extern "C"
70
+ #endif
71
+
72
+ #endif /* OLM_ERROR_H_ */
@@ -0,0 +1,235 @@
1
+ /* Copyright 2016 OpenMarket Ltd
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ #ifndef OLM_INBOUND_GROUP_SESSION_H_
16
+ #define OLM_INBOUND_GROUP_SESSION_H_
17
+
18
+ #include <stddef.h>
19
+ #include <stdint.h>
20
+
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif
24
+
25
+ typedef struct OlmInboundGroupSession OlmInboundGroupSession;
26
+
27
+ /** get the size of an inbound group session, in bytes. */
28
+ size_t olm_inbound_group_session_size(void);
29
+
30
+ /**
31
+ * Initialise an inbound group session object using the supplied memory
32
+ * The supplied memory should be at least olm_inbound_group_session_size()
33
+ * bytes.
34
+ */
35
+ OlmInboundGroupSession * olm_inbound_group_session(
36
+ void *memory
37
+ );
38
+
39
+ /**
40
+ * A null terminated string describing the most recent error to happen to a
41
+ * group session */
42
+ const char *olm_inbound_group_session_last_error(
43
+ const OlmInboundGroupSession *session
44
+ );
45
+
46
+ /** Clears the memory used to back this group session */
47
+ size_t olm_clear_inbound_group_session(
48
+ OlmInboundGroupSession *session
49
+ );
50
+
51
+ /** Returns the number of bytes needed to store an inbound group session */
52
+ size_t olm_pickle_inbound_group_session_length(
53
+ const OlmInboundGroupSession *session
54
+ );
55
+
56
+ /**
57
+ * Stores a group session as a base64 string. Encrypts the session using the
58
+ * supplied key. Returns the length of the session on success.
59
+ *
60
+ * Returns olm_error() on failure. If the pickle output buffer
61
+ * is smaller than olm_pickle_inbound_group_session_length() then
62
+ * olm_inbound_group_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL"
63
+ */
64
+ size_t olm_pickle_inbound_group_session(
65
+ OlmInboundGroupSession *session,
66
+ void const * key, size_t key_length,
67
+ void * pickled, size_t pickled_length
68
+ );
69
+
70
+ /**
71
+ * Loads a group session from a pickled base64 string. Decrypts the session
72
+ * using the supplied key.
73
+ *
74
+ * Returns olm_error() on failure. If the key doesn't match the one used to
75
+ * encrypt the account then olm_inbound_group_session_last_error() will be
76
+ * "BAD_ACCOUNT_KEY". If the base64 couldn't be decoded then
77
+ * olm_inbound_group_session_last_error() will be "INVALID_BASE64". The input
78
+ * pickled buffer is destroyed
79
+ */
80
+ size_t olm_unpickle_inbound_group_session(
81
+ OlmInboundGroupSession *session,
82
+ void const * key, size_t key_length,
83
+ void * pickled, size_t pickled_length
84
+ );
85
+
86
+
87
+ /**
88
+ * Start a new inbound group session, from a key exported from
89
+ * olm_outbound_group_session_key
90
+ *
91
+ * Returns olm_error() on failure. On failure last_error will be set with an
92
+ * error code. The last_error will be:
93
+ *
94
+ * * OLM_INVALID_BASE64 if the session_key is not valid base64
95
+ * * OLM_BAD_SESSION_KEY if the session_key is invalid
96
+ */
97
+ size_t olm_init_inbound_group_session(
98
+ OlmInboundGroupSession *session,
99
+ /* base64-encoded keys */
100
+ uint8_t const * session_key, size_t session_key_length
101
+ );
102
+
103
+ /**
104
+ * Import an inbound group session, from a previous export.
105
+ *
106
+ * Returns olm_error() on failure. On failure last_error will be set with an
107
+ * error code. The last_error will be:
108
+ *
109
+ * * OLM_INVALID_BASE64 if the session_key is not valid base64
110
+ * * OLM_BAD_SESSION_KEY if the session_key is invalid
111
+ */
112
+ size_t olm_import_inbound_group_session(
113
+ OlmInboundGroupSession *session,
114
+ /* base64-encoded keys; note that it will be overwritten with the base64-decoded
115
+ data. */
116
+ uint8_t const * session_key, size_t session_key_length
117
+ );
118
+
119
+
120
+ /**
121
+ * Get an upper bound on the number of bytes of plain-text the decrypt method
122
+ * will write for a given input message length. The actual size could be
123
+ * different due to padding.
124
+ *
125
+ * The input message buffer is destroyed.
126
+ *
127
+ * Returns olm_error() on failure.
128
+ */
129
+ size_t olm_group_decrypt_max_plaintext_length(
130
+ OlmInboundGroupSession *session,
131
+ uint8_t * message, size_t message_length
132
+ );
133
+
134
+ /**
135
+ * Decrypt a message.
136
+ *
137
+ * The input message buffer is destroyed.
138
+ *
139
+ * Returns the length of the decrypted plain-text, or olm_error() on failure.
140
+ *
141
+ * On failure last_error will be set with an error code. The last_error will
142
+ * be:
143
+ * * OLM_OUTPUT_BUFFER_TOO_SMALL if the plain-text buffer is too small
144
+ * * OLM_INVALID_BASE64 if the message is not valid base-64
145
+ * * OLM_BAD_MESSAGE_VERSION if the message was encrypted with an unsupported
146
+ * version of the protocol
147
+ * * OLM_BAD_MESSAGE_FORMAT if the message headers could not be decoded
148
+ * * OLM_BAD_MESSAGE_MAC if the message could not be verified
149
+ * * OLM_UNKNOWN_MESSAGE_INDEX if we do not have a session key corresponding to the
150
+ * message's index (ie, it was sent before the session key was shared with
151
+ * us)
152
+ */
153
+ size_t olm_group_decrypt(
154
+ OlmInboundGroupSession *session,
155
+
156
+ /* input; note that it will be overwritten with the base64-decoded
157
+ message. */
158
+ uint8_t * message, size_t message_length,
159
+
160
+ /* output */
161
+ uint8_t * plaintext, size_t max_plaintext_length,
162
+ uint32_t * message_index
163
+ );
164
+
165
+
166
+ /**
167
+ * Get the number of bytes returned by olm_inbound_group_session_id()
168
+ */
169
+ size_t olm_inbound_group_session_id_length(
170
+ const OlmInboundGroupSession *session
171
+ );
172
+
173
+ /**
174
+ * Get a base64-encoded identifier for this session.
175
+ *
176
+ * Returns the length of the session id on success or olm_error() on
177
+ * failure. On failure last_error will be set with an error code. The
178
+ * last_error will be OUTPUT_BUFFER_TOO_SMALL if the id buffer was too
179
+ * small.
180
+ */
181
+ size_t olm_inbound_group_session_id(
182
+ OlmInboundGroupSession *session,
183
+ uint8_t * id, size_t id_length
184
+ );
185
+
186
+ /**
187
+ * Get the first message index we know how to decrypt.
188
+ */
189
+ uint32_t olm_inbound_group_session_first_known_index(
190
+ const OlmInboundGroupSession *session
191
+ );
192
+
193
+
194
+ /**
195
+ * Check if the session has been verified as a valid session.
196
+ *
197
+ * (A session is verified either because the original session share was signed,
198
+ * or because we have subsequently successfully decrypted a message.)
199
+ *
200
+ * This is mainly intended for the unit tests, currently.
201
+ */
202
+ int olm_inbound_group_session_is_verified(
203
+ const OlmInboundGroupSession *session
204
+ );
205
+
206
+ /**
207
+ * Get the number of bytes returned by olm_export_inbound_group_session()
208
+ */
209
+ size_t olm_export_inbound_group_session_length(
210
+ const OlmInboundGroupSession *session
211
+ );
212
+
213
+ /**
214
+ * Export the base64-encoded ratchet key for this session, at the given index,
215
+ * in a format which can be used by olm_import_inbound_group_session
216
+ *
217
+ * Returns the length of the ratchet key on success or olm_error() on
218
+ * failure. On failure last_error will be set with an error code. The
219
+ * last_error will be:
220
+ * * OUTPUT_BUFFER_TOO_SMALL if the buffer was too small
221
+ * * OLM_UNKNOWN_MESSAGE_INDEX if we do not have a session key corresponding to the
222
+ * given index (ie, it was sent before the session key was shared with
223
+ * us)
224
+ */
225
+ size_t olm_export_inbound_group_session(
226
+ OlmInboundGroupSession *session,
227
+ uint8_t * key, size_t key_length, uint32_t message_index
228
+ );
229
+
230
+
231
+ #ifdef __cplusplus
232
+ } // extern "C"
233
+ #endif
234
+
235
+ #endif /* OLM_INBOUND_GROUP_SESSION_H_ */
@@ -0,0 +1,119 @@
1
+ /* Copyright 2015 OpenMarket Ltd
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ #ifndef OLM_LIST_HH_
16
+ #define OLM_LIST_HH_
17
+
18
+ #include <cstddef>
19
+
20
+ namespace olm {
21
+
22
+ template<typename T, std::size_t max_size>
23
+ class List {
24
+ public:
25
+ List() : _end(_data) {}
26
+
27
+ typedef T * iterator;
28
+ typedef T const * const_iterator;
29
+
30
+ T * begin() { return _data; }
31
+ T * end() { return _end; }
32
+ T const * begin() const { return _data; }
33
+ T const * end() const { return _end; }
34
+
35
+ /**
36
+ * Is the list empty?
37
+ */
38
+ bool empty() const { return _end == _data; }
39
+
40
+ /**
41
+ * The number of items in the list.
42
+ */
43
+ std::size_t size() const { return _end - _data; }
44
+
45
+ T & operator[](std::size_t index) { return _data[index]; }
46
+
47
+ T const & operator[](std::size_t index) const { return _data[index]; }
48
+
49
+ /**
50
+ * Erase the item from the list at the given position.
51
+ */
52
+ void erase(T * pos) {
53
+ --_end;
54
+ while (pos != _end) {
55
+ *pos = *(pos + 1);
56
+ ++pos;
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Make space for an item in the list at a given position.
62
+ * If inserting the item makes the list longer than max_size then
63
+ * the end of the list is discarded.
64
+ * Returns the where the item is inserted.
65
+ */
66
+ T * insert(T * pos) {
67
+ if (_end != _data + max_size) {
68
+ ++_end;
69
+ } else if (pos == _end) {
70
+ --pos;
71
+ }
72
+ T * tmp = _end - 1;
73
+ while (tmp != pos) {
74
+ *tmp = *(tmp - 1);
75
+ --tmp;
76
+ }
77
+ return pos;
78
+ }
79
+
80
+ /**
81
+ * Make space for an item in the list at the start of the list
82
+ */
83
+ T * insert() { return insert(begin()); }
84
+
85
+ /**
86
+ * Insert an item into the list at a given position.
87
+ * If inserting the item makes the list longer than max_size then
88
+ * the end of the list is discarded.
89
+ * Returns the where the item is inserted.
90
+ */
91
+ T * insert(T * pos, T const & value) {
92
+ pos = insert(pos);
93
+ *pos = value;
94
+ return pos;
95
+ }
96
+
97
+ List<T, max_size> & operator=(List<T, max_size> const & other) {
98
+ if (this == &other) {
99
+ return *this;
100
+ }
101
+ T * this_pos = _data;
102
+ T * const other_pos = other._data;
103
+ while (other_pos != other._end) {
104
+ *this_pos = *other;
105
+ ++this_pos;
106
+ ++other_pos;
107
+ }
108
+ _end = this_pos;
109
+ return *this;
110
+ }
111
+
112
+ private:
113
+ T * _end;
114
+ T _data[max_size];
115
+ };
116
+
117
+ } // namespace olm
118
+
119
+ #endif /* OLM_LIST_HH_ */
@@ -0,0 +1,95 @@
1
+ /* Copyright 2016 OpenMarket Ltd
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ #ifndef OLM_MEGOLM_H_
17
+ #define OLM_MEGOLM_H_
18
+
19
+ /**
20
+ * implementation of the Megolm multi-part ratchet used in group chats.
21
+ */
22
+
23
+ #include <stdint.h>
24
+ #include <stdlib.h>
25
+
26
+ #ifdef __cplusplus
27
+ extern "C" {
28
+ #endif
29
+
30
+ /**
31
+ * number of bytes in each part of the ratchet; this should be the same as
32
+ * the length of the hash function used in the HMAC (32 bytes for us, as we
33
+ * use HMAC-SHA-256)
34
+ */
35
+ #define MEGOLM_RATCHET_PART_LENGTH 32 /* SHA256_OUTPUT_LENGTH */
36
+
37
+ /**
38
+ * number of parts in the ratchet; the advance() implementations rely on
39
+ * this being 4.
40
+ */
41
+ #define MEGOLM_RATCHET_PARTS 4
42
+
43
+ #define MEGOLM_RATCHET_LENGTH (MEGOLM_RATCHET_PARTS * MEGOLM_RATCHET_PART_LENGTH)
44
+
45
+ typedef struct Megolm {
46
+ uint8_t data[MEGOLM_RATCHET_PARTS][MEGOLM_RATCHET_PART_LENGTH];
47
+ uint32_t counter;
48
+ } Megolm;
49
+
50
+
51
+ /**
52
+ * The cipher used in megolm-backed conversations
53
+ *
54
+ * (AES256 + SHA256, with keys based on an HKDF with info of MEGOLM_KEYS)
55
+ */
56
+ extern const struct _olm_cipher *megolm_cipher;
57
+
58
+ /**
59
+ * initialize the megolm ratchet. random_data should be at least
60
+ * MEGOLM_RATCHET_LENGTH bytes of randomness.
61
+ */
62
+ void megolm_init(Megolm *megolm, uint8_t const *random_data, uint32_t counter);
63
+
64
+ /** Returns the number of bytes needed to store a megolm */
65
+ size_t megolm_pickle_length(const Megolm *megolm);
66
+
67
+ /**
68
+ * Pickle the megolm. Returns a pointer to the next free space in the buffer.
69
+ */
70
+ uint8_t * megolm_pickle(const Megolm *megolm, uint8_t *pos);
71
+
72
+ /**
73
+ * Unpickle the megolm. Returns a pointer to the next item in the buffer.
74
+ */
75
+ const uint8_t * megolm_unpickle(Megolm *megolm, const uint8_t *pos,
76
+ const uint8_t *end);
77
+
78
+
79
+ /** advance the ratchet by one step */
80
+ void megolm_advance(Megolm *megolm);
81
+
82
+ /**
83
+ * get the key data in the ratchet. The returned data is
84
+ * MEGOLM_RATCHET_LENGTH bytes long.
85
+ */
86
+ #define megolm_get_data(megolm) ((const uint8_t *)((megolm)->data))
87
+
88
+ /** advance the ratchet to a given count */
89
+ void megolm_advance_to(Megolm *megolm, uint32_t advance_to);
90
+
91
+ #ifdef __cplusplus
92
+ } // extern "C"
93
+ #endif
94
+
95
+ #endif /* OLM_MEGOLM_H_ */
@@ -0,0 +1,41 @@
1
+ /* Copyright 2015, 2016 OpenMarket Ltd
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ /* C bindings for memory functions */
17
+
18
+
19
+ #ifndef OLM_MEMORY_H_
20
+ #define OLM_MEMORY_H_
21
+
22
+ #include <stddef.h>
23
+
24
+ #ifdef __cplusplus
25
+ extern "C" {
26
+ #endif
27
+
28
+ /**
29
+ * Clear the memory held in the buffer. This is more resilient to being
30
+ * optimised away than memset or bzero.
31
+ */
32
+ void _olm_unset(
33
+ void volatile * buffer, size_t buffer_length
34
+ );
35
+
36
+ #ifdef __cplusplus
37
+ } // extern "C"
38
+ #endif
39
+
40
+
41
+ #endif /* OLM_MEMORY_H_ */
@@ -0,0 +1,90 @@
1
+ /* Copyright 2015, 2016 OpenMarket Ltd
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ #include <cstddef>
16
+ #include <cstdint>
17
+ #include <cstring>
18
+ #include <iomanip>
19
+ #include <iostream>
20
+ #include <sstream>
21
+ #include <type_traits>
22
+
23
+ namespace olm {
24
+
25
+ /** Clear the memory held in the buffer */
26
+ void unset(
27
+ void volatile * buffer, std::size_t buffer_length
28
+ );
29
+
30
+ /** Clear the memory backing an object */
31
+ template<typename T>
32
+ void unset(T & value) {
33
+ unset(reinterpret_cast<void volatile *>(&value), sizeof(T));
34
+ }
35
+
36
+ /** Check if two buffers are equal in constant time. */
37
+ bool is_equal(
38
+ std::uint8_t const * buffer_a,
39
+ std::uint8_t const * buffer_b,
40
+ std::size_t length
41
+ );
42
+
43
+ /** Check if two fixed size arrays are equals */
44
+ template<typename T>
45
+ bool array_equal(
46
+ T const & array_a,
47
+ T const & array_b
48
+ ) {
49
+ static_assert(
50
+ std::is_array<T>::value
51
+ && std::is_convertible<T, std::uint8_t *>::value
52
+ && sizeof(T) > 0,
53
+ "Arguments to array_equal must be std::uint8_t arrays[]."
54
+ );
55
+ return is_equal(array_a, array_b, sizeof(T));
56
+ }
57
+
58
+ /** Copy into a fixed size array */
59
+ template<typename T>
60
+ std::uint8_t const * load_array(
61
+ T & destination,
62
+ std::uint8_t const * source
63
+ ) {
64
+ static_assert(
65
+ std::is_array<T>::value
66
+ && std::is_convertible<T, std::uint8_t *>::value
67
+ && sizeof(T) > 0,
68
+ "The first argument to load_array must be a std::uint8_t array[]."
69
+ );
70
+ std::memcpy(destination, source, sizeof(T));
71
+ return source + sizeof(T);
72
+ }
73
+
74
+ /** Copy from a fixed size array */
75
+ template<typename T>
76
+ std::uint8_t * store_array(
77
+ std::uint8_t * destination,
78
+ T const & source
79
+ ) {
80
+ static_assert(
81
+ std::is_array<T>::value
82
+ && std::is_convertible<T, std::uint8_t *>::value
83
+ && sizeof(T) > 0,
84
+ "The second argument to store_array must be a std::uint8_t array[]."
85
+ );
86
+ std::memcpy(destination, source, sizeof(T));
87
+ return destination + sizeof(T);
88
+ }
89
+
90
+ } // namespace olm