Skip to content

Commit fe6e1b2

Browse files
authored
Merge pull request #771 from Nordix/ci-updates
Fix Botan build and test failures
2 parents 519f7a5 + 8635f76 commit fe6e1b2

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

.github/workflows/ci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,15 @@ jobs:
6767
- arch: x64
6868
backend: openssl
6969
target-platform: x64
70+
build-options:
7071
- arch: x64
7172
backend: botan
7273
target-platform: x64
74+
build-options: -DENABLE_ECC=OFF -DENABLE_EDDSA=OFF
7375
- arch: x86
7476
backend: openssl
7577
target-platform: Win32
78+
build-options: -DENABLE_ECC=OFF -DENABLE_EDDSA=OFF
7679
steps:
7780
- uses: actions/checkout@v4
7881
- uses: ilammy/msvc-dev-cmd@v1
@@ -93,7 +96,7 @@ jobs:
9396
- name: Build
9497
run: |
9598
mkdir build
96-
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
99+
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
97100
cmake --build build
98101
- name: Test
99102
env:

src/lib/crypto/BotanSymmetricAlgorithm.cpp

+40-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,26 @@ bool BotanSymmetricAlgorithm::encryptInit(const SymmetricKey* key, const SymMode
169169
try
170170
{
171171
Botan::SymmetricKey botanKey = Botan::SymmetricKey(key->getKeyBits().const_byte_str(), key->getKeyBits().size());
172-
if (mode == SymMode::GCM)
172+
if (mode == SymMode::ECB)
173+
{
174+
// ECB cipher mode was dropped in Botan 2.0
175+
const std::vector<std::string> algo_parts = split_on_delim(cipherName, '/');
176+
const std::string cipher_name = algo_parts[0];
177+
bool with_pkcs7_padding;
178+
if (algo_parts.size() == 3 && algo_parts[2] == "PKCS7")
179+
{
180+
with_pkcs7_padding = true;
181+
}
182+
else
183+
{
184+
with_pkcs7_padding = false;
185+
}
186+
std::unique_ptr<Botan::BlockCipher> bc(Botan::BlockCipher::create(cipher_name));
187+
Botan::Keyed_Filter* cipher = new Botan::Cipher_Mode_Filter(new Botan::ECB_Encryption(bc.release(), with_pkcs7_padding));
188+
cipher->set_key(botanKey);
189+
cryption = new Botan::Pipe(cipher);
190+
}
191+
else if (mode == SymMode::GCM)
173192
{
174193
Botan::AEAD_Mode* aead = Botan::get_aead(cipherName, Botan::ENCRYPTION);
175194
aead->set_key(botanKey);
@@ -385,7 +404,26 @@ bool BotanSymmetricAlgorithm::decryptInit(const SymmetricKey* key, const SymMode
385404
try
386405
{
387406
Botan::SymmetricKey botanKey = Botan::SymmetricKey(key->getKeyBits().const_byte_str(), key->getKeyBits().size());
388-
if (mode == SymMode::GCM)
407+
if (mode == SymMode::ECB)
408+
{
409+
// ECB cipher mode was dropped in Botan 2.0
410+
const std::vector<std::string> algo_parts = split_on_delim(cipherName, '/');
411+
const std::string cipher_name = algo_parts[0];
412+
bool with_pkcs7_padding;
413+
if (algo_parts.size() == 3 && algo_parts[2] == "PKCS7")
414+
{
415+
with_pkcs7_padding = true;
416+
}
417+
else
418+
{
419+
with_pkcs7_padding = false;
420+
}
421+
std::unique_ptr<Botan::BlockCipher> bc(Botan::BlockCipher::create(cipher_name));
422+
Botan::Keyed_Filter* cipher = new Botan::Cipher_Mode_Filter(new Botan::ECB_Decryption(bc.release(),with_pkcs7_padding));
423+
cipher->set_key(botanKey);
424+
cryption = new Botan::Pipe(cipher);
425+
}
426+
else if (mode == SymMode::GCM)
389427
{
390428
Botan::AEAD_Mode* aead = Botan::get_aead(cipherName, Botan::DECRYPTION);
391429
aead->set_key(botanKey);

src/lib/crypto/Botan_ecb.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Botan {
2222
/**
2323
* ECB mode
2424
*/
25-
class BOTAN_DLL ECB_Mode : public Cipher_Mode
25+
class ECB_Mode : public Cipher_Mode
2626
{
2727
public:
2828
std::string name() const override;
@@ -57,7 +57,7 @@ class BOTAN_DLL ECB_Mode : public Cipher_Mode
5757
/**
5858
* ECB Encryption
5959
*/
60-
class BOTAN_DLL ECB_Encryption final : public ECB_Mode
60+
class ECB_Encryption final : public ECB_Mode
6161
{
6262
public:
6363
/**
@@ -78,7 +78,7 @@ class BOTAN_DLL ECB_Encryption final : public ECB_Mode
7878
/**
7979
* ECB Decryption
8080
*/
81-
class BOTAN_DLL ECB_Decryption final : public ECB_Mode
81+
class ECB_Decryption final : public ECB_Mode
8282
{
8383
public:
8484
/**

src/lib/crypto/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ if(WITH_BOTAN)
9595
BotanDSAKeyPair.cpp
9696
BotanDSAPrivateKey.cpp
9797
BotanDSAPublicKey.cpp
98+
Botan_ecb.cpp
9899
BotanECDH.cpp
99100
BotanECDHKeyPair.cpp
100101
BotanECDHPrivateKey.cpp

src/lib/test/SymmetricAlgorithmTests.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1427,8 +1427,10 @@ void SymmetricAlgorithmTests::aesWrapUnwrapED(CK_MECHANISM_TYPE mechanismType, C
14271427
CK_BBOOL bTrue = CK_TRUE;
14281428

14291429
std::map<std::string, EDCurveParam > curves {
1430-
{ "ED25519", {0x06, 0x03, 0x2b, 0x65, 0x70} },
1431-
{ "ED448", {0x06, 0x03, 0x2b, 0x65, 0x71} }
1430+
{ "ED25519", {0x06, 0x03, 0x2b, 0x65, 0x70} }
1431+
#ifndef WITH_BOTAN
1432+
, { "ED448", {0x06, 0x03, 0x2b, 0x65, 0x71} }
1433+
#endif
14321434
};
14331435

14341436
for(auto &curve : curves) {

0 commit comments

Comments
 (0)