From eb99c5752ebfe6d3b640c1f44d240e80bb427d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Wed, 15 Apr 2015 07:52:07 +0000 Subject: [PATCH] x64 fixICU fixes git-svn-id: svn://db.shs.com.ru/pip@100 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- CMakeLists.txt | 4 +-- main.cpp | 79 -------------------------------------------- src/math/picrypt.cpp | 11 +++--- src/math/picrypt.h | 2 +- 4 files changed, 9 insertions(+), 87 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e9ebbb44..d42367b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,12 +126,12 @@ endif () # Check if PIP support cryptographic encryption/decryption by using sodium library if (DEFINED CRYPT) - message(STATUS "Building with CRYPT support") + message(STATUS "Building with crypt support") unset(CRYPT) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_CRYPT") list(APPEND LIBS sodium) else () - message(STATUS "Building without CRYPT, encryption doesn't work") + message(STATUS "Building without crypt support") endif () diff --git a/main.cpp b/main.cpp index e3b19806..e59754b9 100644 --- a/main.cpp +++ b/main.cpp @@ -136,85 +136,6 @@ public: //#include - -template -class FixedPoint { -// friend PICout operator <<(PICout s, const FixedPoint<> & v); -public: - typedef FixedPoint fp; - FixedPoint(const Type &v = Type()) {val = fpv(v);} - FixedPoint(const fp &v) {val = v.val;} - FixedPoint(const float &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << Precision-1));} - FixedPoint(const double &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << Precision-1));} -// FixedPoint(const long double &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << Precision-1));} - - template - fp & operator=(const T & v) {val = fpv(Type(v)); return *this;} - fp & operator=(const fp & v) {val = v.val; return *this;} - fp & operator=(const float &v) {val = FixedPoint(v).val; return *this;} - fp & operator=(const double &v) {val = FixedPoint(v).val; return *this;} - fp & operator=(const long double &v) {val = FixedPoint(v).val; return *this;} - fp & operator-() {fp p = fp(*this); p.val = -val; return p;} - bool operator==(const fp & v) const {return val == v.val;} - bool operator!=(const fp & v) const {return val != v.val;} - - void operator+=(const fp & v) {val += v.val;} - void operator-=(const fp & v) {val -= v.val;} - - void operator*=(const fp & v) {val = fpi(val *v.val);} - void operator/=(const fp & v) {val = fpv(val) / v.val;} - - fp operator+(const fp & v) {fp p = fp(*this); p.val += v.val; return p;} - fp operator-(const fp & v) {fp p = fp(*this); p.val -= v.val; return p;} - - fp operator*(const fp & v) {fp p; p.val = fpi(val * v.val); return p;} - fp operator/(const fp & v) {fp p; p.val = fpv(val) / v.val; return p;} - - /*fp & operator =(const Type & v) {val = fpv(v); return *this;} - bool operator ==(const Type & v) const {val == fpv(v);} - bool operator !=(const Type & v) const {val != fpv(v);} - void operator +=(const Type & v) {val += fpv(v);} - void operator -=(const Type & v) {val -= fpv(v);} - void operator *=(const Type & v) {val *= fpv(v);} - void operator /=(const Type & v) {val /= fpv(v);} - fp operator +(const Type & v) {fp p = fp(*this); p.val += fpv(v); return p;} - fp operator -(const Type & v) {fp p = fp(*this); p.val -= fpv(v); return p;} - fp operator *(const Type & v) {fp p = fp(*this); p.val *= fpv(v); return p;} - fp operator /(const Type & v) {fp p = fp(*this); p.val /= fpv(v); return p;}*/ - - Type fpv(Type v) const {return Type(v << Precision);} - Type fpi(Type v) const {return Type(v >> Precision);} - Type fpc(Type v) const {return v - fpv(fpi(v));} - Type val; -}; - -template -inline PICout operator <<(PICout s, const FixedPoint & v) { - s.space(); s.setControl(0, true); - if (Precision == 0) s << v.val; - else { - std::stringstream ss,sr; - Type tmp = 10; - int n = 1; - Type rs = (2 << Precision-1); - while(tmp < rs) tmp = tmp*10, n++; - tmp *= 10; n++; - Type rv = v.fpc(v.val); - if (rv != 0) tmp = tmp / (rs / rv); - ss << tmp; - PIString r = ss.str(); - if (rv == 0) r.pop_front(); - else r.expandLeftTo(n,'0'); - sr << v.fpi(v.val); - s << PIString(sr.str()) + "." + r; - } - s.restoreControl(); - return s; -} - - - - //#include "mpint.h" //#include "unicode/utypes.h" //#include "unicode/stringpiece.h" diff --git a/src/math/picrypt.cpp b/src/math/picrypt.cpp index a6bd0be6..f6f807ba 100644 --- a/src/math/picrypt.cpp +++ b/src/math/picrypt.cpp @@ -21,6 +21,7 @@ #ifdef PIP_CRYPT # include "sodium.h" #endif +const char hash_def_key[] = "_picrypt_"; PICrypt::PICrypt() { @@ -36,9 +37,9 @@ PICrypt::PICrypt() { } -bool PICrypt::setKey(const PIByteArray & secret) { - if (secret.size() != key_.size()) return false; - key_ = secret; +bool PICrypt::setKey(const PIByteArray & _key) { + if (_key.size() != key_.size()) return false; + key_ = _key; return true; } @@ -48,7 +49,7 @@ PIByteArray PICrypt::setKey(const PIString & secret) { #ifdef PIP_CRYPT hash.resize(crypto_generichash_BYTES); 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(), (const uchar*)hash_def_key, sizeof(hash_def_key) - 1); hash.resize(key_.size()); setKey(hash); #endif @@ -137,7 +138,7 @@ PIByteArray PICrypt::hash(const PIString & secret) { sodium_init(); hash.resize(crypto_generichash_BYTES); 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(), (const uchar*)hash_def_key, sizeof(hash_def_key) - 1); #endif return hash; } diff --git a/src/math/picrypt.h b/src/math/picrypt.h index 8197a282..61d4ca03 100644 --- a/src/math/picrypt.h +++ b/src/math/picrypt.h @@ -29,7 +29,7 @@ class PICrypt { public: PICrypt(); - bool setKey(const PIByteArray & secret); + bool setKey(const PIByteArray & key); PIByteArray setKey(const PIString & secret); PIByteArray key() {return key_;} PIByteArray crypt(const PIByteArray & data);