104 lines
2.3 KiB
ObjectPascal
104 lines
2.3 KiB
ObjectPascal
unit Blake2Impl;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes, SysUtils, CTypes, Types;
|
|
{$I blake2.inc}
|
|
|
|
function load16( const src : pointer) : cuint16; inline;
|
|
procedure store16(var dst : pointer; w: cuint16); inline;
|
|
function load32( const src : pointer) : cuint32; inline;
|
|
procedure store32( var dst : pointer; w: cuint32); inline;
|
|
function load48( const src : pointer) : cuint64;inline;
|
|
procedure store48( var dst : pointer; w: uint64); inline;
|
|
function load64( const src : pointer) : cuint64; inline;
|
|
procedure store64( var dst : pointer; w: cuint64); inline;
|
|
function rotr32( const w : cuint32; const c : cunsigned ): cuint32;inline;
|
|
function rotr64( const w : cuint64; const c : cunsigned ): cuint64;inline;
|
|
procedure secure_zero_memory( var v : pointer; n: csize_t );inline;
|
|
implementation
|
|
|
|
procedure secure_zero_memory( var v : pointer; n : csize_t );
|
|
begin
|
|
FillChar(v, n, 0);
|
|
end;
|
|
|
|
function rotr32( const w : cuint32; const c : cunsigned) : cuint32;inline;
|
|
begin
|
|
Result := (w shr c) or ( w shl ( 64 - c ) );
|
|
end;
|
|
|
|
function rotr64( const w : cuint64; const c : cunsigned ): cuint64;inline;
|
|
begin
|
|
Result := (w shr c) or ( w shl ( 64 - c ) );
|
|
end;
|
|
|
|
procedure store16(var dst: pointer; w: cuint16); inline;
|
|
begin
|
|
Move(w, dst, sizeof(dst));
|
|
end;
|
|
|
|
function load16( const src : pointer) : cuint16; inline;
|
|
var w : cuint16;
|
|
begin
|
|
Move(src, w, sizeof(w));
|
|
Result := w;
|
|
end;
|
|
|
|
procedure store32(var dst: pointer; w: cuint32); inline;
|
|
begin
|
|
Move(w, dst, sizeof(dst));
|
|
end;
|
|
|
|
function load32( const src : pointer) : cuint32; inline;
|
|
var w : cuint32;
|
|
begin
|
|
Move(src, w, sizeof(w));
|
|
Result := w;
|
|
end;
|
|
|
|
procedure store48(var dst : pointer; w : cuint64); inline;
|
|
var p : array[0..6] of cuint8;
|
|
begin
|
|
Move(dst, p, sizeof(p));
|
|
p[0] := w shr 0;
|
|
p[1] := w shr 8;
|
|
p[2] := w shr 16;
|
|
p[3] := w shr 24;
|
|
p[4] := w shr 32;
|
|
p[5] := w shr 40;
|
|
Move(p, dst, sizeof(dst));
|
|
end;
|
|
|
|
function load48( const src : pointer ) : cuint64; inline;
|
|
var p : array[0..6] of cuint64;
|
|
begin
|
|
Move(src, p, sizeof(p));
|
|
Result :=
|
|
p[0] shl 0
|
|
or p[1] shl 8
|
|
or p[2] shl 16
|
|
or p[3] shl 24
|
|
or p[4] shl 32
|
|
or p[5] shl 40;
|
|
end;
|
|
|
|
procedure store64(var dst: pointer; w: cuint64); inline;
|
|
begin
|
|
Move(w, dst, sizeof(dst));
|
|
end;
|
|
|
|
function load64( const src : pointer) : cuint64; inline;
|
|
var
|
|
w : cuint64;
|
|
begin
|
|
Move(src, w, sizeof(w));
|
|
Result := w;
|
|
end;
|
|
|
|
end.
|
|
|