Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file blowfish.h |
| 3 | * |
| 4 | * \brief Blowfish block cipher |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 5 | */ |
| 6 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 7 | * Copyright The Mbed TLS Contributors |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: Apache-2.0 |
| 9 | * |
| 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 11 | * not use this file except in compliance with the License. |
| 12 | * You may obtain a copy of the License at |
| 13 | * |
| 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | * |
| 16 | * Unless required by applicable law or agreed to in writing, software |
| 17 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 18 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | * See the License for the specific language governing permissions and |
| 20 | * limitations under the License. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 21 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 22 | #ifndef MBEDTLS_BLOWFISH_H |
| 23 | #define MBEDTLS_BLOWFISH_H |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 24 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 25 | #if !defined(MBEDTLS_CONFIG_FILE) |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 26 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 27 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 28 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 29 | #endif |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 30 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 31 | #include <stddef.h> |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 32 | #include <stdint.h> |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 33 | |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 34 | #include "mbedtls/platform_util.h" |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 35 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 36 | #define MBEDTLS_BLOWFISH_ENCRYPT 1 |
| 37 | #define MBEDTLS_BLOWFISH_DECRYPT 0 |
Manuel Pégourié-Gonnard | 097c7bb | 2015-06-18 16:43:38 +0200 | [diff] [blame] | 38 | #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448 |
| 39 | #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32 |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 40 | #define MBEDTLS_BLOWFISH_ROUNDS 16 /**< Rounds to use. When increasing this value, make sure to extend the initialisation vectors */ |
| 41 | #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */ |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 42 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 43 | #define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016 /**< Bad input data. */ |
| 44 | |
| 45 | #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018 /**< Invalid data input length. */ |
Ron Eldor | 9924bdc | 2018-10-04 10:59:13 +0300 | [diff] [blame] | 46 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 47 | #ifdef __cplusplus |
| 48 | extern "C" { |
| 49 | #endif |
| 50 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 51 | #if !defined(MBEDTLS_BLOWFISH_ALT) |
| 52 | // Regular implementation |
| 53 | // |
| 54 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 55 | /** |
| 56 | * \brief Blowfish context structure |
| 57 | */ |
Dawid Drozd | 428cc52 | 2018-07-24 10:02:47 +0200 | [diff] [blame] | 58 | typedef struct mbedtls_blowfish_context |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 59 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 60 | uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2]; /*!< Blowfish round keys */ |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 61 | uint32_t S[4][256]; /*!< key dependent S-boxes */ |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 62 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 63 | mbedtls_blowfish_context; |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 64 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 65 | #else /* MBEDTLS_BLOWFISH_ALT */ |
| 66 | #include "blowfish_alt.h" |
| 67 | #endif /* MBEDTLS_BLOWFISH_ALT */ |
| 68 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 69 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 70 | * \brief Initialize a Blowfish context. |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 71 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 72 | * \param ctx The Blowfish context to be initialized. |
| 73 | * This must not be \c NULL. |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 74 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 75 | void mbedtls_blowfish_init( mbedtls_blowfish_context *ctx ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 76 | |
| 77 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 78 | * \brief Clear a Blowfish context. |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 79 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 80 | * \param ctx The Blowfish context to be cleared. |
| 81 | * This may be \c NULL, in which case this function |
| 82 | * returns immediately. If it is not \c NULL, it must |
| 83 | * point to an initialized Blowfish context. |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 84 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 85 | void mbedtls_blowfish_free( mbedtls_blowfish_context *ctx ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 86 | |
| 87 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 88 | * \brief Perform a Blowfish key schedule operation. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 89 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 90 | * \param ctx The Blowfish context to perform the key schedule on. |
| 91 | * \param key The encryption key. This must be a readable buffer of |
| 92 | * length \p keybits Bits. |
| 93 | * \param keybits The length of \p key in Bits. This must be between |
| 94 | * \c 32 and \c 448 and a multiple of \c 8. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 95 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 96 | * \return \c 0 if successful. |
| 97 | * \return A negative error code on failure. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 98 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 99 | int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key, |
Manuel Pégourié-Gonnard | b8186a5 | 2015-06-18 14:58:58 +0200 | [diff] [blame] | 100 | unsigned int keybits ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 101 | |
| 102 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 103 | * \brief Perform a Blowfish-ECB block encryption/decryption operation. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 104 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 105 | * \param ctx The Blowfish context to use. This must be initialized |
| 106 | * and bound to a key. |
| 107 | * \param mode The mode of operation. Possible values are |
| 108 | * #MBEDTLS_BLOWFISH_ENCRYPT for encryption, or |
| 109 | * #MBEDTLS_BLOWFISH_DECRYPT for decryption. |
| 110 | * \param input The input block. This must be a readable buffer |
| 111 | * of size \c 8 Bytes. |
| 112 | * \param output The output block. This must be a writable buffer |
| 113 | * of size \c 8 Bytes. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 114 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 115 | * \return \c 0 if successful. |
| 116 | * \return A negative error code on failure. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 117 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 118 | int mbedtls_blowfish_crypt_ecb( mbedtls_blowfish_context *ctx, |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 119 | int mode, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 120 | const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE], |
| 121 | unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 122 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 123 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 124 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 125 | * \brief Perform a Blowfish-CBC buffer encryption/decryption operation. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 126 | * |
Manuel Pégourié-Gonnard | 2be147a | 2015-01-23 16:19:47 +0000 | [diff] [blame] | 127 | * \note Upon exit, the content of the IV is updated so that you can |
| 128 | * call the function same function again on the following |
| 129 | * block(s) of data and get the same result as if it was |
| 130 | * encrypted in one call. This allows a "streaming" usage. |
| 131 | * If on the other hand you need to retain the contents of the |
| 132 | * IV, you should either save it manually or use the cipher |
| 133 | * module instead. |
| 134 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 135 | * \param ctx The Blowfish context to use. This must be initialized |
| 136 | * and bound to a key. |
| 137 | * \param mode The mode of operation. Possible values are |
| 138 | * #MBEDTLS_BLOWFISH_ENCRYPT for encryption, or |
| 139 | * #MBEDTLS_BLOWFISH_DECRYPT for decryption. |
| 140 | * \param length The length of the input data in Bytes. This must be |
| 141 | * multiple of \c 8. |
| 142 | * \param iv The initialization vector. This must be a read/write buffer |
| 143 | * of length \c 8 Bytes. It is updated by this function. |
| 144 | * \param input The input data. This must be a readable buffer of length |
| 145 | * \p length Bytes. |
| 146 | * \param output The output data. This must be a writable buffer of length |
| 147 | * \p length Bytes. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 148 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 149 | * \return \c 0 if successful. |
| 150 | * \return A negative error code on failure. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 151 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 152 | int mbedtls_blowfish_crypt_cbc( mbedtls_blowfish_context *ctx, |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 153 | int mode, |
| 154 | size_t length, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 155 | unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE], |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 156 | const unsigned char *input, |
| 157 | unsigned char *output ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 158 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 159 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 160 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 161 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 162 | * \brief Perform a Blowfish CFB buffer encryption/decryption operation. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 163 | * |
Manuel Pégourié-Gonnard | 2be147a | 2015-01-23 16:19:47 +0000 | [diff] [blame] | 164 | * \note Upon exit, the content of the IV is updated so that you can |
| 165 | * call the function same function again on the following |
| 166 | * block(s) of data and get the same result as if it was |
| 167 | * encrypted in one call. This allows a "streaming" usage. |
| 168 | * If on the other hand you need to retain the contents of the |
| 169 | * IV, you should either save it manually or use the cipher |
| 170 | * module instead. |
| 171 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 172 | * \param ctx The Blowfish context to use. This must be initialized |
| 173 | * and bound to a key. |
| 174 | * \param mode The mode of operation. Possible values are |
| 175 | * #MBEDTLS_BLOWFISH_ENCRYPT for encryption, or |
| 176 | * #MBEDTLS_BLOWFISH_DECRYPT for decryption. |
| 177 | * \param length The length of the input data in Bytes. |
| 178 | * \param iv_off The offset in the initialiation vector. |
| 179 | * The value pointed to must be smaller than \c 8 Bytes. |
| 180 | * It is updated by this function to support the aforementioned |
| 181 | * streaming usage. |
| 182 | * \param iv The initialization vector. This must be a read/write buffer |
| 183 | * of size \c 8 Bytes. It is updated after use. |
| 184 | * \param input The input data. This must be a readable buffer of length |
| 185 | * \p length Bytes. |
| 186 | * \param output The output data. This must be a writable buffer of length |
| 187 | * \p length Bytes. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 188 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 189 | * \return \c 0 if successful. |
| 190 | * \return A negative error code on failure. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 191 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 192 | int mbedtls_blowfish_crypt_cfb64( mbedtls_blowfish_context *ctx, |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 193 | int mode, |
| 194 | size_t length, |
| 195 | size_t *iv_off, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 196 | unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE], |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 197 | const unsigned char *input, |
| 198 | unsigned char *output ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 199 | #endif /*MBEDTLS_CIPHER_MODE_CFB */ |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 200 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 201 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 202 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 203 | * \brief Perform a Blowfish-CTR buffer encryption/decryption operation. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 204 | * |
Manuel Pégourié-Gonnard | 22997b7 | 2018-02-28 12:29:41 +0100 | [diff] [blame] | 205 | * \warning You must never reuse a nonce value with the same key. Doing so |
| 206 | * would void the encryption for the two messages encrypted with |
| 207 | * the same nonce and key. |
| 208 | * |
| 209 | * There are two common strategies for managing nonces with CTR: |
| 210 | * |
Manuel Pégourié-Gonnard | d0f143b | 2018-05-24 12:01:58 +0200 | [diff] [blame] | 211 | * 1. You can handle everything as a single message processed over |
| 212 | * successive calls to this function. In that case, you want to |
| 213 | * set \p nonce_counter and \p nc_off to 0 for the first call, and |
| 214 | * then preserve the values of \p nonce_counter, \p nc_off and \p |
| 215 | * stream_block across calls to this function as they will be |
| 216 | * updated by this function. |
Manuel Pégourié-Gonnard | 22997b7 | 2018-02-28 12:29:41 +0100 | [diff] [blame] | 217 | * |
Manuel Pégourié-Gonnard | d0f143b | 2018-05-24 12:01:58 +0200 | [diff] [blame] | 218 | * With this strategy, you must not encrypt more than 2**64 |
| 219 | * blocks of data with the same key. |
| 220 | * |
| 221 | * 2. You can encrypt separate messages by dividing the \p |
| 222 | * nonce_counter buffer in two areas: the first one used for a |
| 223 | * per-message nonce, handled by yourself, and the second one |
| 224 | * updated by this function internally. |
| 225 | * |
| 226 | * For example, you might reserve the first 4 bytes for the |
| 227 | * per-message nonce, and the last 4 bytes for internal use. In that |
| 228 | * case, before calling this function on a new message you need to |
| 229 | * set the first 4 bytes of \p nonce_counter to your chosen nonce |
| 230 | * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p |
| 231 | * stream_block to be ignored). That way, you can encrypt at most |
| 232 | * 2**32 messages of up to 2**32 blocks each with the same key. |
| 233 | * |
| 234 | * The per-message nonce (or information sufficient to reconstruct |
| 235 | * it) needs to be communicated with the ciphertext and must be unique. |
| 236 | * The recommended way to ensure uniqueness is to use a message |
| 237 | * counter. |
| 238 | * |
| 239 | * Note that for both stategies, sizes are measured in blocks and |
| 240 | * that a Blowfish block is 8 bytes. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 241 | * |
Manuel Pégourié-Gonnard | fa0c47d | 2018-05-24 19:02:06 +0200 | [diff] [blame] | 242 | * \warning Upon return, \p stream_block contains sensitive data. Its |
| 243 | * content must not be written to insecure storage and should be |
| 244 | * securely discarded as soon as it's no longer needed. |
| 245 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 246 | * \param ctx The Blowfish context to use. This must be initialized |
| 247 | * and bound to a key. |
| 248 | * \param length The length of the input data in Bytes. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 249 | * \param nc_off The offset in the current stream_block (for resuming |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 250 | * within current cipher stream). The offset pointer |
| 251 | * should be \c 0 at the start of a stream and must be |
| 252 | * smaller than \c 8. It is updated by this function. |
| 253 | * \param nonce_counter The 64-bit nonce and counter. This must point to a |
| 254 | * read/write buffer of length \c 8 Bytes. |
| 255 | * \param stream_block The saved stream-block for resuming. This must point to |
| 256 | * a read/write buffer of length \c 8 Bytes. |
| 257 | * \param input The input data. This must be a readable buffer of |
| 258 | * length \p length Bytes. |
| 259 | * \param output The output data. This must be a writable buffer of |
| 260 | * length \p length Bytes. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 261 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 262 | * \return \c 0 if successful. |
| 263 | * \return A negative error code on failure. |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 264 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 265 | int mbedtls_blowfish_crypt_ctr( mbedtls_blowfish_context *ctx, |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 266 | size_t length, |
| 267 | size_t *nc_off, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 268 | unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE], |
| 269 | unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE], |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 270 | const unsigned char *input, |
| 271 | unsigned char *output ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 272 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 273 | |
| 274 | #ifdef __cplusplus |
| 275 | } |
| 276 | #endif |
| 277 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 278 | #endif /* blowfish.h */ |