6 * Electronic codebook (ECB)
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
12 #include <ipxe/crypto.h>
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 );
20 * Create a cipher-block chaining mode of behaviour of an existing cipher
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
28 #define ECB_CIPHER( _ecb_name, _ecb_cipher, _raw_cipher, _raw_context, \
30 static int _ecb_name ## _setkey ( void *ctx, const void *key, \
32 return cipher_setkey ( &_raw_cipher, ctx, key, keylen ); \
34 static void _ecb_name ## _setiv ( void *ctx, const void *iv ) { \
35 cipher_setiv ( &_raw_cipher, ctx, iv ); \
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 ); \
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 ); \
45 struct cipher_algorithm _ecb_cipher = { \
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, \
55 #endif /* _IPXE_ECB_H */