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  cipher_setiv ( &_raw_cipher, ctx, iv ); \
36 } \
37 static void _ecb_name ## _encrypt ( void *ctx, const void *src, \
38  void *dst, size_t len ) { \
39  ecb_encrypt ( ctx, src, dst, len, &_raw_cipher ); \
40 } \
41 static void _ecb_name ## _decrypt ( void *ctx, const void *src, \
42  void *dst, size_t len ) { \
43  ecb_decrypt ( ctx, src, dst, len, &_raw_cipher ); \
44 } \
45 struct cipher_algorithm _ecb_cipher = { \
46  .name = #_ecb_name, \
47  .ctxsize = sizeof ( _raw_context ), \
48  .blocksize = _blocksize, \
49  .setkey = _ecb_name ## _setkey, \
50  .setiv = _ecb_name ## _setiv, \
51  .encrypt = _ecb_name ## _encrypt, \
52  .decrypt = _ecb_name ## _decrypt, \
53 };
54 
55 #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
Cryptographic API.
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
uint32_t len
Length.
Definition: ena.h:14
A cipher algorithm.
Definition: crypto.h:48
void ecb_decrypt(void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher)
Decrypt data.
Definition: ecb.c:68