AES 演算法,分組長度為128 bit,密鑰長度可為128、192、256 bit。
AES_128_CBC(Cipher Block Chaining)
1、The total number of bits in the plaintext must be a multiple of the block size, 128bit。
加密就是將各段加密然後拼接起來,再在頭上加上IV,輸入包含:aes key、IV、plaintext | padding,輸出為:ciphertext;
解密時,輸入包括:aes key、IV、ciphertext,輸出為:plaintext。
2、CBC Encryption: C1 = CIPHK(P1 ⊕ IV);
Cj = CIPHK(Pj ⊕ Cj-1) for j = 2 … n.
CBC Decryption: P1 = CIPH-1K(C1) ⊕ IV;
Pj = CIPH -1K(Cj) ⊕ Cj-1 for j = 2 … n
其中 IV 是128 bits,其產生參考《sp800-38a.pdf》p27;
padding 具體參考《sp800-38a.pdf》p24 和 《rfc 2630》,我沒搞清楚;
CIPHK 指的是 aes128 的加密函數,CIPH -1K 指的是 aes128 的解密函數。
3、圖示
請看《sp800-38a.pdf》 p17。
AES_128_CTR(Counter)
1、The total number of bits in the message is (n-1)b+u, where 1≤ u≤ b。
加密就是各段加密拼接,再在頭上加上initial counter。輸入包含:aes key、initial counter、plaintext,輸出為:ciphertext;
解密時,輸入包括:aes key、initial counter、ciphertext,其輸出為:plaintext。
2、 CTR Encryption: Oj = CIPHK(Tj) for j = 1, 2 … n;
Cj = Pj ⊕ Oj for j = 1, 2 … n-1;
C*n = P*n ⊕ MSBu(On).
CTR Decryption: Oj = CIPHK(Tj) for j = 1, 2 … n;
Pj = Cj ⊕ Oj for j = 1, 2 … n-1;
P*n = C*n ⊕ MSBu(On).
其中 initial counter 即 T1 是 128 bits,其產生參考《sp800-38a.pdf》p26;
T2....Tn 的產生是通過 Incrementing Function,參考 《sp800-38a.pdf》p25,其實就是在原基礎上加 1;
CIPHK 指的是 aes128 的加密函數;
MSB 指的是 Most Significant Bit。
3、圖示
請看《sp800-38a.pdf》 p23。
本文所有東西均歸納自《sp800-38a.pdf》。