Fix ArgumentOutOfRangeException in PKCS1MaskGenerationMethod + unit tests. Fix bug...
authorSebastien Pouliot <sebastien@xamarin.com>
Fri, 23 Mar 2012 13:10:27 +0000 (09:10 -0400)
committerSebastien Pouliot <sebastien@xamarin.com>
Fri, 23 Mar 2012 13:10:27 +0000 (09:10 -0400)
mcs/class/corlib/Mono.Security.Cryptography/PKCS1.cs
mcs/class/corlib/Test/System.Security.Cryptography/PKCS1MaskGenerationMethodTest.cs

index 6cf82682f7be2d92c319b1be2931d1a375bfd17d..ca979eec32c39318131cd5a3954727c113fb9208 100644 (file)
@@ -408,7 +408,7 @@ namespace Mono.Security.Cryptography {
                                Buffer.BlockCopy (C, 0, toBeHashed, mgfSeedLength, 4);
                                byte[] output = hash.ComputeHash (toBeHashed);
                                Buffer.BlockCopy (output, 0, T, pos, hLen);
-                               pos += mgfSeedLength;
+                               pos += hLen;
                        }
                        
                        // 4. Output the leading maskLen octets of T as the octet string mask.
index 37ac3528bf8708f15cd25b8ad87c05a1f4095d1e..222ed82a1e4c9f8f761f8cc50100e1a2869fdad5 100644 (file)
@@ -91,6 +91,16 @@ namespace MonoTests.System.Security.Cryptography {
                        byte[] random = { 0x01 };
                        byte[] mask = pkcs1.GenerateMask (random, -1);
                }
+               
+               [Test]
+               public void Bug3777 ()
+               {
+                       int maskLen = 0x3F;
+                       int seedLen = 0x40;
+                       byte [] seed = new byte [seedLen];
+                       byte [] mask = pkcs1.GenerateMask (seed, maskLen);
+                       Assert.AreEqual (maskLen, mask.Length, "Length");
+               }
 
                // This test will FAIL with MS framework 1.0 and 1.1 as their MGF1 implementation is buggy
                // see ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1-vec.zip for RSA tests vector