Skip to content

Commit

Permalink
Replace cmake fatal command by message of type FATAL_ERROR
Browse files Browse the repository at this point in the history
Avoid implicit cast from size_t to uint8_t in SHA and HMAC-SHA wrappers
  • Loading branch information
AndreaGianarda committed Dec 14, 2023
1 parent 71c3532 commit d4891d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ include("cmake/BCToolboxCMakeUtils.cmake")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

if(ENABLE_MBEDTLS AND ENABLE_OPENSSL)
fatal("Cannot build bctoolbox with both openssl and mbedtls enabled")
message(FATAL_ERROR "Cannot build bctoolbox with both openssl and mbedtls enabled")
endif()

if(NOT CPACK_GENERATOR AND NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
Expand All @@ -74,7 +74,7 @@ if(ENABLE_MBEDTLS)
if(MbedTLS_FOUND)
message(STATUS "Found mbedTLS v${MbedTLS_VERSION}")
if(MbedTLS_VERSION LESS 3)
fatal(WARNING "Mbedtls version incompatible (requires v3)")
message(FATAL_ERROR "Mbedtls version incompatible (requires v3)")
endif()
set(HAVE_MBEDTLS 1)
endif()
Expand Down
12 changes: 8 additions & 4 deletions src/crypto/crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,35 @@ std::vector<uint8_t> HMAC(BCTBX_UNUSED(const std::vector<uint8_t> &key),
template <>
std::vector<uint8_t> HMAC<SHA1>(const std::vector<uint8_t> &key, const std::vector<uint8_t> &input) {
std::vector<uint8_t> hmacOutput(SHA1::ssize());
bctbx_hmacSha1(key.data(), key.size(), input.data(), input.size(), hmacOutput.size(), hmacOutput.data());
bctbx_hmacSha1(key.data(), key.size(), input.data(), input.size(), static_cast<uint8_t>(hmacOutput.size()),
hmacOutput.data());
return hmacOutput;
}

/* HMAC specialized template for SHA256 */
template <>
std::vector<uint8_t> HMAC<SHA256>(const std::vector<uint8_t> &key, const std::vector<uint8_t> &input) {
std::vector<uint8_t> hmacOutput(SHA256::ssize());
bctbx_hmacSha256(key.data(), key.size(), input.data(), input.size(), hmacOutput.size(), hmacOutput.data());
bctbx_hmacSha256(key.data(), key.size(), input.data(), input.size(), static_cast<uint8_t>(hmacOutput.size()),
hmacOutput.data());
return hmacOutput;
}

/* HMAC specialized template for SHA384 */
template <>
std::vector<uint8_t> HMAC<SHA384>(const std::vector<uint8_t> &key, const std::vector<uint8_t> &input) {
std::vector<uint8_t> hmacOutput(SHA384::ssize());
bctbx_hmacSha384(key.data(), key.size(), input.data(), input.size(), hmacOutput.size(), hmacOutput.data());
bctbx_hmacSha384(key.data(), key.size(), input.data(), input.size(), static_cast<uint8_t>(hmacOutput.size()),
hmacOutput.data());
return hmacOutput;
}

/* HMAC specialized template for SHA512 */
template <>
std::vector<uint8_t> HMAC<SHA512>(const std::vector<uint8_t> &key, const std::vector<uint8_t> &input) {
std::vector<uint8_t> hmacOutput(SHA512::ssize());
bctbx_hmacSha512(key.data(), key.size(), input.data(), input.size(), hmacOutput.size(), hmacOutput.data());
bctbx_hmacSha512(key.data(), key.size(), input.data(), input.size(), static_cast<uint8_t>(hmacOutput.size()),
hmacOutput.data());
return hmacOutput;
}

Expand Down

0 comments on commit d4891d1

Please sign in to comment.