mirror of
https://github.com/ipxe/ipxe
synced 2025-12-25 09:01:24 +03:00
[crypto] Add our own general-purpose cipher-block chaining routines
This commit is contained in:
50
src/include/gpxe/cbc.h
Normal file
50
src/include/gpxe/cbc.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef _GPXE_CBC_H
|
||||
#define _GPXE_CBC_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* Cipher-block chaining
|
||||
*
|
||||
*/
|
||||
|
||||
#include <gpxe/crypto.h>
|
||||
|
||||
/**
|
||||
* Set key
|
||||
*
|
||||
* @v ctx Context
|
||||
* @v key Key
|
||||
* @v keylen Key length
|
||||
* @v cipher Underlying cipher algorithm
|
||||
* @v cbc_ctx CBC context
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static inline int cbc_setkey ( void *ctx, const void *key, size_t keylen,
|
||||
struct cipher_algorithm *cipher,
|
||||
void *cbc_ctx __unused ) {
|
||||
|
||||
return cipher_setkey ( cipher, ctx, key, keylen );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set initialisation vector
|
||||
*
|
||||
* @v ctx Context
|
||||
* @v iv Initialisation vector
|
||||
* @v cipher Underlying cipher algorithm
|
||||
* @v cbc_ctx CBC context
|
||||
*/
|
||||
static inline void cbc_setiv ( void *ctx __unused, const void *iv,
|
||||
struct cipher_algorithm *cipher,
|
||||
void *cbc_ctx ) {
|
||||
memcpy ( cbc_ctx, iv, cipher->blocksize );
|
||||
}
|
||||
|
||||
extern void cbc_encrypt ( void *ctx, const void *src, void *dst,
|
||||
size_t len, struct cipher_algorithm *cipher,
|
||||
void *cbc_ctx );
|
||||
extern void cbc_decrypt ( void *ctx, const void *src, void *dst,
|
||||
size_t len, struct cipher_algorithm *cipher,
|
||||
void *cbc_ctx );
|
||||
|
||||
#endif /* _GPXE_CBC_H */
|
||||
Reference in New Issue
Block a user