Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file cipher.c |
| 3 | * |
| 4 | * \brief Generic cipher wrapper for PolarSSL |
| 5 | * |
| 6 | * \author Adriaan de Jong <dejong@fox-it.com> |
| 7 | * |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 8 | * Copyright (C) 2006-2013, Brainspark B.V. |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 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 | #include "polarssl/config.h" |
| 31 | |
| 32 | #if defined(POLARSSL_CIPHER_C) |
| 33 | |
| 34 | #include "polarssl/cipher.h" |
| 35 | #include "polarssl/cipher_wrap.h" |
| 36 | |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 37 | #if defined(POLARSSL_GCM_C) |
| 38 | #include "polarssl/gcm.h" |
| 39 | #endif |
| 40 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 41 | #include <stdlib.h> |
| 42 | |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 43 | #if defined(POLARSSL_ARC4_C) || defined(POLARSSL_CIPHER_NULL_CIPHER) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 44 | #define POLARSSL_CIPHER_MODE_STREAM |
| 45 | #endif |
| 46 | |
Paul Bakker | af5c85f | 2011-04-18 03:47:52 +0000 | [diff] [blame] | 47 | #if defined _MSC_VER && !defined strcasecmp |
| 48 | #define strcasecmp _stricmp |
| 49 | #endif |
| 50 | |
Paul Bakker | 72f6266 | 2011-01-16 21:27:44 +0000 | [diff] [blame] | 51 | static const int supported_ciphers[] = { |
| 52 | |
| 53 | #if defined(POLARSSL_AES_C) |
| 54 | POLARSSL_CIPHER_AES_128_CBC, |
| 55 | POLARSSL_CIPHER_AES_192_CBC, |
| 56 | POLARSSL_CIPHER_AES_256_CBC, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 57 | |
| 58 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 59 | POLARSSL_CIPHER_AES_128_CFB128, |
| 60 | POLARSSL_CIPHER_AES_192_CFB128, |
| 61 | POLARSSL_CIPHER_AES_256_CFB128, |
| 62 | #endif /* defined(POLARSSL_CIPHER_MODE_CFB) */ |
| 63 | |
| 64 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 65 | POLARSSL_CIPHER_AES_128_CTR, |
| 66 | POLARSSL_CIPHER_AES_192_CTR, |
| 67 | POLARSSL_CIPHER_AES_256_CTR, |
| 68 | #endif /* defined(POLARSSL_CIPHER_MODE_CTR) */ |
| 69 | |
Paul Bakker | 72f6266 | 2011-01-16 21:27:44 +0000 | [diff] [blame] | 70 | #endif /* defined(POLARSSL_AES_C) */ |
| 71 | |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 72 | #if defined(POLARSSL_ARC4_C) |
| 73 | POLARSSL_CIPHER_ARC4_128, |
| 74 | #endif |
| 75 | |
Paul Bakker | 72f6266 | 2011-01-16 21:27:44 +0000 | [diff] [blame] | 76 | #if defined(POLARSSL_CAMELLIA_C) |
| 77 | POLARSSL_CIPHER_CAMELLIA_128_CBC, |
| 78 | POLARSSL_CIPHER_CAMELLIA_192_CBC, |
| 79 | POLARSSL_CIPHER_CAMELLIA_256_CBC, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 80 | |
| 81 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 82 | POLARSSL_CIPHER_CAMELLIA_128_CFB128, |
| 83 | POLARSSL_CIPHER_CAMELLIA_192_CFB128, |
| 84 | POLARSSL_CIPHER_CAMELLIA_256_CFB128, |
| 85 | #endif /* defined(POLARSSL_CIPHER_MODE_CFB) */ |
| 86 | |
| 87 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 88 | POLARSSL_CIPHER_CAMELLIA_128_CTR, |
| 89 | POLARSSL_CIPHER_CAMELLIA_192_CTR, |
| 90 | POLARSSL_CIPHER_CAMELLIA_256_CTR, |
| 91 | #endif /* defined(POLARSSL_CIPHER_MODE_CTR) */ |
| 92 | |
Paul Bakker | 72f6266 | 2011-01-16 21:27:44 +0000 | [diff] [blame] | 93 | #endif /* defined(POLARSSL_CAMELLIA_C) */ |
| 94 | |
| 95 | #if defined(POLARSSL_DES_C) |
| 96 | POLARSSL_CIPHER_DES_CBC, |
| 97 | POLARSSL_CIPHER_DES_EDE_CBC, |
| 98 | POLARSSL_CIPHER_DES_EDE3_CBC, |
| 99 | #endif /* defined(POLARSSL_DES_C) */ |
| 100 | |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 101 | #if defined(POLARSSL_BLOWFISH_C) |
| 102 | POLARSSL_CIPHER_BLOWFISH_CBC, |
| 103 | |
| 104 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 105 | POLARSSL_CIPHER_BLOWFISH_CFB64, |
| 106 | #endif /* defined(POLARSSL_CIPHER_MODE_CFB) */ |
| 107 | |
| 108 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 109 | POLARSSL_CIPHER_BLOWFISH_CTR, |
| 110 | #endif /* defined(POLARSSL_CIPHER_MODE_CTR) */ |
| 111 | |
| 112 | #endif /* defined(POLARSSL_BLOWFISH_C) */ |
| 113 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 114 | #if defined(POLARSSL_CIPHER_NULL_CIPHER) |
| 115 | POLARSSL_CIPHER_NULL, |
| 116 | #endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */ |
| 117 | |
Paul Bakker | 72f6266 | 2011-01-16 21:27:44 +0000 | [diff] [blame] | 118 | 0 |
| 119 | }; |
| 120 | |
| 121 | const int *cipher_list( void ) |
| 122 | { |
| 123 | return supported_ciphers; |
| 124 | } |
| 125 | |
Paul Bakker | ec1b984 | 2012-01-14 18:24:43 +0000 | [diff] [blame] | 126 | const cipher_info_t *cipher_info_from_type( const cipher_type_t cipher_type ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 127 | { |
| 128 | /* Find static cipher information */ |
| 129 | switch ( cipher_type ) |
| 130 | { |
| 131 | #if defined(POLARSSL_AES_C) |
| 132 | case POLARSSL_CIPHER_AES_128_CBC: |
| 133 | return &aes_128_cbc_info; |
| 134 | case POLARSSL_CIPHER_AES_192_CBC: |
| 135 | return &aes_192_cbc_info; |
| 136 | case POLARSSL_CIPHER_AES_256_CBC: |
| 137 | return &aes_256_cbc_info; |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 138 | |
| 139 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 140 | case POLARSSL_CIPHER_AES_128_CFB128: |
| 141 | return &aes_128_cfb128_info; |
| 142 | case POLARSSL_CIPHER_AES_192_CFB128: |
| 143 | return &aes_192_cfb128_info; |
| 144 | case POLARSSL_CIPHER_AES_256_CFB128: |
| 145 | return &aes_256_cfb128_info; |
| 146 | #endif /* defined(POLARSSL_CIPHER_MODE_CFB) */ |
| 147 | |
| 148 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 149 | case POLARSSL_CIPHER_AES_128_CTR: |
| 150 | return &aes_128_ctr_info; |
| 151 | case POLARSSL_CIPHER_AES_192_CTR: |
| 152 | return &aes_192_ctr_info; |
| 153 | case POLARSSL_CIPHER_AES_256_CTR: |
| 154 | return &aes_256_ctr_info; |
| 155 | #endif /* defined(POLARSSL_CIPHER_MODE_CTR) */ |
| 156 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 157 | #if defined(POLARSSL_GCM_C) |
| 158 | case POLARSSL_CIPHER_AES_128_GCM: |
| 159 | return &aes_128_gcm_info; |
| 160 | case POLARSSL_CIPHER_AES_256_GCM: |
| 161 | return &aes_256_gcm_info; |
| 162 | #endif /* defined(POLARSSL_GCM_C) */ |
| 163 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 164 | #endif |
| 165 | |
| 166 | #if defined(POLARSSL_CAMELLIA_C) |
| 167 | case POLARSSL_CIPHER_CAMELLIA_128_CBC: |
| 168 | return &camellia_128_cbc_info; |
| 169 | case POLARSSL_CIPHER_CAMELLIA_192_CBC: |
| 170 | return &camellia_192_cbc_info; |
| 171 | case POLARSSL_CIPHER_CAMELLIA_256_CBC: |
| 172 | return &camellia_256_cbc_info; |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 173 | |
| 174 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 175 | case POLARSSL_CIPHER_CAMELLIA_128_CFB128: |
| 176 | return &camellia_128_cfb128_info; |
| 177 | case POLARSSL_CIPHER_CAMELLIA_192_CFB128: |
| 178 | return &camellia_192_cfb128_info; |
| 179 | case POLARSSL_CIPHER_CAMELLIA_256_CFB128: |
| 180 | return &camellia_256_cfb128_info; |
| 181 | #endif /* defined(POLARSSL_CIPHER_MODE_CFB) */ |
| 182 | |
| 183 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 184 | case POLARSSL_CIPHER_CAMELLIA_128_CTR: |
| 185 | return &camellia_128_ctr_info; |
| 186 | case POLARSSL_CIPHER_CAMELLIA_192_CTR: |
| 187 | return &camellia_192_ctr_info; |
| 188 | case POLARSSL_CIPHER_CAMELLIA_256_CTR: |
| 189 | return &camellia_256_ctr_info; |
| 190 | #endif /* defined(POLARSSL_CIPHER_MODE_CTR) */ |
| 191 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 192 | #endif |
| 193 | |
| 194 | #if defined(POLARSSL_DES_C) |
| 195 | case POLARSSL_CIPHER_DES_CBC: |
| 196 | return &des_cbc_info; |
| 197 | case POLARSSL_CIPHER_DES_EDE_CBC: |
| 198 | return &des_ede_cbc_info; |
| 199 | case POLARSSL_CIPHER_DES_EDE3_CBC: |
| 200 | return &des_ede3_cbc_info; |
| 201 | #endif |
| 202 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 203 | #if defined(POLARSSL_ARC4_C) |
| 204 | case POLARSSL_CIPHER_ARC4_128: |
| 205 | return &arc4_128_info; |
| 206 | #endif |
| 207 | |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 208 | #if defined(POLARSSL_BLOWFISH_C) |
| 209 | case POLARSSL_CIPHER_BLOWFISH_CBC: |
| 210 | return &blowfish_cbc_info; |
| 211 | |
| 212 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 213 | case POLARSSL_CIPHER_BLOWFISH_CFB64: |
| 214 | return &blowfish_cfb64_info; |
| 215 | #endif /* defined(POLARSSL_CIPHER_MODE_CFB) */ |
| 216 | |
| 217 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 218 | case POLARSSL_CIPHER_BLOWFISH_CTR: |
| 219 | return &blowfish_ctr_info; |
| 220 | #endif /* defined(POLARSSL_CIPHER_MODE_CTR) */ |
| 221 | |
| 222 | #endif |
| 223 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 224 | #if defined(POLARSSL_CIPHER_NULL_CIPHER) |
| 225 | case POLARSSL_CIPHER_NULL: |
| 226 | return &null_cipher_info; |
| 227 | #endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */ |
| 228 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 229 | default: |
| 230 | return NULL; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | const cipher_info_t *cipher_info_from_string( const char *cipher_name ) |
| 235 | { |
| 236 | if( NULL == cipher_name ) |
| 237 | return NULL; |
| 238 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 239 | /* Get the appropriate cipher information */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 240 | #if defined(POLARSSL_CAMELLIA_C) |
| 241 | if( !strcasecmp( "CAMELLIA-128-CBC", cipher_name ) ) |
| 242 | return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_128_CBC ); |
| 243 | if( !strcasecmp( "CAMELLIA-192-CBC", cipher_name ) ) |
| 244 | return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_192_CBC ); |
| 245 | if( !strcasecmp( "CAMELLIA-256-CBC", cipher_name ) ) |
| 246 | return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_256_CBC ); |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 247 | |
| 248 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 249 | if( !strcasecmp( "CAMELLIA-128-CFB128", cipher_name ) ) |
| 250 | return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_128_CFB128 ); |
| 251 | if( !strcasecmp( "CAMELLIA-192-CFB128", cipher_name ) ) |
| 252 | return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_192_CFB128 ); |
| 253 | if( !strcasecmp( "CAMELLIA-256-CFB128", cipher_name ) ) |
| 254 | return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_256_CFB128 ); |
| 255 | #endif /* defined(POLARSSL_CIPHER_MODE_CFB) */ |
| 256 | |
| 257 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 258 | if( !strcasecmp( "CAMELLIA-128-CTR", cipher_name ) ) |
| 259 | return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_128_CTR ); |
| 260 | if( !strcasecmp( "CAMELLIA-192-CTR", cipher_name ) ) |
| 261 | return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_192_CTR ); |
| 262 | if( !strcasecmp( "CAMELLIA-256-CTR", cipher_name ) ) |
| 263 | return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_256_CTR ); |
| 264 | #endif /* defined(POLARSSL_CIPHER_MODE_CTR) */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 265 | #endif |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 266 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 267 | #if defined(POLARSSL_AES_C) |
| 268 | if( !strcasecmp( "AES-128-CBC", cipher_name ) ) |
| 269 | return cipher_info_from_type( POLARSSL_CIPHER_AES_128_CBC ); |
| 270 | if( !strcasecmp( "AES-192-CBC", cipher_name ) ) |
| 271 | return cipher_info_from_type( POLARSSL_CIPHER_AES_192_CBC ); |
| 272 | if( !strcasecmp( "AES-256-CBC", cipher_name ) ) |
| 273 | return cipher_info_from_type( POLARSSL_CIPHER_AES_256_CBC ); |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 274 | |
| 275 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 276 | if( !strcasecmp( "AES-128-CFB128", cipher_name ) ) |
| 277 | return cipher_info_from_type( POLARSSL_CIPHER_AES_128_CFB128 ); |
| 278 | if( !strcasecmp( "AES-192-CFB128", cipher_name ) ) |
| 279 | return cipher_info_from_type( POLARSSL_CIPHER_AES_192_CFB128 ); |
| 280 | if( !strcasecmp( "AES-256-CFB128", cipher_name ) ) |
| 281 | return cipher_info_from_type( POLARSSL_CIPHER_AES_256_CFB128 ); |
| 282 | #endif /* defined(POLARSSL_CIPHER_MODE_CFB) */ |
| 283 | |
| 284 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 285 | if( !strcasecmp( "AES-128-CTR", cipher_name ) ) |
| 286 | return cipher_info_from_type( POLARSSL_CIPHER_AES_128_CTR ); |
| 287 | if( !strcasecmp( "AES-192-CTR", cipher_name ) ) |
| 288 | return cipher_info_from_type( POLARSSL_CIPHER_AES_192_CTR ); |
| 289 | if( !strcasecmp( "AES-256-CTR", cipher_name ) ) |
| 290 | return cipher_info_from_type( POLARSSL_CIPHER_AES_256_CTR ); |
| 291 | #endif /* defined(POLARSSL_CIPHER_MODE_CTR) */ |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 292 | |
| 293 | #if defined(POLARSSL_GCM_C) |
| 294 | if( !strcasecmp( "AES-128-GCM", cipher_name ) ) |
| 295 | return cipher_info_from_type( POLARSSL_CIPHER_AES_128_GCM ); |
| 296 | if( !strcasecmp( "AES-256-GCM", cipher_name ) ) |
| 297 | return cipher_info_from_type( POLARSSL_CIPHER_AES_256_GCM ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 298 | #endif |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 299 | #endif /* POLARSSL_AES_C */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 300 | |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 301 | #if defined(POLARSSL_ARC4_C) |
| 302 | if( !strcasecmp( "ARC4-128", cipher_name ) ) |
| 303 | return( cipher_info_from_type( POLARSSL_CIPHER_ARC4_128 ) ); |
| 304 | #endif |
| 305 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 306 | #if defined(POLARSSL_DES_C) |
| 307 | if( !strcasecmp( "DES-CBC", cipher_name ) ) |
| 308 | return cipher_info_from_type( POLARSSL_CIPHER_DES_CBC ); |
| 309 | if( !strcasecmp( "DES-EDE-CBC", cipher_name ) ) |
| 310 | return cipher_info_from_type( POLARSSL_CIPHER_DES_EDE_CBC ); |
| 311 | if( !strcasecmp( "DES-EDE3-CBC", cipher_name ) ) |
| 312 | return cipher_info_from_type( POLARSSL_CIPHER_DES_EDE3_CBC ); |
| 313 | #endif |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 314 | |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 315 | #if defined(POLARSSL_BLOWFISH_C) |
| 316 | if( !strcasecmp( "BLOWFISH-CBC", cipher_name ) ) |
| 317 | return cipher_info_from_type( POLARSSL_CIPHER_BLOWFISH_CBC ); |
| 318 | |
| 319 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 320 | if( !strcasecmp( "BLOWFISH-CFB64", cipher_name ) ) |
| 321 | return cipher_info_from_type( POLARSSL_CIPHER_BLOWFISH_CFB64 ); |
| 322 | #endif /* defined(POLARSSL_CIPHER_MODE_CFB) */ |
| 323 | |
| 324 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 325 | if( !strcasecmp( "BLOWFISH-CTR", cipher_name ) ) |
| 326 | return cipher_info_from_type( POLARSSL_CIPHER_BLOWFISH_CTR ); |
| 327 | #endif /* defined(POLARSSL_CIPHER_MODE_CTR) */ |
| 328 | #endif |
| 329 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 330 | #if defined(POLARSSL_CIPHER_NULL_CIPHER) |
| 331 | if( !strcasecmp( "NULL", cipher_name ) ) |
| 332 | return cipher_info_from_type( POLARSSL_CIPHER_NULL ); |
| 333 | #endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */ |
| 334 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 335 | return NULL; |
| 336 | } |
| 337 | |
| 338 | int cipher_init_ctx( cipher_context_t *ctx, const cipher_info_t *cipher_info ) |
| 339 | { |
| 340 | if( NULL == cipher_info || NULL == ctx ) |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 341 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 342 | |
Paul Bakker | 279432a | 2012-04-26 10:09:35 +0000 | [diff] [blame] | 343 | memset( ctx, 0, sizeof( cipher_context_t ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 344 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 345 | if( NULL == ( ctx->cipher_ctx = cipher_info->base->ctx_alloc_func() ) ) |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 346 | return POLARSSL_ERR_CIPHER_ALLOC_FAILED; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 347 | |
| 348 | ctx->cipher_info = cipher_info; |
| 349 | |
Manuel Pégourié-Gonnard | ac56a1a | 2013-07-25 12:31:10 +0200 | [diff] [blame] | 350 | /* |
| 351 | * Ignore possible errors caused by a cipher mode that doesn't use padding |
| 352 | */ |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 353 | #if defined(POLARSSL_CIPHER_PADDING_PKCS7) |
Manuel Pégourié-Gonnard | ac56a1a | 2013-07-25 12:31:10 +0200 | [diff] [blame] | 354 | (void) cipher_set_padding_mode( ctx, POLARSSL_PADDING_PKCS7 ); |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 355 | #else |
| 356 | (void) cipher_set_padding_mode( ctx, POLARSSL_PADDING_NONE ); |
| 357 | #endif |
Manuel Pégourié-Gonnard | ac56a1a | 2013-07-25 12:31:10 +0200 | [diff] [blame] | 358 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | int cipher_free_ctx( cipher_context_t *ctx ) |
| 363 | { |
| 364 | if( ctx == NULL || ctx->cipher_info == NULL ) |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 365 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 366 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 367 | ctx->cipher_info->base->ctx_free_func( ctx->cipher_ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | int cipher_setkey( cipher_context_t *ctx, const unsigned char *key, |
| 373 | int key_length, const operation_t operation ) |
| 374 | { |
| 375 | if( NULL == ctx || NULL == ctx->cipher_info ) |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 376 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 377 | |
| 378 | ctx->key_length = key_length; |
| 379 | ctx->operation = operation; |
| 380 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 381 | /* |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 382 | * For CFB and CTR mode always use the encryption key schedule |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 383 | */ |
| 384 | if( POLARSSL_ENCRYPT == operation || |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 385 | POLARSSL_MODE_CFB == ctx->cipher_info->mode || |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 386 | POLARSSL_MODE_CTR == ctx->cipher_info->mode ) |
| 387 | { |
| 388 | return ctx->cipher_info->base->setkey_enc_func( ctx->cipher_ctx, key, |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 389 | ctx->key_length ); |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 390 | } |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 391 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 392 | if( POLARSSL_DECRYPT == operation ) |
| 393 | return ctx->cipher_info->base->setkey_dec_func( ctx->cipher_ctx, key, |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 394 | ctx->key_length ); |
| 395 | |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 396 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Manuel Pégourié-Gonnard | 9c853b9 | 2013-09-03 13:04:44 +0200 | [diff] [blame] | 399 | int cipher_set_iv( cipher_context_t *ctx, |
| 400 | const unsigned char *iv, size_t iv_len ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 401 | { |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 402 | size_t actual_iv_size; |
Manuel Pégourié-Gonnard | 9c853b9 | 2013-09-03 13:04:44 +0200 | [diff] [blame] | 403 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 404 | if( NULL == ctx || NULL == ctx->cipher_info || NULL == iv ) |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 405 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 406 | |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 407 | if( ctx->cipher_info->accepts_variable_iv_size ) |
| 408 | actual_iv_size = iv_len; |
| 409 | else |
| 410 | actual_iv_size = ctx->cipher_info->iv_size; |
Manuel Pégourié-Gonnard | 9c853b9 | 2013-09-03 13:04:44 +0200 | [diff] [blame] | 411 | |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 412 | memcpy( ctx->iv, iv, actual_iv_size ); |
| 413 | ctx->iv_size = actual_iv_size; |
Manuel Pégourié-Gonnard | 9c853b9 | 2013-09-03 13:04:44 +0200 | [diff] [blame] | 414 | |
| 415 | return 0; |
| 416 | } |
| 417 | |
Manuel Pégourié-Gonnard | 2adc40c | 2013-09-03 13:54:12 +0200 | [diff] [blame^] | 418 | int cipher_reset( cipher_context_t *ctx ) |
Manuel Pégourié-Gonnard | 9c853b9 | 2013-09-03 13:04:44 +0200 | [diff] [blame] | 419 | { |
Manuel Pégourié-Gonnard | 2adc40c | 2013-09-03 13:54:12 +0200 | [diff] [blame^] | 420 | if( NULL == ctx || NULL == ctx->cipher_info ) |
| 421 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
| 422 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 423 | ctx->unprocessed_len = 0; |
| 424 | |
Manuel Pégourié-Gonnard | 2adc40c | 2013-09-03 13:54:12 +0200 | [diff] [blame^] | 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | int cipher_update_ad( cipher_context_t *ctx, |
| 429 | const unsigned char *ad, size_t ad_len ) |
| 430 | { |
| 431 | if( NULL == ctx || NULL == ctx->cipher_info ) |
| 432 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
| 433 | |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 434 | #if defined(POLARSSL_GCM_C) |
| 435 | if( POLARSSL_MODE_GCM == ctx->cipher_info->mode ) |
| 436 | { |
Manuel Pégourié-Gonnard | 2adc40c | 2013-09-03 13:54:12 +0200 | [diff] [blame^] | 437 | /* Make sure we're called right after cipher_reset() */ |
| 438 | if( ((gcm_context *) ctx->cipher_ctx)->len != 0 || |
| 439 | ((gcm_context *) ctx->cipher_ctx)->add_len != 0 ) |
| 440 | { |
| 441 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 442 | } |
| 443 | |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 444 | return gcm_starts( ctx->cipher_ctx, ctx->operation, |
Manuel Pégourié-Gonnard | 9c853b9 | 2013-09-03 13:04:44 +0200 | [diff] [blame] | 445 | ctx->iv, ctx->iv_size, ad, ad_len ); |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 446 | } |
Manuel Pégourié-Gonnard | 9241be7 | 2013-08-31 17:31:03 +0200 | [diff] [blame] | 447 | #else |
| 448 | ((void) ad); |
| 449 | ((void) ad_len); |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 450 | #endif |
| 451 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 452 | return 0; |
| 453 | } |
| 454 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 455 | int cipher_update( cipher_context_t *ctx, const unsigned char *input, size_t ilen, |
| 456 | unsigned char *output, size_t *olen ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 457 | { |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 458 | int ret; |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 459 | size_t copy_len = 0; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 460 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 461 | *olen = 0; |
| 462 | |
| 463 | if( NULL == ctx || NULL == ctx->cipher_info || NULL == olen ) |
Paul Bakker | a885d68 | 2011-01-20 16:35:05 +0000 | [diff] [blame] | 464 | { |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 465 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
Paul Bakker | a885d68 | 2011-01-20 16:35:05 +0000 | [diff] [blame] | 466 | } |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 467 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 468 | if( input == output && |
| 469 | ( ctx->unprocessed_len != 0 || ilen % cipher_get_block_size( ctx ) ) ) |
| 470 | { |
| 471 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
| 472 | } |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 473 | |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 474 | if( ctx->cipher_info->mode == POLARSSL_MODE_CBC || |
| 475 | ctx->cipher_info->mode == POLARSSL_MODE_GCM ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 476 | { |
| 477 | /* |
| 478 | * If there is not enough data for a full block, cache it. |
| 479 | */ |
| 480 | if( ( ctx->operation == POLARSSL_DECRYPT && |
| 481 | ilen + ctx->unprocessed_len <= cipher_get_block_size( ctx ) ) || |
| 482 | ( ctx->operation == POLARSSL_ENCRYPT && |
| 483 | ilen + ctx->unprocessed_len < cipher_get_block_size( ctx ) ) ) |
| 484 | { |
| 485 | memcpy( &( ctx->unprocessed_data[ctx->unprocessed_len] ), input, |
| 486 | ilen ); |
| 487 | |
| 488 | ctx->unprocessed_len += ilen; |
| 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | /* |
| 493 | * Process cached data first |
| 494 | */ |
| 495 | if( ctx->unprocessed_len != 0 ) |
| 496 | { |
| 497 | copy_len = cipher_get_block_size( ctx ) - ctx->unprocessed_len; |
| 498 | |
| 499 | memcpy( &( ctx->unprocessed_data[ctx->unprocessed_len] ), input, |
| 500 | copy_len ); |
| 501 | |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 502 | #if defined(POLARSSL_GCM_C) |
| 503 | if( ctx->cipher_info->mode == POLARSSL_MODE_GCM ) |
| 504 | { |
| 505 | if( 0 != ( ret = gcm_update( ctx->cipher_ctx, |
| 506 | cipher_get_block_size( ctx ), |
| 507 | ctx->unprocessed_data, output ) ) ) |
| 508 | { |
| 509 | return ret; |
| 510 | } |
| 511 | } |
| 512 | else |
| 513 | #endif |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 514 | if( 0 != ( ret = ctx->cipher_info->base->cbc_func( ctx->cipher_ctx, |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 515 | ctx->operation, cipher_get_block_size( ctx ), ctx->iv, |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 516 | ctx->unprocessed_data, output ) ) ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 517 | { |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 518 | return ret; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | *olen += cipher_get_block_size( ctx ); |
| 522 | output += cipher_get_block_size( ctx ); |
| 523 | ctx->unprocessed_len = 0; |
| 524 | |
| 525 | input += copy_len; |
| 526 | ilen -= copy_len; |
| 527 | } |
| 528 | |
| 529 | /* |
| 530 | * Cache final, incomplete block |
| 531 | */ |
| 532 | if( 0 != ilen ) |
| 533 | { |
| 534 | copy_len = ilen % cipher_get_block_size( ctx ); |
| 535 | if( copy_len == 0 && ctx->operation == POLARSSL_DECRYPT ) |
| 536 | copy_len = cipher_get_block_size(ctx); |
| 537 | |
| 538 | memcpy( ctx->unprocessed_data, &( input[ilen - copy_len] ), |
| 539 | copy_len ); |
| 540 | |
| 541 | ctx->unprocessed_len += copy_len; |
| 542 | ilen -= copy_len; |
| 543 | } |
| 544 | |
| 545 | /* |
| 546 | * Process remaining full blocks |
| 547 | */ |
| 548 | if( ilen ) |
| 549 | { |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 550 | #if defined(POLARSSL_GCM_C) |
| 551 | if( ctx->cipher_info->mode == POLARSSL_MODE_GCM ) |
| 552 | { |
| 553 | if( 0 != ( ret = gcm_update( ctx->cipher_ctx, |
| 554 | ilen, input, output ) ) ) |
| 555 | { |
| 556 | return ret; |
| 557 | } |
| 558 | } |
| 559 | else |
| 560 | #endif |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 561 | if( 0 != ( ret = ctx->cipher_info->base->cbc_func( ctx->cipher_ctx, |
| 562 | ctx->operation, ilen, ctx->iv, input, output ) ) ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 563 | { |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 564 | return ret; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 565 | } |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 566 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 567 | *olen += ilen; |
| 568 | } |
| 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 573 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 574 | if( ctx->cipher_info->mode == POLARSSL_MODE_CFB ) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 575 | { |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 576 | if( 0 != ( ret = ctx->cipher_info->base->cfb_func( ctx->cipher_ctx, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 577 | ctx->operation, ilen, &ctx->unprocessed_len, ctx->iv, |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 578 | input, output ) ) ) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 579 | { |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 580 | return ret; |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | *olen = ilen; |
| 584 | |
| 585 | return 0; |
| 586 | } |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 587 | #endif |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 588 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 589 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 590 | if( ctx->cipher_info->mode == POLARSSL_MODE_CTR ) |
| 591 | { |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 592 | if( 0 != ( ret = ctx->cipher_info->base->ctr_func( ctx->cipher_ctx, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 593 | ilen, &ctx->unprocessed_len, ctx->iv, |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 594 | ctx->unprocessed_data, input, output ) ) ) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 595 | { |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 596 | return ret; |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | *olen = ilen; |
| 600 | |
| 601 | return 0; |
| 602 | } |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 603 | #endif |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 604 | |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 605 | #if defined(POLARSSL_CIPHER_MODE_STREAM) |
| 606 | if( ctx->cipher_info->mode == POLARSSL_MODE_STREAM ) |
| 607 | { |
| 608 | if( 0 != ( ret = ctx->cipher_info->base->stream_func( ctx->cipher_ctx, |
| 609 | ilen, input, output ) ) ) |
| 610 | { |
| 611 | return ret; |
| 612 | } |
| 613 | |
| 614 | *olen = ilen; |
| 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | #endif |
| 619 | |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 620 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 623 | #if defined(POLARSSL_CIPHER_PADDING_PKCS7) |
Manuel Pégourié-Gonnard | 679f9e9 | 2013-07-26 12:46:02 +0200 | [diff] [blame] | 624 | /* |
| 625 | * PKCS7 (and PKCS5) padding: fill with ll bytes, with ll = padding_len |
| 626 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 627 | static void add_pkcs_padding( unsigned char *output, size_t output_len, |
| 628 | size_t data_len ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 629 | { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 630 | size_t padding_len = output_len - data_len; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 631 | unsigned char i = 0; |
| 632 | |
| 633 | for( i = 0; i < padding_len; i++ ) |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 634 | output[data_len + i] = (unsigned char) padding_len; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 635 | } |
| 636 | |
Manuel Pégourié-Gonnard | ac56a1a | 2013-07-25 12:31:10 +0200 | [diff] [blame] | 637 | static int get_pkcs_padding( unsigned char *input, size_t input_len, |
| 638 | size_t *data_len ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 639 | { |
Paul Bakker | ec1b984 | 2012-01-14 18:24:43 +0000 | [diff] [blame] | 640 | unsigned int i, padding_len = 0; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 641 | |
Paul Bakker | a885d68 | 2011-01-20 16:35:05 +0000 | [diff] [blame] | 642 | if( NULL == input || NULL == data_len ) |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 643 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 644 | |
| 645 | padding_len = input[input_len - 1]; |
| 646 | |
Manuel Pégourié-Gonnard | b7d24bc | 2013-07-26 10:58:48 +0200 | [diff] [blame] | 647 | if( padding_len > input_len || padding_len == 0 ) |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 648 | return POLARSSL_ERR_CIPHER_INVALID_PADDING; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 649 | |
Paul Bakker | a885d68 | 2011-01-20 16:35:05 +0000 | [diff] [blame] | 650 | for( i = input_len - padding_len; i < input_len; i++ ) |
| 651 | if( input[i] != padding_len ) |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 652 | return POLARSSL_ERR_CIPHER_INVALID_PADDING; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 653 | |
| 654 | *data_len = input_len - padding_len; |
| 655 | |
| 656 | return 0; |
| 657 | } |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 658 | #endif /* POLARSSL_CIPHER_PADDING_PKCS7 */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 659 | |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 660 | #if defined(POLARSSL_CIPHER_PADDING_ONE_AND_ZEROS) |
Manuel Pégourié-Gonnard | 679f9e9 | 2013-07-26 12:46:02 +0200 | [diff] [blame] | 661 | /* |
| 662 | * One and zeros padding: fill with 80 00 ... 00 |
| 663 | */ |
| 664 | static void add_one_and_zeros_padding( unsigned char *output, |
| 665 | size_t output_len, size_t data_len ) |
| 666 | { |
| 667 | size_t padding_len = output_len - data_len; |
| 668 | unsigned char i = 0; |
| 669 | |
| 670 | output[data_len] = 0x80; |
| 671 | for( i = 1; i < padding_len; i++ ) |
| 672 | output[data_len + i] = 0x00; |
| 673 | } |
| 674 | |
| 675 | static int get_one_and_zeros_padding( unsigned char *input, size_t input_len, |
| 676 | size_t *data_len ) |
| 677 | { |
| 678 | unsigned char *p = input + input_len - 1; |
| 679 | |
| 680 | if( NULL == input || NULL == data_len ) |
| 681 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
| 682 | |
| 683 | while( *p == 0x00 && p > input ) |
| 684 | --p; |
| 685 | |
| 686 | if( *p != 0x80 ) |
| 687 | return POLARSSL_ERR_CIPHER_INVALID_PADDING; |
| 688 | |
| 689 | *data_len = p - input; |
| 690 | |
| 691 | return 0; |
| 692 | } |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 693 | #endif /* POLARSSL_CIPHER_PADDING_ONE_AND_ZEROS */ |
Manuel Pégourié-Gonnard | 679f9e9 | 2013-07-26 12:46:02 +0200 | [diff] [blame] | 694 | |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 695 | #if defined(POLARSSL_CIPHER_PADDING_ZEROS_AND_LEN) |
Manuel Pégourié-Gonnard | 8d4291b | 2013-07-26 14:55:18 +0200 | [diff] [blame] | 696 | /* |
| 697 | * Zeros and len padding: fill with 00 ... 00 ll, where ll is padding length |
| 698 | */ |
| 699 | static void add_zeros_and_len_padding( unsigned char *output, |
| 700 | size_t output_len, size_t data_len ) |
| 701 | { |
| 702 | size_t padding_len = output_len - data_len; |
| 703 | unsigned char i = 0; |
| 704 | |
| 705 | for( i = 1; i < padding_len; i++ ) |
| 706 | output[data_len + i - 1] = 0x00; |
| 707 | output[output_len - 1] = (unsigned char) padding_len; |
| 708 | } |
| 709 | |
| 710 | static int get_zeros_and_len_padding( unsigned char *input, size_t input_len, |
| 711 | size_t *data_len ) |
| 712 | { |
| 713 | unsigned int i, padding_len = 0; |
| 714 | |
| 715 | if( NULL == input || NULL == data_len ) |
| 716 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
| 717 | |
| 718 | padding_len = input[input_len - 1]; |
| 719 | |
| 720 | if( padding_len > input_len || padding_len == 0 ) |
| 721 | return POLARSSL_ERR_CIPHER_INVALID_PADDING; |
| 722 | |
| 723 | for( i = input_len - padding_len; i < input_len - 1; i++ ) |
| 724 | if( input[i] != 0x00 ) |
| 725 | return POLARSSL_ERR_CIPHER_INVALID_PADDING; |
| 726 | |
| 727 | *data_len = input_len - padding_len; |
| 728 | |
| 729 | return 0; |
| 730 | } |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 731 | #endif /* POLARSSL_CIPHER_PADDING_ZEROS_AND_LEN */ |
Manuel Pégourié-Gonnard | 8d4291b | 2013-07-26 14:55:18 +0200 | [diff] [blame] | 732 | |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 733 | #if defined(POLARSSL_CIPHER_PADDING_ZEROS) |
Manuel Pégourié-Gonnard | 0e7d2c0 | 2013-07-26 16:05:14 +0200 | [diff] [blame] | 734 | /* |
| 735 | * Zero padding: fill with 00 ... 00 |
| 736 | */ |
| 737 | static void add_zeros_padding( unsigned char *output, |
| 738 | size_t output_len, size_t data_len ) |
| 739 | { |
| 740 | unsigned char i; |
| 741 | |
| 742 | for( i = data_len; i < output_len; i++ ) |
| 743 | output[i] = 0x00; |
| 744 | } |
| 745 | |
| 746 | static int get_zeros_padding( unsigned char *input, size_t input_len, |
| 747 | size_t *data_len ) |
| 748 | { |
| 749 | unsigned char *p = input + input_len - 1; |
| 750 | if( NULL == input || NULL == data_len ) |
| 751 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
| 752 | |
| 753 | while( *p == 0x00 && p > input ) |
| 754 | --p; |
| 755 | |
| 756 | *data_len = *p == 0x00 ? 0 : p - input + 1; |
| 757 | |
| 758 | return 0; |
| 759 | } |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 760 | #endif /* POLARSSL_CIPHER_PADDING_ZEROS */ |
Manuel Pégourié-Gonnard | 0e7d2c0 | 2013-07-26 16:05:14 +0200 | [diff] [blame] | 761 | |
Manuel Pégourié-Gonnard | ebdc413 | 2013-07-26 16:50:44 +0200 | [diff] [blame] | 762 | /* |
| 763 | * No padding: don't pad :) |
| 764 | * |
| 765 | * There is no add_padding function (check for NULL in cipher_finish) |
| 766 | * but a trivial get_padding function |
| 767 | */ |
| 768 | static int get_no_padding( unsigned char *input, size_t input_len, |
| 769 | size_t *data_len ) |
| 770 | { |
| 771 | if( NULL == input || NULL == data_len ) |
| 772 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
| 773 | |
| 774 | *data_len = input_len; |
| 775 | |
| 776 | return 0; |
| 777 | } |
| 778 | |
Manuel Pégourié-Gonnard | 9241be7 | 2013-08-31 17:31:03 +0200 | [diff] [blame] | 779 | int cipher_finish( cipher_context_t *ctx, |
| 780 | unsigned char *output, size_t *olen, |
| 781 | unsigned char *tag, size_t tag_len ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 782 | { |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 783 | int ret = 0; |
| 784 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 785 | if( NULL == ctx || NULL == ctx->cipher_info || NULL == olen ) |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 786 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 787 | |
| 788 | *olen = 0; |
| 789 | |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 790 | if( POLARSSL_MODE_CFB == ctx->cipher_info->mode || |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 791 | POLARSSL_MODE_CTR == ctx->cipher_info->mode || |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 792 | POLARSSL_MODE_STREAM == ctx->cipher_info->mode ) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 793 | { |
| 794 | return 0; |
| 795 | } |
| 796 | |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 797 | #if defined(POLARSSL_GCM_C) |
| 798 | if( POLARSSL_MODE_GCM == ctx->cipher_info->mode ) |
| 799 | { |
Manuel Pégourié-Gonnard | 9241be7 | 2013-08-31 17:31:03 +0200 | [diff] [blame] | 800 | unsigned char check_tag[16]; |
| 801 | size_t i; |
| 802 | int diff; |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 803 | |
| 804 | if( 0 != ( ret = gcm_update( ctx->cipher_ctx, |
| 805 | ctx->unprocessed_len, ctx->unprocessed_data, |
| 806 | output ) ) ) |
| 807 | { |
| 808 | return( ret ); |
| 809 | } |
| 810 | |
| 811 | *olen += ctx->unprocessed_len; |
| 812 | |
Manuel Pégourié-Gonnard | 9241be7 | 2013-08-31 17:31:03 +0200 | [diff] [blame] | 813 | if( 0 != ( ret = gcm_finish( ctx->cipher_ctx, check_tag, tag_len ) ) ) |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 814 | return( ret ); |
| 815 | |
Manuel Pégourié-Gonnard | 9241be7 | 2013-08-31 17:31:03 +0200 | [diff] [blame] | 816 | /* On encryption, write the tag */ |
| 817 | if( POLARSSL_ENCRYPT == ctx->operation ) |
| 818 | { |
| 819 | if( tag_len != 0 ) |
| 820 | memcpy( tag, check_tag, tag_len ); |
| 821 | return( 0 ); |
| 822 | } |
| 823 | |
| 824 | /* On decryption, check the tag (in "constant-time") */ |
| 825 | for( diff = 0, i = 0; i < tag_len; i++ ) |
| 826 | diff |= tag[i] ^ check_tag[i]; |
| 827 | |
| 828 | if( diff != 0 ) |
| 829 | return( POLARSSL_ERR_GCM_AUTH_FAILED ); |
| 830 | |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 831 | return( 0 ); |
| 832 | } |
Manuel Pégourié-Gonnard | 9241be7 | 2013-08-31 17:31:03 +0200 | [diff] [blame] | 833 | #else |
| 834 | ((void) tag); |
| 835 | ((void) tag_len); |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 836 | #endif |
| 837 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 838 | if( POLARSSL_MODE_CBC == ctx->cipher_info->mode ) |
| 839 | { |
| 840 | if( POLARSSL_ENCRYPT == ctx->operation ) |
| 841 | { |
Manuel Pégourié-Gonnard | ebdc413 | 2013-07-26 16:50:44 +0200 | [diff] [blame] | 842 | /* check for 'no padding' mode */ |
| 843 | if( NULL == ctx->add_padding ) |
| 844 | { |
| 845 | if( 0 != ctx->unprocessed_len ) |
| 846 | return POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED; |
| 847 | |
| 848 | return 0; |
| 849 | } |
| 850 | |
Manuel Pégourié-Gonnard | ac56a1a | 2013-07-25 12:31:10 +0200 | [diff] [blame] | 851 | ctx->add_padding( ctx->unprocessed_data, cipher_get_iv_size( ctx ), |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 852 | ctx->unprocessed_len ); |
| 853 | } |
| 854 | else if ( cipher_get_block_size( ctx ) != ctx->unprocessed_len ) |
| 855 | { |
Manuel Pégourié-Gonnard | ebdc413 | 2013-07-26 16:50:44 +0200 | [diff] [blame] | 856 | /* |
| 857 | * For decrypt operations, expect a full block, |
| 858 | * or an empty block if no padding |
| 859 | */ |
| 860 | if( NULL == ctx->add_padding && 0 == ctx->unprocessed_len ) |
| 861 | return 0; |
| 862 | |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 863 | return POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | /* cipher block */ |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 867 | if( 0 != ( ret = ctx->cipher_info->base->cbc_func( ctx->cipher_ctx, |
| 868 | ctx->operation, cipher_get_block_size( ctx ), ctx->iv, |
| 869 | ctx->unprocessed_data, output ) ) ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 870 | { |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 871 | return ret; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | /* Set output size for decryption */ |
| 875 | if( POLARSSL_DECRYPT == ctx->operation ) |
Manuel Pégourié-Gonnard | ac56a1a | 2013-07-25 12:31:10 +0200 | [diff] [blame] | 876 | return ctx->get_padding( output, cipher_get_block_size( ctx ), |
| 877 | olen ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 878 | |
| 879 | /* Set output size for encryption */ |
| 880 | *olen = cipher_get_block_size( ctx ); |
| 881 | return 0; |
| 882 | } |
| 883 | |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 884 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 885 | } |
| 886 | |
Manuel Pégourié-Gonnard | ac56a1a | 2013-07-25 12:31:10 +0200 | [diff] [blame] | 887 | int cipher_set_padding_mode( cipher_context_t *ctx, cipher_padding_t mode ) |
| 888 | { |
| 889 | if( NULL == ctx || |
| 890 | POLARSSL_MODE_CBC != ctx->cipher_info->mode ) |
| 891 | { |
| 892 | return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; |
| 893 | } |
| 894 | |
Paul Bakker | 1a45d91 | 2013-08-14 12:04:26 +0200 | [diff] [blame] | 895 | switch( mode ) |
Manuel Pégourié-Gonnard | ac56a1a | 2013-07-25 12:31:10 +0200 | [diff] [blame] | 896 | { |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 897 | #if defined(POLARSSL_CIPHER_PADDING_PKCS7) |
Paul Bakker | 1a45d91 | 2013-08-14 12:04:26 +0200 | [diff] [blame] | 898 | case POLARSSL_PADDING_PKCS7: |
Manuel Pégourié-Gonnard | ac56a1a | 2013-07-25 12:31:10 +0200 | [diff] [blame] | 899 | ctx->add_padding = add_pkcs_padding; |
| 900 | ctx->get_padding = get_pkcs_padding; |
Paul Bakker | 1a45d91 | 2013-08-14 12:04:26 +0200 | [diff] [blame] | 901 | break; |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 902 | #endif |
| 903 | #if defined(POLARSSL_CIPHER_PADDING_ONE_AND_ZEROS) |
Paul Bakker | 1a45d91 | 2013-08-14 12:04:26 +0200 | [diff] [blame] | 904 | case POLARSSL_PADDING_ONE_AND_ZEROS: |
Manuel Pégourié-Gonnard | 679f9e9 | 2013-07-26 12:46:02 +0200 | [diff] [blame] | 905 | ctx->add_padding = add_one_and_zeros_padding; |
| 906 | ctx->get_padding = get_one_and_zeros_padding; |
Paul Bakker | 1a45d91 | 2013-08-14 12:04:26 +0200 | [diff] [blame] | 907 | break; |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 908 | #endif |
| 909 | #if defined(POLARSSL_CIPHER_PADDING_ZEROS_AND_LEN) |
Paul Bakker | 1a45d91 | 2013-08-14 12:04:26 +0200 | [diff] [blame] | 910 | case POLARSSL_PADDING_ZEROS_AND_LEN: |
Manuel Pégourié-Gonnard | 8d4291b | 2013-07-26 14:55:18 +0200 | [diff] [blame] | 911 | ctx->add_padding = add_zeros_and_len_padding; |
| 912 | ctx->get_padding = get_zeros_and_len_padding; |
Paul Bakker | 1a45d91 | 2013-08-14 12:04:26 +0200 | [diff] [blame] | 913 | break; |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 914 | #endif |
| 915 | #if defined(POLARSSL_CIPHER_PADDING_ZEROS) |
Paul Bakker | 1a45d91 | 2013-08-14 12:04:26 +0200 | [diff] [blame] | 916 | case POLARSSL_PADDING_ZEROS: |
Manuel Pégourié-Gonnard | 0e7d2c0 | 2013-07-26 16:05:14 +0200 | [diff] [blame] | 917 | ctx->add_padding = add_zeros_padding; |
| 918 | ctx->get_padding = get_zeros_padding; |
Paul Bakker | 1a45d91 | 2013-08-14 12:04:26 +0200 | [diff] [blame] | 919 | break; |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 920 | #endif |
Paul Bakker | 1a45d91 | 2013-08-14 12:04:26 +0200 | [diff] [blame] | 921 | case POLARSSL_PADDING_NONE: |
Manuel Pégourié-Gonnard | ebdc413 | 2013-07-26 16:50:44 +0200 | [diff] [blame] | 922 | ctx->add_padding = NULL; |
| 923 | ctx->get_padding = get_no_padding; |
Paul Bakker | 1a45d91 | 2013-08-14 12:04:26 +0200 | [diff] [blame] | 924 | break; |
| 925 | |
| 926 | default: |
Paul Bakker | 48e93c8 | 2013-08-14 12:21:18 +0200 | [diff] [blame] | 927 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
Manuel Pégourié-Gonnard | ebdc413 | 2013-07-26 16:50:44 +0200 | [diff] [blame] | 928 | } |
| 929 | |
Paul Bakker | 1a45d91 | 2013-08-14 12:04:26 +0200 | [diff] [blame] | 930 | return 0; |
Manuel Pégourié-Gonnard | ac56a1a | 2013-07-25 12:31:10 +0200 | [diff] [blame] | 931 | } |
| 932 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 933 | #if defined(POLARSSL_SELF_TEST) |
| 934 | |
| 935 | #include <stdio.h> |
| 936 | |
| 937 | #define ASSERT(x) if (!(x)) { \ |
| 938 | printf( "failed with %i at %s\n", value, (#x) ); \ |
| 939 | return( 1 ); \ |
| 940 | } |
| 941 | /* |
| 942 | * Checkup routine |
| 943 | */ |
| 944 | |
| 945 | int cipher_self_test( int verbose ) |
| 946 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 947 | ((void) verbose); |
| 948 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 949 | return( 0 ); |
| 950 | } |
| 951 | |
| 952 | #endif |
| 953 | |
| 954 | #endif |