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