virgil-crypto 2.3.0 → 3.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -0
  3. data/.gitmodules +0 -0
  4. data/.travis.yml +13 -0
  5. data/Gemfile +0 -0
  6. data/README.md +113 -9
  7. data/Rakefile +0 -0
  8. data/ext/native/src/.clang-format +37 -0
  9. data/ext/native/src/.gitignore +3 -0
  10. data/ext/native/src/.travis.yml +2 -1
  11. data/ext/native/src/CMakeLists.txt +66 -63
  12. data/ext/native/src/ChangeLog +114 -2
  13. data/ext/native/src/Dockerfile_Golang +29 -8
  14. data/ext/native/src/Jenkinsfile +61 -50
  15. data/ext/native/src/LICENSE +0 -0
  16. data/ext/native/src/README.md +137 -167
  17. data/ext/native/src/VERSION +1 -1
  18. data/ext/native/src/benchmark.md +140 -0
  19. data/ext/native/src/benchmark/CMakeLists.txt +0 -0
  20. data/ext/native/src/benchmark/benchmark_cipher.cxx +0 -0
  21. data/ext/native/src/benchmark/benchmark_hash.cxx +0 -0
  22. data/ext/native/src/benchmark/benchmark_keys.cxx +0 -0
  23. data/ext/native/src/benchmark/benchmark_pythia.cxx +61 -0
  24. data/ext/native/src/benchmark/benchmark_random.cxx +0 -0
  25. data/ext/native/src/benchmark/benchmark_signer.cxx +0 -0
  26. data/ext/native/src/ci/install-dependencies.sh +8 -12
  27. data/ext/native/src/ci/publish-docs.sh +107 -22
  28. data/ext/native/src/ci/travis-deployment-key.enc +0 -0
  29. data/ext/native/src/cmake/TransitiveArgs.cmake +78 -0
  30. data/ext/native/src/cmake/TransitiveToolchainArgs.cmake +105 -0
  31. data/ext/native/src/cmake/add_mono_metadata.cmake +103 -0
  32. data/ext/native/src/cmake/apple.cmake +56 -11
  33. data/ext/native/src/cmake/aux_source_directory_to_file.cmake +0 -0
  34. data/ext/native/src/cmake/check_pointer_size.cmake +0 -0
  35. data/ext/native/src/cmake/copy_all_files.cmake +0 -0
  36. data/ext/native/src/cmake/file_regex_replace.cmake +0 -0
  37. data/ext/native/src/cmake/find_host_utils.cmake +0 -0
  38. data/ext/native/src/cmake/uppercase_first_char.cmake +0 -0
  39. data/ext/native/src/cmake/uppercase_namespaces.cmake +3 -0
  40. data/ext/native/src/cmake/virgil_depends.cmake +0 -0
  41. data/ext/native/src/cmake/virgil_depends_local.cmake +2 -0
  42. data/ext/native/src/docs/.gitignore +0 -0
  43. data/ext/native/src/lib/CMakeLists.txt +59 -1
  44. data/ext/native/src/lib/Doxyfile.in +1 -1
  45. data/ext/native/src/lib/Info.plist.in +0 -0
  46. data/ext/native/src/lib/cmake/config.cmake.in +0 -0
  47. data/ext/native/src/lib/include/virgil/crypto/VirgilByteArrayUtils.h +0 -0
  48. data/ext/native/src/lib/include/virgil/crypto/VirgilChunkCipher.h +0 -0
  49. data/ext/native/src/lib/include/virgil/crypto/VirgilCipherBase.h +0 -0
  50. data/ext/native/src/lib/include/virgil/crypto/VirgilContentInfo.h +0 -0
  51. data/ext/native/src/lib/include/virgil/crypto/VirgilCrypto.h +13 -0
  52. data/ext/native/src/lib/include/virgil/crypto/VirgilCryptoError.h +0 -0
  53. data/ext/native/src/lib/include/virgil/crypto/VirgilCustomParams.h +0 -0
  54. data/ext/native/src/lib/include/virgil/crypto/VirgilKeyPair.h +30 -0
  55. data/ext/native/src/lib/include/virgil/crypto/VirgilSignerBase.h +0 -0
  56. data/ext/native/src/lib/include/virgil/crypto/VirgilStreamCipher.h +0 -0
  57. data/ext/native/src/lib/include/virgil/crypto/VirgilStreamSigner.h +0 -0
  58. data/ext/native/src/lib/include/virgil/crypto/VirgilTinyCipher.h +0 -0
  59. data/ext/native/src/lib/include/virgil/crypto/VirgilVersion.h +0 -0
  60. data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilAsymmetricCipher.h +17 -0
  61. data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilHKDF.h +0 -0
  62. data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilPBKDF.h +0 -0
  63. data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilSystemCryptoError.h +0 -0
  64. data/ext/native/src/lib/include/virgil/crypto/foundation/asn1/VirgilAsn1Compatible.h +0 -0
  65. data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSContent.h +0 -0
  66. data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSContentInfo.h +0 -0
  67. data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSEncryptedContent.h +0 -0
  68. data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSEnvelopedData.h +0 -0
  69. data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSKeyTransRecipient.h +0 -0
  70. data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSPasswordRecipient.h +0 -0
  71. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFS.h +0 -0
  72. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSEncryptedMessage.h +0 -0
  73. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSInitiatorPrivateInfo.h +0 -0
  74. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSInitiatorPublicInfo.h +0 -0
  75. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSPrivateKey.h +0 -0
  76. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSPublicKey.h +0 -0
  77. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSResponderPrivateInfo.h +0 -0
  78. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSResponderPublicInfo.h +0 -0
  79. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSSession.h +0 -0
  80. data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationCipher.h +0 -0
  81. data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationDH.h +0 -0
  82. data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationHash.h +0 -0
  83. data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationKDF.h +0 -0
  84. data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationRandom.h +0 -0
  85. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythia.h +181 -0
  86. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaBlindResult.h +89 -0
  87. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaContext.h +72 -0
  88. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaError.h +161 -0
  89. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaProveResult.h +89 -0
  90. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaTransformResult.h +91 -0
  91. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaTransformationKeyPair.h +87 -0
  92. data/ext/native/src/lib/include/virgil/crypto/pythia/virgil_pythia_c.h +203 -0
  93. data/ext/native/src/lib/include/virgil/crypto/stream/VirgilBytesDataSink.h +0 -0
  94. data/ext/native/src/lib/include/virgil/crypto/stream/VirgilBytesDataSource.h +0 -0
  95. data/ext/native/src/lib/mainpage.dox +6 -0
  96. data/ext/native/src/lib/module.modulemap +7 -0
  97. data/ext/native/src/lib/src/VirgilAsn1Alg.cxx +0 -0
  98. data/ext/native/src/lib/src/VirgilAsn1Alg.h +0 -0
  99. data/ext/native/src/lib/src/VirgilAsn1Compatible.cxx +0 -0
  100. data/ext/native/src/lib/src/VirgilAsymmetricCipher.cxx +82 -0
  101. data/ext/native/src/lib/src/VirgilByteArrayUtils.cxx +0 -0
  102. data/ext/native/src/lib/src/VirgilCMSContent.cxx +0 -0
  103. data/ext/native/src/lib/src/VirgilCMSContentInfo.cxx +0 -0
  104. data/ext/native/src/lib/src/VirgilCMSEncryptedContent.cxx +0 -0
  105. data/ext/native/src/lib/src/VirgilCMSEnvelopedData.cxx +0 -0
  106. data/ext/native/src/lib/src/VirgilCMSKeyTransRecipient.cxx +0 -0
  107. data/ext/native/src/lib/src/VirgilCMSPasswordRecipient.cxx +0 -0
  108. data/ext/native/src/lib/src/VirgilChunkCipher.cxx +0 -0
  109. data/ext/native/src/lib/src/VirgilCipherBase.cxx +0 -0
  110. data/ext/native/src/lib/src/VirgilConfig.cxx +51 -0
  111. data/ext/native/src/lib/src/VirgilConfig.h.in +43 -1
  112. data/ext/native/src/lib/src/VirgilContentInfo.cxx +0 -0
  113. data/ext/native/src/lib/src/VirgilCryptoError.cxx +0 -0
  114. data/ext/native/src/lib/src/VirgilCustomParams.cxx +0 -0
  115. data/ext/native/src/lib/src/VirgilDataSink.cxx +0 -0
  116. data/ext/native/src/lib/src/VirgilHKDF.cxx +0 -0
  117. data/ext/native/src/lib/src/VirgilKeyPair.cxx +19 -0
  118. data/ext/native/src/lib/src/VirgilOID.h +0 -0
  119. data/ext/native/src/lib/src/VirgilPBKDF.cxx +0 -0
  120. data/ext/native/src/lib/src/VirgilSignerBase.cxx +0 -0
  121. data/ext/native/src/lib/src/VirgilStreamCipher.cxx +0 -0
  122. data/ext/native/src/lib/src/VirgilStreamSigner.cxx +0 -0
  123. data/ext/native/src/lib/src/VirgilSystemCryptoError.cxx +0 -0
  124. data/ext/native/src/lib/src/VirgilTagFilter.cxx +0 -0
  125. data/ext/native/src/lib/src/VirgilTagFilter.h +0 -0
  126. data/ext/native/src/lib/src/VirgilTinyCipher.cxx +0 -0
  127. data/ext/native/src/lib/src/VirgilVersion.cxx.in +0 -0
  128. data/ext/native/src/lib/src/mbedtls_context.h +0 -0
  129. data/ext/native/src/lib/src/mbedtls_context_policy_spec.h +0 -0
  130. data/ext/native/src/lib/src/mbedtls_type_utils.h +0 -0
  131. data/ext/native/src/lib/src/pfs/VirgilPFS.cxx +0 -0
  132. data/ext/native/src/lib/src/pfs/VirgilPFSEncryptedMessage.cxx +0 -0
  133. data/ext/native/src/lib/src/pfs/VirgilPFSInitiatorPrivateInfo.cxx +0 -0
  134. data/ext/native/src/lib/src/pfs/VirgilPFSInitiatorPublicInfo.cxx +0 -0
  135. data/ext/native/src/lib/src/pfs/VirgilPFSPrivateKey.cxx +0 -0
  136. data/ext/native/src/lib/src/pfs/VirgilPFSPublicKey.cxx +0 -0
  137. data/ext/native/src/lib/src/pfs/VirgilPFSResponderPrivateInfo.cxx +0 -0
  138. data/ext/native/src/lib/src/pfs/VirgilPFSResponderPublicInfo.cxx +0 -0
  139. data/ext/native/src/lib/src/pfs/VirgilPFSSession.cxx +0 -0
  140. data/ext/native/src/lib/src/primitive/VirgilOperationCipher.cxx +0 -0
  141. data/ext/native/src/lib/src/primitive/VirgilOperationDH.cxx +0 -0
  142. data/ext/native/src/lib/src/primitive/VirgilOperationHash.cxx +0 -0
  143. data/ext/native/src/lib/src/primitive/VirgilOperationKDF.cxx +0 -0
  144. data/ext/native/src/lib/src/primitive/VirgilOperationRandom.cxx +0 -0
  145. data/ext/native/src/lib/src/pythia/VirgilPythia.cxx +202 -0
  146. data/ext/native/src/lib/src/pythia/VirgilPythiaContext.cxx +116 -0
  147. data/ext/native/src/lib/src/pythia/VirgilPythiaError.cxx +58 -0
  148. data/ext/native/src/lib/src/pythia/virgil_pythia_c.cxx +129 -0
  149. data/ext/native/src/lib/src/stream/VirgilBytesDataSink.cxx +0 -0
  150. data/ext/native/src/lib/src/stream/VirgilBytesDataSource.cxx +0 -0
  151. data/ext/native/src/lib/src/utils.h +3 -2
  152. data/ext/native/src/libs_ext/mbedtls/configs/config.h +0 -0
  153. data/ext/native/src/libs_ext/mbedtls/configs/config_desktop.h +0 -0
  154. data/ext/native/src/libs_ext/mbedtls/mbedtls.cmake +0 -0
  155. data/ext/native/src/{cmake/cmake_args.cmake → libs_ext/pythia/pythia.cmake} +24 -28
  156. data/ext/native/src/libs_ext/rapidjson/rapidjson.cmake +0 -0
  157. data/ext/native/src/libs_ext/tinyformat/cmake/config.cmake.in +0 -0
  158. data/ext/native/src/libs_ext/tinyformat/tinyformat.cmake +0 -0
  159. data/ext/native/src/migration-2.0.md +0 -0
  160. data/ext/native/src/tests/CMakeLists.txt +0 -0
  161. data/ext/native/src/tests/catch.hpp +0 -0
  162. data/ext/native/src/tests/data/test_data_pfs_with_otc.json +0 -0
  163. data/ext/native/src/tests/data/test_data_pfs_without_otc.json +0 -0
  164. data/ext/native/src/tests/deterministic_keys.h +293 -0
  165. data/ext/native/src/tests/rsa_keys.h +229 -123
  166. data/ext/native/src/tests/test_asn1_writer.cxx +0 -0
  167. data/ext/native/src/tests/test_asymmetric_cipher.cxx +65 -0
  168. data/ext/native/src/tests/test_base64.cxx +0 -0
  169. data/ext/native/src/tests/test_byte_array_utils.cxx +0 -0
  170. data/ext/native/src/tests/test_chunk_cipher.cxx +0 -0
  171. data/ext/native/src/tests/test_cipher.cxx +8 -4
  172. data/ext/native/src/tests/test_cipher_base.cxx +0 -0
  173. data/ext/native/src/tests/test_contract_copy_move.cxx +4 -1
  174. data/ext/native/src/tests/test_data_pfs.h +0 -0
  175. data/ext/native/src/tests/test_hash.cxx +0 -0
  176. data/ext/native/src/tests/test_hkdf.cxx +0 -0
  177. data/ext/native/src/tests/test_key_pair.cxx +65 -3
  178. data/ext/native/src/tests/test_pbe.cxx +0 -0
  179. data/ext/native/src/tests/test_pbkdf.cxx +0 -0
  180. data/ext/native/src/tests/test_pfs.cxx +0 -0
  181. data/ext/native/src/tests/test_pythia.cxx +157 -0
  182. data/ext/native/src/tests/test_random.cxx +0 -0
  183. data/ext/native/src/tests/test_runner.cxx +0 -0
  184. data/ext/native/src/tests/test_signer.cxx +0 -0
  185. data/ext/native/src/tests/test_stream_cipher.cxx +0 -0
  186. data/ext/native/src/tests/test_stream_data_source.cxx +0 -0
  187. data/ext/native/src/tests/test_symmetric_cipher.cxx +0 -0
  188. data/ext/native/src/tests/test_tag_filter.cxx +0 -0
  189. data/ext/native/src/tests/test_tiny_cipher.cxx +0 -0
  190. data/ext/native/src/utils/build.bat +0 -0
  191. data/ext/native/src/utils/build.sh +238 -68
  192. data/ext/native/src/utils/zip.vbs +0 -0
  193. data/ext/native/src/virgil-crypto.sublime-project +15 -0
  194. data/ext/native/src/wrappers/asmjs/CMakeLists.txt +0 -8
  195. data/ext/native/src/wrappers/emsdk/CMakeLists.txt +2 -2
  196. data/ext/native/src/wrappers/emsdk/error.js +0 -0
  197. data/ext/native/src/wrappers/emsdk/example.html +152 -31
  198. data/ext/native/src/wrappers/emsdk/helpers.js +140 -135
  199. data/ext/native/src/wrappers/emsdk/patch_embind.pl +0 -0
  200. data/ext/native/src/wrappers/emsdk/wrapper.cxx +55 -0
  201. data/ext/native/src/wrappers/go/CMakeLists.txt +6 -5
  202. data/ext/native/src/wrappers/java/CMakeLists.txt +27 -4
  203. data/ext/native/src/wrappers/java/src/JniLoader.java +167 -0
  204. data/ext/native/src/wrappers/java/src/VirgilStreamDataSink.java +0 -0
  205. data/ext/native/src/wrappers/java/src/VirgilStreamDataSource.java +0 -0
  206. data/ext/native/src/wrappers/net/CMakeLists.txt +41 -8
  207. data/ext/native/src/wrappers/net/cmake/UseCSharp.cmake +5 -5
  208. data/ext/native/src/wrappers/net/src/VirgilStreamDataSink.cs +0 -0
  209. data/ext/native/src/wrappers/net/src/VirgilStreamDataSource.cs +0 -0
  210. data/ext/native/src/wrappers/nodejs/checksum.txt +66 -0
  211. data/ext/native/src/wrappers/php/CMakeLists.txt +2 -5
  212. data/ext/native/src/wrappers/php/tests/CMakeLists.txt +6 -0
  213. data/ext/native/src/wrappers/php/tests/VirgilChunkCipher_Test.php.in +0 -0
  214. data/ext/native/src/wrappers/php/tests/VirgilCustomParams_Test.php.in +0 -0
  215. data/ext/native/src/wrappers/php/tests/VirgilKDF_Test.php.in +0 -0
  216. data/ext/native/src/wrappers/php/tests/VirgilPBE_Test.php.in +0 -0
  217. data/ext/native/src/wrappers/php/tests/VirgilPBKDF_Test.php.in +0 -0
  218. data/ext/native/src/wrappers/php/tests/VirgilPythia_Test.php.in +87 -0
  219. data/ext/native/src/wrappers/php/tests/VirgilStreamCipher_Test.php.in +0 -0
  220. data/ext/native/src/wrappers/php/tests/VirgilStreamSigner_Test.php.in +0 -0
  221. data/ext/native/src/wrappers/php/tests/VirgilVersion_Test.php.in +0 -0
  222. data/ext/native/src/wrappers/python/CMakeLists.txt +4 -1
  223. data/ext/native/src/wrappers/ruby/CMakeLists.txt +4 -1
  224. data/ext/native/src/wrappers/swig/common.i +0 -0
  225. data/ext/native/src/wrappers/swig/csharp/FixedArray.i +0 -0
  226. data/ext/native/src/wrappers/swig/csharp/VirgilByteArray.i +0 -0
  227. data/ext/native/src/wrappers/swig/csharp/common.i +0 -0
  228. data/ext/native/src/wrappers/swig/csharp/csharphead.swg.in +0 -0
  229. data/ext/native/src/wrappers/swig/go/common.i.in +7 -0
  230. data/ext/native/src/wrappers/swig/java/VirgilByteArray.i +0 -0
  231. data/ext/native/src/wrappers/swig/java/common.i +6 -0
  232. data/ext/native/src/wrappers/swig/php/common.i +0 -0
  233. data/ext/native/src/wrappers/swig/php/php7/VirgilByteArray.i +0 -0
  234. data/ext/native/src/wrappers/swig/util.i +0 -0
  235. data/ext/native/src/wrappers/swig/wrapper.i.in +18 -7
  236. data/ext/native/src/wrappers/webasm/CMakeLists.txt +0 -8
  237. data/ext/rakefile.rb +77 -56
  238. data/lib/virgil/crypto.rb +53 -9
  239. data/lib/virgil/crypto/access_token_signer.rb +79 -0
  240. data/lib/virgil/crypto/bytes.rb +81 -17
  241. data/lib/virgil/crypto/card_crypto.rb +115 -0
  242. data/lib/virgil/crypto/crypto_exception.rb +40 -0
  243. data/lib/virgil/crypto/hash_algorithm.rb +82 -0
  244. data/lib/virgil/crypto/key_pair.rb +41 -0
  245. data/lib/virgil/crypto/key_pair_type.rb +98 -0
  246. data/lib/virgil/crypto/private_key.rb +40 -0
  247. data/lib/virgil/crypto/private_key_exporter.rb +67 -0
  248. data/lib/virgil/crypto/public_key.rb +40 -0
  249. data/lib/virgil/crypto/{virgil_stream_data_sink.rb → stream_data_sink.rb} +12 -12
  250. data/lib/virgil/crypto/{virgil_stream_data_source.rb → stream_data_source.rb} +12 -12
  251. data/lib/virgil/crypto/validation.rb +59 -0
  252. data/lib/virgil/crypto/version.rb +35 -1
  253. data/lib/virgil/crypto/virgil_crypto.rb +595 -0
  254. data/lib/virgil/native_crypto.rb +80 -60
  255. data/lib/virgil/os.rb +40 -6
  256. data/secrets.tar.enc +0 -0
  257. data/virgil-crypto.gemspec +6 -7
  258. metadata +62 -12
  259. data/ext/native/src/cmake/android.toolchain.cmake +0 -1697
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Copyright (C) 2015-2018 Virgil Security Inc.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * (1) Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ *
13
+ * (2) Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in
15
+ * the documentation and/or other materials provided with the
16
+ * distribution.
17
+ *
18
+ * (3) Neither the name of the copyright holder nor the names of its
19
+ * contributors may be used to endorse or promote products derived from
20
+ * this software without specific prior written permission.
21
+ *
22
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
23
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ * POSSIBILITY OF SUCH DAMAGE.
33
+ *
34
+ * Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
35
+ */
36
+
37
+ #include "VirgilConfig.h"
38
+
39
+ using virgil::crypto::VirgilConfig;
40
+
41
+ bool VirgilConfig::hasFeatureStreamImpl() {
42
+ return VIRGIL_CRYPTO_FEATURE_STREAM_IMPL;
43
+ }
44
+
45
+ bool VirgilConfig::hasFeaturePythiaImpl() {
46
+ return VIRGIL_CRYPTO_FEATURE_PYTHIA;
47
+ }
48
+
49
+ bool VirgilConfig::hasFeaturePythiaMultiThread() {
50
+ return VIRGIL_CRYPTO_FEATURE_PYTHIA_MT;
51
+ }
@@ -34,11 +34,53 @@
34
34
  * Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
