-
Notifications
You must be signed in to change notification settings - Fork 60
/
crypto.h
129 lines (108 loc) · 3.25 KB
/
crypto.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef __CRYPTO_H__
#define __CRYPTO_H__
#include <stdlib.h>
#include "port_x.h"
#ifdef ARDUINO8266_SERVER_CPP
#ifdef __cplusplus
extern "C" {
#endif
#endif
typedef unsigned char byte;
#define HKDF_HASH_SIZE 32 // CHACHA20_POLY1305_AEAD_KEYSIZE
int crypto_hkdf(
const byte *key, size_t key_size,
const byte *salt, size_t salt_size,
const byte *info, size_t info_size,
byte *output, size_t *output_size
);
// SRP
struct _Srp;
typedef struct _Srp Srp;
Srp *crypto_srp_new();
void crypto_srp_free(Srp *srp);
int crypto_srp_init(Srp *srp, const char *username, const char *password);
int crypto_srp_get_salt(Srp *srp, byte *buffer, size_t *buffer_length);
int crypto_srp_get_public_key(Srp *srp, byte *buffer, size_t *buffer_length);
int crypto_srp_compute_key(
Srp *srp,
const byte *client_public_key, size_t client_public_key_size,
const byte *server_public_key, size_t server_public_key_size
);
int crypto_srp_verify(Srp *srp, const byte *proof, size_t proof_size);
int crypto_srp_get_proof(Srp *srp, byte *proof, size_t *proof_size);
int crypto_srp_hkdf(
Srp *srp,
const byte *salt, size_t salt_size,
const byte *info, size_t info_size,
byte *output, size_t *output_size
);
int crypto_chacha20poly1305_encrypt(
const byte *key, const byte *nonce, const byte *aad, size_t aad_size,
const byte *message, size_t message_size,
byte *encrypted, size_t *encrypted_size
);
int crypto_chacha20poly1305_decrypt(
const byte *key, const byte *nonce, const byte *aad, size_t aad_size,
const byte *message, size_t message_size,
byte *decrypted, size_t *descrypted_size
);
// ED25519
struct _ed25519_key;
typedef struct _ed25519_key ed25519_key;
ed25519_key *crypto_ed25519_new();
ed25519_key *crypto_ed25519_generate();
void crypto_ed25519_free(ed25519_key *key);
int crypto_ed25519_import_key(
ed25519_key *key,
const byte *data, size_t size
);
int crypto_ed25519_export_key(
const ed25519_key *key,
byte *buffer, size_t *size
);
int crypto_ed25519_import_public_key(
ed25519_key *key,
const byte *data, size_t size
);
int crypto_ed25519_export_public_key(
const ed25519_key *key,
byte *buffer, size_t *size
);
int crypto_ed25519_sign(
const ed25519_key *key,
const byte *message, size_t message_size,
byte *signature, size_t *signature_size
);
int crypto_ed25519_verify(
const ed25519_key *key,
const byte *message, size_t message_size,
const byte *signature, size_t signature_size
);
// CURVE25519
struct _curve25519_key;
typedef struct _curve25519_key curve25519_key;
curve25519_key *crypto_curve25519_getcached(int idx);
int crypto_curve25519_init(curve25519_key *key);
curve25519_key *crypto_curve25519_new();
void crypto_curve25519_done(curve25519_key *key);
int crypto_curve25519_generate(curve25519_key *key);
void crypto_curve25519_free(curve25519_key *key);
int crypto_curve25519_import_public(
curve25519_key *key,
const byte *data, size_t size
);
int crypto_curve25519_export_public(
const curve25519_key *key,
byte *buffer, size_t *size
);
int crypto_curve25519_shared_secret(
const curve25519_key *private_key,
const curve25519_key *public_key,
byte *buffer, size_t *size
);
#ifdef ARDUINO8266_SERVER_CPP
#ifdef __cplusplus
} // extern C
#endif
#endif
#endif // __CRYPTO_H__