AesCryptoServiceProvider.GenerateIV 在用完唯一 IV 的数量之前可以安全调用多少次?

How many times can AesCryptoServiceProvider.GenerateIV be safely called before exhausting the number of unique IVs?

我很困惑。根据下面我的 IV "MUST" 对每一轮加密都是唯一的。

Properties of an IV depend on the cryptographic scheme used. A basic requirement is uniqueness, which means that no IV may be reused under the same key. For block ciphers, repeated IV values devolve the encryption scheme into electronic codebook mode: equal IV and equal plaintext result in equal ciphertext. - https://en.wikipedia.org/wiki/Initialization_vector

我正在使用 .NET AesCryptoServiceProvider class。我正在使用 GenerateIV 生成新的 IV 并将该 IV 与密文一起发送到远程端点,然后远程端点将使用 IV 和私有共享密钥解密数据包。

我的数据包是 XML,因此将始终以相同的前导文本开头。 (例如“unique_text”)

我的密钥在密钥的五到十分钟生命周期内可能存在数千个 encrypt/decrypt 周期。在两次生成相同的 IV 之前,我可以调用 GenerateIV 多少次?或者换句话说,GenerateIV 适合多少个周期?五、十、百、千、百万?

这里是有问题的代码:

_sessionKeys[_currentSessionKeyId].GenerateIV();
var key = _sessionKeys[_currentSessionKeyId].Key;
var iv = _sessionKeys[_currentSessionKeyId].IV;

ICryptoTransform encryptor = _sessionKeys[_currentSessionKeyId].CreateEncryptor(key,iv);

看来AesCryptoServiceProvider.GenerateIV生成的IV是有限大小的,那么在生成重复IV之前可以调用的次数也是有限的。但是那个有限的数字是多少。

IV 中有 128 位(16 字节)。根据 Birthday Attack 上的 Wikipeda 页面(您会看到从池中随机提取重复值的概率)有 0.0000000000000001% 的机会看到任何数字两次,您必须调用该函数大约 26,000,000,000 次。要使任何数字出现两次的概率为 1%,您必须调用它 2,600,000,000,000,000,000 次。

这假设 GenerateIV 有一个 "good" 随机数生成器,它应该有一个均匀分布。