vtools_ksum 1 with Ada.Command_Line; use Ada.Command_Line;
vtools_ksum 2 with Ada.Directories;use Ada.Directories;
vtools_ksum 3 with Ada.Exceptions;
vtools_ksum 4 with Ada.Io_Exceptions;
vtools_ksum 5 with Ada.Sequential_IO;
vtools_ksum 6 with Ada.Text_IO; use Ada.Text_IO;
vtools_ksum 7 with Bits; use Bits;
vtools_ksum 8 with Interfaces; use Interfaces;
vtools_ksum 9 with SMG_Keccak; use SMG_Keccak;
vtools_ksum 10 with Character_IO; use Character_IO;
vtools_ksum 11 procedure Ksum is
vtools_ksum 12 Buffer_Size: constant Natural := 2048;
vtools_ksum 13 Hash_Size: constant Natural := 64;
vtools_ksum 14 Byte_Size: constant Natural := 8;
vtools_ksum 15
vtools_ksum 16 package CIO renames Character_IO.Character_IO;
vtools_ksum 17 Fs: File_Size;
vtools_ksum 18 File: CIO.File_Type;
vtools_ksum 19 Ctx: Keccak_Context(Block_Len=>Default_Bitrate);
vtools_ksum 20 Buf: String(1..Buffer_Size);
vtools_ksum 21 B: Bitstream(1..Buf'Length*Byte_Size);
vtools_ksum 22
vtools_ksum 23 function Read_Buffer return Integer is
vtools_ksum 24 C: Character;
vtools_ksum 25 begin
vtools_ksum 26 for I in 1..Buf'Length loop
vtools_ksum 27 CIO.Read(File, C);
vtools_ksum 28 Buf(I):=C;
vtools_ksum 29 if End_Of_File(File) then
vtools_ksum 30 return I;
vtools_ksum 31 end if;
vtools_ksum 32 end loop;
vtools_ksum 33 return Buf'Length;
vtools_ksum 34 end Read_Buffer;
vtools_ksum 35
vtools_ksum 36 begin
vtools_ksum 37 for Arg in 1..Argument_Count loop
vtools_ksum 38 declare
vtools_ksum 39 Filename: String:=Argument(Arg);
vtools_ksum 40 begin
vtools_ksum 41 Fs:=Size(Filename);
vtools_ksum 42 Character_IO.Open(File, CIO.In_File, Filename);
vtools_ksum 43 declare
vtools_ksum 44 O: Bitstream(1..Hash_Size*Byte_Size);
vtools_ksum 45 N: Integer;
vtools_ksum 46 begin
vtools_ksum 47 KeccakBegin(Ctx);
vtools_ksum 48 Read_Loop:
vtools_ksum 49 loop
vtools_ksum 50 exit Read_Loop when End_Of_File(File);
vtools_ksum 51 N := Read_Buffer;
vtools_ksum 52 ToBitstream(Buf(1..N), B(1..N*Byte_Size));
vtools_ksum 53 KeccakHash(Ctx, B(1..N*Byte_Size));
vtools_ksum 54 end loop Read_Loop;
vtools_ksum 55 KeccakEnd(Ctx, O);
vtools_ksum 56 declare
vtools_ksum 57 Hex: String := ToHex(O);
vtools_ksum 58 begin
vtools_ksum 59 Put(Hex); Put(" "); Put_Line(Filename);
vtools_ksum 60 end;
vtools_ksum 61 end;
vtools_ksum 62 Character_IO.Close(File);
vtools_ksum 63 exception
vtools_ksum 64 when The_Error : others =>
vtools_ksum 65 Put(Standard_Error, Filename); Put(": ");
vtools_ksum 66 Put_Line(Ada.Exceptions.Exception_Message(The_Error));
vtools_ksum 67 end;
vtools_ksum 68 end loop;
vtools_ksum 69 end;