iPXE
ecb.h File Reference

Electronic codebook (ECB) More...

#include <ipxe/crypto.h>

Go to the source code of this file.

Macros

#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)
 FILE_SECBOOT (PERMITTED)
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.

Macro Definition Documentation

◆ ECB_CIPHER

#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, \
size_t ivlen ) { \
cipher_setiv ( &_raw_cipher, ctx, iv, ivlen ); \
} \
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, \
.alignsize = _blocksize, \
.authsize = 0, \
.setkey = _ecb_name ## _setkey, \
.setiv = _ecb_name ## _setiv, \
.encrypt = _ecb_name ## _encrypt, \
.decrypt = _ecb_name ## _decrypt, \
.auth = cipher_null_auth, \
};
union @162305117151260234136356364136041353210355154177 key
Sense key.
Definition scsi.h:3
struct golan_eq_context ctx
Definition CIB_PRM.h:0
static const void * src
Definition string.h:48
void cipher_null_auth(void *ctx __unused, void *auth __unused)
Definition crypto_null.c:80
ring len
Length.
Definition dwmac.h:226
static int cipher_setkey(struct cipher_algorithm *cipher, void *ctx, const void *key, size_t keylen)
Definition crypto.h:235
u8 iv[16]
Initialization vector.
Definition wpa.h:33

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 29 of file ecb.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

References ctx, len, and src.

◆ ecb_encrypt()

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

Encrypt data.

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

Definition at line 46 of file ecb.c.

47 {
48 size_t blocksize = raw_cipher->blocksize;
49
50 assert ( ( len % blocksize ) == 0 );
51
52 while ( len ) {
53 cipher_encrypt ( raw_cipher, ctx, src, dst, blocksize );
54 dst += blocksize;
55 src += blocksize;
56 len -= blocksize;
57 }
58}
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
#define cipher_encrypt(cipher, ctx, src, dst, len)
Definition crypto.h:251
size_t blocksize
Block size.
Definition crypto.h:61

References assert, cipher_algorithm::blocksize, cipher_encrypt, ctx, len, and src.

◆ ecb_decrypt()

void ecb_decrypt ( void * ctx,
const void * src,
void * dst,
size_t len,
struct cipher_algorithm * raw_cipher )
extern

Decrypt data.

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

Definition at line 69 of file ecb.c.

70 {
71 size_t blocksize = raw_cipher->blocksize;
72
73 assert ( ( len % blocksize ) == 0 );
74
75 while ( len ) {
76 cipher_decrypt ( raw_cipher, ctx, src, dst, blocksize );
77 dst += blocksize;
78 src += blocksize;
79 len -= blocksize;
80 }
81}
#define cipher_decrypt(cipher, ctx, src, dst, len)
Definition crypto.h:261

References assert, cipher_algorithm::blocksize, cipher_decrypt, ctx, len, and src.