Skip to content

Commit

Permalink
move code to build with clang 15
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Gomenyuk committed Nov 21, 2024
1 parent 3e176cb commit 6409c4b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
cmakeGen: '"Unix Makefiles"'
cc: clang
cxx: clang++
tools: NONINTERACTIVE=1 brew install libomp llvm
tools: NONINTERACTIVE=1 brew install libomp

steps:
- uses: actions/checkout@v3
Expand Down
131 changes: 65 additions & 66 deletions src/configProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,86 @@ class ConfigProcessor final
template <typename KeyType>
[[nodiscard]] std::shared_ptr<KeyType> aquireKey(
const std::string_view keyName);

[[nodiscard]] std::shared_ptr<lbcrypto::CryptoContextImpl<lbcrypto::DCRTPoly>> aquireCC(
const std::string_view ccName);

template <typename KeyType>
void generateKeyPairAndSerialize(
const std::string_view keyName,
nlohmann::json& keyContent);
void generateKeyPairAndSerialize(const std::string_view keyName, nlohmann::json& keyContent)
{
std::shared_ptr<lbcrypto::CryptoContextImpl<lbcrypto::DCRTPoly>> cc =
aquireCC(keyContent["cryptocontext"].get<std::string_view>());
cc->Enable(lbcrypto::PKE);
lbcrypto::KeyPair<lbcrypto::DCRTPoly> keyPair = cc->KeyGen();
const std::string& linkedKeyName
= keyContent["linked_key_for_generation"].get_ref<const std::string&>();
if (!linkedKeyName.empty())
{
if (!(m_configJson[linkedKeyName]["linked_key_for_generation"].get<std::string_view>() == keyName &&
m_configJson[linkedKeyName]["source"].get<std::string_view>().empty()))
{
throw std::runtime_error("Incorrect linking between keys");
}
if constexpr (std::is_same_v<KeyType, lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>)
{
auto itKey = getKeyMap<lbcrypto::PublicKeyImpl<lbcrypto::DCRTPoly>>().emplace(

Check failure on line 112 in src/configProcessor.h

View workflow job for this annotation

GitHub Actions / macos-latest-Release Build

function 'getKeyMap<lbcrypto::PublicKeyImpl<lbcrypto::DCRTPolyImpl<bigintdyn::mubintvec<bigintdyn::ubint<unsigned long long>>>>>' with deduced return type cannot be used before it is defined
linkedKeyName, std::move(getKeyFromKeyPair<lbcrypto::PublicKeyImpl<lbcrypto::DCRTPoly>>(keyPair))).first;

Check failure on line 113 in src/configProcessor.h

View workflow job for this annotation

GitHub Actions / macos-latest-Release Build

function 'getKeyFromKeyPair<lbcrypto::PublicKeyImpl<lbcrypto::DCRTPolyImpl<bigintdyn::mubintvec<bigintdyn::ubint<unsigned long long>>>>>' with deduced return type cannot be used before it is defined
serialize<lbcrypto::PublicKeyImpl<lbcrypto::DCRTPoly>>(linkedKeyName, itKey->second);
}
else
{
auto itKey = getKeyMap<lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>().emplace(

Check failure on line 118 in src/configProcessor.h

View workflow job for this annotation

GitHub Actions / macos-latest-Release Build

function 'getKeyMap<lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPolyImpl<bigintdyn::mubintvec<bigintdyn::ubint<unsigned long long>>>>>' with deduced return type cannot be used before it is defined
linkedKeyName, std::move(getKeyFromKeyPair<lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>(keyPair))).first;

Check failure on line 119 in src/configProcessor.h

View workflow job for this annotation

GitHub Actions / macos-latest-Release Build

function 'getKeyFromKeyPair<lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPolyImpl<bigintdyn::mubintvec<bigintdyn::ubint<unsigned long long>>>>>' with deduced return type cannot be used before it is defined
serialize<lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>(linkedKeyName, itKey->second);
}
updateSource(linkedKeyName, m_configJson[linkedKeyName]);
}
else
{
if constexpr (std::is_same_v<KeyType, lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>)
{
serialize<lbcrypto::PublicKeyImpl<lbcrypto::DCRTPoly>>(std::string(keyName) + "." +
m_configJson[linkedKeyName]["type"].get<std::string>(),
getKeyFromKeyPair<lbcrypto::PublicKeyImpl<lbcrypto::DCRTPoly>>(keyPair));

Check failure on line 130 in src/configProcessor.h

View workflow job for this annotation

GitHub Actions / macos-latest-Release Build

function 'getKeyFromKeyPair<lbcrypto::PublicKeyImpl<lbcrypto::DCRTPolyImpl<bigintdyn::mubintvec<bigintdyn::ubint<unsigned long long>>>>>' with deduced return type cannot be used before it is defined
}
else
{
serialize<lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>(std::string(keyName) + "." +
m_configJson[linkedKeyName]["type"].get<std::string>(),
getKeyFromKeyPair<lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>(keyPair));

Check failure on line 136 in src/configProcessor.h

View workflow job for this annotation

GitHub Actions / macos-latest-Release Build

function 'getKeyFromKeyPair<lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPolyImpl<bigintdyn::mubintvec<bigintdyn::ubint<unsigned long long>>>>>' with deduced return type cannot be used before it is defined
}
}
auto itKey = getKeyMap<KeyType>().emplace(keyName, std::move(getKeyFromKeyPair<KeyType>(keyPair))).first;
const std::string keyNameStr(itKey->first);
serialize<KeyType>(keyNameStr, itKey->second);
updateSource(keyNameStr, keyContent);
}

