66#![ no_std]
77#![ no_main]
88
9+ use capsules_extra:: test:: hmac_md5:: TestHmacMd5 ;
10+ use capsules_extra:: test:: hmac_sha1:: TestHmacSha1 ;
11+ use capsules_extra:: test:: hmac_sha224:: TestHmacSha224 ;
912use capsules_extra:: test:: hmac_sha256:: TestHmacSha256 ;
13+ use capsules_extra:: test:: md5:: TestMd5 ;
14+ use capsules_extra:: test:: sha1:: TestSha1 ;
15+ use capsules_extra:: test:: sha224:: TestSha224 ;
1016use capsules_extra:: test:: sha256:: TestSha256 ;
1117use kernel:: capabilities;
1218use kernel:: component:: Component ;
@@ -17,9 +23,10 @@ use kernel::utilities::single_thread_value::SingleThreadValue;
1723use kernel:: { create_capability, static_init} ;
1824
1925use stm32u545:: gpio:: PinId ;
20- use stm32u545:: hash:: sha256:: Sha256Adapter ;
2126
22- use kernel:: debug;
27+ use stm32u545:: hash:: md5:: Md5Adapter ;
28+ use stm32u545:: hash:: sha1:: Sha1Adapter ;
29+ use stm32u545:: hash:: sha224:: { self , Sha224Adapter } ;
2330use stm32u545:: hash:: traits:: HashAdaptee ;
2431
2532pub mod io;
@@ -62,13 +69,41 @@ struct NucleoU545RE {
6269 // 'static,
6370 // stm32u545::hash::sha256::Sha256Adapter<'static>,
6471 // >,
65- // MD5
66- // hash: &'static capsules_extra::test::md5::TestMd5<'static, stm32u545::hash::Hash<'static>>,
6772 // HMAC-SHA256
68- hash : & ' static capsules_extra:: test:: hmac_sha256:: TestHmacSha256 <
73+ // hash: &'static capsules_extra::test::hmac_sha256::TestHmacSha256<
74+ // 'static,
75+ // stm32u545::hash::md5::Md5Adapter<'static>,
76+ // >,
77+ // MD5
78+ // hash: &'static capsules_extra::test::md5::TestMd5<
79+ // 'static,
80+ // stm32u545::hash::md5::Md5Adapter<'static>,
81+ // >,
82+ // HMAC-MD5
83+ // hash: &'static capsules_extra::test::hmac_md5::TestHmacMd5<
84+ // 'static,
85+ // stm32u545::hash::md5::Md5Adapter<'static>,
86+ // >,
87+ // SHA224
88+ // hash: &'static capsules_extra::test::sha224::TestSha224<
89+ // 'static,
90+ // stm32u545::hash::sha224::Sha224Adapter<'static>,
91+ // >,
92+ // HMAC-SHA224
93+ hash : & ' static capsules_extra:: test:: hmac_sha224:: TestHmacSha224 <
6994 ' static ,
70- stm32u545:: hash:: sha256 :: Sha256Adapter < ' static > ,
95+ stm32u545:: hash:: sha224 :: Sha224Adapter < ' static > ,
7196 > ,
97+ // SHA1
98+ // hash: &'static capsules_extra::test::sha1::TestSha1<
99+ // 'static,
100+ // stm32u545::hash::sha1::Sha1Adapter<'static>,
101+ // >,
102+ // HMAC-SHA1
103+ // hash: &'static capsules_extra::test::hmac_sha1::TestHmacSha1<
104+ // 'static,
105+ // stm32u545::hash::sha1::Sha1Adapter<'static>,
106+ // >,
72107}
73108
74109impl SyscallDriverLookup for NucleoU545RE {
@@ -189,12 +224,26 @@ unsafe fn start() -> (
189224 periphs. tim2 . start ( ) ;
190225 set_pin_primary_functions ( periphs) ;
191226
192- let sha256 = static_init ! (
193- stm32u545:: hash:: sha256:: Sha256Adapter <' static >,
194- stm32u545:: hash:: sha256:: Sha256Adapter :: new( hash)
227+ // let sha256 = static_init!(
228+ // stm32u545::hash::sha256::Sha256Adapter<'static>,
229+ // stm32u545::hash::sha256::Sha256Adapter::new(hash)
230+ // );
231+ // let md5 = static_init!(
232+ // stm32u545::hash::md5::Md5Adapter<'static>,
233+ // stm32u545::hash::md5::Md5Adapter::new(hash)
234+ // );
235+
236+ let sha224 = static_init ! (
237+ stm32u545:: hash:: sha224:: Sha224Adapter <' static >,
238+ stm32u545:: hash:: sha224:: Sha224Adapter :: new( hash)
195239 ) ;
196240
197- hash. set_adapter ( sha256) ;
241+ // let sha1 = static_init!(
242+ // stm32u545::hash::sha1::Sha1Adapter<'static>,
243+ // stm32u545::hash::sha1::Sha1Adapter::new(hash)
244+ // );
245+
246+ hash. set_adapter ( sha224) ;
198247
199248 // Kernel and Muxes
200249 let processes = components:: process_array:: ProcessArrayComponent :: new ( )
@@ -266,16 +315,16 @@ unsafe fn start() -> (
266315
267316 // Various test cases
268317 // Test 1: Simple SHA256
269- let hash_data_buffer = static_init ! ( [ u8 ; 6 ] , [ 0x61 , 0x62 , 0x63 , 0x64 , 0x65 , 0x66 ] ) ;
318+ // let hash_data_buffer = static_init!([u8; 6], [0x61, 0x62, 0x63, 0x64, 0x65, 0x66]);
270319
271- let hash_digest_buffer = static_init ! (
272- [ u8 ; 32 ] ,
273- [
274- 0xbe , 0xf5 , 0x7e , 0xc7 , 0xf5 , 0x3a , 0x6d , 0x40 , 0xbe , 0xb6 , 0x40 , 0xa7 , 0x80 , 0xa6 ,
275- 0x39 , 0xc8 , 0x3b , 0xc2 , 0x9a , 0xc8 , 0xa9 , 0x81 , 0x6f , 0x1f , 0xc6 , 0xc5 , 0xc6 , 0xdc ,
276- 0xd9 , 0x3c , 0x47 , 0x21
277- ]
278- ) ;
320+ // let hash_digest_buffer = static_init!(
321+ // [u8; 32],
322+ // [
323+ // 0xbe, 0xf5, 0x7e, 0xc7, 0xf5, 0x3a, 0x6d, 0x40, 0xbe, 0xb6, 0x40, 0xa7, 0x80, 0xa6,
324+ // 0x39, 0xc8, 0x3b, 0xc2, 0x9a, 0xc8, 0xa9, 0x81, 0x6f, 0x1f, 0xc6, 0xc5, 0xc6, 0xdc,
325+ // 0xd9, 0x3c, 0x47, 0x21
326+ // ]
327+ // );
279328
280329 // Test 2: Less than FIFO size
281330 // let hash_data_buffer = static_init!(
@@ -389,37 +438,37 @@ unsafe fn start() -> (
389438 // ]
390439 // );
391440
392- let hash_data_buffer = static_init ! (
393- [ u8 ; 113 ] ,
394- [
395- 0x48 , 0x65 , 0x6c , 0x6c , 0x6f , 0x2c , 0x20 , 0x52 , 0x75 , 0x73 , 0x74 , 0x79 , 0x21 , 0x20 ,
396- 0x57 , 0x65 , 0x20 , 0x61 , 0x72 , 0x65 , 0x20 , 0x70 , 0x6f , 0x72 , 0x74 , 0x69 , 0x6e , 0x67 ,
397- 0x20 , 0x48 , 0x41 , 0x53 , 0x48 , 0x20 , 0x70 , 0x65 , 0x72 , 0x69 , 0x70 , 0x68 , 0x65 , 0x72 ,
398- 0x61 , 0x6c , 0x20 , 0x74 , 0x6f , 0x20 , 0x54 , 0x6f , 0x63 , 0x6b , 0x20 , 0x4f , 0x53 , 0x2e ,
399- 0x20 , 0x4e , 0x6f , 0x77 , 0x20 , 0x77 , 0x65 , 0x20 , 0x61 , 0x72 , 0x65 , 0x20 , 0x74 , 0x72 ,
400- 0x79 , 0x69 , 0x6e , 0x67 , 0x20 , 0x74 , 0x6f , 0x20 , 0x63 , 0x68 , 0x65 , 0x63 , 0x6b , 0x20 ,
401- 0x69 , 0x6e , 0x74 , 0x65 , 0x72 , 0x72 , 0x75 , 0x70 , 0x74 , 0x73 , 0x20 , 0x61 , 0x6e , 0x64 ,
402- 0x20 , 0x62 , 0x75 , 0x66 , 0x66 , 0x65 , 0x72 , 0x69 , 0x6e , 0x67 , 0x96 , 0x12 , 0xff , 0x45 ,
403- 0x11
404- ]
405- ) ;
441+ // let hash_data_buffer = static_init!(
442+ // [u8; 113],
443+ // [
444+ // 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x52, 0x75, 0x73, 0x74, 0x79, 0x21, 0x20,
445+ // 0x57, 0x65, 0x20, 0x61, 0x72, 0x65, 0x20, 0x70, 0x6f, 0x72, 0x74, 0x69, 0x6e, 0x67,
446+ // 0x20, 0x48, 0x41, 0x53, 0x48, 0x20, 0x70, 0x65, 0x72, 0x69, 0x70, 0x68, 0x65, 0x72,
447+ // 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x54, 0x6f, 0x63, 0x6b, 0x20, 0x4f, 0x53, 0x2e,
448+ // 0x20, 0x4e, 0x6f, 0x77, 0x20, 0x77, 0x65, 0x20, 0x61, 0x72, 0x65, 0x20, 0x74, 0x72,
449+ // 0x79, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x6f, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20,
450+ // 0x69, 0x6e, 0x74, 0x65, 0x72, 0x72, 0x75, 0x70, 0x74, 0x73, 0x20, 0x61, 0x6e, 0x64,
451+ // 0x20, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x96, 0x12, 0xff, 0x45,
452+ // 0x11
453+ // ]
454+ // );
406455
407- let hash_digest_buffer = static_init ! ( [ u8 ; 32 ] , [ 0u8 ; 32 ] ) ;
408- let correct = static_init ! (
409- [ u8 ; 32 ] ,
410- [
411- 0xbb , 0x98 , 0x4f , 0xc1 , 0xd0 , 0xf8 , 0x38 , 0x25 , 0x52 , 0xcc , 0x85 , 0xda , 0xb7 , 0x24 ,
412- 0x81 , 0x11 , 0xca , 0xa1 , 0xcb , 0x82 , 0x69 , 0x75 , 0xc5 , 0x41 , 0x1a , 0x33 , 0x48 , 0x96 ,
413- 0xb3 , 0xa9 , 0xb3 , 0xf0
414- ]
415- ) ;
416- let hmac_key = static_init ! (
417- [ u8 ; 25 ] ,
418- [
419- 0x12 , 0x34 , 0x56 , 0x78 , 0x98 , 0x76 , 0x54 , 0x32 , 0x12 , 0x34 , 0x56 , 0x76 , 0x54 , 0x32 ,
420- 0x12 , 0x34 , 0x56 , 0x76 , 0x54 , 0x32 , 0x23 , 0x45 , 0x67 , 0x65 , 0x43
421- ]
422- ) ;
456+ // let hash_digest_buffer = static_init!([u8; 32], [0u8; 32]);
457+ // let correct = static_init!(
458+ // [u8; 32],
459+ // [
460+ // 0xbb, 0x98, 0x4f, 0xc1, 0xd0, 0xf8, 0x38, 0x25, 0x52, 0xcc, 0x85, 0xda, 0xb7, 0x24,
461+ // 0x81, 0x11, 0xca, 0xa1, 0xcb, 0x82, 0x69, 0x75, 0xc5, 0x41, 0x1a, 0x33, 0x48, 0x96,
462+ // 0xb3, 0xa9, 0xb3, 0xf0
463+ // ]
464+ // );
465+ // let hmac_key = static_init!(
466+ // [u8; 25],
467+ // [
468+ // 0x12, 0x34, 0x56, 0x78, 0x98, 0x76, 0x54, 0x32, 0x12, 0x34, 0x56, 0x76, 0x54, 0x32,
469+ // 0x12, 0x34, 0x56, 0x76, 0x54, 0x32, 0x23, 0x45, 0x67, 0x65, 0x43
470+ // ]
471+ // );
423472
424473 // VERY BIG EXAMPLE
425474 //
@@ -462,56 +511,135 @@ unsafe fn start() -> (
462511 // ]
463512 // );
464513
465- let test_hash = static_init ! (
466- TestHmacSha256 <' static , stm32u545:: hash:: sha256:: Sha256Adapter <' static >>,
467- TestHmacSha256 :: new(
468- sha256,
469- hmac_key,
470- hash_data_buffer,
471- hash_digest_buffer,
472- correct
473- )
474- ) ;
514+ // let test_hash = static_init!(
515+ // TestHmacSha256<'static, stm32u545::hash::sha256::Sha256Adapter<'static>>,
516+ // TestHmacSha256::new(
517+ // sha256,
518+ // hmac_key,
519+ // hash_data_buffer,
520+ // hash_digest_buffer,
521+ // correct
522+ // )
523+ // );
475524
476525 // let test_hash = static_init!(
477526 // TestSha256<'static, Sha256Adapter<'static>>,
478527 // TestSha256::new(sha256, hash_data_buffer, hash_digest_buffer, true)
479528 // );
529+ //
480530
481531 // MD5
482532 // let hash_data_buffer = static_init!([u8; 4], [0x61, 0x62, 0x63, 0x64]);
483533
484534 // let hash_digest_buffer = static_init!(
485- // [u8; 32 ],
535+ // [u8; 16 ],
486536 // [
487537 // 0xe2, 0xfc, 0x71, 0x4c, 0x47, 0x27, 0xee, 0x93, 0x95, 0xf3, 0x24, 0xcd, 0x2e, 0x7f,
488- // 0x33, 0x1f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
538+ // 0x33, 0x1f,
489539 // ]
490540 // );
491541
542+ // let test_hash = static_init!(
543+ // TestMd5<'static, Md5Adapter<'static>>,
544+ // TestMd5::new(md5, hash_data_buffer, hash_digest_buffer, true)
545+ // );
546+ // HMAC-MD5
547+
548+ // let hmac_key = static_init!([u8; 6], [0x12, 0x34, 0x56, 0x78, 0x91, 0x01]);
549+
550+ // let hash_data_buffer = static_init!([u8; 5], [0x61, 0x62, 0x63, 0x64, 0x65]);
551+
552+ // let hash_digest_buffer = static_init!([u8; 16], [0u8; 16]);
553+ // let correct = static_init!(
554+ // [u8; 16],
555+ // [
556+ // 0xc8, 0x27, 0x73, 0xee, 0xb9, 0x9c, 0x7b, 0xf0, 0x12, 0xc1, 0xbc, 0xb6, 0x5b, 0x87,
557+ // 0xa1, 0x12
558+ // ]
559+ // );
560+ // let test_hash = static_init!(
561+ // TestHmacMd5<'static, Md5Adapter<'static>>,
562+ // TestHmacMd5::new(md5, hmac_key, hash_data_buffer, hash_digest_buffer, correct)
563+ // );
564+
492565 // SHA1
493566 // let hash_data_buffer = static_init!([u8; 4], [0x61, 0x62, 0x63, 0x64]);
494567
495568 // let hash_digest_buffer = static_init!(
496- // [u8; 32 ],
569+ // [u8; 20 ],
497570 // [
498571 // 0x81, 0xfe, 0x8b, 0xfe, 0x87, 0x57, 0x6c, 0x3e, 0xcb, 0x22, 0x42, 0x6f, 0x8e, 0x57,
499- // 0x84, 0x73, 0x82, 0x91, 0x7a, 0xcf, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
572+ // 0x84, 0x73, 0x82, 0x91, 0x7a, 0xcf
500573 // ]
501574 // );
575+ // let test_hash = static_init!(
576+ // TestSha1<'static, Sha1Adapter<'static>>,
577+ // TestSha1::new(sha1, hash_data_buffer, hash_digest_buffer, true)
578+ // );
579+
580+ // HMAC-SHA1
581+ // let hmac_key = static_init!([u8; 6], [0x12, 0x34, 0x56, 0x78, 0x91, 0x01]);
582+
583+ // let hash_data_buffer = static_init!([u8; 5], [0x61, 0x62, 0x63, 0x64, 0x65]);
584+
585+ // let hash_digest_buffer = static_init!([u8; 20], [0u8; 20]);
586+ // let correct = static_init!(
587+ // [u8; 20],
588+ // [
589+ // 0x1a, 0x44, 0xb6, 0xc8, 0xf1, 0xa5, 0x60, 0x98, 0x5b, 0xb8, 0x72, 0x1e, 0x8f, 0x70,
590+ // 0x42, 0xc3, 0x08, 0x21, 0xf5, 0xb2
591+ // ]
592+ // );
593+ // let test_hash = static_init!(
594+ // TestHmacSha1<'static, Sha1Adapter<'static>>,
595+ // TestHmacSha1::new(
596+ // sha1,
597+ // hmac_key,
598+ // hash_data_buffer,
599+ // hash_digest_buffer,
600+ // correct
601+ // )
602+ // );
502603 //
503604 // SHA224
504605 // let hash_data_buffer = static_init!([u8; 4], [0x61, 0x62, 0x63, 0x64]);
505606
506607 // let hash_digest_buffer = static_init!(
507- // [u8; 32 ],
608+ // [u8; 28 ],
508609 // [
509610 // 0xa7, 0x66, 0x54, 0xd8, 0xe3, 0x55, 0x0e, 0x9a, 0x2d, 0x67, 0xa0, 0xee, 0xb6, 0xc6,
510- // 0x7b, 0x22, 0x0e, 0x58, 0x85, 0xed, 0xdd, 0x3f, 0xde, 0x13, 0x58, 0x06, 0xe6, 0x01, 0,
511- // 0, 0, 0,
611+ // 0x7b, 0x22, 0x0e, 0x58, 0x85, 0xed, 0xdd, 0x3f, 0xde, 0x13, 0x58, 0x06, 0xe6, 0x01
512612 // ]
513613 // );
514614
615+ // let test_hash = static_init!(
616+ // TestSha224<'static, Sha224Adapter<'static>>,
617+ // TestSha224::new(sha224, hash_data_buffer, hash_digest_buffer, true)
618+ // );
619+ // HMAC-SHA224
620+ let hmac_key = static_init ! ( [ u8 ; 6 ] , [ 0x12 , 0x34 , 0x56 , 0x78 , 0x91 , 0x01 ] ) ;
621+
622+ let hash_data_buffer = static_init ! ( [ u8 ; 5 ] , [ 0x61 , 0x62 , 0x63 , 0x64 , 0x65 ] ) ;
623+
624+ let hash_digest_buffer = static_init ! ( [ u8 ; 28 ] , [ 0u8 ; 28 ] ) ;
625+ let correct = static_init ! (
626+ [ u8 ; 28 ] ,
627+ [
628+ 0x50 , 0x64 , 0x2b , 0x2c , 0xfe , 0x92 , 0xa5 , 0x2e , 0xd5 , 0x99 , 0x81 , 0x97 , 0xcc , 0x14 ,
629+ 0x2b , 0x44 , 0x71 , 0xea , 0xd6 , 0xcc , 0x71 , 0x97 , 0xc8 , 0x67 , 0xc2 , 0x64 , 0x9a , 0x86
630+ ]
631+ ) ;
632+ let test_hash = static_init ! (
633+ TestHmacSha224 <' static , Sha224Adapter <' static >>,
634+ TestHmacSha224 :: new(
635+ sha224,
636+ hmac_key,
637+ hash_data_buffer,
638+ hash_digest_buffer,
639+ correct
640+ )
641+ ) ;
642+
515643 // Platform and Interrupts
516644 let platform = static_init ! (
517645 NucleoU545RE ,
0 commit comments