Skip to content

Commit 161b544

Browse files
authored
Merge pull request #45 from Orange-OpenSource/no-eccx08
Add ARDUINO_DISABLE_ECCX08
2 parents e985450 + c3748fd commit 161b544

13 files changed

+91
-2
lines changed

README.adoc

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ image:https://github.com/{repository-owner}/{repository-name}/workflows/Spell%20
88

99
Port of https://bearssl.org[BearSSL] to Arduino.
1010

11-
This library depends on ArduinoECCX08.
11+
This library depends on ArduinoECCX08. This dependency could be
12+
disabled by defining ARDUINO_DISABLE_ECCX08 in ArduinoBearSSLConfig.h
13+
(see examples).
1214

1315
== License ==
1416

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef ARDUINO_BEARSSL_CONFIG_H_
2+
#define ARDUINO_BEARSSL_CONFIG_H_
3+
4+
/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */
5+
//#define ARDUINO_DISABLE_ECCX08
6+
7+
#endif /* ARDUINO_BEARSSL_CONFIG_H_ */

examples/DES/ArduinoBearSSLConfig.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef ARDUINO_BEARSSL_CONFIG_H_
2+
#define ARDUINO_BEARSSL_CONFIG_H_
3+
4+
/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */
5+
//#define ARDUINO_DISABLE_ECCX08
6+
7+
#endif /* ARDUINO_BEARSSL_CONFIG_H_ */

examples/MD5/ArduinoBearSSLConfig.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef ARDUINO_BEARSSL_CONFIG_H_
2+
#define ARDUINO_BEARSSL_CONFIG_H_
3+
4+
/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */
5+
//#define ARDUINO_DISABLE_ECCX08
6+
7+
#endif /* ARDUINO_BEARSSL_CONFIG_H_ */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef ARDUINO_BEARSSL_CONFIG_H_
2+
#define ARDUINO_BEARSSL_CONFIG_H_
3+
4+
/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */
5+
//#define ARDUINO_DISABLE_ECCX08
6+
7+
#endif /* ARDUINO_BEARSSL_CONFIG_H_ */

examples/SHA1/ArduinoBearSSLConfig.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef ARDUINO_BEARSSL_CONFIG_H_
2+
#define ARDUINO_BEARSSL_CONFIG_H_
3+
4+
/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */
5+
//#define ARDUINO_DISABLE_ECCX08
6+
7+
#endif /* ARDUINO_BEARSSL_CONFIG_H_ */
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef ARDUINO_BEARSSL_CONFIG_H_
2+
#define ARDUINO_BEARSSL_CONFIG_H_
3+
4+
/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */
5+
//#define ARDUINO_DISABLE_ECCX08
6+
7+
#endif /* ARDUINO_BEARSSL_CONFIG_H_ */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef ARDUINO_BEARSSL_CONFIG_H_
2+
#define ARDUINO_BEARSSL_CONFIG_H_
3+
4+
/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */
5+
//#define ARDUINO_DISABLE_ECCX08
6+
7+
#endif /* ARDUINO_BEARSSL_CONFIG_H_ */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef ARDUINO_BEARSSL_CONFIG_H_
2+
#define ARDUINO_BEARSSL_CONFIG_H_
3+
4+
/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */
5+
//#define ARDUINO_DISABLE_ECCX08
6+
7+
#endif /* ARDUINO_BEARSSL_CONFIG_H_ */

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"

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

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

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)