aes.h File Reference

#include "crypto/axtls/crypto.h"

Go to the source code of this file.

Data Structures

struct  aes_context
 AES context. More...

Defines

#define AES_BLOCKSIZE   16
 Basic AES blocksize.
#define AES_CTX_SIZE   sizeof ( struct aes_context )
 AES context size.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
int aes_wrap (const void *kek, const void *src, void *dest, int nblk)
 Wrap a key or other data using AES Key Wrap (RFC 3394).
int aes_unwrap (const void *kek, const void *src, void *dest, int nblk)
 Unwrap a key or other data using AES Key Wrap (RFC 3394).

Variables

struct cipher_algorithm aes_algorithm
 Basic AES algorithm.
struct cipher_algorithm aes_cbc_algorithm


Define Documentation

#define AES_BLOCKSIZE   16

Basic AES blocksize.

Definition at line 9 of file aes.h.

Referenced by aes_decrypt(), and aes_encrypt().

#define AES_CTX_SIZE   sizeof ( struct aes_context )

AES context size.

Definition at line 22 of file aes.h.

Referenced by aes_unwrap(), and aes_wrap().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

int aes_wrap ( const void *  kek,
const void *  src,
void *  dest,
int  nblk 
)

Wrap a key or other data using AES Key Wrap (RFC 3394).

Parameters:
kek Key Encryption Key, 16 bytes
src Data to encrypt
nblk Number of 8-byte blocks in data
Return values:
dest Encrypted data (8 bytes longer than input)
The algorithm is implemented such that src and dest may point to the same buffer.

Definition at line 37 of file aes_wrap.c.

References aes_algorithm, AES_CTX_SIZE, cipher_encrypt, cipher_setkey(), free(), malloc(), memcpy, memmove(), memset(), and u8.

00038 {
00039         u8 *A = dest;
00040         u8 B[16];
00041         u8 *R;
00042         int i, j;
00043         void *aes_ctx = malloc ( AES_CTX_SIZE );
00044 
00045         if ( ! aes_ctx )
00046                 return -1;
00047 
00048         cipher_setkey ( &aes_algorithm, aes_ctx, kek, 16 );
00049 
00050         /* Set up */
00051         memset ( A, 0xA6, sizeof ( A ) );
00052         memmove ( dest + 8, src, nblk * 8 );
00053 
00054         /* Wrap */
00055         for ( j = 0; j < 6; j++ ) {
00056                 R = dest + 8;
00057                 for ( i = 1; i <= nblk; i++ ) {
00058                         memcpy ( B, A, 8 );
00059                         memcpy ( B + 8, R, 8 );
00060                         cipher_encrypt ( &aes_algorithm, aes_ctx, B, B, 16 );
00061                         memcpy ( A, B, 8 );
00062                         A[7] ^= ( nblk * j ) + i;
00063                         memcpy ( R, B + 8, 8 );
00064                         R += 8;
00065                 }
00066         }
00067 
00068         free ( aes_ctx );
00069         return 0;
00070 }

int aes_unwrap ( const void *  kek,
const void *  src,
void *  dest,
int  nblk 
)

Unwrap a key or other data using AES Key Wrap (RFC 3394).

Parameters:
kek Key Encryption Key, 16 bytes
src Data to decrypt
nblk Number of 8-byte blocks in plaintext key
Return values:
dest Decrypted data (8 bytes shorter than input)
rc Zero on success, nonzero on IV mismatch
The algorithm is implemented such that src and dest may point to the same buffer.

Definition at line 84 of file aes_wrap.c.

References aes_algorithm, AES_CTX_SIZE, cipher_decrypt, cipher_setkey(), free(), malloc(), memcpy, memmove(), and u8.

Referenced by ccmp_kie_decrypt().

00085 {
00086         u8 A[8], B[16];
00087         u8 *R;
00088         int i, j;
00089         void *aes_ctx = malloc ( AES_CTX_SIZE );
00090 
00091         if ( ! aes_ctx )
00092                 return -1;
00093 
00094         cipher_setkey ( &aes_algorithm, aes_ctx, kek, 16 );
00095 
00096         /* Set up */
00097         memcpy ( A, src, 8 );
00098         memmove ( dest, src + 8, nblk * 8 );
00099 
00100         /* Unwrap */
00101         for ( j = 5; j >= 0; j-- ) {
00102                 R = dest + ( nblk - 1 ) * 8;
00103                 for ( i = nblk; i >= 1; i-- ) {
00104                         memcpy ( B, A, 8 );
00105                         memcpy ( B + 8, R, 8 );
00106                         B[7] ^= ( nblk * j ) + i;
00107                         cipher_decrypt ( &aes_algorithm, aes_ctx, B, B, 16 );
00108                         memcpy ( A, B, 8 );
00109                         memcpy ( R, B + 8, 8 );
00110                         R -= 8;
00111                 }
00112         }
00113 
00114         free ( aes_ctx );
00115 
00116         /* Check IV */
00117         for ( i = 0; i < 8; i++ ) {
00118                 if ( A[i] != 0xA6 )
00119                         return -1;
00120         }
00121 
00122         return 0;
00123 }


Variable Documentation

Basic AES algorithm.

Definition at line 146 of file axtls_aes.c.

Referenced by aes_unwrap(), aes_wrap(), ccmp_cbc_mac(), ccmp_ctr_xor(), ccmp_feed_cbc_mac(), and ccmp_init().

Referenced by tls_select_cipher().


Generated on Tue Apr 6 20:01:48 2010 for gPXE by  doxygen 1.5.7.1