【发布时间】:2018-07-07 13:04:24
【问题描述】:
RFC 7539 定义其 AEAD 结构如下:
chacha20_aead_encrypt(aad, key, iv, constant, plaintext):
nonce = constant | iv
otk = poly1305_key_gen(key, nonce)
ciphertext = chacha20_encrypt(key, 1, nonce, plaintext)
mac_data = aad | pad16(aad)
mac_data |= ciphertext | pad16(ciphertext)
mac_data |= num_to_4_le_bytes(aad.length)
mac_data |= num_to_4_le_bytes(ciphertext.length)
tag = poly1305_mac(mac_data, otk)
return (ciphertext, tag)
另一方面,libsodium 实现如下:
chacha20_aead_encrypt(aad, key, iv, constant, plaintext):
nonce = constant | iv
otk = poly1305_key_gen(key, nonce)
ciphertext = chacha20_encrypt(key, 1, nonce, plaintext)
mac_data = aad
mac_data |= num_to_8_le_bytes(aad.length)
mac_data |= ciphertext
mac_data |= num_to_8_le_bytes(ciphertext.length)
tag = poly1305_mac(mac_data, otk)
return (ciphertext, tag)
基本上,libsodium 在其 Poly1305 通道上不使用填充和交错数据和元数据(其长度)。由于块对齐问题,这对优化非常不友好:计算附加数据的 MAC 后,下一个数据不需要块对齐,因此不能使用高度优化和交错的 Chacha20-Poly1305 构造。
这个决定背后的原因是什么?
【问题讨论】:
-
为什么不问问作者呢?一个措辞良好的问题通常会得到回答。加密的好处是我们拥有大多数密码学家还活着的奢侈:)