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.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/.gitmodules +0 -0
- data/.travis.yml +13 -0
- data/Gemfile +0 -0
- data/README.md +113 -9
- data/Rakefile +0 -0
- data/ext/native/src/.clang-format +37 -0
- data/ext/native/src/.gitignore +3 -0
- data/ext/native/src/.travis.yml +2 -1
- data/ext/native/src/CMakeLists.txt +66 -63
- data/ext/native/src/ChangeLog +114 -2
- data/ext/native/src/Dockerfile_Golang +29 -8
- data/ext/native/src/Jenkinsfile +61 -50
- data/ext/native/src/LICENSE +0 -0
- data/ext/native/src/README.md +137 -167
- data/ext/native/src/VERSION +1 -1
- data/ext/native/src/benchmark.md +140 -0
- data/ext/native/src/benchmark/CMakeLists.txt +0 -0
- data/ext/native/src/benchmark/benchmark_cipher.cxx +0 -0
- data/ext/native/src/benchmark/benchmark_hash.cxx +0 -0
- data/ext/native/src/benchmark/benchmark_keys.cxx +0 -0
- data/ext/native/src/benchmark/benchmark_pythia.cxx +61 -0
- data/ext/native/src/benchmark/benchmark_random.cxx +0 -0
- data/ext/native/src/benchmark/benchmark_signer.cxx +0 -0
- data/ext/native/src/ci/install-dependencies.sh +8 -12
- data/ext/native/src/ci/publish-docs.sh +107 -22
- data/ext/native/src/ci/travis-deployment-key.enc +0 -0
- data/ext/native/src/cmake/TransitiveArgs.cmake +78 -0
- data/ext/native/src/cmake/TransitiveToolchainArgs.cmake +105 -0
- data/ext/native/src/cmake/add_mono_metadata.cmake +103 -0
- data/ext/native/src/cmake/apple.cmake +56 -11
- data/ext/native/src/cmake/aux_source_directory_to_file.cmake +0 -0
- data/ext/native/src/cmake/check_pointer_size.cmake +0 -0
- data/ext/native/src/cmake/copy_all_files.cmake +0 -0
- data/ext/native/src/cmake/file_regex_replace.cmake +0 -0
- data/ext/native/src/cmake/find_host_utils.cmake +0 -0
- data/ext/native/src/cmake/uppercase_first_char.cmake +0 -0
- data/ext/native/src/cmake/uppercase_namespaces.cmake +3 -0
- data/ext/native/src/cmake/virgil_depends.cmake +0 -0
- data/ext/native/src/cmake/virgil_depends_local.cmake +2 -0
- data/ext/native/src/docs/.gitignore +0 -0
- data/ext/native/src/lib/CMakeLists.txt +59 -1
- data/ext/native/src/lib/Doxyfile.in +1 -1
- data/ext/native/src/lib/Info.plist.in +0 -0
- data/ext/native/src/lib/cmake/config.cmake.in +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilByteArrayUtils.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilChunkCipher.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilCipherBase.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilContentInfo.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilCrypto.h +13 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilCryptoError.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilCustomParams.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilKeyPair.h +30 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilSignerBase.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilStreamCipher.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilStreamSigner.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilTinyCipher.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/VirgilVersion.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilAsymmetricCipher.h +17 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilHKDF.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilPBKDF.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilSystemCryptoError.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/asn1/VirgilAsn1Compatible.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSContent.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSContentInfo.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSEncryptedContent.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSEnvelopedData.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSKeyTransRecipient.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSPasswordRecipient.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFS.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSEncryptedMessage.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSInitiatorPrivateInfo.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSInitiatorPublicInfo.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSPrivateKey.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSPublicKey.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSResponderPrivateInfo.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSResponderPublicInfo.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSSession.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationCipher.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationDH.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationHash.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationKDF.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationRandom.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythia.h +181 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaBlindResult.h +89 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaContext.h +72 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaError.h +161 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaProveResult.h +89 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaTransformResult.h +91 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaTransformationKeyPair.h +87 -0
- data/ext/native/src/lib/include/virgil/crypto/pythia/virgil_pythia_c.h +203 -0
- data/ext/native/src/lib/include/virgil/crypto/stream/VirgilBytesDataSink.h +0 -0
- data/ext/native/src/lib/include/virgil/crypto/stream/VirgilBytesDataSource.h +0 -0
- data/ext/native/src/lib/mainpage.dox +6 -0
- data/ext/native/src/lib/module.modulemap +7 -0
- data/ext/native/src/lib/src/VirgilAsn1Alg.cxx +0 -0
- data/ext/native/src/lib/src/VirgilAsn1Alg.h +0 -0
- data/ext/native/src/lib/src/VirgilAsn1Compatible.cxx +0 -0
- data/ext/native/src/lib/src/VirgilAsymmetricCipher.cxx +82 -0
- data/ext/native/src/lib/src/VirgilByteArrayUtils.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCMSContent.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCMSContentInfo.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCMSEncryptedContent.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCMSEnvelopedData.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCMSKeyTransRecipient.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCMSPasswordRecipient.cxx +0 -0
- data/ext/native/src/lib/src/VirgilChunkCipher.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCipherBase.cxx +0 -0
- data/ext/native/src/lib/src/VirgilConfig.cxx +51 -0
- data/ext/native/src/lib/src/VirgilConfig.h.in +43 -1
- data/ext/native/src/lib/src/VirgilContentInfo.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCryptoError.cxx +0 -0
- data/ext/native/src/lib/src/VirgilCustomParams.cxx +0 -0
- data/ext/native/src/lib/src/VirgilDataSink.cxx +0 -0
- data/ext/native/src/lib/src/VirgilHKDF.cxx +0 -0
- data/ext/native/src/lib/src/VirgilKeyPair.cxx +19 -0
- data/ext/native/src/lib/src/VirgilOID.h +0 -0
- data/ext/native/src/lib/src/VirgilPBKDF.cxx +0 -0
- data/ext/native/src/lib/src/VirgilSignerBase.cxx +0 -0
- data/ext/native/src/lib/src/VirgilStreamCipher.cxx +0 -0
- data/ext/native/src/lib/src/VirgilStreamSigner.cxx +0 -0
- data/ext/native/src/lib/src/VirgilSystemCryptoError.cxx +0 -0
- data/ext/native/src/lib/src/VirgilTagFilter.cxx +0 -0
- data/ext/native/src/lib/src/VirgilTagFilter.h +0 -0
- data/ext/native/src/lib/src/VirgilTinyCipher.cxx +0 -0
- data/ext/native/src/lib/src/VirgilVersion.cxx.in +0 -0
- data/ext/native/src/lib/src/mbedtls_context.h +0 -0
- data/ext/native/src/lib/src/mbedtls_context_policy_spec.h +0 -0
- data/ext/native/src/lib/src/mbedtls_type_utils.h +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFS.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSEncryptedMessage.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSInitiatorPrivateInfo.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSInitiatorPublicInfo.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSPrivateKey.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSPublicKey.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSResponderPrivateInfo.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSResponderPublicInfo.cxx +0 -0
- data/ext/native/src/lib/src/pfs/VirgilPFSSession.cxx +0 -0
- data/ext/native/src/lib/src/primitive/VirgilOperationCipher.cxx +0 -0
- data/ext/native/src/lib/src/primitive/VirgilOperationDH.cxx +0 -0
- data/ext/native/src/lib/src/primitive/VirgilOperationHash.cxx +0 -0
- data/ext/native/src/lib/src/primitive/VirgilOperationKDF.cxx +0 -0
- data/ext/native/src/lib/src/primitive/VirgilOperationRandom.cxx +0 -0
- data/ext/native/src/lib/src/pythia/VirgilPythia.cxx +202 -0
- data/ext/native/src/lib/src/pythia/VirgilPythiaContext.cxx +116 -0
- data/ext/native/src/lib/src/pythia/VirgilPythiaError.cxx +58 -0
- data/ext/native/src/lib/src/pythia/virgil_pythia_c.cxx +129 -0
- data/ext/native/src/lib/src/stream/VirgilBytesDataSink.cxx +0 -0
- data/ext/native/src/lib/src/stream/VirgilBytesDataSource.cxx +0 -0
- data/ext/native/src/lib/src/utils.h +3 -2
- data/ext/native/src/libs_ext/mbedtls/configs/config.h +0 -0
- data/ext/native/src/libs_ext/mbedtls/configs/config_desktop.h +0 -0
- data/ext/native/src/libs_ext/mbedtls/mbedtls.cmake +0 -0
- data/ext/native/src/{cmake/cmake_args.cmake → libs_ext/pythia/pythia.cmake} +24 -28
- data/ext/native/src/libs_ext/rapidjson/rapidjson.cmake +0 -0
- data/ext/native/src/libs_ext/tinyformat/cmake/config.cmake.in +0 -0
- data/ext/native/src/libs_ext/tinyformat/tinyformat.cmake +0 -0
- data/ext/native/src/migration-2.0.md +0 -0
- data/ext/native/src/tests/CMakeLists.txt +0 -0
- data/ext/native/src/tests/catch.hpp +0 -0
- data/ext/native/src/tests/data/test_data_pfs_with_otc.json +0 -0
- data/ext/native/src/tests/data/test_data_pfs_without_otc.json +0 -0
- data/ext/native/src/tests/deterministic_keys.h +293 -0
- data/ext/native/src/tests/rsa_keys.h +229 -123
- data/ext/native/src/tests/test_asn1_writer.cxx +0 -0
- data/ext/native/src/tests/test_asymmetric_cipher.cxx +65 -0
- data/ext/native/src/tests/test_base64.cxx +0 -0
- data/ext/native/src/tests/test_byte_array_utils.cxx +0 -0
- data/ext/native/src/tests/test_chunk_cipher.cxx +0 -0
- data/ext/native/src/tests/test_cipher.cxx +8 -4
- data/ext/native/src/tests/test_cipher_base.cxx +0 -0
- data/ext/native/src/tests/test_contract_copy_move.cxx +4 -1
- data/ext/native/src/tests/test_data_pfs.h +0 -0
- data/ext/native/src/tests/test_hash.cxx +0 -0
- data/ext/native/src/tests/test_hkdf.cxx +0 -0
- data/ext/native/src/tests/test_key_pair.cxx +65 -3
- data/ext/native/src/tests/test_pbe.cxx +0 -0
- data/ext/native/src/tests/test_pbkdf.cxx +0 -0
- data/ext/native/src/tests/test_pfs.cxx +0 -0
- data/ext/native/src/tests/test_pythia.cxx +157 -0
- data/ext/native/src/tests/test_random.cxx +0 -0
- data/ext/native/src/tests/test_runner.cxx +0 -0
- data/ext/native/src/tests/test_signer.cxx +0 -0
- data/ext/native/src/tests/test_stream_cipher.cxx +0 -0
- data/ext/native/src/tests/test_stream_data_source.cxx +0 -0
- data/ext/native/src/tests/test_symmetric_cipher.cxx +0 -0
- data/ext/native/src/tests/test_tag_filter.cxx +0 -0
- data/ext/native/src/tests/test_tiny_cipher.cxx +0 -0
- data/ext/native/src/utils/build.bat +0 -0
- data/ext/native/src/utils/build.sh +238 -68
- data/ext/native/src/utils/zip.vbs +0 -0
- data/ext/native/src/virgil-crypto.sublime-project +15 -0
- data/ext/native/src/wrappers/asmjs/CMakeLists.txt +0 -8
- data/ext/native/src/wrappers/emsdk/CMakeLists.txt +2 -2
- data/ext/native/src/wrappers/emsdk/error.js +0 -0
- data/ext/native/src/wrappers/emsdk/example.html +152 -31
- data/ext/native/src/wrappers/emsdk/helpers.js +140 -135
- data/ext/native/src/wrappers/emsdk/patch_embind.pl +0 -0
- data/ext/native/src/wrappers/emsdk/wrapper.cxx +55 -0
- data/ext/native/src/wrappers/go/CMakeLists.txt +6 -5
- data/ext/native/src/wrappers/java/CMakeLists.txt +27 -4
- data/ext/native/src/wrappers/java/src/JniLoader.java +167 -0
- data/ext/native/src/wrappers/java/src/VirgilStreamDataSink.java +0 -0
- data/ext/native/src/wrappers/java/src/VirgilStreamDataSource.java +0 -0
- data/ext/native/src/wrappers/net/CMakeLists.txt +41 -8
- data/ext/native/src/wrappers/net/cmake/UseCSharp.cmake +5 -5
- data/ext/native/src/wrappers/net/src/VirgilStreamDataSink.cs +0 -0
- data/ext/native/src/wrappers/net/src/VirgilStreamDataSource.cs +0 -0
- data/ext/native/src/wrappers/nodejs/checksum.txt +66 -0
- data/ext/native/src/wrappers/php/CMakeLists.txt +2 -5
- data/ext/native/src/wrappers/php/tests/CMakeLists.txt +6 -0
- data/ext/native/src/wrappers/php/tests/VirgilChunkCipher_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilCustomParams_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilKDF_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilPBE_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilPBKDF_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilPythia_Test.php.in +87 -0
- data/ext/native/src/wrappers/php/tests/VirgilStreamCipher_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilStreamSigner_Test.php.in +0 -0
- data/ext/native/src/wrappers/php/tests/VirgilVersion_Test.php.in +0 -0
- data/ext/native/src/wrappers/python/CMakeLists.txt +4 -1
- data/ext/native/src/wrappers/ruby/CMakeLists.txt +4 -1
- data/ext/native/src/wrappers/swig/common.i +0 -0
- data/ext/native/src/wrappers/swig/csharp/FixedArray.i +0 -0
- data/ext/native/src/wrappers/swig/csharp/VirgilByteArray.i +0 -0
- data/ext/native/src/wrappers/swig/csharp/common.i +0 -0
- data/ext/native/src/wrappers/swig/csharp/csharphead.swg.in +0 -0
- data/ext/native/src/wrappers/swig/go/common.i.in +7 -0
- data/ext/native/src/wrappers/swig/java/VirgilByteArray.i +0 -0
- data/ext/native/src/wrappers/swig/java/common.i +6 -0
- data/ext/native/src/wrappers/swig/php/common.i +0 -0
- data/ext/native/src/wrappers/swig/php/php7/VirgilByteArray.i +0 -0
- data/ext/native/src/wrappers/swig/util.i +0 -0
- data/ext/native/src/wrappers/swig/wrapper.i.in +18 -7
- data/ext/native/src/wrappers/webasm/CMakeLists.txt +0 -8
- data/ext/rakefile.rb +77 -56
- data/lib/virgil/crypto.rb +53 -9
- data/lib/virgil/crypto/access_token_signer.rb +79 -0
- data/lib/virgil/crypto/bytes.rb +81 -17
- data/lib/virgil/crypto/card_crypto.rb +115 -0
- data/lib/virgil/crypto/crypto_exception.rb +40 -0
- data/lib/virgil/crypto/hash_algorithm.rb +82 -0
- data/lib/virgil/crypto/key_pair.rb +41 -0
- data/lib/virgil/crypto/key_pair_type.rb +98 -0
- data/lib/virgil/crypto/private_key.rb +40 -0
- data/lib/virgil/crypto/private_key_exporter.rb +67 -0
- data/lib/virgil/crypto/public_key.rb +40 -0
- data/lib/virgil/crypto/{virgil_stream_data_sink.rb → stream_data_sink.rb} +12 -12
- data/lib/virgil/crypto/{virgil_stream_data_source.rb → stream_data_source.rb} +12 -12
- data/lib/virgil/crypto/validation.rb +59 -0
- data/lib/virgil/crypto/version.rb +35 -1
- data/lib/virgil/crypto/virgil_crypto.rb +595 -0
- data/lib/virgil/native_crypto.rb +80 -60
- data/lib/virgil/os.rb +40 -6
- data/secrets.tar.enc +0 -0
- data/virgil-crypto.gemspec +6 -7
- metadata +62 -12
- data/ext/native/src/cmake/android.toolchain.cmake +0 -1697
File without changes
|
@@ -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
|
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 =
|
7
|
-
var keys =
|
8
|
-
var certId =
|
9
|
-
var data =
|
10
|
-
var cipher = new
|
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 =
|
27
|
-
var keys =
|
28
|
-
var certId =
|
29
|
-
var data =
|
30
|
-
var cipher = new
|
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
|
34
|
-
var dataSink = new
|
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
|
38
|
-
var decryptedDataSink = new
|
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 =
|
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 =
|
60
|
-
var keys =
|
61
|
-
var
|
62
|
-
var
|
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
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
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
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
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
|
+
})();
|