OKlibrary  0.2.1.6
AdvancedEncryptionStandard.hpp File Reference

User documentation for the Maxima computer algebra system implementation of the AES block cipher. More...

Go to the source code of this file.


Detailed Description

User documentation for the Maxima computer algebra system implementation of the AES block cipher.

Using AES at the Maxima/Lisp level

Functions are presented which implement the AES ("Advanced Encryption Standard") block cipher.

Overview

  • Throughout the implementation, particular parameters maintain the same shortened names for brevity, and ease of use:
    • p - plaintext block
    • k - key block
    • c - ciphertext block.
  • In all functions the plaintext, key and ciphertext blocks are assumed to be the same dimension.
  • There are several helper functions which allow one to use the AES encryption and decryption functions with preset parameter functions:
    • "aes_encrypt(p,k,r)" and "aes_decrypt(c,k,r)" are the functions used to encrypt/decrypt a plaintext 4xn (for n = 4,5 or 6) matrix p with a key matrix k of the same dimension, where the elements of the matrices are given as polynomials (see "Data Types"). Here, r is the number of rounds to apply during encryption/decryption.
    • "aes_encrypt_nat" and "aes_decrypt_nat" are the same as "aes_encrypt" and "aes_decrypt", except they take lists of integers, which represent the matrices polynomials column by column from "aes_encrypt" etc via int2poly(n,2) where n is the integer (see "Examples").
  • For each of the above functions, there are versions suffixed with "_std" which fix the number of rounds to the standard 10 for AES.

Data Types

  • AES bytes are represented as arbitrary polynomials and then are "brought into range" or "standardised" using the Rijndael modulo polynomial (see rijn_polynomial in ComputerAlgebra/Cryptology/Lisp/CryptoSystems/Rijndael/ByteField.mac).
  • AES blocks are then matrices of polynomials, where the four row, n column nature of the AES block is given by the dimension of the matrix.
  • There is no interface within this implementation to the bit-level of the AES, although one can access this level if one standardises a polynomial (representing a byte) using rijn_stand (see ComputerAlgebra/Cryptology/Lisp/CryptoSystems/Rijndael/ByteField.mac) and then considers the coefficient of the polynomial using the same correspondence of coefficients to "bits of a byte" as occurs in the definition of Rijndael (i.e., the coefficient of x^7 becomes the most significant bit of the byte and the coefficient of 1 becomes the least - see [Design of Rijndael;John Daemen and Vincent Rijmen]).

Examples

  • Encrypting a 128-bit word represented as a list of integers :
    > key :  [202,200,168,53,202,187,250,252,46,206,107,75,12,120,233,226]$
    > plaintext : create_list(i,i,0,15)$
    > ciphertext : aes_encrypt_nat_std(plaintext,key);
    [223,7,143,218,18,249,134,153,203,218,50,237,88,69,163,149]
    > aes_decrypt_nat_std(ciphertext,key);
    [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
       
  • There are also helper functions which allow the encryption or decryption using the hexidecimal notation used for AES/Rijndael:
    > plaintext : "3243F6A8885A308D313198A2E0370734"$
    > key       : "2B7E151628AED2A6ABF7158809CF4F3C"$
    > aes_encrypt_hex_std(plaintext,key);
    "3925841D02DC09FBDC118597196A0B32"
    > aes_decrypt_hex_std("3925841D02DC09FBDC118597196A0B32", key);
    "2B7E151628AED2A6ABF7158809CF4F3C"
       
    This test vector is taken from [Design of Rijndael;John Daemen and Vincent Rijmen].
  • A general remark:
    1. AES is a cryptographic primitive, and should not be used directly for encryption purposes.
    2. Care must be taken how to decompose a larger piece of data to be encrypted into blocks of the (small) sizes allowed by AES.
    3. Most useful in this respect is the "CBC mode" (cipher-block chaining mode; not implemented yet), which encrypts a sequence of blocks in a manner such that the result of the encryption of one block influences the encryption of the next block.

Definition in file AdvancedEncryptionStandard.hpp.