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
|
/*
* crypto.h
*
* Created on: Jun 25, 2015
* Author: tim
*/
#ifndef HOMEKIT_CRYPTO_H_
#define HOMEKIT_CRYPTO_H_
//#define USE_UNACL_SCALARMULT 1
#define USE_TWEETNACL_SCALARMULT 1
#if defined(USE_UNACL_SCALARMULT)
#include "uNaCl/api.h"
#endif
#include "tweetnacl-modified/tweetnacl.h"
#include "srp/srp.h"
#include "random.h"
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct
{
struct
{
// Public key is the last 32-bytes of the secret key
union
{
uint8_t secret[64];
struct
{
uint8_t __ignore__[32];
uint8_t pub[32];
};
};
} sign;
// Client we are paired with
struct
{
uint8_t name[36];
uint8_t ltpk[32];
} client;
} crypto_keys_t;
extern crypto_keys_t crypto_keys;
extern void crypto_init(void);
extern void crypto_scheduleStoreKeys(void);
extern void crypto_storeKeys(void);
extern uint8_t crypto_verifyAndDecrypt(const uint8_t* key, uint8_t* nonce, uint8_t* encrypted, uint8_t length, uint8_t* output_buf, uint8_t* mac);
extern void crypto_encryptAndSeal(const uint8_t* key, uint8_t* nonce, uint8_t* plain, uint16_t length, uint8_t* output_buf, uint8_t* output_mac);
extern void crypto_sha512hmac(uint8_t* hash, uint8_t* salt, uint8_t salt_length, uint8_t* data, uint8_t data_length);
extern void crypto_hkdf(uint8_t* target, uint8_t* salt, uint8_t salt_length, uint8_t* info, uint8_t info_length, uint8_t* ikm, uint8_t ikm_length);
extern void crypto_transportEncrypt(uint8_t* key, uint8_t* nonce, uint8_t* plaintext, uint16_t plength, uint8_t* ciphertext, uint16_t* clength);
extern uint8_t crypto_transportDecrypt(uint8_t* key, uint8_t* nonce, uint8_t* ciphertext, uint16_t clength, uint8_t* plaintext, uint16_t* plength);
extern uint8_t crypto_advertise(void);
void crypto_printkey(void);
#ifdef __cplusplus
}
#endif
#endif /* HOMEKIT_CRYPTO_H_ */
|