Olive.Hash/Blake2/Blake2b.pp

70 lines
1.9 KiB
ObjectPascal

{$codepage utf8}
{$h+}{$mode objfpc}{$R-}
Unit Blake2b;
interface
Uses
Blake2Impl,
Classes,
SysUtils,
CTypes;
const
{$RANGECHECKS OFF}
blake2b_IV : array[0..7] of Int64 = (
$6a09e667f3bcc908, $bb67ae8584caa73b,
$3c6ef372fe94f82b, $a54ff53a5f1d36f1,
$510e527fade682d1, $9b05688c2b3e6c1f,
$1f83d9abfb41bd6b, $5be0cd19137e2179
);
{$RANGECHECKS ON}
blake2b_sigma : array[0..11,0..15] of cuint8 = (
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15),
( 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 ) ,
( 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 ) ,
( 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 ) ,
( 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 ) ,
( 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 ) ,
( 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 ) ,
( 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 ) ,
( 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 ) ,
( 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 ) ,
( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ) ,
( 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 )
);
procedure blake2b_set_lastnode( var S : blake2b_state );
function blake2b_is_lastblock( const S : blake2b_state ) : boolean;
procedure blake2b_set_lastblock( var S : blake2b_state );
implementation
procedure blake2b_set_lastnode( var S : blake2b_state );
var lastNode : Int64;
begin
lastNode := Int64(-1);
move(lastNode, S.f[1], sizeof(cuint64));
end;
function blake2b_is_lastblock( const S : blake2b_state ) : boolean;
begin
Result := S.f[0] <> 0;
end;
procedure blake2b_set_lastblock( var S : blake2b_state );
var lastNode : Int64;
begin
if Boolean(S.last_node) then
begin
blake2b_set_lastnode( S );
end;
lastNode := Int64(-1);
Move(lastNode, S.f[0], sizeof(cuint64));
end;
end.