From 811db204a63682b78be97aafe83fe24d203215a2 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 30 Jan 2007 22:54:20 +0000 Subject: [PATCH] Added cipher wrapper functions --- src/include/gpxe/crypto.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/include/gpxe/crypto.h b/src/include/gpxe/crypto.h index 9023c354..1b543f05 100644 --- a/src/include/gpxe/crypto.h +++ b/src/include/gpxe/crypto.h @@ -8,6 +8,8 @@ */ #include +#include +#include /** A cryptographic algorithm */ struct crypto_algorithm { @@ -83,4 +85,28 @@ static inline void digest_final ( struct crypto_algorithm *crypto, crypto->final ( ctx, out ); } +static inline int cipher_encrypt ( struct crypto_algorithm *crypto, + void *ctx, const void *src, void *dst, + size_t len ) { + if ( ( len & ( crypto->blocksize - 1 ) ) ) { + return -EINVAL; + } + crypto->encode ( ctx, src, dst, len ); + return 0; +} + +static inline int cipher_decrypt ( struct crypto_algorithm *crypto, + void *ctx, const void *src, void *dst, + size_t len ) { + if ( ( len & ( crypto->blocksize - 1 ) ) ) { + return -EINVAL; + } + crypto->decode ( ctx, src, dst, len ); + return 0; +} + +static inline int is_stream_cipher ( struct crypto_algorithm *crypto ) { + return ( crypto->blocksize == 1 ); +} + #endif /* _GPXE_CRYPTO_H */