/// <summary> /// Gets the secondary hash algorithm used for pool mixing, serving roughly analogous /// to key whitening. /// </summary> /// <returns>A hash algorithm suitable for the current platform serving as the /// secondary hash algorithm for pool mixing, or null if no secondary hash /// algorithm can be used (e.g. due to FIPS algorithm restrictions)</returns> /// <remarks>The instance returned need not be freed as it is cached.</remarks> private static HashAlgorithm GetSecondaryHash() { if (HasSecondaryHashAlgorithm) { return(SecondaryHashAlgorithmCache); } HashFactoryDelegate[] priorityList = new HashFactoryDelegate[] { delegate() { return(new RIPEMD160Managed()); } }; foreach (HashFactoryDelegate func in priorityList) { try { SecondaryHashAlgorithmCache = func(); break; } catch (PlatformNotSupportedException) { } catch (InvalidOperationException) { } } HasSecondaryHashAlgorithm = true; return(SecondaryHashAlgorithmCache); }
/// <summary> /// Gets the primary hash algorithm used for pool mixing. /// </summary> /// <returns>A hash algorithm suitable for the current platform serving as the /// primary hash algorithm for pool mixing.</returns> /// <remarks>The instance returned need not be freed as it is cached.</remarks> private static HashAlgorithm GetPrimaryHash() { if (PrimaryHashAlgorithmCache != null) { return(PrimaryHashAlgorithmCache); } HashFactoryDelegate[] priorityList = new HashFactoryDelegate[] { delegate() { return(new SHA512Cng()); }, delegate() { return(new SHA512CryptoServiceProvider()); }, delegate() { return(new SHA512Managed()); }, delegate() { return(new SHA256Cng()); }, delegate() { return(new SHA256CryptoServiceProvider()); }, delegate() { return(new SHA256Managed()); }, delegate() { return(new SHA1Cng()); }, delegate() { return(new SHA1CryptoServiceProvider()); }, delegate() { return(new SHA1Managed()); } }; foreach (HashFactoryDelegate func in priorityList) { try { return(PrimaryHashAlgorithmCache = func()); } catch (PlatformNotSupportedException) { } catch (InvalidOperationException) { } } throw new InvalidOperationException(S._("No suitable hash algorithms were found " + "on this computer.")); }