Skip to content

Commit a893b00

Browse files
Copilotachamayou
andauthored
Remove all mbedtls references from the codebase (#28)
* Initial plan * Remove all mbedtls references from codebase - Remove MBEDTLS CMake option and find_library block from CMakeLists.txt - Remove MBEDTLS condition from test/CMakeLists.txt - Remove mbedtls include and sha256 functions from merklecpp.h - Remove all HAVE_MBEDTLS conditional code from test files - Remove libmbedtls-dev install and -DMBEDTLS=ON from CI workflow - Remove mbedTLS references from documentation Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com> * Remove accidentally committed codeql build artifacts and add to .gitignore Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com> * Apply suggestion from @achamayou --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com> Co-authored-by: Amaury Chamayou <amaury@xargs.fr>
1 parent c148d5a commit a893b00

7 files changed

Lines changed: 8 additions & 126 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
steps:
3434
- name: Install packages
35-
run: sudo apt install libmbedtls-dev doctest-dev clang
35+
run: sudo apt install doctest-dev clang
3636
if: matrix.os == 'ubuntu-latest'
3737

3838
- uses: actions/checkout@v4
@@ -47,7 +47,7 @@ jobs:
4747
working-directory: ${{github.workspace}}/build/${{ matrix.build_type }}
4848
run: |
4949
if [ "$RUNNER_OS" == "Linux" ]; then
50-
cmake $GITHUB_WORKSPACE -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DTESTS=ON -DOPENSSL=ON -DMBEDTLS=ON
50+
cmake $GITHUB_WORKSPACE -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DTESTS=ON -DOPENSSL=ON
5151
else
5252
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DTESTS=ON
5353
fi

CMakeLists.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ option(PROFILE "enable profiling" OFF)
1212
option(TESTS "enable testing" OFF)
1313
option(EVERCRYPT "enable comparison with EverCrypt Merkle trees" OFF)
1414
option(OPENSSL "enable OpenSSL" OFF)
15-
option(MBEDTLS "enable mbedTLS" OFF)
1615
option(TRACE "enable debug traces" OFF)
1716

1817
add_library(merklecpp INTERFACE)
@@ -51,17 +50,6 @@ if(OPENSSL)
5150
target_link_libraries(merklecpp INTERFACE crypto)
5251
endif()
5352

54-
if(MBEDTLS)
55-
find_library(MBEDCRYPTO_LIBRARY NAMES mbedcrypto)
56-
target_compile_definitions(merklecpp INTERFACE HAVE_MBEDTLS)
57-
target_link_libraries(merklecpp INTERFACE mbedcrypto)
58-
if (NOT MBEDCRYPTO_LIBRARY)
59-
message(FATAL_ERROR "mbedTLS not found")
60-
else()
61-
message("-- Found mbedTLS at ${MBEDCRYPTO_LIBRARY}")
62-
endif()
63-
endif()
64-
6553
if(TESTS)
6654
enable_testing()
6755

doc/index.rst

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and function.
99
A default implementation without further dependencies is provided as
1010
:cpp:type:`merkle::Tree`, which uses the SHA256 compression function
1111
(:cpp:func:`merkle::sha256_compress`). merklecpp also provides bindings
12-
for the respective OpenSSL and mbedTLS functions (see `Hash functions`_),
12+
for the respective OpenSSL functions (see `Hash functions`_),
1313
which can be specified as a template parameter as illustrated by the following
1414
example:
1515

@@ -48,22 +48,16 @@ Hash functions
4848

4949
By default, merklecpp uses the SHA256 compression function
5050
(:cpp:func:`merkle::sha256_compress`) for node hashes. For convenience,
51-
it also provides bindings to the SHA256 implementations in OpenSSL and mbedTLS.
52-
To enable these bindings, merklecpp requires the compiler macros
53-
:code:`HAVE_OPENSSL` and :code:`HAVE_MBEDTLS` to be defined.
51+
it also provides bindings to the SHA256 implementation in OpenSSL.
52+
To enable these bindings, merklecpp requires the compiler macro
53+
:code:`HAVE_OPENSSL` to be defined.
5454

5555
.. doxygenfunction:: merkle::sha256_compress
5656
:project: merklecpp
5757

5858
.. doxygenfunction:: merkle::sha256_openssl
5959
:project: merklecpp
6060

61-
.. doxygenfunction:: merkle::sha256_compress_mbedtls
62-
:project: merklecpp
63-
64-
.. doxygenfunction:: merkle::sha256_mbedtls
65-
:project: merklecpp
66-
6761
.. toctree::
6862
:maxdepth: 2
6963
:caption: Contents:

merklecpp.h

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
# include <openssl/sha.h>
2222
#endif
2323

24-
#ifdef HAVE_MBEDTLS
25-
# include <mbedtls/sha256.h>
26-
#endif
27-
2824
#ifdef MERKLECPP_TRACE_ENABLED
2925
// Hashes in the trace output are truncated to TRACE_HASH_SIZE bytes.
3026
# define TRACE_HASH_SIZE 3
@@ -1917,45 +1913,6 @@ namespace merkle
19171913
}
19181914
#endif
19191915

