- 0B7D9C9BA8094D32022CAFC676276DDF492FC26965DDAE35CB67DDDFC906B95B5D9025896BAE70ED46A1C6FFD8999D87C707A1EDB5577E5751FC48272108C8DD
+ 108527AA9877FD1AA76FDF913C50760854260B8406DB12A4C7B1A1A052D593EACC2D59D8F36F7BF70BDC6AC21A3A28E80930C89A64020AE597B67976100F61E2
smg_comms/tests/test_serializing.adb
(12 . 14)(12 . 17)
438 package body Test_Serializing is
439
440 procedure Serialize_Keyset_SS is
441 Msg : Serpent_Msg;
442 KSet : Serpent_Keyset(5);
443 LSB : Interfaces.Unsigned_8 := 16#01#;
444 MSB : Interfaces.Unsigned_8 := 16#80#;
445 LMSB: Interfaces.Unsigned_8 := 16#81#;
446 Counter : Interfaces.Unsigned_16 := 101;
447 NewSet: Serpent_Keyset;
448 NewCounter: Interfaces.Unsigned_16:=0;
449 Msg : Serpent_Msg;
450 RMsg : RSA_Msg;
451 KSet : Serpent_Keyset(5);
452 LSB : Interfaces.Unsigned_8 := 16#01#;
453 MSB : Interfaces.Unsigned_8 := 16#80#;
454 LMSB : Interfaces.Unsigned_8 := 16#81#;
455 Counter : Interfaces.Unsigned_16 := 101;
456 NewSetS : Serpent_Keyset;
457 NewSetR : Serpent_Keyset;
458 NewCounterR: Interfaces.Unsigned_16:=0;
459 NewCounterS: Interfaces.Unsigned_16:=0;
460 begin
461 Put_Line("Generating the Serpent Keys...");
462 -- fill a set of Serpent Keys
(28 . 17)(31 . 20)
464 end loop;
465 KSet.Flag := LSB;
466
467 Put_Line("Writing the keys to message...");
468 -- write keyset to serpent message
469 Put_Line("Writing the keys to messages...");
470 -- write keyset to serpent & rsa messages
471 Write_SKeys_SMsg( KSet, Counter, Msg );
472 Write_SKeys_RMsg( KSet, Counter, RMsg );
473
474 Put_Line("Reading keys back from message...");
475 -- read keyset from message
476 Read_SKeys_SMsg( Msg, Counter, NewSet );
477 Put_Line("Reading keys back from messages...");
478 -- read keyset from serpent and rsa messages
479 Read_SKeys_SMsg( Msg, NewCounterS, NewSetS );
480 Read_SKeys_RMsg( RMsg, NewCounterR, NewSetR );
481
482 Put_Line("Comparing the keysets...");
483 -- compare the two keysets
484 if NewSet /= KSet then
485 if NewCounterS /= Counter or NewCounterS /= Counter or
486 NewSetS /= KSet or NewSetR /= KSet then
487 Put_Line("FAIL: keysets are different!");
488 else
489 Put_Line("PASS: keysets are the same!");
(47 . 7)(53 . 7)
491 Put_Line("Attempting to read from mangled message");
492 begin
493 Msg(Msg'First) := Msg(Msg'First)+25;
494 Read_SKeys_SMsg( Msg, Counter, NewSet);
495 Read_SKeys_SMsg( Msg, Counter, NewSetS);
496 Put_Line("FAIL: read failed to raise invalid message exception!");
497 exception
498 when Invalid_Msg =>
(55 . 5)(61 . 74)
500 end;
501 end Serialize_Keyset_SS;
502
503 procedure Serialize_Keys_Mgm is
504 N_Burnt : Counter_8bits;
505 Counter : Interfaces.Unsigned_16 := 16#EDA9#;
506 Mgm_S : Keys_Mgm;
507 Mgm_R : Keys_Mgm;
508 Cnt_S : Interfaces.Unsigned_16:=0;
509 Cnt_R : Interfaces.Unsigned_16:=0;
510 O1 : Octets_1;
511 SMsg : Serpent_Msg;
512 RMsg : RSA_Msg;
513 begin
514 -- fill the struct with random stuff
515 RNG.Get_Octets( O1 );
516 N_Burnt := Cast(O1);
517 declare
518 Mgm: Keys_Mgm(N_Burnt);
519 begin
520 RNG.Get_Octets( O1 );
521 Mgm.N_Server := O1(O1'First);
522 RNG.Get_Octets( O1 );
523 Mgm.N_Client := O1(O1'First);
524 RNG.Get_Octets( O1 );
525 Mgm.Key_ID := O1(O1'First);
526 if N_Burnt > 0 then
527 RNG.Get_Octets( Mgm.Burnt );
528 end if;
529 -- write it to Serpent and RSA messages
530 Write_KMgm_SMsg(Mgm, Counter, SMsg);
531 Write_KMgm_RMsg(Mgm, Counter, RMsg);
532
533 -- read it back from Serpent and RSA messages
534 Read_KMgm_SMsg( SMsg, Cnt_S, Mgm_S );
535 Read_KMgm_RMsg( RMsg, Cnt_R, Mgm_R );
536
537 -- check results
538 if Cnt_S /= Counter or
539 Mgm_S.N_Burnt /= Mgm.N_Burnt or
540 Mgm_S /= Mgm then
541 Put_Line("FAIL: read/write key management struct to S msg.");
542 else
543 Put_Line("PASS: read/write key management struct to S msg.");
544 end if;
545
546 if Cnt_R /= Counter or
547 Mgm_R.N_Burnt /= Mgm.N_Burnt or
548 Mgm_R /= Mgm then
549 Put_Line("FAIL: read/write key management struct to R msg.");
550 Put_Line("Cnt_R is " & Unsigned_16'Image(Cnt_R));
551 Put_Line("Counter is " & Unsigned_16'Image(Counter));
552 Put_Line("Mgm_R.N_Burnt is " & Counter_8bits'Image(Mgm_R.N_Burnt));
553 Put_Line("Mgm.N_Burnt is " & Counter_8bits'Image(Mgm.N_Burnt));
554 else
555 Put_Line("PASS: read/write key management struct to R msg.");
556 end if;
557
558 -- attempt mangled call - should raise exception
559 begin
560 SMsg(SMsg'First) := SMsg(SMsg'First) + 1;
561 Read_KMgm_SMsg( SMsg, Cnt_S, Mgm_S);
562 Put_Line("FAIL: Read_KMgm_SMsg failed to raise exception!");
563 exception
564 when Invalid_Msg =>
565 Put_Line("PASS: Read_KMgm_SMsg correctly raised exception.");
566 end;
567
568 end;
569
570 end Serialize_Keys_Mgm;
571
572 end Test_Serializing;
573