工作模式.md

参考:

分组密码工作模式

电子密码本 EBC

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
              +----------------+                    +-----------------+   
              | plaintext[0:n] |                    | plaintext[n:2n] |   
              +-------|--------+                    +-------|---------+   
                      |                                     |             
                      v                                     v             
         +-------------------------+           +-------------------------+
 key---->| block cipher encryption |   key---->| block cipher encryption |
         +------------|------------+           +------------|------------+
                      |                                     |             
                      v                                     v             
              +-----------------+                   +------------------+  
              | ciphertext[0:n] |                   | ciphertext[n:2n] |  
              +-----------------+                   +------------------+  

密码分组连接 CBC

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
             +----------------+                    +-----------------+    
             | plaintext[0:n] |                    | plaintext[n:2n] |    
             +--------+-------+                    +--------+--------+    
                      |                                     |             
                      v                                     v             
 iv----------------->xor             +-------------------->xor            
                      |              |                      |             
                      v              |                      v             
         +-------------------------+ |         +-------------------------+
 key---->| block cipher encryption | | key---->| block cipher encryption |
         +------------|------------+ |         +------------|------------+
                      |              |                      |             
                      v              |                      v             
              +-----------------+    |              +------------------+  
              | ciphertext[0:n] -----+              | ciphertext[n:2n] |  
              +-----------------+                   +------------------+  

密码反馈 CFB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
                     iv                                                      
                      |              --------------------------+             
                      v              |                         v             
         +-------------------------+ |            +-------------------------+
 key---->| block cipher encryption | |    key---->| block cipher encryption |
         +------------+------------+ |            +------------+------------+
                      |              |                         |             
+----------------+    v              |  +-----------------+    v             
| plaintext[0:n] +-->xor             |  | plaintext[n:2n] +-->xor
+----------------+    |              |  +-----------------+    |             
                      v              |                         v             
              +-----------------+    |                +------------------+    
              | ciphertext[0:n] +----+                | ciphertext[n:2n] |    
              +-----------------+                     +------------------+    

输出反馈 OFB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
                     iv                                                      
                      |              --------------------------+             
                      v              |                         v             
         +-------------------------+ |            +-------------------------+
 key---->| block cipher encryption | |    key---->| block cipher encryption |
         +------------+------------+ |            +------------+------------+
                      |              |                         |
                      +--------------+                         |             
+----------------+    v                 +-----------------+    v             
| plaintext[0:n] +-->xor                | plaintext[n:2n] +-->xor            
+----------------+    |                 +-----------------+    |             
                      v                                        v             
              +-----------------+                    +------------------+    
              | ciphertext[0:n] |                    | ciphertext[n:2n] |    
              +-----------------+                    +------------------+    

计数器 CTR

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
           +----------+----------+                  +----------+----------+  
           |    nonce |counter=0 |                  |    nonce |counter=1 |  
           +----------+----------+                  +----------+----------+  
                      |                                        |             
                      v                                        v             
         +-------------------------+              +-------------------------+
 key---->| block cipher encryption |      key---->| block cipher encryption |
         +------------+------------+              +------------+------------+
                      |                                        |             
+----------------+    v                 +-----------------+    v             
| plaintext[0:n] --->xor                | plaintext[n:2n] --->xor            
+----------------+    |                 +-----------------+    |             
                      v                                        v             
              +-----------------+                    +------------------+    
              | ciphertext[0:n] |                    | ciphertext[n:2n] |    
              +-----------------+                    +------------------+