summaryrefslogtreecommitdiffstats
path: root/src/include/gpxe/cbc.h
blob: e2d57764eff1073eb0b0bfb190be94ef77796b82 (plain) (blame)
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
#ifndef _GPXE_CBC_H
#define _GPXE_CBC_H

/** @file
 *
 * Cipher-block chaining
 *
 */

#include <gpxe/crypto.h>

/**
 * Set key
 *
 * @v ctx		Context
 * @v key		Key
 * @v keylen		Key length
 * @v cipher		Underlying cipher algorithm
 * @v cbc_ctx		CBC context
 * @ret rc		Return status code
 */
static inline int cbc_setkey ( void *ctx, const void *key, size_t keylen,
			       struct cipher_algorithm *cipher,
			       void *cbc_ctx __unused ) {

	return cipher_setkey ( cipher, ctx, key, keylen );
}

/**
 * Set initialisation vector
 *
 * @v ctx		Context
 * @v iv		Initialisation vector
 * @v cipher		Underlying cipher algorithm
 * @v cbc_ctx		CBC context
 */
static inline void cbc_setiv ( void *ctx __unused, const void *iv,
			       struct cipher_algorithm *cipher,
			       void *cbc_ctx ) {
	memcpy ( cbc_ctx, iv, cipher->blocksize );
}

extern void cbc_encrypt ( void *ctx, const void *src, void *dst,
			  size_t len, struct cipher_algorithm *cipher,
			  void *cbc_ctx );
extern void cbc_decrypt ( void *ctx, const void *src, void *dst,
			  size_t len, struct cipher_algorithm *cipher,
			  void *cbc_ctx );

#endif /* _GPXE_CBC_H */