50dc01852d4936fb295ffc109583092899f2035e
[openssl.git] / crypto / modes / modes.h
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
10 typedef void (*block128_f)(const unsigned char in[16],
11                         unsigned char out[16],
12                         const void *key);
13
14 typedef 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
18 typedef void (*ctr128_f)(const unsigned char *in, unsigned char *out,
19                         size_t blocks, const void *key,
20                         const unsigned char ivec[16]);
21
22 typedef 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
26 void 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);
29 void 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
33 void 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
38 void 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
43 void 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
48 void 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);
52 void 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);
56 void 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
61 size_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);
64 size_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);
67 size_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);
70 size_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
74 size_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);
77 size_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);
80 size_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);
83 size_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
87 typedef struct gcm128_context GCM128_CONTEXT;
88
89 GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block);
90 void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx,void *key,block128_f block);
91 void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv,
92                         size_t len);
93 int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const unsigned char *aad,
94                         size_t len);
95 int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
96                         const unsigned char *in, unsigned char *out,
97                         size_t len);
98 int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
99                         const unsigned char *in, unsigned char *out,
100                         size_t len);
101 int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
102                         const unsigned char *in, unsigned char *out,
103                         size_t len, ctr128_f stream);
104 int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
105                         const unsigned char *in, unsigned char *out,
106                         size_t len, ctr128_f stream);
107 int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx,const unsigned char *tag,
108                         size_t len);
109 void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
110 void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx);
111
112 typedef struct ccm128_context CCM128_CONTEXT;
113
114 void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx,
115         unsigned int M, unsigned int L, void *key,block128_f block);
116 int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx,
117         const unsigned char *nonce, size_t nlen, size_t mlen);
118 void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx,
119         const unsigned char *aad, size_t alen);
120 int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx,
121         const unsigned char *inp, unsigned char *out, size_t len);
122 int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx,
123         const unsigned char *inp, unsigned char *out, size_t len);
124 int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx,
125         const unsigned char *inp, unsigned char *out, size_t len,
126         ccm128_f stream);
127 int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx,
128         const unsigned char *inp, unsigned char *out, size_t len,
129         ccm128_f stream);
130 size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
131
132 typedef struct xts128_context XTS128_CONTEXT;
133
134 int 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
137 size_t CRYPTO_128_wrap(void *key, const unsigned char *iv,
138                 unsigned char *out,
139                 const unsigned char *in, size_t inlen, block128_f block);
140
141 size_t CRYPTO_128_unwrap(void *key, const unsigned char *iv,
142                 unsigned char *out,
143                 const unsigned char *in, size_t inlen, block128_f block);
144 size_t CRYPTO_128_wrap_pad(void *key, const unsigned char *icv,
145                 unsigned char *out,
146                 const unsigned char *in, size_t inlen, block128_f block);
147 size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv,
148                 unsigned char *out,
149                 const unsigned char *in, size_t inlen, block128_f block);