1,593
社区成员
发帖
与我相关
我的任务
分享
program hmac_sha384_example;
{$APPTYPE CONSOLE}
uses
SysUtils, hmac, hash, hmacsha3;
const
data = 'abcdefg';
key = '123456';
var
HMacContent: THMAC_Context;
mac: TSHA384Digest;
i: Integer;
begin
hmac_SHA384_init(HMacContent, PChar(key), Length(key));
hmac_SHA384_updateXL(HMacContent, PChar(data), Length(data));
hmac_SHA384_final(HMacContent, mac);
for i := 0 to Length(mac) do
Write(Format('%.2x',[mac[i]]));
Readln;
end.
unit HMACSHA3;
interface
{$i STD.INC}
uses
BTypes,Hash,HMAC,SHA384;
procedure hmac_SHA384_init(var ctx: THMAC_Context; key: pointer; klen: word);
{-initialize HMAC context with key}
{$ifdef DLL} stdcall; {$endif}
procedure hmac_SHA384_inits(var ctx: THMAC_Context; skey: Str255);
{-initialize HMAC context with skey}
{$ifdef DLL} stdcall; {$endif}
procedure hmac_SHA384_update(var ctx: THMAC_Context; data: pointer; dlen: word);
{-HMAC data input, may be called more than once}
{$ifdef DLL} stdcall; {$endif}
procedure hmac_SHA384_updateXL(var ctx: THMAC_Context; data: pointer; dlen: longint);
{-HMAC data input, may be called more than once}
{$ifdef DLL} stdcall; {$endif}
procedure hmac_SHA384_final(var ctx: THMAC_Context; var mac: TSHA384Digest);
{-end data input, calculate HMAC digest}
{$ifdef DLL} stdcall; {$endif}
implementation
{---------------------------------------------------------------------------}
procedure hmac_SHA384_init(var ctx: THMAC_Context; key: pointer; klen: word);
{-initialize HMAC context with key}
var
phash: PHashDesc;
begin
phash := FindHash_by_ID(_SHA384);
hmac_init(ctx, phash, key, klen);
end;
{---------------------------------------------------------------------------}
procedure hmac_SHA384_inits(var ctx: THMAC_Context; skey: Str255);
{-initialize HMAC context with skey}
begin
hmac_SHA384_init(ctx, @skey[1], length(skey));
end;
{---------------------------------------------------------------------------}
procedure hmac_SHA384_update(var ctx: THMAC_Context; data: pointer; dlen: word);
{-HMAC data input, may be called more than once}
begin
hmac_updateXL(ctx, data, dlen);
end;
{---------------------------------------------------------------------------}
procedure hmac_SHA384_updateXL(var ctx: THMAC_Context; data: pointer; dlen: longint);
{-HMAC data input, may be called more than once}
begin
hmac_updateXL(ctx, data, dlen);
end;
{---------------------------------------------------------------------------}
procedure hmac_SHA384_final(var ctx: THMAC_Context; var mac: TSHA384Digest);
{-end data input, calculate HMAC digest}
var
d: THashDigest;
begin
hmac_final(ctx, d);
move(d, mac, sizeof(mac));
end;
end.
procedure hmac_SHA256_init(var ctx: THMAC_Context; key: pointer; klen: word);
{-initialize HMAC context with key}
{$ifdef DLL} stdcall; {$endif}
procedure hmac_SHA256_inits(var ctx: THMAC_Context; skey: Str255);
{-initialize HMAC context with skey}
{$ifdef DLL} stdcall; {$endif}
procedure hmac_SHA256_update(var ctx: THMAC_Context; data: pointer; dlen: word);
{-HMAC data input, may be called more than once}
{$ifdef DLL} stdcall; {$endif}
procedure hmac_SHA256_updateXL(var ctx: THMAC_Context; data: pointer; dlen: longint);
{-HMAC data input, may be called more than once}
{$ifdef DLL} stdcall; {$endif}
procedure hmac_SHA256_final(var ctx: THMAC_Context; var mac: TSHA256Digest);
{-end data input, calculate HMAC digest}
{$ifdef DLL} stdcall; {$endif}