35
35
  */
36
36
 
37
+
38
+ #ifndef VIRGIL_CRYPTO_CONFIG
39
+ #define VIRGIL_CRYPTO_CONFIG
40
+
37
41
  /**
38
42
  * Contains conditional macroses, that was used during library build.
39
43
  */
40
44
 
41
45
  /**
42
- * On/Off status of the feature : C++ streams.
46
+ * On/Off status of the feature: C++ streams.
43
47
  */
44
48
  #cmakedefine01 VIRGIL_CRYPTO_FEATURE_STREAM_IMPL
49
+
50
+ /**
51
+ * On/Off status of the feature: Pythia.
52
+ */
53
+ #cmakedefine01 VIRGIL_CRYPTO_FEATURE_PYTHIA
54
+
55
+ /**
56
+ * On/Off status of the Pythia multhi-threading.
57
+ */
58
+ #cmakedefine01 VIRGIL_CRYPTO_FEATURE_PYTHIA_MT
59
+
60
+
61
+ namespace virgil {
62
+ namespace crypto {
63
+
64
+ class VirgilConfig {
65
+ public:
66
+ /**
67
+ * @brief Runtime equiavalent of VIRGIL_CRYPTO_FEATURE_STREAM_IMPL
68
+ */
69
+ static bool hasFeatureStreamImpl();
70
+
71
+ /**
72
+ * @brief Runtime equiavalent of VIRGIL_CRYPTO_FEATURE_PYTHIA
73
+ */
74
+ static bool hasFeaturePythiaImpl();
75
+
76
+ /**
77
+ * @brief Runtime equiavalent of VIRGIL_CRYPTO_FEATURE_PYTHIA_MT
78
+ */
79
+ static bool hasFeaturePythiaMultiThread();
80
+
81
+ };
82
+
83
+ } // crypto
84
+ } // virgil
85
+
86
+ #endif /* VIRGIL_CRYPTO_CONFIG */
File without changes
File without changes
@@ -73,6 +73,25 @@ VirgilKeyPair VirgilKeyPair::generateFrom(
73
73
  return VirgilKeyPair(cipher.exportPublicKeyToPEM(), cipher.exportPrivateKeyToPEM(newKeyPairPassword));
74
74
  }
