Move the public SIV mode functions from public headers to internal ones
[openssl.git] / include / openssl / modes.h
1 /*
2  * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #ifndef HEADER_MODES_H
11 # define HEADER_MODES_H
12
13 # include <stddef.h>
14 # include <openssl/ossl_typ.h>
15
16 # ifdef  __cplusplus
17 extern "C" {
18 # endif
19 typedef void (*block128_f) (const unsigned char in[16],
20                             unsigned char out[16], const void *key);
21
22 typedef void (*cbc128_f) (const unsigned char *in, unsigned char *out,
23                           size_t len, const void *key,
24                           unsigned char ivec[16], int enc);
25
26 typedef void (*ctr128_f) (const unsigned char *in, unsigned char *out,
27                           size_t blocks, const void *key,
28                           const unsigned char ivec[16]);
29
30 typedef void (*ccm128_f) (const unsigned char *in, unsigned char *out,
31                           size_t blocks, const void *key,
32                           const unsigned char ivec[16],
33                           unsigned char cmac[16]);
34
35 void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out,
36                            size_t len, const void *key,
37                            unsigned char ivec[16], block128_f block);
38 void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
39                            size_t len, const void *key,
40                            unsigned char ivec[16], block128_f block);
41
42 void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out,
43                            size_t len, const void *key,
44                            unsigned char ivec[16],
45                            unsigned char ecount_buf[16], unsigned int *num,
46                            block128_f block);
47
48 void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out,
49                                  size_t len, const void *key,
50                                  unsigned char ivec[16],
51                                  unsigned char ecount_buf[16],
52                                  unsigned int *num, ctr128_f ctr);
53
54 void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out,
55                            size_t len, const void *key,
56                            unsigned char ivec[16], int *num,
57                            block128_f block);
58
59 void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
60                            size_t len, const void *key,
61                            unsigned char ivec[16], int *num,
62                            int enc, block128_f block);
63 void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
64                              size_t length, const void *key,
65                              unsigned char ivec[16], int *num,
66                              int enc, block128_f block);
67 void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
68                              size_t bits, const void *key,
69                              unsigned char ivec[16], int *num,
70                              int enc, block128_f block);
71
72 size_t CRYPTO_cts128_encrypt_block(const unsigned char *in,
73                                    unsigned char *out, size_t len,
74                                    const void *key, unsigned char ivec[16],
75                                    block128_f block);
76 size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out,
77                              size_t len, const void *key,
78                              unsigned char ivec[16], cbc128_f cbc);
79 size_t CRYPTO_cts128_decrypt_block(const unsigned char *in,
80                                    unsigned char *out, size_t len,
81                                    const void *key, unsigned char ivec[16],
82                                    block128_f block);
83 size_t CRYPTO_cts128_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 size_t CRYPTO_nistcts128_encrypt_block(const unsigned char *in,
88                                        unsigned char *out, size_t len,
89                                        const void *key,
90                                        unsigned char ivec[16],
91                                        block128_f block);
92 size_t CRYPTO_nistcts128_encrypt(const unsigned char *in, unsigned char *out,
93                                  size_t len, const void *key,
94                                  unsigned char ivec[16], cbc128_f cbc);
95 size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in,
96                                        unsigned char *out, size_t len,
97                                        const void *key,
98                                        unsigned char ivec[16],
99                                        block128_f block);
100 size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out,
101                                  size_t len, const void *key,
102                                  unsigned char ivec[16], cbc128_f cbc);
103
104 typedef struct gcm128_context GCM128_CONTEXT;
105
106 GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block);
107 void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block);
108 void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv,
109                          size_t len);
110 int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const unsigned char *aad,
111                       size_t len);
112 int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
113                           const unsigned char *in, unsigned char *out,
114                           size_t len);
115 int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
116                           const unsigned char *in, unsigned char *out,
117                           size_t len);
118 int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
119                                 const unsigned char *in, unsigned char *out,
120                                 size_t len, ctr128_f stream);
121 int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
122                                 const unsigned char *in, unsigned char *out,
123                                 size_t len, ctr128_f stream);
124 int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag,
125                          size_t len);
126 void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
127 void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx);
128
129 typedef struct ccm128_context CCM128_CONTEXT;
130
131 void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx,
132                         unsigned int M, unsigned int L, void *key,
133                         block128_f block);
134 int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx, const unsigned char *nonce,
135                         size_t nlen, size_t mlen);
136 void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx, const unsigned char *aad,
137                        size_t alen);
138 int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx, const unsigned char *inp,
139                           unsigned char *out, size_t len);
140 int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx, const unsigned char *inp,
141                           unsigned char *out, size_t len);
142 int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp,
143                                 unsigned char *out, size_t len,
144                                 ccm128_f stream);
145 int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp,
146                                 unsigned char *out, size_t len,
147                                 ccm128_f stream);
148 size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
149
150 typedef struct xts128_context XTS128_CONTEXT;
151
152 int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx,
153                           const unsigned char iv[16],
154                           const unsigned char *inp, unsigned char *out,
155                           size_t len, int enc);
156
157 size_t CRYPTO_128_wrap(void *key, const unsigned char *iv,
158                        unsigned char *out,
159                        const unsigned char *in, size_t inlen,
160                        block128_f block);
161
162 size_t CRYPTO_128_unwrap(void *key, const unsigned char *iv,
163                          unsigned char *out,
164                          const unsigned char *in, size_t inlen,
165                          block128_f block);
166 size_t CRYPTO_128_wrap_pad(void *key, const unsigned char *icv,
167                            unsigned char *out, const unsigned char *in,
168                            size_t inlen, block128_f block);
169 size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv,
170                              unsigned char *out, const unsigned char *in,
171                              size_t inlen, block128_f block);
172
173 # ifndef OPENSSL_NO_OCB
174 typedef struct ocb128_context OCB128_CONTEXT;
175
176 typedef void (*ocb128_f) (const unsigned char *in, unsigned char *out,
177                           size_t blocks, const void *key,
178                           size_t start_block_num,
179                           unsigned char offset_i[16],
180                           const unsigned char L_[][16],
181                           unsigned char checksum[16]);
182
183 OCB128_CONTEXT *CRYPTO_ocb128_new(void *keyenc, void *keydec,
184                                   block128_f encrypt, block128_f decrypt,
185                                   ocb128_f stream);
186 int CRYPTO_ocb128_init(OCB128_CONTEXT *ctx, void *keyenc, void *keydec,
187                        block128_f encrypt, block128_f decrypt,
188                        ocb128_f stream);
189 int CRYPTO_ocb128_copy_ctx(OCB128_CONTEXT *dest, OCB128_CONTEXT *src,
190                            void *keyenc, void *keydec);
191 int CRYPTO_ocb128_setiv(OCB128_CONTEXT *ctx, const unsigned char *iv,
192                         size_t len, size_t taglen);
193 int CRYPTO_ocb128_aad(OCB128_CONTEXT *ctx, const unsigned char *aad,
194                       size_t len);
195 int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx, const unsigned char *in,
196                           unsigned char *out, size_t len);
197 int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx, const unsigned char *in,
198                           unsigned char *out, size_t len);
199 int CRYPTO_ocb128_finish(OCB128_CONTEXT *ctx, const unsigned char *tag,
200                          size_t len);
201 int CRYPTO_ocb128_tag(OCB128_CONTEXT *ctx, unsigned char *tag, size_t len);
202 void CRYPTO_ocb128_cleanup(OCB128_CONTEXT *ctx);
203 # endif                          /* OPENSSL_NO_OCB */
204
205 # ifdef  __cplusplus
206 }
207 # endif
208
209 #endif