XTS模式
🌐 XTS mode
XTS 密码在可以独立调节的 数据单元 上操作。一个 Cipheriv 或 Decipheriv 实例代表一个完整的数据单元,它的 iv 参数提供 16 字节的 tweak。每个不同的逻辑数据单元都使用带有合适位置 tweak 的新实例。
🌐 XTS ciphers operate on independently tweakable data units. A Cipheriv or
Decipheriv instance represents one complete data unit, and its iv argument
provides the 16-byte tweak. Use a new instance with the appropriate positional
tweak for each different logical data unit.
使用 XTS 模式的应用必须遵守这些限制:
🌐 Applications which use XTS mode must adhere to these restrictions:
- 明文或密文必须至少有一个16字节的块。它的长度不必是16字节的倍数,因为XTS会对最后的部分块使用密文窃取。
- 密文和明文的长度一样。
cipher.update()或decipher.update()必须只使用所有输入数据调用一次。像write(data)、end(data)或pipe()这样的流方法可能会失败,因为 XTS 不接受多次数据更新。cipher.final()或decipher.final()仍然需要被调用来完成操作。
sm4-xts 中,选择 xtsStandard 选项为 crypto.createCipheriv() 或 crypto.createDecipheriv() 可以选择 GB/T 17964-2021 的默认 'GB' 变体,或 IEEE Std 1619-2007 的 'IEEE' 变体。加密和解密必须使用相同的变体。这个选项只对 sm4-xts 可用;不适用于 AES-XTS 密码。OpenSSL 默认提供者在 OpenSSL 3.2 或更高版本中支持 sm4-xts。
🌐 For sm4-xts, the xtsStandard option to crypto.createCipheriv() or
crypto.createDecipheriv() selects either the default 'GB' variant from
GB/T 17964-2021 or the 'IEEE' variant from IEEE Std 1619-2007. Encryption and
decryption must use the same variant. The option is available only for
sm4-xts; it does not apply to AES-XTS ciphers. OpenSSL's default provider
supports sm4-xts in OpenSSL 3.2 or later.