axtls_aes.c File Reference

AES algorithm. More...

#include <string.h>
#include <errno.h>
#include <byteswap.h>
#include <gpxe/crypto.h>
#include <gpxe/cbc.h>
#include <gpxe/aes.h>
#include "crypto/axtls/crypto.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static int aes_setkey (void *ctx, const void *key, size_t keylen)
 Set key.
static void aes_setiv (void *ctx __unused, const void *iv __unused)
 Set initialisation vector.
static void aes_call_axtls (AES_CTX *axtls_ctx, const void *src, void *dst, void(*func)(const AES_CTX *axtls_ctx, uint32_t *data))
 Call AXTLS' AES_encrypt() or AES_decrypt() functions.
static void aes_encrypt (void *ctx, const void *src, void *dst, size_t len)
 Encrypt data.
static void aes_decrypt (void *ctx, const void *src, void *dst, size_t len)
 Decrypt data.
 CBC_CIPHER (aes_cbc, aes_cbc_algorithm, aes_algorithm, struct aes_context, AES_BLOCKSIZE)

Variables

struct cipher_algorithm aes_algorithm
 Basic AES algorithm.


Detailed Description

AES algorithm.

Definition in file axtls_aes.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

static int aes_setkey ( void *  ctx,
const void *  key,
size_t  keylen 
) [static]

Set key.

Parameters:
ctx Context
key Key
keylen Key length
Return values:
rc Return status code

Definition at line 43 of file axtls_aes.c.

References AES_MODE_128, AES_MODE_256, AES_set_key(), aes_context::axtls_ctx, aes_context::decrypting, EINVAL, and aes_key_st::iv.

00043                                                                     {
00044         struct aes_context *aes_ctx = ctx;
00045         AES_MODE mode;
00046         void *iv;
00047 
00048         switch ( keylen ) {
00049         case ( 128 / 8 ):
00050                 mode = AES_MODE_128;
00051                 break;
00052         case ( 256 / 8 ):
00053                 mode = AES_MODE_256;
00054                 break;
00055         default:
00056                 return -EINVAL;
00057         }
00058 
00059         /* IV is not a relevant concept at this stage; use a dummy
00060          * value that will have no side-effects.
00061          */
00062         iv = &aes_ctx->axtls_ctx.iv;
00063 
00064         AES_set_key ( &aes_ctx->axtls_ctx, key, iv, mode );
00065 
00066         aes_ctx->decrypting = 0;
00067 
00068         return 0;
00069 }

static void aes_setiv ( void *ctx  __unused,
const void *iv  __unused 
) [static]

Set initialisation vector.

Parameters:
ctx Context
iv Initialisation vector

Definition at line 77 of file axtls_aes.c.

00077                                                                       {
00078         /* Nothing to do */
00079 }

static void aes_call_axtls ( AES_CTX axtls_ctx,
const void *  src,
void *  dst,
void(*)(const AES_CTX *axtls_ctx, uint32_t *data)  func 
) [static]

Call AXTLS' AES_encrypt() or AES_decrypt() functions.

Parameters:
axtls_ctx AXTLS AES context
src Data to process
dst Buffer for output
func AXTLS AES function to call

Definition at line 89 of file axtls_aes.c.

References htonl, and ntohl.

Referenced by aes_decrypt(), and aes_encrypt().

00091                                                                  {
00092         const uint32_t *srcl = src;
00093         uint32_t *dstl = dst;
00094         unsigned int i;
00095 
00096         /* AXTLS' AES_encrypt() and AES_decrypt() functions both
00097          * expect to deal with an array of four dwords in host-endian
00098          * order.
00099          */
00100         for ( i = 0 ; i < 4 ; i++ )
00101                 dstl[i] = ntohl ( srcl[i] );
00102         func ( axtls_ctx, dstl );
00103         for ( i = 0 ; i < 4 ; i++ )
00104                 dstl[i] = htonl ( dstl[i] );
00105 }

static void aes_encrypt ( void *  ctx,
const void *  src,
void *  dst,
size_t  len 
) [static]

Encrypt data.

Parameters:
ctx Context
src Data to encrypt
dst Buffer for encrypted data
len Length of data

Definition at line 115 of file axtls_aes.c.

References AES_BLOCKSIZE, aes_call_axtls(), AES_encrypt(), assert, aes_context::axtls_ctx, and aes_context::decrypting.

00116                                        {
00117         struct aes_context *aes_ctx = ctx;
00118 
00119         assert ( len == AES_BLOCKSIZE );
00120         if ( aes_ctx->decrypting )
00121                 assert ( 0 );
00122         aes_call_axtls ( &aes_ctx->axtls_ctx, src, dst, AES_encrypt );
00123 }

static void aes_decrypt ( void *  ctx,
const void *  src,
void *  dst,
size_t  len 
) [static]

Decrypt data.

Parameters:
ctx Context
src Data to decrypt
dst Buffer for decrypted data
len Length of data

Definition at line 133 of file axtls_aes.c.

References AES_BLOCKSIZE, aes_call_axtls(), AES_convert_key(), AES_decrypt(), assert, aes_context::axtls_ctx, and aes_context::decrypting.

00134                                        {
00135         struct aes_context *aes_ctx = ctx;
00136 
00137         assert ( len == AES_BLOCKSIZE );
00138         if ( ! aes_ctx->decrypting ) {
00139                 AES_convert_key ( &aes_ctx->axtls_ctx );
00140                 aes_ctx->decrypting = 1;
00141         }
00142         aes_call_axtls ( &aes_ctx->axtls_ctx, src, dst, AES_decrypt );
00143 }

CBC_CIPHER ( aes_cbc  ,
aes_cbc_algorithm  ,
aes_algorithm  ,
struct aes_context  ,
AES_BLOCKSIZE   
)


Variable Documentation

Initial value:

 {
        .name = "aes",
        .ctxsize = sizeof ( struct aes_context ),
        .blocksize = AES_BLOCKSIZE,
        .setkey = aes_setkey,
        .setiv = aes_setiv,
        .encrypt = aes_encrypt,
        .decrypt = aes_decrypt,
}
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().


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