Bump copyright date to 2019
[tor.git] / src / test / test_hs_ntor.c
blob1c694e6040c0337b4654f1f77e90b4a7ee68dc9d
1 /* Copyright (c) 2017-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 /**
5 * \file test_hs_ntor.c
6 * \brief Test hidden service ntor functionality.
7 */
9 #include "test/test.h"
10 #include "test/test_helpers.h"
11 #include "test/log_test_helpers.h"
12 #include "lib/crypt_ops/crypto_curve25519.h"
13 #include "lib/crypt_ops/crypto_ed25519.h"
15 #include "core/crypto/hs_ntor.h"
17 /* Test the HS ntor handshake. Simulate the sending of an encrypted INTRODUCE1
18 * cell, and verify the proper derivation of decryption keys on the other end.
19 * Then simulate the sending of an authenticated RENDEZVOUS1 cell and verify
20 * the proper verification on the other end. */
21 static void
22 test_hs_ntor(void *arg)
24 int retval;
26 uint8_t subcredential[DIGEST256_LEN];
28 ed25519_keypair_t service_intro_auth_keypair;
29 curve25519_keypair_t service_intro_enc_keypair;
30 curve25519_keypair_t service_ephemeral_rend_keypair;
32 curve25519_keypair_t client_ephemeral_enc_keypair;
34 hs_ntor_intro_cell_keys_t client_hs_ntor_intro_cell_keys;
35 hs_ntor_intro_cell_keys_t service_hs_ntor_intro_cell_keys;
37 hs_ntor_rend_cell_keys_t service_hs_ntor_rend_cell_keys;
38 hs_ntor_rend_cell_keys_t client_hs_ntor_rend_cell_keys;
40 (void) arg;
42 /* Generate fake data for this unittest */
44 /* Generate fake subcredential */
45 memset(subcredential, 'Z', DIGEST256_LEN);
47 /* service */
48 curve25519_keypair_generate(&service_intro_enc_keypair, 0);
49 ed25519_keypair_generate(&service_intro_auth_keypair, 0);
50 curve25519_keypair_generate(&service_ephemeral_rend_keypair, 0);
51 /* client */
52 curve25519_keypair_generate(&client_ephemeral_enc_keypair, 0);
55 /* Client: Simulate the sending of an encrypted INTRODUCE1 cell */
56 retval =
57 hs_ntor_client_get_introduce1_keys(&service_intro_auth_keypair.pubkey,
58 &service_intro_enc_keypair.pubkey,
59 &client_ephemeral_enc_keypair,
60 subcredential,
61 &client_hs_ntor_intro_cell_keys);
62 tt_int_op(retval, OP_EQ, 0);
64 /* Service: Simulate the decryption of the received INTRODUCE1 */
65 retval =
66 hs_ntor_service_get_introduce1_keys(&service_intro_auth_keypair.pubkey,
67 &service_intro_enc_keypair,
68 &client_ephemeral_enc_keypair.pubkey,
69 subcredential,
70 &service_hs_ntor_intro_cell_keys);
71 tt_int_op(retval, OP_EQ, 0);
73 /* Test that the INTRODUCE1 encryption/mac keys match! */
74 tt_mem_op(client_hs_ntor_intro_cell_keys.enc_key, OP_EQ,
75 service_hs_ntor_intro_cell_keys.enc_key,
76 CIPHER256_KEY_LEN);
77 tt_mem_op(client_hs_ntor_intro_cell_keys.mac_key, OP_EQ,
78 service_hs_ntor_intro_cell_keys.mac_key,
79 DIGEST256_LEN);
81 /* Service: Simulate creation of RENDEZVOUS1 key material. */
82 retval =
83 hs_ntor_service_get_rendezvous1_keys(&service_intro_auth_keypair.pubkey,
84 &service_intro_enc_keypair,
85 &service_ephemeral_rend_keypair,
86 &client_ephemeral_enc_keypair.pubkey,
87 &service_hs_ntor_rend_cell_keys);
88 tt_int_op(retval, OP_EQ, 0);
90 /* Client: Simulate the verification of a received RENDEZVOUS1 cell */
91 retval =
92 hs_ntor_client_get_rendezvous1_keys(&service_intro_auth_keypair.pubkey,
93 &client_ephemeral_enc_keypair,
94 &service_intro_enc_keypair.pubkey,
95 &service_ephemeral_rend_keypair.pubkey,
96 &client_hs_ntor_rend_cell_keys);
97 tt_int_op(retval, OP_EQ, 0);
99 /* Test that the RENDEZVOUS1 key material match! */
100 tt_mem_op(client_hs_ntor_rend_cell_keys.rend_cell_auth_mac, OP_EQ,
101 service_hs_ntor_rend_cell_keys.rend_cell_auth_mac,
102 DIGEST256_LEN);
103 tt_mem_op(client_hs_ntor_rend_cell_keys.ntor_key_seed, OP_EQ,
104 service_hs_ntor_rend_cell_keys.ntor_key_seed,
105 DIGEST256_LEN);
106 done:
110 struct testcase_t hs_ntor_tests[] = {
111 { "hs_ntor", test_hs_ntor, TT_FORK,
112 NULL, NULL },
114 END_OF_TESTCASES