All CBC ciphersuites via the cipher layer

This commit is contained in:
Paul Bakker 2013-08-31 17:40:26 +02:00
parent da02a7f45e
commit cca5b81d18

View file

@ -642,15 +642,12 @@ int ssl_derive_keys( ssl_context *ssl )
break; break;
#endif #endif
#if defined(POLARSSL_DES_C)
case POLARSSL_CIPHER_DES_EDE3_CBC: case POLARSSL_CIPHER_DES_EDE3_CBC:
des3_set3key_enc( (des3_context *) transform->ctx_enc, key1 ); case POLARSSL_CIPHER_CAMELLIA_128_CBC:
des3_set3key_dec( (des3_context *) transform->ctx_dec, key2 ); case POLARSSL_CIPHER_CAMELLIA_256_CBC:
break;
#endif
case POLARSSL_CIPHER_AES_128_CBC: case POLARSSL_CIPHER_AES_128_CBC:
case POLARSSL_CIPHER_AES_256_CBC: case POLARSSL_CIPHER_AES_256_CBC:
case POLARSSL_CIPHER_DES_CBC:
if( ( ret = cipher_init_ctx( &transform->cipher_ctx_enc, if( ( ret = cipher_init_ctx( &transform->cipher_ctx_enc,
cipher_info ) ) != 0 ) cipher_info ) ) != 0 )
{ {
@ -690,23 +687,6 @@ int ssl_derive_keys( ssl_context *ssl )
} }
break; break;
#if defined(POLARSSL_CAMELLIA_C)
case POLARSSL_CIPHER_CAMELLIA_128_CBC:
case POLARSSL_CIPHER_CAMELLIA_256_CBC:
camellia_setkey_enc( (camellia_context*) transform->ctx_enc, key1,
cipher_info->key_length );
camellia_setkey_dec( (camellia_context*) transform->ctx_dec, key2,
cipher_info->key_length );
break;
#endif
#if defined(POLARSSL_DES_C)
case POLARSSL_CIPHER_DES_CBC:
des_setkey_enc( (des_context *) transform->ctx_enc, key1 );
des_setkey_dec( (des_context *) transform->ctx_dec, key2 );
break;
#endif
#if defined(POLARSSL_GCM_C) #if defined(POLARSSL_GCM_C)
case POLARSSL_CIPHER_AES_128_GCM: case POLARSSL_CIPHER_AES_128_GCM:
case POLARSSL_CIPHER_AES_256_GCM: case POLARSSL_CIPHER_AES_256_GCM:
@ -1083,24 +1063,6 @@ static int ssl_encrypt_buf( ssl_context *ssl )
SSL_DEBUG_BUF( 4, "before encrypt: output payload", SSL_DEBUG_BUF( 4, "before encrypt: output payload",
ssl->out_iv, ssl->out_msglen ); ssl->out_iv, ssl->out_msglen );
switch( ssl->transform_out->ciphersuite_info->cipher )
{
#if defined(POLARSSL_DES_C)
case POLARSSL_CIPHER_DES_CBC:
des_crypt_cbc( (des_context *) ssl->transform_out->ctx_enc,
DES_ENCRYPT, enc_msglen,
ssl->transform_out->iv_enc, enc_msg, enc_msg );
break;
case POLARSSL_CIPHER_DES_EDE3_CBC:
des3_crypt_cbc( (des3_context *) ssl->transform_out->ctx_enc,
DES_ENCRYPT, enc_msglen,
ssl->transform_out->iv_enc, enc_msg, enc_msg );
break;
#endif
case POLARSSL_CIPHER_AES_128_CBC:
case POLARSSL_CIPHER_AES_256_CBC:
if( ( ret = cipher_reset( &ssl->transform_out->cipher_ctx_enc, if( ( ret = cipher_reset( &ssl->transform_out->cipher_ctx_enc,
ssl->transform_out->iv_enc ) ) != 0 ) ssl->transform_out->iv_enc ) ) != 0 )
{ {
@ -1141,20 +1103,6 @@ static int ssl_encrypt_buf( ssl_context *ssl )
ssl->transform_out->ivlen ); ssl->transform_out->ivlen );
} }
#endif #endif
break;
#if defined(POLARSSL_CAMELLIA_C)
case POLARSSL_CIPHER_CAMELLIA_128_CBC:
case POLARSSL_CIPHER_CAMELLIA_256_CBC:
camellia_crypt_cbc( (camellia_context *) ssl->transform_out->ctx_enc,
CAMELLIA_ENCRYPT, enc_msglen,
ssl->transform_out->iv_enc, enc_msg, enc_msg );
break;
#endif
default:
return( POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE );
}
} }
for( i = 8; i > 0; i-- ) for( i = 8; i > 0; i-- )
@ -1307,24 +1255,6 @@ static int ssl_decrypt_buf( ssl_context *ssl )
} }
#endif /* POLARSSL_SSL_PROTO_TLS1_1 || POLARSSL_SSL_PROTO_TLS1_2 */ #endif /* POLARSSL_SSL_PROTO_TLS1_1 || POLARSSL_SSL_PROTO_TLS1_2 */
switch( ssl->transform_in->ciphersuite_info->cipher )
{
#if defined(POLARSSL_DES_C)
case POLARSSL_CIPHER_DES_CBC:
des_crypt_cbc( (des_context *) ssl->transform_in->ctx_dec,
DES_DECRYPT, dec_msglen,
ssl->transform_in->iv_dec, dec_msg, dec_msg_result );
break;
case POLARSSL_CIPHER_DES_EDE3_CBC:
des3_crypt_cbc( (des3_context *) ssl->transform_in->ctx_dec,
DES_DECRYPT, dec_msglen,
ssl->transform_in->iv_dec, dec_msg, dec_msg_result );
break;
#endif
case POLARSSL_CIPHER_AES_128_CBC:
case POLARSSL_CIPHER_AES_256_CBC:
if( ( ret = cipher_reset( &ssl->transform_in->cipher_ctx_dec, if( ( ret = cipher_reset( &ssl->transform_in->cipher_ctx_dec,
ssl->transform_in->iv_dec ) ) != 0 ) ssl->transform_in->iv_dec ) ) != 0 )
{ {
@ -1363,20 +1293,6 @@ static int ssl_decrypt_buf( ssl_context *ssl )
ssl->transform_in->ivlen ); ssl->transform_in->ivlen );
} }
#endif #endif
break;
#if defined(POLARSSL_CAMELLIA_C)
case POLARSSL_CIPHER_CAMELLIA_128_CBC:
case POLARSSL_CIPHER_CAMELLIA_256_CBC:
camellia_crypt_cbc( (camellia_context *) ssl->transform_in->ctx_dec,
CAMELLIA_DECRYPT, dec_msglen,
ssl->transform_in->iv_dec, dec_msg, dec_msg_result );
break;
#endif
default:
return( POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE );
}
padlen = 1 + ssl->in_msg[ssl->in_msglen - 1]; padlen = 1 + ssl->in_msg[ssl->in_msglen - 1];