Skip to content

Commit b178262

Browse files
Copilotmaxtropets
andauthored
Remove aes_gcm_encrypt/decrypt convenience API from ccf::crypto (#7811)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: maxtropets <16566519+maxtropets@users.noreply.github.com> Co-authored-by: Max <maxtropets@microsoft.com>
1 parent 193e7d8 commit b178262

7 files changed

Lines changed: 30 additions & 125 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [7.0.0-rc2]
9+
10+
[7.0.0-rc2]: https://github.com/microsoft/CCF/releases/tag/ccf-7.0.0-rc2
11+
12+
### Removed
13+
14+
- Removed `aes_gcm_encrypt()`, `aes_gcm_decrypt()`, and `default_iv` from `ccf::crypto` (#7811).
15+
816
## [7.0.0-rc1]
917

1018
[7.0.0-rc1]: https://github.com/microsoft/CCF/releases/tag/ccf-7.0.0-rc1

doc/build_apps/crypto.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ Symmetric Keys
6363

6464
Currently, only AES-GCM is supported for symmetric encryption. New keys are generated via :cpp:func:`ccf::crypto::Entropy::random`
6565

66-
.. doxygenfunction:: ccf::crypto::aes_gcm_encrypt
67-
:project: CCF
68-
69-
.. doxygenfunction:: ccf::crypto::aes_gcm_decrypt
70-
:project: CCF
71-
7266
.. doxygenclass:: ccf::crypto::Entropy
7367
:project: CCF
7468
:members:

include/ccf/crypto/symmetric_key.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -106,31 +106,4 @@ namespace ccf::crypto
106106
throw std::runtime_error("Unsupported key size");
107107
}
108108
}
109-
110-
/** Default initialization vector for AES-GCM (12 zeroes) */
111-
static std::vector<uint8_t> default_iv(iv_size, 0);
112-
113-
/// AES-GCM Encryption with @p key of @p data
114-
/// @param key The key
115-
/// @param plaintext The data
116-
/// @param iv Intialization vector
117-
/// @param aad Additional authenticated data
118-
/// @return ciphertext
119-
std::vector<uint8_t> aes_gcm_encrypt(
120-
std::span<const uint8_t> key,
121-
std::span<const uint8_t> plaintext,
122-
const std::vector<uint8_t>& iv = default_iv,
123-
const std::vector<uint8_t>& aad = {});
124-
125-
/// AES-GCM Decryption with @p key of @p data
126-
/// @param key The key
127-
/// @param ciphertext The (encrypted) data
128-
/// @param iv Initialization vector
129-
/// @param aad Additional authenticated data
130-
/// @return plaintext
131-
std::vector<uint8_t> aes_gcm_decrypt(
132-
std::span<const uint8_t> key,
133-
std::span<const uint8_t> ciphertext,
134-
const std::vector<uint8_t>& iv = default_iv,
135-
const std::vector<uint8_t>& aad = {});
136109
}

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "ccf"
7-
version = "7.0.0.rc1"
7+
version = "7.0.0.rc2"
88
authors = [
99
{ name="CCF Team", email="CCF-Sec@microsoft.com" },
1010
]

src/crypto/symmetric_key.cpp

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include "ccf/crypto/symmetric_key.h"
88
#include "ds/serialized.h"
99

10-
#include <climits>
11-
1210
#define FMT_HEADER_ONLY
1311
#include <fmt/format.h>
1412

@@ -103,49 +101,4 @@ namespace ccf::crypto
103101
{
104102
return std::make_unique<KeyAesGcm_OpenSSL>(rawKey);
105103
}
106-
107-
std::vector<uint8_t> aes_gcm_encrypt(
108-
std::span<const uint8_t> key,
109-
std::span<const uint8_t> plaintext,
110-
const std::vector<uint8_t>& iv,
111-
const std::vector<uint8_t>& aad)
112-
{
113-
check_supported_aes_key_size(key.size() * CHAR_BIT);
114-
115-
std::vector<uint8_t> r;
116-
std::vector<uint8_t> tag(GCM_SIZE_TAG);
117-
auto k = make_key_aes_gcm(key);
118-
k->encrypt(iv, plaintext, aad, r, tag.data());
119-
r.insert(r.end(), tag.begin(), tag.end());
120-
return r;
121-
}
122-
123-
std::vector<uint8_t> aes_gcm_decrypt(
124-
std::span<const uint8_t> key,
125-
std::span<const uint8_t> ciphertext,
126-
const std::vector<uint8_t>& iv,
127-
const std::vector<uint8_t>& aad)
128-
{
129-
check_supported_aes_key_size(key.size() * CHAR_BIT);
130-
131-
if (ciphertext.size() <= GCM_SIZE_TAG)
132-
{
133-
throw std::runtime_error("Not enough ciphertext");
134-
}
135-
136-
size_t ciphertext_length = ciphertext.size() - GCM_SIZE_TAG;
137-
std::vector<uint8_t> r;
138-
auto k = make_key_aes_gcm(key);
139-
if (!k->decrypt(
140-
iv,
141-
ciphertext.data() + ciphertext_length,
142-
std::span<const uint8_t>(ciphertext.data(), ciphertext_length),
143-
aad,
144-
r))
145-
{
146-
throw std::runtime_error("Failed to decrypt");
147-
}
148-
149-
return r;
150-
}
151104
}

