Skip to content

Commit b17b4c7

Browse files
committed
Major rework for Secure Element support
1 parent 8d378ea commit b17b4c7

14 files changed

+1414
-264
lines changed

src/aes/lmic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static void aesroundkeys () {
245245
}
246246
}
247247

248-
u4_t os_aes (u1_t mode, xref2u1_t buf, u2_t len) {
248+
u4_t os_aes_original (u1_t mode, xref2u1_t buf, u2_t len) {
249249

250250
aesroundkeys();
251251

src/aes/lmic_aes_api.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
3+
Module: lmic_aes_api.h
4+
5+
Function:
6+
The API type
7+
8+
Copyright & License:
9+
See accompanying LICENSE file.
10+
11+
Author:
12+
Terry Moore, MCCI May 2020
13+
14+
*/
15+
16+
//! \file
17+
18+
#ifndef _lmic_aes_api_h_
19+
#define _lmic_aes_api_h_
20+
21+
#ifndef _lmic_h_
22+
# include "../lmic/oslmic.h"
23+
#endif
24+
25+
#ifndef _lmic_aes_interface_h_
26+
# include "lmic_aes_interface.h"
27+
#endif
28+
29+
LMIC_BEGIN_DECLS
30+
31+
// linkage to well-known drivers. Only one is used.
32+
LMIC_AES_request_t os_aes_original;
33+
LMIC_AES_request_t os_aes_generic;
34+
35+
static inline
36+
u4_t os_aes(u1_t mode, xref2u1_t buf, u2_t len) {
37+
#ifdef USE_ORIGINAL_AES
38+
return os_aes_original(mode, buf, len);
39+
#else
40+
return os_aes_generic(mode, buf, len);
41+
#endif
42+
}
43+
44+
LMIC_END_DECLS
45+
46+
#endif // _lmic_aes_api_h_

src/aes/lmic_aes_interface.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
3+
Module: lmic_aes_interface.h
4+
5+
Function:
6+
The API type
7+
8+
Copyright & License:
9+
See accompanying LICENSE file.
10+
11+
Author:
12+
Terry Moore, MCCI May 2020
13+
14+
*/
15+
16+
//! \file
17+
18+
#ifndef _lmic_aes_interface_h_
19+
#define _lmic_aes_interface_h_
20+
21+
#ifndef _lmic_env_h_
22+
# include "../lmic/lmic_env.h"
23+
#endif
24+
25+
#ifndef _oslmic_types_h_
26+
# include "../lmic/oslmic_types.h"
27+
#endif
28+
29+
LMIC_BEGIN_DECLS
30+
31+
/****************************************************************************\
32+
| Things needed for AES
33+
\****************************************************************************/
34+
35+
extern u4_t AESAUX[];
36+
extern u4_t AESKEY[];
37+
#define AESkey ((u1_t*)AESKEY)
38+
#define AESaux ((u1_t*)AESAUX)
39+
40+
#ifndef AES_ENC // if AES_ENC is defined as macro all other values must be too
41+
#define AES_ENC 0x00
42+
#define AES_DEC 0x01
43+
#define AES_MIC 0x02
44+
#define AES_CTR 0x04
45+
#define AES_MICNOAUX 0x08
46+
#endif
47+
48+
typedef
49+
u4_t LMIC_ABI_STD
50+
LMIC_AES_request_t(u1_t mode, xref2u1_t buf, u2_t len);
51+
52+
53+
/// \brief Declare secure element functions for a given driver
54+
///
55+
/// \param a_driver Fragment of driver name to insert in function names, e.g `Default`.
56+
///
57+
/// \details
58+
/// The parameter is macro-expanded and then substituted to declare each
59+
/// of the interface functions for the specified driver.
60+
///
61+
/// To use this, write `LMIC_AES_DECLARE_DRIVER_FNS(driverName)`, where \p driverName
62+
/// is the name of the driver, e.g. `ibm` or `ideetron`.
63+
///
64+
#define LMIC_AES_DECLARE_DRIVER_FNS(a_driver) \
65+
LMIC_AES_request_t LMIC_AES_##a_driver##_request \
66+
67+
LMIC_END_DECLS
68+
69+
#endif // _lmic_aes_interface_h_

src/aes/other.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
*
2424
* extern "C" void lmic_aes_encrypt(u1_t *data, u1_t *key);
2525
*
26-
* That takes a single 16-byte buffer and encrypts it wit the given
26+
* That takes a single 16-byte buffer and encrypts it with the given
2727
* 16-byte key.
2828
*/
2929

30-
#include "../lmic/oslmic.h"
30+
#include "lmic_aes_api.h"
3131

3232
#if !defined(USE_ORIGINAL_AES)
3333

@@ -123,7 +123,7 @@ static void os_aes_ctr (xref2u1_t buf, u2_t len) {
123123
}
124124
}
125125

126-
u4_t os_aes (u1_t mode, xref2u1_t buf, u2_t len) {
126+
u4_t os_aes_generic (u1_t mode, xref2u1_t buf, u2_t len) {
127127
switch (mode & ~AES_MICNOAUX) {
128128
case AES_MIC:
129129
os_aes_cmac(buf, len, /* prepend_aux */ !(mode & AES_MICNOAUX));

0 commit comments

Comments
 (0)