1920-
#ifdef HAVE_MBEDTLS
1921-
/// @brief mbedTLS SHA256 compression function
1922-
/// @param l Left node hash
1923-
/// @param r Right node hash
1924-
/// @param out Output node hash
1925-
/// @note Technically, mbedtls_internal_sha256_process is marked for internal
1926-
/// use only.
1927-
static inline void sha256_compress_mbedtls(
1928-
const HashT<32>& l, const HashT<32>& r, HashT<32>& out)
1929-
{
1930-
unsigned char block[32 * 2];
1931-
memcpy(&block[0], l.bytes, 32);
1932-
memcpy(&block[32], r.bytes, 32);
1933-
1934-
mbedtls_sha256_context ctx;
1935-
mbedtls_sha256_init(&ctx);
1936-
mbedtls_sha256_starts_ret(&ctx, false);
1937-
mbedtls_internal_sha256_process(&ctx, &block[0]);
1938-
1939-
for (int i = 0; i < 8; i++)
1940-
((uint32_t*)out.bytes)[i] = htobe32(ctx.state[i]);
1941-
}
1942-
1943-
/// @brief mbedTLS SHA256
1944-
/// @param l Left node hash
1945-
/// @param r Right node hash
1946-
/// @param out Output node hash
1947-
static inline void sha256_mbedtls(
1948-
const merkle::HashT<32>& l,
1949-
const merkle::HashT<32>& r,
1950-
merkle::HashT<32>& out)
1951-
{
1952-
uint8_t block[32 * 2];
1953-
memcpy(&block[0], l.bytes, 32);
1954-
memcpy(&block[32], r.bytes, 32);
1955-
mbedtls_sha256_ret(block, sizeof(block), out.bytes, false);
1956-
}
1957-
#endif
1958-
19591916
/// @brief Type of hashes in the default tree type
19601917
typedef HashT<32> Hash;
19611918

test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ if(TARGET evercrypt.host)
3434
endif()
3535

3636
if(OPENSSL
37-
OR MBEDTLS
3837
OR EVERCRYPT
3938
)
4039
add_merklecpp_test(compare_hash_functions compare_hash_functions.cpp)

test/compare_hash_functions.cpp

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ typedef merkle::TreeT<32, sha256_evercrypt> EverCryptFullTree;
5050
typedef merkle::TreeT<32, merkle::sha256_openssl> OpenSSLFullTree;
5151
#endif
5252

53-
#ifdef HAVE_MBEDTLS
54-
typedef merkle::TreeT<32, merkle::sha256_compress_mbedtls> MbedTLSTree;
55-
typedef merkle::TreeT<32, merkle::sha256_mbedtls> MbedTLSFullTree;
56-
#endif
57-
5853
template <
5954
void (*HF1)(
6055
const merkle::HashT<32>& l,
@@ -102,10 +97,6 @@ void compare_compression_hashes()
10297
EverCryptTree mte;
10398
#endif
10499

105-
#ifdef HAVE_MBEDTLS
106-
MbedTLSTree mtm;
107-
#endif
108-
109100
// Build trees with k+1 leaves
110101
int j = 0;
111102
auto hashes = make_hashes(k + 1);
@@ -118,10 +109,6 @@ void compare_compression_hashes()
118109
mte.insert(h);
119110
#endif
120111

121-
#ifdef HAVE_MBEDTLS
122-
mtm.insert(h);
123-
#endif
124-
125112
total_inserts++;
126113

127114
if ((j++ % root_interval) == 0)
@@ -130,10 +117,6 @@ void compare_compression_hashes()
130117
compare_roots(mt, mte, "EverCrypt");
131118
#endif
132119

133-
#ifdef HAVE_MBEDTLS
134-
compare_roots(mt, mtm, "mbedTLS");
135-
#endif
136-
137120
total_roots++;
138121
}
139122
}
@@ -142,17 +125,14 @@ void compare_compression_hashes()
142125
compare_roots(mt, mte, "EverCrypt");
143126
#endif
144127