src/crypto/test/crypto.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -886,15 +886,6 @@ TEST_CASE("CKM_RSA_AES_KEY_WRAP")
886886
REQUIRE(unwrapped == key_to_wrap);
887887
}
888888

889-
TEST_CASE("AES-GCM convenience functions")
890-
{
891-
EntropyPtr entropy = get_entropy();
892-
std::vector<uint8_t> key = entropy->random(GCM_DEFAULT_KEY_SIZE);
893-
auto encrypted = aes_gcm_encrypt(key, contents);
894-
auto decrypted = aes_gcm_decrypt(key, encrypted);
895-
REQUIRE(decrypted == contents);
896-
}
897-
898889
TEST_CASE("x509 time")
899890
{
900891
auto time = ccf::nonstd::SystemClock::now();
@@ -1334,23 +1325,6 @@ TEST_CASE("Sign and verify a chain with an intermediate and different subjects")
13341325
REQUIRE(!rc);
13351326
}
13361327

1337-
TEST_CASE("Decrypt should validate integrity")
1338-
{
1339-
auto key = get_entropy()->random(16);
1340-
std::vector<uint8_t> expected_plaintext = {0xde, 0xad, 0xbe, 0xef};
1341-
auto ciphertext = ccf::crypto::aes_gcm_encrypt(key, expected_plaintext);
1342-
auto decrypted_plaintext = ccf::crypto::aes_gcm_decrypt(key, ciphertext);
1343-
1344-
CHECK_EQ(expected_plaintext, decrypted_plaintext);
1345-
1346-
// corrupt part of ciphertext
1347-
auto broken_ciphertext = std::vector<uint8_t>(ciphertext);
1348-
broken_ciphertext[ciphertext.size() / 2] =
1349-
~broken_ciphertext[ciphertext.size() / 2];
1350-
1351-
CHECK_THROWS(ccf::crypto::aes_gcm_decrypt(key, broken_ciphertext));
1352-
}
1353-
13541328
TEST_CASE("Do not trust non-ca certs")
13551329
{
13561330
auto kp = ccf::crypto::make_ec_key_pair(CurveID::SECP384R1);

src/pal/test/snp_ioctl_test.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,17 @@ TEST_CASE("SNP derive key")
4242
ccf::ds::to_hex(key1->get_raw()), ccf::ds::to_hex(key2->get_raw()));
4343

4444
std::vector<uint8_t> expected_plaintext = {0xde, 0xad, 0xbe, 0xef};
45-
auto ciphertext =
46-
ccf::crypto::aes_gcm_encrypt(key1->get_raw(), expected_plaintext);
47-
auto decrypted_plaintext =
48-
ccf::crypto::aes_gcm_decrypt(key2->get_raw(), ciphertext);
45+
auto entropy = ccf::crypto::get_entropy();
46+
auto iv = entropy->random(ccf::crypto::iv_size);
47+
48+
auto k1 = ccf::crypto::make_key_aes_gcm(key1->get_raw());
49+
std::vector<uint8_t> cipher;
50+
uint8_t tag[ccf::crypto::GCM_SIZE_TAG];
51+
k1->encrypt(iv, expected_plaintext, {}, cipher, tag);
52+
53+
auto k2 = ccf::crypto::make_key_aes_gcm(key2->get_raw());
54+
std::vector<uint8_t> decrypted_plaintext;
55+
REQUIRE(k2->decrypt(iv, tag, cipher, {}, decrypted_plaintext));
4956

5057
CHECK_EQ(
5158
ccf::ds::to_hex(expected_plaintext), ccf::ds::to_hex(decrypted_plaintext));
@@ -63,21 +70,17 @@ TEST_CASE("SNP derived keys with different TCBs should be different")
6370
CHECK_NE(ccf::ds::to_hex(key1->get_raw()), ccf::ds::to_hex(key2->get_raw()));
6471

6572
std::vector<uint8_t> expected_plaintext = {0xde, 0xad, 0xbe, 0xef};
66-
bool threw = false;
67-
try
68-
{
69-
auto ciphertext =
70-
ccf::crypto::aes_gcm_encrypt(key1->get_raw(), expected_plaintext);
71-
auto decrypted_plaintext =
72-
ccf::crypto::aes_gcm_decrypt(key2->get_raw(), ciphertext);
73-
}
74-
catch (std::runtime_error& e)
75-
{
76-
CHECK(std::string(e.what()) == "Failed to decrypt");
77-
threw = true;
78-
}
73+
auto entropy = ccf::crypto::get_entropy();
74+
auto iv = entropy->random(ccf::crypto::iv_size);
75+
76+
auto k1 = ccf::crypto::make_key_aes_gcm(key1->get_raw());
77+
std::vector<uint8_t> cipher;
78+
uint8_t tag[ccf::crypto::GCM_SIZE_TAG];
79+
k1->encrypt(iv, expected_plaintext, {}, cipher, tag);
7980

80-
CHECK(threw == true);
81+
auto k2 = ccf::crypto::make_key_aes_gcm(key2->get_raw());
82+
std::vector<uint8_t> decrypted_plaintext;
83+
CHECK_FALSE(k2->decrypt(iv, tag, cipher, {}, decrypted_plaintext));
8184
}
8285

8386
int main(int argc, char** argv)

0 commit comments

Comments
 (0)