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
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <ipxe/crypto.h>
14
15extern void ecb_encrypt ( void *ctx, const void *src, void *dst,
16 size_t len, struct cipher_algorithm *raw_cipher );
17extern 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 ) \
31static int _ecb_name ## _setkey ( void *ctx, const void *key, \
32 size_t keylen ) { \
33 return cipher_setkey ( &_raw_cipher, ctx, key, keylen ); \
34} \
35static void _ecb_name ## _setiv ( void *ctx, const void *iv, \
36 size_t ivlen ) { \
37 cipher_setiv ( &_raw_cipher, ctx, iv, ivlen ); \
38} \
39static 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} \
43static 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} \
47struct 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 */
struct golan_eq_context ctx
Definition CIB_PRM.h:0
static const void * src
Definition string.h:48
ring len
Length.
Definition dwmac.h:226
void ecb_decrypt(void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher)
Decrypt data.
Definition ecb.c:69
void ecb_encrypt(void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher)
Encrypt data.
Definition ecb.c:46
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
Cryptographic API.
A cipher algorithm.
Definition crypto.h:51