Skip to content

Commit

Permalink
Virgil Security Crypto Library v2.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeySeroshtan committed Jun 21, 2018
2 parents 0bb2afb + 67f791a commit 0494728
Show file tree
Hide file tree
Showing 24 changed files with 705 additions and 163 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ project (VirgilSecurity)
# Set library version
set (VIRGIL_VERSION_MAJOR 2)
set (VIRGIL_VERSION_MINOR 4)
set (VIRGIL_VERSION_PATCH 5)
set (VIRGIL_VERSION_PATCH 6)
set (VIRGIL_VERSION_TAG)
set (VIRGIL_VERSION ${VIRGIL_VERSION_MAJOR}.${VIRGIL_VERSION_MINOR}.${VIRGIL_VERSION_PATCH})
set (VIRGIL_SOVERSION 2)
Expand Down
23 changes: 23 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
virgil ChangeLog (Sorted per date)

= Version 2.4.6 released 2018-06-21

## Features

* [PHP] Make available to build PHP wrapper on Windows
* [CI] Add build of PHP binaries on Jenkins and publish them to CDN
* [Build] Add universal CMake module 'FindPHP.cmake' that finds PHP on Windows and Unix
* [Build] Add building of target 'php' with 'build.bat' script

## Changes

* [JS] Update NodeJS version v10.1.0 -> v10.4.1
* [JS] Update NodeJS version v9.11.1 -> v9.11.2
* [JS] Update NodeJS version v8.11.2 -> v8.11.3
* [JS] Update NodeJS version v6.14.2 -> v6.14.3
* [SWIG] Place includes at the 'begin' SWIG section instead of 'header' section


## Bugfix

* [Lib] Fix crash on Pythia object creation for NodeJS versions >= 10.0


= Version 2.4.5 released 2018-05-30

## Changes
Expand Down
16 changes: 12 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ def createNativeWindowsBuild(slave) {
bat 'utils\\build.bat net'
bat 'utils\\build.bat java'
bat 'utils\\build.bat nodejs-4.9.1'
bat 'utils\\build.bat nodejs-6.14.2'
bat 'utils\\build.bat nodejs-6.14.3'
bat 'utils\\build.bat nodejs-7.10.1'
bat 'utils\\build.bat nodejs-8.11.2'
bat 'utils\\build.bat nodejs-9.11.1'
bat 'utils\\build.bat nodejs-10.1.0'
bat 'utils\\build.bat nodejs-8.11.3'
bat 'utils\\build.bat nodejs-9.11.2'
bat 'utils\\build.bat nodejs-10.4.1'
withEnv(["PATH=C:\\Python27_x86;${env.PATH}"]) {
bat 'utils\\build.bat python-2.7-x86'
}
Expand Down Expand Up @@ -166,11 +166,19 @@ def createNativeWindowsBuild(slave) {
bat 'utils\\build.bat python-3.6-x64'
}
}
withEnv(["MSVC_ROOT=C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community",
"PHP_HOME=C:\\php-7.2.6",
"PHP_DEVEL_HOME=C:\\php-7.2.6-devel",\
"PHPUNIT_HOME=C:\\phpunit-7.2.4"]) {

bat 'utils\\build.bat php-7.2-x64'
}
organizeFilesWindows('install\\cpp')
organizeFilesWindows('install\\net')
organizeFilesWindows('install\\java')
organizeFilesWindows('install\\nodejs')
organizeFilesWindows('install\\python')
organizeFilesWindows('install\\php')
archiveArtifacts('install/**')
}
}
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.5
2.4.6
74 changes: 11 additions & 63 deletions lib/include/virgil/crypto/VirgilByteArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@
#ifndef VIRGIL_BYTE_ARRAY_H
#define VIRGIL_BYTE_ARRAY_H

#include <cstring>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <tuple>

