- This is an implementation of the AES encryption algorithm (Rijndael)
- designed by Joan Daemen and Vincent Rijmen. This version is designed
- to provide both fixed and dynamic block and key lengths and can also
- run with either big or little endian internal byte order.
-
- NOTE: Input block and key lengths are given in terms of the lengths of
- the byte arrays involved, the legal values being 16, 24 and 32.
-
- A. THE CIPHER INTERFACE
-
- byte (an unsigned 8-bit type)
- word (an unsigned 32-bit type)
- aes_ret: (a signed 16 bit type for function return values)
- aes_good (value != 0, a good return)
- aes_bad (value == 0, an error return)
- enum aes_key: (encryption direction)
- enc (set key for encryption)
- dec (set key for decryption)
- both (set key for both)
- class or struct aes (structure for context)
-
- C subroutine calls:
-
- aes_ret set_blk(const word block_length, aes *cx) (variable block size)
- aes_ret set_key(const byte key[], const word key_length,
- const enum aes_key direction, aes *cx)
- aes_ret encrypt(const byte input_blk[], byte output_blk[], const aes *cx)
- aes_ret decrypt(const byte input_blk[], byte output_blk[], const aes *cx)
-
- IMPORTANT NOTE: If you are using this C interface and your compiler does
- not set the memory used for objects to zero before use, you will need to
- ensure that cx.mode is set to zero before using the C subroutine calls.
-
- C++ aes class subroutines:
-
- aes_ret set_blk(const word block_length) (variable block size)
- aes_ret set_key(const byte key[], const word key_length,
- const aes_key direction)
- aes_ret encrypt(const byte input_blk[], byte output_blk[]) const
- aes_ret decrypt(const byte input_blk[], byte output_blk[]) const
-
- The block length inputs to set_block and set_key are in numbers of
- BYTES, not bits. The calls to subroutines must be made in the above
- order but multiple calls can be made without repeating earlier calls
- if their parameters have not changed. If the cipher block length is
- variable but set_blk has not been called before cipher operations a
- value of 16 is assumed (that is, the AES block size). In contrast to
- earlier versions the block and key length parameters are now checked
- for correctness and the encryption and decryption routines check to
- ensure that an appropriate key has been set before they are called.
-
- B. BYTE ORDER WITHIN 32 BIT WORDS
-
- The fundamental data processing units in Rijndael are 8-bit bytes. The
- input, the output and the key input are all enumerated arrays of bytes
- in which bytes are numbered starting at zero and increasing to one less
- than the number of bytes in the array in question. When these inputs
- and outputs are considered as bit sequences, the n'th byte contains
- bits 8n to 8n+7 of the sequence with the lower numbered bit mapped to
- the most significant bit within the byte (i.e. that having a numeric
- value of 128). However, Rijndael can be implemented more efficiently
- using 32-bit words to process 4 bytes at a time provided that the order
- of bytes within words is known. This order is called big-endian if the
- lowest numbered bytes in words have the highest numeric significance
- and little-endian if the opposite applies. This code can work in either
- order irrespective of the native order of the machine on which it runs.
- The byte order used internally is set by defining INTERNAL_BYTE_ORDER
- whereas the order for all inputs and outputs is specified by defining
- EXTERNAL_BYTE_ORDER, the only purpose of the latter being to determine
- if a byte order change is needed immediately after input and immediately
- before output to account for the use of a different internal byte order.
- In almost all situations both of these defines will be set to the native
- order of the processor on which the code is to run but other settings
- may somtimes be useful in special circumstances.
-
-#define INTERNAL_BYTE_ORDER LITTLE_ENDIAN
-#define EXTERNAL_BYTE_ORDER LITTLE_ENDIAN
-
- C. COMPILATION
-
- To compile AES (Rijndael) for use in C code
- a. Exclude the AES_DLL define in aes.h
- b. Exclude the AES_IN_CPP define in aes.h
-
- To compile AES (Rijndael) for use in in C++ code
- a. Exclude the AES_DLL define in aes.h
- b. Include the AES_IN_CPP define in aes.h
-
- To compile AES (Rijndael) in C as a Dynamic Link Library
- a. Include the AES_DLL define in aes.h
- b. Compile the DLL. If using the test files, exclude aes.c from
- the test build project and compile it with the same defines
- as used for the DLL (ensure that the DLL path is correct)
-
- D. CONFIGURATION OPTIONS (see also aes.c)
-
- 1. define BLOCK_SIZE to set the cipher block size (16, 24 or 32) or
- leave this undefined for dynamically variable block size (this will
- result in much slower code).
- 2. set AES_IN_CPP to use the code from C++ rather than C
- 3. set AES_DLL if AES (Rijndael) is to be compiled to a DLL
- 4. set INTERNAL_BYTE_ORDER to one of the above constants to set the
- internal byte order (the order used within the algorithm code)
- 5. set EXTERNAL_BYTE_ORDER to one of the above constants to set the byte
- order used at the external interfaces for the input, output and key
- byte arrays.
-
- IMPORTANT NOTE: BLOCK_SIZE is in BYTES: 16, 24, 32 or undefined for aes.c
- and 16, 20, 24, 28, 32 or undefined for aes++.c. If left undefined a
- slower version providing variable block length is compiled
-
-#define BLOCK_SIZE 16
-
- Define AES_IN_CPP if you intend to use the AES C++ class rather than the
- C code directly.
-
-#define AES_IN_CPP
-
- Define AES_DLL if you wish to compile the code to produce a Windows DLL
-
-#define AES_DLL
-