tor  0.4.1.0-alpha-dev
onion.c
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
41 #include "core/or/or.h"
42 
43 #include "app/config/config.h"
45 #include "core/crypto/onion_fast.h"
46 #include "core/crypto/onion_ntor.h"
47 #include "core/crypto/onion_tap.h"
48 #include "core/or/onion.h"
50 
51 #include "core/or/cell_st.h"
52 
53 // trunnel
54 #include "trunnel/ed25519_cert.h"
55 
59 static int
60 check_create_cell(const create_cell_t *cell, int unknown_ok)
61 {
62  switch (cell->cell_type) {
63  case CELL_CREATE:
64  if (cell->handshake_type != ONION_HANDSHAKE_TYPE_TAP &&
65  cell->handshake_type != ONION_HANDSHAKE_TYPE_NTOR)
66  return -1;
67  break;
68  case CELL_CREATE_FAST:
69  if (cell->handshake_type != ONION_HANDSHAKE_TYPE_FAST)
70  return -1;
71  break;
72  case CELL_CREATE2:
73  break;
74  default:
75  return -1;
76  }
77 
78  switch (cell->handshake_type) {
79  case ONION_HANDSHAKE_TYPE_TAP:
80  if (cell->handshake_len != TAP_ONIONSKIN_CHALLENGE_LEN)
81  return -1;
82  break;
83  case ONION_HANDSHAKE_TYPE_FAST:
84  if (cell->handshake_len != CREATE_FAST_LEN)
85  return -1;
86  break;
87  case ONION_HANDSHAKE_TYPE_NTOR:
88  if (cell->handshake_len != NTOR_ONIONSKIN_LEN)
89  return -1;
90  break;
91  default:
92  if (! unknown_ok)
93  return -1;
94  }
95 
96  return 0;
97 }
98 
102 void
103 create_cell_init(create_cell_t *cell_out, uint8_t cell_type,
104  uint16_t handshake_type, uint16_t handshake_len,
105  const uint8_t *onionskin)
106 {
107  memset(cell_out, 0, sizeof(*cell_out));
108 
109  cell_out->cell_type = cell_type;
110  cell_out->handshake_type = handshake_type;
111  cell_out->handshake_len = handshake_len;
112  memcpy(cell_out->onionskin, onionskin, handshake_len);
113 }
114 
122 static int
123 parse_create2_payload(create_cell_t *cell_out, const uint8_t *p, size_t p_len)
124 {
125  uint16_t handshake_type, handshake_len;
126 
127  if (p_len < 4)
128  return -1;
129 
130  handshake_type = ntohs(get_uint16(p));
131  handshake_len = ntohs(get_uint16(p+2));
132 
133  if (handshake_len > CELL_PAYLOAD_SIZE - 4 || handshake_len > p_len - 4)
134  return -1;
135  if (handshake_type == ONION_HANDSHAKE_TYPE_FAST)
136  return -1;
137 
138  create_cell_init(cell_out, CELL_CREATE2, handshake_type, handshake_len,
139  p+4);
140  return 0;
141 }
142 
149 #define NTOR_CREATE_MAGIC "ntorNTORntorNTOR"
150 
154 int
155 create_cell_parse(create_cell_t *cell_out, const cell_t *cell_in)
156 {
157  switch (cell_in->command) {
158  case CELL_CREATE:
159  if (tor_memeq(cell_in->payload, NTOR_CREATE_MAGIC, 16)) {
160  create_cell_init(cell_out, CELL_CREATE, ONION_HANDSHAKE_TYPE_NTOR,
161  NTOR_ONIONSKIN_LEN, cell_in->payload+16);
162  } else {
163  create_cell_init(cell_out, CELL_CREATE, ONION_HANDSHAKE_TYPE_TAP,
164  TAP_ONIONSKIN_CHALLENGE_LEN, cell_in->payload);
165  }
166  break;
167  case CELL_CREATE_FAST:
168  create_cell_init(cell_out, CELL_CREATE_FAST, ONION_HANDSHAKE_TYPE_FAST,
169  CREATE_FAST_LEN, cell_in->payload);
170  break;
171  case CELL_CREATE2:
172  if (parse_create2_payload(cell_out, cell_in->payload,
173  CELL_PAYLOAD_SIZE) < 0)
174  return -1;
175  break;
176  default:
177  return -1;
178  }
179 
180  return check_create_cell(cell_out, 0);
181 }
182 
184 static int
186 {
187  switch (cell->cell_type) {
188  case CELL_CREATED:
189  if (cell->handshake_len != TAP_ONIONSKIN_REPLY_LEN &&
190  cell->handshake_len != NTOR_REPLY_LEN)
191  return -1;
192  break;
193  case CELL_CREATED_FAST:
194  if (cell->handshake_len != CREATED_FAST_LEN)
195  return -1;
196  break;
197  case CELL_CREATED2:
198  if (cell->handshake_len > RELAY_PAYLOAD_SIZE-2)
199  return -1;
200  break;
201  }
202 
203  return 0;
204 }
205 
208 int
209 created_cell_parse(created_cell_t *cell_out, const cell_t *cell_in)
210 {
211  memset(cell_out, 0, sizeof(*cell_out));
212 
213  switch (cell_in->command) {
214  case CELL_CREATED:
215  cell_out->cell_type = CELL_CREATED;
216  cell_out->handshake_len = TAP_ONIONSKIN_REPLY_LEN;
217  memcpy(cell_out->reply, cell_in->payload, TAP_ONIONSKIN_REPLY_LEN);
218  break;
219  case CELL_CREATED_FAST:
220  cell_out->cell_type = CELL_CREATED_FAST;
221  cell_out->handshake_len = CREATED_FAST_LEN;
222  memcpy(cell_out->reply, cell_in->payload, CREATED_FAST_LEN);
223  break;
224  case CELL_CREATED2:
225  {
226  const uint8_t *p = cell_in->payload;
227  cell_out->cell_type = CELL_CREATED2;
228  cell_out->handshake_len = ntohs(get_uint16(p));
229  if (cell_out->handshake_len > CELL_PAYLOAD_SIZE - 2)
230  return -1;
231  memcpy(cell_out->reply, p+2, cell_out->handshake_len);
232  break;
233  }
234  }
235 
236  return check_created_cell(cell_out);
237 }
238 
240 static int
242 {
243  if (tor_digest_is_zero((const char*)cell->node_id))
244  return -1;
245  /* We don't currently allow EXTEND2 cells without an IPv4 address */
246  if (tor_addr_family(&cell->orport_ipv4.addr) == AF_UNSPEC)
247  return -1;
248  if (cell->create_cell.cell_type == CELL_CREATE) {
249  if (cell->cell_type != RELAY_COMMAND_EXTEND)
250  return -1;
251  } else if (cell->create_cell.cell_type == CELL_CREATE2) {
252  if (cell->cell_type != RELAY_COMMAND_EXTEND2 &&
253  cell->cell_type != RELAY_COMMAND_EXTEND)
254  return -1;
255  } else {
256  /* In particular, no CREATE_FAST cells are allowed */
257  return -1;
258  }
259  if (cell->create_cell.handshake_type == ONION_HANDSHAKE_TYPE_FAST)
260  return -1;
261 
262  return check_create_cell(&cell->create_cell, 1);
263 }
264 
265 static int
266 extend_cell_from_extend1_cell_body(extend_cell_t *cell_out,
267  const extend1_cell_body_t *cell)
268 {
269  tor_assert(cell_out);
270  tor_assert(cell);
271  memset(cell_out, 0, sizeof(*cell_out));
272  tor_addr_make_unspec(&cell_out->orport_ipv4.addr);
273  tor_addr_make_unspec(&cell_out->orport_ipv6.addr);
274 
275  cell_out->cell_type = RELAY_COMMAND_EXTEND;
276  tor_addr_from_ipv4h(&cell_out->orport_ipv4.addr, cell->ipv4addr);
277  cell_out->orport_ipv4.port = cell->port;
278  if (tor_memeq(cell->onionskin, NTOR_CREATE_MAGIC, 16)) {
279  cell_out->create_cell.cell_type = CELL_CREATE2;
280  cell_out->create_cell.handshake_type = ONION_HANDSHAKE_TYPE_NTOR;
281  cell_out->create_cell.handshake_len = NTOR_ONIONSKIN_LEN;
282  memcpy(cell_out->create_cell.onionskin, cell->onionskin + 16,
283  NTOR_ONIONSKIN_LEN);
284  } else {
285  cell_out->create_cell.cell_type = CELL_CREATE;
286  cell_out->create_cell.handshake_type = ONION_HANDSHAKE_TYPE_TAP;
287  cell_out->create_cell.handshake_len = TAP_ONIONSKIN_CHALLENGE_LEN;
288  memcpy(cell_out->create_cell.onionskin, cell->onionskin,
289  TAP_ONIONSKIN_CHALLENGE_LEN);
290  }
291  memcpy(cell_out->node_id, cell->identity, DIGEST_LEN);
292  return 0;
293 }
294 
295 static int
296 create_cell_from_create2_cell_body(create_cell_t *cell_out,
297  const create2_cell_body_t *cell)
298 {
299  tor_assert(cell_out);
300  tor_assert(cell);
301  memset(cell_out, 0, sizeof(create_cell_t));
302  if (BUG(cell->handshake_len > sizeof(cell_out->onionskin))) {
303  /* This should be impossible because there just isn't enough room in the
304  * input cell to make the handshake_len this large and provide a
305  * handshake_data to match. */
306  return -1;
307  }
308 
309  cell_out->cell_type = CELL_CREATE2;
310  cell_out->handshake_type = cell->handshake_type;
311  cell_out->handshake_len = cell->handshake_len;
312  memcpy(cell_out->onionskin,
313  create2_cell_body_getconstarray_handshake_data(cell),
314  cell->handshake_len);
315  return 0;
316 }
317 
318 static int
319 extend_cell_from_extend2_cell_body(extend_cell_t *cell_out,
320  const extend2_cell_body_t *cell)
321 {
322  tor_assert(cell_out);
323  tor_assert(cell);
324  int found_ipv4 = 0, found_ipv6 = 0, found_rsa_id = 0, found_ed_id = 0;
325  memset(cell_out, 0, sizeof(*cell_out));
326  tor_addr_make_unspec(&cell_out->orport_ipv4.addr);
327  tor_addr_make_unspec(&cell_out->orport_ipv6.addr);
328  cell_out->cell_type = RELAY_COMMAND_EXTEND2;
329 
330  unsigned i;
331  for (i = 0; i < cell->n_spec; ++i) {
332  const link_specifier_t *ls = extend2_cell_body_getconst_ls(cell, i);
333  switch (ls->ls_type) {
334  case LS_IPV4:
335  if (found_ipv4)
336  continue;
337  found_ipv4 = 1;
338  tor_addr_from_ipv4h(&cell_out->orport_ipv4.addr, ls->un_ipv4_addr);
339  cell_out->orport_ipv4.port = ls->un_ipv4_port;
340  break;
341  case LS_IPV6:
342  if (found_ipv6)
343  continue;
344  found_ipv6 = 1;
345  tor_addr_from_ipv6_bytes(&cell_out->orport_ipv6.addr,
346  (const char *)ls->un_ipv6_addr);
347  cell_out->orport_ipv6.port = ls->un_ipv6_port;
348  break;
349  case LS_LEGACY_ID:
350  if (found_rsa_id)
351  return -1;
352  found_rsa_id = 1;
353  memcpy(cell_out->node_id, ls->un_legacy_id, 20);
354  break;
355  case LS_ED25519_ID:
356  if (found_ed_id)
357  return -1;
358  found_ed_id = 1;
359  memcpy(cell_out->ed_pubkey.pubkey, ls->un_ed25519_id, 32);
360  break;
361  default:
362  /* Ignore this, whatever it is. */
363  break;
364  }
365  }
366 
367  if (!found_rsa_id || !found_ipv4) /* These are mandatory */
368  return -1;
369 
370  return create_cell_from_create2_cell_body(&cell_out->create_cell,
371  cell->create2);
372 }
373 
377 int
378 extend_cell_parse(extend_cell_t *cell_out, const uint8_t command,
379  const uint8_t *payload, size_t payload_length)
380 {
381 
382  tor_assert(cell_out);
383  tor_assert(payload);
384 
385  if (payload_length > RELAY_PAYLOAD_SIZE)
386  return -1;
387 
388  switch (command) {
389  case RELAY_COMMAND_EXTEND:
390  {
391  extend1_cell_body_t *cell = NULL;
392  if (extend1_cell_body_parse(&cell, payload, payload_length)<0 ||
393  cell == NULL) {
394  if (cell)
395  extend1_cell_body_free(cell);
396  return -1;
397  }
398  int r = extend_cell_from_extend1_cell_body(cell_out, cell);
399  extend1_cell_body_free(cell);
400  if (r < 0)
401  return r;
402  }
403  break;
404  case RELAY_COMMAND_EXTEND2:
405  {
406  extend2_cell_body_t *cell = NULL;
407  if (extend2_cell_body_parse(&cell, payload, payload_length) < 0 ||
408  cell == NULL) {
409  if (cell)
410  extend2_cell_body_free(cell);
411  return -1;
412  }
413  int r = extend_cell_from_extend2_cell_body(cell_out, cell);
414  extend2_cell_body_free(cell);
415  if (r < 0)
416  return r;
417  }
418  break;
419  default:
420  return -1;
421  }
422 
423  return check_extend_cell(cell_out);
424 }
425 
427 static int
429 {
430  tor_assert(cell);
431  if (cell->created_cell.cell_type == CELL_CREATED) {
432  if (cell->cell_type != RELAY_COMMAND_EXTENDED)
433  return -1;
434  } else if (cell->created_cell.cell_type == CELL_CREATED2) {
435  if (cell->cell_type != RELAY_COMMAND_EXTENDED2)
436  return -1;
437  } else {
438  return -1;
439  }
440 
441  return check_created_cell(&cell->created_cell);
442 }
443 
447 int
449  const uint8_t command, const uint8_t *payload,
450  size_t payload_len)
451 {
452  tor_assert(cell_out);
453  tor_assert(payload);
454 
455  memset(cell_out, 0, sizeof(*cell_out));
456  if (payload_len > RELAY_PAYLOAD_SIZE)
457  return -1;
458 
459  switch (command) {
460  case RELAY_COMMAND_EXTENDED:
461  if (payload_len != TAP_ONIONSKIN_REPLY_LEN)
462  return -1;
463  cell_out->cell_type = RELAY_COMMAND_EXTENDED;
464  cell_out->created_cell.cell_type = CELL_CREATED;
465  cell_out->created_cell.handshake_len = TAP_ONIONSKIN_REPLY_LEN;
466  memcpy(cell_out->created_cell.reply, payload, TAP_ONIONSKIN_REPLY_LEN);
467  break;
468  case RELAY_COMMAND_EXTENDED2:
469  {
470  cell_out->cell_type = RELAY_COMMAND_EXTENDED2;
471  cell_out->created_cell.cell_type = CELL_CREATED2;
472  cell_out->created_cell.handshake_len = ntohs(get_uint16(payload));
473  if (cell_out->created_cell.handshake_len > RELAY_PAYLOAD_SIZE - 2 ||
474  cell_out->created_cell.handshake_len > payload_len - 2)
475  return -1;
476  memcpy(cell_out->created_cell.reply, payload+2,
477  cell_out->created_cell.handshake_len);
478  }
479  break;
480  default:
481  return -1;
482  }
483 
484  return check_extended_cell(cell_out);
485 }
486 
490 static int
491 create_cell_format_impl(cell_t *cell_out, const create_cell_t *cell_in,
492  int relayed)
493 {
494  uint8_t *p;
495  size_t space;
496  if (check_create_cell(cell_in, relayed) < 0)
497  return -1;
498 
499  memset(cell_out->payload, 0, sizeof(cell_out->payload));
500  cell_out->command = cell_in->cell_type;
501 
502  p = cell_out->payload;
503  space = sizeof(cell_out->payload);
504 
505  switch (cell_in->cell_type) {
506  case CELL_CREATE:
507  if (cell_in->handshake_type == ONION_HANDSHAKE_TYPE_NTOR) {
508  memcpy(p, NTOR_CREATE_MAGIC, 16);
509  p += 16;
510  space -= 16;
511  }
512  /* Fall through */
513  case CELL_CREATE_FAST:
514  tor_assert(cell_in->handshake_len <= space);
515  memcpy(p, cell_in->onionskin, cell_in->handshake_len);
516  break;
517  case CELL_CREATE2:
518  tor_assert(cell_in->handshake_len <= sizeof(cell_out->payload)-4);
519  set_uint16(cell_out->payload, htons(cell_in->handshake_type));
520  set_uint16(cell_out->payload+2, htons(cell_in->handshake_len));
521  memcpy(cell_out->payload + 4, cell_in->onionskin, cell_in->handshake_len);
522  break;
523  default:
524  return -1;
525  }
526 
527  return 0;
528 }
529 
530 int
531 create_cell_format(cell_t *cell_out, const create_cell_t *cell_in)
532 {
533  return create_cell_format_impl(cell_out, cell_in, 0);
534 }
535 
536 int
537 create_cell_format_relayed(cell_t *cell_out, const create_cell_t *cell_in)
538 {
539  return create_cell_format_impl(cell_out, cell_in, 1);
540 }
541 
545 int
546 created_cell_format(cell_t *cell_out, const created_cell_t *cell_in)
547 {
548  if (check_created_cell(cell_in) < 0)
549  return -1;
550 
551  memset(cell_out->payload, 0, sizeof(cell_out->payload));
552  cell_out->command = cell_in->cell_type;
553 
554  switch (cell_in->cell_type) {
555  case CELL_CREATED:
556  case CELL_CREATED_FAST:
557  tor_assert(cell_in->handshake_len <= sizeof(cell_out->payload));
558  memcpy(cell_out->payload, cell_in->reply, cell_in->handshake_len);
559  break;
560  case CELL_CREATED2:
561  tor_assert(cell_in->handshake_len <= sizeof(cell_out->payload)-2);
562  set_uint16(cell_out->payload, htons(cell_in->handshake_len));
563  memcpy(cell_out->payload + 2, cell_in->reply, cell_in->handshake_len);
564  break;
565  default:
566  return -1;
567  }
568  return 0;
569 }
570 
573 static int
575  const or_options_t *options)
576 {
577  if (options->ExtendByEd25519ID != -1)
578  return options->ExtendByEd25519ID; /* The user has an opinion. */
579 
580  return (int) networkstatus_get_param(ns, "ExtendByEd25519ID",
581  0 /* default */,
582  0 /* min */,
583  1 /*max*/);
584 }
585 
590 int
591 extend_cell_format(uint8_t *command_out, uint16_t *len_out,
592  uint8_t *payload_out, const extend_cell_t *cell_in)
593 {
594  uint8_t *p;
595  if (check_extend_cell(cell_in) < 0)
596  return -1;
597 
598  p = payload_out;
599 
600  memset(p, 0, RELAY_PAYLOAD_SIZE);
601 
602  switch (cell_in->cell_type) {
603  case RELAY_COMMAND_EXTEND:
604  {
605  *command_out = RELAY_COMMAND_EXTEND;
606  *len_out = 6 + TAP_ONIONSKIN_CHALLENGE_LEN + DIGEST_LEN;
607  set_uint32(p, tor_addr_to_ipv4n(&cell_in->orport_ipv4.addr));
608  set_uint16(p+4, htons(cell_in->orport_ipv4.port));
609  if (cell_in->create_cell.handshake_type == ONION_HANDSHAKE_TYPE_NTOR) {
610  memcpy(p+6, NTOR_CREATE_MAGIC, 16);
611  memcpy(p+22, cell_in->create_cell.onionskin, NTOR_ONIONSKIN_LEN);
612  } else {
613  memcpy(p+6, cell_in->create_cell.onionskin,
614  TAP_ONIONSKIN_CHALLENGE_LEN);
615  }
616  memcpy(p+6+TAP_ONIONSKIN_CHALLENGE_LEN, cell_in->node_id, DIGEST_LEN);
617  }
618  break;
619  case RELAY_COMMAND_EXTEND2:
620  {
621  uint8_t n_specifiers = 2;
622  *command_out = RELAY_COMMAND_EXTEND2;
623  extend2_cell_body_t *cell = extend2_cell_body_new();
624  link_specifier_t *ls;
625  {
626  /* IPv4 specifier first. */
627  ls = link_specifier_new();
628  extend2_cell_body_add_ls(cell, ls);
629  ls->ls_type = LS_IPV4;
630  ls->ls_len = 6;
631  ls->un_ipv4_addr = tor_addr_to_ipv4h(&cell_in->orport_ipv4.addr);
632  ls->un_ipv4_port = cell_in->orport_ipv4.port;
633  }
634  {
635  /* Then RSA id */
636  ls = link_specifier_new();
637  extend2_cell_body_add_ls(cell, ls);
638  ls->ls_type = LS_LEGACY_ID;
639  ls->ls_len = DIGEST_LEN;
640  memcpy(ls->un_legacy_id, cell_in->node_id, DIGEST_LEN);
641  }
642  if (should_include_ed25519_id_extend_cells(NULL, get_options()) &&
644  /* Then, maybe, the ed25519 id! */
645  ++n_specifiers;
646  ls = link_specifier_new();
647  extend2_cell_body_add_ls(cell, ls);
648  ls->ls_type = LS_ED25519_ID;
649  ls->ls_len = 32;
650  memcpy(ls->un_ed25519_id, cell_in->ed_pubkey.pubkey, 32);
651  }
652  cell->n_spec = n_specifiers;
653 
654  /* Now, the handshake */
655  cell->create2 = create2_cell_body_new();
656  cell->create2->handshake_type = cell_in->create_cell.handshake_type;
657  cell->create2->handshake_len = cell_in->create_cell.handshake_len;
658  create2_cell_body_setlen_handshake_data(cell->create2,
659  cell_in->create_cell.handshake_len);
660  memcpy(create2_cell_body_getarray_handshake_data(cell->create2),
661  cell_in->create_cell.onionskin,
662  cell_in->create_cell.handshake_len);
663 
664  ssize_t len_encoded = extend2_cell_body_encode(
665  payload_out, RELAY_PAYLOAD_SIZE,
666  cell);
667  extend2_cell_body_free(cell);
668  if (len_encoded < 0 || len_encoded > UINT16_MAX)
669  return -1;
670  *len_out = (uint16_t) len_encoded;
671  }
672  break;
673  default:
674  return -1;
675  }
676 
677  return 0;
678 }
679 
684 int
685 extended_cell_format(uint8_t *command_out, uint16_t *len_out,
686  uint8_t *payload_out, const extended_cell_t *cell_in)
687 {
688  uint8_t *p;
689  if (check_extended_cell(cell_in) < 0)
690  return -1;
691 
692  p = payload_out;
693  memset(p, 0, RELAY_PAYLOAD_SIZE);
694 
695  switch (cell_in->cell_type) {
696  case RELAY_COMMAND_EXTENDED:
697  {
698  *command_out = RELAY_COMMAND_EXTENDED;
699  *len_out = TAP_ONIONSKIN_REPLY_LEN;
700  memcpy(payload_out, cell_in->created_cell.reply,
701  TAP_ONIONSKIN_REPLY_LEN);
702  }
703  break;
704  case RELAY_COMMAND_EXTENDED2:
705  {
706  *command_out = RELAY_COMMAND_EXTENDED2;
707  *len_out = 2 + cell_in->created_cell.handshake_len;
708  set_uint16(payload_out, htons(cell_in->created_cell.handshake_len));
710  return -1;
711  memcpy(payload_out+2, cell_in->created_cell.reply,
712  cell_in->created_cell.handshake_len);
713  }
714  break;
715  default:
716  return -1;
717  }
718 
719  return 0;
720 }
#define RELAY_PAYLOAD_SIZE
Definition: or.h:605
uint8_t onionskin[CELL_PAYLOAD_SIZE - 4]
Definition: onion.h:32
static int check_extend_cell(const extend_cell_t *cell)
Definition: onion.c:241
uint8_t payload[CELL_PAYLOAD_SIZE]
Definition: cell_st.h:16
int extend_cell_format(uint8_t *command_out, uint16_t *len_out, uint8_t *payload_out, const extend_cell_t *cell_in)
Definition: onion.c:591
uint8_t cell_type
Definition: onion.h:38
uint16_t handshake_len
Definition: onion.h:30
void tor_addr_make_unspec(tor_addr_t *a)
Definition: address.c:225
void create_cell_init(create_cell_t *cell_out, uint8_t cell_type, uint16_t handshake_type, uint16_t handshake_len, const uint8_t *onionskin)
Definition: onion.c:103
static void set_uint16(void *cp, uint16_t v)
Definition: bytes.h:73
Definition: cell_st.h:12
static uint32_t tor_addr_to_ipv4n(const tor_addr_t *a)
Definition: address.h:145
static int check_create_cell(const create_cell_t *cell, int unknown_ok)
Definition: onion.c:60
Header file for onion_tap.c.
#define NTOR_CREATE_MAGIC
Definition: onion.c:149
Header file for config.c.
uint8_t cell_type
Definition: onion.h:67
static uint32_t tor_addr_to_ipv4h(const tor_addr_t *a)
Definition: address.h:152
Header file for onion.c.
int extend_cell_parse(extend_cell_t *cell_out, const uint8_t command, const uint8_t *payload, size_t payload_length)
Definition: onion.c:378
created_cell_t created_cell
Definition: onion.h:69
struct ed25519_public_key_t ed_pubkey
Definition: onion.h:57
static void set_uint32(void *cp, uint32_t v)
Definition: bytes.h:82
static int create_cell_format_impl(cell_t *cell_out, const create_cell_t *cell_in, int relayed)
Definition: onion.c:491
static int should_include_ed25519_id_extend_cells(const networkstatus_t *ns, const or_options_t *options)
Definition: onion.c:574
tor_assert(buffer)
#define tor_addr_from_ipv4h(dest, v4addr)
Definition: address.h:287
int tor_memeq(const void *a, const void *b, size_t sz)
Definition: di_ops.c:107
#define DIGEST_LEN
Definition: digest_sizes.h:20
void tor_addr_from_ipv6_bytes(tor_addr_t *dest, const char *ipv6_bytes)
Definition: address.c:884
int ed25519_public_key_is_zero(const ed25519_public_key_t *pubkey)
Master header file for Tor-specific functionality.
int created_cell_parse(created_cell_t *cell_out, const cell_t *cell_in)
Definition: onion.c:209
uint8_t reply[CELL_PAYLOAD_SIZE - 2]
Definition: onion.h:42
Header file for onion_fast.c.
uint8_t cell_type
Definition: onion.h:26
static int check_created_cell(const created_cell_t *cell)
Definition: onion.c:185
static uint16_t get_uint16(const void *cp)
Definition: bytes.h:37
static int check_extended_cell(const extended_cell_t *cell)
Definition: onion.c:428
int tor_digest_is_zero(const char *digest)
Definition: util_string.c:96
uint8_t cell_type
Definition: onion.h:48
#define CELL_PAYLOAD_SIZE
Definition: or.h:576
int created_cell_format(cell_t *cell_out, const created_cell_t *cell_in)
Definition: onion.c:546
uint16_t handshake_type
Definition: onion.h:28
int extended_cell_format(uint8_t *command_out, uint16_t *len_out, uint8_t *payload_out, const extended_cell_t *cell_in)
Definition: onion.c:685
uint8_t node_id[DIGEST_LEN]
Definition: onion.h:55
tor_addr_port_t orport_ipv4
Definition: onion.h:50
uint8_t command
Definition: cell_st.h:14
uint16_t handshake_len
Definition: onion.h:40
int extended_cell_parse(extended_cell_t *cell_out, const uint8_t command, const uint8_t *payload, size_t payload_len)
Definition: onion.c:448
int create_cell_parse(create_cell_t *cell_out, const cell_t *cell_in)
Definition: onion.c:155
static int parse_create2_payload(create_cell_t *cell_out, const uint8_t *p, size_t p_len)
Definition: onion.c:123
Header file for networkstatus.c.
static sa_family_t tor_addr_family(const tor_addr_t *a)
Definition: address.h:179
create_cell_t create_cell
Definition: onion.h:61
tor_addr_port_t orport_ipv6
Definition: onion.h:53
Header file for onion_crypto.c.