modes.h revision 238405
1/* ====================================================================
2 * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
3 *
4 * Rights for redistribution and usage in source and binary
5 * forms are granted according to the OpenSSL license.
6 */
7
8#include <stddef.h>
9
10typedef void (*block128_f)(const unsigned char in[16],
11			unsigned char out[16],
12			const void *key);
13
14typedef void (*cbc128_f)(const unsigned char *in, unsigned char *out,
15			size_t len, const void *key,
16			unsigned char ivec[16], int enc);
17
18typedef void (*ctr128_f)(const unsigned char *in, unsigned char *out,
19			size_t blocks, const void *key,
20			const unsigned char ivec[16]);
21
22typedef void (*ccm128_f)(const unsigned char *in, unsigned char *out,
23			size_t blocks, const void *key,
24			const unsigned char ivec[16],unsigned char cmac[16]);
25
26void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out,
27			size_t len, const void *key,
28			unsigned char ivec[16], block128_f block);
29void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
30			size_t len, const void *key,
31			unsigned char ivec[16], block128_f block);
32
33void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out,
34			size_t len, const void *key,
35			unsigned char ivec[16], unsigned char ecount_buf[16],
36			unsigned int *num, block128_f block);
37
38void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out,
39			size_t len, const void *key,
40			unsigned char ivec[16], unsigned char ecount_buf[16],
41			unsigned int *num, ctr128_f ctr);
42
43void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out,
44			size_t len, const void *key,
45			unsigned char ivec[16], int *num,
46			block128_f block);
47
48void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
49			size_t len, const void *key,
50			unsigned char ivec[16], int *num,
51			int enc, block128_f block);
52void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
53			size_t length, const void *key,
54			unsigned char ivec[16], int *num,
55			int enc, block128_f block);
56void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
57			size_t bits, const void *key,
58			unsigned char ivec[16], int *num,
59			int enc, block128_f block);
60
61size_t CRYPTO_cts128_encrypt_block(const unsigned char *in, unsigned char *out,
62			size_t len, const void *key,
63			unsigned char ivec[16], block128_f block);
64size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out,
65			size_t len, const void *key,
66			unsigned char ivec[16], cbc128_f cbc);
67size_t CRYPTO_cts128_decrypt_block(const unsigned char *in, unsigned char *out,
68			size_t len, const void *key,
69			unsigned char ivec[16], block128_f block);
70size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
71			size_t len, const void *key,
72			unsigned char ivec[16], cbc128_f cbc);
73
74size_t CRYPTO_nistcts128_encrypt_block(const unsigned char *in, unsigned char *out,
75			size_t len, const void *key,
76			unsigned char ivec[16], block128_f block);
77size_t CRYPTO_nistcts128_encrypt(const unsigned char *in, unsigned char *out,
78			size_t len, const void *key,
79			unsigned char ivec[16], cbc128_f cbc);
80size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in, unsigned char *out,
81			size_t len, const void *key,
82			unsigned char ivec[16], block128_f block);
83size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out,
84			size_t len, const void *key,
85			unsigned char ivec[16], cbc128_f cbc);
86
87typedef struct gcm128_context GCM128_CONTEXT;
88
89GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block);
90void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx,void *key,block128_f block);
91void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv,
92			size_t len);
93int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const unsigned char *aad,
94			size_t len);
95int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
96			const unsigned char *in, unsigned char *out,
97			size_t len);
98int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
99			const unsigned char *in, unsigned char *out,
100			size_t len);
101int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
102			const unsigned char *in, unsigned char *out,
103			size_t len, ctr128_f stream);
104int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
105			const unsigned char *in, unsigned char *out,
106			size_t len, ctr128_f stream);
107int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx,const unsigned char *tag,
108			size_t len);
109void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
110void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx);
111
112typedef struct ccm128_context CCM128_CONTEXT;
113
114void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx,
115	unsigned int M, unsigned int L, void *key,block128_f block);
116int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx,
117	const unsigned char *nonce, size_t nlen, size_t mlen);
118void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx,
119	const unsigned char *aad, size_t alen);
120int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx,
121	const unsigned char *inp, unsigned char *out, size_t len);
122int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx,
123	const unsigned char *inp, unsigned char *out, size_t len);
124int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx,
125	const unsigned char *inp, unsigned char *out, size_t len,
126	ccm128_f stream);
127int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx,
128	const unsigned char *inp, unsigned char *out, size_t len,
129	ccm128_f stream);
130size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
131
132typedef struct xts128_context XTS128_CONTEXT;
133
134int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
135	const unsigned char *inp, unsigned char *out, size_t len, int enc);
136