首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FIPS 140-2履约情况

FIPS 140-2履约情况
EN

Security用户
提问于 2022-09-07 14:38:45
回答 2查看 140关注 0票数 2

我对安全和加密这一话题非常陌生。我们的软件必须符合FIPS 140-2.我有以下方法(C#)。在这种情况下,算法是AES256。我关心的是,我们使用SHA1来散列密钥。在这里使用SHA1是可以接受的,还是破坏了FIPS的遵从性?

谢谢!

代码语言:javascript
复制
public static ServiceEncryptionKey CreateNew(ServiceEncryptionAlgorithm algorithm)
{
    byte[] keyData;
    using (var key = CreateSymmetricAlgorithm(algorithm))
    {
        key.GenerateKey();
        keyData = key.Key;
    }

    byte[] keyHash;
    using (SHA1Cng sha = new SHA1Cng())
    {
        keyHash = sha.ComputeHash(keyData);
    }
    
    try
    {
        return new ServiceEncryptionKey(algorithm, new ProtectedBytes(keyData), keyHash);
    }
    finally
    {
        Array.Clear(keyData, 0, keyData.Length);
    }
}

private ServiceEncryptionKey(ServiceEncryptionAlgorithm algorithm, ProtectedBytes keyData, byte[] keyHash)
    {
        this.Algorithm = algorithm;
        this.protectedKeyData = keyData;
        this.header = new byte[16 + keyHash.Length];
        this.KeyHash = (byte[])keyHash.Clone();
        Buffer.BlockCopy(new Guid("00000000-0000-0000-0000-000000000000").ToByteArray(), 0, this.header, 0, 16);
        Buffer.BlockCopy(keyHash, 0, this.header, 16, keyHash.Length);
    }

internal ProtectedBytes(byte[] plaintext)
    {
        this.ciphertext = new byte[(plaintext.Length + 0xF) & ~0xF];
        Buffer.BlockCopy(plaintext, 0, ciphertext, 0, plaintext.Length);
        ProtectedMemory.Protect(ciphertext, MemoryProtectionScope.SameProcess);
        this.plaintextLength = plaintext.Length;
    }
EN

回答 2

Security用户

回答已采纳

发布于 2022-09-07 16:33:50

沙-1仍然在最新的FIPS-140-2附件A中获得批准。然而,对于某些用途,NIST SP 800-131 A REV.2不推荐使用SHA-1。

我会调查移动到SHA-2或更高的任何可能的未来打样(并符合较宽松的标准)。

票数 3
EN

Security用户

发布于 2022-09-07 21:36:33

你的代码有问题。

最后,您清除了keyData,这很好。这确保内存转储不会包含加密密钥。

  1. 但你使用的是ProtectedBytes。没有源代码,就很难知道它在做什么。但是,如果可以从这个对象中提取密钥,那么这就是一个问题。
  2. ServiceEncryptionKey的目的还不清楚。如果您使用哈希进行加密,那么有效的加密密钥将保留在内存中,因此可以通过内存转储来检索。这就是为什么在最后清除keyData不能使代码更加安全的原因。
票数 0
EN
页面原文内容由Security提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://security.stackexchange.com/questions/264656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档