Author: spouliot
Date: 2005-03-07 10:58:01 -0500 (Mon, 07 Mar 2005)
New Revision: 41530
Modified:
trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog
trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/MD2Managed.cs
trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/MD4Managed.cs
trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/SHA224Managed.cs
Log:
2005-03-07 Sebastien Pouliot <[EMAIL PROTECTED]>
* MD2Managed.cs: Removed memory allocation from the transform method.
* MD4Managed.cs: Moved memoty allocation to constructor (from init).
* SHA224Managed.cs: Fixed bug #73404 which gaves bad results when the
digested data is longer than 2^32 bits.
Modified: trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog
2005-03-07 15:56:32 UTC (rev 41529)
+++ trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/ChangeLog
2005-03-07 15:58:01 UTC (rev 41530)
@@ -1,3 +1,10 @@
+2005-03-07 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * MD2Managed.cs: Removed memory allocation from the transform method.
+ * MD4Managed.cs: Moved memoty allocation to constructor (from init).
+ * SHA224Managed.cs: Fixed bug #73404 which gaves bad results when the
+ digested data is longer than 2^32 bits.
+
2005-01-11 Sebastien Pouliot <[EMAIL PROTECTED]>
* SymmetricTransform.cs: Added support for ANSI X9.23 padding and
Modified: trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/MD2Managed.cs
===================================================================
--- trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/MD2Managed.cs
2005-03-07 15:56:32 UTC (rev 41529)
+++ trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/MD2Managed.cs
2005-03-07 15:58:01 UTC (rev 41530)
@@ -5,10 +5,8 @@
// Sebastien Pouliot ([EMAIL PROTECTED])
//
// (C) 2001-2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
-
-//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
@@ -43,6 +41,7 @@
private byte[] checksum;
private byte[] buffer;
private int count;
+ private byte[] x;
/// <summary>
/// Permutation of 0..255 constructed from the digits of pi. It
gives a
@@ -87,6 +86,7 @@
state = new byte [16];
checksum = new byte [16];
buffer = new byte [16];
+ x = new byte [48];
// the initialize our context
Initialize ();
}
@@ -97,6 +97,8 @@
Array.Clear (state, 0, 16);
Array.Clear (checksum, 0, 16);
Array.Clear (buffer, 0, 16);
+ // Zeroize sensitive information
+ Array.Clear (x, 0, 48);
}
protected override void HashCore (byte[] array, int ibStart,
int cbSize)
@@ -161,8 +163,6 @@
/// </summary>
private void MD2Transform (byte[] state, byte[] checksum,
byte[] block, int index)
{
- byte[] x = new byte [48];
-
/* Form encryption block from state, block, state ^
block. */
// MD2_memcpy ((POINTER)x, (POINTER)state, 16);
Buffer.BlockCopy (state, 0, x, 0, 16);
@@ -189,10 +189,6 @@
t = checksum [15];
for (int i = 0; i < 16; i++)
t = checksum [i] ^= PI_SUBST [block [index + i]
^ t];
-
- /* Zeroize sensitive information. */
- // MD2_memset ((POINTER)x, 0, sizeof (x));
- Array.Clear (x, 0, 48);
}
}
}
Modified: trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/MD4Managed.cs
===================================================================
--- trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/MD4Managed.cs
2005-03-07 15:56:32 UTC (rev 41529)
+++ trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/MD4Managed.cs
2005-03-07 15:58:01 UTC (rev 41530)
@@ -5,10 +5,8 @@
// Sebastien Pouliot ([EMAIL PROTECTED])
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
-
-//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
@@ -61,13 +59,15 @@
//--- constructor
-----------------------------------------------------------
- public MD4Managed () : base ()
+ public MD4Managed ()
{
// we allocate the context memory
state = new uint [4];
count = new uint [2];
buffer = new byte [64];
digest = new byte [16];
+ // temporary buffer in MD4Transform that we don't want
to keep allocate on each iteration
+ x = new uint [16];
// the initialize our context
Initialize ();
}
@@ -80,9 +80,9 @@
state [1] = 0xefcdab89;
state [2] = 0x98badcfe;
state [3] = 0x10325476;
- // temporary buffer in MD4Transform that we don't want
to keep allocate on each iteration
- x = new uint [16];
+ // Zeroize sensitive information
Array.Clear (buffer, 0, 64);
+ Array.Clear (x, 0, 16);
}
protected override void HashCore (byte[] array, int ibStart,
int cbSize)
@@ -196,9 +196,9 @@
private void Encode (byte[] output, uint[] input)
{
for (int i = 0, j = 0; j < output.Length; i++, j += 4) {
- output [j] = (byte)(input [i] & 0xff);
- output [j+1] = (byte)((input [i] >> 8) & 0xff);
- output [j+2] = (byte)((input [i] >> 16) & 0xff);
+ output [j] = (byte)(input [i]);
+ output [j+1] = (byte)(input [i] >> 8);
+ output [j+2] = (byte)(input [i] >> 16);
output [j+3] = (byte)(input [i] >> 24);
}
}
@@ -276,9 +276,6 @@
state [1] += b;
state [2] += c;
state [3] += d;
-
- /* Zeroize sensitive information. */
- Array.Clear (x, 0, 16);
}
}
}
Modified:
trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/SHA224Managed.cs
===================================================================
--- trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/SHA224Managed.cs
2005-03-07 15:56:32 UTC (rev 41529)
+++ trunk/mcs/class/Mono.Security/Mono.Security.Cryptography/SHA224Managed.cs
2005-03-07 15:58:01 UTC (rev 41530)
@@ -7,7 +7,7 @@
// Sebastien Pouliot <[EMAIL PROTECTED]>
//
// (C) 2001
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -38,7 +38,7 @@
private const int BLOCK_SIZE_BYTES = 64;
private const int HASH_SIZE_BYTES = 32;
private uint[] _H;
- private uint count;
+ private ulong count;
private byte[] _ProcessingBuffer; // Used to start data when
passed less than a block worth.
private int _ProcessingBufferCount; // Counts how much data we
have stored that still needs processed.
@@ -207,46 +207,44 @@
private void ProcessFinalBlock (byte[] inputBuffer, int
inputOffset, int inputCount)
{
- byte[] fooBuffer;
- int paddingSize;
- int i;
- uint size;
+ ulong total = count + (ulong)inputCount;
+ int paddingSize = (56 - (int)(total %
BLOCK_SIZE_BYTES));
- paddingSize = (int)(56 - (inputCount + count) %
BLOCK_SIZE_BYTES);
-
if (paddingSize < 1)
paddingSize += BLOCK_SIZE_BYTES;
- fooBuffer = new byte[inputCount+paddingSize+8];
+ byte[] fooBuffer = new byte[inputCount+paddingSize+8];
- for (i=0; i<inputCount; i++) {
+ for (int i=0; i<inputCount; i++) {
fooBuffer[i] = inputBuffer[i+inputOffset];
}
fooBuffer[inputCount] = 0x80;
- for (i=inputCount+1; i<inputCount+paddingSize; i++) {
+ for (int i=inputCount+1; i<inputCount+paddingSize; i++)
{
fooBuffer[i] = 0x00;
}
- size = (uint)(count+inputCount);
- size *= 8;
+ // I deal in bytes. The algorithm deals in bits.
+ ulong size = total << 3;
+ AddLength (size, fooBuffer, inputCount+paddingSize);
+ ProcessBlock (fooBuffer, 0);
- fooBuffer[inputCount+paddingSize] = 0x00;
- fooBuffer[inputCount+paddingSize+1] = 0x00;
- fooBuffer[inputCount+paddingSize+2] = 0x00;
- fooBuffer[inputCount+paddingSize+3] = 0x00;
-
- fooBuffer[inputCount+paddingSize+4] = (byte)((size) >>
24);
- fooBuffer[inputCount+paddingSize+5] = (byte)((size) >>
16);
- fooBuffer[inputCount+paddingSize+6] = (byte)((size) >>
8);
- fooBuffer[inputCount+paddingSize+7] = (byte)((size) >>
0);
-
- ProcessBlock(fooBuffer, 0);
-
if (inputCount+paddingSize+8 == 128) {
ProcessBlock(fooBuffer, 64);
}
}
+
+ internal void AddLength (ulong length, byte[] buffer, int
position)
+ {
+ buffer [position++] = (byte)(length >> 56);
+ buffer [position++] = (byte)(length >> 48);
+ buffer [position++] = (byte)(length >> 40);
+ buffer [position++] = (byte)(length >> 32);
+ buffer [position++] = (byte)(length >> 24);
+ buffer [position++] = (byte)(length >> 16);
+ buffer [position++] = (byte)(length >> 8);
+ buffer [position] = (byte)(length);
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches