3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // <OWNER>Microsoft</OWNER>
9 namespace System.Security.Cryptography {
10 [System.Runtime.InteropServices.ComVisible(true)]
11 public class PKCS1MaskGenerationMethod : MaskGenerationMethod
13 private String HashNameValue;
16 // public constructors
19 public PKCS1MaskGenerationMethod() {
20 HashNameValue = "SHA1";
27 public String HashName {
28 get { return HashNameValue; }
30 HashNameValue = value;
31 if (HashNameValue == null) {
32 HashNameValue = "SHA1";
41 public override byte[] GenerateMask(byte[] rgbSeed, int cbReturn)
44 HashAlgorithm hash = HashAlgorithm.Create (HashNameValue);
45 return Mono.Security.Cryptography.PKCS1.MGF1 (hash, rgbSeed, cbReturn);
47 HashAlgorithm hash = (HashAlgorithm) CryptoConfig.CreateFromName(HashNameValue);
48 byte[] rgbCounter = new byte[4];
49 byte[] rgbT = new byte[cbReturn];
52 for (int ib=0; ib<rgbT.Length; ) {
53 // Increment counter -- up to 2^32 * sizeof(Hash)
54 Utils.ConvertIntToByteArray(counter++, ref rgbCounter);
55 hash.TransformBlock(rgbSeed, 0, rgbSeed.Length, rgbSeed, 0);
56 hash.TransformFinalBlock(rgbCounter, 0, 4);
57 byte[] _hash = hash.Hash;
59 if (rgbT.Length - ib > _hash.Length) {
60 Buffer.BlockCopy(_hash, 0, rgbT, ib, _hash.Length);
62 Buffer.BlockCopy(_hash, 0, rgbT, ib, rgbT.Length - ib);
64 ib += hash.Hash.Length;