75
75
 
76
+ VirgilKeyPair VirgilKeyPair::generateFromKeyMaterial(
77
+ VirgilKeyPair::Type type,
78
+ const VirgilByteArray& keyMaterial,
79
+ const VirgilByteArray& pwd) {
80
+
81
+ VirgilAsymmetricCipher cipher;
82
+ cipher.genKeyPairFromKeyMaterial(type, keyMaterial);
83
+ return VirgilKeyPair(cipher.exportPublicKeyToPEM(), cipher.exportPrivateKeyToPEM(pwd));
84
+ }
85
+
86
+ VirgilKeyPair VirgilKeyPair::generateRecommendedFromKeyMaterial(
87
+ const VirgilByteArray& keyMaterial,
88
+ const VirgilByteArray& pwd) {
89
+
90
+ VirgilAsymmetricCipher cipher;
91
+ cipher.genKeyPairFromKeyMaterial(Type::FAST_EC_ED25519, keyMaterial);
92
+ return VirgilKeyPair(cipher.exportPublicKeyToPEM(), cipher.exportPrivateKeyToPEM(pwd));
93
+ }
94
+
76
95
  bool VirgilKeyPair::isKeyPairMatch(
77
96
  const VirgilByteArray& publicKey, const VirgilByteArray& privateKey,
78
97
  const VirgilByteArray& privateKeyPassword) {
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Copyright (C) 2015-2018 Virgil Security Inc.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * (1) Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ *
13
+ * (2) Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in
15
+ * the documentation and/or other materials provided with the
16
+ * distribution.
17
+ *
18
+ * (3) Neither the name of the copyright holder nor the names of its
19
+ * contributors may be used to endorse or promote products derived from
20
+ * this software without specific prior written permission.
21
+ *
22
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
23
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ * POSSIBILITY OF SUCH DAMAGE.
33
+ *
34
+ * Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
35
+ */
36
+
37
+ #if VIRGIL_CRYPTO_FEATURE_PYTHIA
38
+
39
+ #include <virgil/crypto/pythia/VirgilPythia.h>
40
+
41
+ #include <virgil/crypto/pythia/VirgilPythiaError.h>
42
+
43
+ #include <pythia/pythia.h>
44
+
45
+ using virgil::crypto::make_error;
46
+ using virgil::crypto::VirgilByteArray;
47
+ using virgil::crypto::VirgilCryptoError;
48
+ using virgil::crypto::pythia::pythia_handler;
49
+ using virgil::crypto::pythia::VirgilPythia;
50
+ using virgil::crypto::pythia::VirgilPythiaBlindResult;
51
+ using virgil::crypto::pythia::VirgilPythiaContext;
52
+ using virgil::crypto::pythia::VirgilPythiaTransformationKeyPair;
53
+ using virgil::crypto::pythia::VirgilPythiaProveResult;
54
+ using virgil::crypto::pythia::VirgilPythiaTransformResult;
55
+
56
+ class buffer_bind_out {
57
+ public:
58
+ buffer_bind_out(VirgilByteArray& out) : buffer_(), out_(out) {
59
+ buffer_.p = out.data();
60
+ buffer_.allocated = out.capacity();
61
+ buffer_.len = 0;
62
+ }
63
+
64
+ ~buffer_bind_out() noexcept {
65
+ out_.resize(buffer_.len);
66
+ }
67
+
68
+ operator pythia_buf_t*() {
69
+ return &buffer_;
70
+ }
71
+
72
+ private:
73
+ pythia_buf_t buffer_;
74
+ VirgilByteArray& out_;
75
+ };
76
+
77
+ class buffer_bind_in {
78
+ public:
79
+ buffer_bind_in(const VirgilByteArray& in) {
80
+ buffer_.p = const_cast<uint8_t*>(in.data());
81
+ buffer_.allocated = in.capacity();
82
+ buffer_.len = in.size();
83
+ }
84
+
85
+ operator const pythia_buf_t*() const {
86
+ return &buffer_;
87
+ }
88
+
89
+ private:
90
+ pythia_buf_t buffer_;
91
+ };
92
+
93
+ VirgilPythiaBlindResult VirgilPythia::blind(const VirgilByteArray& password) {
94
+ VirgilByteArray blindedPassword(PYTHIA_G1_BUF_SIZE);
95
+ VirgilByteArray blindingSecret(PYTHIA_BN_BUF_SIZE);
96
+
97
+ pythia_handler(pythia_w_blind(
98
+ buffer_bind_in(password), buffer_bind_out(blindedPassword),
99
+ buffer_bind_out(blindingSecret)));
100
+
101
+ return VirgilPythiaBlindResult(std::move(blindedPassword), std::move(blindingSecret));
102
+ }
103
+
104
+ VirgilByteArray VirgilPythia::deblind(
105
+ const VirgilByteArray& transformedPassword, const VirgilByteArray& blindingSecret) {
106
+
107
+ VirgilByteArray deblindedPassword(PYTHIA_GT_BUF_SIZE);
108
+
109
+ pythia_handler(pythia_w_deblind(
110
+ buffer_bind_in(transformedPassword), buffer_bind_in(blindingSecret),
111
+ buffer_bind_out(deblindedPassword)));
112
+
113
+ return deblindedPassword;
114
+ }
115
+
116
+ VirgilPythiaTransformationKeyPair VirgilPythia::computeTransformationKeyPair(
117
+ const virgil::crypto::VirgilByteArray &transformationKeyID, const virgil::crypto::VirgilByteArray &pythiaSecret,
118
+ const virgil::crypto::VirgilByteArray &pythiaScopeSecret) {
119
+
120
+ VirgilByteArray transformationPrivateKey(PYTHIA_BN_BUF_SIZE);
121
+ VirgilByteArray transformationPublicKey(PYTHIA_G1_BUF_SIZE);
122
+
123
+ pythia_handler(pythia_w_compute_transformation_key_pair(
124
+ buffer_bind_in(transformationKeyID), buffer_bind_in(pythiaSecret), buffer_bind_in(pythiaScopeSecret),
125
+ buffer_bind_out(transformationPrivateKey), buffer_bind_out(transformationPublicKey)));
126
+
127
+ return VirgilPythiaTransformationKeyPair(
128
+ std::move(transformationPrivateKey), std::move(transformationPublicKey));
129
+ }
130
+
131
+ VirgilPythiaTransformResult VirgilPythia::transform(
132
+ const VirgilByteArray& blindedPassword,
133
+ const VirgilByteArray& tweak, const VirgilByteArray& transformationPrivateKey) {
134
+
135
+ VirgilByteArray transformedPassword(PYTHIA_GT_BUF_SIZE);
136
+ VirgilByteArray transformedTweak(PYTHIA_G2_BUF_SIZE);
137
+
138
+ pythia_handler(pythia_w_transform(
139
+ buffer_bind_in(blindedPassword), buffer_bind_in(tweak), buffer_bind_in(transformationPrivateKey),
140
+ buffer_bind_out(transformedPassword), buffer_bind_out(transformedTweak)));
141
+
142
+ return VirgilPythiaTransformResult(
143
+ std::move(transformedPassword), std::move(transformedTweak));
144
+ }
145
+
146
+ VirgilPythiaProveResult VirgilPythia::prove(
147
+ const VirgilByteArray& transformedPassword, const VirgilByteArray& blindedPassword,
148
+ const VirgilByteArray& transformedTweak, const VirgilPythiaTransformationKeyPair& transformationKeyPair) {
149
+
150
+ VirgilByteArray proofValueC(PYTHIA_BN_BUF_SIZE);
151
+ VirgilByteArray proofValueU(PYTHIA_BN_BUF_SIZE);
152
+
153
+ pythia_handler(pythia_w_prove(
154
+ buffer_bind_in(transformedPassword), buffer_bind_in(blindedPassword),
155
+ buffer_bind_in(transformedTweak), buffer_bind_in(transformationKeyPair.privateKey()),
156
+ buffer_bind_in(transformationKeyPair.publicKey()), buffer_bind_out(proofValueC),
157
+ buffer_bind_out(proofValueU)));
158
+
159
+ return VirgilPythiaProveResult(std::move(proofValueC), std::move(proofValueU));
160
+ }
161
+
162
+ bool VirgilPythia::verify(
163
+ const VirgilByteArray& transformedPassword, const VirgilByteArray& blindedPassword,
164
+ const VirgilByteArray& tweak, const VirgilByteArray& transformationPublicKey,
165
+ const VirgilByteArray& proofValueC, const VirgilByteArray& proofValueU) {
166
+
167
+ int verified = 0;
168
+
169
+ pythia_handler(pythia_w_verify(
170
+ buffer_bind_in(transformedPassword), buffer_bind_in(blindedPassword),
171
+ buffer_bind_in(tweak), buffer_bind_in(transformationPublicKey),
172
+ buffer_bind_in(proofValueC), buffer_bind_in(proofValueU), &verified));
173
+
174
+ return verified != 0;
175
+ }
176
+
177
+ VirgilByteArray VirgilPythia::getPasswordUpdateToken(
178
+ const VirgilByteArray& previousTransformationPrivateKey,
179
+ const VirgilByteArray& newTransformationPrivateKey) {
180
+
181
+ VirgilByteArray passwordUpdateToken(PYTHIA_BN_BUF_SIZE);
182
+
183
+ pythia_handler(pythia_w_get_password_update_token(
184
+ buffer_bind_in(previousTransformationPrivateKey), buffer_bind_in(newTransformationPrivateKey),
185
+ buffer_bind_out(passwordUpdateToken)));
186
+
187
+ return VirgilByteArray(std::move(passwordUpdateToken));
188
+ }
189
+
190
+ VirgilByteArray VirgilPythia::updateDeblindedWithToken(
191
+ const VirgilByteArray& deblindedPassword, const VirgilByteArray& passwordUpdateToken) {
192
+
193
+ VirgilByteArray updatedDeblindedPassword(PYTHIA_GT_BUF_SIZE);
194
+
195
+ pythia_handler(pythia_w_update_deblinded_with_token(
196
+ buffer_bind_in(deblindedPassword), buffer_bind_in(passwordUpdateToken),
197
+ buffer_bind_out(updatedDeblindedPassword)));
198
+
199
+ return VirgilByteArray(std::move(updatedDeblindedPassword));
200
+ }
201
+
202
+ #endif /* VIRGIL_CRYPTO_FEATURE_PYTHIA */
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Copyright (C) 2015-2018 Virgil Security Inc.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * (1) Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ *
13
+ * (2) Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in
15
+ * the documentation and/or other materials provided with the
16
+ * distribution.
17
+ *
18
+ * (3) Neither the name of the copyright holder nor the names of its
19
+ * contributors may be used to endorse or promote products derived from
20
+ * this software without specific prior written permission.
21
+ *
22
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
23
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ * POSSIBILITY OF SUCH DAMAGE.
33
+ *
34
+ * Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
35
+ */
36
+
37
+ #if VIRGIL_CRYPTO_FEATURE_PYTHIA
38
+
39
+ #include <virgil/crypto/pythia/VirgilPythiaContext.h>
40
+
41
+ #include <virgil/crypto/pythia/VirgilPythiaError.h>
42
+
43
+ #include "mbedtls_context.h"
44
+ #include "utils.h"
45
+
46
+ #include <mbedtls/ctr_drbg.h>
47
+ #include <mbedtls/entropy.h>
48
+
49
+ #include <iostream>
50
+ #include <string>
51
+ #include <vector>
52
+
53
+ #include <mutex>
54
+ #include <pythia/pythia.h>
55
+ #include <thread>
56
+ #include <tinyformat/tinyformat.h>
57
+
58
+ using virgil::crypto::make_error;
59
+ using virgil::crypto::foundation::internal::mbedtls_context;
60
+ using virgil::crypto::pythia::pythia_handler;
61
+ using virgil::crypto::pythia::VirgilPythiaContext;
62
+
63
+ #if VIRGIL_CRYPTO_FEATURE_PYTHIA_MT
64
+ # define VIRGIL_THREAD_LOCAL thread_local
65
+ #else
66
+ # define VIRGIL_THREAD_LOCAL
67
+ #endif
68
+
69
+
70
+ static VIRGIL_THREAD_LOCAL mbedtls_context<mbedtls_entropy_context> g_entropy_ctx;
71
+ static VIRGIL_THREAD_LOCAL mbedtls_context<mbedtls_ctr_drbg_context> g_rng_ctx;
72
+ static size_t g_instances;
73
+ static std::mutex g_instances_mutex;
74
+
75
+ static void random_handler(uint8_t* out, int out_len, void*) {
76
+ pythia_handler(mbedtls_ctr_drbg_random(g_rng_ctx.get(), out, out_len));
77
+ }
78
+
79
+ namespace internal {
80
+
81
+ class PythiaContext {
82
+ public:
83
+ PythiaContext() {
84
+ constexpr const char pers[] = "VirgilPythiaContext";
85
+ g_rng_ctx.setup(mbedtls_entropy_func, g_entropy_ctx.get(), pers);
86
+
87
+ std::lock_guard<std::mutex> lock_guard(g_instances_mutex);
88
+ if (g_instances++ > 0) {
89
+ return;
90
+ }
91
+
92
+ pythia_init_args_t init_args;
93
+ init_args.callback = random_handler;
94
+ init_args.args = NULL;
95
+
96
+ pythia_handler(pythia_init(&init_args));
97
+ }
98
+
99
+ ~PythiaContext() noexcept {
100
+ std::lock_guard<std::mutex> lock_guard(g_instances_mutex);
101
+ if (--g_instances > 0) {
102
+ return;
103
+ }
104
+
105
+ pythia_deinit();
106
+ }
107
+ };
108
+
109
+ } // namespace internal
110
+
111
+ VirgilPythiaContext::VirgilPythiaContext() {
112
+ // Need to call ctor on a thread creation and dtor on thread exit
113
+ static VIRGIL_THREAD_LOCAL internal::PythiaContext pythiaContext;
114
+ }
115
+
116
+ #endif /* VIRGIL_CRYPTO_FEATURE_PYTHIA */