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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
// Copyright (c) 2019-2026, Argenox Technologies LLC
// All rights reserved.
//
// SPDX-License-Identifier: GPL-2.0-only OR LicenseRef-Argenox-Commercial-License
//
// This file is part of the NoxTLS Library.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation; version 2 of the License.
//
// Alternatively, this file may be used under the terms of a commercial
// license from Argenox Technologies LLC.
//
// See `noxtls/LICENSE` and `noxtls/LICENSE.md` in this repository for full details.
// CONTACT: info@argenox.com
//! ClientHello construction paths (plain, PSK, and ticket-based variants).
use super::*;
impl Connection {
/// Builds and records a synthetic client hello message using caller random bytes.
///
/// # Arguments
/// * `random`: 32-byte ClientHello random value.
///
/// # Returns
/// Encoded ClientHello handshake message bytes.
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
fn noxtls_client_hello_offer_suites(&self) -> Vec<CipherSuite> {
if let Some(custom) = self.tls13_client_cipher_suites.as_ref() {
return custom.clone();
}
noxtls_default_client_cipher_suites(self.version)
}
fn noxtls_record_client_hello_offer(&mut self) {
self.client_offered_cipher_suites = self.noxtls_client_hello_offer_suites();
self.client_offered_tls_fallback_scsv = false;
}
fn noxtls_sync_client_hello_offer_from_wire(&mut self, msg: &[u8]) -> Result<()> {
let info = Self::noxtls_parse_client_hello_info(msg)?;
self.client_offered_cipher_suites = info.offered_cipher_suites;
self.client_offered_tls_fallback_scsv = info.offered_tls_fallback_scsv;
Ok(())
}
/// Re-parses a sent ClientHello to refresh offered cipher suites and FALLBACK_SCSV state.
///
/// Used when tests mutate ClientHello bytes after [`Connection::noxtls_send_client_hello`].
pub fn noxtls_apply_client_hello_offer_from_wire(&mut self, msg: &[u8]) -> Result<()> {
if self.state != HandshakeState::ClientHelloSent {
return Err(Error::StateError(
"client hello offer can only be refreshed after client hello is sent",
));
}
self.noxtls_sync_client_hello_offer_from_wire(msg)
}
fn noxtls_tls12_client_renegotiation_info_for_offer(&self) -> Option<&[u8]> {
if self.version == TlsVersion::Tls12 && self.tls12_secure_renegotiation_enabled {
if self.tls12_secure_renegotiation_renegotiating {
Some(
self.tls12_secure_renegotiation_client_verify_data
.as_slice(),
)
} else {
Some(&[])
}
} else {
None
}
}
pub fn noxtls_send_client_hello(&mut self, random: &[u8]) -> Result<Vec<u8>> {
if self.state != HandshakeState::Idle {
return Err(Error::StateError("client hello can only be sent from idle"));
}
if random.len() != 32 {
return Err(Error::InvalidLength("client hello random must be 32 bytes"));
}
if self.version == TlsVersion::Tls12 {
let mut client_random = [0_u8; 32];
client_random.copy_from_slice(random);
self.tls12_client_random = Some(client_random);
self.tls12_server_random = None;
self.tls12_pre_master_secret = None;
self.tls12_rsa_encrypted_pre_master_secret = None;
self.tls12_dhe_prime = None;
self.tls12_dhe_server_public_key = None;
self.tls12_dhe_client_public_key = None;
self.tls12_master_secret = None;
self.tls12_extended_master_secret_session_hash = None;
if !self.tls12_secure_renegotiation_renegotiating {
self.tls12_secure_renegotiation_client_verify_data.clear();
self.tls12_secure_renegotiation_server_verify_data.clear();
self.tls12_secure_renegotiation_negotiated = false;
}
self.tls12_secure_renegotiation_offered = self.tls12_secure_renegotiation_enabled;
}
self.noxtls_reset_transcript_for_new_handshake();
self.noxtls_validate_tls13_hrr_retry_group_support()?;
self.noxtls_reset_tls13_certificate_auth_state();
self.noxtls_record_client_hello_offer();
let offered_suites = self.client_offered_cipher_suites.clone();
let key_shares = self.noxtls_prepare_client_key_share(random)?;
let client_hello_body = noxtls_encode_client_hello_body(
self.version,
random,
&offered_suites,
&key_shares,
self.tls13_client_server_name.as_deref(),
&self.tls13_client_alpn_protocols,
self.tls13_request_ocsp_stapling,
self.tls13_client_offer_mldsa_signature,
false,
None,
self.tls13_client_raw_public_keys_enabled,
self.noxtls_tls12_session_id.as_deref(),
self.noxtls_tls12_client_renegotiation_info_for_offer(),
)?;
let msg = noxtls_encode_handshake_message(HANDSHAKE_CLIENT_HELLO, &client_hello_body);
noxtls_tls13_debug_log_bytes("tls13.transcript.client_hello", &msg);
if let Ok(Some(wire_x25519)) = noxtls_extract_tls13_client_hello_x25519_key_share(&msg) {
noxtls_tls13_debug_log_bytes("tls13.client_key_share.x25519_wire", &wire_x25519);
}
self.noxtls_sync_client_hello_offer_from_wire(&msg)?;
self.noxtls_append_transcript(&msg);
self.state = HandshakeState::ClientHelloSent;
self.tls13_early_data_offered_in_client_hello = false;
self.tls13_early_data_accepted_in_encrypted_extensions = false;
self.tls13_end_of_early_data_seen = false;
Ok(msg)
}
pub fn noxtls_start_tls12_secure_renegotiation(&mut self, random: &[u8]) -> Result<Vec<u8>> {
if self.version != TlsVersion::Tls12 {
return Err(Error::StateError(
"secure renegotiation is only modeled for TLS 1.2",
));
}
if !self.tls12_secure_renegotiation_enabled || !self.tls12_secure_renegotiation_negotiated {
return Err(Error::StateError(
"initial tls12 secure renegotiation handshake is not established",
));
}
if self.state != HandshakeState::Finished {
return Err(Error::StateError(
"tls12 secure renegotiation can only start from finished state",
));
}
if self
.tls12_secure_renegotiation_client_verify_data
.is_empty()
{
return Err(Error::StateError(
"tls12 secure renegotiation requires previous client Finished verify_data",
));
}
self.tls12_secure_renegotiation_renegotiating = true;
self.state = HandshakeState::Idle;
self.noxtls_send_client_hello(random)
}
/// Builds and records a TLS 1.3 ClientHello carrying one PSK identity+binder.
///
/// # Arguments
/// * `random`: 32-byte ClientHello random value.
/// * `identity`: PSK identity bytes from ticket cache.
/// * `obfuscated_ticket_age`: Encoded ticket age value for the identity.
/// * `psk`: PSK bytes used to compute binder authentication.
///
/// # Returns
/// Encoded ClientHello handshake message bytes with populated binder.
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
pub fn noxtls_send_client_hello_with_psk(
&mut self,
random: &[u8],
identity: &[u8],
obfuscated_ticket_age: u32,
psk: &[u8],
) -> Result<Vec<u8>> {
self.noxtls_send_client_hello_with_psk_internal(
random,
identity,
obfuscated_ticket_age,
psk,
false,
)
}
/// Builds and records a TLS 1.3 PSK ClientHello that offers early_data.
///
/// This is the external-PSK counterpart to resumption-ticket ClientHello builders whose
/// `max_early_data_size` automatically controls early_data offering.
pub fn noxtls_send_client_hello_with_psk_and_early_data(
&mut self,
random: &[u8],
identity: &[u8],
obfuscated_ticket_age: u32,
psk: &[u8],
) -> Result<Vec<u8>> {
self.noxtls_send_client_hello_with_psk_internal(
random,
identity,
obfuscated_ticket_age,
psk,
true,
)
}
/// Builds and records a TLS 1.3 ClientHello carrying one PSK identity+binder.
///
/// # Arguments
/// * `random`: 32-byte ClientHello random value.
/// * `identity`: PSK identity bytes from ticket cache.
/// * `obfuscated_ticket_age`: Encoded ticket age value for the identity.
/// * `psk`: PSK bytes used to compute binder authentication.
/// * `offer_early_data`: `true` emits the empty early_data extension.
///
/// # Returns
/// Encoded ClientHello handshake message bytes with populated binder.
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
fn noxtls_send_client_hello_with_psk_internal(
&mut self,
random: &[u8],
identity: &[u8],
obfuscated_ticket_age: u32,
psk: &[u8],
offer_early_data: bool,
) -> Result<Vec<u8>> {
if !self.version.uses_tls13_handshake_semantics() {
return Err(Error::StateError(
"psk client hello is currently only modeled for TLS 1.3",
));
}
if self.state != HandshakeState::Idle {
return Err(Error::StateError("client hello can only be sent from idle"));
}
if random.len() != 32 {
return Err(Error::InvalidLength("client hello random must be 32 bytes"));
}
if identity.is_empty() {
return Err(Error::InvalidLength("psk identity must not be empty"));
}
if psk.is_empty() {
return Err(Error::InvalidLength("psk must not be empty"));
}
self.noxtls_reset_transcript_for_new_handshake();
self.noxtls_validate_tls13_hrr_retry_group_support()?;
self.noxtls_reset_tls13_certificate_auth_state();
let binder_len = self.noxtls_negotiated_hash_algorithm().output_len();
let placeholder = vec![0_u8; binder_len];
let placeholder_offer = PskClientOffer {
identities: vec![PskIdentityOffer {
identity,
obfuscated_ticket_age,
}],
binders: vec![placeholder.as_slice()],
};
let offered_suites = {
self.noxtls_record_client_hello_offer();
self.client_offered_cipher_suites.clone()
};
let key_shares = self.noxtls_prepare_client_key_share(random)?;
let placeholder_body = noxtls_encode_client_hello_body(
self.version,
random,
&offered_suites,
&key_shares,
self.tls13_client_server_name.as_deref(),
&self.tls13_client_alpn_protocols,
self.tls13_request_ocsp_stapling,
self.tls13_client_offer_mldsa_signature,
offer_early_data,
Some(&placeholder_offer),
self.tls13_client_raw_public_keys_enabled,
self.noxtls_tls12_session_id.as_deref(),
self.noxtls_tls12_client_renegotiation_info_for_offer(),
)?;
let placeholder_msg =
noxtls_encode_handshake_message(HANDSHAKE_CLIENT_HELLO, &placeholder_body);
let binder = self.noxtls_compute_tls13_psk_binder(psk, &placeholder_msg)?;
let final_offer = PskClientOffer {
identities: vec![PskIdentityOffer {
identity,
obfuscated_ticket_age,
}],
binders: vec![binder.as_slice()],
};
let final_body = noxtls_encode_client_hello_body(
self.version,
random,
&offered_suites,
&key_shares,
self.tls13_client_server_name.as_deref(),
&self.tls13_client_alpn_protocols,
self.tls13_request_ocsp_stapling,
self.tls13_client_offer_mldsa_signature,
offer_early_data,
Some(&final_offer),
self.tls13_client_raw_public_keys_enabled,
self.noxtls_tls12_session_id.as_deref(),
self.noxtls_tls12_client_renegotiation_info_for_offer(),
)?;
let msg = noxtls_encode_handshake_message(HANDSHAKE_CLIENT_HELLO, &final_body);
self.noxtls_append_transcript(&msg);
self.state = HandshakeState::ClientHelloSent;
self.tls13_early_data_offered_in_client_hello = offer_early_data;
self.tls13_early_data_accepted_in_encrypted_extensions = false;
self.tls13_end_of_early_data_seen = false;
Ok(msg)
}
/// Builds and records a TLS 1.3 ClientHello offering multiple resumption tickets.
///
/// # Arguments
/// * `random`: 32-byte ClientHello random value.
/// * `tickets`: Ordered resumption tickets to advertise in pre_shared_key.
///
/// # Returns
/// Encoded ClientHello handshake bytes carrying multiple PSK identities and binders.
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
pub fn noxtls_send_client_hello_with_resumption_tickets(
&mut self,
random: &[u8],
tickets: &[ResumptionTicket],
) -> Result<Vec<u8>> {
let mut obfuscated_ages = Vec::with_capacity(tickets.len());
for ticket in tickets {
obfuscated_ages.push(ticket.obfuscated_ticket_age);
}
self.noxtls_send_client_hello_with_resumption_tickets_with_ages(
random,
tickets,
&obfuscated_ages,
)
}
/// Builds and records a TLS 1.3 ClientHello offering multiple resumption tickets.
///
/// # Arguments
/// * `random`: 32-byte ClientHello random value.
/// * `tickets`: Ordered resumption tickets to advertise in pre_shared_key.
/// * `current_time_ms`: Client-local timestamp used for obfuscated ticket age values.
///
/// # Returns
/// Encoded ClientHello handshake bytes carrying multiple PSK identities and binders.
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
pub fn noxtls_send_client_hello_with_resumption_tickets_at(
&mut self,
random: &[u8],
tickets: &[ResumptionTicket],
current_time_ms: u64,
) -> Result<Vec<u8>> {
if !self.version.uses_tls13_handshake_semantics() {
return Err(Error::StateError(
"psk client hello is currently only modeled for TLS 1.3",
));
}
if self.state != HandshakeState::Idle {
return Err(Error::StateError("client hello can only be sent from idle"));
}
if random.len() != 32 {
return Err(Error::InvalidLength("client hello random must be 32 bytes"));
}
if tickets.is_empty() {
return Err(Error::InvalidLength("ticket list must not be empty"));
}
let mut obfuscated_ages = Vec::with_capacity(tickets.len());
for ticket in tickets {
let elapsed_ms = current_time_ms.saturating_sub(ticket.issued_at_ms);
let elapsed_u32 = elapsed_ms.min(u64::from(u32::MAX)) as u32;
obfuscated_ages.push(ticket.age_add.wrapping_add(elapsed_u32));
}
self.noxtls_send_client_hello_with_resumption_tickets_with_ages(
random,
tickets,
&obfuscated_ages,
)
}
/// Builds multi-ticket ClientHello using caller-selected obfuscated ticket ages.
///
/// # Arguments
///
/// * `self` — `&mut self`.
/// * `random` — `random: &[u8]`.
/// * `tickets` — `tickets: &[ResumptionTicket]`.
/// * `obfuscated_ages` — `obfuscated_ages: &[u32]`.
///
/// # Returns
///
/// On success, the `Ok` payload described by the return type; see the function body for the concrete value.
///
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
fn noxtls_send_client_hello_with_resumption_tickets_with_ages(
&mut self,
random: &[u8],
tickets: &[ResumptionTicket],
obfuscated_ages: &[u32],
) -> Result<Vec<u8>> {
self.noxtls_reset_transcript_for_new_handshake();
self.noxtls_validate_tls13_hrr_retry_group_support()?;
self.noxtls_reset_tls13_certificate_auth_state();
let hash_len = self.noxtls_negotiated_hash_algorithm().output_len();
let mut psk_identities = Vec::with_capacity(tickets.len());
let mut psks = Vec::with_capacity(tickets.len());
for (ticket, obfuscated_age) in tickets.iter().zip(obfuscated_ages.iter().copied()) {
psk_identities.push(PskIdentityOffer {
identity: ticket.identity.as_slice(),
obfuscated_ticket_age: obfuscated_age,
});
psks.push(self.noxtls_derive_tls13_resumption_psk(&ticket.ticket_nonce)?);
}
let zero_binders: Vec<Vec<u8>> = (0..tickets.len()).map(|_| vec![0_u8; hash_len]).collect();
let zero_binder_refs: Vec<&[u8]> = zero_binders.iter().map(Vec::as_slice).collect();
let placeholder_offer = PskClientOffer {
identities: psk_identities,
binders: zero_binder_refs,
};
let offered_suites = {
self.noxtls_record_client_hello_offer();
self.client_offered_cipher_suites.clone()
};
let key_shares = self.noxtls_prepare_client_key_share(random)?;
let placeholder_body = noxtls_encode_client_hello_body(
self.version,
random,
&offered_suites,
&key_shares,
self.tls13_client_server_name.as_deref(),
&self.tls13_client_alpn_protocols,
self.tls13_request_ocsp_stapling,
self.tls13_client_offer_mldsa_signature,
tickets.iter().any(|ticket| ticket.max_early_data_size > 0),
Some(&placeholder_offer),
self.tls13_client_raw_public_keys_enabled,
self.noxtls_tls12_session_id.as_deref(),
self.noxtls_tls12_client_renegotiation_info_for_offer(),
)?;
let placeholder_msg =
noxtls_encode_handshake_message(HANDSHAKE_CLIENT_HELLO, &placeholder_body);
let mut binders = Vec::with_capacity(psks.len());
for psk in &psks {
binders.push(self.noxtls_compute_tls13_psk_binder(psk, &placeholder_msg)?);
}
let binder_refs: Vec<&[u8]> = binders.iter().map(Vec::as_slice).collect();
let final_offer = PskClientOffer {
identities: placeholder_offer.identities,
binders: binder_refs,
};
let final_body = noxtls_encode_client_hello_body(
self.version,
random,
&offered_suites,
&key_shares,
self.tls13_client_server_name.as_deref(),
&self.tls13_client_alpn_protocols,
self.tls13_request_ocsp_stapling,
self.tls13_client_offer_mldsa_signature,
tickets.iter().any(|ticket| ticket.max_early_data_size > 0),
Some(&final_offer),
self.tls13_client_raw_public_keys_enabled,
self.noxtls_tls12_session_id.as_deref(),
self.noxtls_tls12_client_renegotiation_info_for_offer(),
)?;
let msg = noxtls_encode_handshake_message(HANDSHAKE_CLIENT_HELLO, &final_body);
self.noxtls_append_transcript(&msg);
self.state = HandshakeState::ClientHelloSent;
self.tls13_early_data_offered_in_client_hello =
tickets.iter().any(|ticket| ticket.max_early_data_size > 0);
self.tls13_early_data_accepted_in_encrypted_extensions = false;
self.tls13_end_of_early_data_seen = false;
Ok(msg)
}
/// Builds and records a TLS 1.3 ClientHello from a locally-issued resumption ticket.
///
/// # Arguments
/// * `random`: 32-byte ClientHello random value.
/// * `ticket`: Resumption ticket metadata used to derive identity and binder.
///
/// # Returns
/// Encoded ClientHello handshake bytes carrying a pre_shared_key offer.
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
pub fn noxtls_send_client_hello_with_resumption_ticket(
&mut self,
random: &[u8],
ticket: &ResumptionTicket,
) -> Result<Vec<u8>> {
let psk = self.noxtls_derive_tls13_resumption_psk(&ticket.ticket_nonce)?;
self.noxtls_send_client_hello_with_psk_internal(
random,
&ticket.identity,
ticket.obfuscated_ticket_age,
&psk,
ticket.max_early_data_size > 0,
)
}
/// Builds and records a TLS 1.3 ClientHello from a resumption ticket using current age.
///
/// # Arguments
/// * `random`: 32-byte ClientHello random value.
/// * `ticket`: Resumption ticket metadata used to derive identity and binder.
/// * `current_time_ms`: Client-local timestamp used for obfuscated ticket age.
///
/// # Returns
/// Encoded ClientHello handshake bytes carrying a pre_shared_key offer.
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
pub fn noxtls_send_client_hello_with_resumption_ticket_at(
&mut self,
random: &[u8],
ticket: &ResumptionTicket,
current_time_ms: u64,
) -> Result<Vec<u8>> {
let psk = self.noxtls_derive_tls13_resumption_psk(&ticket.ticket_nonce)?;
let elapsed_ms = current_time_ms.saturating_sub(ticket.issued_at_ms);
let elapsed_u32 = elapsed_ms.min(u64::from(u32::MAX)) as u32;
let obfuscated_age = ticket.age_add.wrapping_add(elapsed_u32);
self.noxtls_send_client_hello_with_psk_internal(
random,
&ticket.identity,
obfuscated_age,
&psk,
ticket.max_early_data_size > 0,
)
}
/// Builds and records a client hello with randomness sourced from HMAC-DRBG.
///
/// # Arguments
/// * `drbg`: DRBG instance used to generate ClientHello random bytes.
///
/// # Returns
/// Encoded ClientHello handshake message bytes.
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
pub fn noxtls_send_client_hello_auto(&mut self, drbg: &mut HmacDrbgSha256) -> Result<Vec<u8>> {
let random = drbg.generate(32, b"client_hello_random")?;
self.noxtls_send_client_hello(&random)
}
/// Builds and records a TLS 1.3 PSK ClientHello with DRBG-generated random bytes.
///
/// # Arguments
/// * `drbg`: DRBG instance used to generate ClientHello random bytes.
/// * `identity`: PSK identity bytes from ticket cache.
/// * `obfuscated_ticket_age`: Encoded ticket age value for the identity.
/// * `psk`: PSK bytes used to compute binder authentication.
///
/// # Returns
/// Encoded ClientHello handshake message bytes with populated binder.
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
pub fn noxtls_send_client_hello_with_psk_auto(
&mut self,
drbg: &mut HmacDrbgSha256,
identity: &[u8],
obfuscated_ticket_age: u32,
psk: &[u8],
) -> Result<Vec<u8>> {
let random = drbg.generate(32, b"client_hello_random")?;
self.noxtls_send_client_hello_with_psk(&random, identity, obfuscated_ticket_age, psk)
}
/// Builds and records a TLS 1.3 ClientHello from one ticket with DRBG random bytes.
///
/// # Arguments
/// * `drbg`: DRBG instance used to generate ClientHello random bytes.
/// * `ticket`: Resumption ticket metadata used to derive identity and binder.
///
/// # Returns
/// Encoded ClientHello handshake bytes carrying one pre_shared_key offer.
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
pub fn noxtls_send_client_hello_with_resumption_ticket_auto(
&mut self,
drbg: &mut HmacDrbgSha256,
ticket: &ResumptionTicket,
) -> Result<Vec<u8>> {
let random = drbg.generate(32, b"client_hello_random")?;
self.noxtls_send_client_hello_with_resumption_ticket(&random, ticket)
}
/// Builds and records a TLS 1.3 ClientHello with ticket age using DRBG random bytes.
///
/// # Arguments
/// * `drbg`: DRBG instance used to generate ClientHello random bytes.
/// * `ticket`: Resumption ticket metadata used to derive identity and binder.
/// * `current_time_ms`: Client-local timestamp used for obfuscated ticket age.
///
/// # Returns
/// Encoded ClientHello handshake bytes carrying one pre_shared_key offer.
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
pub fn noxtls_send_client_hello_with_resumption_ticket_at_auto(
&mut self,
drbg: &mut HmacDrbgSha256,
ticket: &ResumptionTicket,
current_time_ms: u64,
) -> Result<Vec<u8>> {
let random = drbg.generate(32, b"client_hello_random")?;
self.noxtls_send_client_hello_with_resumption_ticket_at(&random, ticket, current_time_ms)
}
/// Builds and records a TLS 1.3 multi-ticket ClientHello with DRBG random bytes.
///
/// # Arguments
/// * `drbg`: DRBG instance used to generate ClientHello random bytes.
/// * `tickets`: Ordered resumption tickets to advertise in pre_shared_key.
/// * `current_time_ms`: Client-local timestamp used for obfuscated ticket age values.
///
/// # Returns
/// Encoded ClientHello handshake bytes carrying multiple PSK identities and binders.
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
pub fn noxtls_send_client_hello_with_resumption_tickets_auto(
&mut self,
drbg: &mut HmacDrbgSha256,
tickets: &[ResumptionTicket],
) -> Result<Vec<u8>> {
let random = drbg.generate(32, b"client_hello_random")?;
self.noxtls_send_client_hello_with_resumption_tickets(&random, tickets)
}
/// Builds and records a TLS 1.3 multi-ticket ClientHello with DRBG random bytes.
///
/// # Arguments
/// * `drbg`: DRBG instance used to generate ClientHello random bytes.
/// * `tickets`: Ordered resumption tickets to advertise in pre_shared_key.
/// * `current_time_ms`: Client-local timestamp used for obfuscated ticket age values.
///
/// # Returns
/// Encoded ClientHello handshake bytes carrying multiple PSK identities and binders.
/// # Errors
///
/// Returns [`noxtls_core::Error`] when inputs or handshake state invalidate the operation; see the function body for specific error construction sites.
///
/// # Panics
///
/// This function does not panic.
///
pub fn noxtls_send_client_hello_with_resumption_tickets_at_auto(
&mut self,
drbg: &mut HmacDrbgSha256,
tickets: &[ResumptionTicket],
current_time_ms: u64,
) -> Result<Vec<u8>> {
let random = drbg.generate(32, b"client_hello_random")?;
self.noxtls_send_client_hello_with_resumption_tickets_at(&random, tickets, current_time_ms)
}
}