xref: /freebsd/crypto/openssl/include/openssl/modes.h (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
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 OPENSSL_MODES_H
11 # define OPENSSL_MODES_H
12 # pragma once
13 
14 # include <openssl/macros.h>
15 # ifndef OPENSSL_NO_DEPRECATED_3_0
16 #  define HEADER_MODES_H
17 # endif
18 
19 # include <stddef.h>
20 # include <openssl/types.h>
21 
22 # ifdef  __cplusplus
23 extern "C" {
24 # endif
25 typedef void (*block128_f) (const unsigned char in[16],
26                             unsigned char out[16], const void *key);
27 
28 typedef void (*cbc128_f) (const unsigned char *in, unsigned char *out,
29                           size_t len, const void *key,
30                           unsigned char ivec[16], int enc);
31 
32 typedef void (*ecb128_f) (const unsigned char *in, unsigned char *out,
33                           size_t len, const void *key,
34                           int enc);
35 
36 typedef void (*ctr128_f) (const unsigned char *in, unsigned char *out,
37                           size_t blocks, const void *key,
38                           const unsigned char ivec[16]);
39 
40 typedef void (*ccm128_f) (const unsigned char *in, unsigned char *out,
41                           size_t blocks, const void *key,
42                           const unsigned char ivec[16],
43                           unsigned char cmac[16]);
44 
45 void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out,
46                            size_t len, const void *key,
47                            unsigned char ivec[16], block128_f block);
48 void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
49                            size_t len, const void *key,
50                            unsigned char ivec[16], block128_f block);
51 
52 void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out,
53                            size_t len, const void *key,
54                            unsigned char ivec[16],
55                            unsigned char ecount_buf[16], unsigned int *num,
56                            block128_f block);
57 
58 void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out,
59                                  size_t len, const void *key,
60                                  unsigned char ivec[16],
61                                  unsigned char ecount_buf[16],
62                                  unsigned int *num, ctr128_f ctr);
63 
64 void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out,
65                            size_t len, const void *key,
66                            unsigned char ivec[16], int *num,
67                            block128_f block);
68 
69 void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
70                            size_t len, const void *key,
71                            unsigned char ivec[16], int *num,
72                            int enc, block128_f block);
73 void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
74                              size_t length, const void *key,
75                              unsigned char ivec[16], int *num,
76                              int enc, block128_f block);
77 void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
78                              size_t bits, const void *key,
79                              unsigned char ivec[16], int *num,
80                              int enc, block128_f block);
81 
82 size_t CRYPTO_cts128_encrypt_block(const unsigned char *in,
83                                    unsigned char *out, size_t len,
84                                    const void *key, unsigned char ivec[16],
85                                    block128_f block);
86 size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out,
87                              size_t len, const void *key,
88                              unsigned char ivec[16], cbc128_f cbc);
89 size_t CRYPTO_cts128_decrypt_block(const unsigned char *in,
90                                    unsigned char *out, size_t len,
91                                    const void *key, unsigned char ivec[16],
92                                    block128_f block);
93 size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
94                              size_t len, const void *key,
95                              unsigned char ivec[16], cbc128_f cbc);
96 
97 size_t CRYPTO_nistcts128_encrypt_block(const unsigned char *in,
98                                        unsigned char *out, size_t len,
99                                        const void *key,
100                                        unsigned char ivec[16],
101                                        block128_f block);
102 size_t CRYPTO_nistcts128_encrypt(const unsigned char *in, unsigned char *out,
103                                  size_t len, const void *key,
104                                  unsigned char ivec[16], cbc128_f cbc);
105 size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in,
106                                        unsigned char *out, size_t len,
107                                        const void *key,
108                                        unsigned char ivec[16],
109                                        block128_f block);
110 size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out,
111                                  size_t len, const void *key,
112                                  unsigned char ivec[16], cbc128_f cbc);
113 
114 typedef struct gcm128_context GCM128_CONTEXT;
115 
116 GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block);
117 void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block);
118 void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv,
119                          size_t len);
120 int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const unsigned char *aad,
121                       size_t len);
122 int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
123                           const unsigned char *in, unsigned char *out,
124                           size_t len);
125 int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
126                           const unsigned char *in, unsigned char *out,
127                           size_t len);
128 int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
129                                 const unsigned char *in, unsigned char *out,
130                                 size_t len, ctr128_f stream);
131 int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
132                                 const unsigned char *in, unsigned char *out,
133                                 size_t len, ctr128_f stream);
134 int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag,
135                          size_t len);
136 void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
137 void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx);
138 
139 typedef struct ccm128_context CCM128_CONTEXT;
140 
141 void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx,
142                         unsigned int M, unsigned int L, void *key,
143                         block128_f block);
144 int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx, const unsigned char *nonce,
145                         size_t nlen, size_t mlen);
146 void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx, const unsigned char *aad,
147                        size_t alen);
148 int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx, const unsigned char *inp,
149                           unsigned char *out, size_t len);
150 int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx, const unsigned char *inp,
151                           unsigned char *out, size_t len);
152 int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp,
153                                 unsigned char *out, size_t len,
154                                 ccm128_f stream);
155 int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp,
156                                 unsigned char *out, size_t len,
157                                 ccm128_f stream);
158 size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
159 
160 typedef struct xts128_context XTS128_CONTEXT;
161 
162 int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx,
163                           const unsigned char iv[16],
164                           const unsigned char *inp, unsigned char *out,
165                           size_t len, int enc);
166 
167 size_t CRYPTO_128_wrap(void *key, const unsigned char *iv,
168                        unsigned char *out,
169                        const unsigned char *in, size_t inlen,
170                        block128_f block);
171 
172 size_t CRYPTO_128_unwrap(void *key, const unsigned char *iv,
173                          unsigned char *out,
174                          const unsigned char *in, size_t inlen,
175                          block128_f block);
176 size_t CRYPTO_128_wrap_pad(void *key, const unsigned char *icv,
177                            unsigned char *out, const unsigned char *in,
178                            size_t inlen, block128_f block);
179 size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv,
180                              unsigned char *out, const unsigned char *in,
181                              size_t inlen, block128_f block);
182 
183 # ifndef OPENSSL_NO_OCB
184 typedef struct ocb128_context OCB128_CONTEXT;
185 
186 typedef void (*ocb128_f) (const unsigned char *in, unsigned char *out,
187                           size_t blocks, const void *key,
188                           size_t start_block_num,
189                           unsigned char offset_i[16],
190                           const unsigned char L_[][16],
191                           unsigned char checksum[16]);
192 
193 OCB128_CONTEXT *CRYPTO_ocb128_new(void *keyenc, void *keydec,
194                                   block128_f encrypt, block128_f decrypt,
195                                   ocb128_f stream);
196 int CRYPTO_ocb128_init(OCB128_CONTEXT *ctx, void *keyenc, void *keydec,
197                        block128_f encrypt, block128_f decrypt,
198                        ocb128_f stream);
199 int CRYPTO_ocb128_copy_ctx(OCB128_CONTEXT *dest, OCB128_CONTEXT *src,
200                            void *keyenc, void *keydec);
201 int CRYPTO_ocb128_setiv(OCB128_CONTEXT *ctx, const unsigned char *iv,
202                         size_t len, size_t taglen);
203 int CRYPTO_ocb128_aad(OCB128_CONTEXT *ctx, const unsigned char *aad,
204                       size_t len);
205 int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx, const unsigned char *in,
206                           unsigned char *out, size_t len);
207 int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx, const unsigned char *in,
208                           unsigned char *out, size_t len);
209 int CRYPTO_ocb128_finish(OCB128_CONTEXT *ctx, const unsigned char *tag,
210                          size_t len);
211 int CRYPTO_ocb128_tag(OCB128_CONTEXT *ctx, unsigned char *tag, size_t len);
212 void CRYPTO_ocb128_cleanup(OCB128_CONTEXT *ctx);
213 # endif                          /* OPENSSL_NO_OCB */
214 
215 # ifdef  __cplusplus
216 }
217 # endif
218 
219 #endif
220