diff --git a/CMakeLists.txt b/CMakeLists.txt index e8f4544f..e54b644d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,7 +104,7 @@ endif () # Check if USB is on (to enable use "-DUSB=" argument of cmake) -if (USB) +if (${USB}) message(STATUS "Building with USB support") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_USB") list(APPEND LIBS usb) @@ -114,7 +114,7 @@ endif () # Check if STL containers is on (to enable use "-DSTL=" argument of cmake) -if (STL) +if (${STL}) message(STATUS "Building with STL containers") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_CONTAINERS_STL") else () @@ -123,7 +123,7 @@ endif () # Check if ICU used for PIString and PIChar -if (ICU) +if (${ICU}) message(STATUS "Building with ICU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_ICU") list(APPEND LIBS icuuc) @@ -133,7 +133,7 @@ endif () # Check if PIP support cryptographic encryption/decryption by using sodium library -if (CRYPT) +if (${CRYPT}) message(STATUS "Building with crypt support") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_CRYPT") list(APPEND LIBS sodium) @@ -143,7 +143,7 @@ endif () # Check if PIP should be built with containers introspection -if (INTROSPECTION_CONTAINERS) +if (${INTROSPECTION_CONTAINERS}) message(STATUS "Building with containers introspection") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_INTROSPECTION_CONTAINERS") else () @@ -152,7 +152,7 @@ endif () # Check if PIP should be built with threads introspection -if (INTROSPECTION_THREADS) +if (${INTROSPECTION_THREADS}) message(STATUS "Building with threads introspection") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_INTROSPECTION_THREADS") else () diff --git a/src/math/picrypt.cpp b/src/math/picrypt.cpp index 10feee9c..a0df92da 100644 --- a/src/math/picrypt.cpp +++ b/src/math/picrypt.cpp @@ -84,6 +84,8 @@ PIByteArray PICrypt::crypt(const PIByteArray & data, PIByteArray key) { randombytes_buf(n.data(), n.size()); crypto_secretbox_easy(ret.data(), data.data(), data.size(), n.data(), key.data()); ret.append(n); +#else + piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT="; #endif return ret; } @@ -131,6 +133,8 @@ PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, PIByteArray key, bo // piCout << "[PICrypt]" << "bad key_"; return PIByteArray(); } +#else + piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT="; #endif if (ok) *ok = true; return ret; @@ -144,22 +148,26 @@ PIByteArray PICrypt::hash(const PIString & secret) { hash.resize(crypto_generichash_BYTES); 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); +#else + piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT="; #endif return hash; } ullong PICrypt::shorthash(const PIString& s, PIByteArray key) { - ullong hash; + ullong hash = 0; #ifdef PIP_CRYPT if (crypto_shorthash_BYTES != sizeof(hash)) piCout << "[PICrypt]" << "internal error: bad hash size"; sodium_init(); if (key.size() != crypto_shorthash_KEYBYTES) { - key.resize(crypto_shorthash_KEYBYTES); - randombytes_buf(key.data(), key.size()); + piCout << "[PICrypt]" << "invalid key size" << key.size() << ", shoud be" << crypto_shorthash_KEYBYTES << ", filled zeros"; + key.resize(crypto_shorthash_KEYBYTES, 0); } PIByteArray in(s.data(), s.size()); 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 return hash; } @@ -171,6 +179,8 @@ PIByteArray PICrypt::generateKey() { sodium_init(); hash.resize(crypto_secretbox_KEYBYTES); randombytes_buf(hash.data(), hash.size()); +#else + piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT="; #endif return hash; } @@ -179,6 +189,8 @@ PIByteArray PICrypt::generateKey() { int PICrypt::sizeKey() { #ifdef PIP_CRYPT return crypto_secretbox_KEYBYTES; +#else + piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT="; #endif return 0; } @@ -187,6 +199,8 @@ int PICrypt::sizeKey() { int PICrypt::sizeCrypt() { #ifdef PIP_CRYPT 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 return 0; }