iPXE
ecb.c File Reference

Electronic codebook (ECB). More...

#include <assert.h>
#include <ipxe/crypto.h>
#include <ipxe/ecb.h>

Go to the source code of this file.

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.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ ecb_setkey()

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

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
A cipher algorithm.
Definition crypto.h:58
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 )

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 )

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.