diff options
| author | Michael Brown | 2007-01-30 15:55:17 +0100 |
|---|---|---|
| committer | Michael Brown | 2007-01-30 15:55:17 +0100 |
| commit | db2fde474e4b67482251b3cae5e0068d46af4ab5 (patch) | |
| tree | 9e2d2e23241302c1d819b8019c49b311759d85e9 /src/include | |
| parent | Low-overhead filter streams (diff) | |
| download | ipxe-db2fde474e4b67482251b3cae5e0068d46af4ab5.tar.gz ipxe-db2fde474e4b67482251b3cae5e0068d46af4ab5.tar.xz ipxe-db2fde474e4b67482251b3cae5e0068d46af4ab5.zip | |
Generalise digest_algorithm to crypto_algorithm.
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/gpxe/chap.h | 6 | ||||
| -rw-r--r-- | src/include/gpxe/crypto.h | 90 | ||||
| -rw-r--r-- | src/include/gpxe/md5.h | 4 |
3 files changed, 70 insertions, 30 deletions
diff --git a/src/include/gpxe/chap.h b/src/include/gpxe/chap.h index c85d92f82..0ea7ac5c7 100644 --- a/src/include/gpxe/chap.h +++ b/src/include/gpxe/chap.h @@ -10,12 +10,12 @@ #include <stdint.h> #include <gpxe/md5.h> -struct digest_algorithm; +struct crypto_algorithm; /** A CHAP challenge/response */ struct chap_challenge { /** Digest algorithm used for the response */ - struct digest_algorithm *digest; + struct crypto_algorithm *digest; /** Context used by the digest algorithm */ uint8_t *digest_context; /** CHAP response */ @@ -25,7 +25,7 @@ struct chap_challenge { }; extern int chap_init ( struct chap_challenge *chap, - struct digest_algorithm *digest ); + struct crypto_algorithm *digest ); extern void chap_update ( struct chap_challenge *chap, const void *data, size_t len ); extern void chap_respond ( struct chap_challenge *chap ); diff --git a/src/include/gpxe/crypto.h b/src/include/gpxe/crypto.h index 023a00228..9023c354b 100644 --- a/src/include/gpxe/crypto.h +++ b/src/include/gpxe/crypto.h @@ -9,38 +9,78 @@ #include <stdint.h> -/** - * A message-digest algorithm - * - */ -struct digest_algorithm { +/** A cryptographic algorithm */ +struct crypto_algorithm { /** Algorithm name */ const char *name; - /** Size of a context for this algorithm */ - size_t context_len; - /** Size of a message digest for this algorithm */ - size_t digest_len; - /** - * Initialise digest algorithm - * - * @v context Context for digest operations + /** Context size */ + size_t ctxsize; + /** Block size */ + size_t blocksize; + /** Final output size */ + size_t digestsize; + /** Initialise algorithm + * + * @v ctx Context */ - void ( * init ) ( void *context ); - /** - * Calculate digest over data buffer + void ( * init ) ( void *ctx ); + /** Set key * - * @v context Context for digest operations - * @v data Data buffer - * @v len Length of data buffer + * @v ctx Context + * @v key Key + * @v keylen Key length + * @ret rc Return status code */ - void ( * update ) ( void *context, const void *data, size_t len ); - /** - * Finish calculating digest + int ( * setkey ) ( void *ctx, void *key, size_t keylen ); + /** Encode data + * + * @v ctx Context + * @v src Data to encode + * @v dst Encoded data, or NULL + * @v len Length of data + * @ret rc Return status code * - * @v context Context for digest operations - * @v digest Buffer for message digest + * For a cipher algorithm, the enciphered data should be + * placed in @c dst. For a digest algorithm, only the digest + * state should be updated, and @c dst will be NULL. + * + * @v len is guaranteed to be a multiple of @c blocksize. */ - void ( * finish ) ( void *context, void *digest ); + void ( * encode ) ( void *ctx, const void *src, void *dst, + size_t len ); + /** Decode data + * + * @v ctx Context + * @v src Data to decode + * @v dst Decoded data + * @v len Length of data + * @ret rc Return status code + * + * @v len is guaranteed to be a multiple of @c blocksize. + */ + void ( * decode ) ( void *ctx, const void *src, void *dst, + size_t len ); + /** Finalise algorithm + * + * @v ctx Context + * @v out Algorithm final output + */ + void ( * final ) ( void *ctx, void *out ); }; +static inline void digest_init ( struct crypto_algorithm *crypto, + void *ctx ) { + crypto->init ( ctx ); +} + +static inline void digest_update ( struct crypto_algorithm *crypto, + void *ctx, const void *data, size_t len ) { + crypto->encode ( ctx, data, NULL, len ); +} + +static inline void digest_final ( struct crypto_algorithm *crypto, + void *ctx, void *out ) { + crypto->final ( ctx, out ); +} + #endif /* _GPXE_CRYPTO_H */ diff --git a/src/include/gpxe/md5.h b/src/include/gpxe/md5.h index 56120ca13..f82c94625 100644 --- a/src/include/gpxe/md5.h +++ b/src/include/gpxe/md5.h @@ -1,8 +1,8 @@ #ifndef _GPXE_MD5_H #define _GPXE_MD5_H -struct digest_algorithm; +struct crypto_algorithm; -extern struct digest_algorithm md5_algorithm; +extern struct crypto_algorithm md5_algorithm; #endif /* _GPXE_MD5_H */ |
