[crypto] Add our own general-purpose cipher-block chaining routines
[people/asdlkf/gpxe.git] / src / include / gpxe / cbc.h
1 #ifndef _GPXE_CBC_H
2 #define _GPXE_CBC_H
3
4 /** @file
5  *
6  * Cipher-block chaining
7  *
8  */
9
10 #include <gpxe/crypto.h>
11
12 /**
13  * Set key
14  *
15  * @v ctx               Context
16  * @v key               Key
17  * @v keylen            Key length
18  * @v cipher            Underlying cipher algorithm
19  * @v cbc_ctx           CBC context
20  * @ret rc              Return status code
21  */
22 static inline int cbc_setkey ( void *ctx, const void *key, size_t keylen,
23                                struct cipher_algorithm *cipher,
24                                void *cbc_ctx __unused ) {
25
26         return cipher_setkey ( cipher, ctx, key, keylen );
27 }
28
29 /**
30  * Set initialisation vector
31  *
32  * @v ctx               Context
33  * @v iv                Initialisation vector
34  * @v cipher            Underlying cipher algorithm
35  * @v cbc_ctx           CBC context
36  */
37 static inline void cbc_setiv ( void *ctx __unused, const void *iv,
38                                struct cipher_algorithm *cipher,
39                                void *cbc_ctx ) {
40         memcpy ( cbc_ctx, iv, cipher->blocksize );
41 }
42
43 extern void cbc_encrypt ( void *ctx, const void *src, void *dst,
44                           size_t len, struct cipher_algorithm *cipher,
45                           void *cbc_ctx );
46 extern void cbc_decrypt ( void *ctx, const void *src, void *dst,
47                           size_t len, struct cipher_algorithm *cipher,
48                           void *cbc_ctx );
49
50 #endif /* _GPXE_CBC_H */