1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#ifndef _GPXE_CRYPTO_H
#define _GPXE_CRYPTO_H
/** @file
*
* Cryptographic API
*
*/
#include <stdint.h>
/** A cryptographic algorithm */
struct crypto_algorithm {
/** Algorithm name */
const char *name;
/** Context size */
size_t ctxsize;
/** Block size */
size_t blocksize;
/** Final output size */
size_t digestsize;
/** Initialise algorithm
*
* @v ctx Context
*/
void ( * init ) ( void *ctx );
/** Set key
*
* @v ctx Context
* @v key Key
* @v keylen Key length
* @ret rc Return status code
*/
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
*
* 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 ( * 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 */
|