From 9d151d353a4637e7c1bf1032bf3437e33f09f1f4 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Tue, 17 Nov 2009 17:11:47 +0200 Subject: [PATCH] Fixes a hell of a lot of compiler warnings. * Also implemented a local dcpFillChar() method which uses a 'out' parameter causing less compiler hints. --- Ciphers/dcpblowfish.pas | 6 ++++-- Ciphers/dcpcast128.pas | 7 ++++--- Ciphers/dcpcast256.pas | 7 ++++--- Ciphers/dcpdes.pas | 11 +++++++---- Ciphers/dcpgost.pas | 8 ++++---- Ciphers/dcpice.pas | 9 ++++++--- Ciphers/dcpidea.pas | 5 +++-- Ciphers/dcpmars.pas | 10 +++++++--- Ciphers/dcpmisty1.pas | 7 ++++--- Ciphers/dcprc2.pas | 6 ++++-- Ciphers/dcprc4.pas | 5 +++-- Ciphers/dcprc5.pas | 7 ++++--- Ciphers/dcprc6.pas | 7 ++++--- Ciphers/dcprijndael.pas | 7 ++++--- Ciphers/dcpserpent.pas | 3 ++- Ciphers/dcptea.pas | 1 + Ciphers/dcptwofish.pas | 10 +++++----- Hashes/dcphaval.pas | 6 ++++-- Hashes/dcpmd4.pas | 6 ++++-- Hashes/dcpmd5.pas | 6 ++++-- Hashes/dcpripemd128.pas | 6 ++++-- Hashes/dcpripemd160.pas | 6 ++++-- Hashes/dcpsha1.pas | 6 ++++-- Hashes/dcpsha256.pas | 6 ++++-- Hashes/dcpsha512.pas | 7 +++++-- Hashes/dcptiger.pas | 2 ++ dcpblockciphers.pas | 12 ++++++++++++ dcpcrypt2.pas | 28 +++++++++++++++++++++++++++- 28 files changed, 144 insertions(+), 63 deletions(-) diff --git a/Ciphers/dcpblowfish.pas b/Ciphers/dcpblowfish.pas index 748a0f0..40c170c 100644 --- a/Ciphers/dcpblowfish.pas +++ b/Ciphers/dcpblowfish.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPblowfish; - +unit DCPblowfish; + {$MODE Delphi} interface @@ -79,6 +79,7 @@ var Cipher: TDCP_blowfish; Data: array[0..7] of byte; begin + dcpFillChar(Data, SizeOf(Data), 0); Cipher:= TDCP_blowfish.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(InData1,Data); @@ -104,6 +105,7 @@ var KeyB: PByteArray; Block: array[0..7] of byte; begin + dcpFillChar(Block, SizeOf(Block), 0); Size:= Size div 8; KeyB:= @Key; Move(SBoxOrg,SBox,Sizeof(SBox)); diff --git a/Ciphers/dcpcast128.pas b/Ciphers/dcpcast128.pas index 194dcac..eef2705 100644 --- a/Ciphers/dcpcast128.pas +++ b/Ciphers/dcpcast128.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPcast128; - +unit DCPcast128; + {$MODE Delphi} interface @@ -90,6 +90,7 @@ var Block: array[0..7] of byte; Cipher: TDCP_cast128; begin + dcpFillChar(Block, SizeOf(Block), 0); Cipher:= TDCP_cast128.Create(nil); Cipher.Init(Key,128,nil); Cipher.EncryptECB(InBlock,Block); @@ -122,7 +123,7 @@ begin Rounds:= 12 else Rounds:= 16; - FillChar(x,Sizeof(x),0); + dcpFillChar(x, Sizeof(x), 0); Move(Key,x,Size); x[0]:= (x[0] shr 24) or ((x[0] shr 8) and $FF00) or ((x[0] shl 8) and $FF0000) or (x[0] shl 24); x[1]:= (x[1] shr 24) or ((x[1] shr 8) and $FF00) or ((x[1] shl 8) and $FF0000) or (x[1] shl 24); diff --git a/Ciphers/dcpcast256.pas b/Ciphers/dcpcast256.pas index 7ddbcdf..f5a1d26 100644 --- a/Ciphers/dcpcast256.pas +++ b/Ciphers/dcpcast256.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPcast256; - +unit DCPcast256; + {$MODE Delphi} interface @@ -123,6 +123,7 @@ var Block: array[0..15] of byte; Cipher: TDCP_cast256; begin + dcpFillChar(Block, SizeOf(Block), 0); Cipher:= TDCP_cast256.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(InBlock1,Block); @@ -154,7 +155,7 @@ var begin Size:= Size div 8; - FillChar(x,Sizeof(x),0); + dcpFillChar(x,Sizeof(x),0); Move(Key,x,Size); cm:= $5a827999; diff --git a/Ciphers/dcpdes.pas b/Ciphers/dcpdes.pas index 2365bc7..d9c670c 100644 --- a/Ciphers/dcpdes.pas +++ b/Ciphers/dcpdes.pas @@ -31,8 +31,8 @@ {* 3DES takes either a <= 128bit key and uses one key twice or takes a *} {* <= 192bit key and uses each once (again discarding every 8th bit) *} {******************************************************************************} -unit DCPdes; - +unit DCPdes; + {$MODE Delphi} interface @@ -100,6 +100,7 @@ procedure TDCP_customdes.DoInit(KeyB: PByteArray; KeyData: PDwordArray); var c, d, t, s, t2, i: dword; begin + t := 0; c:= KeyB^[0] or (KeyB^[1] shl 8) or (KeyB^[2] shl 16) or (KeyB^[3] shl 24); d:= KeyB^[4] or (KeyB^[5] shl 8) or (KeyB^[6] shl 16) or (KeyB^[7] shl 24); perm_op(d,c,t,4,$0f0f0f0f); @@ -361,6 +362,7 @@ var Cipher: TDCP_des; Data: array[0..7] of byte; begin + dcpFillChar(Data, SizeOf(Data), 0); Cipher:= TDCP_des.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(InData1,Data); @@ -381,7 +383,7 @@ procedure TDCP_des.InitKey(const Key; Size: longword); var KeyB: array[0..7] of byte; begin - FillChar(KeyB,Sizeof(KeyB),0); + dcpFillChar(KeyB,Sizeof(KeyB),0); Move(Key,KeyB,Size div 8); DoInit(@KeyB,@KeyData); end; @@ -435,6 +437,7 @@ var Cipher: TDCP_3des; Block: array[0..7] of byte; begin + dcpFillChar(Block, SizeOf(Block), 0); Cipher:= TDCP_3des.Create(nil); Cipher.Init(Key,Sizeof(Key)*8,nil); Cipher.EncryptECB(PlainText,Block); @@ -448,7 +451,7 @@ procedure TDCP_3des.InitKey(const Key; Size: longword); var KeyB: array[0..2,0..7] of byte; begin - FillChar(KeyB,Sizeof(KeyB),0); + dcpFillChar(KeyB,Sizeof(KeyB),0); Move(Key,KeyB,Size div 8); DoInit(@KeyB[0],@KeyData[0]); DoInit(@KeyB[1],@KeyData[1]); diff --git a/Ciphers/dcpgost.pas b/Ciphers/dcpgost.pas index 7f5f887..26d5d4c 100644 --- a/Ciphers/dcpgost.pas +++ b/Ciphers/dcpgost.pas @@ -31,8 +31,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPgost; - +unit DCPgost; + {$MODE Delphi} interface @@ -96,6 +96,7 @@ var Block: array[0..7] of byte; Cipher: TDCP_gost; begin + dcpFillChar(Block, SizeOf(Block), 0); Cipher:= TDCP_gost.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(InData1,Block); @@ -118,8 +119,7 @@ var userkey: array[0..31] of byte; begin Size:= Size div 8; - - FillChar(userkey,Sizeof(userkey),0); + dcpFillChar(userkey,Sizeof(userkey),0); Move(Key,userkey,Size); for i:= 0 to 7 do KeyData[i]:= (dword(UserKey[4*i+3]) shl 24) or (dword(UserKey[4*i+2]) shl 16) or diff --git a/Ciphers/dcpice.pas b/Ciphers/dcpice.pas index b8b0798..e119bec 100644 --- a/Ciphers/dcpice.pas +++ b/Ciphers/dcpice.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPice; - +unit DCPice; + {$MODE Delphi} interface @@ -233,7 +233,7 @@ var kb: array[0..3] of word; keyb: array[0..15] of byte; begin - FillChar(keyb,Sizeof(keyb),0); + dcpFillChar(keyb,Sizeof(keyb),0); Move(key,keyb,Size div 8); if n> 0 then rounds:= 16 * n @@ -339,6 +339,7 @@ var Cipher: TDCP_ice; Data: array[0..7] of byte; begin + dcpFillChar(Data, SizeOf(Data), 0); Cipher:= TDCP_ice.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(InData1,Data); @@ -380,6 +381,7 @@ var Cipher: TDCP_thinice; Data: array[0..7] of byte; begin + dcpFillChar(Data, SizeOf(Data), 0); Cipher:= TDCP_thinice.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(InData1,Data); @@ -422,6 +424,7 @@ var Cipher: TDCP_ice2; Data: array[0..7] of byte; begin + dcpFillChar(Data, SizeOf(Data), 0); Cipher:= TDCP_ice2.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(InData1,Data); diff --git a/Ciphers/dcpidea.pas b/Ciphers/dcpidea.pas index f479f37..aed5852 100644 --- a/Ciphers/dcpidea.pas +++ b/Ciphers/dcpidea.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPidea; - +unit DCPidea; + {$MODE Delphi} interface @@ -84,6 +84,7 @@ var Cipher: TDCP_idea; Data: array[0..7] of byte; begin + dcpFillChar(Data, SizeOf(Data), 0); Cipher:= TDCP_idea.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(InData1,Data); diff --git a/Ciphers/dcpmars.pas b/Ciphers/dcpmars.pas index 817a2d5..00d1c0c 100644 --- a/Ciphers/dcpmars.pas +++ b/Ciphers/dcpmars.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPmars; - +unit DCPmars; + {$MODE Delphi} interface @@ -95,6 +95,7 @@ var Cipher: TDCP_mars; Block: array[0..3] of dword; begin + dcpFillChar(Block, SizeOf(Block), 0); Cipher:= TDCP_mars.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(Plain1,Block); @@ -140,8 +141,11 @@ var t: array[-7..39] of DWord; KeyB: array[0..39] of DWord; begin + m := 0; Size:= Size div 8; - FillChar(KeyB,Sizeof(KeyB),0); + dcpFillChar(KeyB,Sizeof(KeyB),0); + dcpFillChar(t, SizeOf(t), 0); + Move(Key,KeyB,Size); Size:= Size div 4; Move(vk,t,Sizeof(vk)); diff --git a/Ciphers/dcpmisty1.pas b/Ciphers/dcpmisty1.pas index 427f16e..67a1110 100644 --- a/Ciphers/dcpmisty1.pas +++ b/Ciphers/dcpmisty1.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPmisty1; - +unit DCPmisty1; + {$MODE Delphi} interface @@ -92,6 +92,7 @@ var Cipher: TDCP_misty1; Block: array[0..7] of byte; begin + dcpFillChar(Block, SizeOf(Block), 0); Cipher:= TDCP_misty1.Create(nil); Cipher.Init(Key,Sizeof(Key)*8,nil); Cipher.EncryptECB(Plain1,Block); @@ -188,7 +189,7 @@ var KeyB: array[0..15] of byte; i: longword; begin - FillChar(KeyB,Sizeof(KeyB),0); + dcpFillChar(KeyB,Sizeof(KeyB),0); Move(Key,KeyB,Size div 8); for i:= 0 to 7 do KeyData[i]:= (KeyB[i*2] * 256) + KeyB[i*2+1]; diff --git a/Ciphers/dcprc2.pas b/Ciphers/dcprc2.pas index bfbe49a..09d2082 100644 --- a/Ciphers/dcprc2.pas +++ b/Ciphers/dcprc2.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPrc2; - +unit DCPrc2; + {$MODE Delphi} interface @@ -96,6 +96,7 @@ var Cipher: TDCP_rc2; Data: array[0..7] of byte; begin + dcpFillChar(Data, SizeOf(Data), 0); Cipher:= TDCP_rc2.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(InData1,Data); @@ -117,6 +118,7 @@ var i: longword; KeyB: array[0..127] of byte; begin + dcpFillChar(KeyB, SizeOf(KeyB), 0); Move(Key,KeyB,Size div 8); for i:= (Size div 8) to 127 do KeyB[i]:= sBox[(KeyB[i-(Size div 8)]+KeyB[i-1]) and $FF]; diff --git a/Ciphers/dcprc4.pas b/Ciphers/dcprc4.pas index 3594635..f683de9 100644 --- a/Ciphers/dcprc4.pas +++ b/Ciphers/dcprc4.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPrc4; - +unit DCPrc4; + {$MODE Delphi} interface @@ -75,6 +75,7 @@ var Cipher: TDCP_rc4; Data: array[0..4] of byte; begin + dcpFillChar(Data, SizeOf(Data), 0); Cipher:= TDCP_rc4.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Encrypt(InData1,Data,Sizeof(Data)); diff --git a/Ciphers/dcprc5.pas b/Ciphers/dcprc5.pas index 9327d00..317af87 100644 --- a/Ciphers/dcprc5.pas +++ b/Ciphers/dcprc5.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPrc5; - +unit DCPrc5; + {$MODE Delphi} interface @@ -106,6 +106,7 @@ var Cipher: TDCP_rc5; Data: array[0..1] of dword; begin + dcpFillChar(Data, SizeOf(Data), 0); Cipher:= TDCP_rc5.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(Plain1,Data); @@ -128,7 +129,7 @@ var i, j, k, xKeyLen: longword; A, B: DWord; begin - FillChar(xKeyD,Sizeof(xKeyD),0); + dcpFillChar(xKeyD,Sizeof(xKeyD),0); Size:= Size div 8; Move(Key,xKeyD,Size); xKeyLen:= Size div 4; diff --git a/Ciphers/dcprc6.pas b/Ciphers/dcprc6.pas index 7745167..64477d1 100644 --- a/Ciphers/dcprc6.pas +++ b/Ciphers/dcprc6.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPrc6; - +unit DCPrc6; + {$MODE Delphi} interface @@ -111,6 +111,7 @@ var Cipher: TDCP_rc6; Data: array[0..15] of byte; begin + dcpFillChar(Data, SizeOf(Data), 0); Cipher:= TDCP_rc6.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(Plain1,Data); @@ -134,7 +135,7 @@ var A, B: DWord; begin Size:= Size div 8; - FillChar(xKeyD,Sizeof(xKeyD),0); + dcpFillChar(xKeyD,Sizeof(xKeyD),0); Move(Key,xKeyD,Size); xKeyLen:= Size div 4; if (Size mod 4)<> 0 then diff --git a/Ciphers/dcprijndael.pas b/Ciphers/dcprijndael.pas index 2404457..5cece85 100644 --- a/Ciphers/dcprijndael.pas +++ b/Ciphers/dcprijndael.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPrijndael; - +unit DCPrijndael; + {$MODE Delphi} interface @@ -98,6 +98,7 @@ var Block: array[0..15] of byte; Cipher: TDCP_rijndael; begin + dcpFillChar(Block, SizeOf(Block), 0); Cipher:= TDCP_rijndael.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(InData1,Block); @@ -138,7 +139,7 @@ var begin Size:= Size div 8; - FillChar(tk,Sizeof(tk),0); + dcpFillChar(tk,Sizeof(tk),0); Move(Key,tk,Size); if Size<= 16 then begin diff --git a/Ciphers/dcpserpent.pas b/Ciphers/dcpserpent.pas index 1987d23..4ec905f 100644 --- a/Ciphers/dcpserpent.pas +++ b/Ciphers/dcpserpent.pas @@ -94,6 +94,7 @@ var Block: array[0..15] of byte; Cipher: TDCP_serpent; begin + dcpFillChar(Block, SizeOf(Block), 0); Cipher:= TDCP_serpent.Create(nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.EncryptECB(InData1,Block); @@ -123,7 +124,7 @@ var t, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17: dword; a, b, c, d: dword; begin - FillChar(kp,256 div 8,0); + dcpFillChar(kp, SizeOf(kp), 0); Move(Key,kp,Size div 8); if Size < 256 then begin diff --git a/Ciphers/dcptea.pas b/Ciphers/dcptea.pas index 4f5214b..ddd4007 100644 --- a/Ciphers/dcptea.pas +++ b/Ciphers/dcptea.pas @@ -83,6 +83,7 @@ var Data: array[0..1] of dword; Cipher: TDCP_tea; begin + dcpFillChar(Data, SizeOf(Data), 0); Cipher:= TDCP_tea.Create(nil); Cipher.Init(Key,Sizeof(Key)*8,nil); Cipher.EncryptECB(PT,Data); diff --git a/Ciphers/dcptwofish.pas b/Ciphers/dcptwofish.pas index 702b23a..f7b9b36 100644 --- a/Ciphers/dcptwofish.pas +++ b/Ciphers/dcptwofish.pas @@ -100,8 +100,8 @@ var Cipher: TDCP_twofish; begin Cipher:= TDCP_twofish.Create(nil); - FillChar(Key,Sizeof(Key),0); - FillChar(Block,Sizeof(Block),0); + dcpFillChar(Key,Sizeof(Key),0); + dcpFillChar(Block,Sizeof(Block),0); for i:= 1 to 49 do begin Cipher.Init(Key,128,nil); @@ -110,8 +110,8 @@ begin Cipher.Burn; end; Result:= boolean(CompareMem(@Block,@Out128,16)); - FillChar(Key,Sizeof(Key),0); - FillChar(Block,Sizeof(Block),0); + dcpFillChar(Key,Sizeof(Key),0); + dcpFillChar(Block,Sizeof(Block),0); for i:= 1 to 49 do begin Cipher.Init(Key,192,nil); @@ -254,7 +254,7 @@ var k64Cnt, i, j, A, B, q: DWord; L0, L1: array[0..255] of byte; begin - FillChar(Key32,Sizeof(Key32),0); + dcpFillChar(Key32,Sizeof(Key32),0); Move(Key,Key32,Size div 8); if Size<= 128 then { pad the key to either 128bit, 192bit or 256bit} Size:= 128 diff --git a/Hashes/dcphaval.pas b/Hashes/dcphaval.pas index c6a15e8..ccba695 100644 --- a/Hashes/dcphaval.pas +++ b/Hashes/dcphaval.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPhaval; - +unit DCPhaval; + {$MODE Delphi} interface @@ -75,6 +75,7 @@ var W: array[0..31] of DWord; Temp: dword; begin + dcpFillChar(W, SizeOf(W), 0); t0:= CurrentHash[0]; t1:= CurrentHash[1]; t2:= CurrentHash[2]; @@ -253,6 +254,7 @@ class function TDCP_haval.SelfTest: boolean; TestHash: TDCP_haval; TestOut: array[0..31] of byte; begin + dcpFillChar(TestOut, SizeOf(TestOut), 0); TestHash:= TDCP_haval.Create(nil); TestHash.Init; TestHash.UpdateStr('abcdefghijklmnopqrstuvwxyz'); diff --git a/Hashes/dcpmd4.pas b/Hashes/dcpmd4.pas index a07f296..3632f09 100644 --- a/Hashes/dcpmd4.pas +++ b/Hashes/dcpmd4.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPmd4; - +unit DCPmd4; + {$MODE Delphi} interface @@ -66,6 +66,7 @@ var Data: array[0..15] of dword; A, B, C, D: dword; begin + dcpFillChar(Data, SizeOf(Data), 0); Move(HashBuffer,Data,Sizeof(Data)); A:= CurrentHash[0]; B:= CurrentHash[1]; @@ -156,6 +157,7 @@ var TestHash: TDCP_md4; TestOut: array[0..19] of byte; begin + dcpFillChar(TestOut, SizeOf(TestOut), 0); TestHash:= TDCP_md4.Create(nil); TestHash.Init; TestHash.UpdateStr('abc'); diff --git a/Hashes/dcpmd5.pas b/Hashes/dcpmd5.pas index f7821fd..0dd38f1 100644 --- a/Hashes/dcpmd5.pas +++ b/Hashes/dcpmd5.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPmd5; - +unit DCPmd5; + {$MODE Delphi} interface @@ -66,6 +66,7 @@ var Data: array[0..15] of dword; A, B, C, D: dword; begin + dcpFillChar(Data, SizeOf(Data), 0); Move(HashBuffer,Data,Sizeof(Data)); A:= CurrentHash[0]; B:= CurrentHash[1]; @@ -173,6 +174,7 @@ var TestHash: TDCP_md5; TestOut: array[0..19] of byte; begin + dcpFillChar(TestOut, SizeOf(TestOut), 0); TestHash:= TDCP_md5.Create(nil); TestHash.Init; TestHash.UpdateStr('abc'); diff --git a/Hashes/dcpripemd128.pas b/Hashes/dcpripemd128.pas index 3596ad1..60c067d 100644 --- a/Hashes/dcpripemd128.pas +++ b/Hashes/dcpripemd128.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPripemd128; - +unit DCPripemd128; + {$MODE Delphi} interface @@ -61,6 +61,7 @@ var X: array[0..15] of DWord; a, aa, b, bb, c, cc, d, dd, t: dword; begin + dcpFillChar(X, SizeOf(X), 0); Move(HashBuffer,X,Sizeof(X)); a:= CurrentHash[0]; aa:= a; b:= CurrentHash[1]; bb:= b; @@ -239,6 +240,7 @@ var TestHash: TDCP_ripemd128; TestOut: array[0..15] of byte; begin + dcpFillChar(TestOut, SizeOf(TestOut), 0); TestHash:= TDCP_ripemd128.Create(nil); TestHash.Init; TestHash.UpdateStr('a'); diff --git a/Hashes/dcpripemd160.pas b/Hashes/dcpripemd160.pas index 83b68c9..39b9907 100644 --- a/Hashes/dcpripemd160.pas +++ b/Hashes/dcpripemd160.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPripemd160; - +unit DCPripemd160; + {$MODE Delphi} interface @@ -61,6 +61,7 @@ var aa, bb, cc, dd, ee, aaa, bbb, ccc, ddd, eee: DWord; X: array[0..15] of DWord; begin + dcpFillChar(X, SizeOf(X), 0); Move(HashBuffer,X,Sizeof(X)); aa:= CurrentHash[0]; aaa:= CurrentHash[0]; @@ -599,6 +600,7 @@ var TestHash: TDCP_ripemd160; TestOut: array[0..19] of byte; begin + dcpFillChar(TestOut, SizeOf(TestOut), 0); TestHash:= TDCP_ripemd160.Create(nil); TestHash.Init; TestHash.UpdateStr('a'); diff --git a/Hashes/dcpsha1.pas b/Hashes/dcpsha1.pas index 1b3c408..5ffba90 100644 --- a/Hashes/dcpsha1.pas +++ b/Hashes/dcpsha1.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPsha1; - +unit DCPsha1; + {$MODE Delphi} interface @@ -66,6 +66,7 @@ var i: longword; begin Index:= 0; + dcpFillChar(W, SizeOf(W), 0); Move(HashBuffer,W,Sizeof(HashBuffer)); for i:= 0 to 15 do W[i]:= SwapDWord(W[i]); @@ -191,6 +192,7 @@ var TestHash: TDCP_sha1; TestOut: array[0..19] of byte; begin + dcpFillChar(TestOut, SizeOf(TestOut), 0); TestHash:= TDCP_sha1.Create(nil); TestHash.Init; TestHash.UpdateStr('abc'); diff --git a/Hashes/dcpsha256.pas b/Hashes/dcpsha256.pas index 3341539..79b66e8 100644 --- a/Hashes/dcpsha256.pas +++ b/Hashes/dcpsha256.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPsha256; - +unit DCPsha256; + {$MODE Delphi} interface @@ -66,6 +66,7 @@ var i: longword; begin Index:= 0; + dcpFillChar(W, SizeOf(W), 0); a:= CurrentHash[0]; b:= CurrentHash[1]; c:= CurrentHash[2]; d:= CurrentHash[3]; e:= CurrentHash[4]; f:= CurrentHash[5]; g:= CurrentHash[6]; h:= CurrentHash[7]; Move(HashBuffer,W,Sizeof(HashBuffer)); @@ -191,6 +192,7 @@ var TestHash: TDCP_sha256; TestOut: array[0..31] of byte; begin + dcpFillChar(TestOut, SizeOf(TestOut), 0); TestHash:= TDCP_sha256.Create(nil); TestHash.Init; TestHash.UpdateStr('abc'); diff --git a/Hashes/dcpsha512.pas b/Hashes/dcpsha512.pas index eac83e1..395adb2 100644 --- a/Hashes/dcpsha512.pas +++ b/Hashes/dcpsha512.pas @@ -22,8 +22,8 @@ {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* DEALINGS IN THE SOFTWARE. *} {******************************************************************************} -unit DCPsha512; - +unit DCPsha512; + {$MODE Delphi} interface @@ -81,6 +81,7 @@ var i: longword; begin Index:= 0; + dcpFillChar(W, SizeOf(W), 0); a:= CurrentHash[0]; b:= CurrentHash[1]; c:= CurrentHash[2]; d:= CurrentHash[3]; e:= CurrentHash[4]; f:= CurrentHash[5]; g:= CurrentHash[6]; h:= CurrentHash[7]; Move(HashBuffer,W,Sizeof(HashBuffer)); @@ -265,6 +266,7 @@ var TestHash: TDCP_sha384; TestOut: array[0..47] of byte; begin + dcpFillChar(TestOut, SizeOf(TestOut), 0); TestHash:= TDCP_sha384.Create(nil); TestHash.Init; TestHash.UpdateStr('abc'); @@ -343,6 +345,7 @@ var TestHash: TDCP_sha512; TestOut: array[0..63] of byte; begin + dcpFillChar(TestOut, SizeOf(TestOut), 0); TestHash:= TDCP_sha512.Create(nil); TestHash.Init; TestHash.UpdateStr('abc'); diff --git a/Hashes/dcptiger.pas b/Hashes/dcptiger.pas index 8690209..7f3aac8 100644 --- a/Hashes/dcptiger.pas +++ b/Hashes/dcptiger.pas @@ -61,6 +61,7 @@ var a, b, c, aa, bb, cc: int64; x: array[0..7] of int64; begin + dcpFillChar(x, SizeOf(x), 0); a:= CurrentHash[0]; aa:= a; b:= CurrentHash[1]; bb:= b; c:= CurrentHash[2]; cc:= c; @@ -228,6 +229,7 @@ var TestHash: TDCP_tiger; TestOut: array[0..2] of int64; begin + dcpFillChar(TestOut, SizeOf(TestOut), 0); TestHash:= TDCP_tiger.Create(nil); TestHash.Init; TestHash.UpdateStr('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-'); diff --git a/dcpblockciphers.pas b/dcpblockciphers.pas index 7407e68..49b88cd 100644 --- a/dcpblockciphers.pas +++ b/dcpblockciphers.pas @@ -224,6 +224,7 @@ var begin if not fInitialized then raise EDCP_blockcipher.Create('Cipher not initialized'); + dcpFillChar(Temp, SizeOf(Temp), 0); p1:= @Indata; p2:= @Outdata; for i:= 1 to (Size div 8) do @@ -254,6 +255,7 @@ begin raise EDCP_blockcipher.Create('Cipher not initialized'); p1:= @Indata; p2:= @Outdata; + dcpFillChar(Temp, SizeOf(Temp), 0); for i:= 1 to Size do begin EncryptECB(CV,Temp); @@ -276,6 +278,7 @@ begin raise EDCP_blockcipher.Create('Cipher not initialized'); p1:= @Indata; p2:= @Outdata; + dcpFillChar(Temp, SizeOf(Temp), 0); for i:= 1 to Size do begin TempByte:= p1^; @@ -324,6 +327,7 @@ begin raise EDCP_blockcipher.Create('Cipher not initialized'); p1:= @Indata; p2:= @Outdata; + dcpFillChar(Temp, SizeOf(Temp), 0); for i:= 1 to (Size div 8) do begin Move(p1^,Temp,8); @@ -402,6 +406,7 @@ begin raise EDCP_blockcipher.Create('Cipher not initialized'); p1:= @Indata; p2:= @Outdata; + dcpFillChar(Temp, SizeOf(Temp), 0); for i:= 1 to (Size div 8) do begin EncryptECB(CV,temp); @@ -430,6 +435,7 @@ begin raise EDCP_blockcipher.Create('Cipher not initialized'); p1:= @Indata; p2:= @Outdata; + dcpFillChar(Temp, SizeOf(Temp), 0); for i:= 1 to (Size div 8) do begin EncryptECB(CV,temp); @@ -551,6 +557,7 @@ begin raise EDCP_blockcipher.Create('Cipher not initialized'); p1:= @Indata; p2:= @Outdata; + dcpFillChar(Temp, SizeOf(Temp), 0); for i:= 1 to (Size div 16) do begin Move(p1^,p2^,16); @@ -579,6 +586,7 @@ begin raise EDCP_blockcipher.Create('Cipher not initialized'); p1:= @Indata; p2:= @Outdata; + dcpFillChar(Temp, SizeOf(Temp), 0); for i:= 1 to Size do begin EncryptECB(CV,Temp); @@ -601,6 +609,7 @@ begin raise EDCP_blockcipher.Create('Cipher not initialized'); p1:= @Indata; p2:= @Outdata; + dcpFillChar(Temp, SizeOf(Temp), 0); for i:= 1 to Size do begin TempByte:= p1^; @@ -649,6 +658,7 @@ begin raise EDCP_blockcipher.Create('Cipher not initialized'); p1:= @Indata; p2:= @Outdata; + dcpFillChar(Temp, SizeOf(Temp), 0); for i:= 1 to (Size div 16) do begin Move(p1^,Temp,16); @@ -727,6 +737,7 @@ begin raise EDCP_blockcipher.Create('Cipher not initialized'); p1:= @Indata; p2:= @Outdata; + dcpFillChar(Temp, SizeOf(Temp), 0); for i:= 1 to (Size div 16) do begin EncryptECB(CV,temp); @@ -755,6 +766,7 @@ begin raise EDCP_blockcipher.Create('Cipher not initialized'); p1:= @Indata; p2:= @Outdata; + dcpFillChar(Temp, SizeOf(Temp), 0); for i:= 1 to (Size div 16) do begin EncryptECB(CV,temp); diff --git a/dcpcrypt2.pas b/dcpcrypt2.pas index 40b9066..f1e3a81 100644 --- a/dcpcrypt2.pas +++ b/dcpcrypt2.pas @@ -247,9 +247,14 @@ type { Helper functions } procedure XorBlock(var InData1, InData2; Size: longword); +// removes the compiler hint due to first param being 'var' instead of 'out' +procedure dcpFillChar(out x; count: SizeInt; Value: Byte); overload; +procedure dcpFillChar(out x; count: SizeInt; Value: Char); overload; + implementation + {$Q-}{$R-} @@ -319,6 +324,7 @@ var Buffer: array[0..8191] of byte; i, read: integer; begin + dcpFillChar(Buffer, SizeOf(Buffer), 0); for i:= 1 to (Size div Sizeof(Buffer)) do begin read:= Stream.Read(Buffer,Sizeof(Buffer)); @@ -414,9 +420,13 @@ begin Hash.Final(Digest^); Hash.Free; if MaxKeySize< HashType.GetHashSize then - Init(Digest^,MaxKeySize,nil) + begin + Init(Digest^,MaxKeySize,nil); + end else + begin Init(Digest^,HashType.GetHashSize,nil); + end; FillChar(Digest^,HashType.GetHashSize div 8,$FF); FreeMem(Digest); except @@ -446,6 +456,7 @@ var Buffer: array[0..8191] of byte; i, Read: longword; begin + dcpFillChar(Buffer, SizeOf(Buffer), 0); Result:= 0; for i:= 1 to (Size div Sizeof(Buffer)) do begin @@ -468,6 +479,7 @@ var Buffer: array[0..8191] of byte; i, Read: longword; begin + dcpFillChar(Buffer, SizeOf(Buffer), 0); Result:= 0; for i:= 1 to (Size div Sizeof(Buffer)) do begin @@ -639,5 +651,19 @@ begin b1[i] := b1[i] xor b2[i]; end; +procedure dcpFillChar(out x; count: SizeInt; Value: Byte); +begin + {$HINTS OFF} + FillChar(x, count, value); + {$HINTS ON} +end; + +procedure dcpFillChar(out x; count: SizeInt; Value: Char); +begin + {$HINTS OFF} + FillChar(x, count, Value); + {$HINTS ON} +end; + end.