diff -uNr a/vtools/manifest b/vtools/manifest --- a/vtools/manifest 7896d8cc732aef7cbaae1c872dd824f51c5f6d1d23e42bb57ce03cf7b84664cc2140d4dbb9c70b72e14a1f82a59acdda3b7432e90423f0a8e93cf4fe5abf2e7f +++ b/vtools/manifest de81a97d5da86b1a3f934e6afb04b4ab40aa58163ad292438814fd9ca1dc09d9209c4984099e2e709fbe637cf8046a30b04039e2abce74ec565bf2f7881c0e91 @@ -2,3 +2,4 @@ 511300 phf vdiff_fixes_newline_gcc Fixes for C99 compatability, support for "No newline at end of file" directive. 511300 phf keccak Included diana_coman's keccak implementation. 511300 phf vdiff_keccak Vdiff hashing and output using Keccak instead of SHA512. +512600 phf vtools_fixes_bitrate_char_array Fixes for keccak from diana_coman, different approach to C interop. diff -uNr a/vtools/src/keccak_c.adb b/vtools/src/keccak_c.adb --- a/vtools/src/keccak_c.adb 680efb9458a976f700a689a6b0678510172945e94d35207f07bea280bb87b30edc889968fbf6c922c8cc5c79b9193986ab66037cc36f47d52b49e91826c22fe4 +++ b/vtools/src/keccak_c.adb 252a6f237724580f4af2f1fbf2dff39dcdd7c1a14ac7c17021d4ed0d0939f6394bf2cbce3e2ecc3261b8474ecf0d7de34728467679e557a7c44bad510d070747 @@ -54,28 +54,41 @@ end C_Begin; procedure C_Hash(Ctx: in C_Context_Access; - Input: Interfaces.C.Char_Array; - Len: Interfaces.C.Size_T) is + Input: Char_Star; + Len: Interfaces.C.size_t) is L: Natural := Natural(Len); S: String(1..L); B: Bitstream(1..S'Length*8); + Ptr: Char_Star := Input; begin - Interfaces.C.To_Ada(Input, S, L, Trim_Nul => False); + if Input = null then + raise C.Strings.Dereference_Error; + end if; + for Chr of S loop + Chr := Character(Ptr.all); + Char_Ptrs.Increment(Ptr); + end loop; ToBitstream(S, B); KeccakHash(Ctx.all, B); end C_Hash; procedure C_End(Ctx: C_Context_Access; - Output: out Interfaces.C.Char_Array; + Output: Char_Star; Len: Interfaces.C.Size_T) is L: Natural := Natural(Len); S: String(1..L); B: Bitstream(1..S'Length*8); - Count: Interfaces.C.Size_T; + Ptr: Char_Star := Output; begin + if Output = null then + raise C.Strings.Dereference_Error; + end if; KeccakEnd(Ctx.all, B); ToString(B, S); - Interfaces.C.To_C(S, Output(0..Len), Count, Append_Nul => False); + for Chr of S loop + Ptr.all := Interfaces.C.char(Chr); + Char_Ptrs.Increment(Ptr); + end loop; -- Len = Count end C_End; diff -uNr a/vtools/src/keccak_c.ads b/vtools/src/keccak_c.ads --- a/vtools/src/keccak_c.ads 33d0a8bfac503d941796252636419dfbc9917d9d67c2e15e13e85083afb8ed46cde57452b61ef275ccfde07b7891d510467b49868882248a5836bce52ef7a7d0 +++ b/vtools/src/keccak_c.ads 9e720f186b11bb3e2d398765619e1e4220659e74bdf9ad4d3be83eeb51c9a45e5f7a4bfcece333f5e86b50838874dbc31462efd45f25294c3661eb069c9e4db2 @@ -1,8 +1,17 @@ with Interfaces; use Interfaces; with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; +with Interfaces.C.Pointers; with Ada.Unchecked_Deallocation; with SMG_Keccak; use SMG_Keccak; package Keccak_C is + package Char_Ptrs is + new Interfaces.C.Pointers (Index => size_t, + Element => char, + Element_Array => char_array, + Default_Terminator => nul); + use type Char_Ptrs.Pointer; + subtype Char_Star is Char_Ptrs.Pointer; subtype C_Context is Keccak_Context(Block_Len=>Default_Bitrate); type C_Context_Access is access C_Context; procedure C_Get_Size(Size: out Interfaces.C.size_t); @@ -10,11 +19,11 @@ function C_Begin return C_Context_Access; pragma Export (C, C_Begin, "keccak_begin"); procedure C_Hash(Ctx: C_Context_Access; - Input: Interfaces.C.Char_Array; + Input: Char_Star; Len: Interfaces.C.Size_T); pragma Export (C, C_Hash, "keccak_hash"); procedure C_End(Ctx: C_Context_Access; - Output: out Interfaces.C.Char_Array; + Output: Char_Star; Len: Interfaces.C.Size_T); pragma Export (C, C_End, "keccak_end"); procedure C_Deallocate(Ctx: in out C_Context_Access); diff -uNr a/vtools/src/smg_keccak.adb b/vtools/src/smg_keccak.adb --- a/vtools/src/smg_keccak.adb 8f038c226bd823b585a5081adbdbbf6a394c552875346ab9474c3a7679a8f7636704eb3230f0588fb250fb3a45d584e68a1de7fe92ee209c91d2cdaa0fe3e217 +++ b/vtools/src/smg_keccak.adb b45b24d4e1024ed3c006f3b1754cea63cb7dd34ba653e3ad017bb54800d4b43c5283e7fba95c434d8f7fe470118c2137da999d55a6335bd80be7491ad7fdca92 @@ -217,7 +217,7 @@ ToPos := Block'Last; FromPos := ToPos - SBB + 1; BWord := (others => 0); - BWord(Bitword'First .. Bitword'First + SBB - 1) := Block(ToPos..FromPos); + BWord(Bitword'First .. Bitword'First + SBB - 1) := Block(FromPos..ToPos); Word := BitsToWord( BWord ); S( X, Y ) := S( X, Y ) xor Word; end if;