Skip to content

Commit dabbbb2

Browse files
committed
Merge branch 'feature/add_crypto_library' into 'master'
feat(lib): move out crypto library from internal See merge request sdk/ESP8266_RTOS_SDK!450
2 parents 1870ecf + 925d868 commit dabbbb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+9879
-3
lines changed

components/esp8266/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ register_component()
1111

1212
target_link_libraries(${COMPONENT_NAME} "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib")
1313
if(NOT CONFIG_NO_BLOBS)
14-
target_link_libraries(${COMPONENT_NAME} crypto gcc hal core
14+
target_link_libraries(${COMPONENT_NAME} gcc hal core
1515
net80211 phy pp smartconfig ssc wpa)
1616
endif()
1717

components/esp8266/component.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ COMPONENT_SRCDIRS := driver source
1111

1212
LIBS ?=
1313
ifndef CONFIG_NO_BLOBS
14-
LIBS += crypto gcc hal core net80211 \
14+
LIBS += gcc hal core net80211 \
1515
phy pp smartconfig ssc wpa
1616
endif
1717

components/esp8266/lib/VERSION

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
gwen:
2-
crypto: eca7811
32
core: 8ee40dd
43
net80211: eca7811
54
pp: eca7811

components/esp8266/lib/libcrypto.a

-100 KB
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
COMPONENT_ADD_INCLUDEDIRS := include port/include
2+
COMPONENT_SRCDIRS := src/crypto
3+
4+
CFLAGS += -DEMBEDDED_SUPP -D__ets__ -DESPRESSIF_USE
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* AES functions
3+
* Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License version 2 as
7+
* published by the Free Software Foundation.
8+
*
9+
* Alternatively, this software may be distributed under the terms of BSD
10+
* license.
11+
*
12+
* See README and COPYING for more details.
13+
*/
14+
15+
#ifndef AES_H
16+
#define AES_H
17+
18+
#define AES_BLOCK_SIZE 16
19+
20+
void * aes_encrypt_init(const u8 *key, size_t len);
21+
void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt);
22+
void aes_encrypt_deinit(void *ctx);
23+
void * aes_decrypt_init(const u8 *key, size_t len);
24+
void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain);
25+
void aes_decrypt_deinit(void *ctx);
26+
27+
#endif /* AES_H */
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* AES (Rijndael) cipher
3+
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License version 2 as
7+
* published by the Free Software Foundation.
8+
*
9+
* Alternatively, this software may be distributed under the terms of BSD
10+
* license.
11+
*
12+
* See README and COPYING for more details.
13+
*/
14+
15+
#ifndef AES_I_H
16+
#define AES_I_H
17+
18+
#include "aes.h"
19+
20+
/* #define FULL_UNROLL */
21+
#define AES_SMALL_TABLES
22+
23+
extern const u32 Te0[256];
24+
extern const u32 Te1[256];
25+
extern const u32 Te2[256];
26+
extern const u32 Te3[256];
27+
extern const u32 Te4[256];
28+
extern const u32 Td0[256];
29+
extern const u32 Td1[256];
30+
extern const u32 Td2[256];
31+
extern const u32 Td3[256];
32+
extern const u32 Td4[256];
33+
extern const u32 rcon[10];
34+
extern const u8 Td4s[256];
35+
extern const u8 rcons[10];
36+
37+
#ifndef AES_SMALL_TABLES
38+
39+
#define RCON(i) rcon[(i)]
40+
41+
#define TE0(i) Te0[((i) >> 24) & 0xff]
42+
#define TE1(i) Te1[((i) >> 16) & 0xff]
43+
#define TE2(i) Te2[((i) >> 8) & 0xff]
44+
#define TE3(i) Te3[(i) & 0xff]
45+
#define TE41(i) (Te4[((i) >> 24) & 0xff] & 0xff000000)
46+
#define TE42(i) (Te4[((i) >> 16) & 0xff] & 0x00ff0000)
47+
#define TE43(i) (Te4[((i) >> 8) & 0xff] & 0x0000ff00)
48+
#define TE44(i) (Te4[(i) & 0xff] & 0x000000ff)
49+
#define TE421(i) (Te4[((i) >> 16) & 0xff] & 0xff000000)
50+
#define TE432(i) (Te4[((i) >> 8) & 0xff] & 0x00ff0000)
51+
#define TE443(i) (Te4[(i) & 0xff] & 0x0000ff00)
52+
#define TE414(i) (Te4[((i) >> 24) & 0xff] & 0x000000ff)
53+
#define TE411(i) (Te4[((i) >> 24) & 0xff] & 0xff000000)
54+
#define TE422(i) (Te4[((i) >> 16) & 0xff] & 0x00ff0000)
55+
#define TE433(i) (Te4[((i) >> 8) & 0xff] & 0x0000ff00)
56+
#define TE444(i) (Te4[(i) & 0xff] & 0x000000ff)
57+
#define TE4(i) (Te4[(i)] & 0x000000ff)
58+
59+
#define TD0(i) Td0[((i) >> 24) & 0xff]
60+
#define TD1(i) Td1[((i) >> 16) & 0xff]
61+
#define TD2(i) Td2[((i) >> 8) & 0xff]
62+
#define TD3(i) Td3[(i) & 0xff]
63+
#define TD41(i) (Td4[((i) >> 24) & 0xff] & 0xff000000)
64+
#define TD42(i) (Td4[((i) >> 16) & 0xff] & 0x00ff0000)
65+
#define TD43(i) (Td4[((i) >> 8) & 0xff] & 0x0000ff00)
66+
#define TD44(i) (Td4[(i) & 0xff] & 0x000000ff)
67+
#define TD0_(i) Td0[(i) & 0xff]
68+
#define TD1_(i) Td1[(i) & 0xff]
69+
#define TD2_(i) Td2[(i) & 0xff]
70+
#define TD3_(i) Td3[(i) & 0xff]
71+
72+
#else /* AES_SMALL_TABLES */
73+
74+
#define RCON(i) (rcons[(i)] << 24)
75+
76+
static inline u32 rotr(u32 val, int bits)
77+
{
78+
return (val >> bits) | (val << (32 - bits));
79+
}
80+
81+
#define TE0(i) Te0[((i) >> 24) & 0xff]
82+
#define TE1(i) rotr(Te0[((i) >> 16) & 0xff], 8)
83+
#define TE2(i) rotr(Te0[((i) >> 8) & 0xff], 16)
84+
#define TE3(i) rotr(Te0[(i) & 0xff], 24)
85+
#define TE41(i) ((Te0[((i) >> 24) & 0xff] << 8) & 0xff000000)
86+
#define TE42(i) (Te0[((i) >> 16) & 0xff] & 0x00ff0000)
87+
#define TE43(i) (Te0[((i) >> 8) & 0xff] & 0x0000ff00)
88+
#define TE44(i) ((Te0[(i) & 0xff] >> 8) & 0x000000ff)
89+
#define TE421(i) ((Te0[((i) >> 16) & 0xff] << 8) & 0xff000000)
90+
#define TE432(i) (Te0[((i) >> 8) & 0xff] & 0x00ff0000)
91+
#define TE443(i) (Te0[(i) & 0xff] & 0x0000ff00)
92+
#define TE414(i) ((Te0[((i) >> 24) & 0xff] >> 8) & 0x000000ff)
93+
#define TE411(i) ((Te0[((i) >> 24) & 0xff] << 8) & 0xff000000)
94+
#define TE422(i) (Te0[((i) >> 16) & 0xff] & 0x00ff0000)
95+
#define TE433(i) (Te0[((i) >> 8) & 0xff] & 0x0000ff00)
96+
#define TE444(i) ((Te0[(i) & 0xff] >> 8) & 0x000000ff)
97+
#define TE4(i) ((Te0[(i)] >> 8) & 0x000000ff)
98+
99+
#define TD0(i) Td0[((i) >> 24) & 0xff]
100+
#define TD1(i) rotr(Td0[((i) >> 16) & 0xff], 8)
101+
#define TD2(i) rotr(Td0[((i) >> 8) & 0xff], 16)
102+
#define TD3(i) rotr(Td0[(i) & 0xff], 24)
103+
#define TD41(i) (Td4s[((i) >> 24) & 0xff] << 24)
104+
#define TD42(i) (Td4s[((i) >> 16) & 0xff] << 16)
105+
#define TD43(i) (Td4s[((i) >> 8) & 0xff] << 8)
106+
#define TD44(i) (Td4s[(i) & 0xff])
107+
#define TD0_(i) Td0[(i) & 0xff]
108+
#define TD1_(i) rotr(Td0[(i) & 0xff], 8)
109+
#define TD2_(i) rotr(Td0[(i) & 0xff], 16)
110+
#define TD3_(i) rotr(Td0[(i) & 0xff], 24)
111+
112+
#endif /* AES_SMALL_TABLES */
113+
114+
#ifdef _MSC_VER
115+
#define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
116+
#define GETU32(p) SWAP(*((u32 *)(p)))
117+
#define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
118+
#else
119+
#define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ \
120+
((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
121+
#define PUTU32(ct, st) { \
122+
(ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); \
123+
(ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
124+
#endif
125+
126+
#define AES_PRIV_SIZE (4 * 4 * 15 + 4)
127+
#define AES_PRIV_NR_POS (4 * 15)
128+
129+
int rijndaelKeySetupEnc(u32 rk[], const u8 cipherKey[], int keyBits);
130+
131+
#endif /* AES_I_H */
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* AES-based functions
3+
*
4+
* - AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
5+
* - One-Key CBC MAC (OMAC1) hash with AES-128
6+
* - AES-128 CTR mode encryption
7+
* - AES-128 EAX mode encryption/decryption
8+
* - AES-128 CBC
9+
*
10+
* Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
11+
*
12+
* This program is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License version 2 as
14+
* published by the Free Software Foundation.
15+
*
16+
* Alternatively, this software may be distributed under the terms of BSD
17+
* license.
18+
*
19+
* See README and COPYING for more details.
20+
*/
21+
22+
#ifndef AES_WRAP_H
23+
#define AES_WRAP_H
24+
25+
int __must_check aes_wrap(const u8 *kek, int n, const u8 *plain, u8 *cipher);
26+
int __must_check aes_unwrap(const u8 *kek, int n, const u8 *cipher, u8 *plain);
27+
int __must_check omac1_aes_128_vector(const u8 *key, size_t num_elem,
28+
const u8 *addr[], const size_t *len,
29+
u8 *mac);
30+
int __must_check omac1_aes_128(const u8 *key, const u8 *data, size_t data_len,
31+
u8 *mac);
32+
int __must_check aes_128_encrypt_block(const u8 *key, const u8 *in, u8 *out);
33+
int __must_check aes_128_ctr_encrypt(const u8 *key, const u8 *nonce,
34+
u8 *data, size_t data_len);
35+
int __must_check aes_128_eax_encrypt(const u8 *key,
36+
const u8 *nonce, size_t nonce_len,
37+
const u8 *hdr, size_t hdr_len,
38+
u8 *data, size_t data_len, u8 *tag);
39+
int __must_check aes_128_eax_decrypt(const u8 *key,
40+
const u8 *nonce, size_t nonce_len,
41+
const u8 *hdr, size_t hdr_len,
42+
u8 *data, size_t data_len, const u8 *tag);
43+
int __must_check aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data,
44+
size_t data_len);
45+
int __must_check aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data,
46+
size_t data_len);
47+
48+
#endif /* AES_WRAP_H */
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Base64 encoding/decoding (RFC1341)
3+
* Copyright (c) 2005, Jouni Malinen <j@w1.fi>
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License version 2 as
7+
* published by the Free Software Foundation.
8+
*
9+
* Alternatively, this software may be distributed under the terms of BSD
10+
* license.
11+
*
12+
* See README and COPYING for more details.
13+
*/
14+
15+
#ifndef BASE64_H
16+
#define BASE64_H
17+
18+
unsigned char * base64_encode(const unsigned char *src, size_t len,
19+
size_t *out_len);
20+
unsigned char * base64_decode(const unsigned char *src, size_t len,
21+
size_t *out_len);
22+
23+
#endif /* BASE64_H */

0 commit comments

Comments
 (0)