Modes of Operation

by: burt rosenberg
at: university of miami
date: sep 2019
NAME
    encrypt
    
SYNOPSIS
    encrypt.py [-dv] [-m _mode_] [-n _nonce_] [-p _padding_] key
  
DESCRIPTION
    Encrypt standard-in to standard-out using AES-128.

    The key is an ascii string interpreted as a byte string, padded with nulls 
    or truncated to the key length of 16 bytes. 

    The input is padded to a multiple of the block size, 16 bytes, using PKCS#7 or
    optionally another padding standard. The encryption is by counter mode, or optionally
    by another mode. 

OPTIONS 
    -h help
    -d decrypt
    -m the mode to use, one of cntr (default) cbc, ofb or ecb.
    -n the IV to use aka the nonce. if omitted algorithm uses a random nonce (recommended)
    -p the padding to use, one of pkcs (default), iso or zero
    -v verbose

NEW OPTIONS (after 2019)
    -h help
    -d decrypt
    -m the mode to use, one of cntr (default) cbc, ofb or ecb.
    -n endian, either "big" or "little"
    -p the padding to use, one of pkcs (default), iso or zero
    -R no randomness. The IV and key are set to zero, and the key argument is ignored
    -v verbose

HISTORY
    Introduced in csc609/507-201 september 2019

BUGS
    No specification for ecb/zero mode on an empty message.
    No endianness specification for counter mode.
    Interface changed and some options were renamed.

Goals

The block cipher we will use is AES, the Advanced Encryption Standard (AES). AES is the result of a world wide competition for a cipher to replace DES, the Digital Encryption Standard, as the NIST recognized standard cipher. As an entry in the competition, the cipher was called Rijndael, after the inventors. Because that is hard to spell, it was also known as Rain-Doll.

Please implement all modes and paddings of the encrypt.py description above.

I have adapted a publicly available python implementation of Rain-Doll, despite the fact that it would be wiser to have included a standard Python package implementing the cipher. However, I wanted just the core code, as transparently written as possible, ad simply support simple block encryption. Cryptography libraries would also include implementations of modes, paddings, and more advanced features, that I do not want to highlight at this time.

Modes of Operation


             m0      m1      m2  
             |       |       |   
             |       |       |    
            +-+     +-+     +-+  
            |E|     |E|     |E|  
            +-+     +-+     +-+       
             |       |       |         
             |       |       |  
             c1      c2      c3      

            **** ECB Mode  ****  
            
                        

      IV     m0      m1      m2  
      |      |       |       |   
      +-----(+)  +--(+)  +--(+)   
      |      |   |   |   |   |    
      |     +-+  |  +-+  |  +-+  
      |     |E|  |  |E|  |  |E|  
      |     +-+  |  +-+  |  +-+       
      |      |   |   |   |   |         
      |      +---+   +---+   +--- ...       
      |      |       |       |  
      c0/IV  c1      c2      c3      

         ****  CBC Mode  ****              
               
      IV  
      |
      +----+   +----+   +----+
      |    |   |    |   |    |
      |   +-+  |   +-+  |   +-+
      |   |E|  |   |E|  |   |E|
      |   +-+  |   +-+  |   +-+  
      |    |   |    |   |    |
      |    +---+    +---+    +--- ...
      |    |        |        |   
      |   (+)--m0  (+)--m1  (+)--m2 
      |    |        |        |  
   c0/IV   c1       c2       c3
         
         ****  OFB MODE  ****

      IV  
      |
      +----+--|+1|--+--|+1|--+-- ... 
      |    |        |        |
      |   +-+      +-+      +-+
      |   |E|      |E|      |E|
      |   +-+      +-+      +-+  
      |    |        |        |   
      |   (+)--m0  (+)--m1  (+)--m2 
      |    |        |        |  
   c0/IV   c1       c2       c3
         
      ****  COUNTER MODE  ****


Electronic code book (ECB)
Cipher block chaining (CBC)
Output Feedback (OFB)
Counter Mode

Padding schemes

PKCS#7 padding using the rules:
ISO padding using the rules:
Zero padding using the rules:
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

author: burton rosenberg
created: 22 sep 2019
update: 19 oct 2019