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
|
use x25519_dalek::PublicKey;
use x25519_dalek::StaticSecret;
use x25519_dalek::SharedSecret;
/* Mutable part of handshake state */
enum StateMutable {
Reset,
InitiationSent,
InitiationProcessed,
ReponseSent
}
/* Immutable part of the handshake state */
struct StateFixed {
sk : StaticSecret,
pk : PublicKey,
ss : SharedSecret
}
struct State {
m : StateMutable,
f : StateFixed,
}
struct KeyPair {
send : [u8; 32],
recv : [u8; 32]
}
impl State {
/* Initialize a new handshake state machine
*/
fn new(sk : StaticSecret, pk : PublicKey) -> State {
let ss = sk.diffie_hellman(&pk);
State {
m : StateMutable::Reset,
f : StateFixed{sk, pk, ss}
}
}
/* Begin a new handshake, returns the initial handshake message
*/
fn begin(&self) -> Vec<u8> {
vec![]
}
/* Process a handshake message.
*
* Result is either a new state (and optionally a new key pair) or an error
*/
fn process(&self, msg : &[u8]) -> Result<(State, Option<KeyPair>), ()> {
Err(())
}
}
|