Changeset 47 for trunk/DevTestMethods


Ignore:
Timestamp:
Nov 21, 2008, 4:21:44 PM (13 years ago)
Author:
Gerhard Junker
Message:

pkcs#5 TestMethods, 2 additional tests included

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DevTestMethods/pkcsTest.cs

    r38 r47  
    4343        }
    4444
    45         private void pkcs5part(byte[] key, byte[] salt, int hmac, byte[] result )
     45        private void pkcs5part(byte[] key, byte[] salt, int hmac, int count, byte[] result)
    4646        {
    4747            PKCS5Settings set = new PKCS5Settings();
    48             set.Count = 2048;
     48            set.Count = count;
    4949            set.SHAFunction = hmac;
    50             set.Length = 24 * 8; // Length must be in bits and not in bytes
     50            set.Length = result.Length * 8; // Length must be in bits and not in bytes
    5151
    5252            PKCS5.PKCS5 p = new PKCS5.PKCS5();
     
    5555            p.SaltData = salt;
    5656
     57            string tmp = "key is  ";
     58            foreach (byte b in key)
     59                tmp += b.ToString("x2") + " ";
     60            testContextInstance.WriteLine(tmp);
     61
     62            tmp = "salt is ";
     63            foreach (byte b in salt)
     64                tmp += b.ToString("x2") + " ";
     65            testContextInstance.WriteLine(tmp);
     66
    5767            p.Hash();
    5868            byte[] h = p.HashOutputData;
    5969            p.Dispose();
    6070
    61             //set = (PKCS5.PKCS5Settings)p.Settings;
    62             //testContextInstance.WriteLine("Settings: hash length is   {0} bits.", set.Length);
    63             //testContextInstance.WriteLine("Settings: hash function is {0}.", set.SHAFunction);
    64             //testContextInstance.WriteLine("Settings: hash count is    {0}.", set.Count);
    65 
    6671            // both arrays of same size?
    6772            Assert.AreEqual(h.Length, result.Length, "Different hash sizes found");
    6873
    69             string tmp = "expected hash is  ";
     74            tmp = "expected hash is  ";
    7075            foreach (byte b in result)
    7176                tmp += b.ToString("x2") + " ";
     
    8489                Assert.AreEqual(result[i], h[i], "Different hash values found");
    8590            }
     91
     92            testContextInstance.WriteLine("----");
    8693        }
    8794
     
    105112            byte[] result_SHA1   = { 0xBF, 0xDE, 0x6B, 0xE9, 0x4D, 0xF7, 0xE1, 0x1D, 0xD4, 0x09, 0xBC, 0xE2, 0x0A, 0x02, 0x55, 0xEC, 0x32, 0x7C, 0xB9, 0x36, 0xFF, 0xE9, 0x36, 0x43 };
    106113            byte[] result_SHA256 = { 0x97, 0xB5, 0xA9, 0x1D, 0x35, 0xAF, 0x54, 0x23, 0x24, 0x88, 0x13, 0x15, 0xC4, 0xF8, 0x49, 0xE3, 0x27, 0xC4, 0x70, 0x7D, 0x1B, 0xC9, 0xD3, 0x22 };
    107             byte[] result_SHA384 = { 0xbd, 0x60, 0x78, 0x73, 0x1c, 0xef, 0x2c, 0xf5, 0xbd, 0xc4, 0x87, 0x48, 0xa9, 0xda, 0x18, 0x2d, 0xdc, 0x7b, 0x48, 0xa3, 0xcc, 0x28, 0x06, 0x9e }; 
    108             byte[] result_SHA512 = { 0xe6, 0xfa, 0x68, 0xfe, 0xc0, 0xa2, 0xbe, 0x24, 0x77, 0x80, 0x9f, 0x89, 0x83, 0xe2, 0x71, 0x9e, 0xb2, 0x94, 0x15, 0xc6, 0x1e, 0xfa, 0xcf, 0x34};
     114            byte[] result_SHA384 = { 0xbd, 0x60, 0x78, 0x73, 0x1c, 0xef, 0x2c, 0xf5, 0xbd, 0xc4, 0x87, 0x48, 0xa9, 0xda, 0x18, 0x2d, 0xdc, 0x7b, 0x48, 0xa3, 0xcc, 0x28, 0x06, 0x9e };
     115            byte[] result_SHA512 = { 0xe6, 0xfa, 0x68, 0xfe, 0xc0, 0xa2, 0xbe, 0x24, 0x77, 0x80, 0x9f, 0x89, 0x83, 0xe2, 0x71, 0x9e, 0xb2, 0x94, 0x15, 0xc6, 0x1e, 0xfa, 0xcf, 0x34 };
    109116
    110             pkcs5part(key, salt, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.MD5, result_MD5);
    111             pkcs5part(key, salt, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.SHA1, result_SHA1);
    112             pkcs5part(key, salt, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.SHA256, result_SHA256);
    113             pkcs5part(key, salt, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.SHA384, result_SHA384);
    114             pkcs5part(key, salt, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.SHA512, result_SHA512);
     117            pkcs5part(key, salt, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.MD5,    2048, result_MD5);
     118            pkcs5part(key, salt, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.SHA1,   2048, result_SHA1);
     119            pkcs5part(key, salt, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.SHA256, 2048, result_SHA256);
     120            pkcs5part(key, salt, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.SHA384, 2048, result_SHA384);
     121            pkcs5part(key, salt, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.SHA512, 2048, result_SHA512);
     122
     123            // http://www.ietf.org/rfc/rfc3962.txt
     124            // Appendix B.  Sample Test Vectors, page 9
     125
     126            byte[] salt2 = { 0x41, 0x54, 0x48, 0x45, 0x4e, 0x41, 0x2e, 0x4d, 0x49, 0x54, 0x2e, 0x45, 0x44, 0x55, 0x72, 0x61, 0x65, 0x62, 0x75, 0x72, 0x6e }; // "ATHENA.MIT.EDUraeburn"
     127
     128            byte[] result1a = { 0xcd, 0xed, 0xb5, 0x28, 0x1b, 0xb2, 0xf8, 0x01, 0x56, 0x5a, 0x11, 0x22, 0xb2, 0x56, 0x35, 0x15 };
     129            byte[] result1b = { 0xcd, 0xed, 0xb5, 0x28, 0x1b, 0xb2, 0xf8, 0x01, 0x56, 0x5a, 0x11, 0x22, 0xb2, 0x56, 0x35, 0x15, 0x0a, 0xd1, 0xf7, 0xa0, 0x4b, 0xb9, 0xf3, 0xa3, 0x33, 0xec, 0xc0, 0xe2, 0xe1, 0xf7, 0x08, 0x37 };
     130
     131            pkcs5part(key, salt2, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.SHA1, 1, result1a);
     132            pkcs5part(key, salt2, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.SHA1, 1, result1b);
     133
     134            byte[] result2a = { 0x01, 0xdb, 0xee, 0x7f, 0x4a, 0x9e, 0x24, 0x3e, 0x98, 0x8b, 0x62, 0xc7, 0x3c, 0xda, 0x93, 0x5d };
     135            byte[] result2b = { 0x01, 0xdb, 0xee, 0x7f, 0x4a, 0x9e, 0x24, 0x3e, 0x98, 0x8b, 0x62, 0xc7, 0x3c, 0xda, 0x93, 0x5d, 0xa0, 0x53, 0x78, 0xb9, 0x32, 0x44, 0xec, 0x8f, 0x48, 0xa9, 0x9e, 0x61, 0xad, 0x79, 0x9d, 0x86 };
     136
     137            pkcs5part(key, salt2, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.SHA1, 2, result2a);
     138            pkcs5part(key, salt2, (int)System.Security.Cryptography.PKCS5MaskGenerationMethod.ShaFunction.SHA1, 2, result2b);
     139
    115140        }
    116141    }
Note: See TracChangeset for help on using the changeset viewer.