cbc.h File Reference

Cipher-block chaining. More...

#include <gpxe/crypto.h>

Go to the source code of this file.

Defines

#define CBC_CIPHER(_cbc_name, _cbc_cipher, _raw_cipher, _raw_context, _blocksize)
 Create a cipher-block chaining mode of behaviour of an existing cipher.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static int cbc_setkey (void *ctx, const void *key, size_t keylen, struct cipher_algorithm *raw_cipher, void *cbc_ctx __unused)
 Set key.
static void cbc_setiv (void *ctx __unused, const void *iv, struct cipher_algorithm *raw_cipher, void *cbc_ctx)
 Set initialisation vector.
void cbc_encrypt (void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher, void *cbc_ctx)
 Encrypt data.
void cbc_decrypt (void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher, void *cbc_ctx)
 Decrypt data.


Detailed Description

Cipher-block chaining.

Definition in file cbc.h.


Define Documentation

#define CBC_CIPHER ( _cbc_name,
_cbc_cipher,
_raw_cipher,
_raw_context,
_blocksize   ) 

Create a cipher-block chaining mode of behaviour of an existing cipher.

Parameters:
_cbc_name Name for the new CBC cipher
_cbc_cipher New cipher algorithm
_raw_cipher Underlying cipher algorithm
_raw_context Context structure for the underlying cipher
_blocksize Cipher block size

Definition at line 62 of file cbc.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

static int cbc_setkey ( void *  ctx,
const void *  key,
size_t  keylen,
struct cipher_algorithm raw_cipher,
void *cbc_ctx  __unused 
) [inline, static]

Set key.

Parameters:
ctx Context
key Key
keylen Key length
raw_cipher Underlying cipher algorithm
cbc_ctx CBC context
Return values:
rc Return status code

Definition at line 24 of file cbc.h.

References cipher_setkey().

00026                                                         {
00027 
00028         return cipher_setkey ( raw_cipher, ctx, key, keylen );
00029 }

static void cbc_setiv ( void *ctx  __unused,
const void *  iv,
struct cipher_algorithm raw_cipher,
void *  cbc_ctx 
) [inline, static]

Set initialisation vector.

Parameters:
ctx Context
iv Initialisation vector
raw_cipher Underlying cipher algorithm
cbc_ctx CBC context

Definition at line 39 of file cbc.h.

References cipher_algorithm::blocksize, and memcpy.

00041                                                {
00042         memcpy ( cbc_ctx, iv, raw_cipher->blocksize );
00043 }

void cbc_encrypt ( void *  ctx,
const void *  src,
void *  dst,
size_t  len,
struct cipher_algorithm raw_cipher,
void *  cbc_ctx 
)

Encrypt data.

Parameters:
ctx Context
src Data to encrypt
dst Buffer for encrypted data
len Length of data
raw_cipher Underlying cipher algorithm
cbc_ctx CBC context

Definition at line 61 of file cbc.c.

References assert, cipher_algorithm::blocksize, digest_algorithm::blocksize, cbc_xor(), cipher_encrypt, and memcpy.

00062                                                                         {
00063         size_t blocksize = raw_cipher->blocksize;
00064 
00065         assert ( ( len % blocksize ) == 0 );
00066 
00067         while ( len ) {
00068                 cbc_xor ( src, cbc_ctx, blocksize );
00069                 cipher_encrypt ( raw_cipher, ctx, cbc_ctx, dst, blocksize );
00070                 memcpy ( cbc_ctx, dst, blocksize );
00071                 dst += blocksize;
00072                 src += blocksize;
00073                 len -= blocksize;
00074         }
00075 }

void cbc_decrypt ( void *  ctx,
const void *  src,
void *  dst,
size_t  len,
struct cipher_algorithm raw_cipher,
void *  cbc_ctx 
)

Decrypt data.

Parameters:
ctx Context
src Data to decrypt
dst Buffer for decrypted data
len Length of data
raw_cipher Underlying cipher algorithm
cbc_ctx CBC context

Definition at line 87 of file cbc.c.

References assert, cipher_algorithm::blocksize, digest_algorithm::blocksize, cbc_xor(), cipher_decrypt, and memcpy.

00088                                                                         {
00089         size_t blocksize = raw_cipher->blocksize;
00090 
00091         assert ( ( len % blocksize ) == 0 );
00092 
00093         while ( len ) {
00094                 cipher_decrypt ( raw_cipher, ctx, src, dst, blocksize );
00095                 cbc_xor ( cbc_ctx, dst, blocksize );
00096                 memcpy ( cbc_ctx, src, blocksize );
00097                 dst += blocksize;
00098                 src += blocksize;
00099                 len -= blocksize;
00100         }
00101 }


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