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
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
use crate::bitfields::{self, Adkd, DsmKroot, Mack, NmaHeader, NmaStatus, Prnd, TagAndInfo};
use crate::types::{BitSlice, NUM_SVNS};
use crate::validation::{NotValidated, Validated};
use crate::{Gst, Svn, Tow};
use aes::Aes128;
use bitvec::prelude::*;
use cmac::Cmac;
use core::fmt;
use crypto_common::KeyInit;
use hmac::{Hmac, Mac};
use p256::ecdsa::VerifyingKey;
use sha2::{Digest, Sha256};
use sha3::Sha3_256;
const MAX_KEY_BYTES: usize = 32;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct Chain {
status: ChainStatus,
id: u8,
hash_function: HashFunction,
mac_function: MacFunction,
key_size_bytes: usize,
tag_size_bits: usize,
maclt: u8,
alpha: u64,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum ChainStatus {
Test,
Operational,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum HashFunction {
Sha256,
Sha3_256,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum MacFunction {
HmacSha256,
CmacAes,
}
impl Chain {
pub fn from_dsm_kroot(nma_header: NmaHeader, dsm_kroot: DsmKroot) -> Result<Chain, ChainError> {
let status = match nma_header.nma_status() {
NmaStatus::Test => ChainStatus::Test,
NmaStatus::Operational => ChainStatus::Operational,
NmaStatus::DontUse => return Err(ChainError::NmaDontUse),
NmaStatus::Reserved => return Err(ChainError::ReservedField),
};
let hash_function = match dsm_kroot.hash_function() {
bitfields::HashFunction::Sha256 => HashFunction::Sha256,
bitfields::HashFunction::Sha3_256 => HashFunction::Sha3_256,
bitfields::HashFunction::Reserved => return Err(ChainError::ReservedField),
};
let mac_function = match dsm_kroot.mac_function() {
bitfields::MacFunction::HmacSha256 => MacFunction::HmacSha256,
bitfields::MacFunction::CmacAes => MacFunction::CmacAes,
bitfields::MacFunction::Reserved => return Err(ChainError::ReservedField),
};
let key_size_bytes = match dsm_kroot.key_size() {
Some(s) => {
assert!(s % 8 == 0);
s / 8
}
None => return Err(ChainError::ReservedField),
};
let tag_size_bits = dsm_kroot.tag_size().ok_or(ChainError::ReservedField)?;
Ok(Chain {
status,
id: nma_header.chain_id(),
hash_function,
mac_function,
key_size_bytes,
tag_size_bits,
maclt: dsm_kroot.mac_lookup_table(),
alpha: dsm_kroot.alpha(),
})
}
pub fn chain_status(&self) -> ChainStatus {
self.status
}
pub fn chain_id(&self) -> u8 {
self.id
}
pub fn hash_function(&self) -> HashFunction {
self.hash_function
}
pub fn mac_function(&self) -> MacFunction {
self.mac_function
}
pub fn key_size_bytes(&self) -> usize {
self.key_size_bytes
}
pub fn key_size_bits(&self) -> usize {
self.key_size_bytes() * 8
}
pub fn tag_size_bits(&self) -> usize {
self.tag_size_bits
}
pub fn mac_lookup_table(&self) -> u8 {
self.maclt
}
pub fn alpha(&self) -> u64 {
self.alpha
}
pub fn validate_adkd<V>(
&self,
num_tag: usize,
tag: TagAndInfo<V>,
prna: Svn,
gst_tag: Gst,
) -> Result<(), AdkdCheckError> {
assert!(num_tag >= 1);
let column = (gst_tag.tow() / 30) % 2;
assert!((column == 0) || (column == 1));
let (adkd, object) = match (self.maclt, column, num_tag) {
(27, 0, 1 | 2 | 3 | 5) => (Adkd::InavCed, AuthObject::Other),
(27, _, 4) => (Adkd::SlowMac, AuthObject::SelfAuth),
(27, 1, 1 | 2 | 5) => (Adkd::InavCed, AuthObject::Other),
(27, 1, 3) => (Adkd::InavTiming, AuthObject::SelfAuth),
(28, 0, 1 | 2 | 3 | 5 | 6 | 8 | 9) => (Adkd::InavCed, AuthObject::Other),
(28, 0, 4) => (Adkd::InavCed, AuthObject::SelfAuth),
(28, _, 7) => (Adkd::SlowMac, AuthObject::SelfAuth),
(28, 1, 1 | 2 | 4 | 5 | 8 | 9) => (Adkd::InavCed, AuthObject::Other),
(28, 1, 3) => (Adkd::InavCed, AuthObject::SelfAuth),
(28, 1, 6) => (Adkd::InavTiming, AuthObject::SelfAuth),
(31, 0, 1 | 2 | 4) => (Adkd::InavCed, AuthObject::Other),
(31, _, 3) => (Adkd::SlowMac, AuthObject::SelfAuth),
(31, 1, 1 | 2) => (Adkd::InavCed, AuthObject::Other),
(31, 1, 4) => (Adkd::InavTiming, AuthObject::SelfAuth),
(33, 0, 1 | 3 | 5) => (Adkd::InavCed, AuthObject::Other),
(33, 0, 2) => (Adkd::InavTiming, AuthObject::SelfAuth),
(33, 0, 4) => (Adkd::SlowMac, AuthObject::SelfAuth),
(33, 1, 1 | 2 | 4) => (Adkd::InavCed, AuthObject::Other),
(33, 1, 3) => (Adkd::SlowMac, AuthObject::SelfAuth),
(33, 1, 5) => (Adkd::SlowMac, AuthObject::Other),
(27 | 28 | 31 | 33, _, _) => return Err(AdkdCheckError::InvalidTagNumber),
(_, _, _) => return Err(AdkdCheckError::InvalidMaclt),
};
assert!((adkd != Adkd::InavTiming) || (object == AuthObject::SelfAuth));
if tag.adkd() != adkd {
Err(AdkdCheckError::WrongAdkd)
} else if adkd == Adkd::InavTiming {
if tag.prnd() != Prnd::GalileoConstellation {
Err(AdkdCheckError::WrongPrnd)
} else {
Ok(())
}
} else if let Prnd::GalileoSvid(prnd) = tag.prnd() {
if object == AuthObject::SelfAuth && prnd != prna.try_into().unwrap() {
Err(AdkdCheckError::WrongPrnd)
} else if (1..=NUM_SVNS).contains(&prnd.into()) {
Ok(())
} else {
Err(AdkdCheckError::WrongPrnd)
}
} else {
unreachable!()
}
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum ChainError {
ReservedField,
NmaDontUse,
}
impl fmt::Display for ChainError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ChainError::ReservedField => "reserved value present in some field".fmt(f),
ChainError::NmaDontUse => "NMA status is \"don't use\"".fmt(f),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for ChainError {}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum AdkdCheckError {
InvalidTagNumber,
InvalidMaclt,
WrongAdkd,
WrongPrnd,
}
impl fmt::Display for AdkdCheckError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AdkdCheckError::InvalidTagNumber => "invalid tag number".fmt(f),
AdkdCheckError::InvalidMaclt => "invalid MAC look-up table".fmt(f),
AdkdCheckError::WrongAdkd => "ADKD does not match MAC look-up table entry".fmt(f),
AdkdCheckError::WrongPrnd => "PRND field does not match MAC look-up table entry".fmt(f),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for AdkdCheckError {}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
enum AuthObject {
SelfAuth,
Other,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct Key<V> {
data: [u8; MAX_KEY_BYTES],
chain: Chain,
gst_subframe: Gst,
_validated: V,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum ValidationError {
WrongOneWayFunction,
DifferentChain,
DoesNotFollow,
TooManyDerivations,
}
impl fmt::Display for ValidationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ValidationError::WrongOneWayFunction => "derived key does not match".fmt(f),
ValidationError::DifferentChain => "keys belong to different chains".fmt(f),
ValidationError::DoesNotFollow => "key is older than validating key".fmt(f),
ValidationError::TooManyDerivations => "time difference between keys too large".fmt(f),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for ValidationError {}
impl<V> Key<V> {
pub fn gst_subframe(&self) -> Gst {
self.gst_subframe
}
fn check_gst(gst: Gst) {
assert!(gst.is_subframe());
}
pub fn chain(&self) -> &Chain {
&self.chain
}
fn store_gst(buffer: &mut [u8], gst: Gst) {
let bits = BitSlice::from_slice_mut(buffer);
bits[0..12].store_be(gst.wn());
bits[12..32].store_be(gst.tow());
}
}
impl Key<NotValidated> {
pub fn from_bitslice(slice: &BitSlice, gst: Gst, chain: &Chain) -> Key<NotValidated> {
Self::check_gst(gst);
let mut data = [0; MAX_KEY_BYTES];
BitSlice::from_slice_mut(&mut data)[..chain.key_size_bytes * 8].copy_from_bitslice(slice);
Key {
data,
chain: *chain,
gst_subframe: gst,
_validated: NotValidated {},
}
}
pub fn from_slice(slice: &[u8], gst: Gst, chain: &Chain) -> Key<NotValidated> {
Self::check_gst(gst);
let mut data = [0; MAX_KEY_BYTES];
data[..chain.key_size_bytes].copy_from_slice(slice);
Key {
data,
chain: *chain,
gst_subframe: gst,
_validated: NotValidated {},
}
}
}
impl<V> Key<V> {
fn force_valid(self) -> Key<Validated> {
Key {
data: self.data,
chain: self.chain,
gst_subframe: self.gst_subframe,
_validated: Validated {},
}
}
}
impl Key<Validated> {
pub fn from_dsm_kroot(
nma_header: NmaHeader,
dsm_kroot: DsmKroot,
pubkey: &VerifyingKey,
) -> Result<Key<Validated>, KrootValidationError> {
let chain = Chain::from_dsm_kroot(nma_header, dsm_kroot)
.map_err(KrootValidationError::WrongDsmKrootChain)?;
if !dsm_kroot.check_padding(nma_header) {
return Err(KrootValidationError::WrongDsmKrootPadding);
}
if !dsm_kroot.check_signature(nma_header, pubkey) {
return Err(KrootValidationError::WrongEcdsa);
}
let wn = dsm_kroot.kroot_wn();
let tow = Tow::from(dsm_kroot.kroot_towh()) * 3600;
let gst = Gst::new(wn, tow);
Self::check_gst(gst);
let gst = gst.add_seconds(-30);
Ok(Key::from_slice(dsm_kroot.kroot(), gst, &chain).force_valid())
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum KrootValidationError {
WrongDsmKrootChain(ChainError),
WrongDsmKrootPadding,
WrongEcdsa,
}
impl fmt::Display for KrootValidationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
KrootValidationError::WrongDsmKrootChain(e) => {
write!(f, "invalid chain in DSM-KROOT ({})", e)
}
KrootValidationError::WrongDsmKrootPadding => "incorrect padding in DSM-KROOT".fmt(f),
KrootValidationError::WrongEcdsa => "invalid ECDSA signature in DSM-KROOT".fmt(f),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for KrootValidationError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
KrootValidationError::WrongDsmKrootChain(e) => Some(e),
KrootValidationError::WrongDsmKrootPadding | KrootValidationError::WrongEcdsa => None,
}
}
}
impl<V: Clone> Key<V> {
pub fn one_way_function(&self) -> Key<V> {
let mut buffer = [0; MAX_KEY_BYTES + 10];
let size = self.chain.key_size_bytes;
buffer[..size].copy_from_slice(&self.data[..size]);
let previous_subframe = self.gst_subframe.add_seconds(-30);
Self::store_gst(&mut buffer[size..size + 4], previous_subframe);
buffer[size + 4..size + 10].copy_from_slice(&self.chain.alpha.to_be_bytes()[2..]);
let mut new_key = [0; MAX_KEY_BYTES];
self.hash_message(&buffer[..size + 10], &mut new_key[..size]);
Key {
data: new_key,
chain: self.chain,
gst_subframe: previous_subframe,
_validated: self._validated.clone(),
}
}
fn hash_message(&self, message: &[u8], hash_out: &mut [u8]) {
match self.chain.hash_function {
HashFunction::Sha256 => Self::hash_message_digest::<Sha256>(message, hash_out),
HashFunction::Sha3_256 => Self::hash_message_digest::<Sha3_256>(message, hash_out),
}
}
fn hash_message_digest<D: Digest>(message: &[u8], hash_out: &mut [u8]) {
let mut hash = D::new();
hash.update(message);
let hash = hash.finalize();
hash_out.copy_from_slice(&hash[..hash_out.len()]);
}
pub fn derive(&self, num_derivations: usize) -> Key<V> {
let mut derived_key = self.clone();
for _ in 0..num_derivations {
derived_key = derived_key.one_way_function();
}
derived_key
}
}
impl Key<Validated> {
pub fn validate_key<V: Clone>(
&self,
other: &Key<V>,
) -> Result<Key<Validated>, ValidationError> {
if self.chain != other.chain {
return Err(ValidationError::DifferentChain);
}
if self.gst_subframe >= other.gst_subframe {
return Err(ValidationError::DoesNotFollow);
}
let derivations = i32::from(other.gst_subframe.wn() - self.gst_subframe.wn())
* (7 * 24 * 3600 / 30)
+ (i32::try_from(other.gst_subframe.tow()).unwrap()
- i32::try_from(self.gst_subframe.tow()).unwrap())
/ 30;
assert!(derivations >= 1);
if derivations > 3000 {
return Err(ValidationError::TooManyDerivations);
}
let derived_key = other.derive(derivations.try_into().unwrap());
assert!(derived_key.gst_subframe == self.gst_subframe);
let size = self.chain.key_size_bytes;
if derived_key.data[..size] == self.data[..size] {
Ok(other.clone().force_valid())
} else {
Err(ValidationError::WrongOneWayFunction)
}
}
pub fn validate_tag(
&self,
tag: &BitSlice,
tag_gst: Gst,
prnd: u8,
prna: Svn,
ctr: u8,
navdata: &BitSlice,
) -> bool {
const BUFF_SIZE: usize = 76;
let mut buffer = [0u8; BUFF_SIZE];
buffer[0] = prnd;
let num_bytes =
1 + self.fill_common_tag_message(&mut buffer[1..], tag_gst, prna, ctr, navdata);
self.check_tag(&buffer[..num_bytes], tag)
}
pub fn validate_tag0(
&self,
tag0: &BitSlice,
tag_gst: Gst,
prna: Svn,
navdata: &BitSlice,
) -> bool {
const BUFF_SIZE: usize = 75;
let mut buffer = [0u8; BUFF_SIZE];
let num_bytes = self.fill_common_tag_message(&mut buffer, tag_gst, prna, 1, navdata);
self.check_tag(&buffer[..num_bytes], tag0)
}
fn fill_common_tag_message(
&self,
buffer: &mut [u8],
gst: Gst,
prna: Svn,
ctr: u8,
navdata: &BitSlice,
) -> usize {
buffer[0] = u8::from(prna);
Self::store_gst(&mut buffer[1..5], gst);
buffer[5] = ctr;
let remaining_bits = BitSlice::from_slice_mut(&mut buffer[6..]);
remaining_bits[..2].store_be(match self.chain.status {
ChainStatus::Test => 1,
ChainStatus::Operational => 2,
});
remaining_bits[2..2 + navdata.len()].copy_from_bitslice(navdata);
6 + (2 + navdata.len() + 7) / 8 }
fn check_tag(&self, message: &[u8], tag: &BitSlice) -> bool {
match self.chain.mac_function {
MacFunction::HmacSha256 => self.check_tag_mac::<Hmac<Sha256>>(message, tag),
MacFunction::CmacAes => self.check_tag_mac::<Cmac<Aes128>>(message, tag),
}
}
fn check_tag_mac<M: Mac + KeyInit>(&self, message: &[u8], tag: &BitSlice) -> bool {
let key = &self.data[..self.chain.key_size_bytes];
let mut mac = <M as Mac>::new_from_slice(key).unwrap();
mac.update(message);
let mac = mac.finalize().into_bytes();
let computed = &BitSlice::from_slice(&mac)[..tag.len()];
computed == tag
}
pub fn validate_macseq<V>(&self, mack: &Mack<V>, prna: Svn, gst_mack: Gst) -> bool {
let mut buffer = [0u8; 5];
buffer[0] = prna.into();
Self::store_gst(&mut buffer[1..5], gst_mack);
let num_bytes = 5;
let mut macseq_buffer = [0u8; 2];
let macseq_bits = &mut BitSlice::from_slice_mut(&mut macseq_buffer)[..12];
macseq_bits.store_be::<u16>(mack.macseq());
self.check_tag(&buffer[..num_bytes], macseq_bits)
}
}
#[cfg(test)]
mod test {
use super::*;
use hex_literal::hex;
fn test_chain() -> Chain {
Chain {
status: ChainStatus::Test,
id: 1,
hash_function: HashFunction::Sha256,
mac_function: MacFunction::HmacSha256,
key_size_bytes: 16,
tag_size_bits: 40,
maclt: 0x21,
alpha: 0x25d3964da3a2,
}
}
#[test]
fn one_way_function() {
let chain = test_chain();
let k0 = Key::from_slice(
&hex!("42 b4 19 da 6a da 1c 0a 3d 6f 56 a5 e5 dc 59 a7"),
Gst::new(1176, 120930),
&chain,
);
let k1 = Key::from_slice(
&hex!("95 42 aa d4 7a bf 39 ba fe 56 68 61 af e8 80 b2"),
Gst::new(1176, 120960),
&chain,
);
assert_eq!(k1.one_way_function(), k0);
}
#[test]
fn validation_kroot() {
let chain = test_chain();
let kroot = Key::from_slice(
&hex!("84 1e 1d e4 d4 58 c0 e9 84 24 76 e0 04 66 6c f3"),
Gst::new(1176, 0x21 * 3600 - 30), &chain,
);
let kroot = kroot.force_valid();
let key = Key::from_slice(
&hex!("42 b4 19 da 6a da 1c 0a 3d 6f 56 a5 e5 dc 59 a7"),
Gst::new(1176, 120930),
&chain,
);
assert!(kroot.validate_key(&key).is_ok());
}
#[test]
fn tag0() {
let tag0 = BitSlice::from_slice(&hex!("8f 54 58 88 71"));
let tag0_gst = Gst::new(1176, 121050);
let prna = Svn::try_from(21).unwrap();
let chain = test_chain();
let key = Key::from_slice(
&hex!("19 58 e7 76 6f b4 08 cb d6 a8 de fc e4 c7 d5 66"),
Gst::new(1176, 121080),
&chain,
)
.force_valid();
let navdata_adkd0 = &BitSlice::from_slice(&hex!(
"
12 07 d0 ec 19 90 2e 00 1f e1 06 aa 04 ed 97 12
11 f0 56 1f 49 ea ce 67 88 4d 18 57 81 9f 12 3f
f0 37 48 93 42 c3 c2 96 c7 65 c3 83 1a c4 85 40
01 7f fd 87 d0 fe 85 ee 31 ff f6 20 0c 68 0b fe
48 00 50 14 00"
))[..549];
assert!(key.validate_tag0(tag0, tag0_gst, prna, navdata_adkd0));
}
fn test_mack() -> Mack<'static, NotValidated> {
let key_size = 128;
let tag_size = 40;
Mack::new(
&hex!(
"
7e ff 9e 16 a5 dd f0 04 f0 3c 9b 6b 1b 07 4d 49
2e dd 67 0b 02 60 ef 9b 83 36 13 c0 94 a8 72 a7
f6 12 05 8f 2e f7 63 24 0e c5 ca 40 0f ad f1 12
47 9f 05 44 9a 25 d8 2e 80 c8 00 00"
),
key_size,
tag_size,
)
}
fn test_key() -> Key<NotValidated> {
Key::from_slice(
&hex!("19 58 e7 76 6f b4 08 cb d6 a8 de fc e4 c7 d5 66"),
Gst::new(1176, 121080),
&test_chain(),
)
}
#[test]
fn adkd() {
let mack = test_mack();
let prna = Svn::try_from(19).unwrap();
for j in 1..mack.num_tags() {
assert!(test_chain()
.validate_adkd(j, mack.tag_and_info(j), prna, Gst::new(1176, 121050))
.is_ok());
}
}
#[test]
fn macseq() {
let key = test_key().force_valid();
let mack = test_mack();
let prna = Svn::try_from(19).unwrap();
assert!(key.validate_macseq(&mack, prna, Gst::new(1176, 121050)));
}
}