145-
#ifdef HAVE_MBEDTLS
146-
compare_roots(mt, mtm, "mbedTLS");
147-
#endif
148128
}
149129

150130
std::cout << num_trees << " trees, " << total_inserts << " inserts, "
151131
<< total_roots << " roots with SHA256 compression function: OK"
152132
<< std::endl;
153133
}
154134

155-
#if defined(HAVE_OPENSSL) && (defined(HAVE_EVERCRYPT) || defined(HAVE_MBEDTLS))
135+
#if defined(HAVE_OPENSSL) && defined(HAVE_EVERCRYPT)
156136
void compare_full_hashes()
157137
{
158138
# ifndef NDEBUG
@@ -173,10 +153,6 @@ void compare_full_hashes()
173153
merkle::TreeT<32, sha256_evercrypt> mte;
174154
# endif
175155

176-
# ifdef HAVE_MBEDTLS
177-
MbedTLSFullTree mtm;
178-
# endif
179-
180156
// Build trees with k+1 leaves
181157
int j = 0;
182158
auto hashes = make_hashes(k + 1);
@@ -189,10 +165,6 @@ void compare_full_hashes()
189165
mte.insert(h);
190166
# endif
191167

192-
# ifdef HAVE_MBEDTLS
193-
mtm.insert(h);
194-
# endif
195-
196168
total_inserts++;
197169

198170
if ((j++ % root_interval) == 0)
@@ -201,10 +173,6 @@ void compare_full_hashes()
201173
compare_roots(mto, mte, "EverCrypt");
202174
# endif
203175

204-
# ifdef HAVE_MBEDTLS
205-
compare_roots(mto, mtm, "mbedTLS");
206-
# endif
207-
208176
total_roots++;
209177
}
210178
}
@@ -213,9 +181,6 @@ void compare_full_hashes()
213181
compare_roots(mto, mte, "OpenSSL");
214182
# endif
215183

216-
# ifdef HAVE_MBEDTLS
217-
compare_roots(mto, mtm, "mbedTLS");
218-
# endif
219184
}
220185

221186
std::cout << num_trees << " trees, " << total_inserts << " inserts, "
@@ -293,7 +258,7 @@ int main()
293258

294259
compare_compression_hashes();
295260

296-
#if defined(HAVE_EVERCRYPT) && (defined(HAVE_OPENSSL) || defined(HAVE_MBEDTLS))
261+
#if defined(HAVE_EVERCRYPT) && defined(HAVE_OPENSSL)
297262
compare_full_hashes();
298263
#endif
299264

@@ -312,10 +277,6 @@ int main()
312277

313278
bench<merkle::Tree>(hashes, "merklecpp", root_interval);
314279

315-
#ifdef HAVE_MBEDTLS
316-
bench<MbedTLSTree>(hashes, "mbedTLS", root_interval);
317-
#endif
318-
319280
#ifdef HAVE_EVERCRYPT
320281
bench<EverCryptTree>(hashes, "EverCrypt", root_interval);
321282
#endif
@@ -326,10 +287,6 @@ int main()
326287
bench<OpenSSLFullTree>(hashes, "OpenSSL", root_interval);
327288
#endif
328289

329-
#ifdef HAVE_MBEDTLS
330-
bench<MbedTLSFullTree>(hashes, "mbedTLS", root_interval);
331-
#endif
332-
333290
#ifdef HAVE_EVERCRYPT
334291
bench<EverCryptFullTree>(hashes, "EverCrypt", root_interval);
335292
#endif

test/demo_tree.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,6 @@ int main()
6767
}
6868
#endif
6969

70-
#ifdef HAVE_MBEDTLS
71-
{
72-
auto hashes = make_hashes(num_leaves);
73-
/// SNIPPET_START: mbedTLS-SHA256
74-
merkle::TreeT<32, merkle::sha256_openssl> tree;
75-
for (auto h : hashes)
76-
tree.insert(h);
77-
auto root = tree.root();
78-
auto path = tree.path(hashes.size() - 1);
79-
assert(path->verify(root));
80-
/// SNIPPET_END: mbedTLS-SHA256
81-
}
82-
#endif
8370
}
8471
catch (std::exception& ex)
8572
{

0 commit comments

Comments
 (0)