forked from bristolcrypto/SPDZ-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
STS.h
72 lines (60 loc) · 2.18 KB
/
STS.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
// (C) 2017 University of Bristol. See License.txt
#ifndef _NETWORK_STS
#define _NETWORK_STS
/* The Station to Station protocol
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <sodium.h>
using namespace std;
typedef enum
{ UNKNOWN // Have not started the interaction or have cleared the memory
, SENT1 // Sent initial message
, SENT2 // Received 1, sent 2
, FINISHED // Done (received msg 2 & sent 3 or received msg 3)
, UNDEFINED // For arrays/vectors/etc of STS classes that are initialized later.
} phase_t;
struct msg1_st {
unsigned char bytes[crypto_box_PUBLICKEYBYTES];
};
typedef struct msg1_st sts_msg1_t;
struct msg2_st {
unsigned char pubkey[crypto_box_PUBLICKEYBYTES];
unsigned char sig[crypto_sign_BYTES];
};
typedef struct msg2_st sts_msg2_t;
struct msg3_st {
unsigned char bytes[crypto_sign_BYTES];
};
typedef struct msg3_st sts_msg3_t;
class STS
{
phase_t phase;
unsigned char their_public_sign_key[crypto_sign_PUBLICKEYBYTES];
unsigned char my_public_sign_key[crypto_sign_PUBLICKEYBYTES];
unsigned char my_private_sign_key[crypto_sign_SECRETKEYBYTES];
unsigned char ephemeral_private_key[crypto_box_SECRETKEYBYTES];
unsigned char ephemeral_public_key[crypto_box_PUBLICKEYBYTES];
unsigned char their_ephemeral_public_key[crypto_box_PUBLICKEYBYTES];
unsigned char raw_secret[crypto_hash_sha512_BYTES];
uint64_t kdf_counter;
public:
STS();
STS( const unsigned char theirPub[crypto_sign_PUBLICKEYBYTES]
, const unsigned char myPub[crypto_sign_PUBLICKEYBYTES]
, const unsigned char myPriv[crypto_sign_SECRETKEYBYTES]);
~STS();
void init( const unsigned char theirPub[crypto_sign_PUBLICKEYBYTES]
, const unsigned char myPub[crypto_sign_PUBLICKEYBYTES]
, const unsigned char myPriv[crypto_sign_SECRETKEYBYTES]);
sts_msg1_t send_msg1();
sts_msg3_t recv_msg2(sts_msg2_t msg2);
sts_msg2_t recv_msg1(sts_msg1_t msg1);
void recv_msg3(sts_msg3_t msg3);
vector<unsigned char> derive_secret(size_t);
private:
vector<unsigned char> unsafe_derive_secret(size_t);
void kdf_block(unsigned char *block);
};
#endif /* _NETWORK_STS */