# AES (Advanced Encryption Standard)
[Libraries]

Encrypt and decrypt data using AES. More...

## Functions
int | Aes_Encrypt (unsigned char *output, int outlen, unsigned char *input, int inlen, unsigned char *password)
| Ecrypt a block of data using AES.
int | Aes_Decrypt (unsigned char *output, int outlen, unsigned char *input, int inlen, unsigned char *password)
| Decrypt a block of AES encrypted data.

## Detailed Description

Encrypt and decrypt data using AES.

AES is a block cipher adopted for use by the NSA (US government agency). According to Wikipedia, "This marks the first time the public has had access to a cipher approved by the NSA for top secret information." Pretty cool, right? This is a good way to send info privately from your Make Controller over the network, to a web server for example.

AES requires that both sides of communication have access to the same key. So both your Make Controller, and whatever other device it's communicating with need to know about the same password so they can decrypt data that has been encrypted by the other.

There are several different flavors of AES. There are two main ways in which AES libraries differ:

- the way they chain blocks
- the way they pad data

This library uses ECB (Electronic Code Book) chaining, and pads data with a character that corresponds to the number of bytes needed to pad to 16. Check the Wikipedia article for an explanation - http://en.wikipedia.org/wiki/Advanced_Encryption_Standard

The lookup tables used in this library will use somewhere between 8 and 13 kB of program space, depending on the compiler optimization you use. Memory usage is pretty minimal.

Code is used and adapted from Philip J. Erdelsky - see http://www.efgh.com/software/rijndael.htm for the original.

## Function Documentation

int Aes_Decrypt | ( | unsigned char * | output,
|  | int | outlen,
|  | unsigned char * | input,
|  | int | inlen,
|  | unsigned char * | password |
| ) |  |  |

Decrypt a block of AES encrypted data.

Parameters:

  | output | A pointer to the buffer into which the decrypted data will be written.
  | outlen | The maximum number of bytes of data to write into the output buffer.
  | input | A pointer to the encrypted block to be decrytped.
  | inlen | The number of bytes to be decrypted.
  | password | The password, or key, used to encrypt the data. Must be 16 bytes long.

Returns:
  The number of bytes written, or -1 on failure.

Example

        // first encrypt some data, then decrypt it and make sure we get out what we put in
        unsigned char cipherbuf[256];
        unsigned char plainbuf[256];
        unsigned char plaintext[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // our plaintext to encrypt
        unsigned char secret[] = "A SECRET PASSWORD"; // 16 bytes long

        int written = Aes_Encrypt(cipherbuf, 256, plaintext, 26, secret);
        written = Aes_Decrypt(plainbuf, 256, cipherbuf, written, secret);
        // we now have our original plaintext in plainbuf

Definition at line 1373 of file aes.c.

int Aes_Encrypt | ( | unsigned char * | output,
|  | int | outlen,
|  | unsigned char * | input,
|  | int | inlen,
|  | unsigned char * | password |
| ) |  |  |

Ecrypt a block of data using AES.

Parameters:

  | output | A pointer to the buffer into which the encrypted data will be written.
  | outlen | The maximum number of bytes to write into the output buffer.
  | input | A pointer to the data to be encrypted.
  | inlen | The number of bytes of data to encrypt.
  | password | The password, or key, used to encrypt the data. Must be 16 bytes long.

Returns:
  The number of bytes encrypted, or -1 on failure.

Example

        #define BUFF_SIZE 256
        unsigned char cipherbuf[BUFF_SIZE]; // the buffer that will be written into
        unsigned char plaintext[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // the text to encrypt
        unsigned char secret[] = "A SECRET PASSWORD"; // 16 bytes long
        int written = Aes_Encrypt(cipherbuf, BUFF_SIZE, plaintext, 26, secret);

Definition at line 1298 of file aes.c.