-
+ 27BBB5C117F46558F9F220E460E66C340D340E1D5315EC372B6C7765D709B22E56277A21712643CBCF8DB468752F5A22A7E9D832150A4B32B1C343B69ED24B20
smg_comms/tests/test_packing.adb
(0 . 0)(1 . 63)
897 -- Tests for SMG_Comms.Packing
898 -- S.MG, 2018
899
900 with Packing; use Packing;
901 with Raw_Types; use Raw_Types;
902 with Serpent; use Serpent;
903
904 with Interfaces; use Interfaces;
905 with Ada.Text_IO; use Ada.Text_IO;
906
907 package body Test_Packing is
908
909 procedure Print(Data: in Raw_Types.Octets; Msg: in String) is
910 begin
911 Put_Line(Msg);
912 for I of Data loop
913 Put(Unsigned_8'Image(I));
914 end loop;
915 New_Line;
916 end Print;
917
918 procedure Test_Pack_Unpack is
919 InMsg : Serpent_Msg := (others => 0);
920 OutMsg : Serpent_Msg := (others => 0);
921
922 InPkt : Serpent_Pkt := (others => 0);
923 OutPkt : Serpent_Pkt := (others => 0);
924
925 K : Key := (others => 0);
926 KS : Key_Schedule;
927 Plain : Block := (others => 0);
928 Encr : Block := (others => 0);
929 Len : constant Natural :=
930 Raw_Types.SERPENT_OCTETS / Serpent.Block'Length;
931 begin
932 for I in 1 .. 128 loop
933 OutPkt := Pack(InMsg, K);
934 if OutPkt = InMsg then
935 raise Test_Error;
936 end if;
937
938 OutMsg := Unpack(OutPkt, K);
939 if OutMsg /= InMsg then
940 raise Test_Error;
941 end if;
942
943 -- check result of pack
944 Prepare_Key(K, KS);
945 for J in 1 .. Len loop
946 Plain := InMsg((J-1)*Block'Length + 1 .. J*Block'Length);
947 Serpent.Encrypt(KS, Plain, Encr);
948 if Encr /= OutPkt((J-1)*Block'Length + 1 .. J*Block'Length) then
949 raise Test_Error;
950 end if;
951 end loop;
952
953 -- iterate, re-packing as "message" the previous package
954 InMsg := OutPkt;
955 end loop;
956
957 end Test_Pack_Unpack;
958
959 end Test_Packing;