modes.h 10.2 KB
Newer Older
R
Rich Salz 已提交
1 2
/*
 * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
3
 *
R
Rich Salz 已提交
4 5 6 7
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
8 9
 */

10 11
#ifndef HEADER_MODES_H
# define HEADER_MODES_H
12

13 14 15
# include <stddef.h>

# ifdef  __cplusplus
16
extern "C" {
17
# endif
18 19
typedef void (*block128_f) (const unsigned char in[16],
                            unsigned char out[16], const void *key);
20

21 22 23
typedef void (*cbc128_f) (const unsigned char *in, unsigned char *out,
                          size_t len, const void *key,
                          unsigned char ivec[16], int enc);
24

25 26 27
typedef void (*ctr128_f) (const unsigned char *in, unsigned char *out,
                          size_t blocks, const void *key,
                          const unsigned char ivec[16]);
A
Andy Polyakov 已提交
28

29 30 31 32
typedef void (*ccm128_f) (const unsigned char *in, unsigned char *out,
                          size_t blocks, const void *key,
                          const unsigned char ivec[16],
                          unsigned char cmac[16]);
33

34
void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out,
35 36
                           size_t len, const void *key,
                           unsigned char ivec[16], block128_f block);
37
void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
38 39
                           size_t len, const void *key,
                           unsigned char ivec[16], block128_f block);
40 41

void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out,
42 43 44 45
                           size_t len, const void *key,
                           unsigned char ivec[16],
                           unsigned char ecount_buf[16], unsigned int *num,
                           block128_f block);
46

A
Andy Polyakov 已提交
47
void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out,
48 49 50 51
                                 size_t len, const void *key,
                                 unsigned char ivec[16],
                                 unsigned char ecount_buf[16],
                                 unsigned int *num, ctr128_f ctr);
A
Andy Polyakov 已提交
52

53
void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out,
54 55 56
                           size_t len, const void *key,
                           unsigned char ivec[16], int *num,
                           block128_f block);
57 58

void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
59 60 61
                           size_t len, const void *key,
                           unsigned char ivec[16], int *num,
                           int enc, block128_f block);
62
void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
63 64 65
                             size_t length, const void *key,
                             unsigned char ivec[16], int *num,
                             int enc, block128_f block);
66
void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
67 68 69 70 71 72 73 74
                             size_t bits, const void *key,
                             unsigned char ivec[16], int *num,
                             int enc, block128_f block);

size_t CRYPTO_cts128_encrypt_block(const unsigned char *in,
                                   unsigned char *out, size_t len,
                                   const void *key, unsigned char ivec[16],
                                   block128_f block);
75
size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out,
76 77 78 79 80 81
                             size_t len, const void *key,
                             unsigned char ivec[16], cbc128_f cbc);
size_t CRYPTO_cts128_decrypt_block(const unsigned char *in,
                                   unsigned char *out, size_t len,
                                   const void *key, unsigned char ivec[16],
                                   block128_f block);
82
size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
83 84 85 86 87 88 89 90
                             size_t len, const void *key,
                             unsigned char ivec[16], cbc128_f cbc);

size_t CRYPTO_nistcts128_encrypt_block(const unsigned char *in,
                                       unsigned char *out, size_t len,
                                       const void *key,
                                       unsigned char ivec[16],
                                       block128_f block);
91
size_t CRYPTO_nistcts128_encrypt(const unsigned char *in, unsigned char *out,
92 93 94 95 96 97 98
                                 size_t len, const void *key,
                                 unsigned char ivec[16], cbc128_f cbc);
size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in,
                                       unsigned char *out, size_t len,
                                       const void *key,
                                       unsigned char ivec[16],
                                       block128_f block);
99
size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out,
100 101
                                 size_t len, const void *key,
                                 unsigned char ivec[16], cbc128_f cbc);
102 103 104

typedef struct gcm128_context GCM128_CONTEXT;

105
GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block);
106
void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block);
107
void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv,
108
                         size_t len);
109
int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const unsigned char *aad,
110
                      size_t len);
111
int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
112 113
                          const unsigned char *in, unsigned char *out,
                          size_t len);
