-
+ 4A973D255432BC899FB3DFE8AB16F5A9A29578FD141DBC501083CFDE8D9C42F8D037D778B5DF1458B9EA86623EF675DB876EF38C9792C3FDB1834F55B4FEC248
vtools/src/ksum.adb
(0 . 0)(1 . 69)
24 with Ada.Command_Line; use Ada.Command_Line;
25 with Ada.Directories;use Ada.Directories;
26 with Ada.Exceptions;
27 with Ada.Io_Exceptions;
28 with Ada.Sequential_IO;
29 with Ada.Text_IO; use Ada.Text_IO;
30 with Bits; use Bits;
31 with Interfaces; use Interfaces;
32 with SMG_Keccak; use SMG_Keccak;
33 with Character_IO; use Character_IO;
34 procedure Ksum is
35 Buffer_Size: constant Natural := 2048;
36 Hash_Size: constant Natural := 64;
37 Byte_Size: constant Natural := 8;
38
39 package CIO renames Character_IO.Character_IO;
40 Fs: File_Size;
41 File: CIO.File_Type;
42 Ctx: Keccak_Context(Block_Len=>Default_Bitrate);
43 Buf: String(1..Buffer_Size);
44 B: Bitstream(1..Buf'Length*Byte_Size);
45
46 function Read_Buffer return Integer is
47 C: Character;
48 begin
49 for I in 1..Buf'Length loop
50 CIO.Read(File, C);
51 Buf(I):=C;
52 if End_Of_File(File) then
53 return I;
54 end if;
55 end loop;
56 return Buf'Length;
57 end Read_Buffer;
58
59 begin
60 for Arg in 1..Argument_Count loop
61 declare
62 Filename: String:=Argument(Arg);
63 begin
64 Fs:=Size(Filename);
65 Character_IO.Open(File, CIO.In_File, Filename);
66 declare
67 O: Bitstream(1..Hash_Size*Byte_Size);
68 N: Integer;
69 begin
70 KeccakBegin(Ctx);
71 Read_Loop:
72 loop
73 exit Read_Loop when End_Of_File(File);
74 N := Read_Buffer;
75 ToBitstream(Buf(1..N), B(1..N*Byte_Size));
76 KeccakHash(Ctx, B(1..N*Byte_Size));
77 end loop Read_Loop;
78 KeccakEnd(Ctx, O);
79 declare
80 Hex: String := ToHex(O);
81 begin
82 Put(Hex); Put(" "); Put_Line(Filename);
83 end;
84 end;
85 Character_IO.Close(File);
86 exception
87 when The_Error : others =>
88 Put(Standard_Error, Filename); Put(": ");
89 Put_Line(Ada.Exceptions.Exception_Message(The_Error));
90 end;
91 end loop;
92 end;