iPXE
Defines | Functions
ecb.h File Reference

Electronic codebook (ECB) More...

#include <ipxe/crypto.h>

Go to the source code of this file.

Defines

#define ECB_CIPHER(_ecb_name, _ecb_cipher, _raw_cipher, _raw_context, _blocksize)
 Create a cipher-block chaining mode of behaviour of an existing cipher.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
void ecb_encrypt (void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher)
 Encrypt data.
void ecb_decrypt (void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher)
 Decrypt data.

Detailed Description

Electronic codebook (ECB)

Definition in file ecb.h.


Define Documentation

#define ECB_CIPHER (   _ecb_name,
  _ecb_cipher,
  _raw_cipher,
  _raw_context,
  _blocksize 
)
Value:
static int _ecb_name ## _setkey ( void *ctx, const void *key,           \
                                  size_t keylen ) {                     \
        return cipher_setkey ( &_raw_cipher, ctx, key, keylen );        \
}                                                                       \
static void _ecb_name ## _setiv ( void *ctx, const void *iv ) {         \
        cipher_setiv ( &_raw_cipher, ctx, iv );                         \
}                                                                       \
static void _ecb_name ## _encrypt ( void *ctx, const void *src,         \
                                    void *dst, size_t len ) {           \
        ecb_encrypt ( ctx, src, dst, len, &_raw_cipher );               \
}                                                                       \
static void _ecb_name ## _decrypt ( void *ctx, const void *src,         \
                                    void *dst, size_t len ) {           \
        ecb_decrypt ( ctx, src, dst, len, &_raw_cipher );               \
}                                                                       \
struct cipher_algorithm _ecb_cipher = {                                 \
        .name           = #_ecb_name,                                   \
        .ctxsize        = sizeof ( _raw_context ),                      \
        .blocksize      = _blocksize,                                   \
        .setkey         = _ecb_name ## _setkey,                         \
        .setiv          = _ecb_name ## _setiv,                          \
        .encrypt        = _ecb_name ## _encrypt,                        \
        .decrypt        = _ecb_name ## _decrypt,                        \
};

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

Parameters:
_ecb_nameName for the new ECB cipher
_ecb_cipherNew cipher algorithm
_raw_cipherUnderlying cipher algorithm
_raw_contextContext structure for the underlying cipher
_blocksizeCipher block size

Definition at line 28 of file ecb.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
void ecb_encrypt ( void *  ctx,
const void *  src,
void *  dst,
size_t  len,
struct cipher_algorithm raw_cipher 
)

Encrypt data.

Parameters:
ctxContext
srcData to encrypt
dstBuffer for encrypted data
lenLength of data
raw_cipherUnderlying cipher algorithm

Definition at line 45 of file ecb.c.

References assert, cipher_algorithm::blocksize, and cipher_encrypt.

                                                         {
        size_t blocksize = raw_cipher->blocksize;

        assert ( ( len % blocksize ) == 0 );

        while ( len ) {
                cipher_encrypt ( raw_cipher, ctx, src, dst, blocksize );
                dst += blocksize;
                src += blocksize;
                len -= blocksize;
        }
}
void ecb_decrypt ( void *  ctx,
const void *  src,
void *  dst,
size_t  len,
struct cipher_algorithm raw_cipher 
)

Decrypt data.

Parameters:
ctxContext
srcData to decrypt
dstBuffer for decrypted data
lenLength of data
raw_cipherUnderlying cipher algorithm

Definition at line 68 of file ecb.c.

References assert, cipher_algorithm::blocksize, and cipher_decrypt.

                                                         {
        size_t blocksize = raw_cipher->blocksize;

        assert ( ( len % blocksize ) == 0 );

        while ( len ) {
                cipher_decrypt ( raw_cipher, ctx, src, dst, blocksize );
                dst += blocksize;
                src += blocksize;
                len -= blocksize;
        }
}