namespace virgil { namespace crypto {
Expand Down Expand Up @@ -71,33 +67,19 @@ namespace virgil { namespace crypto {
/**
* @brief Represents given string as byte array.
*/
inline VirgilByteArray str2bytes(const std::string& str) {
return VIRGIL_BYTE_ARRAY_FROM_PTR_AND_LEN(str.data(), str.size());
}
VirgilByteArray str2bytes(const std::string& str);

/**
* @brief Represent given byte array as string.
*/
inline std::string bytes2str(const VirgilByteArray& array) {
return std::string(reinterpret_cast<const char*>(array.data()), array.size());
}
std::string bytes2str(const VirgilByteArray& array);

/**
* @brief Translate given HEX string to the byte array.
* @param hexStr - HEX string.
* @return Byte array.
*/
inline VirgilByteArray hex2bytes(const std::string hexStr) {
VirgilByteArray result;
std::istringstream istr(hexStr);
char hexChars[3] = {0x00};
while (istr.read(hexChars, 2)) {
int byte = 0;
std::istringstream(hexChars) >> std::hex >> byte;
result.push_back((unsigned char) byte);
}
return result;
}
VirgilByteArray hex2bytes(const std::string hexStr);

/**
* @brief Translate given byte array to the HEX string.
Expand All @@ -106,38 +88,21 @@ inline VirgilByteArray hex2bytes(const std::string hexStr) {
* and all bytes will be separated with whitespaces.
* @return HEX string.
*/
inline std::string bytes2hex(const VirgilByteArray& array, bool formatted = false) {
std::ostringstream hexStream;
hexStream << std::setfill('0');
for (size_t i = 0; i < array.size(); ++i) {
hexStream << std::hex << std::setw(2) << (int) array[i];
if (formatted) {
hexStream << (((i + 1) % 16 == 0) ? "\n" : " ");
}
}
return hexStream.str();
}
std::string bytes2hex(const VirgilByteArray& array, bool formatted = false) ;

/**
* @name ByteArray security clear utilities
*/
///@{
/**
* @brief Make all bytes zero.
*/
inline void bytes_zeroize(VirgilByteArray& array) {
size_t n = array.size();
volatile unsigned char* p = const_cast<unsigned char*>(array.data());
while (n--) { *p++ = 0; }
}
void bytes_zeroize(VirgilByteArray& array) ;

/**
* @brief Make all chars zero.
*/
inline void string_zeroize(std::string& str) {
size_t n = str.size();
volatile char* p = const_cast<char*>(str.c_str());
while (n--) { *p++ = '\0'; }
}
void string_zeroize(std::string& str);
///@}

/**
Expand All @@ -146,47 +111,30 @@ inline void string_zeroize(std::string& str) {
* @param src - bytes append from.
* @return Reference to destination (dst).
*/
inline VirgilByteArray& bytes_append(VirgilByteArray& dst, const VirgilByteArray& src) {
dst.insert(dst.end(), src.cbegin(), src.cend());
return dst;
}
VirgilByteArray& bytes_append(VirgilByteArray& dst, const VirgilByteArray& src);

/**
* @brief Split given bytes to two sequences.
* @param src - bytes to be splitted.
* @param pos - splitting position.
* @return Two sequences: src[0, pos), src[pos, src.size()).
*/
inline std::tuple<VirgilByteArray, VirgilByteArray> bytes_split(const VirgilByteArray& src, size_t pos) {
return std::make_tuple(
VirgilByteArray(src.cbegin(), src.cbegin() + pos),
VirgilByteArray(src.cbegin() + pos, src.cend()));
}
std::tuple<VirgilByteArray, VirgilByteArray> bytes_split(const VirgilByteArray& src, size_t pos);

/**
* @brief Split given bytes to two sequences of the same size.
* @param src - bytes to be splitted.
* @return Two sequences: src[0, src.size()/2), src[src.size()/2, src.size()).
*/
inline std::tuple<VirgilByteArray, VirgilByteArray> bytes_split_half(const VirgilByteArray& src) {
const auto halfPos = src.size() >> 1;
return bytes_split(src, halfPos);
}
std::tuple<VirgilByteArray, VirgilByteArray> bytes_split_half(const VirgilByteArray& src);

/**
* @brief Split given bytes to the chuns of the given size.
* @param src - bytes to be splitted.
* @param chunkSize - size of the chunk.
* @return Chunks, each of the chunkSize.
*/
inline std::vector<VirgilByteArray> bytes_split_chunks(const VirgilByteArray& src, size_t chunkSize) {
std::vector<VirgilByteArray> chunks;
for (auto begin = src.cbegin(); begin < src.cend(); begin += chunkSize) {
auto end = std::min(begin + chunkSize, src.end());
chunks.emplace_back(VirgilByteArray(begin, end));
}
return chunks;
}
std::vector<VirgilByteArray> bytes_split_chunks(const VirgilByteArray& src, size_t chunkSize);

}}
#endif /* VIRGIL_BYTE_ARRAY_H */
3 changes: 2 additions & 1 deletion lib/include/virgil/crypto/primitive/VirgilOperationCipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class VirgilOperationCipher {
virtual VirgilByteArray doDecrypt(
const VirgilByteArray& plainText, const VirgilByteArray& key, const VirgilByteArray& nonce,
const VirgilByteArray& authData) const = 0;

virtual ~Concept() noexcept = default;
};

template<class Impl>
Expand All @@ -153,7 +155,6 @@ class VirgilOperationCipher {
const VirgilByteArray& authData) const override {
return impl_.decrypt(plainText, key, nonce, authData);
}

private:
Impl impl_;
};
Expand Down
2 changes: 2 additions & 0 deletions lib/include/virgil/crypto/primitive/VirgilOperationDH.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class VirgilOperationDH {
virtual VirgilByteArray doCalculate(
const VirgilByteArray& publicKey, const VirgilByteArray& privateKey,
const VirgilByteArray& privateKeyPassword) const = 0;

virtual ~Concept() noexcept = default;
};

template<class Impl>
Expand Down
4 changes: 3 additions & 1 deletion lib/include/virgil/crypto/primitive/VirgilOperationHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ class VirgilOperationHash {
virtual void doUpdate(const VirgilByteArray& data) = 0;

virtual VirgilByteArray doFinish() = 0;
};

virtual ~Concept() noexcept = default;
};

