-- Tests for SMG_Comms.Packing -- S.MG, 2018 with Packing; use Packing; with Raw_Types; use Raw_Types; with Serpent; use Serpent; with Interfaces; use Interfaces; with Ada.Text_IO; use Ada.Text_IO; package body Test_Packing is procedure Print(Data: in Raw_Types.Octets; Msg: in String) is begin Put_Line(Msg); for I of Data loop Put(Unsigned_8'Image(I)); end loop; New_Line; end Print; procedure Test_Pack_Unpack is InMsg : Serpent_Msg := (others => 0); OutMsg : Serpent_Msg := (others => 0); InPkt : Serpent_Pkt := (others => 0); OutPkt : Serpent_Pkt := (others => 0); K : Key := (others => 0); KS : Key_Schedule; Plain : Block := (others => 0); Encr : Block := (others => 0); Len : constant Natural := Raw_Types.SERPENT_OCTETS / Serpent.Block'Length; begin for I in 1 .. 128 loop OutPkt := Pack(InMsg, K); if OutPkt = InMsg then raise Test_Error; end if; OutMsg := Unpack(OutPkt, K); if OutMsg /= InMsg then raise Test_Error; end if; -- check result of pack Prepare_Key(K, KS); for J in 1 .. Len loop Plain := InMsg((J-1)*Block'Length + 1 .. J*Block'Length); Serpent.Encrypt(KS, Plain, Encr); if Encr /= OutPkt((J-1)*Block'Length + 1 .. J*Block'Length) then raise Test_Error; end if; end loop; -- iterate, re-packing as "message" the previous package InMsg := OutPkt; end loop; end Test_Pack_Unpack; end Test_Packing;