[[nodiscard]] std::shared_ptr<lbcrypto::CryptoContextImpl<lbcrypto::DCRTPoly>> generateCC(
const std::string_view ccName,
const nlohmann::json& ccContent);

template <typename SchemeType>
[[nodiscard]] static lbcrypto::CCParams<SchemeType> getCCParams(
const nlohmann::json& ccContent);

template <typename KeyType>
[[nodiscard]] inline auto& getKeyMap() noexcept;
[[nodiscard]] inline auto& getKeyMap() noexcept
{
if constexpr (std::is_same_v<std::remove_cvref_t<KeyType>, lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>)
return m_privateKeyMap;
else
return m_publicKeyMap;
}

template <typename KeyType>
[[nodiscard]] inline auto& getKeyFromKeyPair(
lbcrypto::KeyPair<lbcrypto::DCRTPoly>& keyPair) noexcept;
[[nodiscard]] inline auto& getKeyFromKeyPair(lbcrypto::KeyPair<lbcrypto::DCRTPoly>& keyPair) noexcept
{
if constexpr (std::is_same_v<std::remove_cvref_t<KeyType>, lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>)
return keyPair.secretKey;
else
return keyPair.publicKey;
}

inline void updateSource(
const std::string& filename,
Expand Down Expand Up @@ -382,57 +441,6 @@ template <typename KeyType>
return itCC->second;
}

template <typename KeyType>
void ConfigProcessor::generateKeyPairAndSerialize(const std::string_view keyName, nlohmann::json& keyContent)
{
std::shared_ptr<lbcrypto::CryptoContextImpl<lbcrypto::DCRTPoly>> cc =
aquireCC(keyContent["cryptocontext"].get<std::string_view>());
cc->Enable(lbcrypto::PKE);
lbcrypto::KeyPair<lbcrypto::DCRTPoly> keyPair = cc->KeyGen();
const std::string& linkedKeyName
= keyContent["linked_key_for_generation"].get_ref<const std::string&>();
if (!linkedKeyName.empty())
{
if (!(m_configJson[linkedKeyName]["linked_key_for_generation"].get<std::string_view>() == keyName &&
m_configJson[linkedKeyName]["source"].get<std::string_view>().empty()))
{
throw std::runtime_error("Incorrect linking between keys");
}
if constexpr (std::is_same_v<KeyType, lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>)
{
auto itKey = getKeyMap<lbcrypto::PublicKeyImpl<lbcrypto::DCRTPoly>>().emplace(
linkedKeyName, std::move(getKeyFromKeyPair<lbcrypto::PublicKeyImpl<lbcrypto::DCRTPoly>>(keyPair))).first;
serialize<lbcrypto::PublicKeyImpl<lbcrypto::DCRTPoly>>(linkedKeyName, itKey->second);
}
else
{
auto itKey = getKeyMap<lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>().emplace(
linkedKeyName, std::move(getKeyFromKeyPair<lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>(keyPair))).first;
serialize<lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>(linkedKeyName, itKey->second);
}
updateSource(linkedKeyName, m_configJson[linkedKeyName]);
}
else
{
if constexpr (std::is_same_v<KeyType, lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>)
{
serialize<lbcrypto::PublicKeyImpl<lbcrypto::DCRTPoly>>(std::string(keyName) + "." +
m_configJson[linkedKeyName]["type"].get<std::string>(),
getKeyFromKeyPair<lbcrypto::PublicKeyImpl<lbcrypto::DCRTPoly>>(keyPair));
}
else
{
serialize<lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>(std::string(keyName) + "." +
m_configJson[linkedKeyName]["type"].get<std::string>(),
getKeyFromKeyPair<lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>(keyPair));
}
}
auto itKey = getKeyMap<KeyType>().emplace(keyName, std::move(getKeyFromKeyPair<KeyType>(keyPair))).first;
const std::string keyNameStr(itKey->first);
serialize<KeyType>(keyNameStr, itKey->second);
updateSource(keyNameStr, keyContent);
}

[[nodiscard]] std::shared_ptr<lbcrypto::CryptoContextImpl<lbcrypto::DCRTPoly>> ConfigProcessor::generateCC(
const std::string_view ccName, const nlohmann::json& ccContent)
{
Expand Down Expand Up @@ -531,15 +539,6 @@ template <typename KeyType>
return m_publicKeyMap;
}

template <typename KeyType>
[[nodiscard]] inline auto& ConfigProcessor::getKeyFromKeyPair(lbcrypto::KeyPair<lbcrypto::DCRTPoly>& keyPair) noexcept
{
if constexpr (std::is_same_v<std::remove_cvref_t<KeyType>, lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>>)
return keyPair.secretKey;
else
return keyPair.publicKey;
}

inline void ConfigProcessor::updateSource(const std::string& filename, nlohmann::json& argContent)
{
static const std::string path = "local://" + m_outputCryptoObjectsDirectory;
Expand Down

0 comments on commit 6409c4b

Please sign in to comment.