Skip to content

Commit 1997da1

Browse files
committed
Enable side-by-side storages. The "all" mode can now build and use both
pubkey and symkey storages alongside each other. It is assumed that the correct storage is passed to the relevant e4c_protect / e4c_unprotect implementation, and there is (currently) no way to type check this.
1 parent 11e9566 commit 1997da1

29 files changed

+491
-569
lines changed

include/e4/e4.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#ifdef __cplusplus
2323
extern "C" {
24-
#endif
24+
#endif /* C++ */
2525

2626
#include <stddef.h>
2727
#include <stdint.h>
@@ -113,14 +113,14 @@ message.
113113

114114
#define e4c_protect_message e4c_pubkey_protect_message
115115
#define e4c_unprotect_message e4c_pubkey_unprotect_message
116-
#endif
116+
#endif /* E4_MODE_PUBKEY */
117117

118118
#ifdef E4_MODE_SYMKEY
119119
#include "e4/e4symkey.h"
120120

121121
#define e4c_protect_message e4c_symkey_protect_message
122122
#define e4c_unprotect_message e4c_symkey_unprotect_message
123-
#endif
123+
#endif /* E4_MODE_SYMKEY */
124124

125125
#ifdef E4_MODE_ALL
126126
/* include forward declarations for specific implementations.
@@ -129,12 +129,12 @@ message.
129129
*/
130130
#include "e4/e4pubkey.h"
131131
#include "e4/e4symkey.h"
132-
#endif
132+
#endif /* E4_MODE_ALL */
133133

134134

135135

136136
#ifdef __cplusplus
137137
}
138-
#endif
138+
#endif /* C++ */
139139

140-
#endif
140+
#endif /* include guard */

include/e4/e4pubkey.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ int e4c_pubkey_protect_message(uint8_t *ciphertext,
88
const uint8_t *message,
99
size_t message_len,
1010
const char *topic_name,
11-
e4storage *storage,
11+
void* storage,
1212
const uint32_t proto_opts);
1313

