mirror of https://github.com/ipxe/ipxe.git
Added cipher wrapper functions
parent
b3e4418ea8
commit
811db204a6
|
@ -8,6 +8,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
/** A cryptographic algorithm */
|
/** A cryptographic algorithm */
|
||||||
struct crypto_algorithm {
|
struct crypto_algorithm {
|
||||||
|
@ -83,4 +85,28 @@ static inline void digest_final ( struct crypto_algorithm *crypto,
|
||||||
crypto->final ( ctx, out );
|
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 */
|
#endif /* _GPXE_CRYPTO_H */
|
||||||
|
|
Loading…
Reference in New Issue