8000 Merge branch 'master' into adam5wu/master · Adam5Wu/bearssl-esp8266@98bc517 · GitHub
[go: up one dir, main page]

Skip to content

Commit 98bc517

Browse files
committed
Merge branch 'master' into adam5wu/master
2 parents 96ea7fe + 94e9704 commit 98bc517

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

README-esp8266.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This repo contains BearSSL (https://bearssl.org) ported for use on the
2+
ESP8266 by Earle F. Philhower, III <earlephilhower@yahoo.com>.
3+
4+
Due to stack limitations on the ESP8266, most functions that have large
5+
stack frames have been ported via macros to use a secondary stack,
6+
managed in the heap.
7+
8+
Many constants and the output of the Forth compiler T0 now is stored in
9+
PROGMEM, and patches have been applied to seamlessly run the interpreter
10+
from that space.
11+
12+
Additional functions for parsing public keys and for a dynamic trust
13+
anchor repository (since ESP8266 PROGMEM or RAM too small) were added.
14+
15+
To build:
16+
. Ensure the SDK gcc is present in your path
17+
. make clean
18+
. make CONF=esp8266 T0 # Compiles the *.t0 -> *.c forth interpreters
19+
. make CONF=esp8266
20+
. Copy the resulting lib in esp8266/libbearssl.a to the Arduino path
21+
22+
May 15, 2018
23+
-EFP3
24+

src/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227

228228
/*
229229
* When BR_BE_UNALIGNED is enabled, then the current architecture is
230-
* assumed to use little-endian encoding for integers, and to tolerate
230+
* assumed to use big-endian encoding for integers, and to tolerate
231231
* unaligned accesses with no or minimal time penalty.
232232
*
233233
#define BR_BE_UNALIGNED 1

src/int/i15_mulacc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@ void
2929
br_i15_mulacc(uint16_t *d, const uint16_t *a, const uint16_t *b)
3030
{
3131
size_t alen, blen, u;
32+
unsigned dl, dh;
3233

3334
alen = (a[0] + 15) >> 4;
3435
blen = (b[0] + 15) >> 4;
35-
d[0] = a[0] + b[0];
36+
37+
/*
38+
* Announced bit length of d[] will be the sum of the announced
39+
* bit lengths of a[] and b[]; but the lengths are encoded.
40+
*/
41+
dl = (a[0] & 15) + (d[0] & 15);
42+
dh = (a[0] >> 4) + (b[0] >> 4);
43+
d[0] = (dh << 4) + dl + (~(uint16_t)(dl - 15) >> 15);
44+
3645
for (u = 0; u < blen; u ++) {
3746
uint32_t f;
3847
size_t v;

src/int/i31_mulacc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@ void
2929
br_i31_mulacc(uint32_t *d, const uint32_t *a, const uint32_t *b)
3030
{
3131
size_t alen, blen, u;
32+
uint32_t dl, dh;
3233

3334
alen = (a[0] + 31) >> 5;
3435
blen = (b[0] + 31) >> 5;
35-
d[0] = a[0] + b[0];
36+
37+
/*
38+
* We want to add the two bit lengths, but these are encoded,
39+
* which requires some extra care.
40+
*/
41+
dl = (a[0] & 31) + (b[0] & 31);
42+
dh = (a[0] >> 5) + (b[0] >> 5);
43+
d[0] = (dh << 5) + dl + (~(uint32_t)(dl - 31) >> 31);
44+
3645
for (u = 0; u < blen; u ++) {
3746
uint32_t f;
3847
size_t v;

test/test_crypto.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4759,6 +4759,11 @@ test_RSA_sign(const char *name, br_rsa_private fpriv,
47594759
{
47604760
unsigned char t1[128], t2[128];
47614761
unsigned char hv[20], tmp[20];
4762+
unsigned char rsa_n[128], rsa_e[3], rsa_p[64], rsa_q[64];
4763+
unsigned char rsa_dp[64], rsa_dq[64], rsa_iq[64];
4764+
br_rsa_public_key rsa_pk;
4765+
br_rsa_private_key rsa_sk;
4766+
unsigned char hv2[64], tmp2[64], sig[128];
47624767
br_sha1_context hc;
47634768
size_t u;
47644769

@@ -4812,6 +4817,41 @@ test_RSA_sign(const char *name, br_rsa_private fpriv,
48124817
fflush(stdout);
48134818
}
48144819

4820+
/*
4821+
* Another KAT test, which historically showed a bug.
4822+
*/
4823+
rsa_pk.n = rsa_n;
4824+
rsa_pk.nlen = hextobin(rsa_n, "E65DAEF196D22C300B3DAE1CE5157EDF821BB6038E419D8D363A8B2DA84A1321042330E6F87A8BD8FE6BA1D2A17031955ED2315CC5FD2397197E238A5E0D2D0AFD25717E814EC4D2BBA887327A3C5B3A450FD8D547BDFCBB0F73B997CA13DD5E7572C4D5BAA764A349BAB2F868ACF4574AE2C7AEC94B77D2EE00A21B6CB175BB");
4825+
rsa_pk.e = rsa_e;
4826+
rsa_pk.elen = hextobin(rsa_e, "010001");
4827+
4828+
rsa_sk.n_bitlen = 1024;
4829+
rsa_sk.p = rsa_p;
4830+
rsa_sk.plen = hextobin(rsa_p, "FF58513DBA4F3F42DFDFD3E6AFB6BD62DE27E06BA3C9D9F9B542CB21228C2AAE67936514161C8FDC1A248A50195CAF22ADC50DA89BFED1B9EEFBB37304241357");
4831+
rsa_sk.q = rsa_q;
4832+
rsa_sk.qlen = hextobin(rsa_q, "E6F4F66818B7442297DDEB45E9B3D438E5B57BB5EF86EFF2462AD6B9C10F383517CDD2E7E36EAD4BEBCC57CFE8AA985F7E7B38B96D30FFBE9ED9FE21B1CFB63D");
4833+
rsa_sk.dp = rsa_dp;
4834+
rsa_sk.dplen = hextobin(rsa_dp, "6F89517B682D83919F9EF2BDBA955526A1A9C382E139A3A84AC01160B8E9871F458901C7035D988D6931FAE4C01F57350BB89E9DBEFE50F829E6F25CD43B39E3");
4835+
rsa_sk.dq = rsa_dq;
4836+
rsa_sk.dqlen = hextobin(rsa_dq, "409E08D2D7176F58BE64B88EB6F4394C31F8B4C412600E821A5FA1F416AFCB6A0F5EE6C33A3E9CFDC0DB4B3640427A9F3D23FC9AE491F0FBC435F98433DB8981");
4837+
rsa_sk.iq = rsa_iq;
4838+
rsa_sk.iqlen = hextobin(rsa_iq, "CF333D6AD66D02B4D11C8C23CA669D14D71803ADC3943BE03B1E48F52F385BCFDDFD0F85AD02A984E504FC6612549D4E7867B7D09DD13196BFC3FAA4B57393A9");
4839+
hextobin(sig, "CFB84D161E6DB130736FC6212EBE575571AF341CEF5757C19952A5364C90E3C47549E520E26253DAE70F645F31FA8B5DA9AE282741D3CA4B1CC365B7BD75D6D61D4CFD9AD9EDD17D23E0BA7D9775138DBABC7FF2A57587FE1EA1B51E8F3C68326E26FF89D8CF92BDD4C787D04857DFC3266E6B33B92AA08809929C72642F35C2");
4840+
4841+
hextobin(hv2, "F66C62B38E1CC69C378C0E16574AE5C6443FDFA3E85C6205C00B3231CAA3074EC1481BDC22AB575E6CF3CCD9EDA6B39F83923FC0E6475C799D257545F77233B4");
4842+
if (!fsign(BR_HASH_OID_SHA512, hv2, 64, &rsa_sk, t2)) {
4843+
fprintf(stderr, "Signature generation failed (2)\n");
4844+
exit(EXIT_FAILURE);
4845+
}
4846+
check_equals("Regenerated signature (2)", t2, sig, sizeof t2);
4847+
if (!fvrfy(t2, sizeof t2, BR_HASH_OID_SHA512,
4848+
sizeof tmp2, &rsa_pk, tmp2))
4849+
{
4850+
fprintf(stderr, "Signature verification failed (2)\n");
4851+
exit(EXIT_FAILURE);
4852+
}
4853+
check_equals("Extracted hash value (2)", hv2, tmp2, sizeof tmp2);
4854+
48154855
printf(" done.\n");
48164856
fflush(stdout);
48174857
}

0 commit comments

Comments
 (0)
0