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
File without changes
@@ -0,0 +1,15 @@
1
+ {
2
+ "folders":
3
+ [
4
+ {
5
+ "path": ".",
6
+ "folder_exclude_patterns": ["*build*", ".idea", ".depends_cache"]
7
+ }
8
+ ],
9
+ "settings": {
10
+ "ClangFormat": {
11
+ "format_on_save": false
12
+ },
13
+ "rulers": [120]
14
+ }
15
+ }
@@ -57,11 +57,3 @@ include ("${WRAPPERS_ROOT}/emsdk/CMakeLists.txt")
57
57
  # ---------------------------------------------------------------------------
58
58
  # Add specific 'install' options to the target
59
59
  # ---------------------------------------------------------------------------
60
-
61
- string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
62
-
63
- if ("${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}" MATCHES "(-O2|-O3|-Os|-Oz)")
64
-
65
- install (FILES $<TARGET_FILE:${WRAPPER_TARGET}>.mem DESTINATION "${INSTALL_LIB_DIR_NAME}")
66
- install (FILES $<TARGET_FILE:${WRAPPER_TARGET}>.mem DESTINATION "${WRAPPER_DOC_DIR_NAME}/example")
67
- endif ()
@@ -53,7 +53,7 @@ set (WRAPPER_DOC_DIR_NAME "${INSTALL_DOC_DIR_NAME}/${WRAPPER_TARGET}/${VIRGIL_VE
53
53
  set (ORIGINAL_EMBIND_FILE "${EMSCRIPTEN}/system/include/emscripten/bind.h")
54
54
  set (VIRGIL_EMBIND_FILE "${CMAKE_CURRENT_BINARY_DIR}/virgil_bind.h")
55
55
 
56
- message (STATUS "To be able support of custom exception handling\n"
56
+ message (STATUS "To be able support custom exception handling\n"
57
57
  " patched header '${VIRGIL_EMBIND_FILE}' is used,\n"
58
58
  " instead of '${ORIGINAL_EMBIND_FILE}' header."
59
59
  )
@@ -90,7 +90,7 @@ target_link_libraries (${WRAPPER_TARGET} ${WRAPPED_LIB_NAME})
90
90
  target_compile_options (${WRAPPER_TARGET} PUBLIC -s DISABLE_EXCEPTION_CATCHING=0)
91
91
 
92
92
  set_property (TARGET ${WRAPPER_TARGET} APPEND_STRING PROPERTY
93
- LINK_FLAGS " --bind -s DISABLE_EXCEPTION_CATCHING=0")
93
+ LINK_FLAGS " --bind -s SINGLE_FILE=1 -s DISABLE_EXCEPTION_CATCHING=0 -s MODULARIZE=1 -s 'EXPORT_NAME=\"__virgilCrypto\"'")
94
94
 
95
95
  em_link_js_library (${WRAPPER_TARGET} ${CMAKE_CURRENT_LIST_DIR}/error.js)
96
96
  em_link_post_js (${WRAPPER_TARGET} ${CMAKE_CURRENT_LIST_DIR}/helpers.js)
File without changes
@@ -1,13 +1,20 @@
1
1
  <!doctype html>
2
2
  <html>
3
+ <head>
4
+ <title>VirgilCrypto browser test</title>
5
+ <script src="https://unpkg.com/lodash@4.17.5/lodash.js"></script>
6
+ <script src="https://unpkg.com/benchmark@2.1.4/benchmark.js"></script>
7
+ <script src="@WRAPPER_TARGET@.js"></script>
8
+ </head>
9
+ <body>
3
10
  <script type="text/javascript">
4
- function test_encryption() {
11
+ function test_encryption(lib) {
5
12
  console.time("encryption/decryption");
6
- var pwd = Module.VirgilByteArray.fromUTF8("password");
7
- var keys = Module.VirgilKeyPair.generateRecommended(pwd);
8
- var certId = Module.VirgilByteArray.fromUTF8("17648c7e-9ca3-4707-bdc6-a5c57b7a18fc");
9
- var data = Module.VirgilByteArray.fromUTF8("data to be encrypted");
10
- var cipher = new Module.VirgilCipher();
13
+ var pwd = lib.VirgilByteArray.fromUTF8("password");
14
+ var keys = lib.VirgilKeyPair.generateRecommended(pwd);
15
+ var certId = lib.VirgilByteArray.fromUTF8("17648c7e-9ca3-4707-bdc6-a5c57b7a18fc");
16
+ var data = lib.VirgilByteArray.fromUTF8("data to be encrypted");
17
+ var cipher = new lib.VirgilCipher();
11
18
  cipher.addKeyRecipient(certId, keys.publicKey());
12
19
  var encryptedData = cipher.encrypt(data, true);
13
20
  var decryptedData = cipher.decryptWithKey(encryptedData, certId, keys.privateKey(), pwd);
@@ -21,25 +28,25 @@
21
28
  decryptedData.delete();
22
29
  console.timeEnd("encryption/decryption");
23
30
  };
24
- function test_stream_encryption() {
31
+ function test_stream_encryption(lib) {
25
32
  console.time("stream encryption/decryption");
26
- var pwd = Module.VirgilByteArray.fromUTF8("password");
27
- var keys = Module.VirgilKeyPair.generateRecommended(pwd);
28
- var certId = Module.VirgilByteArray.fromUTF8("17648c7e-9ca3-4707-bdc6-a5c57b7a18fc");
29
- var data = Module.VirgilByteArray.fromUTF8("data to be encrypted");
30
- var cipher = new Module.VirgilStreamCipher();
33
+ var pwd = lib.VirgilByteArray.fromUTF8("password");
34
+ var keys = lib.VirgilKeyPair.generateRecommended(pwd);
35
+ var certId = lib.VirgilByteArray.fromUTF8("17648c7e-9ca3-4707-bdc6-a5c57b7a18fc");
36
+ var data = lib.VirgilByteArray.fromUTF8("data to be encrypted");
37
+ var cipher = new lib.VirgilStreamCipher();
31
38
  cipher.addKeyRecipient(certId, keys.publicKey());
32
39
 
33
- var dataSource = new Module.VirgilStreamDataSource(data.toUint8Array(), 1);
34
- var dataSink = new Module.VirgilStreamDataSink();
40
+ var dataSource = new lib.VirgilStreamDataSource(data.toUint8Array(), 1);
41
+ var dataSink = new lib.VirgilStreamDataSink();
35
42
  cipher.encrypt(dataSource, dataSink, true);
36
43
 
37
- var encrypedDataSource = new Module.VirgilStreamDataSource(dataSink.getBytes(), 2);
38
- var decryptedDataSink = new Module.VirgilStreamDataSink();
44
+ var encrypedDataSource = new lib.VirgilStreamDataSource(dataSink.getBytes(), 2);
45
+ var decryptedDataSink = new lib.VirgilStreamDataSink();
39
46
 
40
47
  cipher.decryptWithKey(encrypedDataSource, decryptedDataSink, certId, keys.privateKey(), pwd);
41
48
 
42
- var decryptedData = Module.VirgilByteArray.fromUint8Array(decryptedDataSink.getBytes());
49
+ var decryptedData = lib.VirgilByteArray.fromUint8Array(decryptedDataSink.getBytes());
43
50
 
44
51
  console.log(decryptedData.toUTF8());
45
52
  pwd.delete();
@@ -54,30 +61,144 @@
54
61
  decryptedDataSink.delete();
55
62
  console.timeEnd("stream encryption/decryption");
56
63
  };
57
- function test_sign() {
64
+ function test_sign(lib) {
58
65
  console.time("sign/verify");
59
- var pwd = Module.VirgilByteArray.fromUTF8("");
60
- var keys = Module.VirgilKeyPair.generateRecommended(pwd);
61
- var certId = Module.VirgilByteArray.fromUTF8("17648c7e-9ca3-4707-bdc6-a5c57b7a18fc");
62
- var data = Module.VirgilByteArray.fromUTF8("data to be signed");
63
- var signer = new Module.VirgilSigner();
66
+ var pwd = lib.VirgilByteArray.fromUTF8("");
67
+ var keys = lib.VirgilKeyPair.generateRecommended(pwd);
68
+ var data = lib.VirgilByteArray.fromUTF8("data to be signed");
69
+ var signer = new lib.VirgilSigner();
64
70
  var sign = signer.sign(data, keys.privateKey(), pwd);
65
71
  var verified = signer.verify(data, sign, keys.publicKey());
66
72
  console.log("Data verification " + (verified ? "passed" : "failed"));
67
73
  pwd.delete();
68
74
  keys.delete();
69
- certId.delete();
70
75
  data.delete();
71
76
  signer.delete();
72
77
  sign.delete();
73
78
  console.timeEnd("sign/verify");
74
79
  };
75
- var Module = {
76
- onRuntimeInitialized: function() {
77
- console.log(Module.VirgilVersion.asString())
78
- }
79
- };
80
+
81
+ function encrypt(lib, data, publicKey, certId) {
82
+ var cipher = new lib.VirgilCipher();
83
+ cipher.addKeyRecipient(certId, publicKey);
84
+ var ciphertext = cipher.encrypt(data, true);
85
+ cipher.delete();
86
+ return ciphertext;
87
+ }
88
+
89
+ function decrypt(lib, ciphertext, privateKey, certId) {
90
+ var cipher = new lib.VirgilCipher();
91
+ var decrypted = cipher.decryptWithKey(ciphertext, certId, privateKey, lib.VirgilByteArray.fromUTF8(''));
92
+ cipher.delete();
93
+ return decrypted;
94
+ }
95
+
96
+ function calcSignature(lib, data, privateKey) {
97
+ var signer = new lib.VirgilSigner();
98
+ var signature = signer.sign(data, privateKey, lib.VirgilByteArray.fromUTF8(""));
99
+ signer.delete();
100
+ return signature;
101
+ }
102
+
103
+ function verifySignature(lib, data, signature, publicKey) {
104
+ var signer = new lib.VirgilSigner();
105
+ var verified = signer.verify(data, signature, publicKey);
106
+ signer.delete();
107
+ return verified;
108
+ }
109
+
110
+ function runTests(instance) {
111
+ console.log('Starting tests');
112
+
113
+ test_encryption(instance);
114
+ test_stream_encryption(instance);
115
+ test_sign(instance);
116
+ }
117
+
118
+ function runBenchmarks(instance) {
119
+ console.log('Starting benchmarks');
120
+ var suite = new Benchmark.Suite();
121
+
122
+ // key pair for encryption / decryption
123
+ var eKeypair = instance.VirgilKeyPair.generateRecommended(
124
+ instance.VirgilByteArray.fromUTF8('')
125
+ );
126
+
127
+ // key pair for generating / verifying signature
128
+ var sKeypair = instance.VirgilKeyPair.generateRecommended(
129
+ instance.VirgilByteArray.fromUTF8('')
130
+ );
131
+
132
+ // 32 random bytes to be used as RECIPIENT_ID
133
+ var eCertId = instance.VirgilByteArray.fromUint8Array(
134
+ window.crypto.getRandomValues(new Uint8Array(32))
135
+ );
136
+
137
+ // 1kB of data to encrypt / decrypt
138
+ var eData = instance.VirgilByteArray.fromUint8Array(
139
+ window.crypto.getRandomValues(new Uint8Array(1024))
140
+ );
141
+ var eCiphertext = encrypt(instance, eData, eKeypair.publicKey(), eCertId);
142
+
143
+ // 1kB of data to sign / verify
144
+ var sData = instance.VirgilByteArray.fromUint8Array(
145
+ window.crypto.getRandomValues(new Uint8Array(1024))
146
+ );
147
+ var sSignature = calcSignature(instance, sData, sKeypair.privateKey());
148
+
149
+ suite.add('KeyPair#generateRecommended without password', function () {
150
+ var keypair = instance.VirgilKeyPair.generateRecommended(
151
+ instance.VirgilByteArray.fromUTF8('')
152
+ );
153
+ keypair.delete();
154
+ })
155
+ .add('KeyPair#generateRecommended with password', function () {
156
+ var keypair = instance.VirgilKeyPair.generateRecommended(
157
+ instance.VirgilByteArray.fromUTF8('passphrase')
158
+ );
159
+ keypair.delete();
160
+ })
161
+ .add('KeyPair#generate NIST-256 without password', function() {
162
+ var keypair = instance.VirgilKeyPair.generate(
163
+ instance.VirgilKeyPair.Type.EC_SECP256R1,
164
+ instance.VirgilByteArray.fromUTF8('')
165
+ );
166
+ keypair.delete();
167
+ })
168
+ .add('KeyPair#generate NIST-256 with password', function() {
169
+ var keypair = instance.VirgilKeyPair.generate(
170
+ instance.VirgilKeyPair.Type.EC_SECP256R1,
171
+ instance.VirgilByteArray.fromUTF8('passphrase')
172
+ );
173
+ keypair.delete();
174
+ })
175
+ .add('Cipher#encrypt', function () {
176
+ encrypt(instance, eData, eKeypair.publicKey(), eCertId).delete();
177
+ })
178
+ .add('Cipher#decryptWithKey', function () {
179
+ decrypt(instance, eCiphertext, eKeypair.privateKey(), eCertId).delete();
180
+ })
181
+ .add('Signer#sign', function () {
182
+ calcSignature(instance, sData, sKeypair.privateKey()).delete();
183
+ })
184
+ .add('Signer#verify', function () {
185
+ verifySignature(instance, sData, sSignature, sKeypair.publicKey());
186
+ })
187
+ .on('cycle', function (event) {
188
+ console.log(String(event.target));
189
+ })
190
+ .on('complete', function () {
191
+ console.log('Done');
192
+ })
193
+ .run();
194
+ }
195
+
196
+ __virgilCrypto().then(function (instance) {
197
+ console.log(instance.VirgilVersion.asString());
198
+ runTests(instance);
199
+ console.log('');
200
+ runBenchmarks(instance);
201
+ });
80
202
  </script>
81
- <script async type="text/javascript" src="@WRAPPER_TARGET@.js"></script>
82
- </body>
203
+ </body>
83
204
  </html>
@@ -34,139 +34,144 @@
34
34
  * Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
35
35
  */
36
36
 
37
- function virgil_init () {
38
- Module['VirgilByteArray']['fromUTF8'] = function(string) {
39
- var ba = new Module.VirgilByteArray();
40
- ba.fromUTF8(string);
41
- return ba;
42
- };
43
-
44
- Module['VirgilByteArray']['prototype']['fromUTF8'] = function(string) {
45
- var s = unescape(encodeURIComponent(string));
46
- var charList = s.split('');
47
- var uintArray = [];
48
- for (var i = 0; i < charList.length; ++i) {
49
- uintArray.push(charList[i].charCodeAt(0));
50
- }
51
- this.assign(new Uint8Array(uintArray));
52
- };
53
-
54
- Module['VirgilByteArray']['prototype']['toUTF8'] = function() {
55
- var encodedString = String.fromCharCode.apply(null, this.data());
56
- return decodeURIComponent(escape(encodedString));
57
- };
58
-
59
- Module['VirgilByteArray']['fromUint8Array'] = function(uint8Array) {
60
- var byteArray = new Module.VirgilByteArray;
61
- byteArray.assign(uint8Array);
62
- return byteArray;
63
- };
64
-
65
- Module['VirgilByteArray']['prototype']['fromUint8Array'] = function(uint8Array) {
66
- this.assign(uint8Array);
67
- };
68
-
69
- Module['VirgilByteArray']['prototype']['toUint8Array'] = function() {
70
- var size = this.size();
71
- var array = new Uint8Array(size);
72
- for (var i = 0; i < size; ++i) {
73
- array[i] = this.get(i);
74
- }
75
- return array;
76
- };
77
-
78
- Module['VirgilStreamDataSource'] = Module.VirgilDataSource.extend("VirgilDataSource", {
79
- __construct: function(uint8Array, chunkSize) {
80
- this.__parent.__construct.call(this);
81
- this.position = 0;
82
- this.chunkSize = chunkSize || 1024 * 1024; // 1MB by default
83
- this.bytes = uint8Array;
84
- },
85
- hasData: function() {
86
- return this.position < this.bytes.length;
87
- },
88
- read: function() {
89
- var start = this.position;
90
- var end = start + this.chunkSize;
91
- var chunk = this._slice(start, end);
92
- var bytesRead = chunk.length;
93
- var byteArray = Module.VirgilByteArray.fromUint8Array(chunk);
94
-
95
- this.seek(this.position + bytesRead);
96
- return byteArray;
97
- },
98
- seek: function(offset) {
99
- if (offset < 0) {
100
- offset = this.bytes.length + offset;
101
- }
102
- this.position = offset;
103
- },
104
- _slice: function(start, end) {
105
- if (typeof this.bytes.slice === 'function') {
106
- return this.bytes.slice(start, end);
107
- }
108
- var source = this.bytes;
109
- var len = source.length;
110
- var relativeStart = start;
111
- var k = (relativeStart < 0) ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
112
- var relativeEnd = (end === undefined) ? len : end;
113
- var final = (relativeEnd < 0) ? Math.max(len + relativeEnd, 0) : Math.min(relativeEnd, len);
114
- var count = final - k;
115
- var dest = new Uint8Array(count);
116
- var n = 0;
117
- while (k < final) {
118
- dest[n] = source[k];
119
- ++k;
120
- ++n;
121
- }
122
- return dest;
37
+ (function() {
38
+ function virgil_init () {
39
+ Module['VirgilByteArray']['fromUTF8'] = function(string) {
40
+ var ba = new Module['VirgilByteArray']();
41
+ ba.fromUTF8(string);
42
+ return ba;
43
+ };
44
+
45
+ Module['VirgilByteArray']['prototype']['fromUTF8'] = function(string) {
46
+ var s = unescape(encodeURIComponent(string));
47
+ var charList = s.split('');
48
+ var uintArray = [];
49
+ for (var i = 0; i < charList.length; ++i) {
50
+ uintArray.push(charList[i].charCodeAt(0));
51
+ }
52
+ this.assign(new Uint8Array(uintArray));
53
+ };
54
+
55
+ Module['VirgilByteArray']['prototype']['toUTF8'] = function() {
56
+ var encodedString = String.fromCharCode.apply(null, this.data());
57
+ return decodeURIComponent(escape(encodedString));
58
+ };
59
+
60
+ Module['VirgilByteArray']['fromUint8Array'] = function(uint8Array) {
61
+ var byteArray = new Module['VirgilByteArray'];
62
+ byteArray.assign(uint8Array);
63
+ return byteArray;
64
+ };
65
+
66
+ Module['VirgilByteArray']['prototype']['fromUint8Array'] = function(uint8Array) {
67
+ this.assign(uint8Array);
68
+ };
69
+
70
+ Module['VirgilByteArray']['prototype']['toUint8Array'] = function() {
71
+ var size = this.size();
72
+ var array = new Uint8Array(size);
73
+ for (var i = 0; i < size; ++i) {
74
+ array[i] = this.get(i);
75
+ }
76
+ return array;
77
+ };
78
+
79
+ Module['VirgilStreamDataSource'] = Module['VirgilDataSource'].extend("VirgilDataSource", {
80
+ __construct: function(uint8Array, chunkSize) {
81
+ this.__parent.__construct.call(this);
82
+ this.position = 0;
83
+ this.chunkSize = chunkSize || 1024 * 1024; // 1MB by default
84
+ this.bytes = uint8Array;
85
+ },
86
+ hasData: function() {
87
+ return this.position < this.bytes.length;
88
+ },
89
+ read: function() {
90
+ var start = this.position;
91
+ var end = start + this.chunkSize;
92
+ var chunk = this._slice(start, end);
93
+ var bytesRead = chunk.length;
94
+ var byteArray = Module['VirgilByteArray'].fromUint8Array(chunk);
95
+
96
+ this.seek(this.position + bytesRead);
97
+ return byteArray;
98
+ },
99
+ seek: function(offset) {
100
+ if (offset < 0) {
101
+ offset = this.bytes.length + offset;
102
+ }
103
+ this.position = offset;
104
+ },
105
+ _slice: function(start, end) {
106
+ if (typeof this.bytes.slice === 'function') {
107
+ return this.bytes.slice(start, end);
108
+ }
109
+ var source = this.bytes;
110
+ var len = source.length;
111
+ var relativeStart = start;
112
+ var k = (relativeStart < 0) ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
113
+ var relativeEnd = (end === undefined) ? len : end;
114
+ var final = (relativeEnd < 0) ? Math.max(len + relativeEnd, 0) : Math.min(relativeEnd, len);
115
+ var count = final - k;
116
+ var dest = new Uint8Array(count);
117
+ var n = 0;
118
+ while (k < final) {
119
+ dest[n] = source[k];
120
+ ++k;
121
+ ++n;
122
+ }
123
+ return dest;
124
+ }
125
+ });
126
+
127
+ Module['VirgilStreamDataSink'] = Module['VirgilDataSink'].extend("VirgilDataSink", {
128
+ __construct: function() {
129
+ this.__parent.__construct.call(this);
130
+ this.bytes = new Uint8Array(0);
131
+ },
132
+ isGood: function() {
133
+ return true;
134
+ },
135
+ write: function(bytes) {
136
+ var chunk = bytes.toUint8Array();
137
+ this._append(chunk);
138
+ },
139
+ getBytes: function () {
140
+ return this.bytes;
141
+ },
142
+ _append: function (uint8Array) {
143
+ var result;
144
+ var totalLength = this.bytes.length + uint8Array.length;
145
+
146
+ result = new Uint8Array(totalLength);
147
+ result.set(this.bytes, 0);
148
+ result.set(uint8Array, this.bytes.length);
149
+
150
+ this.bytes = result;
151
+ }
152
+ });
153
+
154
+ Module['VirgilKeyPair']['Type'] = Module['VirgilKeyPairType']
155
+ Module['VirgilPBKDF']['Algorithm'] = Module['VirgilPBKDFAlgorithm']
156
+ Module['VirgilHash']['Algorithm'] = Module['VirgilHashAlgorithm']
157
+ Module['VirgilTinyCipher']['PackageSize'] = Module['VirgilTinyCipherPackageSize']
158
+ Module['VirgilHash']['Algorithm'] = Module['VirgilHashAlgorithm']
159
+ Module['VirgilPBE']['Algorithm'] = Module['VirgilPBEAlgorithm']
160
+ Module['VirgilSymmetricCipher']['Algorithm'] = Module['VirgilSymmetricCipherAlgorithm']
161
+ Module['VirgilSymmetricCipher']['Padding'] = Module['VirgilSymmetricCipherPadding']
162
+ }
163
+
164
+ if (Module['VirgilVersion']) {
165
+ // initialized synchronously (asmjs)
166
+ virgil_init();
167
+ } else {
168
+ // initialized asynchronously (wasm)
169
+ var originalOnInit = Module['onRuntimeInitialized'];
170
+ Module['onRuntimeInitialized'] = function onRuntimeInitialized() {
171
+ virgil_init();
172
+ if (typeof originalOnInit === 'function') {
173
+ originalOnInit();
123
174
  }
124
- });
125
-
126
- Module['VirgilStreamDataSink'] = Module.VirgilDataSink.extend("VirgilDataSink", {
127
- __construct: function() {
128
- this.__parent.__construct.call(this);
129
- this.bytes = new Uint8Array(0);
130
- },
131
- isGood: function() {
132
- return true;
133
- },
134
- write: function(bytes) {
135
- var chunk = bytes.toUint8Array();
136
- this._append(chunk);
137
- },
138
- getBytes: function () {
139
- return this.bytes;
140
- },
141
- _append: function (uint8Array) {
142
- var result;
143
- var totalLength = this.bytes.length + uint8Array.length;
144
-
145
- result = new Uint8Array(totalLength);
146
- result.set(this.bytes, 0);
147
- result.set(uint8Array, this.bytes.length);
148
-
149
- this.bytes = result;
150
- }
151
- });
152
-
153
- Module['VirgilKeyPair']['Type'] = Module['VirgilKeyPairType']
154
- Module['VirgilPBKDF']['Algorithm'] = Module['VirgilPBKDFAlgorithm']
155
- Module['VirgilHash']['Algorithm'] = Module['VirgilHashAlgorithm']
156
- Module['VirgilTinyCipher']['PackageSize'] = Module['VirgilTinyCipherPackageSize']
157
- Module['VirgilHash']['Algorithm'] = Module['VirgilHashAlgorithm']
158
- Module['VirgilPBE']['Algorithm'] = Module['VirgilPBEAlgorithm']
159
- Module['VirgilSymmetricCipher']['Algorithm'] = Module['VirgilSymmetricCipherAlgorithm']
160
- Module['VirgilSymmetricCipher']['Padding'] = Module['VirgilSymmetricCipherPadding']
161
-
162
- }
163
-
164
- if (Module['VirgilVersion']) {
165
- // AsmJS path
166
- virgil_init ();
167
-
168
- } else {
169
- // WebAssembly path
170
- Module['postRun'].push(virgil_init);
171
- }
172
-
175
+ };
176
+ }
177
+ })();