views:

1434

answers:

3

Right now the only way I can get the RijndaelManaged algorithm to work on a computer with the Local Security Setting for FIPS turned on, is to disable it. It is a government computer, so I'm not sure how that will fly. I've seen posts on the msdn blog sites that say they are working on an AES FIPS compliant version, but I cant seem to find out anything more. Does anyone know when this might happen?

+4  A: 

I never realized this before this question, but you're right. The constructor has this:

public RijndaelManaged()
{
    if (Utils.FipsAlgorithmPolicy == 1)
    {
        throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
    }
}

System.Security.Cryptography.AesManaged has something similar:

public AesManaged()
{
    if (CoreCryptoConfig.EnforceFipsAlgorithms)
    {
        throw new InvalidOperationException(SR.GetString("Cryptography_NonCompliantFIPSAlgorithm"));
    }
    this.m_rijndael = new RijndaelManaged();
    this.m_rijndael.BlockSize = this.BlockSize;
    this.m_rijndael.KeySize = this.KeySize;
}

Have you tried System.Security.Cryptography.AesCryptoServiceProvider? It should work since it's using the CAPI based FIPS AES implementation built into Windows.

This question on Microsoft's .NET Base Class Library forum discusses which algorithms are FIPS compliant and has good links.

It appears that Microsoft is making a consistent effort to obey the setting of HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy on pre-Vista machines and use of the BCryptGetFipsAlgorithmMode API for post-Vista.

I assume there is non-trivial effort involved in certifying an implementation as FIPS compliant, that is why Microsoft probably doesn't want to repeat the process and only offers the AesCryptoServiceProvider for customers that absolutely need this requirement.

This MSDN blog post has a comment that makes it clearer:

The easy way to figure out if an algorithm is compliant or not is to look at the suffix. None of the *Managed types are FIPS certified. The *CryptoServiceProvider and *Cng types however, may well be FIPS certified. If they implement an algorithm that FIPS allows, and are using the default Microsoft providers, then they will be.

For instance, SHA256Managed is not (because it is *Managed). SHA256CryptoServiceProvider and SHA256Cng are.
MD5CryptoServiceProvider is not (because MD5 is not a FIPS algorithm).

Jeff Moser
We did try the AesCryptoServiceProvider first, but we couldn't get the desired encryption/decryption results and I dont think it is supported in the compact framework. Everything with the RijndealManaged seemed ok, until we ran into this problem
SwDevMan81
By "results", do you mean performance? It looks like Microsoft doesn't want to go through an implementation validation process for something beyond their CAPI for the current time. Microsoft clearly went out of their way to (probably) comply with Federal customers who wanted a single policy bit they could set to prohibit non-FIPS solutions. You could use a library like BouncyCastle ( http://www.bouncycastle.org/csharp/index.html ) that ignores this bit if you simply wanted to use a managed FIPS implementation.
Jeff Moser
(Updated answer with additional info)
Jeff Moser
By results, I mean we tried the AesCryptoServiceProvider and RijndealManaged with the same cipher mode (CFB), padding (None), init vector and keys and they produced different encrypted results.
SwDevMan81
Were your key bytes and block sizes identical? They should produce identical results. Can you post a brief snippet of what you tried into a new question with a title like "Why are RijndaelManaged and AesCryptoServiceProvider returning different results?" and then link to that from here and I'll try to check it out.
Jeff Moser
Yeah, I'll have to do it later, but I can post it.
SwDevMan81
http://stackoverflow.com/questions/957388/why-are-rijndaelmanaged-and-aescryptoserviceprovider-returning-different-results
SwDevMan81
What would be the correct code for the Utils.FipsAlgorithmPolicy function? Thank you!
Luke
Luke: The "AesCryptoServiceProvider" uses the Crypto API (CAPI) which is FIPS compliant: AesCryptoServiceProvider. The Utils.FipsAlgorithmPolicy on Vista and later, calls BCryptGetFipsAlgorithmMode: http://msdn.microsoft.com/en-us/library/aa375460%28VS.85%29.aspx on earlier OS's, a check to "FIPSAlgorithmPolicy" value under HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa is done.All this said, if at all possible, try to refactor your design to use TLS/SSL or some high level crypto instead of calling this class directly.
Jeff Moser
I wrote much more about this in a comment to my Stick Figure Guide to AES: http://www.moserware.com/2009/09/stick-figure-guide-to-advanced.html?showComment=1254448126873#c7933132611242458392
Jeff Moser
A: 

The unmanaged AesCryptoServiceProvider is certified if the OS itself is certified as it calls the OS. And it will be a darned site quicker as well, at the cost of cross platform compatibility.

blowdart
A: 

My site had to get a waver for FIPS compliance in .net.

Jeff Walker
Where did get the waiver?
SwDevMan81
NETWARCOM? This is the Navy command that hands down the security edicts.
Jeff Walker