diff options
author | Michael Brown | 2007-01-30 23:54:20 +0100 |
---|---|---|
committer | Michael Brown | 2007-01-30 23:54:20 +0100 |
commit | 811db204a63682b78be97aafe83fe24d203215a2 (patch) | |
tree | 8de92c07e4c49a53ce5b41e23571b2c39988f8eb /src | |
parent | Missing check-in (diff) | |
download | ipxe-811db204a63682b78be97aafe83fe24d203215a2.tar.gz ipxe-811db204a63682b78be97aafe83fe24d203215a2.tar.xz ipxe-811db204a63682b78be97aafe83fe24d203215a2.zip |
Added cipher wrapper functions
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gpxe/crypto.h | 26 |
1 files changed, 26 insertions, 0 deletions
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 <stdint.h> +#include <stddef.h> +#include <errno.h> /** 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 */ |