PolarSSL v1.1.4
|
00001 00030 #include "polarssl/config.h" 00031 00032 #if defined(POLARSSL_CIPHER_C) 00033 00034 #include "polarssl/cipher_wrap.h" 00035 #include "polarssl/aes.h" 00036 #include "polarssl/camellia.h" 00037 #include "polarssl/des.h" 00038 00039 #include <stdlib.h> 00040 00041 #if defined(POLARSSL_AES_C) 00042 00043 int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, 00044 unsigned char *iv, const unsigned char *input, unsigned char *output ) 00045 { 00046 return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input, output ); 00047 } 00048 00049 int aes_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length, 00050 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output ) 00051 { 00052 #if defined(POLARSSL_CIPHER_MODE_CFB) 00053 return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv, input, output ); 00054 #else 00055 ((void) ctx); 00056 ((void) operation); 00057 ((void) length); 00058 ((void) iv_off); 00059 ((void) iv); 00060 ((void) input); 00061 ((void) output); 00062 00063 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; 00064 #endif 00065 } 00066 00067 int aes_crypt_ctr_wrap( void *ctx, size_t length, 00068 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block, 00069 const unsigned char *input, unsigned char *output ) 00070 { 00071 #if defined(POLARSSL_CIPHER_MODE_CTR) 00072 return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter, 00073 stream_block, input, output ); 00074 #else 00075 ((void) ctx); 00076 ((void) length); 00077 ((void) nc_off); 00078 ((void) nonce_counter); 00079 ((void) stream_block); 00080 ((void) input); 00081 ((void) output); 00082 00083 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; 00084 #endif 00085 } 00086 00087 int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 00088 { 00089 return aes_setkey_dec( (aes_context *) ctx, key, key_length ); 00090 } 00091 00092 int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 00093 { 00094 return aes_setkey_enc( (aes_context *) ctx, key, key_length ); 00095 } 00096 00097 static void * aes_ctx_alloc( void ) 00098 { 00099 return malloc( sizeof( aes_context ) ); 00100 } 00101 00102 static void aes_ctx_free( void *ctx ) 00103 { 00104 free( ctx ); 00105 } 00106 00107 const cipher_base_t aes_info = { 00108 POLARSSL_CIPHER_ID_AES, 00109 aes_crypt_cbc_wrap, 00110 aes_crypt_cfb128_wrap, 00111 aes_crypt_ctr_wrap, 00112 aes_setkey_enc_wrap, 00113 aes_setkey_dec_wrap, 00114 aes_ctx_alloc, 00115 aes_ctx_free 00116 }; 00117 00118 const cipher_info_t aes_128_cbc_info = { 00119 POLARSSL_CIPHER_AES_128_CBC, 00120 POLARSSL_MODE_CBC, 00121 128, 00122 "AES-128-CBC", 00123 16, 00124 16, 00125 &aes_info 00126 }; 00127 00128 const cipher_info_t aes_192_cbc_info = { 00129 POLARSSL_CIPHER_AES_192_CBC, 00130 POLARSSL_MODE_CBC, 00131 192, 00132 "AES-192-CBC", 00133 16, 00134 16, 00135 &aes_info 00136 }; 00137 00138 const cipher_info_t aes_256_cbc_info = { 00139 POLARSSL_CIPHER_AES_256_CBC, 00140 POLARSSL_MODE_CBC, 00141 256, 00142 "AES-256-CBC", 00143 16, 00144 16, 00145 &aes_info 00146 }; 00147 00148 #if defined(POLARSSL_CIPHER_MODE_CFB) 00149 const cipher_info_t aes_128_cfb128_info = { 00150 POLARSSL_CIPHER_AES_128_CFB128, 00151 POLARSSL_MODE_CFB128, 00152 128, 00153 "AES-128-CFB128", 00154 16, 00155 16, 00156 &aes_info 00157 }; 00158 00159 const cipher_info_t aes_192_cfb128_info = { 00160 POLARSSL_CIPHER_AES_192_CFB128, 00161 POLARSSL_MODE_CFB128, 00162 192, 00163 "AES-192-CFB128", 00164 16, 00165 16, 00166 &aes_info 00167 }; 00168 00169 const cipher_info_t aes_256_cfb128_info = { 00170 POLARSSL_CIPHER_AES_256_CFB128, 00171 POLARSSL_MODE_CFB128, 00172 256, 00173 "AES-256-CFB128", 00174 16, 00175 16, 00176 &aes_info 00177 }; 00178 #endif /* POLARSSL_CIPHER_MODE_CFB */ 00179 00180 #if defined(POLARSSL_CIPHER_MODE_CTR) 00181 const cipher_info_t aes_128_ctr_info = { 00182 POLARSSL_CIPHER_AES_128_CTR, 00183 POLARSSL_MODE_CTR, 00184 128, 00185 "AES-128-CTR", 00186 16, 00187 16, 00188 &aes_info 00189 }; 00190 00191 const cipher_info_t aes_192_ctr_info = { 00192 POLARSSL_CIPHER_AES_192_CTR, 00193 POLARSSL_MODE_CTR, 00194 192, 00195 "AES-192-CTR", 00196 16, 00197 16, 00198 &aes_info 00199 }; 00200 00201 const cipher_info_t aes_256_ctr_info = { 00202 POLARSSL_CIPHER_AES_256_CTR, 00203 POLARSSL_MODE_CTR, 00204 256, 00205 "AES-256-CTR", 00206 16, 00207 16, 00208 &aes_info 00209 }; 00210 #endif /* POLARSSL_CIPHER_MODE_CTR */ 00211 00212 #endif 00213 00214 #if defined(POLARSSL_CAMELLIA_C) 00215 00216 int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, 00217 unsigned char *iv, const unsigned char *input, unsigned char *output ) 00218 { 00219 return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, input, output ); 00220 } 00221 00222 int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length, 00223 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output ) 00224 { 00225 #if defined(POLARSSL_CIPHER_MODE_CFB) 00226 return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, iv_off, iv, input, output ); 00227 #else 00228 ((void) ctx); 00229 ((void) operation); 00230 ((void) length); 00231 ((void) iv_off); 00232 ((void) iv); 00233 ((void) input); 00234 ((void) output); 00235 00236 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; 00237 #endif 00238 } 00239 00240 int camellia_crypt_ctr_wrap( void *ctx, size_t length, 00241 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block, 00242 const unsigned char *input, unsigned char *output ) 00243 { 00244 #if defined(POLARSSL_CIPHER_MODE_CTR) 00245 return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, nonce_counter, 00246 stream_block, input, output ); 00247 #else 00248 ((void) ctx); 00249 ((void) length); 00250 ((void) nc_off); 00251 ((void) nonce_counter); 00252 ((void) stream_block); 00253 ((void) input); 00254 ((void) output); 00255 00256 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; 00257 #endif 00258 } 00259 00260 int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 00261 { 00262 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length ); 00263 } 00264 00265 int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 00266 { 00267 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length ); 00268 } 00269 00270 static void * camellia_ctx_alloc( void ) 00271 { 00272 return malloc( sizeof( camellia_context ) ); 00273 } 00274 00275 static void camellia_ctx_free( void *ctx ) 00276 { 00277 free( ctx ); 00278 } 00279 00280 const cipher_base_t camellia_info = { 00281 POLARSSL_CIPHER_ID_CAMELLIA, 00282 camellia_crypt_cbc_wrap, 00283 camellia_crypt_cfb128_wrap, 00284 camellia_crypt_ctr_wrap, 00285 camellia_setkey_enc_wrap, 00286 camellia_setkey_dec_wrap, 00287 camellia_ctx_alloc, 00288 camellia_ctx_free 00289 }; 00290 00291 const cipher_info_t camellia_128_cbc_info = { 00292 POLARSSL_CIPHER_CAMELLIA_128_CBC, 00293 POLARSSL_MODE_CBC, 00294 128, 00295 "CAMELLIA-128-CBC", 00296 16, 00297 16, 00298 &camellia_info 00299 }; 00300 00301 const cipher_info_t camellia_192_cbc_info = { 00302 POLARSSL_CIPHER_CAMELLIA_192_CBC, 00303 POLARSSL_MODE_CBC, 00304 192, 00305 "CAMELLIA-192-CBC", 00306 16, 00307 16, 00308 &camellia_info 00309 }; 00310 00311 const cipher_info_t camellia_256_cbc_info = { 00312 POLARSSL_CIPHER_CAMELLIA_256_CBC, 00313 POLARSSL_MODE_CBC, 00314 256, 00315 "CAMELLIA-256-CBC", 00316 16, 00317 16, 00318 &camellia_info 00319 }; 00320 00321 #if defined(POLARSSL_CIPHER_MODE_CFB) 00322 const cipher_info_t camellia_128_cfb128_info = { 00323 POLARSSL_CIPHER_CAMELLIA_128_CFB128, 00324 POLARSSL_MODE_CFB128, 00325 128, 00326 "CAMELLIA-128-CFB128", 00327 16, 00328 16, 00329 &camellia_info 00330 }; 00331 00332 const cipher_info_t camellia_192_cfb128_info = { 00333 POLARSSL_CIPHER_CAMELLIA_192_CFB128, 00334 POLARSSL_MODE_CFB128, 00335 192, 00336 "CAMELLIA-192-CFB128", 00337 16, 00338 16, 00339 &camellia_info 00340 }; 00341 00342 const cipher_info_t camellia_256_cfb128_info = { 00343 POLARSSL_CIPHER_CAMELLIA_256_CFB128, 00344 POLARSSL_MODE_CFB128, 00345 256, 00346 "CAMELLIA-256-CFB128", 00347 16, 00348 16, 00349 &camellia_info 00350 }; 00351 #endif /* POLARSSL_CIPHER_MODE_CFB */ 00352 00353 #if defined(POLARSSL_CIPHER_MODE_CTR) 00354 const cipher_info_t camellia_128_ctr_info = { 00355 POLARSSL_CIPHER_CAMELLIA_128_CTR, 00356 POLARSSL_MODE_CTR, 00357 128, 00358 "CAMELLIA-128-CTR", 00359 16, 00360 16, 00361 &camellia_info 00362 }; 00363 00364 const cipher_info_t camellia_192_ctr_info = { 00365 POLARSSL_CIPHER_CAMELLIA_192_CTR, 00366 POLARSSL_MODE_CTR, 00367 192, 00368 "CAMELLIA-192-CTR", 00369 16, 00370 16, 00371 &camellia_info 00372 }; 00373 00374 const cipher_info_t camellia_256_ctr_info = { 00375 POLARSSL_CIPHER_CAMELLIA_256_CTR, 00376 POLARSSL_MODE_CTR, 00377 256, 00378 "CAMELLIA-256-CTR", 00379 16, 00380 16, 00381 &camellia_info 00382 }; 00383 #endif /* POLARSSL_CIPHER_MODE_CTR */ 00384 00385 #endif 00386 00387 #if defined(POLARSSL_DES_C) 00388 00389 int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, 00390 unsigned char *iv, const unsigned char *input, unsigned char *output ) 00391 { 00392 return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, output ); 00393 } 00394 00395 int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, 00396 unsigned char *iv, const unsigned char *input, unsigned char *output ) 00397 { 00398 return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, output ); 00399 } 00400 00401 int des_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length, 00402 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output ) 00403 { 00404 ((void) ctx); 00405 ((void) operation); 00406 ((void) length); 00407 ((void) iv_off); 00408 ((void) iv); 00409 ((void) input); 00410 ((void) output); 00411 00412 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; 00413 } 00414 00415 int des_crypt_ctr_wrap( void *ctx, size_t length, 00416 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block, 00417 const unsigned char *input, unsigned char *output ) 00418 { 00419 ((void) ctx); 00420 ((void) length); 00421 ((void) nc_off); 00422 ((void) nonce_counter); 00423 ((void) stream_block); 00424 ((void) input); 00425 ((void) output); 00426 00427 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; 00428 } 00429 00430 00431 int des_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 00432 { 00433 ((void) key_length); 00434 00435 return des_setkey_dec( (des_context *) ctx, key ); 00436 } 00437 00438 int des_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 00439 { 00440 ((void) key_length); 00441 00442 return des_setkey_enc( (des_context *) ctx, key ); 00443 } 00444 00445 int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 00446 { 00447 ((void) key_length); 00448 00449 return des3_set2key_dec( (des3_context *) ctx, key ); 00450 } 00451 00452 int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 00453 { 00454 ((void) key_length); 00455 00456 return des3_set2key_enc( (des3_context *) ctx, key ); 00457 } 00458 00459 int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 00460 { 00461 ((void) key_length); 00462 00463 return des3_set3key_dec( (des3_context *) ctx, key ); 00464 } 00465 00466 int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 00467 { 00468 ((void) key_length); 00469 00470 return des3_set3key_enc( (des3_context *) ctx, key ); 00471 } 00472 00473 static void * des_ctx_alloc( void ) 00474 { 00475 return malloc( sizeof( des_context ) ); 00476 } 00477 00478 static void * des3_ctx_alloc( void ) 00479 { 00480 return malloc( sizeof( des3_context ) ); 00481 } 00482 00483 static void des_ctx_free( void *ctx ) 00484 { 00485 free( ctx ); 00486 } 00487 00488 const cipher_base_t des_info = { 00489 POLARSSL_CIPHER_ID_DES, 00490 des_crypt_cbc_wrap, 00491 des_crypt_cfb128_wrap, 00492 des_crypt_ctr_wrap, 00493 des_setkey_enc_wrap, 00494 des_setkey_dec_wrap, 00495 des_ctx_alloc, 00496 des_ctx_free 00497 }; 00498 00499 const cipher_info_t des_cbc_info = { 00500 POLARSSL_CIPHER_DES_CBC, 00501 POLARSSL_MODE_CBC, 00502 POLARSSL_KEY_LENGTH_DES, 00503 "DES-CBC", 00504 8, 00505 8, 00506 &des_info 00507 }; 00508 00509 const cipher_base_t des_ede_info = { 00510 POLARSSL_CIPHER_ID_DES, 00511 des3_crypt_cbc_wrap, 00512 des_crypt_cfb128_wrap, 00513 des_crypt_ctr_wrap, 00514 des3_set2key_enc_wrap, 00515 des3_set2key_dec_wrap, 00516 des3_ctx_alloc, 00517 des_ctx_free 00518 }; 00519 00520 const cipher_info_t des_ede_cbc_info = { 00521 POLARSSL_CIPHER_DES_EDE_CBC, 00522 POLARSSL_MODE_CBC, 00523 POLARSSL_KEY_LENGTH_DES_EDE, 00524 "DES-EDE-CBC", 00525 16, 00526 16, 00527 &des_ede_info 00528 }; 00529 00530 const cipher_base_t des_ede3_info = { 00531 POLARSSL_CIPHER_ID_DES, 00532 des3_crypt_cbc_wrap, 00533 des_crypt_cfb128_wrap, 00534 des_crypt_ctr_wrap, 00535 des3_set3key_enc_wrap, 00536 des3_set3key_dec_wrap, 00537 des3_ctx_alloc, 00538 des_ctx_free 00539 }; 00540 00541 const cipher_info_t des_ede3_cbc_info = { 00542 POLARSSL_CIPHER_DES_EDE3_CBC, 00543 POLARSSL_MODE_CBC, 00544 POLARSSL_KEY_LENGTH_DES_EDE3, 00545 "DES-EDE3-CBC", 00546 8, 00547 8, 00548 &des_ede3_info 00549 }; 00550 #endif 00551 00552 #endif