1414
int e4c_pubkey_unprotect_message(uint8_t *message,
@@ -17,9 +17,9 @@ int e4c_pubkey_unprotect_message(uint8_t *message,
1717
const uint8_t *ciphertext,
1818
size_t ciphertext_len,
1919
const char *topic_name,
20-
e4storage *storage,
20+
void* storage,
2121
const uint32_t proto_opts);
2222

23-
int e4c_pubkey_c2sharedsecret_derivestore(e4storage* storage);
23+
int e4c_pubkey_c2sharedsecret_derivestore(void* storage);
2424

25-
#endif
25+
#endif /* include guard */

include/e4/e4symkey.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ int e4c_symkey_protect_message(uint8_t *ciphertext,
88
const uint8_t *message,
99
size_t message_len,
1010
const char *topic_name,
11-
e4storage *storage,
11+
void* storage,
1212
const uint32_t proto_opts);
1313

1414
int e4c_symkey_unprotect_message(uint8_t *message,
@@ -17,7 +17,7 @@ int e4c_symkey_unprotect_message(uint8_t *message,
1717
const uint8_t *ciphertext,
1818
size_t ciphertext_len,
1919
const char *topic_name,
20-
e4storage *storage,
20+
void* storage,
2121
const uint32_t proto_opts);
2222

23-
#endif
23+
#endif /* include guard */

include/e4/error.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636
/* Incompatible storage type */
3737
#define E4_ERROR_PERSISTENCE_INCOMPATIBLE -113
3838

39-
#endif
39+
#endif /* include guard */

include/e4/internal/e4c_store_mem.h include/e4/internal/e4c_common_storage.h

+4-29
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,14 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include <fcntl.h>
20-
#ifndef _E4C_STORE_MEM_H_
21-
#define _E4C_STORE_MEM_H_
19+
#ifndef _E4C_STORE_COMMON_H_
20+
#define _E4C_STORE_COMMON_H_
2221

23-
#include <stddef.h>
24-
#include <stdint.h>
25-
26-
#ifndef E4_TOPICS_MAX
27-
#define E4_TOPICS_MAX 100
28-
#endif
29-
30-
#define E4_MAX_PATH 255
31-
32-
/* In memory structures that represent the file. */
33-
34-
typedef struct
22+
typedef struct _e4_topic_key
3523
{
3624
uint8_t topic[E4_TOPICHASH_LEN];
3725
uint8_t key[E4_KEY_LEN];
3826
} topic_key;
3927

40-
41-
struct _e4storage
42-
{
43-
/* These fields are persisted by the sync command */
44-
uint8_t id[E4_ID_LEN];
45-
uint8_t key[E4_KEY_LEN];
46-
uint16_t topiccount;
47-
topic_key topics[E4_TOPICS_MAX];
48-
49-
/* These fields are set at run time only */
50-
char filepath[E4_MAX_PATH + 1];
51-
uint8_t ctrltopic[E4_TOPICHASH_LEN];
52-
};
53-
5428
#endif
29+

include/e4/internal/e4c_pk_store_file.h

+4-9
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include <fcntl.h>
20-
2119
#ifndef _E4C_STORE_PK_FILE_H_
2220
#define _E4C_STORE_PK_FILE_H_
2321

2422
#include <stddef.h>
2523
#include <stdint.h>
24+
#include <fcntl.h>
2625

2726
#ifndef E4_DEVICES_MAX
2827
#define E4_DEVICES_MAX 100
@@ -36,19 +35,15 @@
3635

3736
/* In memory structures that represent the file. */
3837

39-
typedef struct _e4_topic_key
40-
{
41-
uint8_t topic[E4_TOPICHASH_LEN];
42-
uint8_t key[E4_KEY_LEN];
43-
} topic_key;
38+
#include "e4c_common_storage.h"
4439

4540
typedef struct _e4_device_key
4641
{
4742
uint8_t id[E4_ID_LEN];
4843
uint8_t pubkey[E4_PK_EDDSA_PUBKEY_LEN];
4944
} device_key;
5045

51-
struct _e4storage
46+
typedef struct _e4storage_pubkey
5247
{
5348
/* These fields are persisted by the sync command */
5449
uint8_t id[E4_ID_LEN];
@@ -67,6 +62,6 @@ struct _e4storage
6762
/* These fields are set at run time only */
6863
char filepath[E4_MAX_PATH + 1];
6964
uint8_t ctrltopic[E4_TOPICHASH_LEN];
70-
};
65+
} e4storage_pubkey;
7166

7267
#endif

include/e4/internal/e4c_pk_store_mem.h

-54
This file was deleted.

include/e4/internal/e4c_store_file.h include/e4/internal/e4c_sym_store_file.h

+5-10
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include <fcntl.h>
19+
2020

2121
#ifndef _E4C_STORE_FILE_H_
2222
#define _E4C_STORE_FILE_H_
2323

2424
#include <stddef.h>
2525
#include <stdint.h>
26+
#include <fcntl.h>
2627

2728
#ifndef E4_TOPICS_MAX
2829
#define E4_TOPICS_MAX 100
@@ -31,15 +32,9 @@
3132
#define E4_MAX_PATH 255
3233

3334
/* In memory structures that represent the file. */
35+
#include "e4c_common_storage.h"
3436

35-
typedef struct
36-
{
37-
uint8_t topic[E4_TOPICHASH_LEN];
38-
uint8_t key[E4_KEY_LEN];
39-
} topic_key;
40-
41-
42-
struct _e4storage
37+
typedef struct _e4storage_symkey
4338
{
4439
/* These fields are persisted by the sync command */
4540
uint8_t id[E4_ID_LEN];
@@ -50,6 +45,6 @@ struct _e4storage
5045
/* These fields are set at run time only */
5146
char filepath[E4_MAX_PATH + 1];
5247
uint8_t ctrltopic[E4_TOPICHASH_LEN];
53-
};
48+
} e4storage_symkey;
5449

5550
#endif

0 commit comments

Comments
 (0)