114
int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
115 116
                          const unsigned char *in, unsigned char *out,
                          size_t len);
117
int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
118 119
                                const unsigned char *in, unsigned char *out,
                                size_t len, ctr128_f stream);
120
int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
121 122 123 124
                                const unsigned char *in, unsigned char *out,
                                size_t len, ctr128_f stream);
int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag,
                         size_t len);
125
void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
126
void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx);
127

128 129 130
typedef struct ccm128_context CCM128_CONTEXT;

void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx,
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
                        unsigned int M, unsigned int L, void *key,
                        block128_f block);
int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx, const unsigned char *nonce,
                        size_t nlen, size_t mlen);
void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx, const unsigned char *aad,
                       size_t alen);
int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx, const unsigned char *inp,
                          unsigned char *out, size_t len);
int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx, const unsigned char *inp,
                          unsigned char *out, size_t len);
int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp,
                                unsigned char *out, size_t len,
                                ccm128_f stream);
int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp,
                                unsigned char *out, size_t len,
                                ccm128_f stream);
147
size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
148

149 150
typedef struct xts128_context XTS128_CONTEXT;

151 152 153 154
int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx,
                          const unsigned char iv[16],
                          const unsigned char *inp, unsigned char *out,
                          size_t len, int enc);
155

156
size_t CRYPTO_128_wrap(void *key, const unsigned char *iv,
157 158 159
                       unsigned char *out,
                       const unsigned char *in, size_t inlen,
                       block128_f block);
160 161

size_t CRYPTO_128_unwrap(void *key, const unsigned char *iv,
162 163 164
                         unsigned char *out,
                         const unsigned char *in, size_t inlen,
                         block128_f block);
D
Dr. Stephen Henson 已提交
165
size_t CRYPTO_128_wrap_pad(void *key, const unsigned char *icv,
166 167
                           unsigned char *out, const unsigned char *in,
                           size_t inlen, block128_f block);
D
Dr. Stephen Henson 已提交
168
size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv,
169 170
                             unsigned char *out, const unsigned char *in,
                             size_t inlen, block128_f block);
171

172
# ifndef OPENSSL_NO_OCB
173 174
typedef struct ocb128_context OCB128_CONTEXT;

175 176 177 178 179 180 181
typedef void (*ocb128_f) (const unsigned char *in, unsigned char *out,
                          size_t blocks, const void *key,
                          size_t start_block_num,
                          unsigned char offset_i[16],
                          const unsigned char L_[][16],
                          unsigned char checksum[16]);

182
OCB128_CONTEXT *CRYPTO_ocb128_new(void *keyenc, void *keydec,
183 184
                                  block128_f encrypt, block128_f decrypt,
                                  ocb128_f stream);
185
int CRYPTO_ocb128_init(OCB128_CONTEXT *ctx, void *keyenc, void *keydec,
186 187
                       block128_f encrypt, block128_f decrypt,
                       ocb128_f stream);
188
int CRYPTO_ocb128_copy_ctx(OCB128_CONTEXT *dest, OCB128_CONTEXT *src,
189
                           void *keyenc, void *keydec);
190
int CRYPTO_ocb128_setiv(OCB128_CONTEXT *ctx, const unsigned char *iv,
191
                        size_t len, size_t taglen);
192
int CRYPTO_ocb128_aad(OCB128_CONTEXT *ctx, const unsigned char *aad,
193 194 195 196 197 198 199
                      size_t len);
int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx, const unsigned char *in,
                          unsigned char *out, size_t len);
int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx, const unsigned char *in,
                          unsigned char *out, size_t len);
int CRYPTO_ocb128_finish(OCB128_CONTEXT *ctx, const unsigned char *tag,
                         size_t len);
200 201
int CRYPTO_ocb128_tag(OCB128_CONTEXT *ctx, unsigned char *tag, size_t len);
void CRYPTO_ocb128_cleanup(OCB128_CONTEXT *ctx);
202
# endif                          /* OPENSSL_NO_OCB */
203

204
# ifdef  __cplusplus
205
}
206 207
# endif

208
#endif