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 an electronic codebook mode of behaviour of an existing cipher.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int ecb_setkey (struct cipher_algorithm *cipher, void *ctx, const void *key, size_t keylen)
 Set key.
void ecb_encrypt (struct cipher_algorithm *cipher, void *ctx, const void *src, void *dst, size_t len)
 Encrypt data.
void ecb_decrypt (struct cipher_algorithm *cipher, void *ctx, const void *src, void *dst, size_t len)
 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:
struct cipher_algorithm _ecb_cipher = { \
.name = #_ecb_name, \
.ctxsize = sizeof ( _raw_context ), \
.blocksize = _blocksize, \
.alignsize = _blocksize, \
.authsize = 0, \
.confidential = 1, \
.setkey = ecb_setkey, \
.setiv = cipher_null_setiv, \
.encrypt = ecb_encrypt, \
.decrypt = ecb_decrypt, \
.auth = cipher_null_auth, \
.priv = &_raw_cipher, \
};
int cipher_null_setiv(struct cipher_algorithm *cipher __unused, void *ctx __unused, const void *iv __unused, size_t ivlen __unused)
Definition crypto_null.c:70
void cipher_null_auth(struct cipher_algorithm *cipher __unused, void *ctx __unused, void *auth __unused)
Definition crypto_null.c:89
int ecb_setkey(struct cipher_algorithm *cipher, void *ctx, const void *key, size_t keylen)
Set key.
Definition ecb.c:46
void ecb_decrypt(struct cipher_algorithm *cipher, void *ctx, const void *src, void *dst, size_t len)
Decrypt data.
Definition ecb.c:86
void ecb_encrypt(struct cipher_algorithm *cipher, void *ctx, const void *src, void *dst, size_t len)
Encrypt data.
Definition ecb.c:62
A cipher algorithm.
Definition crypto.h:58
static struct tlan_private * priv
Definition tlan.c:225

Create an electronic codebook 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 31 of file ecb.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

References ctx, key, len, and src.

◆ ecb_setkey()

int ecb_setkey ( struct cipher_algorithm * cipher,
void * ctx,
const void * key,
size_t keylen )
extern

Set key.

Parameters
cipherCipher algorithm
ctxContext
keyKey
keylenKey length
Return values
rcReturn status code

Definition at line 46 of file ecb.c.

47 {
48 struct cipher_algorithm *raw_cipher = cipher->priv;
49
50 return cipher_setkey ( raw_cipher, ctx, key, keylen );
51}
struct golan_eq_context ctx
Definition CIB_PRM.h:0
union @162305117151260234136356364136041353210355154177 key
static int cipher_setkey(struct cipher_algorithm *cipher, void *ctx, const void *key, size_t keylen)
Definition crypto.h:310
void * priv
Algorithm private data.
Definition crypto.h:138

References cipher_setkey(), ctx, key, and cipher_algorithm::priv.

◆ ecb_encrypt()

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

Encrypt data.

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

Definition at line 62 of file ecb.c.

63 {
64 struct cipher_algorithm *raw_cipher = cipher->priv;
65 size_t blocksize = raw_cipher->blocksize;
66
67 assert ( ( len % blocksize ) == 0 );
68
69 while ( len ) {
70 cipher_encrypt ( raw_cipher, ctx, src, dst, blocksize );
71 dst += blocksize;
72 src += blocksize;
73 len -= blocksize;
74 }
75}
static const void * src
Definition string.h:48
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
ring len
Length.
Definition dwmac.h:226
#define cipher_encrypt(cipher, ctx, src, dst, len)
Definition crypto.h:326
size_t blocksize
Block size.
Definition crypto.h:68

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

◆ ecb_decrypt()

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

Decrypt data.

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

Definition at line 86 of file ecb.c.

87 {
88 struct cipher_algorithm *raw_cipher = cipher->priv;
89 size_t blocksize = raw_cipher->blocksize;
90
91 assert ( ( len % blocksize ) == 0 );
92
93 while ( len ) {
94 cipher_decrypt ( raw_cipher, ctx, src, dst, blocksize );
95 dst += blocksize;
96 src += blocksize;
97 len -= blocksize;
98 }
99}
#define cipher_decrypt(cipher, ctx, src, dst, len)
Definition crypto.h:336

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