Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Botan build and test failures #771

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ jobs:
- arch: x64
backend: openssl
target-platform: x64
build-options:
- arch: x64
backend: botan
target-platform: x64
build-options: -DENABLE_ECC=OFF -DENABLE_EDDSA=OFF
- arch: x86
backend: openssl
target-platform: Win32
build-options: -DENABLE_ECC=OFF -DENABLE_EDDSA=OFF
steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
Expand All @@ -93,7 +96,7 @@ jobs:
- name: Build
run: |
mkdir build
cmake -B build ${{ steps.vcpkg.outputs.vcpkg-cmake-config }} -A ${{ matrix.target-platform }} -DWITH_CRYPTO_BACKEND=${{ matrix.backend }} -DDISABLE_NON_PAGED_MEMORY=ON -DBUILD_TESTS=ON
cmake -B build ${{ steps.vcpkg.outputs.vcpkg-cmake-config }} -A ${{ matrix.target-platform }} -DWITH_CRYPTO_BACKEND=${{ matrix.backend }} ${{ matrix.build-options }} -DDISABLE_NON_PAGED_MEMORY=ON -DBUILD_TESTS=ON
cmake --build build
- name: Test
env:
Expand Down
42 changes: 40 additions & 2 deletions src/lib/crypto/BotanSymmetricAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,26 @@ bool BotanSymmetricAlgorithm::encryptInit(const SymmetricKey* key, const SymMode
try
{
Botan::SymmetricKey botanKey = Botan::SymmetricKey(key->getKeyBits().const_byte_str(), key->getKeyBits().size());
if (mode == SymMode::GCM)
if (mode == SymMode::ECB)
{
// ECB cipher mode was dropped in Botan 2.0
const std::vector<std::string> algo_parts = split_on_delim(cipherName, '/');
const std::string cipher_name = algo_parts[0];
bool with_pkcs7_padding;
if (algo_parts.size() == 3 && algo_parts[2] == "PKCS7")
{
with_pkcs7_padding = true;
}
else
{
with_pkcs7_padding = false;
}
std::unique_ptr<Botan::BlockCipher> bc(Botan::BlockCipher::create(cipher_name));
Botan::Keyed_Filter* cipher = new Botan::Cipher_Mode_Filter(new Botan::ECB_Encryption(bc.release(), with_pkcs7_padding));
cipher->set_key(botanKey);
cryption = new Botan::Pipe(cipher);
}
else if (mode == SymMode::GCM)
{
Botan::AEAD_Mode* aead = Botan::get_aead(cipherName, Botan::ENCRYPTION);
aead->set_key(botanKey);
Expand Down Expand Up @@ -385,7 +404,26 @@ bool BotanSymmetricAlgorithm::decryptInit(const SymmetricKey* key, const SymMode
try
{
Botan::SymmetricKey botanKey = Botan::SymmetricKey(key->getKeyBits().const_byte_str(), key->getKeyBits().size());
if (mode == SymMode::GCM)
if (mode == SymMode::ECB)
{
// ECB cipher mode was dropped in Botan 2.0
const std::vector<std::string> algo_parts = split_on_delim(cipherName, '/');
const std::string cipher_name = algo_parts[0];
bool with_pkcs7_padding;
if (algo_parts.size() == 3 && algo_parts[2] == "PKCS7")
{
with_pkcs7_padding = true;
}
else
{
with_pkcs7_padding = false;
}
std::unique_ptr<Botan::BlockCipher> bc(Botan::BlockCipher::create(cipher_name));
Botan::Keyed_Filter* cipher = new Botan::Cipher_Mode_Filter(new Botan::ECB_Decryption(bc.release(),with_pkcs7_padding));
cipher->set_key(botanKey);
cryption = new Botan::Pipe(cipher);
}
else if (mode == SymMode::GCM)
{
Botan::AEAD_Mode* aead = Botan::get_aead(cipherName, Botan::DECRYPTION);
aead->set_key(botanKey);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/crypto/Botan_ecb.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Botan {
/**
* ECB mode
*/
class BOTAN_DLL ECB_Mode : public Cipher_Mode
class ECB_Mode : public Cipher_Mode
{
public:
std::string name() const override;
Expand Down Expand Up @@ -57,7 +57,7 @@ class BOTAN_DLL ECB_Mode : public Cipher_Mode
/**
* ECB Encryption
*/
class BOTAN_DLL ECB_Encryption final : public ECB_Mode
class ECB_Encryption final : public ECB_Mode
{
public:
/**
Expand All @@ -78,7 +78,7 @@ class BOTAN_DLL ECB_Encryption final : public ECB_Mode
/**
* ECB Decryption
*/
class BOTAN_DLL ECB_Decryption final : public ECB_Mode
class ECB_Decryption final : public ECB_Mode
{
public:
/**
Expand Down
1 change: 1 addition & 0 deletions src/lib/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ if(WITH_BOTAN)
BotanDSAKeyPair.cpp
BotanDSAPrivateKey.cpp
BotanDSAPublicKey.cpp
Botan_ecb.cpp
BotanECDH.cpp
BotanECDHKeyPair.cpp
BotanECDHPrivateKey.cpp
Expand Down
6 changes: 4 additions & 2 deletions src/lib/test/SymmetricAlgorithmTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,10 @@ void SymmetricAlgorithmTests::aesWrapUnwrapED(CK_MECHANISM_TYPE mechanismType, C
CK_BBOOL bTrue = CK_TRUE;

std::map<std::string, EDCurveParam > curves {
{ "ED25519", {0x06, 0x03, 0x2b, 0x65, 0x70} },
{ "ED448", {0x06, 0x03, 0x2b, 0x65, 0x71} }
{ "ED25519", {0x06, 0x03, 0x2b, 0x65, 0x70} }
#ifndef WITH_BOTAN
, { "ED448", {0x06, 0x03, 0x2b, 0x65, 0x71} }
#endif
};

for(auto &curve : curves) {
Expand Down