public byte[] Hash(byte[] input, HashProviders provider = HashProviders.Default) { IHashProvider p = null; if (provider == HashProviders.UserAccountSecurity) { p = _resolver.Resolve <IHashProvider>("MURMUR3"); } else { p = _resolver.Resolve <IHashProvider>(); } return(p.Hash(input)); }
/// <summary> /// Creates <see cref="TypeRegistration"/> entries registration by a container. /// </summary> /// <returns>The type registration entries.</returns> public IEnumerable <TypeRegistration> GetRegistrations(IConfigurationSource configurationSource) { var hashProviderRegistrations = HashProviders.SelectMany(hpd => hpd.GetRegistrations(configurationSource)); hashProviderRegistrations = SetDefaultHashProviderRegistration(hashProviderRegistrations); var symmetricCryptoProviderRegistrations = SymmetricCryptoProviders.SelectMany(scpd => scpd.GetRegistrations(configurationSource)); symmetricCryptoProviderRegistrations = SetDefaultSymmetricCryptoProvider(symmetricCryptoProviderRegistrations); var cryptoManagerRegistrations = CreateCryptographyManagerRegistrations(configurationSource); return(hashProviderRegistrations .Concat(symmetricCryptoProviderRegistrations) .Concat(cryptoManagerRegistrations) .Select(r => MarkPublicRegistration <IHashProvider>(r)) .Select(r => MarkPublicRegistration <ISymmetricCryptoProvider>(r))); }
/// <summary> /// Internal constructor (used to perform OAEP with a different hash and hash output length /// </summary> /// <param name="ohashProvider"></param> /// <param name="hashLength"></param> internal OAEP( HashProviders.IHashProvider ohashProvider, int hashLength ) { m_hashProvider = ohashProvider; m_hLen = hashLength; }
/// <summary> /// Mask generation function. /// </summary> /// <param name="seed">Seed</param> /// <param name="maskLen">Length of generated mask</param> /// <param name="hashLength">Length of the hash produced by the supplied hash provider</param> /// <param name="hashProvider">Hash provider to use in mask generation</param> /// <returns>Generated mask of specified length</returns> internal static byte[] OAEPMGF( byte[] seed, int maskLen, int hashLength, HashProviders.IHashProvider hashProvider ) { byte[] result = new byte[maskLen]; //Determine how many interations we have to do. We'll be appending //m_hLen (hash length) bytes for every iteration, so the size of the generated byte array //will be m_hLen * iNum (number of iterations). int iNum = (int)Math.Floor( (double)( maskLen / hashLength ) ) + 1; //Mask that will be truncated to create the final //resulting mask returned by this function. byte[] bytLongMask = new byte[( iNum * hashLength )]; byte[] bytAppend = new byte[4]; byte[] bytTmp = null; int iPadLen = 0; byte[] bytSeedHash = new byte[hashLength]; //Padded pseudorandom seed to be hashed. byte[] bytPadSeed = new byte[( seed.Length + 4 )]; seed.CopyTo( bytPadSeed, 0 ); for( int i = 0; i <= iNum - 1; i++ ) { //Convert the iterator to an Octet String byte array bytTmp = CryptoMathematics.I2OSP( i, 4 ); //Calculate the needed padding zeros, and add //them to the resulting Array. Result must be 4 bytes long. iPadLen = bytAppend.Length - bytTmp.Length; bytTmp.CopyTo( bytAppend, 0 ); //Hash the pseudorandom padded seed and append it to the //long version of the mask. bytAppend.CopyTo( bytPadSeed, seed.Length ); bytSeedHash = hashProvider.ComputeHash( bytPadSeed ); bytSeedHash.CopyTo( bytLongMask, i * hashLength ); } //Copy the first maskLen bytes of bytLongMask to the result //and return the result. Array.Copy( bytLongMask, result, maskLen ); return result; }