md5 complete + md5sum added as a prog.
git-svn-id: https://spexeah.com:8443/svn/Asuro@971 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
parent
86013b1125
commit
739898068b
@ -207,7 +207,6 @@ type
|
|||||||
Server_Hostname : Array[0..63] of uint8;
|
Server_Hostname : Array[0..63] of uint8;
|
||||||
Boot_File : Array[0..127] of uint8;
|
Boot_File : Array[0..127] of uint8;
|
||||||
Magic_Cookie : Array[0..3] of uint8;
|
Magic_Cookie : Array[0..3] of uint8;
|
||||||
Option_start : char;
|
|
||||||
end;
|
end;
|
||||||
PDHCPHeader = ^TDHCPHeader;
|
PDHCPHeader = ^TDHCPHeader;
|
||||||
TDHCPOpCode = (
|
TDHCPOpCode = (
|
||||||
|
@ -5,7 +5,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
lmemorymanager, console,
|
lmemorymanager, console,
|
||||||
nettypes, netutils, udp, netlog, net,
|
nettypes, netutils, udp, netlog, net,
|
||||||
util, rand, lists;
|
util, rand, lists, tracer;
|
||||||
|
|
||||||
type
|
type
|
||||||
TDHCPOptions = PLinkedListBase;
|
TDHCPOptions = PLinkedListBase;
|
||||||
@ -14,7 +14,6 @@ type
|
|||||||
Opcode : TDHCPOpCode;
|
Opcode : TDHCPOpCode;
|
||||||
Size : uint32;
|
Size : uint32;
|
||||||
Value : void;
|
Value : void;
|
||||||
Header_Location : void;
|
|
||||||
Reverse_Endian : boolean;
|
Reverse_Endian : boolean;
|
||||||
end;
|
end;
|
||||||
PDHCPOption = ^TDHCPOption;
|
PDHCPOption = ^TDHCPOption;
|
||||||
@ -25,8 +24,124 @@ procedure DHCPDiscover();
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
var
|
var
|
||||||
XID : uint32;
|
XID : uint32;
|
||||||
Socket : PUDPBindContext;
|
Socket : PUDPBindContext;
|
||||||
|
FlipExclude : bitpacked Array[0..255] of boolean;
|
||||||
|
|
||||||
|
procedure newOption(DHCPOptions : PDHCPOptions; Opcode : TDHCPOpCode; Data : void; Length : uint32; SwapEndian : Boolean);
|
||||||
|
var
|
||||||
|
Option : PDHCPOption;
|
||||||
|
read32 : puint32;
|
||||||
|
read16 : puint16;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Option:= PDHCPOption(LL_Add(PLinkedListBase(DHCPOptions)));
|
||||||
|
Option^.Opcode:= Opcode;
|
||||||
|
Option^.Size:= Length;
|
||||||
|
Option^.Reverse_Endian:= SwapEndian;
|
||||||
|
if Length > 0 then begin
|
||||||
|
Option^.Value:= kalloc(Length);
|
||||||
|
memcpy(uint32(Data), uint32(Option^.Value), Length);
|
||||||
|
if Length = 2 then begin
|
||||||
|
if SwapEndian then begin
|
||||||
|
read16:= puint16(Option^.Value);
|
||||||
|
read16^:= switchendian16(read16^);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if Length = 4 then begin
|
||||||
|
if SwapEndian then begin
|
||||||
|
read32:= puint32(Option^.Value);
|
||||||
|
read32^:= switchendian32(read32^);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
|
Option^.Value:= nil;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure deleteOption(DHCPOptions : PDHCPOptions; idx : uint32);
|
||||||
|
var
|
||||||
|
Option : PDHCPOption;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Option:= PDHCPOption(LL_Get(PLinkedListBase(DHCPOptions), idx));
|
||||||
|
if Option <> nil then begin
|
||||||
|
if Option^.Value <> nil then begin
|
||||||
|
kfree(Option^.Value);
|
||||||
|
end;
|
||||||
|
LL_Delete(PLinkedListBase(DHCPOptions), idx);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function newOptions : PDHCPOptions;
|
||||||
|
begin
|
||||||
|
newOptions:= PDHCPOptions(LL_New(sizeof(TDHCPOption)));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure freeOptions(Options : PDHCPOptions);
|
||||||
|
begin
|
||||||
|
if Options <> nil then begin
|
||||||
|
while LL_Size(PLinkedListBase(Options)) > 0 do begin
|
||||||
|
deleteOption(Options, 0);
|
||||||
|
end;
|
||||||
|
LL_Free(PLinkedListBase(Options));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function writeOptions(Header : PDHCPHeader; Options : PDHCPOptions; newLength : puint16) : PDHCPHeader;
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure readOptions(DHCPOptions : PDHCPOptions; p_data : void; p_len : uint16);
|
||||||
|
var
|
||||||
|
headerSize : uint32;
|
||||||
|
|
||||||
|
buffer : puint8;
|
||||||
|
|
||||||
|
bufferEnd : puint8;
|
||||||
|
bufferStart : puint8;
|
||||||
|
|
||||||
|
HaveOp : boolean;
|
||||||
|
HaveLen : boolean;
|
||||||
|
|
||||||
|
Opcode : TDHCPOpCode;
|
||||||
|
Length : uint8;
|
||||||
|
|
||||||
|
begin
|
||||||
|
HeaderSize:= sizeOf(TDHCPHeader);
|
||||||
|
bufferEnd:= puint8(uint32(p_data) + p_len);
|
||||||
|
bufferStart:= puint8(uint32(p_data) + headerSize);
|
||||||
|
buffer:= bufferStart;
|
||||||
|
HaveOp:= false;
|
||||||
|
HaveLen:= false;
|
||||||
|
while (uint32(buffer) < uint32(bufferEnd)) do begin
|
||||||
|
if HaveLen then begin
|
||||||
|
newOption(DHCPOptions, Opcode, void(buffer), Length, not FlipExclude[ord(Opcode)]);
|
||||||
|
inc(buffer, Length);
|
||||||
|
HaveOp:= false;
|
||||||
|
HaveLen:= false;
|
||||||
|
end else if HaveOp then begin
|
||||||
|
Length:= buffer^;
|
||||||
|
HaveLen:= true;
|
||||||
|
inc(buffer);
|
||||||
|
end else begin
|
||||||
|
Opcode:= TDHCPOpCode(buffer^);
|
||||||
|
case opcode of
|
||||||
|
PAD:begin
|
||||||
|
Length:= 0;
|
||||||
|
haveLen:= true;
|
||||||
|
end;
|
||||||
|
END_VENDOR_OPTIONS:begin
|
||||||
|
Length:= 0;
|
||||||
|
haveLen:= true;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
HaveOp:= true;
|
||||||
|
inc(buffer)
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure processPacket(p_data : void; p_len : uint16; context : PUDPPacketContext);
|
procedure processPacket(p_data : void; p_len : uint16; context : PUDPPacketContext);
|
||||||
begin
|
begin
|
||||||
@ -39,8 +154,71 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure register();
|
procedure register();
|
||||||
|
var
|
||||||
|
i : uint8;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
tracer.push_trace('dhcp.register');
|
||||||
console.outputln('DHCP', 'Register begin.');
|
console.outputln('DHCP', 'Register begin.');
|
||||||
|
for i:=0 to 255 do begin
|
||||||
|
FlipExclude[i]:= false;
|
||||||
|
end;
|
||||||
|
// FlipExclude[ord(PAD)]:= true;
|
||||||
|
// FlipExclude[ord(SUBNET_MASK)]:= true;
|
||||||
|
// FlipExclude[ord(ROUTER)]:= true;
|
||||||
|
// FlipExclude[ord(TIME_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(NAME_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(DNS_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(LOG_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(COOKIE_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(LPR_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(IMPRESS_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(RESOURCE_LOCATION_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(HOST_NAME)]:= true;
|
||||||
|
// FlipExclude[ord(MERIT_DUMP_FILE)]:= true;
|
||||||
|
// FlipExclude[ord(DOMAIN_NAME)]:= true;
|
||||||
|
// FlipExclude[ord(SWAP_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(ROOT_PATH)]:= true;
|
||||||
|
// FlipExclude[ord(EXTENSIONS_PATH)]:= true;
|
||||||
|
// FlipExclude[ord(END_VENDOR_OPTIONS)]:= true;
|
||||||
|
// FlipExclude[ord(BROADCAST_ADDRESS)]:= true;
|
||||||
|
// FlipExclude[ord(ROUTER_SOLICITATION_ADDRESS)]:= true;
|
||||||
|
// FlipExclude[ord(STATIC_ROUTE)]:= true;
|
||||||
|
// FlipExclude[ord(NETWORK_INFORMATION_SERVICE_DOMAIN)]:= true;
|
||||||
|
// FlipExclude[ord(NETWORK_INFORMATION_SERVERS)]:= true;
|
||||||
|
// FlipExclude[ord(NTP_SERVERS)]:= true;
|
||||||
|
// FlipExclude[ord(VENDOR_SPECIFIC_INFORMATION)]:= true;
|
||||||
|
// FlipExclude[ord(NETBIOS_OVER_TCP_NAME_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(NETBIOS_OVER_TCP_DATAGRAM_DISTRIBUTION_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(NETBIOS_OVER_TCP_SCOPE)]:= true;
|
||||||
|
// FlipExclude[ord(X_WINDOW_SYSTEM_FONT_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(X_WINDOW_SYSTEM_DISPLAY_MANAGER)]:= true;
|
||||||
|
// FlipExclude[ord(NETWORK_INFORMATION_SERVICE_PLUS_DOMAIN)]:= true;
|
||||||
|
// FlipExclude[ord(NETWORK_INFORMATION_SERVICE_PLUS_SERVERS)]:= true;
|
||||||
|
// FlipExclude[ord(MOBILE_IP_HOME_AGENT)]:= true;
|
||||||
|
// FlipExclude[ord(SMTP_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(POP3_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(NNTP_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(DEFAULT_WWW_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(DEFAULT_FINGER_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(DEFAULT_IRC_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(STREETTALK_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(STDA_SERVER)]:= true;
|
||||||
|
// FlipExclude[ord(REQUESTED_IP_ADDRESS)]:= true;
|
||||||
|
// FlipExclude[ord(SERVER_IDENTIFIER)]:= true;
|
||||||
|
// FlipExclude[ord(PARAMETER_REQUEST_LIST)]:= true;
|
||||||
|
// FlipExclude[ord(VENDOR_CLASS_IDENTIFIER)]:= true;
|
||||||
|
// FlipExclude[ord(CLIENT_IDENTIFIER)]:= true;
|
||||||
|
// FlipExclude[ord(TFTP_SERVER_NAME)]:= true;
|
||||||
|
// FlipExclude[ord(BOOTFILE_NAME)]:= true;
|
||||||
|
// FlipExclude[ord(RELAY_AGENT_INFORMATION)]:= true;
|
||||||
|
// FlipExclude[ord(NDS_SERVERS)]:= true;
|
||||||
|
// FlipExclude[ord(NDS_TREE_NAME)]:= true;
|
||||||
|
// FlipExclude[ord(NDS_CONTEXT)]:= true;
|
||||||
|
// FlipExclude[ord(POSIX_TIMEZONE)]:= true;
|
||||||
|
// FlipExclude[ord(TZ_TIMEZONE)]:= true;
|
||||||
|
// FlipExclude[ord(DOMAIN_SEARCH)]:= true;
|
||||||
|
// FlipExclude[ord(CLASSLESS_STATIC_ROUTE)]:= true;
|
||||||
Socket:= PUDPBindContext(Kalloc(sizeof(TUDPBindContext)));
|
Socket:= PUDPBindContext(Kalloc(sizeof(TUDPBindContext)));
|
||||||
Socket^.Port:= 68;
|
Socket^.Port:= 68;
|
||||||
Socket^.Callback:= @processPacket;
|
Socket^.Callback:= @processPacket;
|
||||||
|
@ -41,6 +41,7 @@ var
|
|||||||
I : uInt32;
|
I : uInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
tracer.push_trace('MD5.Invert');
|
||||||
S := Source;
|
S := Source;
|
||||||
T := Dest;
|
T := Dest;
|
||||||
for I := 1 to (Count div 4) do begin
|
for I := 1 to (Count div 4) do begin
|
||||||
@ -50,65 +51,94 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure MD5Transform(context : PMD5Context; buffer : PuInt8);
|
procedure MD5Transform(Context: PMD5Context; Buffer: Pointer);
|
||||||
procedure R1(a : PuInt32; b,c,d,x : uInt32; s : uInt8; ac : uInt32);
|
type
|
||||||
begin
|
TBlock = array[0..15] of Cardinal;
|
||||||
a^ := b + RolDWord(uInt32(a^ + ((b and c) or ((not b) and d)) + x + ac), s);
|
PBlock = ^TBlock;
|
||||||
end;
|
|
||||||
procedure R2(a : PuInt32; b,c,d,x : uInt32; s : uInt8; ac : uInt32);
|
|
||||||
begin
|
|
||||||
a^ := b + RolDWord(uInt32(a^ + ((b and d) or (c and (not d))) + x + ac), s);
|
|
||||||
end;
|
|
||||||
procedure R3(a : PuInt32; b,c,d,x : uInt32; s : uInt8; ac : uInt32);
|
|
||||||
begin
|
|
||||||
a^ := b + RolDWord(uInt32(a^ + (b xor c xor d) + x + ac), s);
|
|
||||||
end;
|
|
||||||
procedure R4(a : PuInt32; b,c,d,x : uInt32; s : uInt8; ac : uInt32);
|
|
||||||
begin
|
|
||||||
a^ := b + RolDWord(uInt32(a^ + (c xor (b or (not d))) + x + ac), s);
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
var
|
||||||
a, b, c, d : uInt32;
|
a, b, c, d: Cardinal;
|
||||||
Block : array[0..15] of uInt32;
|
//Block: array[0..15] of Cardinal absolute Buffer;
|
||||||
|
Block: PBlock absolute Buffer;
|
||||||
begin
|
begin
|
||||||
Invert(Buffer, @Block, 64);
|
tracer.push_trace('MD5.MD5Transform');
|
||||||
a := context^.State[0];
|
//Invert(Buffer, @Block, 64);
|
||||||
b := context^.State[1];
|
a := Context^.State[0];
|
||||||
c := context^.State[2];
|
b := Context^.State[1];
|
||||||
d := context^.State[3];
|
c := Context^.State[2];
|
||||||
|
d := Context^.State[3];
|
||||||
// Round 1
|
// Round 1
|
||||||
R1(PuInt32(@a),b,c,d,Block[0] , 7,$d76aa478); R1(PuInt32(@d),a,b,c,Block[1] ,12,$e8c7b756); R1(PuInt32(@c),d,a,b,Block[2] ,17,$242070db); R1(PuInt32(@b),c,d,a,Block[3] ,22,$c1bdceee);
|
a := b + roldword(dword(a + ((b and c) or ((not b) and d)) + Block^[0] + $d76aa478), 7);
|
||||||
R1(PuInt32(@a),b,c,d,Block[4] , 7,$f57c0faf); R1(PuInt32(@d),a,b,c,Block[5] ,12,$4787c62a); R1(PuInt32(@c),d,a,b,Block[6] ,17,$a8304613); R1(PuInt32(@b),c,d,a,Block[7] ,22,$fd469501);
|
d := a + roldword(dword(d + ((a and b) or ((not a) and c)) + Block^[1] + $e8c7b756), 12);
|
||||||
R1(PuInt32(@a),b,c,d,Block[8] , 7,$698098d8); R1(PuInt32(@d),a,b,c,Block[9] ,12,$8b44f7af); R1(PuInt32(@c),d,a,b,Block[10],17,$ffff5bb1); R1(PuInt32(@b),c,d,a,Block[11],22,$895cd7be);
|
c := d + roldword(dword(c + ((d and a) or ((not d) and b)) + Block^[2] + $242070db), 17);
|
||||||
R1(PuInt32(@a),b,c,d,Block[12], 7,$6b901122); R1(PuInt32(@d),a,b,c,Block[13],12,$fd987193); R1(PuInt32(@c),d,a,b,Block[14],17,$a679438e); R1(PuInt32(@b),c,d,a,Block[15],22,$49b40821);
|
b := c + roldword(dword(b + ((c and d) or ((not c) and a)) + Block^[3] + $c1bdceee), 22);
|
||||||
|
a := b + roldword(dword(a + ((b and c) or ((not b) and d)) + Block^[4] + $f57c0faf), 7);
|
||||||
|
d := a + roldword(dword(d + ((a and b) or ((not a) and c)) + Block^[5] + $4787c62a), 12);
|
||||||
|
c := d + roldword(dword(c + ((d and a) or ((not d) and b)) + Block^[6] + $a8304613), 17);
|
||||||
|
b := c + roldword(dword(b + ((c and d) or ((not c) and a)) + Block^[7] + $fd469501), 22);
|
||||||
|
a := b + roldword(dword(a + ((b and c) or ((not b) and d)) + Block^[8] + $698098d8), 7);
|
||||||
|
d := a + roldword(dword(d + ((a and b) or ((not a) and c)) + Block^[9] + $8b44f7af), 12);
|
||||||
|
c := d + roldword(dword(c + ((d and a) or ((not d) and b)) + Block^[10] + $ffff5bb1), 17);
|
||||||
|
b := c + roldword(dword(b + ((c and d) or ((not c) and a)) + Block^[11] + $895cd7be), 22);
|
||||||
|
a := b + roldword(dword(a + ((b and c) or ((not b) and d)) + Block^[12] + $6b901122), 7);
|
||||||
|
d := a + roldword(dword(d + ((a and b) or ((not a) and c)) + Block^[13] + $fd987193), 12);
|
||||||
|
c := d + roldword(dword(c + ((d and a) or ((not d) and b)) + Block^[14] + $a679438e), 17);
|
||||||
|
b := c + roldword(dword(b + ((c and d) or ((not c) and a)) + Block^[15] + $49b40821), 22);
|
||||||
// Round 2
|
// Round 2
|
||||||
R2(PuInt32(@a),b,c,d,Block[1] , 5,$f61e2562); R2(PuInt32(@d),a,b,c,Block[6] , 9,$c040b340); R2(PuInt32(@c),d,a,b,Block[11],14,$265e5a51); R2(PuInt32(@b),c,d,a,Block[0] ,20,$e9b6c7aa);
|
a := b + roldword(dword(a + ((b and d) or (c and (not d))) + Block^[1] + $f61e2562), 5);
|
||||||
R2(PuInt32(@a),b,c,d,Block[5] , 5,$d62f105d); R2(PuInt32(@d),a,b,c,Block[10], 9,$02441453); R2(PuInt32(@c),d,a,b,Block[15],14,$d8a1e681); R2(PuInt32(@b),c,d,a,Block[4] ,20,$e7d3fbc8);
|
d := a + roldword(dword(d + ((a and c) or (b and (not c))) + Block^[6] + $c040b340), 9);
|
||||||
R2(PuInt32(@a),b,c,d,Block[9] , 5,$21e1cde6); R2(PuInt32(@d),a,b,c,Block[14], 9,$c33707d6); R2(PuInt32(@c),d,a,b,Block[3] ,14,$f4d50d87); R2(PuInt32(@b),c,d,a,Block[8] ,20,$455a14ed);
|
c := d + roldword(dword(c + ((d and b) or (a and (not b))) + Block^[11] + $265e5a51), 14);
|
||||||
R2(PuInt32(@a),b,c,d,Block[13], 5,$a9e3e905); R2(PuInt32(@d),a,b,c,Block[2] , 9,$fcefa3f8); R2(PuInt32(@c),d,a,b,Block[7] ,14,$676f02d9); R2(PuInt32(@b),c,d,a,Block[12],20,$8d2a4c8a);
|
b := c + roldword(dword(b + ((c and a) or (d and (not a))) + Block^[0] + $e9b6c7aa), 20);
|
||||||
|
a := b + roldword(dword(a + ((b and d) or (c and (not d))) + Block^[5] + $d62f105d), 5);
|
||||||
|
d := a + roldword(dword(d + ((a and c) or (b and (not c))) + Block^[10] + $02441453), 9);
|
||||||
|
c := d + roldword(dword(c + ((d and b) or (a and (not b))) + Block^[15] + $d8a1e681), 14);
|
||||||
|
b := c + roldword(dword(b + ((c and a) or (d and (not a))) + Block^[4] + $e7d3fbc8), 20);
|
||||||
|
a := b + roldword(dword(a + ((b and d) or (c and (not d))) + Block^[9] + $21e1cde6), 5);
|
||||||
|
d := a + roldword(dword(d + ((a and c) or (b and (not c))) + Block^[14] + $c33707d6), 9);
|
||||||
|
c := d + roldword(dword(c + ((d and b) or (a and (not b))) + Block^[3] + $f4d50d87), 14);
|
||||||
|
b := c + roldword(dword(b + ((c and a) or (d and (not a))) + Block^[8] + $455a14ed), 20);
|
||||||
|
a := b + roldword(dword(a + ((b and d) or (c and (not d))) + Block^[13] + $a9e3e905), 5);
|
||||||
|
d := a + roldword(dword(d + ((a and c) or (b and (not c))) + Block^[2] + $fcefa3f8), 9);
|
||||||
|
c := d + roldword(dword(c + ((d and b) or (a and (not b))) + Block^[7] + $676f02d9), 14);
|
||||||
|
b := c + roldword(dword(b + ((c and a) or (d and (not a))) + Block^[12] + $8d2a4c8a), 20);
|
||||||
// Round 3
|
// Round 3
|
||||||
R3(PuInt32(@a),b,c,d,Block[5] , 4,$fffa3942); R3(PuInt32(@d),a,b,c,Block[8] ,11,$8771f681); R3(PuInt32(@c),d,a,b,Block[11],16,$6d9d6122); R3(PuInt32(@b),c,d,a,Block[14],23,$fde5380c);
|
a := b + roldword(dword(a + (b xor c xor d) + Block^[5] + $fffa3942), 4);
|
||||||
R3(PuInt32(@a),b,c,d,Block[1] , 4,$a4beea44); R3(PuInt32(@d),a,b,c,Block[4] ,11,$4bdecfa9); R3(PuInt32(@c),d,a,b,Block[7] ,16,$f6bb4b60); R3(PuInt32(@b),c,d,a,Block[10],23,$bebfbc70);
|
d := a + roldword(dword(d + (a xor b xor c) + Block^[8] + $8771f681), 11);
|
||||||
R3(PuInt32(@a),b,c,d,Block[13], 4,$289b7ec6); R3(PuInt32(@d),a,b,c,Block[0] ,11,$eaa127fa); R3(PuInt32(@c),d,a,b,Block[3] ,16,$d4ef3085); R3(PuInt32(@b),c,d,a,Block[6] ,23,$04881d05);
|
c := d + roldword(dword(c + (d xor a xor b) + Block^[11] + $6d9d6122), 16);
|
||||||
R3(PuInt32(@a),b,c,d,Block[9] , 4,$d9d4d039); R3(PuInt32(@d),a,b,c,Block[12],11,$e6db99e5); R3(PuInt32(@c),d,a,b,Block[15],16,$1fa27cf8); R3(PuInt32(@b),c,d,a,Block[2] ,23,$c4ac5665);
|
b := c + roldword(dword(b + (c xor d xor a) + Block^[14] + $fde5380c), 23);
|
||||||
|
a := b + roldword(dword(a + (b xor c xor d) + Block^[1] + $a4beea44), 4);
|
||||||
|
d := a + roldword(dword(d + (a xor b xor c) + Block^[4] + $4bdecfa9), 11);
|
||||||
|
c := d + roldword(dword(c + (d xor a xor b) + Block^[7] + $f6bb4b60), 16);
|
||||||
|
b := c + roldword(dword(b + (c xor d xor a) + Block^[10] + $bebfbc70), 23);
|
||||||
|
a := b + roldword(dword(a + (b xor c xor d) + Block^[13] + $289b7ec6), 4);
|
||||||
|
d := a + roldword(dword(d + (a xor b xor c) + Block^[0] + $eaa127fa), 11);
|
||||||
|
c := d + roldword(dword(c + (d xor a xor b) + Block^[3] + $d4ef3085), 16);
|
||||||
|
b := c + roldword(dword(b + (c xor d xor a) + Block^[6] + $04881d05), 23);
|
||||||
|
a := b + roldword(dword(a + (b xor c xor d) + Block^[9] + $d9d4d039), 4);
|
||||||
|
d := a + roldword(dword(d + (a xor b xor c) + Block^[12] + $e6db99e5), 11);
|
||||||
|
c := d + roldword(dword(c + (d xor a xor b) + Block^[15] + $1fa27cf8), 16);
|
||||||
|
b := c + roldword(dword(b + (c xor d xor a) + Block^[2] + $c4ac5665), 23);
|
||||||
// Round 4
|
// Round 4
|
||||||
R4(PuInt32(@a),b,c,d,Block[0] , 6,$f4292244); R4(PuInt32(@d),a,b,c,Block[7] ,10,$432aff97); R4(PuInt32(@c),d,a,b,Block[14],15,$ab9423a7); R4(PuInt32(@b),c,d,a,Block[5] ,21,$fc93a039);
|
a := b + roldword(dword(a + (c xor (b or (not d))) + Block^[0] + $f4292244), 6);
|
||||||
R4(PuInt32(@a),b,c,d,Block[12], 6,$655b59c3); R4(PuInt32(@d),a,b,c,Block[3] ,10,$8f0ccc92); R4(PuInt32(@c),d,a,b,Block[10],15,$ffeff47d); R4(PuInt32(@b),c,d,a,Block[1] ,21,$85845dd1);
|
d := a + roldword(dword(d + (b xor (a or (not c))) + Block^[7] + $432aff97), 10);
|
||||||
R4(PuInt32(@a),b,c,d,Block[8] , 6,$6fa87e4f); R4(PuInt32(@d),a,b,c,Block[15],10,$fe2ce6e0); R4(PuInt32(@c),d,a,b,Block[6] ,15,$a3014314); R4(PuInt32(@b),c,d,a,Block[13],21,$4e0811a1);
|
c := d + roldword(dword(c + (a xor (d or (not b))) + Block^[14] + $ab9423a7), 15);
|
||||||
R4(PuInt32(@a),b,c,d,Block[4] , 6,$f7537e82); R4(PuInt32(@d),a,b,c,Block[11],10,$bd3af235); R4(PuInt32(@c),d,a,b,Block[2] ,15,$2ad7d2bb); R4(PuInt32(@b),c,d,a,Block[9] ,21,$eb86d391);
|
b := c + roldword(dword(b + (d xor (c or (not a))) + Block^[5] + $fc93a039), 21);
|
||||||
|
a := b + roldword(dword(a + (c xor (b or (not d))) + Block^[12] + $655b59c3), 6);
|
||||||
inc(context^.State[0],a);
|
d := a + roldword(dword(d + (b xor (a or (not c))) + Block^[3] + $8f0ccc92), 10);
|
||||||
inc(context^.State[1],b);
|
c := d + roldword(dword(c + (a xor (d or (not b))) + Block^[10] + $ffeff47d), 15);
|
||||||
inc(context^.State[2],c);
|
b := c + roldword(dword(b + (d xor (c or (not a))) + Block^[1] + $85845dd1), 21);
|
||||||
inc(context^.State[3],d);
|
a := b + roldword(dword(a + (c xor (b or (not d))) + Block^[8] + $6fa87e4f), 6);
|
||||||
|
d := a + roldword(dword(d + (b xor (a or (not c))) + Block^[15] + $fe2ce6e0), 10);
|
||||||
inc(context^.Length,64);
|
c := d + roldword(dword(c + (a xor (d or (not b))) + Block^[6] + $a3014314), 15);
|
||||||
|
b := c + roldword(dword(b + (d xor (c or (not a))) + Block^[13] + $4e0811a1), 21);
|
||||||
|
a := b + roldword(dword(a + (c xor (b or (not d))) + Block^[4] + $f7537e82), 6);
|
||||||
|
d := a + roldword(dword(d + (b xor (a or (not c))) + Block^[11] + $bd3af235), 10);
|
||||||
|
c := d + roldword(dword(c + (a xor (d or (not b))) + Block^[2] + $2ad7d2bb), 15);
|
||||||
|
b := c + roldword(dword(b + (d xor (c or (not a))) + Block^[9] + $eb86d391), 21);
|
||||||
|
inc(Context^.State[0],a);
|
||||||
|
inc(Context^.State[1],b);
|
||||||
|
inc(Context^.State[2],c);
|
||||||
|
inc(Context^.State[3],d);
|
||||||
|
inc(Context^.Length,64);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure MD5Init(context : PMD5Context);
|
procedure MD5Init(context : PMD5Context);
|
||||||
@ -129,34 +159,31 @@ var
|
|||||||
Align : uInt32;
|
Align : uInt32;
|
||||||
Src : PuInt8;
|
Src : PuInt8;
|
||||||
Num : uInt32;
|
Num : uInt32;
|
||||||
|
i : uint32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
tracer.push_trace('MD5.MD5Update');
|
tracer.push_trace('MD5.MD5Update');
|
||||||
if bufferLen = 0 then Exit;
|
if bufferLen = 0 then Exit;
|
||||||
|
|
||||||
Align := context^.Align;
|
Align := context^.Align;
|
||||||
Src := buffer;
|
Src := buffer;
|
||||||
Num := 0;
|
Num := 0;
|
||||||
|
|
||||||
if context^.BufferCount > 0 then begin
|
if context^.BufferCount > 0 then begin
|
||||||
Num := Align - context^.BufferCount;
|
Num := Align - context^.BufferCount;
|
||||||
if Num > bufferLen then
|
if Num > bufferLen then num := bufferLen;
|
||||||
num := bufferLen;
|
memcpy(uInt32(Src), uInt32(@context^.Buffer[Context^.BufferCount]), Num);
|
||||||
memcpy(uInt32(Src), uInt32(@context^.Buffer[0]), Num);
|
|
||||||
context^.BufferCount := context^.BufferCount + Num;
|
context^.BufferCount := context^.BufferCount + Num;
|
||||||
Src := PuInt8(uInt32(Src) + Num);
|
Src := PuInt8(uInt32(Src) + uint32(Num));
|
||||||
if context^.BufferCount = Align then begin
|
if context^.BufferCount = Align then begin
|
||||||
MD5Transform(context, @context^.buffer[0]);
|
MD5Transform(context, @context^.buffer[0]);
|
||||||
context^.BufferCount := 0;
|
context^.BufferCount := 0;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Num := bufferLen - Num;
|
Num := bufferLen - Num;
|
||||||
While Num >= Align do begin
|
While Num >= Align do begin
|
||||||
MD5Transform(context, Src);
|
MD5Transform(context, Src);
|
||||||
Src := PuInt8(uInt32(Src) + Align);
|
Src := PuInt8(uInt32(Src) + Align);
|
||||||
Num := Num - Align;
|
Num := Num - Align;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if Num > 0 then begin
|
if Num > 0 then begin
|
||||||
context^.BufferCount := Num;
|
context^.BufferCount := Num;
|
||||||
memcpy(uInt32(Src), uInt32(@context^.Buffer[0]), Num);
|
memcpy(uInt32(Src), uInt32(@context^.Buffer[0]), Num);
|
||||||
@ -170,6 +197,8 @@ var
|
|||||||
Length : uInt64;
|
Length : uInt64;
|
||||||
Pads : uInt32;
|
Pads : uInt32;
|
||||||
Digest : PMD5Digest;
|
Digest : PMD5Digest;
|
||||||
|
i : uint32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
tracer.push_trace('MD5.MD5Final');
|
tracer.push_trace('MD5.MD5Final');
|
||||||
Length := 8 * (context^.Length + context^.BufferCount);
|
Length := 8 * (context^.Length + context^.BufferCount);
|
||||||
@ -178,13 +207,10 @@ begin
|
|||||||
else
|
else
|
||||||
Pads := 56 - context^.BufferCount;
|
Pads := 56 - context^.BufferCount;
|
||||||
MD5Update(context, PuInt8(@MD5_Padding[0]), Pads);
|
MD5Update(context, PuInt8(@MD5_Padding[0]), Pads);
|
||||||
|
|
||||||
MD5Update(context, PuInt8(@Length), 8);
|
MD5Update(context, PuInt8(@Length), 8);
|
||||||
|
|
||||||
Digest := PMD5Digest(kalloc(SizeOf(TMD5Digest)));
|
Digest := PMD5Digest(kalloc(SizeOf(TMD5Digest)));
|
||||||
memset(uInt32(Digest), 0, SizeOf(TMD5Digest));
|
memset(uInt32(Digest), 0, SizeOf(TMD5Digest));
|
||||||
Invert(PuInt8(@context^.State[0]), PuInt32(@Digest[0]), 16);
|
Invert(PuInt8(@context^.State), PuInt32(Digest), 16);
|
||||||
|
|
||||||
memset(uInt32(context), 0, SizeOf(TMD5Context));
|
memset(uInt32(context), 0, SizeOf(TMD5Context));
|
||||||
MD5Final := Digest;
|
MD5Final := Digest;
|
||||||
end;
|
end;
|
||||||
@ -195,22 +221,10 @@ var
|
|||||||
begin
|
begin
|
||||||
tracer.push_trace('MD5.MD5Buffer');
|
tracer.push_trace('MD5.MD5Buffer');
|
||||||
context := PMD5Context(kalloc(SizeOf(TMD5Context)));
|
context := PMD5Context(kalloc(SizeOf(TMD5Context)));
|
||||||
memset(uInt32(context), 0, SizeOf(TMD5Context));
|
MD5Init(context);
|
||||||
outputln('md5', 'Init');
|
MD5Update(context, buffer, bufferLen);
|
||||||
console.redrawwindows;
|
MD5Buffer := MD5Final(context);
|
||||||
MD5Init(@context);
|
kfree(void(context));
|
||||||
outputln('md5', 'Init Done');
|
|
||||||
console.redrawwindows;
|
|
||||||
outputln('md5', 'Update');
|
|
||||||
console.redrawwindows;
|
|
||||||
MD5Update(@context, buffer, bufferLen);
|
|
||||||
outputln('md5', 'Update Done');
|
|
||||||
console.redrawwindows;
|
|
||||||
outputln('md5', 'Final');
|
|
||||||
console.redrawwindows;
|
|
||||||
MD5Buffer := MD5Final(@context);
|
|
||||||
outputln('md5', 'Final Done');
|
|
||||||
console.redrawwindows;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
@ -21,7 +21,6 @@ type
|
|||||||
hresult = cardinal;
|
hresult = cardinal;
|
||||||
dword = cardinal;
|
dword = cardinal;
|
||||||
integer = longint;
|
integer = longint;
|
||||||
|
|
||||||
pchar = ^char;
|
pchar = ^char;
|
||||||
|
|
||||||
//Standard Types
|
//Standard Types
|
||||||
|
@ -502,7 +502,7 @@ begin
|
|||||||
for i:=0 to Dist-1 do begin
|
for i:=0 to Dist-1 do begin
|
||||||
asm
|
asm
|
||||||
MOV EAX, result
|
MOV EAX, result
|
||||||
ROL result, 1
|
ROL EAX, 1
|
||||||
MOV result, EAX
|
MOV result, EAX
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -525,7 +525,7 @@ begin
|
|||||||
for i:=0 to Dist-1 do begin
|
for i:=0 to Dist-1 do begin
|
||||||
asm
|
asm
|
||||||
MOV EAX, result
|
MOV EAX, result
|
||||||
ROR result, 1
|
ROR EAX, 1
|
||||||
MOV result, EAX
|
MOV result, EAX
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -46,7 +46,7 @@ uses
|
|||||||
edit,
|
edit,
|
||||||
udpcat,
|
udpcat,
|
||||||
cpu,
|
cpu,
|
||||||
md5,
|
md5, md5sum,
|
||||||
rand;
|
rand;
|
||||||
|
|
||||||
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
|
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
|
||||||
@ -99,8 +99,6 @@ var
|
|||||||
test : puint8;
|
test : puint8;
|
||||||
fb : puint16;
|
fb : puint16;
|
||||||
l : PLinkedListBase;
|
l : PLinkedListBase;
|
||||||
MD5_Data : array [0..4] of Char = ('h','e','l','l','o');
|
|
||||||
MD5_Hash : PMD5Digest;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
{ Serial Init }
|
{ Serial Init }
|
||||||
@ -210,7 +208,7 @@ begin
|
|||||||
net.init;
|
net.init;
|
||||||
|
|
||||||
tracer.push_trace('kmain.VMINIT');
|
tracer.push_trace('kmain.VMINIT');
|
||||||
vm.init();
|
//vm.init();
|
||||||
|
|
||||||
{ Init Progs }
|
{ Init Progs }
|
||||||
tracer.push_trace('kmain.SHELLINIT');
|
tracer.push_trace('kmain.SHELLINIT');
|
||||||
@ -228,19 +226,13 @@ begin
|
|||||||
tracer.push_trace('kmain.EDIT');
|
tracer.push_trace('kmain.EDIT');
|
||||||
edit.init();
|
edit.init();
|
||||||
udpcat.init();
|
udpcat.init();
|
||||||
|
md5sum.init();
|
||||||
terminal.run();
|
terminal.run();
|
||||||
|
|
||||||
{ Init Splash }
|
{ Init Splash }
|
||||||
//tracer.push_trace('kmain.SPLASHINIT');
|
//tracer.push_trace('kmain.SPLASHINIT');
|
||||||
//splash.init();
|
//splash.init();
|
||||||
|
|
||||||
writestring('MD5_Hash: ');
|
|
||||||
MD5_Hash := MD5Buffer(puint8(@MD5_Data[0]), 5);
|
|
||||||
for i := 0 to 15 do begin
|
|
||||||
writehexpair(MD5_Hash^[i]);
|
|
||||||
end;
|
|
||||||
writestringln(' ');
|
|
||||||
|
|
||||||
{ End of Boot }
|
{ End of Boot }
|
||||||
tracer.push_trace('kmain.EOB');
|
tracer.push_trace('kmain.EOB');
|
||||||
|
|
||||||
|
40
src/prog/md5sum.pas
Normal file
40
src/prog/md5sum.pas
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
Prog->VMLog - Virtual Machine Event Log.
|
||||||
|
|
||||||
|
@author(Kieron Morris <kjm@kieronmorris.me>)
|
||||||
|
}
|
||||||
|
unit md5sum;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
console, terminal, keyboard, util, strings, tracer, md5;
|
||||||
|
|
||||||
|
procedure init();
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
procedure run(Params : PParamList);
|
||||||
|
var
|
||||||
|
md5word : pchar;
|
||||||
|
wordlen : uint32;
|
||||||
|
MD5_Hash : PMD5Digest;
|
||||||
|
i : uint32;
|
||||||
|
|
||||||
|
begin
|
||||||
|
md5word:= getParam(0, Params);
|
||||||
|
wordlen:= stringSize(md5word);
|
||||||
|
MD5_Hash := MD5Buffer(puint8(md5word), wordlen);
|
||||||
|
for i:=0 to 15 do begin
|
||||||
|
writehexpairWND(MD5_Hash^[i], getTerminalHWND);
|
||||||
|
end;
|
||||||
|
writestringlnWND(' ', getTerminalHWND);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure init();
|
||||||
|
begin
|
||||||
|
tracer.push_trace('md5sum.init');
|
||||||
|
terminal.registerCommand('MD5SUM', @Run, 'Perform MD5SUM on a word.');
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
Loading…
x
Reference in New Issue
Block a user