iPXE
ecb.h
Go to the documentation of this file.
00001 #ifndef _IPXE_ECB_H
00002 #define _IPXE_ECB_H
00003 
00004 /** @file
00005  *
00006  * Electronic codebook (ECB)
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <ipxe/crypto.h>
00013 
00014 extern void ecb_encrypt ( void *ctx, const void *src, void *dst,
00015                           size_t len, struct cipher_algorithm *raw_cipher );
00016 extern void ecb_decrypt ( void *ctx, const void *src, void *dst,
00017                           size_t len, struct cipher_algorithm *raw_cipher );
00018 
00019 /**
00020  * Create a cipher-block chaining mode of behaviour of an existing cipher
00021  *
00022  * @v _ecb_name         Name for the new ECB cipher
00023  * @v _ecb_cipher       New cipher algorithm
00024  * @v _raw_cipher       Underlying cipher algorithm
00025  * @v _raw_context      Context structure for the underlying cipher
00026  * @v _blocksize        Cipher block size
00027  */
00028 #define ECB_CIPHER( _ecb_name, _ecb_cipher, _raw_cipher, _raw_context,  \
00029                     _blocksize )                                        \
00030 static int _ecb_name ## _setkey ( void *ctx, const void *key,           \
00031                                   size_t keylen ) {                     \
00032         return cipher_setkey ( &_raw_cipher, ctx, key, keylen );        \
00033 }                                                                       \
00034 static void _ecb_name ## _setiv ( void *ctx, const void *iv ) {         \
00035         cipher_setiv ( &_raw_cipher, ctx, iv );                         \
00036 }                                                                       \
00037 static void _ecb_name ## _encrypt ( void *ctx, const void *src,         \
00038                                     void *dst, size_t len ) {           \
00039         ecb_encrypt ( ctx, src, dst, len, &_raw_cipher );               \
00040 }                                                                       \
00041 static void _ecb_name ## _decrypt ( void *ctx, const void *src,         \
00042                                     void *dst, size_t len ) {           \
00043         ecb_decrypt ( ctx, src, dst, len, &_raw_cipher );               \
00044 }                                                                       \
00045 struct cipher_algorithm _ecb_cipher = {                                 \
00046         .name           = #_ecb_name,                                   \
00047         .ctxsize        = sizeof ( _raw_context ),                      \
00048         .blocksize      = _blocksize,                                   \
00049         .setkey         = _ecb_name ## _setkey,                         \
00050         .setiv          = _ecb_name ## _setiv,                          \
00051         .encrypt        = _ecb_name ## _encrypt,                        \
00052         .decrypt        = _ecb_name ## _decrypt,                        \
00053 };
00054 
00055 #endif /* _IPXE_ECB_H */