lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved. |
| 3 | * |
| 4 | * Licensed under the OpenSSL license (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 | |
| 15 | # ifdef __cplusplus |
| 16 | extern "C" { |
| 17 | # endif |
| 18 | typedef void (*block128_f) (const unsigned char in[16], |
| 19 | unsigned char out[16], const void *key); |
| 20 | |
| 21 | typedef void (*cbc128_f) (const unsigned char *in, unsigned char *out, |
| 22 | size_t len, const void *key, |
| 23 | unsigned char ivec[16], int enc); |
| 24 | |
| 25 | typedef void (*ctr128_f) (const unsigned char *in, unsigned char *out, |
| 26 | size_t blocks, const void *key, |
| 27 | const unsigned char ivec[16]); |
| 28 | |
| 29 | typedef void (*ccm128_f) (const unsigned char *in, unsigned char *out, |
| 30 | size_t blocks, const void *key, |
| 31 | const unsigned char ivec[16], |
| 32 | unsigned char cmac[16]); |
| 33 | |
| 34 | void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out, |
| 35 | size_t len, const void *key, |
| 36 | unsigned char ivec[16], block128_f block); |
| 37 | void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out, |
| 38 | size_t len, const void *key, |
| 39 | unsigned char ivec[16], block128_f block); |
| 40 | |
| 41 | void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out, |
| 42 | size_t len, const void *key, |
| 43 | unsigned char ivec[16], |
| 44 | unsigned char ecount_buf[16], unsigned int *num, |
| 45 | block128_f block); |
| 46 | |
| 47 | void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out, |
| 48 | size_t len, const void *key, |
| 49 | unsigned char ivec[16], |
| 50 | unsigned char ecount_buf[16], |
| 51 | unsigned int *num, ctr128_f ctr); |
| 52 | |
| 53 | void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out, |
| 54 | size_t len, const void *key, |
| 55 | unsigned char ivec[16], int *num, |
| 56 | block128_f block); |
| 57 | |
| 58 | void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out, |
| 59 | size_t len, const void *key, |
| 60 | unsigned char ivec[16], int *num, |
| 61 | int enc, block128_f block); |
| 62 | void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out, |
| 63 | size_t length, const void *key, |
| 64 | unsigned char ivec[16], int *num, |
| 65 | int enc, block128_f block); |
| 66 | void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out, |
| 67 | size_t bits, const void *key, |
| 68 | unsigned char ivec[16], int *num, |
| 69 | int enc, block128_f block); |
| 70 | |
| 71 | size_t CRYPTO_cts128_encrypt_block(const unsigned char *in, |
| 72 | unsigned char *out, size_t len, |
| 73 | const void *key, unsigned char ivec[16], |
| 74 | block128_f block); |
| 75 | size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out, |
| 76 | size_t len, const void *key, |
| 77 | unsigned char ivec[16], cbc128_f cbc); |
| 78 | size_t CRYPTO_cts128_decrypt_block(const unsigned char *in, |
| 79 | unsigned char *out, size_t len, |
| 80 | const void *key, unsigned char ivec[16], |
| 81 | block128_f block); |
| 82 | size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out, |
| 83 | size_t len, const void *key, |
| 84 | unsigned char ivec[16], cbc128_f cbc); |
| 85 | |
| 86 | size_t CRYPTO_nistcts128_encrypt_block(const unsigned char *in, |
| 87 | unsigned char *out, size_t len, |
| 88 | const void *key, |
| 89 | unsigned char ivec[16], |
| 90 | block128_f block); |
| 91 | size_t CRYPTO_nistcts128_encrypt(const unsigned char *in, unsigned char *out, |
| 92 | size_t len, const void *key, |
| 93 | unsigned char ivec[16], cbc128_f cbc); |
| 94 | size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in, |
| 95 | unsigned char *out, size_t len, |
| 96 | const void *key, |
| 97 | unsigned char ivec[16], |
| 98 | block128_f block); |
| 99 | size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out, |
| 100 | size_t len, const void *key, |
| 101 | unsigned char ivec[16], cbc128_f cbc); |
| 102 | |
| 103 | typedef struct gcm128_context GCM128_CONTEXT; |
| 104 | |
| 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 | const unsigned char *in, unsigned char *out, |
| 113 | size_t len); |
| 114 | int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, |
| 115 | const unsigned char *in, unsigned char *out, |
| 116 | size_t len); |
| 117 | int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx, |
| 118 | const unsigned char *in, unsigned char *out, |
| 119 | size_t len, ctr128_f stream); |
| 120 | int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx, |
| 121 | const unsigned char *in, unsigned char *out, |
| 122 | size_t len, ctr128_f stream); |
| 123 | int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag, |
| 124 | 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 | typedef struct ccm128_context CCM128_CONTEXT; |
| 129 | |
| 130 | void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx, |
| 131 | unsigned int M, unsigned int L, void *key, |
| 132 | block128_f block); |
| 133 | int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx, const unsigned char *nonce, |
| 134 | size_t nlen, size_t mlen); |
| 135 | void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx, const unsigned char *aad, |
| 136 | size_t alen); |
| 137 | int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx, const unsigned char *inp, |
| 138 | unsigned char *out, size_t len); |
| 139 | int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx, const unsigned char *inp, |
| 140 | unsigned char *out, size_t len); |
| 141 | int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp, |
| 142 | unsigned char *out, size_t len, |
| 143 | ccm128_f stream); |
| 144 | int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp, |
| 145 | unsigned char *out, size_t len, |
| 146 | ccm128_f stream); |
| 147 | size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len); |
| 148 | |
| 149 | typedef struct xts128_context XTS128_CONTEXT; |
| 150 | |
| 151 | int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, |
| 152 | const unsigned char iv[16], |
| 153 | const unsigned char *inp, unsigned char *out, |
| 154 | size_t len, int enc); |
| 155 | |
| 156 | size_t CRYPTO_128_wrap(void *key, const unsigned char *iv, |
| 157 | unsigned char *out, |
| 158 | const unsigned char *in, size_t inlen, |
| 159 | block128_f block); |
| 160 | |
| 161 | size_t CRYPTO_128_unwrap(void *key, const unsigned char *iv, |
| 162 | unsigned char *out, |
| 163 | const unsigned char *in, size_t inlen, |
| 164 | block128_f block); |
| 165 | size_t CRYPTO_128_wrap_pad(void *key, const unsigned char *icv, |
| 166 | unsigned char *out, const unsigned char *in, |
| 167 | size_t inlen, block128_f block); |
| 168 | size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv, |
| 169 | unsigned char *out, const unsigned char *in, |
| 170 | size_t inlen, block128_f block); |
| 171 | |
| 172 | # ifndef OPENSSL_NO_OCB |
| 173 | typedef struct ocb128_context OCB128_CONTEXT; |
| 174 | |
| 175 | typedef void (*ocb128_f) (const unsigned char *in, unsigned char *out, |
| 176 | size_t blocks, const void *key, |
| 177 | size_t start_block_num, |
| 178 | unsigned char offset_i[16], |
| 179 | const unsigned char L_[][16], |
| 180 | unsigned char checksum[16]); |
| 181 | |
| 182 | OCB128_CONTEXT *CRYPTO_ocb128_new(void *keyenc, void *keydec, |
| 183 | block128_f encrypt, block128_f decrypt, |
| 184 | ocb128_f stream); |
| 185 | int CRYPTO_ocb128_init(OCB128_CONTEXT *ctx, void *keyenc, void *keydec, |
| 186 | block128_f encrypt, block128_f decrypt, |
| 187 | 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 | size_t len); |
| 194 | int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx, const unsigned char *in, |
| 195 | unsigned char *out, size_t len); |
| 196 | int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx, const unsigned char *in, |
| 197 | unsigned char *out, size_t len); |
| 198 | int CRYPTO_ocb128_finish(OCB128_CONTEXT *ctx, const unsigned char *tag, |
| 199 | size_t len); |
| 200 | int CRYPTO_ocb128_tag(OCB128_CONTEXT *ctx, unsigned char *tag, size_t len); |
| 201 | void CRYPTO_ocb128_cleanup(OCB128_CONTEXT *ctx); |
| 202 | # endif /* OPENSSL_NO_OCB */ |
| 203 | |
| 204 | # ifdef __cplusplus |
| 205 | } |
| 206 | # endif |
| 207 | |
| 208 | #endif |