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
@@ -175,12 +175,16 @@ TEST_CASE_ENCRYPT_DECRYPT(RSA_2048)
175
175
 
176
176
  TEST_CASE_ENCRYPT_DECRYPT(RSA_3072)
177
177
 
178
- TEST_CASE_ENCRYPT_DECRYPT(RSA_4096)
179
-
180
- TEST_CASE_ENCRYPT_DECRYPT(RSA_8192)
181
-
182
178
  #undef TEST_CASE_ENCRYPT_DECRYPT
183
179
 
180
+ TEST_CASE("VirgilCipher: encrypt and decrypt with RSA_4096 keys", "[cipher]") {
181
+ test_encrypt_decrypt(VirgilKeyPair(
182
+ VirgilByteArrayUtils::stringToBytes(kRSA_4096_Public),
183
+ VirgilByteArrayUtils::stringToBytes(kRSA_4096_Private)),
184
+ VirgilByteArrayUtils::stringToBytes(kRSA_4096_Password)
185
+ );
186
+ }
187
+
184
188
  TEST_CASE("VirgilCipher: encrypt and decrypt with RSA_8192 keys", "[cipher]") {
185
189
  test_encrypt_decrypt(VirgilKeyPair(
186
190
  VirgilByteArrayUtils::stringToBytes(kRSA_8192_Public),
File without changes
@@ -118,11 +118,14 @@ TEST_CASE("Check contract: copy and move", "[copy/move]") {
118
118
  SECTION_CONTRACT_COPY_AND_MOVE(virgil::crypto::foundation::cms::VirgilCMSKeyTransRecipient);
119
119
  SECTION_CONTRACT_COPY_AND_MOVE(virgil::crypto::foundation::cms::VirgilCMSPasswordRecipient);
120
120
 
121
- #if defined(__GNUG__) && (__GNUC__ == 5 && __GNUC_MINOR__ >= 5 )
121
+ #if ! defined(__GNUG__)
122
122
  // VirgilCryptoException contains field with type std::string,
123
123
  // GCC has bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58265, and it will be fixed in the version 5.5,
124
124
  // it means next condition can not by satisfied:
125
125
  // static_assert(std::is_nothrow_move_assignable<VirgilCryptoException>::value, "Fail");
126
+ // NOTE! Still fail on the gcc-5.5 on the Ubuntu Trusty!
127
+ // NOTE! Still fail on the gcc-6.4 on the Ubuntu Trusty!
128
+ // NOTE! Possible they use previous ABI.
126
129
  SECTION_CONTRACT_COPY_AND_MOVE(virgil::crypto::VirgilCryptoException);
127
130
  SECTION_CONTRACT_COPY_AND_MOVE(virgil::crypto::foundation::cms::VirgilCMSContentInfo);
128
131
  SECTION_CONTRACT_COPY_AND_MOVE(virgil::crypto::VirgilCustomParams);
File without changes
File without changes
File without changes
@@ -41,6 +41,7 @@
41
41
 
42
42
  #include "catch.hpp"
43
43
  #include "rsa_keys.h"
44
+ #include "deterministic_keys.h"
44
45
 
45
46
  #include <virgil/crypto/VirgilByteArray.h>
46
47
  #include <virgil/crypto/VirgilByteArrayUtils.h>
@@ -204,7 +205,55 @@ TEST_CASE("Export Private Key", "[key-pair]") {
204
205
  }
205
206
  }
206
207
 
207
- TEST_CASE("Export keys RSA", "[key-pair][key-pair-rsa]") {
208
+ TEST_CASE("Export keys RSA", "[key-pair]") {
209
+
210
+ SECTION("4096 encrypted") {
211
+
212
+ SECTION("to DER format") {
213
+ REQUIRE_NOTHROW(VirgilKeyPair::publicKeyToDER(
214
+ VirgilByteArrayUtils::stringToBytes(kRSA_4096_Public)
215
+ ));
216
+
217
+ REQUIRE_NOTHROW(VirgilKeyPair::privateKeyToDER(
218
+ VirgilByteArrayUtils::stringToBytes(kRSA_4096_Private),
219
+ VirgilByteArrayUtils::stringToBytes(kRSA_4096_Password)
220
+ ));
221
+ }
222
+
223
+ SECTION("to PEM format") {
224
+ REQUIRE_NOTHROW(VirgilKeyPair::publicKeyToPEM(
225
+ VirgilByteArrayUtils::stringToBytes(kRSA_4096_Public)
226
+ ));
227
+
228
+ REQUIRE_NOTHROW(VirgilKeyPair::privateKeyToPEM(
229
+ VirgilByteArrayUtils::stringToBytes(kRSA_4096_Private),
230
+ VirgilByteArrayUtils::stringToBytes(kRSA_4096_Password)
231
+ ));
232
+ }
233
+ }
234
+
235
+ SECTION("4096 plain") {
236
+
237
+ SECTION("to DER format") {
238
+ REQUIRE_NOTHROW(VirgilKeyPair::publicKeyToDER(
239
+ VirgilByteArrayUtils::stringToBytes(kRSA_4096_Public)
240
+ ));
241
+
242
+ REQUIRE_NOTHROW(VirgilKeyPair::privateKeyToDER(
243
+ VirgilByteArrayUtils::stringToBytes(kRSA_4096_Private_Plain)
244
+ ));
245
+ }
246
+
247
+ SECTION("to PEM format") {
248
+ REQUIRE_NOTHROW(VirgilKeyPair::publicKeyToPEM(
249
+ VirgilByteArrayUtils::stringToBytes(kRSA_4096_Public)
250
+ ));
251
+
252
+ REQUIRE_NOTHROW(VirgilKeyPair::privateKeyToPEM(
253
+ VirgilByteArrayUtils::stringToBytes(kRSA_4096_Private_Plain)
254
+ ));
255
+ }
256
+ }
208
257
 
209
258
  SECTION("8192 encrypted") {
210
259
 
@@ -235,7 +284,7 @@ TEST_CASE("Export keys RSA", "[key-pair][key-pair-rsa]") {
235
284
 
236
285
  SECTION("to DER format") {
237
286
  REQUIRE_NOTHROW(VirgilKeyPair::publicKeyToDER(
238
- VirgilByteArrayUtils::stringToBytes(kRSA_8192_Public_Plain)
287
+ VirgilByteArrayUtils::stringToBytes(kRSA_8192_Public)
239
288
  ));
240
289
 
241
290
  REQUIRE_NOTHROW(VirgilKeyPair::privateKeyToDER(
@@ -245,7 +294,7 @@ TEST_CASE("Export keys RSA", "[key-pair][key-pair-rsa]") {
245
294
 
246
295
  SECTION("to PEM format") {
247
296
  REQUIRE_NOTHROW(VirgilKeyPair::publicKeyToPEM(
248
- VirgilByteArrayUtils::stringToBytes(kRSA_8192_Public_Plain)
297
+ VirgilByteArrayUtils::stringToBytes(kRSA_8192_Public)
249
298
  ));
250
299
 
251
300
  REQUIRE_NOTHROW(VirgilKeyPair::privateKeyToPEM(
@@ -254,3 +303,16 @@ TEST_CASE("Export keys RSA", "[key-pair][key-pair-rsa]") {
254
303
  }
255
304
  }
256
305
  }
306
+
307
+ TEST_CASE("Generate Deterministic Key Pair", "[key-pair]") {
308
+ VirgilByteArray strongKeyMaterial = VirgilByteArrayUtils::hexToBytes(kDeterministic_KeyMaterial);
309
+
310
+ SECTION("check FAST_EC_ED25519") {
311
+ VirgilKeyPair keyPair(VirgilByteArray{}, VirgilByteArray{});
312
+
313
+ REQUIRE_NOTHROW(keyPair = VirgilKeyPair::generateFromKeyMaterial(
314
+ VirgilKeyPair::Algorithm::FAST_EC_ED25519, strongKeyMaterial));
315
+ REQUIRE(kDeterministic_FAST_EC_ED25519_Public == VirgilByteArrayUtils::bytesToString(keyPair.publicKey()));
316
+ REQUIRE(kDeterministic_FAST_EC_ED25519_Private == VirgilByteArrayUtils::bytesToString(keyPair.privateKey()));
317
+ }
318
+ }
File without changes
File without changes
File without changes
@@ -0,0 +1,157 @@
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
+ /**
38
+ * @file test_pythia_c.cxx
39
+ * @brief Test C implementation of the Pythia algorithm
40
+ */
41
+
42
+ #include "catch.hpp"
43
+
44
+ #if VIRGIL_CRYPTO_FEATURE_PYTHIA
45
+
46
+ #include <virgil/crypto/VirgilByteArray.h>
47
+ #include <virgil/crypto/pythia/VirgilPythia.h>
48
+
49
+ using virgil::crypto::bytes2hex;
50
+ using virgil::crypto::hex2bytes;
51
+ using virgil::crypto::str2bytes;
52
+ using virgil::crypto::VirgilByteArray;
53
+ using virgil::crypto::pythia::VirgilPythia;
54
+
55
+ static const VirgilByteArray kDeblindedPassword = hex2bytes(
56
+ "13273238e3119262f86d3213b8eb6b99c093ef48737dfcfae96210f7350e096cbc7e6b992e4e6f705ac3f0a915"
57
+ "d1622c1644596408e3d16126ddfa9ce594e9f361b21ef9c82309e5714c09bcd7f7ec5c2666591134c645d45ed8"
58
+ "c9703e718ee005fe4b97fc40f69b424728831d0a889cd39be04683dd380daa0df67c38279e3b9fe32f6c407803"
59
+ "11f2dfbb6e89fc90ef15fb2c7958e387182dc7ef57f716fdd152a58ac1d3f0d19bfa2f789024333976c69fbe9e"
60
+ "24b58d6cd8fa49c5f4d642b00f8e390c199f37f7b3125758ef284ae10fd9c2da7ea280550baccd55dadd70873a"
61
+ "063bcfc9cac9079042af88a543a6cc09aaed6ba4954d6ee8ccc6e1145944328266616cd00f8a616f0e79e52ddd"
62
+ "2ef970c8ba8f8ffce35505dc643c8e2b6e430a1474a6d043a4daf9b62af87c1d45ca994d23f908f7898a3f44ca"
63
+ "7bb642122087ca819308b3d8afad17ca1f6148e8750870336ca68eb783c89b0dc9d92392f453c650e9f09232b9"
64
+ "fcffd1c2cad24b14d2b4952b7f54552295ce0e854996913c");
65
+
66
+ static const VirgilByteArray kPassword = str2bytes("password");
67
+ static const VirgilByteArray kTransformationKeyID = str2bytes("virgil.com");
68
+ static const VirgilByteArray kTweek = str2bytes("alice");
69
+ static const VirgilByteArray kPythiaSecret = str2bytes("master secret");
70
+ static const VirgilByteArray kNewPythiaSecret = str2bytes("new master secret");
71
+ static const VirgilByteArray kPythiaScopeSecret = str2bytes("server secret");
72
+ static const VirgilByteArray kNewPythiaScopeSecret = str2bytes("new server secret");
73
+
74
+ SCENARIO("VirgilPythia: init", "[pythia]") {
75
+ VirgilPythia pythia;
76
+ }
77
+
78
+ SCENARIO("VirgilPythia: blind / deblind", "[pythia]") {
79
+ VirgilPythia pythia;
80
+
81
+ auto blindResult = pythia.blind(kPassword);
82
+
83
+ auto transformationKeyPair = pythia.computeTransformationKeyPair(kTransformationKeyID, kPythiaSecret, kPythiaScopeSecret);
84
+
85
+ auto transformResult = pythia.transform(
86
+ blindResult.blindedPassword(), kTweek, transformationKeyPair.privateKey());
87
+
88
+ auto deblindResult =
89
+ pythia.deblind(transformResult.transformedPassword(), blindResult.blindingSecret());
90
+
91
+ REQUIRE(bytes2hex(kDeblindedPassword) == bytes2hex(deblindResult));
92
+ }
93
+
94
+ SCENARIO("VirgilPythia: prove / verify", "[pythia]") {
95
+ VirgilPythia pythia;
96
+
97
+ auto blindResult = pythia.blind(kPassword);
98
+
99
+ auto transformationKeyPair = pythia.computeTransformationKeyPair(kTransformationKeyID, kPythiaSecret, kPythiaScopeSecret);
100
+
101
+ auto transformResult = pythia.transform(
102
+ blindResult.blindedPassword(), kTweek, transformationKeyPair.privateKey());
103
+
104
+ auto proveResult = pythia.prove(
105
+ transformResult.transformedPassword(), blindResult.blindedPassword(),
106
+ transformResult.transformedTweak(), transformationKeyPair);
107
+
108
+ auto isVerified = pythia.verify(
109
+ transformResult.transformedPassword(), blindResult.blindedPassword(), kTweek,
110
+ transformationKeyPair.publicKey(), proveResult.proofValueC(),
111
+ proveResult.proofValueU());
112
+
113
+ REQUIRE(true == isVerified);
114
+ }
115
+
116
+
117
+ SCENARIO("VirgilPythia: update password token", "[pythia]") {
118
+ VirgilPythia pythia;
119
+
120
+ auto blindResult = pythia.blind(kPassword);
121
+
122
+ auto transformationKeyPair = pythia.computeTransformationKeyPair(kTransformationKeyID, kPythiaSecret, kPythiaScopeSecret);
123
+
124
+ auto transformResult = pythia.transform(
125
+ blindResult.blindedPassword(), kTweek, transformationKeyPair.privateKey());
126
+
127
+ auto deblindResult =
128
+ pythia.deblind(transformResult.transformedPassword(), blindResult.blindingSecret());
129
+
130
+ auto newTransformationKeyPair = pythia.computeTransformationKeyPair(kTransformationKeyID, kNewPythiaSecret, kNewPythiaScopeSecret);
131
+
132
+ auto passwordUpdateTokenResult = pythia.getPasswordUpdateToken(transformationKeyPair.privateKey(), newTransformationKeyPair.privateKey());
133
+
134
+ auto updatedDeblindPasswordResult = pythia.updateDeblindedWithToken(
135
+ deblindResult, passwordUpdateTokenResult);
136
+
137
+ auto newTransformResult = pythia.transform(
138
+ blindResult.blindedPassword(), kTweek, newTransformationKeyPair.privateKey());
139
+
140
+ auto newDeblindResult =
141
+ pythia.deblind(newTransformResult.transformedPassword(), blindResult.blindingSecret());
142
+
143
+ REQUIRE(bytes2hex(updatedDeblindPasswordResult) ==
144
+ bytes2hex(newDeblindResult));
145
+
146
+ auto proveResult = pythia.prove(
147
+ newTransformResult.transformedPassword(), blindResult.blindedPassword(),
148
+ newTransformResult.transformedTweak(), newTransformationKeyPair);
149
+
150
+ auto isVerified = pythia.verify(
151
+ newTransformResult.transformedPassword(), blindResult.blindedPassword(), kTweek,
152
+ newTransformationKeyPair.publicKey(), proveResult.proofValueC(),
153
+ proveResult.proofValueU());
154
+
155
+ REQUIRE(true == isVerified); }
156
+
157
+ #endif // VIRGIL_CRYPTO_FEATURE_PYTHIA
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -55,31 +55,35 @@ function show_usage {
55
55
  echo -e "${COLOR_RED}[ERROR] $1${COLOR_RESET}"
56
56
  fi
57
57
  echo -e "This script helps to build crypto library for variety of languages and platforms."
58
- echo -e "Common reuirements: CMake 3.0.5, Python, PyYaml, SWIG 3.0.7."
59
- echo -e "${COLOR_BLUE}Usage: ${BASH_SOURCE[0]} [<target>] [<src_dir>] [<build_dir>] [<install_dir>]${COLOR_RESET}"
60
- echo -e " - <target> - (default = cpp) target to build wich contains two parts <name>[-<version>], where <name>:"
61
- echo -e " * cpp - build C++ library;"
62
- echo -e " * macos - build framework for Apple macOSX, requirements: OS X, Xcode;"
63
- echo -e " * ios - build framework for Apple iOS, requirements: OS X, Xcode;"
64
- echo -e " * watchos - build framework for Apple WatchOS, requirements: OS X, Xcode;"
65
- echo -e " * tvos - build framework for Apple TVOS, requirements: OS X, Xcode;"
66
- echo -e " * php - build PHP library, requirements: php-dev;"
67
- echo -e " * python - build Python library;"
68
- echo -e " * ruby - build Ruby library;"
69
- echo -e " * java - build Java library, requirements: \$JAVA_HOME;"
70
- echo -e " * java_android - build Java library under Android platform, requirements: \$ANDROID_NDK;"
71
- echo -e " * net - build .NET library, requirements: .NET or Mono;"
72
- echo -e " * net_macos - build .NET library under Apple macOSX platform, requirements: Mono, OS X, Xcode;"
73
- echo -e " * net_ios - build .NET library under Apple iOS platform, requirements: Mono, OS X, Xcode;"
74
- echo -e " * net_applewatchos - build .NET library under WatchOS platform, requirements: Mono, OS X, Xcode;"
75
- echo -e " * net_appletvos - build .NET library under TVOS platform, requirements: Mono, OS X, Xcode;"
76
- echo -e " * net_android - build .NET library under Android platform, requirements: Mono, \$ANDROID_NDK;"
77
- echo -e " * asmjs - build AsmJS library, requirements: \$EMSDK_HOME;"
78
- echo -e " * webasm - build WebAssembly library, requirements: \$EMSDK_HOME;"
79
- echo -e " * nodejs - build NodeJS module;"
80
- echo -e " * go - build Golang library."
81
- echo -e " - <src_dir> - (default = .) path to the directory where root CMakeLists.txt file is located"
82
- echo -e " - <build_dir> - (default = build/<target>) path to the directory where temp files will be stored"
58
+ echo -e "Common reuirements: CMake 3.10, Python, PyYaml, SWIG 3.0.12."
59
+ echo -e "${COLOR_BLUE}Usage: ${BASH_SOURCE[0]} [--target=<target>] [--feature=<feature>] [--src=<src_dir>] [--build=<build_dir>] [--install=<install_dir>]${COLOR_RESET}"
60
+ echo -e " - <target> - (default = cpp) target to build which contains two parts <name>[-<version>], where <name>:"
61
+ echo -e " * cpp - build C++ library;"
62
+ echo -e " * macos - build framework for Apple macOSX, requirements: OS X, Xcode;"
63
+ echo -e " * ios - build framework for Apple iOS, requirements: OS X, Xcode;"
64
+ echo -e " * watchos - build framework for Apple WatchOS, requirements: OS X, Xcode;"
65
+ echo -e " * tvos - build framework for Apple TVOS, requirements: OS X, Xcode;"
66
+ echo -e " * php - build PHP library, requirements: php-dev;"
67
+ echo -e " * python - build Python library;"
68
+ echo -e " * ruby - build Ruby library;"
69
+ echo -e " * java - build Java library, requirements: \$JAVA_HOME;"
70
+ echo -e " * java_android - build Java library under Android platform, requirements: \$ANDROID_NDK;"
71
+ echo -e " * net - build .NET library, requirements: .NET or Mono;"
72
+ echo -e " * net_macos - build .NET library under Apple macOSX platform, requirements: Mono, OS X, Xcode;"
73
+ echo -e " * net_ios - build .NET library under Apple iOS platform, requirements: Mono, OS X, Xcode;"
74
+ echo -e " * net_applewatchos - build .NET library under WatchOS platform, requirements: Mono, OS X, Xcode;"
75
+ echo -e " * net_appletvos - build .NET library under TVOS platform, requirements: Mono, OS X, Xcode;"
76
+ echo -e " * net_android - build .NET library under Android platform, requirements: Mono, \$ANDROID_NDK;"
77
+ echo -e " * asmjs - build AsmJS library, requirements: \$EMSDK_HOME;"
78
+ echo -e " * webasm - build WebAssembly library, requirements: \$EMSDK_HOME;"
79
+ echo -e " * nodejs - build NodeJS module;"
80
+ echo -e " * go - build Golang library."
81
+ echo -e ""
82
+ echo -e " - <feature> - available features:"
83
+ echo -e " * pythia - ask to enable feature Pythia. Some targets enable this feature by default."
84
+ echo -e ""
85
+ echo -e " - <src_dir> - (default = .) path to the directory where root CMakeLists.txt file is located."
86
+ echo -e " - <build_dir> - (default = build/<target>) path to the directory where temp files will be stored."
83
87
  echo -e " - <install_dir> - (default = install/<target>) path to the directory where library files will be installed".
84
88
 
85
89
  exit ${2:0}
@@ -186,6 +190,8 @@ function make_fat_library {
186
190
 
187
191
  LIBMBEDTLS="libmbedcrypto.a"
188
192
  LIBED25519="libed25519.a"
193
+ LIBRELIC="librelic_s.a"
194
+ LIBPYTHIA="libpythia.a"
189
195
  LIBVIRGIL="libvirgil_crypto.a"
190
196
  if [ ! -z "${WRAPPER_NAME}" ]; then
191
197
  LIBVIRGIL_WRAPPER="virgil_crypto_${WRAPPER_NAME}.a"
@@ -200,6 +206,12 @@ function make_fat_library {
200
206
  # Find all archs of library ed25519
201
207
  LIBED25519_LIBS=$(find "${INDIR}" -name "${LIBED25519}" | tr '\n' ' ')
202
208
 
209
+ # Find all archs of library relic
210
+ LIBRELIC_LIBS=$(find "${INDIR}" -name "${LIBRELIC}" | tr '\n' ' ')
211
+
212
+ # Find all archs of library pythia
213
+ LIBPYTHIA_LIBS=$(find "${INDIR}" -name "${LIBPYTHIA}" | tr '\n' ' ')
214
+
203
215
  # Find all archs of library Virgil Crypto
204
216
  LIBVIRGIL_LIBS=$(find "${INDIR}" -name "${LIBVIRGIL}" | tr '\n' ' ')
205
217
 
@@ -211,24 +223,82 @@ function make_fat_library {
211
223
  xcrun lipo -create ${LIBMBEDTLS_LIBS} -output "$OUTDIR/$LIBMBEDTLS"
212
224
  xcrun lipo -create ${LIBED25519_LIBS} -output "$OUTDIR/$LIBED25519"
213
225
  xcrun lipo -create ${LIBVIRGIL_LIBS} -output "$OUTDIR/$LIBVIRGIL"
226
+
227
+ if [ ! -z "${LIBRELIC_LIBS}" ]; then
228
+ LIBRELIC_FAT="$OUTDIR/$LIBRELIC"
229
+ xcrun lipo -create ${LIBRELIC_LIBS} -output "${LIBRELIC_FAT}"
230
+ fi
231
+
232
+ if [ ! -z "${LIBPYTHIA_LIBS}" ]; then
233
+ LIBPYTHIA_FAT="$OUTDIR/$LIBPYTHIA"
234
+ xcrun lipo -create ${LIBPYTHIA_LIBS} -output "${LIBPYTHIA_FAT}"
235
+ fi
236
+
214
237
  if [ ! -z "${LIBVIRGIL_WRAPPER_LIBS}" ]; then
215
238
  LIBVIRGIL_WRAPPER_FAT="$OUTDIR/$LIBVIRGIL_WRAPPER"
216
239
  xcrun lipo -create ${LIBVIRGIL_WRAPPER_LIBS} -output "$LIBVIRGIL_WRAPPER_FAT"
217
240
  fi
218
241
 
219
242
  # Merge several static libraries in one static library which will actually be framework
220
- xcrun libtool -static -o "$OUTDIR/$LIB_FAT_NAME" \
221
- "$OUTDIR/$LIBMBEDTLS" "$OUTDIR/$LIBED25519" "$OUTDIR/$LIBVIRGIL" "$LIBVIRGIL_WRAPPER_FAT"
243
+ # Note! Spaces in the filenames and paths are prohibited.
244
+ # Note! Quoting the paths leads to failed build.
245
+ xcrun libtool -static -o ${OUTDIR}/${LIB_FAT_NAME} \
246
+ ${OUTDIR}/${LIBMBEDTLS} ${OUTDIR}/${LIBED25519} ${LIBRELIC_FAT} ${LIBPYTHIA_FAT} \
247
+ ${OUTDIR}/${LIBVIRGIL} ${LIBVIRGIL_WRAPPER_FAT}
222
248
 
223
249
  # Cleanup
224
250
  rm -f "$OUTDIR/$LIBMBEDTLS"
225
251
  rm -f "$OUTDIR/$LIBED25519"
226
252
  rm -f "$OUTDIR/$LIBVIRGIL"
253
+
254
+ if [ -f "${LIBPYTHIA_FAT}" ]; then
255
+ rm -f "${LIBPYTHIA_FAT}"
256
+ fi
257
+
258
+ if [ -f "${LIBRELIC_FAT}" ]; then
259
+ rm -f "${LIBRELIC_FAT}"
260
+ fi
261
+
227
262
  if [ -f "${LIBVIRGIL_WRAPPER_FAT}" ]; then
228
263
  rm -f "${LIBVIRGIL_WRAPPER_FAT}"
229
264
  fi
230
265
  }
231
266
 
267
+ # Parse arguments (https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash)
268
+ FEATURES=()
269
+ for arg in "$@"
270
+ do
271
+ case ${arg} in
272
+ --target=*)
273
+ TARGET="${arg#*=}"
274
+ shift
275
+ ;;
276
+ --feature=*)
277
+ FEATURES+=("${arg#*=}")
278
+ shift
279
+ ;;
280
+ --src=*)
281
+ SRC_DIR="${arg#*=}"
282
+ shift
283
+ ;;
284
+ --build=*)
285
+ BUILD_DIR="${arg#*=}"
286
+ shift
287
+ ;;
288
+ --install=*)
289
+ INSTALL_DIR="${arg#*=}"
290
+ shift
291
+ ;;
292
+ -h|--help)
293
+ show_usage
294
+ ;;
295
+ *)
296
+ show_usage "Unknown argument '${arg}', or it's value is not defined."
297
+ ;;
298
+ esac
299
+ done
300
+ set -- "${POSITIONAL[@]}" # restore positional parameters
301
+
232
302
  # Define environment variables.
233
303
  SCRIPT_DIR=$(dirname "$(abspath "${BASH_SOURCE[0]}")")
234
304
  CURRENT_DIR=$(abspath .)
@@ -244,22 +314,17 @@ if [ "${SYSTEM_NAME}" == "linux" ]; then
244
314
  fi
245
315
 
246
316
  if [ -f "${SCRIPT_DIR}/env.sh" ]; then
317
+ show_info "Setting up additional build environment"
247
318
  source "${SCRIPT_DIR}/env.sh"
248
319
  fi
249
320
 
250
321
  # Check arguments
251
- if [ ! -z "$1" ]; then
252
- if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
253
- show_usage
254
- else
255
- TARGET="$1"
256
- fi
257
- else
322
+ if [ -z "$TARGET" ]; then
258
323
  TARGET="cpp"
259
324
  fi
260
325
  show_info "<target> : ${TARGET}"
261
326
 
262
- target_arr=(${1//-/ })
327
+ target_arr=(${TARGET//-/ })
263
328
  TARGET_NAME="${target_arr[0]}"
264
329
  TARGET_VERSION="${target_arr[1]}"
265
330
 
@@ -268,8 +333,8 @@ if [ ! -z "${TARGET_VERSION}" ]; then
268
333
  show_info "<target_version> : ${TARGET_VERSION}"
269
334
  fi
270
335
 
271
- if [ ! -z "$2" ]; then
272
- SRC_DIR=$(abspath "$2")
336
+ if [ ! -z "${SRC_DIR}" ]; then
337
+ SRC_DIR=$(abspath "${SRC_DIR}")
273
338
  else
274
339
  SRC_DIR="${CURRENT_DIR}"
275
340
  fi
@@ -279,9 +344,9 @@ if [ ! -f "${SRC_DIR}/CMakeLists.txt" ]; then
279
344
  show_usage "Source directory does not contain root CMakeLists.txt file!" 1
280
345
  fi
281
346
 
282
- if [ ! -z "$3" ]; then
283
- mkdir -p "$3"
284
- BUILD_DIR=$(abspath "$3")
347
+ if [ ! -z "${BUILD_DIR}" ]; then
348
+ mkdir -p "${BUILD_DIR}"
349
+ BUILD_DIR=$(abspath "${BUILD_DIR}")
285
350
  else
286
351
  BUILD_DIR="${CURRENT_DIR}/build/${TARGET_NAME}/${TARGET_VERSION}"
287
352
  mkdir -p "${BUILD_DIR}"
@@ -289,9 +354,9 @@ else
289
354
  fi
290
355
  show_info "<build_dir>: ${BUILD_DIR}"
291
356
 
292
- if [ ! -z "$4" ]; then
293
- mkdir -p "$4"
294
- INSTALL_DIR=$(abspath "$4")
357
+ if [ ! -z "${INSTALL_DIR}" ]; then
358
+ mkdir -p "${INSTALL_DIR}"
359
+ INSTALL_DIR=$(abspath "${INSTALL_DIR}")
295
360
  else
296
361
  INSTALL_DIR="${CURRENT_DIR}/install/${TARGET_NAME}/${TARGET_VERSION}"
297
362
  mkdir -p "${INSTALL_DIR}"
@@ -299,6 +364,10 @@ else
299
364
  fi
300
365
  show_info "<install_dir>: ${INSTALL_DIR}"
301
366
 
367
+ if [ ! -z "${FEATURES[*]}" ]; then
368
+ show_info "Requested features: ${FEATURES[*]}"
369
+ fi
370
+
302
371
  # Define common build parameters
303
372
  CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Release"
304
373
 
@@ -321,42 +390,95 @@ if [ ! -z "${INSTALL_DIR}" ]; then
321
390
  CMAKE_ARGS+=" -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}"
322
391
  fi
323
392
 
393
+ if [ ! -z "${FEATURES[*]}" ]; then
394
+ for feature in ${FEATURES[*]}; do
395
+ case ${feature} in
396
+ pythia)
397
+ feature_upper=$(echo "${feature}" | awk '{print toupper($0)}')
398
+ CMAKE_ARGS+=" -DVIRGIL_CRYPTO_FEATURE_${feature_upper}=ON"
399
+ ;;
400
+ *)
401
+ show_error "Undefined feature '${feature}'."
402
+ ;;
403
+ esac
404
+ done
405
+ fi
406
+
407
+
324
408
  # Go to the build directory
325
409
  cd "${INSTALL_DIR}" && rm -fr ./*
326
410
  cd "${BUILD_DIR}" && rm -fr ./*
327
411
 
328
412
  # Build for native platforms
329
- if [[ ${TARGET_NAME} =~ ^(cpp|java|php|python|ruby|nodejs|go)$ ]]; then
413
+ if [[ ${TARGET_NAME} =~ ^(cpp|java|net|php|python|ruby|nodejs|go)$ ]]; then
414
+ CMAKE_ARGS+=" -DVIRGIL_CRYPTO_FEATURE_PYTHIA=ON"
330
415
  cmake ${CMAKE_ARGS} -DLANG=${TARGET_NAME} -DPLATFORM_VERSION=${SYSTEM_KERNEL_RELEASE_VERSION} "${SRC_DIR}"
331
416
  make -j8 install
332
417
  fi
333
418
 
334
- # Build for Mono Unix/Linux
335
- if [ "${TARGET_NAME}" == "net" ] && [ "${SYSTEM_NAME}" != "darwin" ]; then
336
- cmake ${CMAKE_ARGS} -DLANG=${TARGET_NAME} -DPLATFORM_VERSION=${SYSTEM_KERNEL_RELEASE_VERSION} "${SRC_DIR}"
419
+ # Build framework for Apple iOS (with Pythia)
420
+ if [ "${TARGET_NAME}" == "ios" ]; then
421
+
422
+ CMAKE_ARGS+=" -LANG=cpp"
423
+ CMAKE_ARGS+=" -DINSTALL_CORE_HEADERS=NO"
424
+ CMAKE_ARGS+=" -DINSTALL_EXT_LIBS=NO"
425
+ CMAKE_ARGS+=" -DINSTALL_EXT_HEADERS=NO"
426
+ CMAKE_ARGS+=" -DCMAKE_TOOLCHAIN_FILE='${SRC_DIR}/cmake/apple.cmake'"
427
+ CMAKE_ARGS+=" -DVIRGIL_CRYPTO_FEATURE_PYTHIA=ON"
428
+
429
+ # Build for device (Pythia is in a multi-thread mode!!!)
430
+ rm -fr -- *
431
+ cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=IOS \
432
+ -DVIRGIL_CRYPTO_FEATURE_PYTHIA_MT=ON \
433
+ -DINSTALL_LIB_DIR_NAME=lib/dev "${SRC_DIR}"
337
434
  make -j8 install
435
+
436
+ # Build for i386 simulator (Pythia is in a single-thread mode!!!)
437
+ rm -fr -- *
438
+ cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=IOS_SIM32 \
439
+ -DVIRGIL_CRYPTO_FEATURE_PYTHIA_MT=OFF \
440
+ -DINSTALL_LIB_DIR_NAME=lib/sim32 "${SRC_DIR}"
441
+ make -j8 install
442
+
443
+ # Build for x86_64 simulator (Pythia is in a multi-thread mode!!!)
444
+ rm -fr -- *
445
+ cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=IOS_SIM64 \
446
+ -DVIRGIL_CRYPTO_FEATURE_PYTHIA_MT=ON \
447
+ -DINSTALL_LIB_DIR_NAME=lib/sim64 "${SRC_DIR}"
448
+ make -j8 install
449
+
450
+ make_fat_framework VSCCrypto "${INSTALL_DIR}" "${INSTALL_DIR}"
451
+
452
+ rm -fr "${INSTALL_DIR:?}/include"
453
+ rm -fr "${INSTALL_DIR:?}/lib"
338
454
  fi
339
455
 
340
- # Build for Apple plaforms create Apple Framework
341
- if [ "${TARGET_NAME}" == "ios" ] || [ "${TARGET_NAME}" == "tvos" ] || \
342
- [ "${TARGET_NAME}" == "watchos" ] || [ "${TARGET_NAME}" == "macos" ]; then
456
+ # Build framework for Apple tvOS, watchOS, macOS (without Pythia)
457
+ if [ "${TARGET_NAME}" == "tvos" ] || [ "${TARGET_NAME}" == "watchos" ] || [ "${TARGET_NAME}" == "macos" ]; then
343
458
 
344
- APPLE_PLATFORM=$(echo "${TARGET_NAME}" | awk '{print toupper($0)}')
459
+ APPLE_PLATFORM_DEVICE=$(echo "${TARGET_NAME}" | awk '{print toupper($0)}')
460
+ APPLE_PLATFORM_SIMULATOR="${APPLE_PLATFORM_DEVICE}_SIM"
345
461
 
346
462
  CMAKE_ARGS+=" -LANG=cpp"
347
463
  CMAKE_ARGS+=" -DINSTALL_CORE_HEADERS=NO"
348
464
  CMAKE_ARGS+=" -DINSTALL_EXT_LIBS=NO"
349
465
  CMAKE_ARGS+=" -DINSTALL_EXT_HEADERS=NO"
350
466
  CMAKE_ARGS+=" -DCMAKE_TOOLCHAIN_FILE='${SRC_DIR}/cmake/apple.cmake'"
467
+ CMAKE_ARGS+=" -DVIRGIL_CRYPTO_FEATURE_PYTHIA=ON"
351
468
 
352
469
  # Build for device
353
- cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=${APPLE_PLATFORM} -DINSTALL_LIB_DIR_NAME=lib/dev "${SRC_DIR}"
470
+ cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=${APPLE_PLATFORM_DEVICE} -DINSTALL_LIB_DIR_NAME=lib/dev "${SRC_DIR}"
354
471
  make -j8 install
355
472
 
356
473
  if [ "${TARGET_NAME}" != "macos" ]; then
357
474
  # Build for simulator
475
+
476
+ if [ "${TARGET_NAME}" == "watchos" ]; then
477
+ CMAKE_ARGS+=" -DVIRGIL_CRYPTO_FEATURE_PYTHIA_MT=OFF"
478
+ fi
479
+
358
480
  rm -fr ./*
359
- cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=${APPLE_PLATFORM}_SIM -DINSTALL_LIB_DIR_NAME=lib/sim "${SRC_DIR}"
481
+ cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=${APPLE_PLATFORM_SIMULATOR} -DINSTALL_LIB_DIR_NAME=lib/sim "${SRC_DIR}"
360
482
  make -j8 install
361
483
  fi
362
484
 
@@ -370,6 +492,7 @@ if [[ "${TARGET_NAME}" == *"android"* ]]; then
370
492
  if [ ! -d "$ANDROID_NDK" ]; then
371
493
  show_usage "Enviroment \$ANDROID_NDK is not defined!" 1
372
494
  fi
495
+
373
496
  if [ "${TARGET_NAME}" == "java_android" ]; then
374
497
  CMAKE_ARGS+=" -DLANG=java"
375
498
  elif [ "${TARGET_NAME}" == "net_android" ]; then
@@ -377,25 +500,67 @@ if [[ "${TARGET_NAME}" == *"android"* ]]; then
377
500
  else
378
501
  show_usage "Unsupported target: ${TARGET_NAME}!"
379
502
  fi
503
+
504
+ CMAKE_ARGS+=" -DVIRGIL_CRYPTO_FEATURE_PYTHIA=ON"
505
+
380
506
  function build_android() {
381
507
  # Build architecture: $1
382
508
  rm -fr ./*
383
- cmake ${CMAKE_ARGS} -DANDROID_ABI="$1" -DCMAKE_TOOLCHAIN_FILE="${SRC_DIR}/cmake/android.toolchain.cmake" "${SRC_DIR}"
509
+ cmake ${CMAKE_ARGS} -DANDROID_ABI="$1" -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" "${SRC_DIR}"
384
510
  make -j8 install
385
511
  }
512
+
386
513
  build_android x86
387
514
  build_android x86_64
388
- build_android mips
389
- build_android mips64
390
- build_android armeabi
391
515
  build_android armeabi-v7a
392
516
  build_android arm64-v8a
393
517
  fi
394
518
 
395
- if [ "${TARGET_NAME}" == "net_ios" ] || [ "${TARGET_NAME}" == "net_tvos" ] || \
396
- [ "${TARGET_NAME}" == "net_watchos" ] || [ "${TARGET_NAME}" == "net_macos" ]; then
519
+ # Build for Mono iOS (with Pyhia)
520
+ if [ "${TARGET_NAME}" == "net_ios" ]; then
521
+
522
+ CMAKE_ARGS+=" -DLANG=net"
523
+ CMAKE_ARGS+=" -DINSTALL_CORE_LIBS=ON"
524
+ CMAKE_ARGS+=" -DINSTALL_CORE_HEADERS=OFF"
525
+ CMAKE_ARGS+=" -DINSTALL_EXT_LIBS=ON"
526
+ CMAKE_ARGS+=" -DINSTALL_EXT_HEADERS=OFF"
527
+ CMAKE_ARGS+=" -DCMAKE_TOOLCHAIN_FILE='${SRC_DIR}/cmake/apple.cmake'"
528
+ CMAKE_ARGS+=" -DVIRGIL_CRYPTO_FEATURE_PYTHIA=ON"
529
+
530
+ # Build for device (Pythia is in a multi-thread mode!!!)
531
+ rm -fr -- *
532
+ cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=IOS \
533
+ -DVIRGIL_CRYPTO_FEATURE_PYTHIA_MT=ON \
534
+ -DINSTALL_LIB_DIR_NAME=lib/dev "${SRC_DIR}"
535
+ make -j8 install
536
+
537
+ # Build for i386 simulator (Pythia is in a single-thread mode!!!)
538
+ rm -fr -- *
539
+ cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=IOS_SIM32 \
540
+ -DVIRGIL_CRYPTO_FEATURE_PYTHIA_MT=OFF \
541
+ -DINSTALL_LIB_DIR_NAME=lib/sim32 "${SRC_DIR}"
542
+ make -j8 install
543
+
544
+ # Build for x86_64 simulator (Pythia is in a multi-thread mode!!!)
545
+ rm -fr -- *
546
+ cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=IOS_SIM64 \
547
+ -DVIRGIL_CRYPTO_FEATURE_PYTHIA_MT=ON \
548
+ -DINSTALL_LIB_DIR_NAME=lib/sim64 "${SRC_DIR}"
549
+ make -j8 install
550
+
551
+ # Create fat library
552
+ make_fat_library libVirgilCryptoNet.a "${INSTALL_DIR}" "${INSTALL_DIR}/libs" "net"
553
+ find "${INSTALL_DIR:?}" -name "*.dll" -exec cp -f {} "${INSTALL_DIR:?}/libs/" \;
554
+ rm -fr "${INSTALL_DIR:?}/include"
555
+ rm -fr "${INSTALL_DIR:?}/lib"
556
+ mv "${INSTALL_DIR:?}/libs" "${INSTALL_DIR:?}/lib"
557
+ fi
558
+
559
+ # Build for Mono tvOS and Mono watchOS (without Pythia)
560
+ if [ "${TARGET_NAME}" == "net_tvos" ] || [ "${TARGET_NAME}" == "net_watchos" ]; then
397
561
 
398
- APPLE_PLATFORM=$(echo "${TARGET_NAME/net_/}" | awk '{print toupper($0)}')
562
+ APPLE_PLATFORM_DEVICE=$(echo "${TARGET_NAME/net_/}" | awk '{print toupper($0)}')
563
+ APPLE_PLATFORM_SIMULATOR="${APPLE_PLATFORM_DEVICE}_SIM"
399
564
 
400
565
  CMAKE_ARGS+=" -DLANG=net"
401
566
  CMAKE_ARGS+=" -DINSTALL_CORE_LIBS=ON"
@@ -405,15 +570,13 @@ if [ "${TARGET_NAME}" == "net_ios" ] || [ "${TARGET_NAME}" == "net_tvos" ] || \
405
570
  CMAKE_ARGS+=" -DCMAKE_TOOLCHAIN_FILE='${SRC_DIR}/cmake/apple.cmake'"
406
571
 
407
572
  # Build for device
408
- cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=${APPLE_PLATFORM} -DINSTALL_LIB_DIR_NAME=lib/dev "${SRC_DIR}"
573
+ cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=${APPLE_PLATFORM_DEVICE} -DINSTALL_LIB_DIR_NAME=lib/dev "${SRC_DIR}"
409
574
  make -j8 install
410
575
 
411
- if [ "${TARGET_NAME}" != "net_macos" ]; then
412
- # Build for simulator
413
- rm -fr ./*
414
- cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=${APPLE_PLATFORM}_SIM -DINSTALL_LIB_DIR_NAME=lib/sim "${SRC_DIR}"
415
- make -j8 install
416
- fi
576
+ # Build for simulator
577
+ rm -fr ./*
578
+ cmake ${CMAKE_ARGS} -DAPPLE_PLATFORM=${APPLE_PLATFORM_SIMULATOR} -DINSTALL_LIB_DIR_NAME=lib/sim "${SRC_DIR}"
579
+ make -j8 install
417
580
 
418
581
  # Create fat library
419
582
  make_fat_library libVirgilCryptoNet.a "${INSTALL_DIR}" "${INSTALL_DIR}/libs" "net"
@@ -429,13 +592,20 @@ if [[ "${TARGET_NAME}" =~ (asmjs|webasm) ]]; then
429
592
  fi
430
593
  source "${EMSDK_HOME}/emsdk_env.sh"
431
594
 
432
- cmake ${CMAKE_ARGS} -DLANG=${TARGET_NAME} \
595
+ CMAKE_ARGS+=" -DVIRGIL_PACKAGE_NAME_FEATURES=ON"
596
+
597
+ cmake ${CMAKE_ARGS} \
598
+ -DLANG=${TARGET_NAME} \
433
599
  -DCMAKE_TOOLCHAIN_FILE="$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake" \
434
600
  -DCMAKE_CXX_FLAGS_RELEASE="-O3" \
435
601
  "${SRC_DIR}"
436
602
  make -j8 install
437
603
  fi
438
604
 
605
+ if [ -z "$(ls -A ./)" ]; then
606
+ show_usage "Given target '${TARGET_NAME}' is not supported." 1
607
+ fi
608
+
439
609
  if [[ ${TARGET_NAME} =~ (ios|tvos|watchos|macos|android) ]]; then
440
610
  ARCH_NAME=$(cat "${BUILD_DIR}/lib_name.txt")
441
611
  else