Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file cipher.h |
| 3 | * |
| 4 | * \brief Generic cipher wrapper. |
| 5 | * |
| 6 | * \author Adriaan de Jong <dejong@fox-it.com> |
| 7 | * |
| 8 | * Copyright (C) 2006-2010, Brainspark B.V. |
| 9 | * |
| 10 | * This file is part of PolarSSL (http://www.polarssl.org) |
| 11 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
| 12 | * |
| 13 | * All rights reserved. |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify |
| 16 | * it under the terms of the GNU General Public License as published by |
| 17 | * the Free Software Foundation; either version 2 of the License, or |
| 18 | * (at your option) any later version. |
| 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | * GNU General Public License for more details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU General Public License along |
| 26 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 27 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 28 | */ |
| 29 | |
| 30 | #ifndef POLARSSL_CIPHER_H |
| 31 | #define POLARSSL_CIPHER_H |
| 32 | |
| 33 | #include <string.h> |
| 34 | |
Paul Bakker | af5c85f | 2011-04-18 03:47:52 +0000 | [diff] [blame] | 35 | #ifdef _MSC_VER |
| 36 | #define inline _inline |
| 37 | #endif |
| 38 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 39 | #define POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080 /**< The selected feature is not available. */ |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame^] | 40 | #define POLARSSL_ERR_CIPHER_BAD_INPUT_DATA -0x6100 /**< Bad input parameters to function. */ |
| 41 | #define POLARSSL_ERR_CIPHER_ALLOC_FAILED -0x6180 /**< Failed to allocate memory. */ |
| 42 | #define POLARSSL_ERR_CIPHER_INVALID_PADDING -0x6200 /**< Input data contains invalid padding and is rejected. */ |
| 43 | #define POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED -0x6280 /**< Decryption of block requires a full block. */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 44 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 45 | typedef enum { |
| 46 | POLARSSL_CIPHER_ID_NONE = 0, |
| 47 | POLARSSL_CIPHER_ID_AES, |
| 48 | POLARSSL_CIPHER_ID_DES, |
| 49 | POLARSSL_CIPHER_ID_3DES, |
| 50 | POLARSSL_CIPHER_ID_CAMELLIA, |
| 51 | } cipher_id_t; |
| 52 | |
| 53 | typedef enum { |
| 54 | POLARSSL_CIPHER_NONE = 0, |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 55 | POLARSSL_CIPHER_AES_128_CBC, |
| 56 | POLARSSL_CIPHER_AES_192_CBC, |
| 57 | POLARSSL_CIPHER_AES_256_CBC, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 58 | POLARSSL_CIPHER_AES_128_CFB128, |
| 59 | POLARSSL_CIPHER_AES_192_CFB128, |
| 60 | POLARSSL_CIPHER_AES_256_CFB128, |
| 61 | POLARSSL_CIPHER_AES_128_CTR, |
| 62 | POLARSSL_CIPHER_AES_192_CTR, |
| 63 | POLARSSL_CIPHER_AES_256_CTR, |
| 64 | POLARSSL_CIPHER_CAMELLIA_128_CBC, |
| 65 | POLARSSL_CIPHER_CAMELLIA_192_CBC, |
| 66 | POLARSSL_CIPHER_CAMELLIA_256_CBC, |
| 67 | POLARSSL_CIPHER_CAMELLIA_128_CFB128, |
| 68 | POLARSSL_CIPHER_CAMELLIA_192_CFB128, |
| 69 | POLARSSL_CIPHER_CAMELLIA_256_CFB128, |
| 70 | POLARSSL_CIPHER_CAMELLIA_128_CTR, |
| 71 | POLARSSL_CIPHER_CAMELLIA_192_CTR, |
| 72 | POLARSSL_CIPHER_CAMELLIA_256_CTR, |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 73 | POLARSSL_CIPHER_DES_CBC, |
| 74 | POLARSSL_CIPHER_DES_EDE_CBC, |
| 75 | POLARSSL_CIPHER_DES_EDE3_CBC |
| 76 | } cipher_type_t; |
| 77 | |
| 78 | typedef enum { |
| 79 | POLARSSL_MODE_NONE = 0, |
| 80 | POLARSSL_MODE_CBC, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 81 | POLARSSL_MODE_CFB128, |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 82 | POLARSSL_MODE_OFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 83 | POLARSSL_MODE_CTR, |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 84 | } cipher_mode_t; |
| 85 | |
| 86 | typedef enum { |
| 87 | POLARSSL_DECRYPT = 0, |
| 88 | POLARSSL_ENCRYPT, |
| 89 | } operation_t; |
| 90 | |
| 91 | enum { |
| 92 | /** Undefined key length */ |
| 93 | POLARSSL_KEY_LENGTH_NONE = 0, |
| 94 | /** Key length, in bits, for DES keys */ |
| 95 | POLARSSL_KEY_LENGTH_DES = 56, |
| 96 | /** Key length, in bits, for DES in two key EDE */ |
| 97 | POLARSSL_KEY_LENGTH_DES_EDE = 112, |
| 98 | /** Key length, in bits, for DES in three-key EDE */ |
| 99 | POLARSSL_KEY_LENGTH_DES_EDE3 = 168, |
| 100 | /** Maximum length of any IV, in bytes */ |
| 101 | POLARSSL_MAX_IV_LENGTH = 16, |
| 102 | }; |
| 103 | |
| 104 | /** |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 105 | * Base cipher information. The non-mode specific functions and values. |
| 106 | */ |
| 107 | typedef struct { |
| 108 | |
| 109 | /** Base Cipher type (e.g. POLARSSL_CIPHER_ID_AES) */ |
| 110 | cipher_id_t cipher; |
| 111 | |
| 112 | /** Encrypt using CBC */ |
| 113 | int (*cbc_func)( void *ctx, operation_t mode, size_t length, unsigned char *iv, |
| 114 | const unsigned char *input, unsigned char *output ); |
| 115 | |
| 116 | /** Encrypt using CFB128 */ |
| 117 | int (*cfb128_func)( void *ctx, operation_t mode, size_t length, size_t *iv_off, |
| 118 | unsigned char *iv, const unsigned char *input, unsigned char *output ); |
| 119 | |
| 120 | /** Encrypt using CTR */ |
| 121 | int (*ctr_func)( void *ctx, size_t length, size_t *nc_off, unsigned char *nonce_counter, |
| 122 | unsigned char *stream_block, const unsigned char *input, unsigned char *output ); |
| 123 | |
| 124 | /** Set key for encryption purposes */ |
| 125 | int (*setkey_enc_func)( void *ctx, const unsigned char *key, unsigned int key_length); |
| 126 | |
| 127 | /** Set key for decryption purposes */ |
| 128 | int (*setkey_dec_func)( void *ctx, const unsigned char *key, unsigned int key_length); |
| 129 | |
| 130 | /** Allocate a new context */ |
| 131 | void * (*ctx_alloc_func)( void ); |
| 132 | |
| 133 | /** Free the given context */ |
| 134 | void (*ctx_free_func)( void *ctx ); |
| 135 | |
| 136 | } cipher_base_t; |
| 137 | |
| 138 | /** |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 139 | * Cipher information. Allows cipher functions to be called in a generic way. |
| 140 | */ |
| 141 | typedef struct { |
| 142 | /** Full cipher identifier (e.g. POLARSSL_CIPHER_AES_256_CBC) */ |
| 143 | cipher_type_t type; |
| 144 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 145 | /** Cipher mode (e.g. POLARSSL_CIPHER_MODE_CBC) */ |
| 146 | cipher_mode_t mode; |
| 147 | |
| 148 | /** Cipher key length, in bits (default length for variable sized ciphers) */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 149 | unsigned int key_length; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 150 | |
Paul Bakker | b6ecaf5 | 2011-04-19 14:29:23 +0000 | [diff] [blame] | 151 | /** Name of the cipher */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 152 | const char * name; |
| 153 | |
| 154 | /** IV size, in bytes */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 155 | unsigned int iv_size; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 156 | |
| 157 | /** block size, in bytes */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 158 | unsigned int block_size; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 159 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 160 | /** Base cipher information and functions */ |
| 161 | const cipher_base_t *base; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 162 | |
| 163 | } cipher_info_t; |
| 164 | |
| 165 | /** |
| 166 | * Generic message digest context. |
| 167 | */ |
| 168 | typedef struct { |
| 169 | /** Information about the associated cipher */ |
| 170 | const cipher_info_t *cipher_info; |
| 171 | |
| 172 | /** Key length to use */ |
| 173 | int key_length; |
| 174 | |
| 175 | /** Operation that the context's key has been initialised for */ |
| 176 | operation_t operation; |
| 177 | |
| 178 | /** Buffer for data that hasn't been encrypted yet */ |
| 179 | unsigned char unprocessed_data[POLARSSL_MAX_IV_LENGTH]; |
| 180 | |
| 181 | /** Number of bytes that still need processing */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 182 | size_t unprocessed_len; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 183 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 184 | /** Current IV or NONCE_COUNTER for CTR-mode */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 185 | unsigned char iv[POLARSSL_MAX_IV_LENGTH]; |
| 186 | |
| 187 | /** Cipher-specific context */ |
| 188 | void *cipher_ctx; |
| 189 | } cipher_context_t; |
| 190 | |
| 191 | #ifdef __cplusplus |
| 192 | extern "C" { |
| 193 | #endif |
| 194 | |
| 195 | /** |
Paul Bakker | 72f6266 | 2011-01-16 21:27:44 +0000 | [diff] [blame] | 196 | * \brief Returns the list of ciphers supported by the generic cipher module. |
| 197 | * |
| 198 | * \return a statically allocated array of ciphers, the last entry |
| 199 | * is 0. |
| 200 | */ |
| 201 | const int *cipher_list( void ); |
| 202 | |
| 203 | /** |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 204 | * \brief Returns the cipher information structure associated |
| 205 | * with the given cipher name. |
| 206 | * |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 207 | * \param cipher_name Name of the cipher to search for. |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 208 | * |
| 209 | * \return the cipher information structure associated with the |
| 210 | * given cipher_name, or NULL if not found. |
| 211 | */ |
| 212 | const cipher_info_t *cipher_info_from_string( const char *cipher_name ); |
| 213 | |
| 214 | /** |
| 215 | * \brief Returns the cipher information structure associated |
| 216 | * with the given cipher type. |
| 217 | * |
| 218 | * \param cipher_type Type of the cipher to search for. |
| 219 | * |
| 220 | * \return the cipher information structure associated with the |
| 221 | * given cipher_type, or NULL if not found. |
| 222 | */ |
| 223 | const cipher_info_t *cipher_info_from_type( const cipher_type_t cipher_type ); |
| 224 | |
| 225 | /** |
| 226 | * \brief Initialises and fills the cipher context structure with |
| 227 | * the appropriate values. |
| 228 | * |
| 229 | * \param ctx context to initialise. May not be NULL. |
| 230 | * \param cipher_info cipher to use. |
| 231 | * |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame^] | 232 | * \return \c 0 on success, |
| 233 | * \c POLARSSL_ERR_CIPHER_BAD_INPUT_DATA on parameter failure, |
| 234 | * \c POLARSSL_ERR_CIPHER_ALLOC_FAILED if allocation of the |
| 235 | * cipher-specific context failed. |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 236 | */ |
| 237 | int cipher_init_ctx( cipher_context_t *ctx, const cipher_info_t *cipher_info ); |
| 238 | |
| 239 | /** |
| 240 | * \brief Free the cipher-specific context of ctx. Freeing ctx |
| 241 | * itself remains the responsibility of the caller. |
| 242 | * |
| 243 | * \param ctx Free the cipher-specific context |
| 244 | * |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame^] | 245 | * \returns 0 on success, POLARSSL_ERR_CIPHER_BAD_INPUT_DATA if |
| 246 | * parameter verification fails. |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 247 | */ |
| 248 | int cipher_free_ctx( cipher_context_t *ctx ); |
| 249 | |
| 250 | /** |
| 251 | * \brief Returns the block size of the given cipher. |
| 252 | * |
| 253 | * \param ctx cipher's context. Must have been initialised. |
| 254 | * |
| 255 | * \return size of the cipher's blocks, or 0 if ctx has not been |
| 256 | * initialised. |
| 257 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 258 | static inline unsigned int cipher_get_block_size( const cipher_context_t *ctx ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 259 | { |
| 260 | if( NULL == ctx || NULL == ctx->cipher_info ) |
| 261 | return 0; |
| 262 | |
| 263 | return ctx->cipher_info->block_size; |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * \brief Returns the size of the cipher's IV. |
| 268 | * |
| 269 | * \param ctx cipher's context. Must have been initialised. |
| 270 | * |
| 271 | * \return size of the cipher's IV, or 0 if ctx has not been |
| 272 | * initialised. |
| 273 | */ |
| 274 | static inline int cipher_get_iv_size( const cipher_context_t *ctx ) |
| 275 | { |
| 276 | if( NULL == ctx || NULL == ctx->cipher_info ) |
| 277 | return 0; |
| 278 | |
| 279 | return ctx->cipher_info->iv_size; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * \brief Returns the type of the given cipher. |
| 284 | * |
| 285 | * \param ctx cipher's context. Must have been initialised. |
| 286 | * |
| 287 | * \return type of the cipher, or POLARSSL_CIPHER_NONE if ctx has |
| 288 | * not been initialised. |
| 289 | */ |
| 290 | static inline cipher_type_t cipher_get_type( const cipher_context_t *ctx ) |
| 291 | { |
| 292 | if( NULL == ctx || NULL == ctx->cipher_info ) |
| 293 | return 0; |
| 294 | |
| 295 | return ctx->cipher_info->type; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * \brief Returns the name of the given cipher, as a string. |
| 300 | * |
| 301 | * \param ctx cipher's context. Must have been initialised. |
| 302 | * |
| 303 | * \return name of the cipher, or NULL if ctx was not initialised. |
| 304 | */ |
| 305 | static inline const char *cipher_get_name( const cipher_context_t *ctx ) |
| 306 | { |
| 307 | if( NULL == ctx || NULL == ctx->cipher_info ) |
| 308 | return 0; |
| 309 | |
| 310 | return ctx->cipher_info->name; |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * \brief Returns the key length of the cipher. |
| 315 | * |
| 316 | * \param ctx cipher's context. Must have been initialised. |
| 317 | * |
| 318 | * \return cipher's key length, in bits, or |
| 319 | * POLARSSL_KEY_LENGTH_NONE if ctx has not been |
| 320 | * initialised. |
| 321 | */ |
| 322 | static inline int cipher_get_key_size ( const cipher_context_t *ctx ) |
| 323 | { |
| 324 | if( NULL == ctx ) |
| 325 | return POLARSSL_KEY_LENGTH_NONE; |
| 326 | |
| 327 | return ctx->key_length; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * \brief Set the key to use with the given context. |
| 332 | * |
| 333 | * \param ctx generic cipher context. May not be NULL. Must have been |
| 334 | * initialised using cipher_context_from_type or |
Paul Bakker | 1f14d08 | 2011-01-20 16:33:24 +0000 | [diff] [blame] | 335 | * cipher_context_from_string. |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 336 | * \param key The key to use. |
| 337 | * \param key_length key length to use, in bits. |
| 338 | * \param operation Operation that the key will be used for, either |
| 339 | * POLARSSL_ENCRYPT or POLARSSL_DECRYPT. |
| 340 | * |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame^] | 341 | * \returns 0 on success, POLARSSL_ERR_CIPHER_BAD_INPUT_DATA if |
| 342 | * parameter verification fails or a cipher specific |
| 343 | * error code. |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 344 | */ |
Paul Bakker | f3b86c1 | 2011-01-27 15:24:17 +0000 | [diff] [blame] | 345 | int cipher_setkey( cipher_context_t *ctx, const unsigned char *key, int key_length, |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 346 | const operation_t operation ); |
| 347 | |
| 348 | /** |
| 349 | * \brief Reset the given context, setting the IV to iv |
| 350 | * |
| 351 | * \param ctx generic cipher context |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 352 | * \param iv IV to use or NONCE_COUNTER in the case of a CTR-mode cipher |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 353 | * |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame^] | 354 | * \returns 0 on success, POLARSSL_ERR_CIPHER_BAD_INPUT_DATA |
| 355 | * if parameter verification fails. |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 356 | */ |
| 357 | int cipher_reset( cipher_context_t *ctx, const unsigned char *iv ); |
| 358 | |
| 359 | /** |
| 360 | * \brief Generic cipher update function. Encrypts/decrypts |
| 361 | * using the given cipher context. Writes as many block |
| 362 | * size'd blocks of data as possible to output. Any data |
| 363 | * that cannot be written immediately will either be added |
| 364 | * to the next block, or flushed when cipher_final is |
| 365 | * called. |
| 366 | * |
| 367 | * \param ctx generic cipher context |
| 368 | * \param input buffer holding the input data |
| 369 | * \param ilen length of the input data |
| 370 | * \param output buffer for the output data. Should be able to hold at |
Paul Bakker | 1f14d08 | 2011-01-20 16:33:24 +0000 | [diff] [blame] | 371 | * least ilen + block_size. Cannot be the same buffer as |
| 372 | * input! |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 373 | * \param olen length of the output data, will be filled with the |
| 374 | * actual number of bytes written. |
| 375 | * |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame^] | 376 | * \returns 0 on success, POLARSSL_ERR_CIPHER_BAD_INPUT_DATA if |
| 377 | * parameter verification fails, |
| 378 | * POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE on an |
| 379 | * unsupported mode for a cipher or a cipher specific |
| 380 | * error code. |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 381 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 382 | int cipher_update( cipher_context_t *ctx, const unsigned char *input, size_t ilen, |
| 383 | unsigned char *output, size_t *olen ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 384 | |
| 385 | /** |
| 386 | * \brief Generic cipher finalisation function. If data still |
| 387 | * needs to be flushed from an incomplete block, data |
| 388 | * contained within it will be padded with the size of |
| 389 | * the last block, and written to the output buffer. |
| 390 | * |
| 391 | * \param ctx Generic message digest context |
| 392 | * \param output buffer to write data to. Needs block_size data available. |
| 393 | * \param olen length of the data written to the output buffer. |
| 394 | * |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame^] | 395 | * \returns 0 on success, POLARSSL_ERR_CIPHER_BAD_INPUT_DATA if |
| 396 | * parameter verification fails, |
| 397 | * POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED if decryption |
| 398 | * expected a full block but was not provided one, |
| 399 | * POLARSSL_ERR_CIPHER_INVALID_PADDING on invalid padding |
| 400 | * while decrypting or a cipher specific error code. |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 401 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 402 | int cipher_finish( cipher_context_t *ctx, unsigned char *output, size_t *olen); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 403 | |
| 404 | |
| 405 | /** |
| 406 | * \brief Checkup routine |
| 407 | * |
| 408 | * \return 0 if successful, or 1 if the test failed |
| 409 | */ |
| 410 | int cipher_self_test( int verbose ); |
| 411 | |
| 412 | #ifdef __cplusplus |
| 413 | } |
| 414 | #endif |
| 415 | |
| 416 | #endif /* POLARSSL_MD_H */ |