… | |
… | |
49 | |
49 | |
50 | typedef curve25519_key ecdh_key; |
50 | typedef curve25519_key ecdh_key; |
51 | |
51 | |
52 | struct rsa_data |
52 | struct rsa_data |
53 | { |
53 | { |
54 | u32 seqno; |
54 | u32 seqno; // (ictx) initial sequence nr (31 bits) |
55 | u8 auth_key[AUTH_SIZE]; |
|
|
56 | u8 mac_key[MAC_KEYSIZE]; // used to generate hmac key |
55 | u8 mac_key[MAC_IKMSIZE]; // (ictx) used to generate hmac key |
57 | u8 cipher_key[CIPHER_KEYSIZE]; // used to generate cipher key |
56 | u8 cipher_key[CIPHER_IKMSIZE]; // (ictx) used to generate cipher key |
58 | u8 hkdf_salt[HKDF_SALT]; // used as hkdf salt |
57 | u8 hkdf_salt[HKDF_SALT]; // (octx) used as hkdf salt |
59 | u8 pad[ |
58 | u8 extra_auth[ // (ictx) additional auth randomness |
60 | (RSABITS >> 3) |
59 | (RSABITS >> 3) |
61 | - 41 // OAEP |
60 | - RSA_OAEP_SIZE |
62 | - sizeof (u32) // seqno |
61 | - sizeof (u32) // seqno |
63 | - AUTH_SIZE |
|
|
64 | - MAC_KEYSIZE |
62 | - MAC_IKMSIZE |
65 | - CIPHER_KEYSIZE |
63 | - CIPHER_IKMSIZE |
66 | - HKDF_SALT |
64 | - HKDF_SALT |
67 | - 3 // struct alignment... |
65 | - 3 // struct alignment... |
68 | ]; |
66 | ]; |
69 | }; |
67 | }; |
70 | |
68 | |
… | |
… | |
100 | |
98 | |
101 | void hmac_set (crypto_ctx * ctx); |
99 | void hmac_set (crypto_ctx * ctx); |
102 | bool hmac_chk (crypto_ctx * ctx); |
100 | bool hmac_chk (crypto_ctx * ctx); |
103 | |
101 | |
104 | private: |
102 | private: |
105 | static unsigned char hmac_digest[EVP_MAX_MD_SIZE]; |
|
|
106 | |
|
|
107 | void hmac_gen (crypto_ctx * ctx); |
103 | void hmac_gen (crypto_ctx * ctx, u8 *hmac_digest); |
108 | }; |
104 | }; |
109 | |
105 | |
110 | struct vpn_packet : hmac_packet |
106 | struct vpn_packet : hmac_packet |
111 | { |
107 | { |
112 | enum ptype |
108 | enum ptype |
… | |
… | |
209 | |
205 | |
210 | ev_tstamp auth_expire; // when the snd_* and *_ecdh values expire |
206 | ev_tstamp auth_expire; // when the snd_* and *_ecdh values expire |
211 | |
207 | |
212 | // send auth data - used for octx |
208 | // send auth data - used for octx |
213 | auth_data snd_auth; |
209 | auth_data snd_auth; |
214 | auth_mac snd_auth_mac; // expected response mac |
|
|
215 | ecdh_key snd_ecdh_a; // the secret ecdh key we used for our request |
210 | ecdh_key snd_ecdh_a; // the secret ecdh key we used for our request |
216 | ecdh_key snd_ecdh_b; // the public ecdh key we received in the response |
211 | ecdh_key snd_ecdh_b; // the public ecdh key we received in the response |
217 | bool have_snd_auth; // received response for our req |
212 | bool have_snd_auth; // received response for our req |
218 | |
213 | |
219 | // receive auth data - used for ictx |
214 | // receive auth data - used for ictx |