smg_comms_packing... 1
smg_comms_packing... 2
smg_comms_packing... 3
smg_comms_packing... 4 with Packing; use Packing;
smg_comms_packing... 5 with Raw_Types; use Raw_Types;
smg_comms_packing... 6 with Serpent; use Serpent;
smg_comms_packing... 7
smg_comms_packing... 8 with Interfaces; use Interfaces;
smg_comms_packing... 9 with Ada.Text_IO; use Ada.Text_IO;
smg_comms_packing... 10
smg_comms_packing... 11 package body Test_Packing is
smg_comms_packing... 12
smg_comms_packing... 13 procedure Print(Data: in Raw_Types.Octets; Msg: in String) is
smg_comms_packing... 14 begin
smg_comms_packing... 15 Put_Line(Msg);
smg_comms_packing... 16 for I of Data loop
smg_comms_packing... 17 Put(Unsigned_8'Image(I));
smg_comms_packing... 18 end loop;
smg_comms_packing... 19 New_Line;
smg_comms_packing... 20 end Print;
smg_comms_packing... 21
smg_comms_packing... 22 procedure Test_Pack_Unpack is
smg_comms_packing... 23 InMsg : Serpent_Msg := (others => 0);
smg_comms_packing... 24 OutMsg : Serpent_Msg := (others => 0);
smg_comms_packing... 25
smg_comms_packing... 26 InPkt : Serpent_Pkt := (others => 0);
smg_comms_packing... 27 OutPkt : Serpent_Pkt := (others => 0);
smg_comms_packing... 28
smg_comms_packing... 29 K : Key := (others => 0);
smg_comms_packing... 30 KS : Key_Schedule;
smg_comms_packing... 31 Plain : Block := (others => 0);
smg_comms_packing... 32 Encr : Block := (others => 0);
smg_comms_packing... 33 Len : constant Natural :=
smg_comms_packing... 34 Raw_Types.SERPENT_OCTETS / Serpent.Block'Length;
smg_comms_packing... 35 begin
smg_comms_packing... 36 for I in 1 .. 128 loop
smg_comms_packing... 37 OutPkt := Pack(InMsg, K);
smg_comms_packing... 38 if OutPkt = InMsg then
smg_comms_packing... 39 raise Test_Error;
smg_comms_packing... 40 end if;
smg_comms_packing... 41
smg_comms_packing... 42 OutMsg := Unpack(OutPkt, K);
smg_comms_packing... 43 if OutMsg /= InMsg then
smg_comms_packing... 44 raise Test_Error;
smg_comms_packing... 45 end if;
smg_comms_packing... 46
smg_comms_packing... 47
smg_comms_packing... 48 Prepare_Key(K, KS);
smg_comms_packing... 49 for J in 1 .. Len loop
smg_comms_packing... 50 Plain := InMsg((J-1)*Block'Length + 1 .. J*Block'Length);
smg_comms_packing... 51 Serpent.Encrypt(KS, Plain, Encr);
smg_comms_packing... 52 if Encr /= OutPkt((J-1)*Block'Length + 1 .. J*Block'Length) then
smg_comms_packing... 53 raise Test_Error;
smg_comms_packing... 54 end if;
smg_comms_packing... 55 end loop;
smg_comms_packing... 56
smg_comms_packing... 57
smg_comms_packing... 58 InMsg := OutPkt;
smg_comms_packing... 59 end loop;
smg_comms_packing... 60
smg_comms_packing... 61 end Test_Pack_Unpack;
smg_comms_packing... 62
smg_comms_packing... 63 end Test_Packing;