Skip to content

Commit 9e45af2

Browse files
committed
Add BEAR_SSL_DISABLE_ECCX08
This new compilation flag will allow the user to use ArduinoBearSSL without ECCX08. Indeed, the cryptographic operations could be done through the default software implementation or offloaded to another secure element such as an applet compliant with the GSMA IoT SAFE standard. Signed-off-by: Fabrice Fontaine <[email protected]>
1 parent e985450 commit 9e45af2

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Diff for: src/BearSSLClient.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
* SOFTWARE.
2323
*/
2424

25+
#ifndef BEAR_SSL_DISABLE_ECCX08
2526
#include <ArduinoECCX08.h>
27+
#endif
2628

2729
#include "ArduinoBearSSL.h"
2830
#include "BearSSLTrustAnchors.h"
@@ -47,8 +49,13 @@ BearSSLClient::BearSSLClient(Client* client, const br_x509_trust_anchor* myTAs,
4749
_noSNI(false),
4850
_ecChainLen(0)
4951
{
52+
#ifndef BEAR_SSL_DISABLE_ECCX08
5053
_ecVrfy = eccX08_vrfy_asn1;
5154
_ecSign = eccX08_sign_asn1;
55+
#else
56+
_ecVrfy = br_ecdsa_vrfy_asn1_get_default();
57+
_ecSign = br_ecdsa_sign_asn1_get_default();
58+
#endif
5259

5360
_ecKey.curve = 0;
5461
_ecKey.x = NULL;
@@ -237,8 +244,13 @@ void BearSSLClient::setEccSlot(int ecc508KeySlot, const byte cert[], int certLen
237244
_ecChainLen = 1;
238245
_ecCertDynamic = false;
239246

247+
#ifndef BEAR_SSL_DISABLE_ECCX08
240248
_ecVrfy = eccX08_vrfy_asn1;
241249
_ecSign = eccX08_sign_asn1;
250+
#else
251+
_ecVrfy = br_ecdsa_vrfy_asn1_get_default();
252+
_ecSign = br_ecdsa_sign_asn1_get_default();
253+
#endif
242254
}
243255

244256
void BearSSLClient::setEccSlot(int ecc508KeySlot, const char cert[])
@@ -352,12 +364,16 @@ int BearSSLClient::connectSSL(const char* host)
352364
// inject entropy in engine
353365
unsigned char entropy[32];
354366

367+
#ifndef BEAR_SSL_DISABLE_ECCX08
355368
if (!ECCX08.begin() || !ECCX08.locked() || !ECCX08.random(entropy, sizeof(entropy))) {
369+
#endif
356370
// no ECCX08 or random failed, fallback to pseudo random
357371
for (size_t i = 0; i < sizeof(entropy); i++) {
358372
entropy[i] = random(0, 255);
359373
}
374+
#ifndef BEAR_SSL_DISABLE_ECCX08
360375
}
376+
#endif
361377
br_ssl_engine_inject_entropy(&_sc.eng, entropy, sizeof(entropy));
362378

363379
// add custom ECDSA vfry and EC sign

Diff for: src/utility/eccX08_sign_asn1.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* SOFTWARE.
2424
*/
2525

26+
#ifndef BEAR_SSL_DISABLE_ECCX08
2627
#include "eccX08_asn1.h"
2728

2829
#include <ArduinoECCX08.h>
@@ -51,3 +52,4 @@ eccX08_sign_asn1(const br_ec_impl * /*impl*/,
5152
memcpy(sig, rsig, sig_len);
5253
return sig_len;
5354
}
55+
#endif

Diff for: src/utility/eccX08_vrfy_asn1.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* SOFTWARE.
2424
*/
2525

26+
#ifndef BEAR_SSL_DISABLE_ECCX08
2627
#include "eccX08_asn1.h"
2728

2829
#include <ArduinoECCX08.h>
@@ -60,3 +61,4 @@ eccX08_vrfy_asn1(const br_ec_impl * /*impl*/,
6061

6162
return 1;
6263
}
64+
#endif

0 commit comments

Comments
 (0)