Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
peazip authored Nov 12, 2024
1 parent 5699039 commit 3c32593
Show file tree
Hide file tree
Showing 23 changed files with 16,330 additions and 15,693 deletions.
35 changes: 30 additions & 5 deletions peazip-sources/dev/fcaes256.pas
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ interface
CH_INTF, AES_INTF;
{$endif}
{$else}
Hash, HMAC, Whirl512, KDF, AES_Type, AES_CTR, AES_EAX;
Hash, HMAC, Whirl512, KDF, AES_Type, AES_CTR, AES_EAX, scrypt;
{$endif}


Expand Down Expand Up @@ -102,7 +102,7 @@ TFCA_HMAC256_Context = record


function FCA_EAX256_init(var cx: TAES_EAXContext; pPW: pointer; pLen: word; var hdr: TFCA256Hdr): integer;
function FCA_EAX256_initP(var cx: TAES_EAXContext; pPW: pointer; pLen: word; var hdr: TFCA256Hdr; niter:byte): integer;
function FCA_EAX256_initP(var cx: TAES_EAXContext; pPW: pointer; pLen: word; var hdr: TFCA256Hdr; niter:byte; tkdf:ansistring): integer;
{-Initialize crypt context using password pointer pPW and hdr.salt}

function FCA_EAX256_initS(var cx: TAES_EAXContext; sPW: Str255; var hdr: TFCA256Hdr): integer;
Expand Down Expand Up @@ -246,18 +246,43 @@ function FCA_EAX256_init(var cx: TAES_EAXContext; pPW: pointer; pLen: word; var
fillchar(XKey, sizeof(XKey),0);
end;

function FCA_EAX256_initP(var cx: TAES_EAXContext; pPW: pointer; pLen: word; var hdr: TFCA256Hdr; niter:byte): integer;
function FCA_EAX256_initP(var cx: TAES_EAXContext; pPW: pointer; pLen: word; var hdr: TFCA256Hdr; niter:byte; tkdf:ansistring): integer;
{-Initialize crypt context using password pointer pPW and hdr.salt}
var
XKey: TX256Key;
Err : integer;
intiter:longint;
intiter,memiter,piter:longint;
begin

intiter:=(niter*100000)+25000;
case niter of
1: memiter:=128*1024;
2: memiter:=256*1024;
3: memiter:=512*1024;
4: memiter:=1024*1024;
5: memiter:=1024*1024;
6: memiter:=1024*1024;
7: memiter:=1024*1024;
else memiter:=64*1024;
end;
case niter of
5: piter:=2;
6: piter:=4;
7: piter:=8;
else piter:=1;
end;

{derive the EAX key / nonce and pw verifier}
Err := pbkdf2(FindHash_by_ID(_Whirlpool), pPW, pLen, @hdr.salt, sizeof(TFCA256Salt), intiter, XKey, sizeof(XKey));
case tkdf of
'scrypt': Err := scrypt_kdf(pPW, pLen, @hdr.salt, sizeof(TFCA256Salt), memiter, 8, piter, XKey, sizeof(XKey));
'pbkdf2': Err := pbkdf2(FindHash_by_ID(_Whirlpool), pPW, pLen, @hdr.salt, sizeof(TFCA256Salt), intiter, XKey, sizeof(XKey));
else
begin
Err:=-1;
FCA_EAX256_initP := Err;
exit;
end;
end;

{init AES EAX mode with ak/hk}
if Err=0 then Err := AES_EAX_Init(XKey.ak, 8*sizeof(XKey.ak), xkey.hk, sizeof(XKey.hk), cx);;
Expand Down
35 changes: 30 additions & 5 deletions peazip-sources/dev/fcsp256.pas
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface
CH_INTF, SP_INTF;
{$endif}
{$else}
Hash, HMAC, Whirl512, KDF, SP_base, SP_CTR, SP_EAX;
Hash, HMAC, Whirl512, KDF, SP_base, SP_CTR, SP_EAX, scrypt;
{$endif}


Expand Down Expand Up @@ -91,7 +91,7 @@ TFCS_HMAC256_Context = record


function FCS_EAX256_init(var cx: TSP_EAXContext; pPW: pointer; pLen: word; var hdr: TFCS256Hdr): integer;
function FCS_EAX256_initP(var cx: TSP_EAXContext; pPW: pointer; pLen: word; var hdr: TFCS256Hdr; niter:byte): integer;
function FCS_EAX256_initP(var cx: TSP_EAXContext; pPW: pointer; pLen: word; var hdr: TFCS256Hdr; niter:byte; tkdf:ansistring): integer;
{-Initialize crypt context using password pointer pPW and hdr.salt}

function FCS_EAX256_initS(var cx: TSP_EAXContext; sPW: Str255; var hdr: TFCS256Hdr): integer;
Expand Down Expand Up @@ -235,18 +235,43 @@ function FCS_EAX256_init(var cx: TSP_EAXContext; pPW: pointer; pLen: word; var h
fillchar(XKey, sizeof(XKey),0);
end;

function FCS_EAX256_initP(var cx: TSP_EAXContext; pPW: pointer; pLen: word; var hdr: TFCS256Hdr; niter:byte): integer;
function FCS_EAX256_initP(var cx: TSP_EAXContext; pPW: pointer; pLen: word; var hdr: TFCS256Hdr; niter:byte; tkdf:ansistring): integer;
{-Initialize crypt context using password pointer pPW and hdr.salt}
var
XKey: TX256Key;
Err : integer;
intiter:longint;
intiter,memiter,piter:longint;
begin

intiter:=(niter*100000)+75000;
case niter of
1: memiter:=128*1024;
2: memiter:=256*1024;
3: memiter:=512*1024;
4: memiter:=1024*1024;
5: memiter:=1024*1024;
6: memiter:=1024*1024;
7: memiter:=1024*1024;
else memiter:=64*1024;
end;
case niter of
5: piter:=2;
6: piter:=4;
7: piter:=8;
else piter:=1;
end;

{derive the EAX key / nonce and pw verifier}
Err := pbkdf2(FindHash_by_ID(_SHA3_512), pPW, pLen, @hdr.salt, sizeof(TFCS256Salt), intiter, XKey, sizeof(XKey));
case tkdf of
'scrypt': Err := scrypt_kdf(pPW, pLen, @hdr.salt, sizeof(TFCS256Salt), memiter, 8, piter, XKey, sizeof(XKey));
'pbkdf2': Err := pbkdf2(FindHash_by_ID(_SHA3_512), pPW, pLen, @hdr.salt, sizeof(TFCS256Salt), intiter, XKey, sizeof(XKey));
else
begin
Err:=-1;
FCS_EAX256_initP := Err;
exit;
end;
end;

{init SP EAX mode with ak/hk}
if Err=0 then Err := SP_EAX_Init(XKey.ak, 8*sizeof(XKey.ak), xkey.hk, sizeof(XKey.hk), cx);;
Expand Down
35 changes: 30 additions & 5 deletions peazip-sources/dev/fctf256.pas
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface
CH_INTF, TF_INTF;
{$endif}
{$else}
Hash, HMAC, Whirl512, KDF, TF_base, TF_CTR, TF_EAX;
Hash, HMAC, Whirl512, KDF, TF_base, TF_CTR, TF_EAX, scrypt;
{$endif}


Expand Down Expand Up @@ -91,7 +91,7 @@ TFCF_HMAC256_Context = record


function FCF_EAX256_init(var cx: TTF_EAXContext; pPW: pointer; pLen: word; var hdr: TFCF256Hdr): integer;
function FCF_EAX256_initP(var cx: TTF_EAXContext; pPW: pointer; pLen: word; var hdr: TFCF256Hdr; niter:byte): integer;
function FCF_EAX256_initP(var cx: TTF_EAXContext; pPW: pointer; pLen: word; var hdr: TFCF256Hdr; niter:byte; tkdf:ansistring): integer;
{-Initialize crypt context using password pointer pPW and hdr.salt}

function FCF_EAX256_initS(var cx: TTF_EAXContext; sPW: Str255; var hdr: TFCF256Hdr): integer;
Expand Down Expand Up @@ -235,18 +235,43 @@ function FCF_EAX256_init(var cx: TTF_EAXContext; pPW: pointer; pLen: word; var h
fillchar(XKey, sizeof(XKey),0);
end;

function FCF_EAX256_initP(var cx: TTF_EAXContext; pPW: pointer; pLen: word; var hdr: TFCF256Hdr; niter:byte): integer;
function FCF_EAX256_initP(var cx: TTF_EAXContext; pPW: pointer; pLen: word; var hdr: TFCF256Hdr; niter:byte; tkdf:ansistring): integer;
{-Initialize crypt context using password pointer pPW and hdr.salt}
var
XKey: TX256Key;
Err : integer;
intiter:longint;
intiter,memiter,piter:longint;
begin

intiter:=(niter*100000)+50000;
case niter of
1: memiter:=128*1024;
2: memiter:=256*1024;
3: memiter:=512*1024;
4: memiter:=1024*1024;
5: memiter:=1024*1024;
6: memiter:=1024*1024;
7: memiter:=1024*1024;
else memiter:=64*1024;
end;
case niter of
5: piter:=2;
6: piter:=4;
7: piter:=8;
else piter:=1;
end;

{derive the EAX key / nonce and pw verifier}
Err := pbkdf2(FindHash_by_ID(_SHA512), pPW, pLen, @hdr.salt, sizeof(TFCF256Salt), intiter, XKey, sizeof(XKey));
case tkdf of
'scrypt': Err := scrypt_kdf(pPW, pLen, @hdr.salt, sizeof(TFCF256Salt), memiter, 8, piter, XKey, sizeof(XKey));
'pbkdf2': Err := pbkdf2(FindHash_by_ID(_SHA512), pPW, pLen, @hdr.salt, sizeof(TFCF256Salt), intiter, XKey, sizeof(XKey));
else
begin
Err:=-1;
FCF_EAX256_initP := Err;
exit;
end;
end;

{init TF EAX mode with ak/hk}
if Err=0 then Err := TF_EAX_Init(XKey.ak, 8*sizeof(XKey.ak), xkey.hk, sizeof(XKey.hk), cx);;
Expand Down
Loading

0 comments on commit 3c32593

Please sign in to comment.