├── VERSION ├── docs └── .gitignore ├── wrappers ├── php │ └── tests │ │ ├── data │ │ ├── asn1_integer.der │ │ ├── asn1_utf8_string.der │ │ ├── asn1_complex.der │ │ ├── asn1_sequence.der │ │ ├── asn1_custom_tag.der │ │ ├── asn1_octet_string.der │ │ ├── certificate_public_key.pem │ │ └── CMakeLists.txt │ │ ├── StringSink.php.in │ │ ├── VirgilRandom_Test.php.in │ │ ├── StringSource.php.in │ │ ├── VirgilPBKDF_Test.php.in │ │ └── VirgilVersion_Test.php.in ├── net │ ├── cmake │ │ ├── UseDotNetFrameworkSdk.cmake │ │ └── UseMono.cmake │ └── src │ │ ├── VirgilStreamDataSink.cs │ │ ├── VirgilStreamDataSource.cs │ │ └── AssemblyInfo.cs ├── swig │ ├── csharp │ │ ├── VirgilByteArray.i │ │ └── common.i │ ├── go │ │ └── common.i.in │ ├── java │ │ └── common.i │ └── util.i ├── emsdk │ └── error.js ├── java │ └── src │ │ ├── VirgilStreamDataSink.java │ │ └── VirgilStreamDataSource.java ├── CMakeLists.txt └── asmjs │ └── CMakeLists.txt ├── ci ├── travis-deployment-key.enc └── install-deployment-key.sh ├── lib ├── module.modulemap ├── src │ ├── VirgilVersion.cxx.in │ ├── VirgilDataSink.cxx │ ├── VirgilConfig.cxx │ ├── primitive │ │ ├── VirgilOperationRandom.cxx │ │ ├── VirgilOperationHash.cxx │ │ ├── VirgilOperationDH.cxx │ │ └── VirgilOperationKDF.cxx │ ├── pfs │ │ ├── VirgilPFSPublicKey.cxx │ │ ├── VirgilPFSPrivateKey.cxx │ │ ├── VirgilPFSInitiatorPublicInfo.cxx │ │ ├── VirgilPFSEncryptedMessage.cxx │ │ ├── VirgilPFSInitiatorPrivateInfo.cxx │ │ ├── VirgilPFSResponderPublicInfo.cxx │ │ └── VirgilPFSResponderPrivateInfo.cxx │ ├── utils.h │ ├── pythia │ │ └── VirgilPythiaError.cxx │ ├── stream │ │ ├── VirgilStreamDataSink.cxx │ │ ├── VirgilBytesDataSink.cxx │ │ ├── VirgilStreamDataSource.cxx │ │ └── VirgilBytesDataSource.cxx │ ├── VirgilSystemCryptoError.cxx │ ├── VirgilAsn1Compatible.cxx │ ├── VirgilTagFilter.cxx │ ├── VirgilConfig.h.in │ ├── VirgilSigner.cxx │ └── VirgilStreamSigner.cxx ├── Info.plist.in ├── cmake │ └── config.cmake.in ├── mainpage.dox └── include │ └── virgil │ └── crypto │ ├── VirgilDataSource.h │ ├── foundation │ └── VirgilBase64.h │ ├── pythia │ └── VirgilPythiaContext.h │ ├── pfs │ ├── VirgilPFSPublicKey.h │ ├── VirgilPFSInitiatorPublicInfo.h │ └── VirgilPFSInitiatorPrivateInfo.h │ ├── VirgilDataSink.h │ ├── stream │ ├── VirgilStreamDataSink.h │ └── VirgilBytesDataSink.h │ └── VirgilVersion.h ├── .gitignore ├── virgil-crypto.sublime-project ├── libs_ext ├── mbedtls │ └── configs │ │ ├── config_desktop.h │ │ └── config.h ├── tinyformat │ ├── cmake │ │ └── config.cmake.in │ └── tinyformat.cmake ├── pythia │ └── pythia.cmake └── rapidjson │ └── rapidjson.cmake ├── .clang-format ├── LICENSE ├── utils ├── env.sh └── zip.vbs ├── tests ├── test_runner.cxx ├── CMakeLists.txt ├── test_stream_data_source.cxx └── test_tag_filter.cxx ├── Dockerfile_Golang ├── cmake ├── uppercase_first_char.cmake ├── find_host_utils.cmake ├── virgil_depends.cmake ├── check_pointer_size.cmake ├── file_regex_replace.cmake ├── copy_all_files.cmake ├── aux_source_directory_to_file.cmake └── TransitiveArgs.cmake ├── benchmark ├── CMakeLists.txt ├── benchmark_pythia.cxx └── benchmark_random.cxx └── .travis.yml /VERSION: -------------------------------------------------------------------------------- 1 | 2.6.4 2 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /wrappers/php/tests/data/asn1_integer.der: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /wrappers/php/tests/data/asn1_utf8_string.der: -------------------------------------------------------------------------------- 1 | Строка в UTF8 -------------------------------------------------------------------------------- /ci/travis-deployment-key.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirgilSecurity/virgil-crypto/HEAD/ci/travis-deployment-key.enc -------------------------------------------------------------------------------- /wrappers/php/tests/data/asn1_complex.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirgilSecurity/virgil-crypto/HEAD/wrappers/php/tests/data/asn1_complex.der -------------------------------------------------------------------------------- /wrappers/php/tests/data/asn1_sequence.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirgilSecurity/virgil-crypto/HEAD/wrappers/php/tests/data/asn1_sequence.der -------------------------------------------------------------------------------- /wrappers/php/tests/data/asn1_custom_tag.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirgilSecurity/virgil-crypto/HEAD/wrappers/php/tests/data/asn1_custom_tag.der -------------------------------------------------------------------------------- /wrappers/php/tests/data/asn1_octet_string.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirgilSecurity/virgil-crypto/HEAD/wrappers/php/tests/data/asn1_octet_string.der -------------------------------------------------------------------------------- /lib/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module VSCCrypto { 2 | header "pythia/pythia_buf.h" 3 | header "pythia/pythia_buf_sizes.h" 4 | header "pythia/virgil_pythia_c.h" 5 | 6 | export * 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ##### 2 | build*/ 3 | install/ 4 | docs/html/ 5 | docs/latex/ 6 | .depends_cache/ 7 | 8 | ##### 9 | # OS X temporary files that should never be committed 10 | 11 | .DS_Store 12 | *.swp 13 | *.lock 14 | profile 15 | 16 | ##### 17 | .idea 18 | 19 | ##### 20 | *.sublime-workspace 21 | -------------------------------------------------------------------------------- /wrappers/php/tests/data/certificate_public_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIGbMBQGByqGSM49AgEGCSskAwMCCAEBDQOBggAEA8GVpzCcTiISVsHjuMZg4gvS 3 | nIT5ubLZ6TZ8LRzPjYah5h71TrHOgJVXkPtzpFbHdWdvcSsAMbLCnvEnTlXFMDn5 4 | 3a3YhN+cTdWZCgleKQCc2keY/alCRdgtjL3po90DuT8WcxSreTlVGkE/TZvCZEes 5 | o+yIBPaohqMzfjvj4Yw= 6 | -----END PUBLIC KEY----- 7 | -------------------------------------------------------------------------------- /virgil-crypto.sublime-project: -------------------------------------------------------------------------------- 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 | } 16 | -------------------------------------------------------------------------------- /libs_ext/mbedtls/configs/config_desktop.h: -------------------------------------------------------------------------------- 1 | #ifndef VIRGIL_MBEDTLS_CONFIG_DESKTOP_H 2 | #define VIRGIL_MBEDTLS_CONFIG_DESKTOP_H 3 | 4 | #define MBEDTLS_PLATFORM_C 5 | #define MBEDTLS_HAVE_ASM 6 | #define MBEDTLS_PADLOCK_C 7 | #define MBEDTLS_HAVE_TIME 8 | #define MBEDTLS_HAVE_TIME_DATE 9 | #define MBEDTLS_AESNI_C 10 | #define MBEDTLS_TIMING_C 11 | #define MBEDTLS_HAVEGE_C 12 | 13 | #endif // VIRGIL_MBEDTLS_CONFIG_DESKTOP_H 14 | -------------------------------------------------------------------------------- /wrappers/net/cmake/UseDotNetFrameworkSdk.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # A CMake Module for using C# .NET. 3 | # 4 | # The following variables are set: 5 | # (none) 6 | # 7 | # This file is based on the work of GDCM: 8 | # http://gdcm.svn.sf.net/viewvc/gdcm/trunk/CMake/UseDotNETFrameworkSDK.cmake 9 | # Copyright (c) 2006-2010 Mathieu Malaterre 10 | # 11 | 12 | message( STATUS "Using .NET compiler version ${CSHARP_DOTNET_VERSION}" ) 13 | -------------------------------------------------------------------------------- /wrappers/net/cmake/UseMono.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # A CMake Module for using Mono. 3 | # 4 | # The following variables are set: 5 | # (none) 6 | # 7 | # Additional references can be found here: 8 | # http://www.mono-project.com/Main_Page 9 | # http://www.mono-project.com/CSharp_Compiler 10 | # 11 | # This file is based on the work of GDCM: 12 | # http://gdcm.svn.sf.net/viewvc/gdcm/trunk/CMake/FindMono.cmake 13 | # Copyright (c) 2006-2010 Mathieu Malaterre 14 | # 15 | 16 | message( STATUS "Using Mono compiler version ${CSHARP_MONO_VERSION}" ) -------------------------------------------------------------------------------- /lib/src/VirgilVersion.cxx.in: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using virgil::crypto::VirgilVersion; 5 | 6 | size_t VirgilVersion::asNumber() { 7 | return (majorVersion() << 16) | (minorVersion() << 8) | patchVersion(); 8 | } 9 | 10 | std::string VirgilVersion::asString() { 11 | return std::string("@VIRGIL_VERSION@"); 12 | } 13 | 14 | size_t VirgilVersion::majorVersion() { 15 | return @VIRGIL_VERSION_MAJOR@; 16 | } 17 | 18 | size_t VirgilVersion::minorVersion() { 19 | return @VIRGIL_VERSION_MINOR@; 20 | } 21 | 22 | size_t VirgilVersion::patchVersion() { 23 | return @VIRGIL_VERSION_PATCH@; 24 | } 25 | 26 | std::string VirgilVersion::fullName() { 27 | return std::string("@VIRGIL_VERSION_FULL_NAME@"); 28 | } 29 | -------------------------------------------------------------------------------- /lib/Info.plist.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${FRAMEWORK_NAME} 9 | CFBundleIdentifier 10 | ${FRAMEWORK_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | FMWK 15 | CFBundleSignature 16 | ???? 17 | CFBundleVersion 18 | ${BUNDLE_SOVERSION} 19 | CFBundleShortVersionString 20 | ${BUNDLE_VERSION} 21 | CSResourcesFileMapped 22 | 23 | MinimumOSVersion 24 | ${APPLE_DEPLOYMENT_TARGET} 25 | 26 | 27 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: LLVM 4 | Standard: Cpp11 5 | TabWidth: 4 6 | UseTab: Never 7 | ColumnLimit: 120 8 | IndentWidth: 4 9 | ConstructorInitializerIndentWidth: 8 10 | ContinuationIndentWidth: 8 11 | AllowShortFunctionsOnASingleLine : false 12 | DerivePointerAlignment: false 13 | PointerAlignment: Left 14 | AlignAfterOpenBracket: AlwaysBreak 15 | AccessModifierOffset: -4 16 | AllowAllParametersOfDeclarationOnNextLine: true 17 | BinPackArguments: true 18 | BinPackParameters: true 19 | AlwaysBreakBeforeMultilineStrings: true 20 | MaxEmptyLinesToKeep: 2 21 | BraceWrapping: 22 | AfterClass: false 23 | AfterControlStatement: false 24 | AfterEnum: false 25 | AfterFunction: false 26 | AfterNamespace: false 27 | AfterObjCDeclaration: false 28 | AfterStruct: false 29 | AfterUnion: false 30 | AfterExternBlock: false 31 | BeforeCatch: false 32 | BeforeElse: false 33 | IndentBraces: false 34 | SplitEmptyFunction: true 35 | SplitEmptyRecord: true 36 | SplitEmptyNamespace: true 37 | ... 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2015-2018 Virgil Security Inc. 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | (1) Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | (2) Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | (3) Neither the name of the copyright holder nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | 33 | Lead Maintainer: Virgil Security Inc. 34 | -------------------------------------------------------------------------------- /utils/env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (C) 2015-2018 Virgil Security Inc. 4 | # 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions are 9 | # met: 10 | # 11 | # (1) Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 14 | # (2) Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in 16 | # the documentation and/or other materials provided with the 17 | # distribution. 18 | # 19 | # (3) Neither the name of the copyright holder nor the names of its 20 | # contributors may be used to endorse or promote products derived from 21 | # this software without specific prior written permission. 22 | # 23 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 24 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 27 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # 35 | # Lead Maintainer: Virgil Security Inc. 36 | # 37 | 38 | # 39 | # Modify this script to configure environment 40 | # 41 | -------------------------------------------------------------------------------- /wrappers/swig/csharp/VirgilByteArray.i: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | %include "csharp/FixedArray.i" 38 | FIXED_ARRAY(byte, unsigned char) 39 | -------------------------------------------------------------------------------- /lib/cmake/config.cmake.in: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | @PACKAGE_INIT@ 38 | 39 | include ("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") 40 | check_required_components ("@PROJECT_NAME@") 41 | -------------------------------------------------------------------------------- /tests/test_runner.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | /** 38 | * @file test_runner.cxx 39 | * @brief Tests entrypoint 40 | */ 41 | 42 | #define CATCH_CONFIG_MAIN 43 | #include "catch.hpp" 44 | -------------------------------------------------------------------------------- /wrappers/emsdk/error.js: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | mergeInto(LibraryManager.library, { 38 | _virgil_throw_error: function(ptr) { 39 | throw new Error(readLatin1String(ptr)); 40 | }, 41 | }); 42 | -------------------------------------------------------------------------------- /libs_ext/tinyformat/cmake/config.cmake.in: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | @PACKAGE_INIT@ 38 | 39 | string (TOUPPER "@PROJECT_NAME@" PROJECT_NAME_UPPERCASE) 40 | 41 | set_and_check (${PROJECT_NAME_UPPERCASE}_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") 42 | 43 | set (PROJECT_NAME_UPPERCASE) 44 | -------------------------------------------------------------------------------- /Dockerfile_Golang: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | # gcc for cgo 4 | RUN apt-get update && apt-get install -y --no-install-recommends \ 5 | g++ \ 6 | gcc \ 7 | libc6-dev \ 8 | make \ 9 | pkg-config \ 10 | swig \ 11 | doxygen \ 12 | curl \ 13 | ca-certificates \ 14 | git \ 15 | wget \ 16 | libssl-dev \ 17 | && rm -rf /var/lib/apt/lists/* 18 | 19 | # install cmake 20 | ENV CMAKE_VERSION 3.10.2 21 | RUN wget https://cmake.org/files/v${CMAKE_VERSION%.*}/cmake-${CMAKE_VERSION}.tar.gz \ 22 | && tar xvfz cmake-${CMAKE_VERSION}.tar.gz \ 23 | && cd cmake-${CMAKE_VERSION} \ 24 | && ./bootstrap \ 25 | && make -j4 \ 26 | && make install \ 27 | && cd - \ 28 | && rm -rf ./cmake-* 29 | 30 | # install golang 31 | ENV GOLANG_VERSION 1.12.10 32 | ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz 33 | ENV GOLANG_DOWNLOAD_SHA256 aaa84147433aed24e70b31da369bb6ca2859464a45de47c2a5023d8573412f6b 34 | 35 | RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \ 36 | && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ 37 | && tar -C /usr/local -xzf golang.tar.gz \ 38 | && rm golang.tar.gz 39 | 40 | ENV GOPATH /go 41 | ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH 42 | 43 | RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" 44 | WORKDIR $GOPATH 45 | 46 | # build virgil-crypto-go 47 | ADD . virgil-crypto 48 | 49 | RUN cd virgil-crypto \ 50 | && cmake -H. -B_build -DCMAKE_INSTALL_PREFIX=_install -DLANG=go -DINSTALL_CORE_LIBS=ON -DVIRGIL_CRYPTO_FEATURE_PYTHIA=ON \ 51 | && cmake --build _build --target install 52 | 53 | # v4 54 | RUN go get -d gopkg.in/virgilsecurity/virgil-crypto-go.v4 \ 55 | && cp -r virgil-crypto/_install/* $GOPATH/src/gopkg.in/virgilsecurity/virgil-crypto-go.v4 56 | 57 | # v5 58 | RUN go get -d gopkg.in/virgilsecurity/virgil-crypto-go.v5 \ 59 | && cp -r virgil-crypto/_install/* $GOPATH/src/gopkg.in/virgilsecurity/virgil-crypto-go.v5 60 | 61 | # cleanup 62 | RUN rm -rf virgil-crypto 63 | -------------------------------------------------------------------------------- /cmake/uppercase_first_char.cmake: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | # 38 | # @brief Make first letter in the string upper case. 39 | # 40 | function (uppercase_first_char src dst) 41 | string (SUBSTRING ${src} 0 1 char) 42 | string (TOUPPER ${char} char) 43 | string (REGEX REPLACE "^.(.*)" "${char}\\1" local_dst "${src}") 44 | set (${dst} ${local_dst} PARENT_SCOPE) 45 | endfunction (uppercase_first_char) 46 | -------------------------------------------------------------------------------- /lib/src/VirgilDataSink.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::crypto::VirgilByteArray; 40 | using virgil::crypto::VirgilDataSink; 41 | 42 | void VirgilDataSink::safeWrite(VirgilDataSink& sink, const VirgilByteArray& data) { 43 | if (!data.empty() && sink.isGood()) { 44 | sink.write(data); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lib/mainpage.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @mainpage Virgil Security Crypto library 3 | * 4 | * The Virgil Security Crypto library offers set of methods that allow encrypt, decrypt, sign and verify data. 5 | */ 6 | 7 | /** 8 | * @namespace virgil 9 | * @brief Root namespace for all Virgil Security libraries. 10 | */ 11 | 12 | /** 13 | * @namespace virgil::crypto 14 | * @brief This namespace contains interfaces for high-level crypto operations, 15 | * i.e. generate key pair, encrypt and decrypt data, sign and verify data. 16 | */ 17 | 18 | /** 19 | * @namespace virgil::crypto::foundation 20 | * @brief This namespace contains interfaces for low-level crypto operations. 21 | */ 22 | 23 | /** 24 | * @namespace virgil::crypto::foundation::asn1 25 | * @brief This namespace contains interfaces for ASN.1 data manipulation. 26 | */ 27 | 28 | /** 29 | * @namespace virgil::crypto::foundation::cms 30 | * @brief This namespace contains interfaces for CMS data manipulation. 31 | */ 32 | 33 | /** 34 | * @namespace virgil::crypto::stream 35 | * @brief This namespace contains interfaces for stream data processing in crypto algorithms. 36 | */ 37 | 38 | /** 39 | * @namespace virgil::crypto::pfs 40 | * @brief This namespace contains interfaces for Perfect Forward Secrecy data and algorithm. 41 | */ 42 | 43 | /** 44 | * @defgroup error Error 45 | * 46 | * @brief This group contains interfaces for error handling mechanism that is used in the library. 47 | */ 48 | 49 | /** 50 | * @defgroup hash Hash 51 | * 52 | * @brief This group contains interfaces for producing cryptographic hashes. 53 | */ 54 | 55 | /** 56 | * @defgroup kdf KDF 57 | * 58 | * @brief This group contains interfaces to Key Derivation Function algorithms. 59 | */ 60 | 61 | /** 62 | * @defgroup cipher Cipher 63 | * 64 | * @brief This group contains interfaces to encryption and to decryption algorithms. 65 | */ 66 | 67 | /** 68 | * @defgroup pfs PFS 69 | * 70 | * @brief This group contains interfaces for Perfect Forward Secrecy module. 71 | */ 72 | 73 | /** 74 | * @defgroup pythia Pythia 75 | * 76 | * @brief This group contains interfaces for Pythia module. 77 | */ 78 | -------------------------------------------------------------------------------- /ci/install-deployment-key.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (C) 2015-2018 Virgil Security Inc. 4 | # 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions are 9 | # met: 10 | # 11 | # (1) Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 14 | # (2) Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in 16 | # the documentation and/or other materials provided with the 17 | # distribution. 18 | # 19 | # (3) Neither the name of the copyright holder nor the names of its 20 | # contributors may be used to endorse or promote products derived from 21 | # this software without specific prior written permission. 22 | # 23 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 24 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 27 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # 35 | # Lead Maintainer: Virgil Security Inc. 36 | # 37 | 38 | set -e 39 | 40 | openssl aes-256-cbc -K $encrypted_ada03e964e0c_key -iv $encrypted_ada03e964e0c_iv \ 41 | -in "${PROJECT_ROOT}/ci/travis-deployment-key.enc" \ 42 | -out "${PROJECT_ROOT}/ci/travis-deployment-key" -d 43 | chmod 0600 "${PROJECT_ROOT}/ci/travis-deployment-key" 44 | eval $(ssh-agent -s) 45 | ssh-add "${PROJECT_ROOT}/ci/travis-deployment-key" 46 | 47 | set +e 48 | -------------------------------------------------------------------------------- /lib/src/VirgilConfig.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include "VirgilConfig.h" 38 | 39 | using virgil::crypto::VirgilConfig; 40 | 41 | bool VirgilConfig::hasFeatureStreamImpl() { 42 | return VIRGIL_CRYPTO_FEATURE_STREAM_IMPL; 43 | } 44 | 45 | bool VirgilConfig::hasFeaturePythiaImpl() { 46 | return VIRGIL_CRYPTO_FEATURE_PYTHIA; 47 | } 48 | 49 | bool VirgilConfig::hasFeaturePythiaMultiThread() { 50 | return VIRGIL_CRYPTO_FEATURE_PYTHIA_MT; 51 | } 52 | -------------------------------------------------------------------------------- /lib/src/primitive/VirgilOperationRandom.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | 38 | #include 39 | 40 | #include 41 | 42 | using virgil::crypto::primitive::VirgilOperationRandom; 43 | using virgil::crypto::foundation::VirgilRandom; 44 | 45 | VirgilOperationRandom VirgilOperationRandom::getDefault() { 46 | return VirgilOperationRandom(VirgilRandom("VirgilRandomFoundation")); 47 | } 48 | -------------------------------------------------------------------------------- /utils/zip.vbs: -------------------------------------------------------------------------------- 1 | ' 2 | ' Lead Maintainer: 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 | 35 | Set objArgs = WScript.Arguments 36 | Set fileSystemObject = CreateObject("Scripting.FileSystemObject") 37 | inputFolder = fileSystemObject.GetAbsolutePathName(objArgs(0)) 38 | zipFile = fileSystemObject.GetAbsolutePathName(objArgs(1)) 39 | 40 | fileSystemObject.CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar) 41 | 42 | Set objShell = CreateObject("Shell.Application") 43 | Set source = objShell.NameSpace(InputFolder) 44 | objShell.NameSpace(ZipFile).CopyHere(source) 45 | wScript.Sleep 2000 46 | -------------------------------------------------------------------------------- /lib/src/primitive/VirgilOperationHash.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | #include 40 | 41 | using virgil::crypto::VirgilByteArray; 42 | using virgil::crypto::primitive::VirgilOperationHash; 43 | using virgil::crypto::foundation::VirgilHash; 44 | 45 | 46 | VirgilOperationHash VirgilOperationHash::getDefault() { 47 | return VirgilOperationHash(VirgilHash(VirgilHash::Algorithm::SHA256)); 48 | } 49 | -------------------------------------------------------------------------------- /lib/src/pfs/VirgilPFSPublicKey.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::crypto::VirgilByteArray; 40 | using virgil::crypto::pfs::VirgilPFSPublicKey; 41 | 42 | VirgilPFSPublicKey::VirgilPFSPublicKey(virgil::crypto::VirgilByteArray key) : key_(std::move(key)) {} 43 | 44 | bool VirgilPFSPublicKey::isEmpty() const { 45 | return key_.empty(); 46 | } 47 | 48 | const VirgilByteArray& VirgilPFSPublicKey::getKey() const { 49 | return key_; 50 | } 51 | -------------------------------------------------------------------------------- /wrappers/php/tests/StringSink.php.in: -------------------------------------------------------------------------------- 1 | 36 | */ 37 | 38 | include_once "@PHP_MODULE_FILE_NAME@"; 39 | 40 | class StringSink extends VirgilDataSink 41 | { 42 | private $result = ""; 43 | 44 | public function isGood() 45 | { 46 | return true; 47 | } 48 | 49 | public function write($data) 50 | { 51 | $this->result .= $data; 52 | } 53 | 54 | public function getResult() 55 | { 56 | return $this->result; 57 | } 58 | } 59 | 60 | ?> 61 | -------------------------------------------------------------------------------- /wrappers/php/tests/data/CMakeLists.txt: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | file (GLOB STALE_DATA_FILES 38 | "${CMAKE_CURRENT_BINARY_DIR}/*.der" 39 | "${CMAKE_CURRENT_BINARY_DIR}/*.pem" 40 | "${CMAKE_CURRENT_BINARY_DIR}/*.json" 41 | ) 42 | if (STALE_DATA_FILES) 43 | file (REMOVE ${STALE_DATA_FILES}) 44 | endif () 45 | 46 | file (GLOB DATA_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.der" "*.pem" "*.json") 47 | 48 | foreach (FILE ${DATA_FILES}) 49 | configure_file (${FILE} ${CMAKE_CURRENT_BINARY_DIR}/${FILE} COPYONLY) 50 | endforeach (FILE) 51 | -------------------------------------------------------------------------------- /wrappers/swig/csharp/common.i: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | 38 | // Renames functions and properties to the CamelCase notation. 39 | %rename("%(camelcase)s", %$isfunction) ""; 40 | %rename("%(camelcase)s", %$isvariable) ""; 41 | 42 | // Apply a rule for renaming the enum elements to avoid the common prefixes 43 | // which are redundant in C# 44 | %rename("%(regex:/^([A-Z][a-z]+)+_(.*)/\\2/)s", %$isenumitem) ""; 45 | 46 | // VirgilByteArray typemap 47 | #define SWIG_VIRGIL_BYTE_ARRAY 48 | %include "VirgilByteArray.i" 49 | -------------------------------------------------------------------------------- /benchmark/CMakeLists.txt: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | cmake_minimum_required (VERSION 3.10 FATAL_ERROR) 38 | 39 | # Enable C++11 40 | set (CMAKE_CXX_STANDARD 11) 41 | set (CMAKE_CXX_STANDARD_REQUIRED ON) 42 | 43 | # Define variables 44 | set (VIRGIL_CRYPTO_LIB_NAME virgil_crypto) 45 | 46 | aux_source_directory (${CMAKE_CURRENT_SOURCE_DIR} SRC_LIST) 47 | 48 | foreach (src ${SRC_LIST}) 49 | get_filename_component (file_name ${src} NAME_WE) 50 | add_executable (${file_name} ${src}) 51 | target_link_libraries (${file_name} ${VIRGIL_CRYPTO_LIB_NAME}) 52 | endforeach (src ${SRC_LIST}) 53 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | cmake_minimum_required (VERSION 3.10 FATAL_ERROR) 38 | 39 | # Define variables 40 | set (VIRGIL_CRYPTO_LIB_NAME virgil_crypto) 41 | set (TEST_RUNNER test_runner) 42 | 43 | aux_source_directory (${CMAKE_CURRENT_SOURCE_DIR} SRC_LIST) 44 | add_executable(${TEST_RUNNER} ${SRC_LIST}) 45 | target_link_libraries (${TEST_RUNNER} ${VIRGIL_CRYPTO_LIB_NAME}) 46 | file (COPY "${CMAKE_CURRENT_SOURCE_DIR}/data" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") 47 | 48 | add_test ( 49 | NAME ${TEST_RUNNER} 50 | COMMAND "${CMAKE_CURRENT_BINARY_DIR}/${TEST_RUNNER}" 51 | ) 52 | -------------------------------------------------------------------------------- /wrappers/php/tests/VirgilRandom_Test.php.in: -------------------------------------------------------------------------------- 1 | 36 | */ 37 | 38 | include_once "@PHP_MODULE_FILE_NAME@"; 39 | include_once "StringSource.php"; 40 | 41 | /** 42 | * @coversDefaultClass VirgilRandom 43 | */ 44 | class VirgilRandom_Test extends PHPUnit\Framework\TestCase { 45 | 46 | /** 47 | * @covers VirgilRandom::randomize 48 | */ 49 | public function test_() { 50 | $random = new VirgilRandom("com.virgilsecurity.random"); 51 | $randomData = $random->randomize(1024); 52 | $this->assertEquals(strlen($randomData), 1024); 53 | } 54 | } 55 | 56 | ?> 57 | -------------------------------------------------------------------------------- /cmake/find_host_utils.cmake: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | # Define ad-hoc macros to find packages, programs and librais 38 | if (NOT COMMAND find_host_package) 39 | macro (find_host_package) 40 | find_package (${ARGN}) 41 | endmacro () 42 | endif () 43 | 44 | if (NOT COMMAND find_host_program) 45 | macro (find_host_program) 46 | find_program (${ARGN}) 47 | endmacro () 48 | endif () 49 | 50 | if (NOT COMMAND find_host_library) 51 | macro (find_host_library) 52 | find_library (${ARGN}) 53 | endmacro () 54 | endif () 55 | 56 | if (NOT COMMAND find_host_path) 57 | macro (find_host_path) 58 | find_path (${ARGN}) 59 | endmacro () 60 | endif () 61 | -------------------------------------------------------------------------------- /cmake/virgil_depends.cmake: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | # 38 | # See 'virgil_depends_local.cmake' for documentation 39 | # Note: 40 | # VIRGIL_DEPENDS_CMAKE_FILE cache varibale can be used to define alternative 'virgil_depends.cmake' 41 | # module implementation, i.e. from an upstream project. 42 | # 43 | 44 | if (EXISTS "${VIRGIL_DEPENDS_CMAKE_FILE}") 45 | include ("${VIRGIL_DEPENDS_CMAKE_FILE}") 46 | else () 47 | find_file (VIRGIL_DEPENDS_CMAKE_FILE "virgil_depends_local.cmake" HINTS ${CMAKE_MODULE_PATH}) 48 | if (VIRGIL_DEPENDS_CMAKE_FILE) 49 | include ("${VIRGIL_DEPENDS_CMAKE_FILE}") 50 | else () 51 | include (virgil_depends_local) 52 | endif () 53 | endif () 54 | -------------------------------------------------------------------------------- /wrappers/net/src/VirgilStreamDataSink.cs: -------------------------------------------------------------------------------- 1 | #region "Copyright (C) 2015-2018 Virgil Security Inc." 2 | /** 3 | * Copyright (C) 2015-2018 Virgil Security Inc. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * (1) Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * (2) Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in 16 | * the documentation and/or other materials provided with the 17 | * distribution. 18 | * 19 | * (3) Neither the name of the copyright holder nor the names of its 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | * Lead Maintainer: Virgil Security Inc. 36 | */ 37 | #endregion 38 | 39 | namespace Virgil.Crypto { 40 | 41 | public class VirgilStreamDataSink : VirgilDataSink 42 | { 43 | private readonly System.IO.Stream stream; 44 | 45 | public VirgilStreamDataSink(System.IO.Stream target) 46 | { 47 | this.stream = target; 48 | } 49 | 50 | public override bool IsGood() 51 | { 52 | return this.stream.CanWrite; 53 | } 54 | 55 | public override void Write(byte[] data) 56 | { 57 | this.stream.Write(data, 0, data.Length); 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /lib/src/utils.h: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #ifndef VIRGIL_CRYPTO_INTERNAL_UTILS_H 38 | #define VIRGIL_CRYPTO_INTERNAL_UTILS_H 39 | 40 | #define VIRGIL_STR(var) #var 41 | 42 | // Define custom implemetation of std::make_unique() function 43 | #if !defined(__cpp_lib_make_unique) 44 | #if !defined(_MSC_VER) || _MSC_VER < 1800 45 | 46 | #include 47 | #include 48 | 49 | namespace std { 50 | template 51 | unique_ptr make_unique(Args&& ... args) { 52 | return unique_ptr(new T(forward(args)...)); 53 | } 54 | } 55 | 56 | #endif // !defined(_MSC_VER) || _MSC_VER < 1800 57 | #endif // __cpp_lib_make_unique 58 | 59 | #endif // VIRGIL_CRYPTO_INTERNAL_UTILS_H 60 | -------------------------------------------------------------------------------- /tests/test_stream_data_source.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | /** 38 | * @file test_stream_data_source.cxx 39 | * @brief Covers class VirgilDataSreamSource 40 | */ 41 | 42 | #if VIRGIL_CRYPTO_FEATURE_STREAM_IMPL 43 | 44 | #include "catch.hpp" 45 | 46 | #include 47 | 48 | #include 49 | 50 | using virgil::crypto::stream::VirgilStreamDataSource; 51 | 52 | TEST_CASE("VirgilStreamDataSource: check data existence in the bad stream", "[stream-data-source]") { 53 | std::fstream nonExistingFile("invalid_path_to_file"); 54 | VirgilStreamDataSource dataSource(nonExistingFile); 55 | REQUIRE_FALSE(dataSource.hasData()); 56 | } 57 | 58 | #endif // VIRGIL_CRYPTO_FEATURE_STREAM_IMPL 59 | -------------------------------------------------------------------------------- /wrappers/php/tests/StringSource.php.in: -------------------------------------------------------------------------------- 1 | 36 | */ 37 | 38 | include_once "@PHP_MODULE_FILE_NAME@"; 39 | 40 | class StringSource extends VirgilDataSource 41 | { 42 | private $source; 43 | private $sourcePos; 44 | function __construct($string) 45 | { 46 | parent::__construct($this); 47 | $this->source = str_split($string, 2); 48 | $this->sourcePos = 0; 49 | } 50 | 51 | public function hasData() 52 | { 53 | return count($this->source) > $this->sourcePos; 54 | } 55 | 56 | public function read() 57 | { 58 | return $this->source[$this->sourcePos++]; 59 | } 60 | 61 | public function reset() 62 | { 63 | $this->sourcePos = 0; 64 | } 65 | } 66 | 67 | ?> 68 | -------------------------------------------------------------------------------- /benchmark/benchmark_pythia.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #define BENCHPRESS_CONFIG_MAIN 38 | 39 | #include "benchpress.hpp" 40 | 41 | 42 | #if VIRGIL_CRYPTO_FEATURE_PYTHIA 43 | 44 | 45 | #include 46 | #include 47 | 48 | using virgil::crypto::VirgilByteArrayUtils; 49 | using virgil::crypto::pythia::VirgilPythia; 50 | 51 | BENCHMARK("pythia init", [](benchpress::context* ctx) { 52 | 53 | ctx->run_parallel([](benchpress::parallel_context* pctx) { 54 | while (pctx->next()) { 55 | VirgilPythia pythia; 56 | auto result = pythia.blind(VirgilByteArrayUtils::stringToBytes("password")); 57 | } 58 | }); 59 | }) 60 | 61 | #endif /* VIRGIL_CRYPTO_FEATURE_PYTHIA */ 62 | -------------------------------------------------------------------------------- /lib/src/pythia/VirgilPythiaError.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | using virgil::crypto::pythia::VirgilPythiaErrorCategory; 43 | 44 | 45 | const VirgilPythiaErrorCategory& virgil::crypto::pythia::pythia_error_category() noexcept { 46 | static VirgilPythiaErrorCategory inst; 47 | return inst; 48 | } 49 | 50 | const char* VirgilPythiaErrorCategory::name() const noexcept { 51 | return "virgil/crypto/pythia"; 52 | } 53 | 54 | std::string VirgilPythiaErrorCategory::message(int ev) const noexcept { 55 | return std::string( 56 | "Pythia library has return error. This is unexpected behaviour, please contact " 57 | "support team."); 58 | } 59 | -------------------------------------------------------------------------------- /lib/src/stream/VirgilStreamDataSink.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | 38 | #if VIRGIL_CRYPTO_FEATURE_STREAM_IMPL 39 | 40 | #include 41 | #include 42 | 43 | using virgil::crypto::VirgilByteArray; 44 | using virgil::crypto::stream::VirgilStreamDataSink; 45 | 46 | VirgilStreamDataSink::VirgilStreamDataSink(std::ostream& out) : out_(out) { 47 | } 48 | 49 | bool VirgilStreamDataSink::isGood() { 50 | return out_.good(); 51 | } 52 | 53 | void VirgilStreamDataSink::write(const VirgilByteArray& data) { 54 | out_.write(reinterpret_cast(data.data()), data.size()); 55 | } 56 | 57 | VirgilStreamDataSink::~VirgilStreamDataSink() noexcept { 58 | } 59 | 60 | #endif /* VIRGIL_CRYPTO_FEATURE_STREAM_IMPL */ 61 | -------------------------------------------------------------------------------- /lib/src/VirgilSystemCryptoError.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | using virgil::crypto::foundation::VirgilSystemCryptoErrorCategory; 43 | 44 | 45 | const VirgilSystemCryptoErrorCategory& virgil::crypto::foundation::system_crypto_category() noexcept { 46 | static VirgilSystemCryptoErrorCategory inst; 47 | return inst; 48 | } 49 | 50 | const char* VirgilSystemCryptoErrorCategory::name() const noexcept { 51 | return "virgil/crypto/mbedtls"; 52 | } 53 | 54 | std::string VirgilSystemCryptoErrorCategory::message(int ev) const noexcept { 55 | std::array errorBuffer; 56 | mbedtls_strerror(ev, errorBuffer.data(), errorBuffer.size()); 57 | return std::string(errorBuffer.data()); 58 | } 59 | -------------------------------------------------------------------------------- /lib/src/stream/VirgilBytesDataSink.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | 38 | #if VIRGIL_CRYPTO_FEATURE_STREAM_IMPL 39 | 40 | #include 41 | #include 42 | 43 | using virgil::crypto::VirgilByteArray; 44 | using virgil::crypto::stream::VirgilBytesDataSink; 45 | 46 | 47 | VirgilBytesDataSink::VirgilBytesDataSink(VirgilByteArray& out) : out_(out) { 48 | } 49 | 50 | bool VirgilBytesDataSink::isGood() { 51 | return true; 52 | } 53 | 54 | void VirgilBytesDataSink::write(const VirgilByteArray& data) { 55 | out_.insert(out_.end(), data.begin(), data.end()); 56 | } 57 | 58 | void VirgilBytesDataSink::reset() { 59 | out_.clear(); 60 | } 61 | 62 | VirgilBytesDataSink::~VirgilBytesDataSink() noexcept { 63 | } 64 | 65 | #endif /* VIRGIL_CRYPTO_FEATURE_STREAM_IMPL */ 66 | -------------------------------------------------------------------------------- /lib/src/pfs/VirgilPFSPrivateKey.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::crypto::VirgilByteArray; 40 | using virgil::crypto::pfs::VirgilPFSPrivateKey; 41 | 42 | VirgilPFSPrivateKey::VirgilPFSPrivateKey( 43 | virgil::crypto::VirgilByteArray key, virgil::crypto::VirgilByteArray password) 44 | : key_(std::move(key)), password_(std::move(password)) {} 45 | 46 | VirgilPFSPrivateKey::~VirgilPFSPrivateKey() noexcept { 47 | bytes_zeroize(key_); 48 | bytes_zeroize(password_); 49 | } 50 | 51 | bool VirgilPFSPrivateKey::isEmpty() const { 52 | return key_.empty(); 53 | } 54 | 55 | const VirgilByteArray& VirgilPFSPrivateKey::getKey() const { 56 | return key_; 57 | } 58 | 59 | const VirgilByteArray& VirgilPFSPrivateKey::getPassword() const { 60 | return password_; 61 | } 62 | -------------------------------------------------------------------------------- /lib/include/virgil/crypto/VirgilDataSource.h: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #ifndef VIRGIL_CRYPTO_VIRGIL_DATA_SOURCE_H 38 | #define VIRGIL_CRYPTO_VIRGIL_DATA_SOURCE_H 39 | 40 | #include "VirgilByteArray.h" 41 | 42 | namespace virgil { namespace crypto { 43 | 44 | /** 45 | * @brief This is base class for input streams. 46 | * 47 | * Defines interface that allows read data from the input stream. 48 | */ 49 | class VirgilDataSource { 50 | public: 51 | /** 52 | * @brief Return true if target source still contains unread data. 53 | */ 54 | virtual bool hasData() = 0; 55 | 56 | /** 57 | * @brief Return next portion of read data from target source. 58 | */ 59 | virtual VirgilByteArray read() = 0; 60 | 61 | virtual ~VirgilDataSource() noexcept = default; 62 | }; 63 | 64 | }} 65 | 66 | #endif /* VIRGIL_CRYPTO_VIRGIL_DATA_SOURCE_H */ 67 | -------------------------------------------------------------------------------- /lib/src/pfs/VirgilPFSInitiatorPublicInfo.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::crypto::VirgilByteArray; 40 | using virgil::crypto::pfs::VirgilPFSInitiatorPublicInfo; 41 | using virgil::crypto::pfs::VirgilPFSPublicKey; 42 | 43 | VirgilPFSInitiatorPublicInfo::VirgilPFSInitiatorPublicInfo( 44 | VirgilPFSPublicKey identityPublicKey, VirgilPFSPublicKey ephemeralPublicKey) 45 | : identityPublicKey_(std::move(identityPublicKey)), 46 | ephemeralPublicKey_(std::move(ephemeralPublicKey)) { 47 | } 48 | 49 | const VirgilPFSPublicKey& VirgilPFSInitiatorPublicInfo::getIdentityPublicKey() const { 50 | return identityPublicKey_; 51 | } 52 | 53 | const VirgilPFSPublicKey& VirgilPFSInitiatorPublicInfo::getEphemeralPublicKey() const { 54 | return ephemeralPublicKey_; 55 | } 56 | -------------------------------------------------------------------------------- /lib/src/pfs/VirgilPFSEncryptedMessage.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::crypto::VirgilByteArray; 40 | using virgil::crypto::pfs::VirgilPFSEncryptedMessage; 41 | 42 | VirgilPFSEncryptedMessage::VirgilPFSEncryptedMessage( 43 | VirgilByteArray sessionIdentifier, VirgilByteArray salt, VirgilByteArray cipherText) 44 | : sessionIdentifier_(std::move(sessionIdentifier)), salt_(std::move(salt)), cipherText_(std::move(cipherText)) { 45 | } 46 | 47 | const VirgilByteArray& VirgilPFSEncryptedMessage::getSessionIdentifier() const { 48 | return sessionIdentifier_; 49 | } 50 | 51 | const VirgilByteArray& VirgilPFSEncryptedMessage::getSalt() const { 52 | return salt_; 53 | } 54 | 55 | const VirgilByteArray& VirgilPFSEncryptedMessage::getCipherText() const { 56 | return cipherText_; 57 | } 58 | -------------------------------------------------------------------------------- /lib/src/primitive/VirgilOperationDH.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | 38 | #include 39 | 40 | #include 41 | 42 | using virgil::crypto::VirgilByteArray; 43 | using virgil::crypto::VirgilCipherBase; 44 | 45 | using virgil::crypto::primitive::VirgilOperationDH; 46 | 47 | namespace { 48 | 49 | class VirgilDHImplementationDefault { 50 | public: 51 | VirgilByteArray calculate( 52 | const VirgilByteArray& publicKey, const VirgilByteArray& privateKey, 53 | const VirgilByteArray& privateKeyPassword) const { 54 | 55 | return VirgilCipherBase::computeShared(publicKey, privateKey, privateKeyPassword); 56 | } 57 | }; 58 | 59 | } 60 | 61 | VirgilOperationDH VirgilOperationDH::getDefault() { 62 | return VirgilOperationDH(VirgilDHImplementationDefault()); 63 | } 64 | -------------------------------------------------------------------------------- /wrappers/java/src/VirgilStreamDataSink.java: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | package com.virgilsecurity.crypto; 38 | 39 | public class VirgilStreamDataSink extends VirgilDataSink implements java.io.Closeable { 40 | private java.io.OutputStream stream; 41 | 42 | public VirgilStreamDataSink(java.io.OutputStream stream) { 43 | this.stream = stream; 44 | } 45 | 46 | @Override 47 | public boolean isGood() throws java.io.IOException { 48 | // If stream is not good, method 'write' will throw exception. 49 | return true; 50 | } 51 | 52 | @Override 53 | public void write(byte[] data) throws java.io.IOException { 54 | this.stream.write(data, 0, data.length); 55 | } 56 | 57 | @Override 58 | public void close() throws java.io.IOException { 59 | this.stream.close(); 60 | this.delete(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /benchmark/benchmark_random.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #define BENCHPRESS_CONFIG_MAIN 38 | 39 | #include "benchpress.hpp" 40 | 41 | #include 42 | 43 | using virgil::crypto::foundation::VirgilRandom; 44 | 45 | void benchmark_random(benchpress::context* ctx, size_t bytes) { 46 | VirgilRandom random("seed"); 47 | ctx->reset_timer(); 48 | for (size_t i = 0; i < ctx->num_iterations(); ++i) { 49 | (void) random.randomize(bytes); 50 | } 51 | } 52 | 53 | BENCHMARK("Random bytes: 32 ", std::bind(benchmark_random, std::placeholders::_1, 32)); 54 | BENCHMARK("Random bytes: 64 ", std::bind(benchmark_random, std::placeholders::_1, 64)); 55 | BENCHMARK("Random bytes: 128", std::bind(benchmark_random, std::placeholders::_1, 128)); 56 | BENCHMARK("Random bytes: 256", std::bind(benchmark_random, std::placeholders::_1, 256)); 57 | -------------------------------------------------------------------------------- /lib/src/pfs/VirgilPFSInitiatorPrivateInfo.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::crypto::VirgilByteArray; 40 | using virgil::crypto::pfs::VirgilPFSInitiatorPrivateInfo; 41 | using virgil::crypto::pfs::VirgilPFSPrivateKey; 42 | 43 | VirgilPFSInitiatorPrivateInfo::VirgilPFSInitiatorPrivateInfo( 44 | VirgilPFSPrivateKey identityPrivateKey, VirgilPFSPrivateKey ephemeralPrivateKey) 45 | : identityPrivateKey_(std::move(identityPrivateKey)), 46 | ephemeralPrivateKey_(std::move(ephemeralPrivateKey)) {} 47 | 48 | const VirgilPFSPrivateKey& VirgilPFSInitiatorPrivateInfo::getIdentityPrivateKey() const { 49 | return identityPrivateKey_; 50 | } 51 | 52 | const VirgilPFSPrivateKey& VirgilPFSInitiatorPrivateInfo::getEphemeralPrivateKey() const { 53 | return ephemeralPrivateKey_; 54 | } 55 | -------------------------------------------------------------------------------- /wrappers/php/tests/VirgilPBKDF_Test.php.in: -------------------------------------------------------------------------------- 1 | 36 | */ 37 | 38 | include_once "@PHP_MODULE_FILE_NAME@"; 39 | 40 | /** 41 | * @coversDefaultClass VirgilPBKDF 42 | */ 43 | class VirgilPBKDF_Test extends PHPUnit\Framework\TestCase { 44 | 45 | /** 46 | * @covers VirgilPBKDF::setAlgorithm 47 | * @covers VirgilPBKDF::setHash 48 | * @covers VirgilPBKDF::derive 49 | */ 50 | public function test_pbkdf() { 51 | $pwd = "password"; 52 | $salt = "salt"; 53 | $iterationCount = 2048; 54 | $outSize = 512; 55 | 56 | $pbkdf = new VirgilPBKDF($salt, $iterationCount); 57 | $pbkdf->setAlgorithm(VirgilPBKDF::Algorithm_PBKDF2); 58 | $pbkdf->setHashAlgorithm(VirgilHash::Algorithm_SHA512); 59 | 60 | $out = $pbkdf->derive($pwd, $outSize); 61 | 62 | $this->assertEquals($outSize, strlen($out)); 63 | } 64 | } 65 | 66 | ?> 67 | -------------------------------------------------------------------------------- /lib/include/virgil/crypto/foundation/VirgilBase64.h: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #ifndef VIRGIL_CRYPTO_BASE64_H 38 | #define VIRGIL_CRYPTO_BASE64_H 39 | 40 | #include 41 | 42 | #include "../VirgilByteArray.h" 43 | 44 | namespace virgil { namespace crypto { namespace foundation { 45 | 46 | /** 47 | * @brief Provides base64 encoding / decoding. 48 | */ 49 | class VirgilBase64 { 50 | public: 51 | /** 52 | * @brief Transform given bytes to the base64 string. 53 | */ 54 | static std::string encode(const virgil::crypto::VirgilByteArray& data); 55 | 56 | /** 57 | * @brief Transform given base64 string to the bytes. 58 | */ 59 | static virgil::crypto::VirgilByteArray decode(const std::string& base64str); 60 | public: 61 | /** 62 | * @brief Deny object creation. 63 | */ 64 | VirgilBase64() = delete; 65 | 66 | }; 67 | 68 | }}} 69 | 70 | #endif /* VIRGIL_CRYPTO_BASE64_H */ 71 | -------------------------------------------------------------------------------- /lib/src/primitive/VirgilOperationKDF.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | 38 | #include 39 | 40 | #include 41 | 42 | using virgil::crypto::VirgilByteArray; 43 | using virgil::crypto::primitive::VirgilOperationKDF; 44 | using virgil::crypto::foundation::VirgilHKDF; 45 | using virgil::crypto::foundation::VirgilHash; 46 | 47 | namespace { 48 | 49 | class VirgilKDFDefaultImpl { 50 | public: 51 | VirgilByteArray derive( 52 | const VirgilByteArray& keyMaterial, const VirgilByteArray& salt, 53 | const VirgilByteArray& info, size_t size) const { 54 | 55 | VirgilHKDF hkdf(VirgilHash::Algorithm::SHA256); 56 | return hkdf.derive(keyMaterial, salt, info, size); 57 | } 58 | }; 59 | 60 | } 61 | 62 | VirgilOperationKDF VirgilOperationKDF::getDefault() { 63 | return VirgilOperationKDF(VirgilKDFDefaultImpl()); 64 | } 65 | -------------------------------------------------------------------------------- /wrappers/CMakeLists.txt: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | # 38 | # Dependent on variables: 39 | # - LANG - target language. 40 | # 41 | # Define variables: 42 | # - WRAPPED_LIB_NAME - name of the wrapped library. 43 | # - WRAPPERS_ROOT - absolute path to the directory of this CMake. 44 | # 45 | 46 | cmake_minimum_required (VERSION 3.10 FATAL_ERROR) 47 | 48 | project (wrappers) 49 | 50 | # Define variables 51 | set (WRAPPED_LIB_NAME virgil_crypto) 52 | set (WRAPPERS_ROOT "${CMAKE_CURRENT_LIST_DIR}") 53 | 54 | # Add include directory of wrapped module 55 | include_directories (${${WRAPPED_LIB_NAME}_SOURCE_DIR}/include) 56 | include_directories (${${WRAPPED_LIB_NAME}_BINARY_DIR}/include) 57 | include_directories (swig) 58 | 59 | # Add wrappers 60 | set (LANG_DIR ${LANG}) 61 | if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${LANG_DIR}") 62 | add_subdirectory (${LANG_DIR}) 63 | else () 64 | message (STATUS "No special wrappers for the language: " ${LANG}) 65 | endif () 66 | -------------------------------------------------------------------------------- /lib/include/virgil/crypto/pythia/VirgilPythiaContext.h: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #ifndef VIRGIL_PYTHIA_CONTEXT_H 38 | #define VIRGIL_PYTHIA_CONTEXT_H 39 | 40 | #include 41 | 42 | namespace virgil { 43 | namespace crypto { 44 | namespace pythia { 45 | 46 | /** 47 | * @brief This class encapsulates Pythia initialization routine. 48 | * 49 | * Motivation: 50 | * Pythia context locates in a global storage or a thread storage 51 | * duration, so it's initialization must be handled properly. 52 | * 53 | * Usage: 54 | * This class object must be defined as a function local variable, or 55 | * non-static class member. 56 | * 57 | * @ingroup pythia 58 | */ 59 | class VirgilPythiaContext { 60 | public: 61 | /** 62 | * @brief Initialize Pythia context. 63 | * 64 | */ 65 | VirgilPythiaContext(); 66 | }; 67 | 68 | } // namespace pythia 69 | } // namespace crypto 70 | } // namespace virgil 71 | 72 | #endif /* VIRGIL_PYTHIA_CONTEXT_H */ 73 | -------------------------------------------------------------------------------- /cmake/check_pointer_size.cmake: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | # 38 | # @brief Defines pointer size for current compiler. 39 | # @return pointer size in bytes thru @param 'pointer_size' 40 | # 41 | function (check_pointer_size pointer_size) 42 | if (CMAKE_CROSSCOMPILING) 43 | set (${pointer_size} "" PARENT_SCOPE) 44 | else () 45 | file (WRITE 46 | ${CMAKE_BINARY_DIR}/CMakeTmp/check_pointer_size.cxx 47 | "int main() { void *ptr = 0; return sizeof(ptr); }" 48 | ) 49 | 50 | try_run ( 51 | RUN_RESULT 52 | COMPILE_RESULT 53 | ${CMAKE_BINARY_DIR} 54 | ${CMAKE_BINARY_DIR}/CMakeTmp/check_pointer_size.cxx 55 | OUTPUT_VARIABLE OUTPUT 56 | ) 57 | 58 | if (COMPILE_RESULT AND RUN_RESULT GREATER 0) 59 | set (${pointer_size} ${RUN_RESULT} PARENT_SCOPE) 60 | else () 61 | set (${pointer_size} "" PARENT_SCOPE) 62 | endif () 63 | endif () 64 | endfunction (check_pointer_size) 65 | -------------------------------------------------------------------------------- /lib/include/virgil/crypto/pfs/VirgilPFSPublicKey.h: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #ifndef VIRGIL_CRYPTO_PFS_VIRGIL_PFS_PUBLIC_KEY_H 38 | #define VIRGIL_CRYPTO_PFS_VIRGIL_PFS_PUBLIC_KEY_H 39 | 40 | #include "../VirgilByteArray.h" 41 | 42 | namespace virgil { namespace crypto { namespace pfs { 43 | 44 | /** 45 | * @brief This is model object that handles public key. 46 | * 47 | * @see VirgilPFS 48 | * @ingroup pfs 49 | */ 50 | class VirgilPFSPublicKey { 51 | public: 52 | /** 53 | * @param key - public key. 54 | */ 55 | explicit VirgilPFSPublicKey(VirgilByteArray key = VirgilByteArray()); 56 | 57 | /** 58 | * @return True if underlying key is not defined. 59 | */ 60 | bool isEmpty() const; 61 | 62 | /** 63 | * @brief Getter. 64 | * @see VirgilPFSPublicKey() 65 | */ 66 | const VirgilByteArray& getKey() const; 67 | 68 | private: 69 | VirgilByteArray key_; 70 | }; 71 | 72 | }}} 73 | 74 | #endif //VIRGIL_CRYPTO_PFS_VIRGIL_PFS_PUBLIC_KEY_H 75 | -------------------------------------------------------------------------------- /libs_ext/pythia/pythia.cmake: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | cmake_minimum_required (VERSION @CMAKE_VERSION@ FATAL_ERROR) 38 | 39 | project ("@VIRGIL_DEPENDS_PACKAGE_NAME@-depends") 40 | 41 | include (ExternalProject) 42 | 43 | # Configure additional CMake parameters 44 | file (APPEND "@VIRGIL_DEPENDS_ARGS_FILE@" 45 | "set (RELIC_USE_PTHREAD @VIRGIL_CRYPTO_FEATURE_PYTHIA_MT@ CACHE INTERNAL \"\")\n" 46 | "set (RELIC_USE_EXT_RNG ON CACHE INTERNAL \"\")\n" 47 | "set (ENABLE_TESTING OFF CACHE INTERNAL \"\")\n" 48 | "set (CMAKE_INSTALL_LIBDIR lib CACHE INTERNAL \"\")\n" 49 | ) 50 | 51 | ExternalProject_Add (${PROJECT_NAME} 52 | DOWNLOAD_DIR "@VIRGIL_DEPENDS_PACKAGE_DOWNLOAD_DIR@" 53 | GIT_REPOSITORY https://github.com/VirgilSecurity/pythia.git 54 | GIT_TAG 0.2.2-alpha 55 | PREFIX "@VIRGIL_DEPENDS_PACKAGE_BUILD_DIR@" 56 | CMAKE_ARGS "@VIRGIL_DEPENDS_CMAKE_ARGS@" 57 | ) 58 | 59 | add_custom_target ("${PROJECT_NAME}-build" ALL COMMENT "Build package ${PROJECT_NAME}") 60 | add_dependencies ("${PROJECT_NAME}-build" ${PROJECT_NAME}) 61 | -------------------------------------------------------------------------------- /wrappers/net/src/VirgilStreamDataSource.cs: -------------------------------------------------------------------------------- 1 | #region "Copyright (C) 2015-2018 Virgil Security Inc." 2 | /** 3 | * Copyright (C) 2015-2018 Virgil Security Inc. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * (1) Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * (2) Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in 16 | * the documentation and/or other materials provided with the 17 | * distribution. 18 | * 19 | * (3) Neither the name of the copyright holder nor the names of its 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | * Lead Maintainer: Virgil Security Inc. 36 | */ 37 | #endregion 38 | 39 | namespace Virgil.Crypto { 40 | 41 | public class VirgilStreamDataSource : VirgilDataSource 42 | { 43 | private readonly System.IO.Stream stream; 44 | private readonly byte[] buffer; 45 | 46 | public VirgilStreamDataSource(System.IO.Stream source) 47 | { 48 | this.stream = source; 49 | this.buffer = new byte[1024]; 50 | } 51 | 52 | public override bool HasData() 53 | { 54 | return this.stream.CanRead && this.stream.Position < this.stream.Length; 55 | } 56 | 57 | public override byte[] Read() 58 | { 59 | int bytesRead = this.stream.Read(buffer, 0, buffer.Length); 60 | 61 | if (bytesRead == buffer.Length) 62 | { 63 | return buffer; 64 | } 65 | 66 | byte[] result = new byte[bytesRead]; 67 | System.Array.Copy(buffer, result, bytesRead); 68 | return result; 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /wrappers/php/tests/VirgilVersion_Test.php.in: -------------------------------------------------------------------------------- 1 | 36 | */ 37 | 38 | include_once "@PHP_MODULE_FILE_NAME@"; 39 | 40 | /** 41 | * @coversDefaultClass VirgilVersion 42 | */ 43 | class VirgilVersion_Test extends PHPUnit\Framework\TestCase { 44 | 45 | /** 46 | * @covers VirgilVersion::minorVersion 47 | * @covers VirgilVersion::majorVersion 48 | * @covers VirgilVersion::patchVersion 49 | * @covers VirgilVersion::asString 50 | * @covers VirgilVersion::asNumber 51 | */ 52 | public function test_version() { 53 | $this->assertEquals(@VIRGIL_VERSION_MAJOR@, VirgilVersion::majorVersion()); 54 | $this->assertEquals(@VIRGIL_VERSION_MINOR@, VirgilVersion::minorVersion()); 55 | $this->assertEquals(@VIRGIL_VERSION_PATCH@, VirgilVersion::patchVersion()); 56 | $this->assertEquals((@VIRGIL_VERSION_MAJOR@ << 16 | @VIRGIL_VERSION_MINOR@ << 8 | @VIRGIL_VERSION_PATCH@), VirgilVersion::asNumber()); 57 | $this->assertEquals("@VIRGIL_VERSION@", VirgilVersion::asString()); 58 | } 59 | } 60 | 61 | ?> 62 | -------------------------------------------------------------------------------- /libs_ext/mbedtls/configs/config.h: -------------------------------------------------------------------------------- 1 | #ifndef MBEDTLS_CONFIG_H 2 | #define MBEDTLS_CONFIG_H 3 | 4 | #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) 5 | #define _CRT_SECURE_NO_DEPRECATE 1 6 | #endif 7 | 8 | #define MBEDTLS_CIPHER_MODE_CBC 9 | #define MBEDTLS_CIPHER_PADDING_PKCS7 10 | #define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS 11 | #define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN 12 | #define MBEDTLS_CIPHER_PADDING_ZEROS 13 | #define MBEDTLS_REMOVE_ARC4_CIPHERSUITES 14 | #define MBEDTLS_ECP_DP_SECP192R1_ENABLED 15 | #define MBEDTLS_ECP_DP_SECP224R1_ENABLED 16 | #define MBEDTLS_ECP_DP_SECP256R1_ENABLED 17 | #define MBEDTLS_ECP_DP_SECP384R1_ENABLED 18 | #define MBEDTLS_ECP_DP_SECP521R1_ENABLED 19 | #define MBEDTLS_ECP_DP_SECP192K1_ENABLED 20 | #define MBEDTLS_ECP_DP_SECP224K1_ENABLED 21 | #define MBEDTLS_ECP_DP_SECP256K1_ENABLED 22 | #define MBEDTLS_ECP_DP_BP256R1_ENABLED 23 | #define MBEDTLS_ECP_DP_BP384R1_ENABLED 24 | #define MBEDTLS_ECP_DP_BP512R1_ENABLED 25 | #define MBEDTLS_ECP_NIST_OPTIM 26 | #define MBEDTLS_ECDSA_DETERMINISTIC 27 | #define MBEDTLS_ERROR_STRERROR_DUMMY 28 | #define MBEDTLS_GENPRIME 29 | #define MBEDTLS_PK_RSA_ALT_SUPPORT 30 | #define MBEDTLS_PKCS1_V15 31 | #define MBEDTLS_VERSION_FEATURES 32 | #define MBEDTLS_AES_C 33 | #define MBEDTLS_ASN1_PARSE_C 34 | #define MBEDTLS_ASN1_WRITE_C 35 | #define MBEDTLS_BASE64_C 36 | #define MBEDTLS_BIGNUM_C 37 | #define MBEDTLS_CCM_C 38 | #define MBEDTLS_CIPHER_C 39 | #define MBEDTLS_CTR_DRBG_C 40 | #define MBEDTLS_DES_C 41 | #define MBEDTLS_ECDH_C 42 | #define MBEDTLS_ECDSA_C 43 | #define MBEDTLS_ECP_C 44 | #define MBEDTLS_ENTROPY_C 45 | #define MBEDTLS_ERROR_C 46 | #define MBEDTLS_GCM_C 47 | #define MBEDTLS_HMAC_DRBG_C 48 | #define MBEDTLS_MD_C 49 | #define MBEDTLS_MD5_C 50 | #define MBEDTLS_KDF_C 51 | #define MBEDTLS_KDF1_C 52 | #define MBEDTLS_KDF2_C 53 | #define MBEDTLS_OID_C 54 | #define MBEDTLS_PEM_PARSE_C 55 | #define MBEDTLS_PEM_WRITE_C 56 | #define MBEDTLS_PK_C 57 | #define MBEDTLS_PK_PARSE_C 58 | #define MBEDTLS_PK_WRITE_C 59 | #define MBEDTLS_PK_WRITE_PKCS8_C 60 | #define MBEDTLS_PKCS5_C 61 | #define MBEDTLS_PKCS12_C 62 | #define MBEDTLS_RSA_C 63 | #define MBEDTLS_ECIES_C 64 | #define MBEDTLS_SHA1_C 65 | #define MBEDTLS_SHA256_C 66 | #define MBEDTLS_SHA512_C 67 | #define MBEDTLS_VERSION_C 68 | #define MBEDTLS_X509_USE_C 69 | #define MBEDTLS_ED25519_C 70 | #define MBEDTLS_FAST_EC_C 71 | #define MBEDTLS_ECP_DP_CURVE25519_ENABLED 72 | #define MBEDTLS_ECP_CURVE25519_OVER_ED25519_ENABLED 73 | #define MBEDTLS_ECDH_CURVE25519_OVER_ED25519_ENABLED 74 | #define MBEDTLS_ECDSA_CURVE25519_OVER_ED25519_ENABLED 75 | 76 | #include "config_platform.h" 77 | 78 | #if defined(MBEDTLS_NO_PLATFORM_ENTROPY) && !defined(MBEDTLS_HAVEGE_C) 79 | #warning "MBEDTLS_NO_PLATFORM_ENTROPY defined, but MBEDTLS_HAVEGE_C not defined" 80 | #endif 81 | 82 | #include "check_config.h" 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /lib/src/pfs/VirgilPFSResponderPublicInfo.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::crypto::VirgilByteArray; 40 | using virgil::crypto::pfs::VirgilPFSResponderPublicInfo; 41 | using virgil::crypto::pfs::VirgilPFSPublicKey; 42 | 43 | VirgilPFSResponderPublicInfo::VirgilPFSResponderPublicInfo( 44 | VirgilPFSPublicKey identityPublicKey, 45 | VirgilPFSPublicKey longTermPublicKey, VirgilPFSPublicKey oneTimePublicKey) 46 | : identityPublicKey_(std::move(identityPublicKey)), 47 | longTermPublicKey_(std::move(longTermPublicKey)), 48 | oneTimePublicKey_(std::move(oneTimePublicKey)) {} 49 | 50 | const VirgilPFSPublicKey& VirgilPFSResponderPublicInfo::getIdentityPublicKey() const { 51 | return identityPublicKey_; 52 | } 53 | 54 | const VirgilPFSPublicKey& VirgilPFSResponderPublicInfo::getLongTermPublicKey() const { 55 | return longTermPublicKey_; 56 | } 57 | 58 | const VirgilPFSPublicKey& VirgilPFSResponderPublicInfo::getOneTimePublicKey() const { 59 | return oneTimePublicKey_; 60 | } 61 | -------------------------------------------------------------------------------- /wrappers/net/src/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | #region "Copyright (C) 2015-2018 Virgil Security Inc." 2 | /** 3 | * Copyright (C) 2015-2018 Virgil Security Inc. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * (1) Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * (2) Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in 16 | * the documentation and/or other materials provided with the 17 | * distribution. 18 | * 19 | * (3) Neither the name of the copyright holder nor the names of its 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 27 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | * Lead Maintainer: Virgil Security Inc. 36 | */ 37 | #endregion 38 | 39 | using System.Reflection; 40 | using System.Runtime.CompilerServices; 41 | 42 | [assembly: AssemblyVersion("@VIRGIL_VERSION@")] 43 | [assembly: AssemblyTitle("C# wrapper over '@WRAPPED_LIB_NAME@' library version @VIRGIL_VERSION@")] 44 | [assembly: AssemblyCopyright("Copyright Virgil Security Inc., GPL, Version 2")] 45 | [assembly: AssemblyDescription("This assembly provides API to the dynamic loaded module " + 46 | "@CMAKE_SHARED_MODULE_PREFIX@@VIRGILCRYPTO_SWIG_TARGET_NAME@@CMAKE_SHARED_MODULE_SUFFIX@")] 47 | [assembly: AssemblyCompany("Virgil Security Inc.")] 48 | [assembly: AssemblyFileVersion("@VIRGIL_VERSION@")] 49 | [assembly: AssemblyCulture("")] 50 | [assembly: AssemblyTrademark("Virgil Security Inc.")] 51 | [assembly: AssemblyProduct("@WRAPPED_LIB_NAME@")] 52 | [assembly: AssemblyInformationalVersion("@VIRGIL_VERSION@")] 53 | [assembly: AssemblyConfiguration("")] 54 | [assembly: AssemblyDelaySign(false)] 55 | [assembly: AssemblyKeyName("")] 56 | [assembly: AssemblyKeyFile("")] 57 | -------------------------------------------------------------------------------- /lib/src/pfs/VirgilPFSResponderPrivateInfo.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::crypto::VirgilByteArray; 40 | using virgil::crypto::pfs::VirgilPFSResponderPrivateInfo; 41 | using virgil::crypto::pfs::VirgilPFSPrivateKey; 42 | 43 | VirgilPFSResponderPrivateInfo::VirgilPFSResponderPrivateInfo( 44 | VirgilPFSPrivateKey identityPrivateKey, 45 | VirgilPFSPrivateKey longTermPrivateKey, VirgilPFSPrivateKey oneTimePrivateKey) 46 | : identityPrivateKey_(std::move(identityPrivateKey)), 47 | longTermPrivateKey_(std::move(longTermPrivateKey)), 48 | oneTimePrivateKey_(std::move(oneTimePrivateKey)) {} 49 | 50 | const VirgilPFSPrivateKey& VirgilPFSResponderPrivateInfo::getIdentityPrivateKey() const { 51 | return identityPrivateKey_; 52 | } 53 | 54 | const VirgilPFSPrivateKey& VirgilPFSResponderPrivateInfo::getLongTermPrivateKey() const { 55 | return longTermPrivateKey_; 56 | } 57 | 58 | const VirgilPFSPrivateKey& VirgilPFSResponderPrivateInfo::getOneTimePrivateKey() const { 59 | return oneTimePrivateKey_; 60 | } 61 | -------------------------------------------------------------------------------- /libs_ext/rapidjson/rapidjson.cmake: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | cmake_minimum_required (VERSION @CMAKE_VERSION@ FATAL_ERROR) 38 | 39 | project ("@VIRGIL_DEPENDS_PACKAGE_NAME@-depends") 40 | 41 | include (ExternalProject) 42 | 43 | # Configure additional CMake parameters 44 | file (APPEND "@VIRGIL_DEPENDS_ARGS_FILE@" 45 | "set (RAPIDJSON_BUILD_EXAMPLES OFF CACHE INTERNAL \"\")\n" 46 | "set (RAPIDJSON_BUILD_TESTS OFF CACHE INTERNAL \"\")\n" 47 | "set (RAPIDJSON_BUILD_DOC OFF CACHE INTERNAL \"\")\n" 48 | "set (RAPIDJSON_BUILD_THIRDPARTY_GTEST OFF CACHE INTERNAL \"\")\n" 49 | "set (RAPIDJSON_BUILD_CXX11 OFF CACHE INTERNAL \"\")\n" 50 | ) 51 | 52 | ExternalProject_Add (${PROJECT_NAME} 53 | DOWNLOAD_DIR "@VIRGIL_DEPENDS_PACKAGE_DOWNLOAD_DIR@" 54 | URL "https://github.com/miloyip/rapidjson/archive/v1.1.0.tar.gz" 55 | URL_HASH SHA256=bf7ced29704a1e696fbccf2a2b4ea068e7774fa37f6d7dd4039d0787f8bed98e 56 | PREFIX "@VIRGIL_DEPENDS_PACKAGE_BUILD_DIR@" 57 | CMAKE_ARGS "@VIRGIL_DEPENDS_CMAKE_ARGS@" 58 | ) 59 | 60 | add_custom_target ("${PROJECT_NAME}-build" ALL COMMENT "Build package ${PROJECT_NAME}") 61 | add_dependencies ("${PROJECT_NAME}-build" ${PROJECT_NAME}) 62 | -------------------------------------------------------------------------------- /lib/src/VirgilAsn1Compatible.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | #include 43 | 44 | using virgil::crypto::VirgilByteArray; 45 | using virgil::crypto::VirgilCryptoException; 46 | 47 | using virgil::crypto::foundation::asn1::VirgilAsn1Compatible; 48 | using virgil::crypto::foundation::asn1::VirgilAsn1Reader; 49 | using virgil::crypto::foundation::asn1::VirgilAsn1Writer; 50 | 51 | VirgilByteArray VirgilAsn1Compatible::toAsn1() const { 52 | VirgilAsn1Writer asn1Writer; 53 | (void) asn1Write(asn1Writer); 54 | return asn1Writer.finish(); 55 | } 56 | 57 | void VirgilAsn1Compatible::fromAsn1(const VirgilByteArray& asn1) { 58 | VirgilAsn1Reader asn1Reader(asn1); 59 | asn1Read(asn1Reader); 60 | } 61 | 62 | 63 | void VirgilAsn1Compatible::checkRequiredField(const VirgilByteArray& param) const { 64 | if (param.empty()) { 65 | throw make_error(VirgilCryptoError::InvalidState); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /lib/src/stream/VirgilStreamDataSource.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | 38 | #if VIRGIL_CRYPTO_FEATURE_STREAM_IMPL 39 | 40 | #include 41 | #include 42 | 43 | #include 44 | 45 | using virgil::crypto::VirgilByteArray; 46 | using virgil::crypto::stream::VirgilStreamDataSource; 47 | 48 | static const size_t kChunkSizeMin = 32; 49 | 50 | VirgilStreamDataSource::VirgilStreamDataSource(std::istream& in, size_t chunkSize) 51 | : in_(in), chunkSize_(std::max(chunkSize, kChunkSizeMin)) { 52 | } 53 | 54 | VirgilStreamDataSource::~VirgilStreamDataSource() noexcept { 55 | } 56 | 57 | bool VirgilStreamDataSource::hasData() { 58 | return in_.good(); 59 | } 60 | 61 | VirgilByteArray VirgilStreamDataSource::read() { 62 | VirgilByteArray result(chunkSize_); 63 | in_.read(reinterpret_cast(result.data()), chunkSize_); 64 | if (!in_) { 65 | // Only part of chunk was read, so result MUST be trimmed. 66 | result.resize(in_.gcount()); 67 | } 68 | return result; 69 | } 70 | 71 | #endif /* VIRGIL_CRYPTO_FEATURE_STREAM_IMPL */ 72 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | matrix: 3 | include: 4 | - os: linux 5 | compiler: gcc 6 | env: LANG=cpp ALT_CC=gcc ALT_CXX=g++ PUBLISH_DOCS=ON 7 | sudo: required 8 | dist: xenial 9 | - os: linux 10 | compiler: gcc 11 | env: LANG=cpp ALT_CC=gcc-5 ALT_CXX=g++-5 12 | sudo: required 13 | dist: xenial 14 | - os: linux 15 | compiler: gcc 16 | env: LANG=cpp ALT_CC=gcc-6 ALT_CXX=g++-6 17 | sudo: required 18 | dist: xenial 19 | - os: linux 20 | compiler: clang 21 | env: LANG=cpp ALT_CC=clang-3.6 ALT_CXX=clang++-3.6 22 | sudo: required 23 | dist: xenial 24 | - os: linux 25 | compiler: gcc 26 | env: LANG=php LANG_VERSION=7.1 27 | sudo: required 28 | dist: xenial 29 | - os: linux 30 | compiler: gcc 31 | env: LANG=php LANG_VERSION=7.2 32 | sudo: required 33 | dist: xenial 34 | - os: linux 35 | compiler: gcc 36 | env: LANG=php LANG_VERSION=7.3 37 | sudo: required 38 | dist: xenial 39 | env: 40 | global: 41 | - VIRGIL_CRYPTO_FEATURE_LOW_LEVEL_WRAP=ON 42 | - VIRGIL_CRYPTO_FEATURE_PYTHIA=ON 43 | - PROJECT_ROOT=${TRAVIS_BUILD_DIR} 44 | - CMAKE_VERSION=3.14.3 45 | - SWIG_VERSION=4.0.0 46 | cache: 47 | directories: 48 | - swig-${SWIG_VERSION} 49 | before_install: 50 | - date -u 51 | - uname -a 52 | - if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then lscpu; fi 53 | # Travis overrides CC environment with compiler predefined values 54 | - if [ -n "${ALT_CC}" ]; then export CC="${ALT_CC}"; fi 55 | - if [ -n "${ALT_CXX}" ]; then export CXX="${ALT_CXX}"; fi 56 | - if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then source "${PROJECT_ROOT}/ci/install-deployment-key.sh"; fi 57 | install: 58 | # Use clean dependencies installation to avoid versions collision. 59 | - export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 60 | - if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then source "${PROJECT_ROOT}/ci/install-dependencies.sh"; fi 61 | - ${CC} --version 62 | - ${CXX} --version 63 | - cmake --version 64 | - swig -version 65 | - doxygen --version 66 | before_script: 67 | - CMAKE_ARGS="-DLANG=${LANG} -DPLATFORM_ARCH=`uname -m`" 68 | - CMAKE_ARGS+=" -DVIRGIL_CRYPTO_FEATURE_LOW_LEVEL_WRAP=${VIRGIL_CRYPTO_FEATURE_LOW_LEVEL_WRAP}" 69 | - CMAKE_ARGS+=" -DVIRGIL_CRYPTO_FEATURE_PYTHIA=${VIRGIL_CRYPTO_FEATURE_PYTHIA}" 70 | - CMAKE_ARGS+=" -DCMAKE_INSTALL_PREFIX=${PROJECT_ROOT}/install" 71 | - CMAKE_ARGS+=" -DLANG_VERSION=${LANG_VERSION}" 72 | - if [ "${LANG}" = "cpp" ]; then CMAKE_ARGS+=" -DVIRGIL_CRYPTO_FEATURE_STREAM_IMPL=ON"; fi 73 | - cmake -H"${PROJECT_ROOT}" -B"${PROJECT_ROOT}/build" ${CMAKE_ARGS} 74 | script: 75 | - cmake --build "${PROJECT_ROOT}/build" -- -j4 76 | - cd "${PROJECT_ROOT}/build" && ctest --verbose && cd - 77 | after_success: 78 | - source "${PROJECT_ROOT}/ci/publish-docs.sh" 79 | 80 | -------------------------------------------------------------------------------- /wrappers/asmjs/CMakeLists.txt: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | cmake_minimum_required (VERSION 3.10 FATAL_ERROR) 38 | 39 | project (${WRAPPED_LIB_NAME}_asmjs) 40 | 41 | # --------------------------------------------------------------------------- 42 | # Configure environment 43 | # --------------------------------------------------------------------------- 44 | set (LANG "asmjs" CACHE STRING "Language is asmjs" FORCE) 45 | set (LANG_VERSION "" CACHE STRING "No version for asmjs" FORCE) 46 | 47 | set (PLATFORM "" CACHE STRING "No platform name for asmjs, because it's crossplatform" FORCE) 48 | set (PLATFORM_VERSION "" CACHE STRING "No platform version for asmjs, because it's crossplatform" FORCE) 49 | 50 | set (WRAPPER_TARGET "${PROJECT_NAME}") 51 | 52 | # --------------------------------------------------------------------------- 53 | # Include common emsdk build instructions 54 | # --------------------------------------------------------------------------- 55 | include ("${WRAPPERS_ROOT}/emsdk/CMakeLists.txt") 56 | 57 | # --------------------------------------------------------------------------- 58 | # Add specific 'install' options to the target 59 | # --------------------------------------------------------------------------- 60 | -------------------------------------------------------------------------------- /lib/src/VirgilTagFilter.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include "VirgilTagFilter.h" 38 | 39 | using virgil::crypto::VirgilByteArray; 40 | using virgil::crypto::foundation::internal::VirgilTagFilter; 41 | 42 | 43 | VirgilTagFilter::VirgilTagFilter() : tagLen_(0), data_(), tag_() { 44 | } 45 | 46 | void VirgilTagFilter::reset(size_t tagLen) { 47 | tagLen_ = tagLen; 48 | data_.clear(); 49 | tag_.clear(); 50 | } 51 | 52 | void VirgilTagFilter::process(const VirgilByteArray& data) { 53 | tag_.insert(tag_.end(), data.begin(), data.end()); 54 | 55 | std::ptrdiff_t tagSurplusLen = tag_.size() - tagLen_; 56 | if (tagSurplusLen > 0) { 57 | auto tagSurplusBegin = tag_.begin(); 58 | auto tagSurplusEnd = tagSurplusBegin + tagSurplusLen; 59 | data_.insert(data_.end(), tagSurplusBegin, tagSurplusEnd); 60 | tag_.erase(tagSurplusBegin, tagSurplusEnd); 61 | } 62 | } 63 | 64 | bool VirgilTagFilter::hasData() const { 65 | return !data_.empty(); 66 | } 67 | 68 | VirgilByteArray VirgilTagFilter::popData() { 69 | VirgilByteArray result; 70 | result.swap(data_); 71 | return result; 72 | } 73 | 74 | VirgilByteArray VirgilTagFilter::tag() const { 75 | return tag_; 76 | } 77 | -------------------------------------------------------------------------------- /lib/src/VirgilConfig.h.in: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | 38 | #ifndef VIRGIL_CRYPTO_CONFIG 39 | #define VIRGIL_CRYPTO_CONFIG 40 | 41 | /** 42 | * Contains conditional macroses, that was used during library build. 43 | */ 44 | 45 | /** 46 | * On/Off status of the feature: C++ streams. 47 | */ 48 | #cmakedefine01 VIRGIL_CRYPTO_FEATURE_STREAM_IMPL 49 | 50 | /** 51 | * On/Off status of the feature: Pythia. 52 | */ 53 | #cmakedefine01 VIRGIL_CRYPTO_FEATURE_PYTHIA 54 | 55 | /** 56 | * On/Off status of the Pythia multhi-threading. 57 | */ 58 | #cmakedefine01 VIRGIL_CRYPTO_FEATURE_PYTHIA_MT 59 | 60 | 61 | namespace virgil { 62 | namespace crypto { 63 | 64 | class VirgilConfig { 65 | public: 66 | /** 67 | * @brief Runtime equiavalent of VIRGIL_CRYPTO_FEATURE_STREAM_IMPL 68 | */ 69 | static bool hasFeatureStreamImpl(); 70 | 71 | /** 72 | * @brief Runtime equiavalent of VIRGIL_CRYPTO_FEATURE_PYTHIA 73 | */ 74 | static bool hasFeaturePythiaImpl(); 75 | 76 | /** 77 | * @brief Runtime equiavalent of VIRGIL_CRYPTO_FEATURE_PYTHIA_MT 78 | */ 79 | static bool hasFeaturePythiaMultiThread(); 80 | 81 | }; 82 | 83 | } // crypto 84 | } // virgil 85 | 86 | #endif /* VIRGIL_CRYPTO_CONFIG */ 87 | -------------------------------------------------------------------------------- /cmake/file_regex_replace.cmake: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | # 38 | # This module can be used as part of the build process to perferom regex replace in given file. 39 | # 40 | # @example: 41 | # add_custom_command (TARGET ${tgt} POST_BUILD 42 | # COMMAND ${CMAKE_COMMAND} 43 | # ARGS 44 | # -DSRC:PATH=${PATH_TO_SOURCE_FILE} 45 | # -DREGULAR_EXPRESSION:STRING="XXX" 46 | # -DREPLACE_EXPRESSION:STRING="YYY" 47 | # -P "${FULL_PATH_TO_THIS_FILE}" 48 | # ) 49 | # 50 | 51 | if (NOT SRC) 52 | message (FATAL_ERROR "Source file is not defined. Please define variable SRC.") 53 | endif () 54 | 55 | if (NOT EXISTS ${SRC}) 56 | message (FATAL_ERROR "Given source file does not exists: " ${SRC}) 57 | endif () 58 | 59 | if (NOT REGULAR_EXPRESSION) 60 | message (FATAL_ERROR "Regular expression is not defined. Please define variable REGULAR_EXPRESSION.") 61 | endif () 62 | 63 | if (NOT REPLACE_EXPRESSION) 64 | message (FATAL_ERROR "Regular expression is not defined. Please define variable REPLACE_EXPRESSION.") 65 | endif () 66 | 67 | file (READ ${SRC} content) 68 | string (REGEX REPLACE "${REGULAR_EXPRESSION}" "${REPLACE_EXPRESSION}" modified_content "${content}") 69 | file (WRITE "${SRC}" "${modified_content}") 70 | -------------------------------------------------------------------------------- /lib/src/stream/VirgilBytesDataSource.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | 38 | #if VIRGIL_CRYPTO_FEATURE_STREAM_IMPL 39 | 40 | #include 41 | 42 | #include 43 | 44 | using virgil::crypto::stream::VirgilBytesDataSource; 45 | using virgil::crypto::VirgilByteArray; 46 | 47 | 48 | static const size_t kChunkSizeMin = 1; 49 | 50 | VirgilBytesDataSource::VirgilBytesDataSource(const VirgilByteArray& in, size_t chunkSize) 51 | : in_(in), chunkSize_(std::max(chunkSize, kChunkSizeMin)), leftBytes_(in.size()) { 52 | } 53 | 54 | VirgilBytesDataSource::~VirgilBytesDataSource() noexcept { 55 | } 56 | 57 | bool VirgilBytesDataSource::hasData() { 58 | return leftBytes_ > 0; 59 | } 60 | 61 | void VirgilBytesDataSource::reset() { 62 | leftBytes_ = in_.size(); 63 | } 64 | 65 | VirgilByteArray VirgilBytesDataSource::read() { 66 | size_t actualChunkSize = std::min(chunkSize_, leftBytes_); 67 | VirgilByteArray::const_iterator start = in_.begin() + in_.size() - leftBytes_; 68 | VirgilByteArray::const_iterator end = start + actualChunkSize; 69 | leftBytes_ -= actualChunkSize; 70 | return VirgilByteArray(start, end); 71 | } 72 | 73 | #endif /* VIRGIL_CRYPTO_FEATURE_STREAM_IMPL */ 74 | -------------------------------------------------------------------------------- /lib/include/virgil/crypto/VirgilDataSink.h: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #ifndef VIRGIL_CRYPTO_VIRGIL_DATA_SINK_H 38 | #define VIRGIL_CRYPTO_VIRGIL_DATA_SINK_H 39 | 40 | #include "VirgilByteArray.h" 41 | 42 | namespace virgil { namespace crypto { 43 | 44 | /** 45 | * @brief This is base class for output streams. 46 | * 47 | * Defines interface that allows write data to the output stream. 48 | */ 49 | class VirgilDataSink { 50 | public: 51 | /** 52 | * @brief Return true if target object is able to write data. 53 | */ 54 | virtual bool isGood() = 0; 55 | 56 | /** 57 | * @brief Write data to the target object. 58 | * @param data data to be written, SHOULD NOT be empty. 59 | */ 60 | virtual void write(const VirgilByteArray& data) = 0; 61 | 62 | /** 63 | * @brief Write data to the sink in a safe way. 64 | * 65 | * Write only if data is not empty and sink is good, otherwise - do nothing 66 | * 67 | * @param sink sink to be written to. 68 | * @param data data to be written. 69 | */ 70 | static void safeWrite(VirgilDataSink& sink, const VirgilByteArray& data); 71 | 72 | virtual ~VirgilDataSink() noexcept = default; 73 | }; 74 | 75 | }} 76 | 77 | #endif /* VIRGIL_CRYPTO_VIRGIL_DATA_SINK_H */ 78 | -------------------------------------------------------------------------------- /wrappers/swig/go/common.i.in: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #cmakedefine SWIG_TARGET_LINUX 38 | 39 | %insert(cgo_comment_typedefs) %{ 40 | #cgo CPPFLAGS: -I${SRCDIR}/include 41 | #cgo LDFLAGS: -L${SRCDIR}/lib -lvirgil_crypto_go -lvirgil_crypto -lmbedcrypto -led25519 -lstdc++ 42 | %} 43 | 44 | #if defined(SWIG_TARGET_LINUX) 45 | %insert(cgo_comment_typedefs) %{ 46 | #cgo LDFLAGS: -lm 47 | %} 48 | #endif 49 | 50 | #if VIRGIL_CRYPTO_FEATURE_PYTHIA 51 | %insert(cgo_comment_typedefs) %{ 52 | #cgo LDFLAGS: -lpythia -lrelic_s 53 | %} 54 | #endif 55 | 56 | %define SWIG_CATCH_STDEXCEPT 57 | /* catching std::exception */ 58 | catch (std::invalid_argument& e) { 59 | SWIG_exception(SWIG_ValueError, e.what() ); 60 | } catch (std::domain_error& e) { 61 | SWIG_exception(SWIG_ValueError, e.what() ); 62 | } catch (std::overflow_error& e) { 63 | SWIG_exception(SWIG_OverflowError, e.what() ); 64 | } catch (std::out_of_range& e) { 65 | SWIG_exception(SWIG_IndexError, e.what() ); 66 | } catch (std::length_error& e) { 67 | SWIG_exception(SWIG_IndexError, e.what() ); 68 | } catch (std::runtime_error& e) { 69 | SWIG_exception(SWIG_RuntimeError, e.what() ); 70 | } catch (std::exception& e) { 71 | SWIG_exception(SWIG_SystemError, e.what() ); 72 | } 73 | %enddef 74 | -------------------------------------------------------------------------------- /lib/include/virgil/crypto/stream/VirgilStreamDataSink.h: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #ifndef VIRGIL_CRYPTO_VIRGIL_STREAM_DATA_SINK_H 38 | #define VIRGIL_CRYPTO_VIRGIL_STREAM_DATA_SINK_H 39 | 40 | #include 41 | 42 | #include "../VirgilDataSink.h" 43 | 44 | namespace virgil { namespace crypto { namespace stream { 45 | 46 | /** 47 | * @brief C++ stream implementation of the VirgilDataSink class. 48 | * 49 | * @note This class CAN not be used in wrappers. 50 | */ 51 | class VirgilStreamDataSink : public virgil::crypto::VirgilDataSink { 52 | public: 53 | /** 54 | * @brief Creates data sink based on std::ostream object. 55 | */ 56 | explicit VirgilStreamDataSink(std::ostream& out); 57 | 58 | /** 59 | * @brief Polymorphic destructor. 60 | */ 61 | virtual ~VirgilStreamDataSink() noexcept; 62 | 63 | /** 64 | * @brief Overriding of @link VirgilDataSink::isGood() @endlink method. 65 | */ 66 | virtual bool isGood(); 67 | 68 | /** 69 | * @brief Overriding of @link VirgilDataSink::write() @endlink method. 70 | */ 71 | virtual void write(const virgil::crypto::VirgilByteArray& data); 72 | 73 | private: 74 | std::ostream& out_; 75 | }; 76 | 77 | }}} 78 | 79 | #endif /* VIRGIL_CRYPTO_VIRGIL_STREAM_DATA_SINK_H */ 80 | -------------------------------------------------------------------------------- /wrappers/java/src/VirgilStreamDataSource.java: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | package com.virgilsecurity.crypto; 38 | 39 | public class VirgilStreamDataSource extends VirgilDataSource implements java.io.Closeable { 40 | private java.io.InputStream stream; 41 | private int chunkSize; 42 | private static int CHUNK_SIZE_DEFAULT = 1024 * 1024; 43 | 44 | public VirgilStreamDataSource(java.io.InputStream stream) { 45 | this.stream = stream; 46 | this.chunkSize = CHUNK_SIZE_DEFAULT; 47 | } 48 | 49 | public VirgilStreamDataSource(java.io.InputStream stream, int chunkSize) { 50 | this.stream = stream; 51 | this.chunkSize = chunkSize; 52 | } 53 | 54 | @Override 55 | public boolean hasData() throws java.io.IOException { 56 | return this.stream.available() > 0; 57 | } 58 | 59 | @Override 60 | public byte[] read() throws java.io.IOException { 61 | final int bytesToReadNum = Math.min(this.stream.available(), this.chunkSize); 62 | byte[] result = new byte[bytesToReadNum]; 63 | this.stream.read(result, 0, bytesToReadNum); 64 | return result; 65 | } 66 | 67 | @Override 68 | public void close() throws java.io.IOException { 69 | this.stream.close(); 70 | this.delete(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /lib/include/virgil/crypto/VirgilVersion.h: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #ifndef VIRGIL_VERSION_H 38 | #define VIRGIL_VERSION_H 39 | 40 | #include 41 | #include 42 | 43 | namespace virgil { namespace crypto { 44 | 45 | /** 46 | * @brief Provides information about Virgil library version. 47 | */ 48 | class VirgilVersion { 49 | public: 50 | /** 51 | * Return version number in the format MMNNPP (Major, Minor, Patch). 52 | * 53 | */ 54 | static size_t asNumber(); 55 | 56 | /** 57 | * Return the version number as string. 58 | */ 59 | static std::string asString(); 60 | 61 | /** 62 | * Return the major version number. 63 | */ 64 | static size_t majorVersion(); 65 | 66 | /** 67 | * Return the minor version number. 68 | */ 69 | static size_t minorVersion(); 70 | 71 | /** 72 | * Return the minor version number. 73 | */ 74 | static size_t patchVersion(); 75 | 76 | /** 77 | * Return version full name. 78 | * 79 | * If current release contains some additional tag, like rc1, 80 | * then version full name will be different from the string returned by method asString(), 81 | * i.e. 1.3.4-rc1, or 1.3.4-coolfeature, etc. 82 | */ 83 | static std::string fullName(); 84 | }; 85 | 86 | }} 87 | 88 | #endif /* VIRGIL_VERSION_H */ 89 | -------------------------------------------------------------------------------- /wrappers/swig/java/common.i: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | %javaexception("java.io.IOException") virgil::crypto::VirgilDataSource::hasData {} 38 | %javaexception("java.io.IOException") virgil::crypto::VirgilDataSource::read {} 39 | %javaexception("java.io.IOException") virgil::crypto::VirgilDataSink::write {} 40 | %javaexception("java.io.IOException") virgil::crypto::VirgilDataSink::isGood {} 41 | 42 | %pragma(java) jniclassimports=%{ 43 | import com.virgilsecurity.crypto.JniLoader; 44 | %} 45 | 46 | %pragma(java) jniclassbase=%{JniLoader%} 47 | 48 | %typemap(javainterfaces) SWIGTYPE "java.lang.AutoCloseable"; 49 | %typemap(javacode) SWIGTYPE %{ 50 | @Override 51 | public void close() { 52 | delete(); 53 | } 54 | %} 55 | 56 | %typemap(javacode) virgil::crypto::VirgilDataSource %{ 57 | @Override 58 | public void close() throws java.io.IOException { 59 | delete(); 60 | } 61 | %} 62 | 63 | %typemap(javacode) virgil::crypto::VirgilDataSink %{ 64 | @Override 65 | public void close() throws java.io.IOException { 66 | delete(); 67 | } 68 | %} 69 | 70 | // VirgilByteArray typemap 71 | #define SWIG_VIRGIL_BYTE_ARRAY 72 | %include "java/VirgilByteArray.i" 73 | 74 | // Apply a rule for renaming the enum elements to avoid the common prefixes 75 | // which are redundant in Java 76 | %rename("%(regex:/^([A-Z][a-z]+)+_(.*)/\\2/)s", %$isenumitem) ""; 77 | -------------------------------------------------------------------------------- /lib/src/VirgilSigner.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | using virgil::crypto::VirgilSigner; 44 | using virgil::crypto::VirgilByteArray; 45 | 46 | using virgil::crypto::foundation::VirgilHash; 47 | 48 | VirgilByteArray VirgilSigner::sign( 49 | const VirgilByteArray& data, const VirgilByteArray& privateKey, const VirgilByteArray& privateKeyPassword) { 50 | 51 | // Calculate data digest 52 | const auto digest = VirgilHash(getHashAlgorithm()).hash(data); 53 | 54 | // Sign digest 55 | const auto signature = signHash(digest, privateKey, privateKeyPassword); 56 | 57 | // Pack signature 58 | return packSignature(signature); 59 | } 60 | 61 | bool VirgilSigner::verify(const VirgilByteArray& data, const VirgilByteArray& sign, const VirgilByteArray& publicKey) { 62 | 63 | // Unpack signature 64 | const auto signature = unpackSignature(sign); // MUST be before getHashAlgorithm() 65 | 66 | // Calculate data digest 67 | VirgilHash hash(getHashAlgorithm()); 68 | const auto digest = hash.hash(data); 69 | 70 | // Verify signature 71 | return verifyHash(digest, signature, publicKey); 72 | } 73 | -------------------------------------------------------------------------------- /cmake/copy_all_files.cmake: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | # 38 | # This module can be used as part of the build process to copy files from given directory and all it's subdirectories 39 | # to the single destination directory. 40 | # 41 | # @example: 42 | # add_custom_command (TARGET ${tgt} POST_BUILD 43 | # COMMAND ${CMAKE_COMMAND} 44 | # ARGS 45 | # -DSRC_DIR:PATH=${PATH_TO_SOURCE_DIR} 46 | # -DDST_DIR:PATH=${PATH_TO_SOURCE_DESTINATION_DIR} 47 | # -DGLOBBING_EXPRESSION:STRING="*.cxx" 48 | # -P "${FULL_PATH_TO_THIS_FILE}" 49 | # ) 50 | # 51 | 52 | if (NOT SRC_DIR) 53 | message (FATAL_ERROR "Source directory is not defined. Please define variable SRC_DIR.") 54 | endif () 55 | 56 | if (NOT IS_DIRECTORY ${SRC_DIR}) 57 | message (FATAL_ERROR "Given source directory does not exists: " ${SRC_DIR}) 58 | endif () 59 | 60 | if (NOT DST_DIR) 61 | message (FATAL_ERROR "Destination directory is not defined. Please define variable DST_DIR.") 62 | endif () 63 | 64 | if (NOT GLOBBING_EXPRESSION) 65 | message (FATAL_ERROR "Globbing expression is not defined. " 66 | "Please define variable GLOBBING_EXPRESSION to be used as template for coping process.") 67 | endif () 68 | 69 | file (GLOB_RECURSE sources ${SRC_DIR} ${GLOBBING_EXPRESSION}) 70 | file (COPY ${sources} DESTINATION ${DST_DIR}) 71 | -------------------------------------------------------------------------------- /cmake/aux_source_directory_to_file.cmake: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | # 38 | # Collects the names of all the source files in the specified directory and stores the list to the provided 39 | # 40 | # @example: 41 | # add_custom_command (TARGET ${tgt} POST_BUILD 42 | # COMMAND ${CMAKE_COMMAND} 43 | # ARGS 44 | # -DSRC_DIR:PATH=${PATH_TO_SOURCE_DIR} 45 | # -DDST_FILE:PATH=${PATH_TO_SOURCE_DESTINATION_FILE} 46 | # -DGLOBBING_EXPRESSION:STRING="*.cxx" 47 | # -P "${FULL_PATH_TO_THIS_FILE}" 48 | # ) 49 | # 50 | 51 | if (NOT SRC_DIR) 52 | message (FATAL_ERROR "Source directory is not defined. Please define variable SRC_DIR.") 53 | endif () 54 | 55 | if (NOT IS_DIRECTORY ${SRC_DIR}) 56 | message (FATAL_ERROR "Given source directory does not exists: " ${SRC_DIR}) 57 | endif () 58 | 59 | if (NOT DST_FILE) 60 | message (FATAL_ERROR "Destination file is not defined. Please define variable DST_FILE.") 61 | endif () 62 | 63 | if (NOT GLOBBING_EXPRESSION) 64 | message (FATAL_ERROR "Globbing expression is not defined. " 65 | "Please define variable GLOBBING_EXPRESSION to be used as template for coping process.") 66 | endif () 67 | 68 | file (GLOB_RECURSE sources ${SRC_DIR} ${GLOBBING_EXPRESSION}) 69 | string (REPLACE ";" "\n" sources "${sources}") 70 | file (WRITE ${DST_FILE} ${sources}) 71 | -------------------------------------------------------------------------------- /libs_ext/tinyformat/tinyformat.cmake: -------------------------------------------------------------------------------- 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. 35 | # 36 | 37 | cmake_minimum_required (VERSION @CMAKE_VERSION@ FATAL_ERROR) 38 | 39 | project (tinyformat VERSION 2.0.1 LANGUAGES CXX) 40 | 41 | # Define names for configuration files 42 | set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in") 43 | set (INSTALL_CFG_DIR_NAME 44 | "lib/cmake/${PROJECT_NAME}" CACHE STRING 45 | "Path to the CMake configuration files be installed" 46 | ) 47 | set (generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") 48 | set (version_config "${generated_dir}/${PROJECT_NAME}-config-version.cmake") 49 | set (project_config "${generated_dir}/${PROJECT_NAME}-config.cmake") 50 | 51 | # Create configuration files 52 | include (CMakePackageConfigHelpers) 53 | 54 | # Write Version Config 55 | write_basic_package_version_file ( 56 | "${version_config}" COMPATIBILITY SameMajorVersion 57 | ) 58 | 59 | # Write Project Config 60 | configure_package_config_file ( 61 | "cmake/config.cmake.in" 62 | "${project_config}" 63 | INSTALL_DESTINATION "${INSTALL_CFG_DIR_NAME}" 64 | PATH_VARS INCLUDE_INSTALL_DIR 65 | ) 66 | 67 | # Install headers 68 | install ( 69 | DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/" 70 | DESTINATION "include/tinyformat" 71 | ) 72 | 73 | # Install configurations 74 | install ( 75 | FILES "${project_config}" "${version_config}" 76 | DESTINATION "${INSTALL_CFG_DIR_NAME}" 77 | ) 78 | -------------------------------------------------------------------------------- /tests/test_tag_filter.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | /** 38 | * @file test_hash.cxx 39 | * @brief Covers class VirgilByteArrayUtils 40 | */ 41 | 42 | #include "catch.hpp" 43 | 44 | #include 45 | 46 | #include 47 | #include 48 | 49 | #include "VirgilTagFilter.h" 50 | 51 | using virgil::crypto::VirgilByteArray; 52 | using virgil::crypto::VirgilByteArrayUtils; 53 | using virgil::crypto::foundation::internal::VirgilTagFilter; 54 | 55 | TEST_CASE("Get TAG", "[tag-filter]") { 56 | VirgilTagFilter tagFilter; 57 | size_t kTagLen = 16; 58 | 59 | SECTION("Case 1") { 60 | tagFilter.reset(kTagLen); 61 | tagFilter.process(VirgilByteArrayUtils::hexToBytes( 62 | "5eb9ee8ee83801858815e0fc301204102ccda65f87808b4dcdfebd970b881e95") 63 | ); 64 | REQUIRE(kTagLen == tagFilter.tag().size()); 65 | REQUIRE(VirgilByteArrayUtils::bytesToHex(tagFilter.tag()) == "2ccda65f87808b4dcdfebd970b881e95"); 66 | } 67 | SECTION("Case 2") { 68 | tagFilter.reset(kTagLen); 69 | tagFilter.process(VirgilByteArrayUtils::hexToBytes( 70 | "11111111111111301204102ccda65f87808b4dcdfebd970b881e95") 71 | ); 72 | REQUIRE(kTagLen == tagFilter.tag().size()); 73 | REQUIRE(VirgilByteArrayUtils::bytesToHex(tagFilter.tag()) == "2ccda65f87808b4dcdfebd970b881e95"); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /lib/include/virgil/crypto/stream/VirgilBytesDataSink.h: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #ifndef VIRGIL_CRYPTO_VIRGIL_BYTES_DATA_SINK_H 38 | #define VIRGIL_CRYPTO_VIRGIL_BYTES_DATA_SINK_H 39 | 40 | #include "../VirgilDataSink.h" 41 | 42 | namespace virgil { namespace crypto { namespace stream { 43 | 44 | /** 45 | * @brief C++ Byte Array implementation of the VirgilDataSink class. 46 | * 47 | * @note This class CAN not be used in wrappers. 48 | */ 49 | class VirgilBytesDataSink : public virgil::crypto::VirgilDataSink { 50 | public: 51 | /** 52 | * @brief Creates data sink based on byte array. 53 | */ 54 | explicit VirgilBytesDataSink(virgil::crypto::VirgilByteArray& out); 55 | 56 | /** 57 | * @brief Polymorphic destructor. 58 | */ 59 | virtual ~VirgilBytesDataSink() noexcept; 60 | 61 | /** 62 | * @brief Overriding of @link VirgilDataSink::isGood() @endlink method. 63 | */ 64 | virtual bool isGood(); 65 | 66 | /** 67 | * @brief Overriding of @link VirgilDataSink::write() @endlink method. 68 | */ 69 | virtual void write(const virgil::crypto::VirgilByteArray& data); 70 | 71 | /** 72 | * @brief Reset internal state to initial. 73 | * 74 | * Erase all data from the output byte array. 75 | */ 76 | virtual void reset(); 77 | 78 | private: 79 | virgil::crypto::VirgilByteArray& out_; 80 | }; 81 | 82 | }}} 83 | 84 | #endif /* VIRGIL_CRYPTO_VIRGIL_BYTES_DATA_SINK_H */ 85 | -------------------------------------------------------------------------------- /lib/include/virgil/crypto/pfs/VirgilPFSInitiatorPublicInfo.h: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #ifndef VIRGIL_CRYPTO_PFS_VIRGIL_PFS_INITIATOR_PUBLIC_INFO_H 38 | #define VIRGIL_CRYPTO_PFS_VIRGIL_PFS_INITIATOR_PUBLIC_INFO_H 39 | 40 | #include "../VirgilByteArray.h" 41 | #include "VirgilPFSPublicKey.h" 42 | 43 | namespace virgil { namespace crypto { namespace pfs { 44 | 45 | /** 46 | * @brief This is model object that represent public information of a PFS Initiator. 47 | * 48 | * Initiator ia a side that starts communication. 49 | * 50 | * @see VirgilPFS 51 | * @ingroup pfs 52 | */ 53 | class VirgilPFSInitiatorPublicInfo { 54 | public: 55 | /** 56 | * @param identityPublicKey - public key that is connected to the Initiator's identity. 57 | * @param ephemeralPublicKey - ephemeral public key. 58 | */ 59 | VirgilPFSInitiatorPublicInfo(VirgilPFSPublicKey identityPublicKey, VirgilPFSPublicKey ephemeralPublicKey); 60 | 61 | /** 62 | * @brief Getter. 63 | * @see VirgilPFSInitiatorPublicInfo() 64 | */ 65 | const VirgilPFSPublicKey& getIdentityPublicKey() const; 66 | 67 | /** 68 | * @brief Getter. 69 | * @see VirgilPFSInitiatorPublicInfo() 70 | */ 71 | const VirgilPFSPublicKey& getEphemeralPublicKey() const; 72 | 73 | private: 74 | VirgilPFSPublicKey identityPublicKey_; 75 | VirgilPFSPublicKey ephemeralPublicKey_; 76 | }; 77 | 78 | }}} 79 | 80 | #endif //VIRGIL_CRYPTO_PFS_VIRGIL_PFS_INITIATOR_PUBLIC_INFO_H 81 | -------------------------------------------------------------------------------- /cmake/TransitiveArgs.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015-2018 Virgil Security Inc. 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are 7 | # met: 8 | # 9 | # (1) Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # 12 | # (2) Redistributions in binary form must reproduce the above copyright 13 | # notice, this list of conditions and the following disclaimer in 14 | # the documentation and/or other materials provided with the 15 | # distribution. 16 | # 17 | # (3) Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR 22 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | # 33 | # Lead Maintainer: Virgil Security Inc. 34 | 35 | 36 | if(${CMAKE_VERSION} VERSION_LESS "3.10") 37 | if(__TRANSITIVE_ARGS_INCLUDED__) 38 | return() 39 | endif() 40 | 41 | set(__TRANSITIVE_ARGS_INCLUDED__ TRUE) 42 | else() 43 | include_guard() 44 | endif() 45 | 46 | 47 | function(TRANSITIVE_ARGS_INIT) 48 | if(NOT TRANSITIVE_ARGS_FILE) 49 | set(TRANSITIVE_ARGS_FILE "${CMAKE_BINARY_DIR}/transitive-args.cmake" CACHE FILEPATH "") 50 | endif () 51 | 52 | if(NOT EXISTS "${TRANSITIVE_ARGS_FILE}") 53 | file(WRITE "${TRANSITIVE_ARGS_FILE}" 54 | "set(TRANSITIVE_ARGS_FILE \"${TRANSITIVE_ARGS_FILE}\" CACHE FILEPATH \"\")\n") 55 | endif() 56 | endfunction() 57 | 58 | 59 | function(TRANSITIVE_ARGS_ADD) 60 | if(NOT TRANSITIVE_ARGS_FILE) 61 | message(FATAL_ERROR "[INTERNAL] TransitiveArgs.cmake: variable TRANSITIVE_ARGS_FILE is not defined") 62 | endif () 63 | 64 | if(NOT EXISTS "${TRANSITIVE_ARGS_FILE}") 65 | message(FATAL_ERROR "[INTERNAL] TransitiveArgs.cmake: file '${TRANSITIVE_ARGS_FILE}' does not exists") 66 | endif () 67 | 68 | file(STRINGS "${TRANSITIVE_ARGS_FILE}" file_content) 69 | 70 | foreach(var ${ARGN}) 71 | if(${var} AND NOT file_content MATCHES "${var}") 72 | file(APPEND "${TRANSITIVE_ARGS_FILE}" "set(${var} \"${${var}}\" CACHE INTERNAL \"\")\n") 73 | endif() 74 | endforeach() 75 | endfunction() 76 | 77 | 78 | transitive_args_init () 79 | -------------------------------------------------------------------------------- /lib/include/virgil/crypto/pfs/VirgilPFSInitiatorPrivateInfo.h: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #ifndef VIRGIL_CRYPTO_PFS_VIRGIL_PFS_INITIATOR_PRIVATE_INFO_H 38 | #define VIRGIL_CRYPTO_PFS_VIRGIL_PFS_INITIATOR_PRIVATE_INFO_H 39 | 40 | #include "../VirgilByteArray.h" 41 | #include "VirgilPFSPrivateKey.h" 42 | 43 | namespace virgil { namespace crypto { namespace pfs { 44 | 45 | /** 46 | * @brief This is model object that represent private information of a PFS Initiator. 47 | * 48 | * Initiator ia a side that starts communication. 49 | * 50 | * @see VirgilPFS 51 | * @ingroup pfs 52 | */ 53 | class VirgilPFSInitiatorPrivateInfo { 54 | public: 55 | /** 56 | * @param identityPrivateKey - private key that is connected to the Initiator's identity. 57 | * @param ephemeralPrivateKey - ephemeral private key. 58 | */ 59 | VirgilPFSInitiatorPrivateInfo(VirgilPFSPrivateKey identityPrivateKey, VirgilPFSPrivateKey ephemeralPrivateKey); 60 | 61 | /** 62 | * @brief Getter. 63 | * @see VirgilPFSInitiatorPrivateInfo() 64 | */ 65 | const VirgilPFSPrivateKey& getIdentityPrivateKey() const; 66 | 67 | /** 68 | * @brief Getter. 69 | * @see VirgilPFSInitiatorPrivateInfo() 70 | */ 71 | const VirgilPFSPrivateKey& getEphemeralPrivateKey() const; 72 | 73 | private: 74 | VirgilPFSPrivateKey identityPrivateKey_; 75 | VirgilPFSPrivateKey ephemeralPrivateKey_; 76 | }; 77 | 78 | }}} 79 | 80 | #endif //VIRGIL_CRYPTO_PFS_VIRGIL_PFS_INITIATOR_PRIVATE_INFO_H 81 | -------------------------------------------------------------------------------- /lib/src/VirgilStreamSigner.cxx: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | #include 38 | 39 | using virgil::crypto::VirgilByteArray; 40 | using virgil::crypto::VirgilDataSource; 41 | using virgil::crypto::VirgilStreamSigner; 42 | 43 | using virgil::crypto::foundation::VirgilHash; 44 | 45 | VirgilByteArray VirgilStreamSigner::sign( 46 | VirgilDataSource& source, const VirgilByteArray& privateKey, 47 | const VirgilByteArray& privateKeyPassword) { 48 | 49 | // Calculate data digest 50 | VirgilHash hash(getHashAlgorithm()); 51 | hash.start(); 52 | while (source.hasData()) { 53 | hash.update(source.read()); 54 | } 55 | const auto digest = hash.finish(); 56 | 57 | // Sign digest 58 | const auto signature = signHash(digest, privateKey, privateKeyPassword); 59 | 60 | // Pack signature 61 | return packSignature(signature); 62 | } 63 | 64 | bool VirgilStreamSigner::verify( 65 | VirgilDataSource& source, const VirgilByteArray& sign, const VirgilByteArray& publicKey) { 66 | 67 | // Unpack signature 68 | const auto signature = unpackSignature(sign); // MUST be before getHashAlgorithm() 69 | 70 | // Calculate data digest 71 | VirgilHash hash(getHashAlgorithm()); 72 | hash.start(); 73 | while (source.hasData()) { 74 | hash.update(source.read()); 75 | } 76 | const auto digest = hash.finish(); 77 | 78 | // Verify signature 79 | return verifyHash(digest, signature, publicKey); 80 | } 81 | -------------------------------------------------------------------------------- /wrappers/swig/util.i: -------------------------------------------------------------------------------- 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. 35 | */ 36 | 37 | %define DEFINE_NAMESPACE(className, package) 38 | #if defined(SWIG_WRAP_NAMESPACE) 39 | %nspace package::className; 40 | #endif 41 | %enddef 42 | 43 | %define INCLUDE_TYPE(typeName, includePath) 44 | %insert("begin") %{ 45 | #include 46 | %} 47 | %include 48 | %enddef 49 | 50 | %define INCLUDE_CLASS(className, package, includePath) 51 | DEFINE_NAMESPACE(className, package) 52 | %insert("begin") %{ 53 | #include 54 | %} 55 | %ignore package::className::className(className&&); 56 | %ignore package::className::operator=(className&&); 57 | %include 58 | %enddef 59 | 60 | %define INCLUDE_CLASS_WITH_DIRECTOR(className, package, includePath) 61 | DEFINE_NAMESPACE(className, package) 62 | %insert("begin") %{ 63 | #include 64 | %} 65 | %feature("director") className; 66 | %include 67 | %enddef 68 | 69 | %define INCLUDE_CLASS_WITH_COPY_CONSTRUCTOR(className, package, includePath) 70 | DEFINE_NAMESPACE(className, package) 71 | %insert("begin") %{ 72 | #include 73 | %} 74 | #if defined(SWIG_WRAP_COPY_CONSTRUCTOR) 75 | %copyctor className; 76 | #else 77 | %ignore package::className::className(const package::className &); 78 | #endif 79 | %include 80 | %enddef 81 | 82 | %define DEFINE_USING(className, package) 83 | %insert("begin") %{ 84 | using package::className; 85 | %} 86 | %enddef 87 | --------------------------------------------------------------------------------