x64 fixICU fixes
git-svn-id: svn://db.shs.com.ru/pip@99 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -126,12 +126,12 @@ endif ()
|
|||||||
|
|
||||||
# Check if PIP support cryptographic encryption/decryption by using sodium library
|
# Check if PIP support cryptographic encryption/decryption by using sodium library
|
||||||
if (DEFINED CRYPT)
|
if (DEFINED CRYPT)
|
||||||
message(STATUS "Building with CRYPT")
|
message(STATUS "Building with CRYPT support")
|
||||||
unset(CRYPT)
|
unset(CRYPT)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_CRYPT")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_CRYPT")
|
||||||
list(APPEND LIBS sodium)
|
list(APPEND LIBS sodium)
|
||||||
else ()
|
else ()
|
||||||
message(STATUS "Building without CRYPTH, encryption doesn't work")
|
message(STATUS "Building without CRYPT, encryption doesn't work")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
main.cpp
2
main.cpp
@@ -232,7 +232,7 @@ int main (int argc, char * argv[]) {
|
|||||||
PIByteArray sba = cr.crypt(ba);
|
PIByteArray sba = cr.crypt(ba);
|
||||||
piCout << ba.size() << ba;
|
piCout << ba.size() << ba;
|
||||||
piCout << k.size() << k;
|
piCout << k.size() << k;
|
||||||
piCout << cr.getKey().size() << cr.getKey();
|
piCout << cr.key().size() << cr.key();
|
||||||
piCout << sba.size() << sba;
|
piCout << sba.size() << sba;
|
||||||
piCout << cr.decrypt(sba).size() << cr.decrypt(sba);
|
piCout << cr.decrypt(sba).size() << cr.decrypt(sba);
|
||||||
sba[random()%sba.size()]++;
|
sba[random()%sba.size()]++;
|
||||||
|
|||||||
@@ -1,16 +1,35 @@
|
|||||||
#include "picrypt.h"
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
Cryptographic class using lib Sodium
|
||||||
|
Copyright (C) 2015 Andrey Bychkov work.a.b@yandex.ru
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "picrypt.h"
|
||||||
#ifdef PIP_CRYPT
|
#ifdef PIP_CRYPT
|
||||||
# include "sodium.h"
|
# include "sodium.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
PICrypt::PICrypt() {
|
PICrypt::PICrypt() {
|
||||||
#ifdef PIP_CRYPT
|
#ifdef PIP_CRYPT
|
||||||
sodium_init();
|
sodium_init();
|
||||||
nonce.resize(crypto_secretbox_NONCEBYTES);
|
nonce_.resize(crypto_secretbox_NONCEBYTES);
|
||||||
key.resize(crypto_secretbox_KEYBYTES);
|
key_.resize(crypto_secretbox_KEYBYTES);
|
||||||
randombytes_buf(key.data(), key.size());
|
randombytes_buf(key_.data(), key_.size());
|
||||||
randombytes_buf(nonce.data(), nonce.size());
|
randombytes_buf(nonce_.data(), nonce_.size());
|
||||||
#else
|
#else
|
||||||
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
|
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
|
||||||
#endif
|
#endif
|
||||||
@@ -18,8 +37,8 @@ PICrypt::PICrypt() {
|
|||||||
|
|
||||||
|
|
||||||
bool PICrypt::setKey(const PIByteArray & secret) {
|
bool PICrypt::setKey(const PIByteArray & secret) {
|
||||||
if (secret.size() != key.size()) return false;
|
if (secret.size() != key_.size()) return false;
|
||||||
key = secret;
|
key_ = secret;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,40 +49,35 @@ PIByteArray PICrypt::setKey(const PIString &secret) {
|
|||||||
hash.resize(crypto_generichash_BYTES);
|
hash.resize(crypto_generichash_BYTES);
|
||||||
PIByteArray s(secret.data(), secret.size());
|
PIByteArray s(secret.data(), secret.size());
|
||||||
crypto_generichash(hash.data(), hash.size(), s.data(), s.size(), 0, 0);
|
crypto_generichash(hash.data(), hash.size(), s.data(), s.size(), 0, 0);
|
||||||
hash.resize(key.size());
|
hash.resize(key_.size());
|
||||||
setKey(hash);
|
setKey(hash);
|
||||||
#endif
|
#endif
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIByteArray PICrypt::getKey() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PIByteArray PICrypt::crypt(const PIByteArray & data) {
|
PIByteArray PICrypt::crypt(const PIByteArray & data) {
|
||||||
PIByteArray ret;
|
PIByteArray ret;
|
||||||
#ifdef PIP_CRYPT
|
#ifdef PIP_CRYPT
|
||||||
ret.resize(data.size() + crypto_secretbox_MACBYTES);
|
ret.resize(data.size() + crypto_secretbox_MACBYTES);
|
||||||
randombytes_buf(nonce.data(), nonce.size());
|
randombytes_buf(nonce_.data(), nonce_.size());
|
||||||
crypto_secretbox_easy(ret.data(), data.data(), data.size(), nonce.data(), key.data());
|
crypto_secretbox_easy(ret.data(), data.data(), data.size(), nonce_.data(), key_.data());
|
||||||
ret.append(nonce);
|
ret.append(nonce_);
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIByteArray PICrypt::crypt(const PIByteArray &data, const PIByteArray &secret) {
|
PIByteArray PICrypt::crypt(const PIByteArray & data, const PIByteArray & key) {
|
||||||
PIByteArray ret;
|
PIByteArray ret;
|
||||||
#ifdef PIP_CRYPT
|
#ifdef PIP_CRYPT
|
||||||
if (secret.size() != crypto_secretbox_KEYBYTES) return PIByteArray();
|
if (key.size() != crypto_secretbox_KEYBYTES) return PIByteArray();
|
||||||
sodium_init();
|
sodium_init();
|
||||||
PIByteArray n;
|
PIByteArray n;
|
||||||
ret.resize(data.size() + crypto_secretbox_MACBYTES);
|
ret.resize(data.size() + crypto_secretbox_MACBYTES);
|
||||||
n.resize(crypto_secretbox_NONCEBYTES);
|
n.resize(crypto_secretbox_NONCEBYTES);
|
||||||
randombytes_buf(n.data(), n.size());
|
randombytes_buf(n.data(), n.size());
|
||||||
crypto_secretbox_easy(ret.data(), data.data(), data.size(), n.data(), secret.data());
|
crypto_secretbox_easy(ret.data(), data.data(), data.size(), n.data(), key.data());
|
||||||
ret.append(n);
|
ret.append(n);
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
@@ -73,15 +87,15 @@ PIByteArray PICrypt::crypt(const PIByteArray &data, const PIByteArray &secret) {
|
|||||||
PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, bool *ok) {
|
PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, bool *ok) {
|
||||||
PIByteArray ret;
|
PIByteArray ret;
|
||||||
#ifdef PIP_CRYPT
|
#ifdef PIP_CRYPT
|
||||||
if (crypt_data.size() < nonce.size() + crypto_secretbox_MACBYTES) {
|
if (crypt_data.size() < nonce_.size() + crypto_secretbox_MACBYTES) {
|
||||||
if (ok) *ok = false;
|
if (ok) *ok = false;
|
||||||
return PIByteArray();
|
return PIByteArray();
|
||||||
}
|
}
|
||||||
ret.resize(crypt_data.size() - nonce.size() - crypto_secretbox_MACBYTES);
|
ret.resize(crypt_data.size() - nonce_.size() - crypto_secretbox_MACBYTES);
|
||||||
memcpy(nonce.data(), crypt_data.data(crypt_data.size() - nonce.size()), nonce.size());
|
memcpy(nonce_.data(), crypt_data.data(crypt_data.size() - nonce_.size()), nonce_.size());
|
||||||
if (crypto_secretbox_open_easy(ret.data(), crypt_data.data(), crypt_data.size() - nonce.size(), nonce.data(), key.data()) != 0) {
|
if (crypto_secretbox_open_easy(ret.data(), crypt_data.data(), crypt_data.size() - nonce_.size(), nonce_.data(), key_.data()) != 0) {
|
||||||
if (ok) *ok = false;
|
if (ok) *ok = false;
|
||||||
// piCout << "[PICrypt]" << "bad key";
|
// piCout << "[PICrypt]" << "bad key_";
|
||||||
return PIByteArray();
|
return PIByteArray();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -90,10 +104,10 @@ PIByteArray PICrypt::decrypt(const PIByteArray &crypt_data, bool *ok) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIByteArray PICrypt::decrypt(const PIByteArray &crypt_data, const PIByteArray &secret, bool *ok) {
|
PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, const PIByteArray & key, bool *ok) {
|
||||||
PIByteArray ret;
|
PIByteArray ret;
|
||||||
#ifdef PIP_CRYPT
|
#ifdef PIP_CRYPT
|
||||||
if (secret.size() != crypto_secretbox_KEYBYTES) {
|
if (key.size() != crypto_secretbox_KEYBYTES) {
|
||||||
if (ok) *ok = false;
|
if (ok) *ok = false;
|
||||||
return PIByteArray();
|
return PIByteArray();
|
||||||
}
|
}
|
||||||
@@ -106,9 +120,9 @@ PIByteArray PICrypt::decrypt(const PIByteArray &crypt_data, const PIByteArray &s
|
|||||||
n.resize(crypto_secretbox_NONCEBYTES);
|
n.resize(crypto_secretbox_NONCEBYTES);
|
||||||
ret.resize(crypt_data.size() - n.size() - crypto_secretbox_MACBYTES);
|
ret.resize(crypt_data.size() - n.size() - crypto_secretbox_MACBYTES);
|
||||||
memcpy(n.data(), crypt_data.data(crypt_data.size() - n.size()), n.size());
|
memcpy(n.data(), crypt_data.data(crypt_data.size() - n.size()), n.size());
|
||||||
if (crypto_secretbox_open_easy(ret.data(), crypt_data.data(), crypt_data.size() - n.size(), n.data(), secret.data()) != 0) {
|
if (crypto_secretbox_open_easy(ret.data(), crypt_data.data(), crypt_data.size() - n.size(), n.data(), key.data()) != 0) {
|
||||||
if (ok) *ok = false;
|
if (ok) *ok = false;
|
||||||
// piCout << "[PICrypt]" << "bad key";
|
// piCout << "[PICrypt]" << "bad key_";
|
||||||
return PIByteArray();
|
return PIByteArray();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*! \file picrypt.h
|
||||||
|
* \brief Cryptographic class using lib Sodium
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
Cryptographic class using lib Sodium
|
||||||
|
Copyright (C) 2015 Andrey Bychkov work.a.b@yandex.ru
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef PICRYPT_H
|
#ifndef PICRYPT_H
|
||||||
#define PICRYPT_H
|
#define PICRYPT_H
|
||||||
|
|
||||||
@@ -9,26 +31,19 @@ public:
|
|||||||
|
|
||||||
bool setKey(const PIByteArray & secret);
|
bool setKey(const PIByteArray & secret);
|
||||||
PIByteArray setKey(const PIString & secret);
|
PIByteArray setKey(const PIString & secret);
|
||||||
|
PIByteArray key() {return key_;}
|
||||||
PIByteArray getKey();
|
|
||||||
|
|
||||||
PIByteArray crypt(const PIByteArray & data);
|
PIByteArray crypt(const PIByteArray & data);
|
||||||
|
|
||||||
PIByteArray decrypt(const PIByteArray & crypt_data, bool * ok = 0);
|
PIByteArray decrypt(const PIByteArray & crypt_data, bool * ok = 0);
|
||||||
|
|
||||||
static PIByteArray crypt(const PIByteArray &data, const PIByteArray &secret);
|
static PIByteArray crypt(const PIByteArray & data, const PIByteArray & key);
|
||||||
|
static PIByteArray decrypt(const PIByteArray & crypt_data, const PIByteArray & key, bool * ok = 0);
|
||||||
static PIByteArray decrypt(const PIByteArray &crypt_data, const PIByteArray &secret, bool * ok = 0);
|
|
||||||
|
|
||||||
static PIByteArray hash(const PIString & secret);
|
static PIByteArray hash(const PIString & secret);
|
||||||
|
|
||||||
static int sizeKey();
|
static int sizeKey();
|
||||||
|
|
||||||
static int sizeCrypt();
|
static int sizeCrypt();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PIByteArray nonce;
|
PIByteArray nonce_, key_;
|
||||||
PIByteArray key;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PICRYPT_H
|
#endif // PICRYPT_H
|
||||||
|
|||||||
@@ -5,6 +5,6 @@
|
|||||||
#define PIP_VERSION_MAJOR 0
|
#define PIP_VERSION_MAJOR 0
|
||||||
#define PIP_VERSION_MINOR 5
|
#define PIP_VERSION_MINOR 5
|
||||||
#define PIP_VERSION_REVISION 1
|
#define PIP_VERSION_REVISION 1
|
||||||
#define PIP_VERSION_SUFFIX "_alphav[i]"
|
#define PIP_VERSION_SUFFIX "_alpha"
|
||||||
|
|
||||||
#endif // PIVERSION_H
|
#endif // PIVERSION_H
|
||||||
|
|||||||
Reference in New Issue
Block a user