Skip to content

Commit af67d41

Browse files
committed
Add ARDUINO_DISABLE_ECCX08
This new compilation flag can be set through ArduinoBearSSLConfig.h and 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 af67d41

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

Diff for: src/ArduinoBearSSL.h

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
#ifndef _ARDUINO_BEAR_SSL_H_
2626
#define _ARDUINO_BEAR_SSL_H_
2727

28+
#if defined __has_include
29+
# if __has_include (<ArduinoBearSSLConfig.h>)
30+
# include <ArduinoBearSSLConfig.h>
31+
# endif
32+
#endif
33+
2834
#include "BearSSLClient.h"
2935
#include "SHA1.h"
3036
#include "SHA256.h"

Diff for: src/BearSSLClient.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
* SOFTWARE.
2323
*/
2424

25+
#include "ArduinoBearSSL.h"
26+
27+
#ifndef ARDUINO_DISABLE_ECCX08
2528
#include <ArduinoECCX08.h>
29+
#endif
2630

27-
#include "ArduinoBearSSL.h"
2831
#include "BearSSLTrustAnchors.h"
2932
#include "utility/eccX08_asn1.h"
3033

@@ -47,8 +50,13 @@ BearSSLClient::BearSSLClient(Client* client, const br_x509_trust_anchor* myTAs,
4750
_noSNI(false),
4851
_ecChainLen(0)
4952
{
53+
#ifndef ARDUINO_DISABLE_ECCX08
5054
_ecVrfy = eccX08_vrfy_asn1;
5155
_ecSign = eccX08_sign_asn1;
56+
#else
57+
_ecVrfy = br_ecdsa_vrfy_asn1_get_default();
58+
_ecSign = br_ecdsa_sign_asn1_get_default();
59+
#endif
5260

5361
_ecKey.curve = 0;
5462
_ecKey.x = NULL;
@@ -237,8 +245,13 @@ void BearSSLClient::setEccSlot(int ecc508KeySlot, const byte cert[], int certLen
237245
_ecChainLen = 1;
238246
_ecCertDynamic = false;
239247

248+
#ifndef ARDUINO_DISABLE_ECCX08
240249
_ecVrfy = eccX08_vrfy_asn1;
241250
_ecSign = eccX08_sign_asn1;
251+
#else
252+
_ecVrfy = br_ecdsa_vrfy_asn1_get_default();
253+
_ecSign = br_ecdsa_sign_asn1_get_default();
254+
#endif
242255
}
243256

244257
void BearSSLClient::setEccSlot(int ecc508KeySlot, const char cert[])
@@ -352,12 +365,16 @@ int BearSSLClient::connectSSL(const char* host)
352365
// inject entropy in engine
353366
unsigned char entropy[32];
354367

368+
#ifndef ARDUINO_DISABLE_ECCX08
355369
if (!ECCX08.begin() || !ECCX08.locked() || !ECCX08.random(entropy, sizeof(entropy))) {
370+
#endif
356371
// no ECCX08 or random failed, fallback to pseudo random
357372
for (size_t i = 0; i < sizeof(entropy); i++) {
358373
entropy[i] = random(0, 255);
359374
}
375+
#ifndef ARDUINO_DISABLE_ECCX08
360376
}
377+
#endif
361378
br_ssl_engine_inject_entropy(&_sc.eng, entropy, sizeof(entropy));
362379

363380
// add custom ECDSA vfry and EC sign

Diff for: src/utility/eccX08_sign_asn1.cpp

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

26+
#include "ArduinoBearSSL.h"
27+
28+
#ifndef ARDUINO_DISABLE_ECCX08
2629
#include "eccX08_asn1.h"
2730

2831
#include <ArduinoECCX08.h>
@@ -51,3 +54,4 @@ eccX08_sign_asn1(const br_ec_impl * /*impl*/,
5154
memcpy(sig, rsig, sig_len);
5255
return sig_len;
5356
}
57+
#endif

Diff for: src/utility/eccX08_vrfy_asn1.cpp

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

26+
#include "ArduinoBearSSL.h"
27+
28+
#ifndef ARDUINO_DISABLE_ECCX08
2629
#include "eccX08_asn1.h"
2730

2831
#include <ArduinoECCX08.h>
@@ -60,3 +63,4 @@ eccX08_vrfy_asn1(const br_ec_impl * /*impl*/,
6063

6164
return 1;
6265
}
66+
#endif

0 commit comments

Comments
 (0)