template<class Impl>
struct Model : Concept {
Expand Down
2 changes: 2 additions & 0 deletions lib/include/virgil/crypto/primitive/VirgilOperationKDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class VirgilOperationKDF {
virtual VirgilByteArray doDerive(
const VirgilByteArray& keyMaterial, const VirgilByteArray& salt,
const VirgilByteArray& info, size_t size) const = 0;

virtual ~Concept() noexcept = default;
};

template<class Impl>
Expand Down
2 changes: 2 additions & 0 deletions lib/include/virgil/crypto/primitive/VirgilOperationRandom.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class VirgilOperationRandom {
virtual VirgilByteArray doRandomize(size_t bytesNum) = 0;

virtual Concept* doCopy() const = 0;

virtual ~Concept() noexcept = default;
};

template<class Random>
Expand Down
3 changes: 2 additions & 1 deletion lib/src/VirgilAsn1Writer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <virgil/crypto/foundation/asn1/VirgilAsn1Writer.h>

#include <cmath>
#include <cstring>

#include <tinyformat/tinyformat.h>
#include <mbedtls/asn1.h>
Expand Down Expand Up @@ -292,7 +293,7 @@ void VirgilAsn1Writer::relocateBuffer(size_t newBufLen) {
size_t writtenBytes = 0;
if (buf_ && p_ && start_) {
writtenBytes = bufLen_ - (p_ - start_);
memcpy(newBuf + newBufLen - writtenBytes, p_, writtenBytes);
std::memcpy(newBuf + newBufLen - writtenBytes, p_, writtenBytes);
delete[] buf_;
}
buf_ = newBuf;
Expand Down
Loading

0 comments on commit 0494728

Please sign in to comment.