git-svn-id: svn://db.shs.com.ru/pip@294 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -104,7 +104,7 @@ endif ()
|
|||||||
|
|
||||||
|
|
||||||
# Check if USB is on (to enable use "-DUSB=" argument of cmake)
|
# Check if USB is on (to enable use "-DUSB=" argument of cmake)
|
||||||
if (USB)
|
if (${USB})
|
||||||
message(STATUS "Building with USB support")
|
message(STATUS "Building with USB support")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_USB")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_USB")
|
||||||
list(APPEND LIBS usb)
|
list(APPEND LIBS usb)
|
||||||
@@ -114,7 +114,7 @@ endif ()
|
|||||||
|
|
||||||
|
|
||||||
# Check if STL containers is on (to enable use "-DSTL=" argument of cmake)
|
# Check if STL containers is on (to enable use "-DSTL=" argument of cmake)
|
||||||
if (STL)
|
if (${STL})
|
||||||
message(STATUS "Building with STL containers")
|
message(STATUS "Building with STL containers")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_CONTAINERS_STL")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_CONTAINERS_STL")
|
||||||
else ()
|
else ()
|
||||||
@@ -123,7 +123,7 @@ endif ()
|
|||||||
|
|
||||||
|
|
||||||
# Check if ICU used for PIString and PIChar
|
# Check if ICU used for PIString and PIChar
|
||||||
if (ICU)
|
if (${ICU})
|
||||||
message(STATUS "Building with ICU")
|
message(STATUS "Building with ICU")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_ICU")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_ICU")
|
||||||
list(APPEND LIBS icuuc)
|
list(APPEND LIBS icuuc)
|
||||||
@@ -133,7 +133,7 @@ endif ()
|
|||||||
|
|
||||||
|
|
||||||
# Check if PIP support cryptographic encryption/decryption by using sodium library
|
# Check if PIP support cryptographic encryption/decryption by using sodium library
|
||||||
if (CRYPT)
|
if (${CRYPT})
|
||||||
message(STATUS "Building with crypt support")
|
message(STATUS "Building with crypt support")
|
||||||
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)
|
||||||
@@ -143,7 +143,7 @@ endif ()
|
|||||||
|
|
||||||
|
|
||||||
# Check if PIP should be built with containers introspection
|
# Check if PIP should be built with containers introspection
|
||||||
if (INTROSPECTION_CONTAINERS)
|
if (${INTROSPECTION_CONTAINERS})
|
||||||
message(STATUS "Building with containers introspection")
|
message(STATUS "Building with containers introspection")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_INTROSPECTION_CONTAINERS")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_INTROSPECTION_CONTAINERS")
|
||||||
else ()
|
else ()
|
||||||
@@ -152,7 +152,7 @@ endif ()
|
|||||||
|
|
||||||
|
|
||||||
# Check if PIP should be built with threads introspection
|
# Check if PIP should be built with threads introspection
|
||||||
if (INTROSPECTION_THREADS)
|
if (${INTROSPECTION_THREADS})
|
||||||
message(STATUS "Building with threads introspection")
|
message(STATUS "Building with threads introspection")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_INTROSPECTION_THREADS")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_INTROSPECTION_THREADS")
|
||||||
else ()
|
else ()
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ PIByteArray PICrypt::crypt(const PIByteArray & data, PIByteArray key) {
|
|||||||
randombytes_buf(n.data(), n.size());
|
randombytes_buf(n.data(), n.size());
|
||||||
crypto_secretbox_easy(ret.data(), data.data(), data.size(), n.data(), key.data());
|
crypto_secretbox_easy(ret.data(), data.data(), data.size(), n.data(), key.data());
|
||||||
ret.append(n);
|
ret.append(n);
|
||||||
|
#else
|
||||||
|
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -131,6 +133,8 @@ PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, PIByteArray key, bo
|
|||||||
// piCout << "[PICrypt]" << "bad key_";
|
// piCout << "[PICrypt]" << "bad key_";
|
||||||
return PIByteArray();
|
return PIByteArray();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
|
||||||
#endif
|
#endif
|
||||||
if (ok) *ok = true;
|
if (ok) *ok = true;
|
||||||
return ret;
|
return ret;
|
||||||
@@ -144,22 +148,26 @@ PIByteArray PICrypt::hash(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(), (const uchar*)hash_def_key, sizeof(hash_def_key) - 1);
|
crypto_generichash(hash.data(), hash.size(), s.data(), s.size(), (const uchar*)hash_def_key, sizeof(hash_def_key) - 1);
|
||||||
|
#else
|
||||||
|
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
|
||||||
#endif
|
#endif
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ullong PICrypt::shorthash(const PIString& s, PIByteArray key) {
|
ullong PICrypt::shorthash(const PIString& s, PIByteArray key) {
|
||||||
ullong hash;
|
ullong hash = 0;
|
||||||
#ifdef PIP_CRYPT
|
#ifdef PIP_CRYPT
|
||||||
if (crypto_shorthash_BYTES != sizeof(hash)) piCout << "[PICrypt]" << "internal error: bad hash size";
|
if (crypto_shorthash_BYTES != sizeof(hash)) piCout << "[PICrypt]" << "internal error: bad hash size";
|
||||||
sodium_init();
|
sodium_init();
|
||||||
if (key.size() != crypto_shorthash_KEYBYTES) {
|
if (key.size() != crypto_shorthash_KEYBYTES) {
|
||||||
key.resize(crypto_shorthash_KEYBYTES);
|
piCout << "[PICrypt]" << "invalid key size" << key.size() << ", shoud be" << crypto_shorthash_KEYBYTES << ", filled zeros";
|
||||||
randombytes_buf(key.data(), key.size());
|
key.resize(crypto_shorthash_KEYBYTES, 0);
|
||||||
}
|
}
|
||||||
PIByteArray in(s.data(), s.size());
|
PIByteArray in(s.data(), s.size());
|
||||||
crypto_shorthash((uchar *)&hash, in.data(), in.size(), key.data());
|
crypto_shorthash((uchar *)&hash, in.data(), in.size(), key.data());
|
||||||
|
#else
|
||||||
|
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
|
||||||
#endif
|
#endif
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
@@ -171,6 +179,8 @@ PIByteArray PICrypt::generateKey() {
|
|||||||
sodium_init();
|
sodium_init();
|
||||||
hash.resize(crypto_secretbox_KEYBYTES);
|
hash.resize(crypto_secretbox_KEYBYTES);
|
||||||
randombytes_buf(hash.data(), hash.size());
|
randombytes_buf(hash.data(), hash.size());
|
||||||
|
#else
|
||||||
|
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
|
||||||
#endif
|
#endif
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
@@ -179,6 +189,8 @@ PIByteArray PICrypt::generateKey() {
|
|||||||
int PICrypt::sizeKey() {
|
int PICrypt::sizeKey() {
|
||||||
#ifdef PIP_CRYPT
|
#ifdef PIP_CRYPT
|
||||||
return crypto_secretbox_KEYBYTES;
|
return crypto_secretbox_KEYBYTES;
|
||||||
|
#else
|
||||||
|
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -187,6 +199,8 @@ int PICrypt::sizeKey() {
|
|||||||
int PICrypt::sizeCrypt() {
|
int PICrypt::sizeCrypt() {
|
||||||
#ifdef PIP_CRYPT
|
#ifdef PIP_CRYPT
|
||||||
return crypto_secretbox_MACBYTES + crypto_secretbox_NONCEBYTES;
|
return crypto_secretbox_MACBYTES + crypto_secretbox_NONCEBYTES;
|
||||||
|
#else
|
||||||
|
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user