iPXE
ecb.h
Go to the documentation of this file.
1 #ifndef _IPXE_ECB_H
2 #define _IPXE_ECB_H
3 
4 /** @file
5  *
6  * Electronic codebook (ECB)
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <ipxe/crypto.h>
13 
14 extern void ecb_encrypt ( void *ctx, const void *src, void *dst,
15  size_t len, struct cipher_algorithm *raw_cipher );
16 extern void ecb_decrypt ( void *ctx, const void *src, void *dst,
17  size_t len, struct cipher_algorithm *raw_cipher );
18 
19 /**
20  * Create a cipher-block chaining mode of behaviour of an existing cipher
21  *
22  * @v _ecb_name Name for the new ECB cipher
23  * @v _ecb_cipher New cipher algorithm
24  * @v _raw_cipher Underlying cipher algorithm
25  * @v _raw_context Context structure for the underlying cipher
26  * @v _blocksize Cipher block size
27  */
28 #define ECB_CIPHER( _ecb_name, _ecb_cipher, _raw_cipher, _raw_context, \
29  _blocksize ) \
30 static int _ecb_name ## _setkey ( void *ctx, const void *key, \
31  size_t keylen ) { \
32  return cipher_setkey ( &_raw_cipher, ctx, key, keylen ); \
33 } \
34 static void _ecb_name ## _setiv ( void *ctx, const void *iv, \
35  size_t ivlen ) { \
36  cipher_setiv ( &_raw_cipher, ctx, iv, ivlen ); \
37 } \
38 static void _ecb_name ## _encrypt ( void *ctx, const void *src, \
39  void *dst, size_t len ) { \
40  ecb_encrypt ( ctx, src, dst, len, &_raw_cipher ); \
41 } \
42 static void _ecb_name ## _decrypt ( void *ctx, const void *src, \
43  void *dst, size_t len ) { \
44  ecb_decrypt ( ctx, src, dst, len, &_raw_cipher ); \
45 } \
46 struct cipher_algorithm _ecb_cipher = { \
47  .name = #_ecb_name, \
48  .ctxsize = sizeof ( _raw_context ), \
49  .blocksize = _blocksize, \
50  .alignsize = _blocksize, \
51  .authsize = 0, \
52  .setkey = _ecb_name ## _setkey, \
53  .setiv = _ecb_name ## _setiv, \
54  .encrypt = _ecb_name ## _encrypt, \
55  .decrypt = _ecb_name ## _decrypt, \
56  .auth = cipher_null_auth, \
57 };
58 
59 #endif /* _IPXE_ECB_H */
void ecb_encrypt(void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher)
Encrypt data.
Definition: ecb.c:45
static void const void void * dst
Definition: crypto.h:244
static void const void * src
Definition: crypto.h:244
Cryptographic API.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14
A cipher algorithm.
Definition: crypto.h:49
void ecb_decrypt(void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher)
Decrypt data.
Definition: ecb.c:68