【发布时间】:2015-06-17 09:47:37
【问题描述】:
我正在尝试使用库 Crypto++ 进行基于 AES 计数器模式的加密/解密
我想将 IV 值拆分为 nonce 和 counter。
有没有直接用nonce和counter来构造IV的API?
我做了以下来实现它
byte counter[AES::BLOCKSIZE/2] = {0x0}; // initialized to zero : 64 bit counter
string counterstr ;
byte nonce[AES::BLOCKSIZE/2]; // 64 bit nonce
string noncestr ;
prng.GenerateBlock(nonce, sizeof(nonce));
StringSource(nonce, sizeof(nonce), true,
new HexEncoder(
new StringSink(noncestr)
) // HexEncoder
);
StringSource(counter, sizeof(counter), true,
new HexEncoder(
new StringSink(counterstr)
) // HexEncoder
);
SecByteBlock no = HexDecodeString(noncestr);
SecByteBlock ctr = HexDecodeString(counterstr);
string ivv = noncestr + counterstr;
SecByteBlock ivvb = HexDecodeString(ivv);
然后我用
e.SetKeyWithIV(key, sizeof(key), iv);
问题:
这是实现这一目标的唯一方法还是有其他更简单的方法?
对块进行加密或解密时,计数器值是否会自动增加?
这个很简单,我应该为每个块指定另一个nonce值吗?
【问题讨论】:
标签: encryption aes crypto++