AES
- doc
- aead
- block size, key length
- ciphertext length
- padding
- gcm
- cts : ciphertext stealing
- adiantum
- aes-siv: RFC5297
- eax
- RFC3686: Using Advanced Encryption Standard (AES) Counter Mode With IPsec Encapsulating Security Payload (ESP)
- RFC5649: Advanced Encryption Standard (AES) Key Wrap with Padding Algorithm
- RFC3394: Advanced Encryption Standard (AES) Key Wrap Algorithm
- aegis
doc
RFC5084 Using AES-CCM and AES-GCM Authenticated Encryption in the Cryptographic Message Syntax (CMS)
RFC5116 Authenticated Encryption
Basic question regarding OpenSSL and AES-GCM
How to choose between AES-CCM and AES-GCM for storage volume encryption
Evaluation of Some BlockcipherModes of Operation
aead
Authenticated encryption with associated data (AEAD),例如ccm (CBC counter mode), gcm (Galois counter mode)。
block size, key length
AES 的 block length 固定为128 bits, key length 可以是 128, 192, 256。
Rijndael 的 block length & key length 是 32 bits 的倍数,最小 128 bits, 最大 256 bits。例如可以取block length = 160 bits, key length = 224 bits。
Blowfish 和 3DES 是8字节。
ciphertext length
假设 x = len(plaintext),不考虑IV/Nonce:
cbc/ecb: 以16bytes对齐
ctr/ofb/cfb : x
gcm : x + 16 (authtag)
ccm(ctr with cbc-mac) : x + 16 (authtag)
openssl enc -aes-256-cbc -salt -in src.txt -out src.aes-256-cbc.enc -k somepasswd
openssl enc -aes-256-ctr -k somepasswd -in src.txt -out src.aes-256-ctr.enc
padding
What is the difference between PKCS#5 padding and PKCS#7 padding
What are the relative merits of padding algorithms pkcs7, iso7816, and x923?
默认使用 PKCS#7 padding。
ANSI X.923 是在最末一位指示padding length,前面以全0做padding content。
PKCS#5 and PKCS#7 是在最末一位指示padding length,前面以padding length做padding content。
ISO/IEC 7816-4 是以80标识padding,后面以全0做padding content。
可见,ANSI X.923/PKCS#7 都不能支持256bit以上的block padding,而ISO/IEC 7816-4可以。
gcm
The Galois/Counter Mode of Operation (GCM)
Nonce-Disrespecting Adversaries
nonce不能重用。
cts : ciphertext stealing
分组加密模式适用。
通过密文处理,无需填充明文到分组大小。
AES-CBC-CTS
加密:明文末尾补0 -> CBC正常加密 -> 对换倒数两个密文块 -> 密文末尾裁减到与明文等长。
解密:解密倒数第二个密文块 -> 从解密结果获得末尾裁减的部分,拼接到最后一个密文块末尾 -> 对换倒数两个密文块 -> 解密 -> 裁减明文。
xts
IEEE 1619
XEX-based tweaked-codebook mode with ciphertext stealing (XTS)
倒数第二个块的密文截取,拼到最后一块的明文后面,做为最后一个分组加密的输入。
解密时,先解密最后一个分组密文,获得最后一块明文+截取的倒数第二个块的密文,再进行倒数第二个块的密文解密。
注意,用到了两个key。key1作用于分组明文,key2随分组id处理。除了倒数第二个分组,每个分组都可以独立解密。
adiantum
AES-XTS: 没硬件加速会比较慢;明文单bit变化,密文最多变化16bytes。
adiantum采用hash(NH + Poly1305), 流密码(XChaCha12)都比较快。
aes-siv: RFC5297
aes-siv: AES-CMAC (S2V) + AES-CTR
aes-siv-key = aes-cmac-key (k1) | aes-ctr-key (k2) |
aes-siv-key 256 bits起步,k1 | k2 前后各半 |
authenticated encryption
key wrapping,替代rfc3394
抵御nonce的reuse、misuse
key derivation,string to vector (s2v)
message authentication
性能相比gcm差
S2V:将原文拆分block,再链式调用aes-cmac,异或处理,最终获得128 bits的输出V。
SIV:将原文与additional data,结合k1,算出S2V输出V。将V作为CTR的IV,结合K2和原文,计算密文C。返回 V | C。 |
eax
RFC3686: Using Advanced Encryption Standard (AES) Counter Mode With IPsec Encapsulating Security Payload (ESP)
stream示例
nonce per-session 32bits, IV per-packet 64bits, ONE=0x01 32bits
CTRBLK := NONCE || IV || ONE
FOR i := 1 to n-1 DO
CT[i] := PT[i] XOR AES(CTRBLK)
CTRBLK := CTRBLK + 1
END
CT[n] := PT[n] XOR TRUNC(AES(CTRBLK))
RFC5649: Advanced Encryption Standard (AES) Key Wrap with Padding Algorithm
单block size以内,padding一下,再ECB。
其他则用RFC3394的aes key wrap
RFC3394: Advanced Encryption Standard (AES) Key Wrap Algorithm
太长不看
aegis
The AEGIS Family of Authenticated Encryption Algorithms
two AES-based authenticated encryption algorithms designed for high-performance applications