summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwatcherhd <watcherhd@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb>2011-11-28 17:32:55 +0000
committerwatcherhd <watcherhd@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb>2011-11-28 17:32:55 +0000
commit4608739039b2f7836da1712ccd418f18b06b0824 (patch)
tree40da2ad0df4f419cfb7b24ee0381d3d3dc58a223
parent81102e19294779547d997db765c61d703a42c95c (diff)
Dbx_mmap_SA: Athena cryptor adapted for FPC and x64 (Thanks to Awkward)
git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@227 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb
-rw-r--r--Dbx_mmap_SA/Cryptors/Athena/UAthena.pas28
-rw-r--r--Dbx_mmap_SA/Cryptors/Athena/athena.dpr16
-rw-r--r--Dbx_mmap_SA/Cryptors/Athena/make.bat9
-rw-r--r--Dbx_mmap_SA/Cryptors/Athena/md5_unit.pas266
4 files changed, 67 insertions, 252 deletions
diff --git a/Dbx_mmap_SA/Cryptors/Athena/UAthena.pas b/Dbx_mmap_SA/Cryptors/Athena/UAthena.pas
index 23cb283..15a9674 100644
--- a/Dbx_mmap_SA/Cryptors/Athena/UAthena.pas
+++ b/Dbx_mmap_SA/Cryptors/Athena/UAthena.pas
@@ -21,19 +21,19 @@ unit UAthena;
interface
uses
- SysUtils, md5_unit, windows;
+ md5_unit, windows;
Type
Arr = array of byte;
PArr = ^Arr;
- Function MD5_Mod(s: string; block_count: byte): string;
- Procedure MakeKey(key: PArr; len: word; pwd: string);
+ Function MD5_Mod(const s: AnsiString; block_count: byte): AnsiString;
+ Procedure MakeKey(key: PArr; len: word; const pwd: AnsiString);
Procedure EncryptData(key: PArr; data: PByte; size: LongWord);
Procedure DecryptData(key: PArr; data: PByte; size: LongWord);
implementation
//==============================================================================
-Function str_back(s: string): string;
+Function str_back(const s: AnsiString): AnsiString;
Var
i: integer;
Begin
@@ -41,9 +41,9 @@ Begin
for i := Length(s) downto 1 do result := result + s[i];
end;
//==============================================================================
-Function MD5_Mod(s: string; block_count: byte): string;
+Function MD5_Mod(const s: AnsiString; block_count: byte): AnsiString;
Var
- s1, s2, sb : String;
+ s1, s2, sb : AnsiString;
k : word;
Begin
sb := str_back(s);
@@ -56,15 +56,19 @@ Begin
result := s2;
end;
//==============================================================================
-Procedure MakeKey(key: PArr; len: word; pwd: string);
+Procedure MakeKey(key: PArr; len: word; const pwd: AnsiString);
Var
- s : string;
+ s : AnsiString;
i : word;
+ dummy: integer;
Begin
if len > 64 then Len := ((Len div 16) + 1)*16 else Len := 64;
SetLength(key^, Len);
s := MD5_mod(pwd, len div 16);
- for i := 1 to length(s) div 2 do key^[i-1] := strtoint('$' + copy(s, i*2 - 1, 2));
+ for i := 1 to length(s) div 2 do
+ begin
+ val('$' + copy(s, i*2 - 1, 2),key^[i-1],dummy);
+ end;
end;
//==============================================================================
Procedure GetNENum(key: arr; var n1, n2: LongWord);
@@ -99,7 +103,7 @@ Begin
k1 := (i+n1+7)*n2 mod lk;
k2 := (i+n2+3)*n1 mod lk;
- PByte(LongWord(data)+i)^ := PByte(LongWord(data)+i)^ xor kg[k1] xor kg[k2];
+ PByte(uint_ptr(data)+i)^ := PByte(uint_ptr(data)+i)^ xor kg[k1] xor kg[k2];
kg[k1] := kg[k1]*k1 + kg[k2] + i*k2;
kg[k2] := kg[k2]*k2 + kg[k1] + i*k1;
@@ -129,7 +133,7 @@ Begin
k1 := (i+n1)*n2 mod lk;
k2 := (i+n2)*n1 mod lk;
- PByte(LongWord(data)+i)^ := PByte(LongWord(data)+i)^ xor ((PByte(LongWord(data)+i-1)^ xor k[k1]) xor k[k2]);
+ PByte(uint_ptr(data)+i)^ := PByte(uint_ptr(data)+i)^ xor ((PByte(uint_ptr(data)+i-1)^ xor k[k1]) xor k[k2]);
end;
end;
//==============================================================================
@@ -148,7 +152,7 @@ Begin
Begin
k1 := (i+n1)*n2 mod lk;
k2 := (i+n2)*n1 mod lk;
- PByte(LongWord(data) + i)^ := PByte(LongWord(data)+i)^ xor ((PByte(LongWord(data) + i - 1)^ xor k[k1]) xor k[k2]);
+ PByte(uint_ptr(data) + i)^ := PByte(uint_ptr(data)+i)^ xor ((PByte(uint_ptr(data) + i - 1)^ xor k[k1]) xor k[k2]);
end;
//---------------------------------------------------------------------------
k1 := (n2 + lk)*n1 mod lk;
diff --git a/Dbx_mmap_SA/Cryptors/Athena/athena.dpr b/Dbx_mmap_SA/Cryptors/Athena/athena.dpr
index 00b95c2..4824b9b 100644
--- a/Dbx_mmap_SA/Cryptors/Athena/athena.dpr
+++ b/Dbx_mmap_SA/Cryptors/Athena/athena.dpr
@@ -20,15 +20,13 @@ library athena;
}
uses
- SysUtils,
- Classes,
UAthena,
WIndows;
{$R *.res}
type
- TGenerateKey = function(key: PChar): PArr; stdcall;
+ TGenerateKey = function(key: PAnsiChar): PArr; stdcall;
TFreeKey = procedure(key: PArr); stdcall;
TEncryptMem = procedure(data: PByte; size: LongWord; key: PArr); stdcall;
@@ -40,11 +38,11 @@ type
EncryptMem: TEncryptMem;
DecryptMem: TEncryptMem;
- Name: PChar;
- Info: PChar;
- Author: PChar;
- Site: PChar;
- Email: PChar;
+ Name: PAnsiChar;
+ Info: PAnsiChar;
+ Author: PAnsiChar;
+ Site: PAnsiChar;
+ Email: PAnsiChar;
version: dword;
@@ -60,7 +58,7 @@ begin
Result := (a shl 24) or (b shl 16) or (c shl 8) or d;
end;
-function GenerateKey(pwd: PChar): PArr; stdcall;
+function GenerateKey(pwd: PAnsiChar): PArr; stdcall;
var
a: PArr;
begin
diff --git a/Dbx_mmap_SA/Cryptors/Athena/make.bat b/Dbx_mmap_SA/Cryptors/Athena/make.bat
new file mode 100644
index 0000000..e847eff
--- /dev/null
+++ b/Dbx_mmap_SA/Cryptors/Athena/make.bat
@@ -0,0 +1,9 @@
+@echo off
+..\delphi\brcc32.exe athena.rc -foathena.res
+if /i '%1' == 'fpc' (
+ ..\FPC\bin\fpc.exe athena.dpr %2 %3 %4 %5 %6 %7 %8 %9
+) else if /i '%1' == 'fpc64' (
+ ..\FPC\bin64\ppcrossx64.exe athena.dpr %2 %3 %4 %5 %6 %7 %8 %9
+) else (
+ ..\delphi\dcc32 athena.dpr %1 %2 %3 %4 %5 %6 %7 %8 %9
+)
diff --git a/Dbx_mmap_SA/Cryptors/Athena/md5_unit.pas b/Dbx_mmap_SA/Cryptors/Athena/md5_unit.pas
index d09c086..500a2eb 100644
--- a/Dbx_mmap_SA/Cryptors/Athena/md5_unit.pas
+++ b/Dbx_mmap_SA/Cryptors/Athena/md5_unit.pas
@@ -2,235 +2,42 @@ unit md5_unit;
interface
-uses
- Windows, SysUtils;
+uses Windows;
Type
TMD5 = Array [0..15] of byte;
-function MD5(s: string): string;
-function MD5_arr(s: string): TMD5;
+function MD5(const s: AnsiString): AnsiString;
+function MD5_arr(const s: AnsiString): TMD5;
implementation
//==============================================================================
-function Int2Hex( Value : DWord; Digits : Integer ) : String;
-asm
- PUSH 0
- ADD ESP, -0Ch
+const
+ HexDigitChr : array [0..15] of AnsiChar = ('0','1','2','3','4','5','6','7',
+ '8','9','A','B','C','D','E','F');
- PUSH EBX
- PUSH ECX
-
- LEA EBX, [ESP+8+0Fh] // EBX := @Buf[ 15 ]
- AND EDX, $F
-
-@@loop: DEC EBX
- DEC EDX
-
- PUSH EAX
- {$IFDEF PARANOIA}
- DB $24, $0F
- {$ELSE}
- AND AL, 0Fh
- {$ENDIF}
- {$IFDEF PARANOIA}
- DB $3C, 9
- {$ELSE}
- CMP AL, 9
- {$ENDIF}
- JA @@10
- {$IFDEF PARANOIA}
- DB $04, 30h-41h+0Ah
- {$ELSE}
- ADD AL,30h-41h+0Ah
- {$ENDIF}
-@@10:
- {$IFDEF PARANOIA}
- DB $04, 41h-0Ah
- {$ELSE}
- ADD AL,41h-0Ah
- {$ENDIF}
- MOV byte ptr [EBX], AL
- POP EAX
- SHR EAX, 4
-
- JNZ @@loop
-
- TEST EDX, EDX
- JG @@loop
-
- POP EAX // EAX = @Result
- MOV EDX, EBX // EDX = @resulting string
- CALL System.@LStrFromPChar
-
- POP EBX
- ADD ESP, 10h
-
-end;
-//==============================================================================
-function MD5(s: string): string;
-var
- a : TMD5;
- i : integer;
- LenHi, LenLo: longword;
- Index: DWord;
- HashBuffer : array[0..63] of byte;
- CurrentHash : array[0..3] of DWord;
-
- procedure Burn;
- begin
- LenHi:= 0; LenLo:= 0;
- Index:= 0;
- FillChar(HashBuffer,Sizeof(HashBuffer),0);
- FillChar(CurrentHash,Sizeof(CurrentHash),0);
- end;
-
- procedure Init;
- begin
- Burn;
- CurrentHash[0]:= $67452301;
- CurrentHash[1]:= $efcdab89;
- CurrentHash[2]:= $98badcfe;
- CurrentHash[3]:= $10325476;
- end;
-
- function LRot32(a, b: longword): longword;
- begin
- Result:= (a shl b) or (a shr (32-b));
- end;
-
- procedure Compress;
- var
- Data : array[0..15] of dword;
- A, B, C, D: dword;
- begin
- Move(HashBuffer,Data,Sizeof(Data));
- A:= CurrentHash[0];
- B:= CurrentHash[1];
- C:= CurrentHash[2];
- D:= CurrentHash[3];
-
- A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 0] + $d76aa478,7);
- D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 1] + $e8c7b756,12);
- C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[ 2] + $242070db,17);
- B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[ 3] + $c1bdceee,22);
- A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 4] + $f57c0faf,7);
- D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 5] + $4787c62a,12);
- C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[ 6] + $a8304613,17);
- B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[ 7] + $fd469501,22);
- A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 8] + $698098d8,7);
- D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 9] + $8b44f7af,12);
- C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[10] + $ffff5bb1,17);
- B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[11] + $895cd7be,22);
- A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[12] + $6b901122,7);
- D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[13] + $fd987193,12);
- C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[14] + $a679438e,17);
- B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[15] + $49b40821,22);
-
- A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[ 1] + $f61e2562,5);
- D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[ 6] + $c040b340,9);
- C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[11] + $265e5a51,14);
- B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[ 0] + $e9b6c7aa,20);
- A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[ 5] + $d62f105d,5);
- D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[10] + $02441453,9);
- C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[15] + $d8a1e681,14);
- B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[ 4] + $e7d3fbc8,20);
- A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[ 9] + $21e1cde6,5);
- D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[14] + $c33707d6,9);
- C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[ 3] + $f4d50d87,14);
- B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[ 8] + $455a14ed,20);
- A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[13] + $a9e3e905,5);
- D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[ 2] + $fcefa3f8,9);
- C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[ 7] + $676f02d9,14);
- B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[12] + $8d2a4c8a,20);
-
- A:= B + LRot32(A + (B xor C xor D) + Data[ 5] + $fffa3942,4);
- D:= A + LRot32(D + (A xor B xor C) + Data[ 8] + $8771f681,11);
- C:= D + LRot32(C + (D xor A xor B) + Data[11] + $6d9d6122,16);
- B:= C + LRot32(B + (C xor D xor A) + Data[14] + $fde5380c,23);
- A:= B + LRot32(A + (B xor C xor D) + Data[ 1] + $a4beea44,4);
- D:= A + LRot32(D + (A xor B xor C) + Data[ 4] + $4bdecfa9,11);
- C:= D + LRot32(C + (D xor A xor B) + Data[ 7] + $f6bb4b60,16);
- B:= C + LRot32(B + (C xor D xor A) + Data[10] + $bebfbc70,23);
- A:= B + LRot32(A + (B xor C xor D) + Data[13] + $289b7ec6,4);
- D:= A + LRot32(D + (A xor B xor C) + Data[ 0] + $eaa127fa,11);
- C:= D + LRot32(C + (D xor A xor B) + Data[ 3] + $d4ef3085,16);
- B:= C + LRot32(B + (C xor D xor A) + Data[ 6] + $04881d05,23);
- A:= B + LRot32(A + (B xor C xor D) + Data[ 9] + $d9d4d039,4);
- D:= A + LRot32(D + (A xor B xor C) + Data[12] + $e6db99e5,11);
- C:= D + LRot32(C + (D xor A xor B) + Data[15] + $1fa27cf8,16);
- B:= C + LRot32(B + (C xor D xor A) + Data[ 2] + $c4ac5665,23);
-
- A:= B + LRot32(A + (C xor (B or (not D))) + Data[ 0] + $f4292244,6);
- D:= A + LRot32(D + (B xor (A or (not C))) + Data[ 7] + $432aff97,10);
- C:= D + LRot32(C + (A xor (D or (not B))) + Data[14] + $ab9423a7,15);
- B:= C + LRot32(B + (D xor (C or (not A))) + Data[ 5] + $fc93a039,21);
- A:= B + LRot32(A + (C xor (B or (not D))) + Data[12] + $655b59c3,6);
- D:= A + LRot32(D + (B xor (A or (not C))) + Data[ 3] + $8f0ccc92,10);
- C:= D + LRot32(C + (A xor (D or (not B))) + Data[10] + $ffeff47d,15);
- B:= C + LRot32(B + (D xor (C or (not A))) + Data[ 1] + $85845dd1,21);
- A:= B + LRot32(A + (C xor (B or (not D))) + Data[ 8] + $6fa87e4f,6);
- D:= A + LRot32(D + (B xor (A or (not C))) + Data[15] + $fe2ce6e0,10);
- C:= D + LRot32(C + (A xor (D or (not B))) + Data[ 6] + $a3014314,15);
- B:= C + LRot32(B + (D xor (C or (not A))) + Data[13] + $4e0811a1,21);
- A:= B + LRot32(A + (C xor (B or (not D))) + Data[ 4] + $f7537e82,6);
- D:= A + LRot32(D + (B xor (A or (not C))) + Data[11] + $bd3af235,10);
- C:= D + LRot32(C + (A xor (D or (not B))) + Data[ 2] + $2ad7d2bb,15);
- B:= C + LRot32(B + (D xor (C or (not A))) + Data[ 9] + $eb86d391,21);
-
- Inc(CurrentHash[0],A);
- Inc(CurrentHash[1],B);
- Inc(CurrentHash[2],C);
- Inc(CurrentHash[3],D);
- Index:= 0;
- FillChar(HashBuffer,Sizeof(HashBuffer),0);
- end;
-
-procedure Update(const Buffer; Size: longword);
+function Int2Hex(Value:dword;Digits:integer=0):AnsiString;
var
- PBuf: ^byte;
+ i:dword;
begin
- Inc(LenHi,Size shr 29);
- Inc(LenLo,Size*8);
- if LenLo < (Size*8) then Inc(LenHi);
- PBuf:= @Buffer;
- while Size> 0 do
- begin
- if (Sizeof(HashBuffer)-Index)<= DWord(Size) then
- begin
- Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index);
- Dec(Size,Sizeof(HashBuffer)-Index);
- Inc(PBuf,Sizeof(HashBuffer)-Index);
- Compress;
- end else
- begin
- Move(PBuf^,HashBuffer[Index],Size);
- Inc(Index,Size);
- Size:= 0;
- end;
- end;
-end;
-
-procedure Final(var Digest);
-begin
- HashBuffer[Index] := $80;
- if Index>= 56 then Compress;
- PDWord(@HashBuffer[56])^ := LenLo;
- PDWord(@HashBuffer[60])^ := LenHi;
- Compress;
- Move(CurrentHash, Digest, Sizeof(CurrentHash));
- Burn;
-end;
-
-begin
- Init;
- Update(s[1], Length(s));
- Final(a);
- result := '';
- for i := 0 to 15 do result := result + Int2Hex(a[i], 2);
- Burn;
+ if Digits<=0 then
+ begin
+ Digits:=0;
+ i:=Value;
+ repeat
+ i:=i shr 4;
+ inc(Digits);
+ until i=0;
+ end;
+ result:='';
+ result[Digits]:=#0;
+ repeat
+ result[Digits]:=AnsiChar(HexDigitChr[Value and $F]);
+ Value:=Value shr 4;
+ Dec(Digits);
+ until Digits=0;
end;
//==============================================================================
-function MD5_arr(s: string): TMD5;
+function MD5_arr(const s: AnsiString): TMD5;
var
a : TMD5;
LenHi, LenLo: longword;
@@ -388,19 +195,16 @@ begin
Update(s[1], Length(s));
Final(a);
result := a;
- Burn;
+end;
+//==============================================================================
+function MD5(const s: AnsiString): AnsiString;
+var
+ a : TMD5;
+ i : integer;
+begin
+ a := MD5_arr(s);
+ result := '';
+ for i := 0 to 15 do result := result + Int2Hex(a[i], 2);
end;
end.
-
-
-
-
-
-
-
-
-
-
-
-