代码之家  ›  专栏  ›  技术社区  ›  user3368561

利伯纳AEAD实施背后的决定

  •  3
  • user3368561  · 技术社区  · 7 年前

    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)
    

    基本上libnadium不使用padding,而是在poly1305过程中交错数据和元数据(其长度)。由于块对齐问题,这对优化非常不利:在计算附加数据的mac之后,下一个数据不需要块对齐,因此不能使用高度优化和交织的chacha20-poly1305构造。

    这个决定背后的原因是什么?

    1 回复  |  直到 7 年前
        1
  •  1
  •   neubert    6 年前

    引用 https://download.libsodium.org/doc/secret-key_cryptography/aead/chacha20-poly1305 “。” LibNadium实现了Chacha20-Poly1305结构的三个版本 “。前两项如下:

    • 原始结构可以使用相同的 密钥(对于大多数协议更是如此),没有任何实际的大小限制 消息的大小(128位标记最多2^64字节)。
    • IETF变体。它可以安全地加密 消息,但单个消息不能超过64*(2^32)-64字节 (近似256 GB)。

    你描述的是“原始结构”。原始结构支持的nonce小于ietf版本(64位对96位),aead结构也不同,正如您所观察到的。

    我的猜测是:“原始结构”是在ietf-rfc编写之前开发的。LibNadium基于 https://en.wikipedia.org/wiki/NaCl_(software) 最初于2008年发布。ietf的rfc是在2015年编写的。