Openssl allows going in and out of FIPS mode. Does the windows crypto api and .net wrapper classes alow a similar function?
I want to enable FIPS mode, sign a document, and then return to normal mode.
Openssl allows going in and out of FIPS mode. Does the windows crypto api and .net wrapper classes alow a similar function?
I want to enable FIPS mode, sign a document, and then return to normal mode.
Unfortunately not; at least, not without some architectural changes.
You can enable/disable FIPS mode by setting a registry value:
HKLM\System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy\Enabled (DWORD)
0 is disabled, 1 is enabled
However, there are some limitations: once you load the cryptographic providers into your process, it "remembers" the state of that FIPS mode for the rest of the process' lifetime. So code like this would work:
(NOTE: both cases assume that FIPS mode is off at the beginning)
static void Main(string[] args)
{
using (RegistryKey fipsAlgorithmPolicy = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy", true))
{
fipsAlgorithmPolicy.SetValue("Enabled", 1, RegistryValueKind.DWord);
}
SHA1 sha = new SHA1Managed(); // throws, which is what you want
}
But code like this would not:
static void Main(string[] args)
{
SHA1 sha = new SHA1Managed(); // Does not throw, which is expected
using (RegistryKey fipsAlgorithmPolicy = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy", true))
{
fipsAlgorithmPolicy.SetValue("Enabled", 1, RegistryValueKind.DWord);
}
sha = new SHA1Managed(); // Also does not throw, which is a shame
}
In order for your code to reflect the new state, you'd have to restart your process. With that being said, what you could do is sequester the code that performs the cryptographic routines into a "helper" process that your application spawns after setting FIPS mode. It'd be a bit of a pain to implement, but it would allow you to toggle FIPS mode and have your code behave as expected.
You can on a per program basis - setting enforceFIPSPolicy to true
in a .NET Runtime Settings Schema will specify that you want to enforce a computer configuration requirement that cryptographic algorithms must comply with the Federal Information Processing Standards (FIPS).