Bug 3777 - PKCS1MaskGenerationMethod fails with ArgumentException
Summary: PKCS1MaskGenerationMethod fails with ArgumentException
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Security ()
Version: 2.10.x
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-03-07 02:50 UTC by Alex
Modified: 2012-03-23 10:00 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Alex 2012-03-07 02:50:48 UTC
Simple test below fails with exception under Mono, in .Net it is executed successfully

static void Main( string[] args )
     int maskLen = 0x3F;
     int seedLen = 0x40;
     byte[] seed = new byte[ seedLen ];
     byte[] mask = new System.Security.Cryptography.PKCS1MaskGenerationMethod().GenerateMask( seed, maskLen );

I think that bug is in implementation of function MGF1 in Mono, below is a chunk of source for it

 // 3. For counter from 0 to \ceil (maskLen / hLen) - 1, do the following:
                        for (int counter = 0; counter < iterations; counter++) {
                                // a.   Convert counter to an octet string C of length 4 octets
                                byte[] C = I2OSP (counter, 4); 
                                // b.   Concatenate the hash of the seed mgfSeed and C to the octet string T:
                                //      T = T || Hash (mgfSeed || C)
                                Buffer.BlockCopy (mgfSeed, 0, toBeHashed, 0, mgfSeedLength);
                                Buffer.BlockCopy (C, 0, toBeHashed, mgfSeedLength, 4);
                                byte[] output = hash.ComputeHash (toBeHashed);
                                Buffer.BlockCopy (output, 0, T, pos, hLen);
                                pos += mgfSeedLength;  // BUG IS HERE, IT SEEMS THAT pos += hLen; IS MORE CORRECT, BUT I NEVER CHECKED IT :)
Comment 1 Sebastien Pouliot 2012-03-23 10:00:30 UTC
Good catch. This is fixed in git and your code was turned into a unit test
master: 11b8dd58cb44b969661702579f17b905d2fa5594
mono-2-10: 8f1b2d3cdec438584f1127462ea0245062c05007