mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 21:15:38 +01:00
Made padding modes configurable from config.h
This commit is contained in:
parent
1a45d91cf2
commit
48e93c84b7
@ -193,6 +193,21 @@
|
|||||||
#define POLARSSL_CIPHER_NULL_CIPHER
|
#define POLARSSL_CIPHER_NULL_CIPHER
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \def POLARSSL_CIPHER_PADDING_XXX
|
||||||
|
*
|
||||||
|
* Uncomment or comment macros to add support for specific padding modes
|
||||||
|
* in the cipher layer with cipher modes that support padding (e.g. CBC)
|
||||||
|
*
|
||||||
|
* If you disable all padding modes, only full blocks can be used with CBC.
|
||||||
|
*
|
||||||
|
* Enable padding modes in the cipher layer.
|
||||||
|
*/
|
||||||
|
#define POLARSSL_CIPHER_PADDING_PKCS7
|
||||||
|
#define POLARSSL_CIPHER_PADDING_ONE_AND_ZEROS
|
||||||
|
#define POLARSSL_CIPHER_PADDING_ZEROS_AND_LEN
|
||||||
|
#define POLARSSL_CIPHER_PADDING_ZEROS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \def POLARSSL_ENABLE_WEAK_CIPHERSUITES
|
* \def POLARSSL_ENABLE_WEAK_CIPHERSUITES
|
||||||
*
|
*
|
||||||
|
@ -326,7 +326,11 @@ int cipher_init_ctx( cipher_context_t *ctx, const cipher_info_t *cipher_info )
|
|||||||
/*
|
/*
|
||||||
* Ignore possible errors caused by a cipher mode that doesn't use padding
|
* Ignore possible errors caused by a cipher mode that doesn't use padding
|
||||||
*/
|
*/
|
||||||
|
#if defined(POLARSSL_CIPHER_PADDING_PKCS7)
|
||||||
(void) cipher_set_padding_mode( ctx, POLARSSL_PADDING_PKCS7 );
|
(void) cipher_set_padding_mode( ctx, POLARSSL_PADDING_PKCS7 );
|
||||||
|
#else
|
||||||
|
(void) cipher_set_padding_mode( ctx, POLARSSL_PADDING_NONE );
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -526,6 +530,7 @@ int cipher_update( cipher_context_t *ctx, const unsigned char *input, size_t ile
|
|||||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(POLARSSL_CIPHER_PADDING_PKCS7)
|
||||||
/*
|
/*
|
||||||
* PKCS7 (and PKCS5) padding: fill with ll bytes, with ll = padding_len
|
* PKCS7 (and PKCS5) padding: fill with ll bytes, with ll = padding_len
|
||||||
*/
|
*/
|
||||||
@ -560,7 +565,9 @@ static int get_pkcs_padding( unsigned char *input, size_t input_len,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif /* POLARSSL_CIPHER_PADDING_PKCS7 */
|
||||||
|
|
||||||
|
#if defined(POLARSSL_CIPHER_PADDING_ONE_AND_ZEROS)
|
||||||
/*
|
/*
|
||||||
* One and zeros padding: fill with 80 00 ... 00
|
* One and zeros padding: fill with 80 00 ... 00
|
||||||
*/
|
*/
|
||||||
@ -593,7 +600,9 @@ static int get_one_and_zeros_padding( unsigned char *input, size_t input_len,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif /* POLARSSL_CIPHER_PADDING_ONE_AND_ZEROS */
|
||||||
|
|
||||||
|
#if defined(POLARSSL_CIPHER_PADDING_ZEROS_AND_LEN)
|
||||||
/*
|
/*
|
||||||
* Zeros and len padding: fill with 00 ... 00 ll, where ll is padding length
|
* Zeros and len padding: fill with 00 ... 00 ll, where ll is padding length
|
||||||
*/
|
*/
|
||||||
@ -629,7 +638,9 @@ static int get_zeros_and_len_padding( unsigned char *input, size_t input_len,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif /* POLARSSL_CIPHER_PADDING_ZEROS_AND_LEN */
|
||||||
|
|
||||||
|
#if defined(POLARSSL_CIPHER_PADDING_ZEROS)
|
||||||
/*
|
/*
|
||||||
* Zero padding: fill with 00 ... 00
|
* Zero padding: fill with 00 ... 00
|
||||||
*/
|
*/
|
||||||
@ -656,6 +667,7 @@ static int get_zeros_padding( unsigned char *input, size_t input_len,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif /* POLARSSL_CIPHER_PADDING_ZEROS */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* No padding: don't pad :)
|
* No padding: don't pad :)
|
||||||
@ -749,33 +761,37 @@ int cipher_set_padding_mode( cipher_context_t *ctx, cipher_padding_t mode )
|
|||||||
|
|
||||||
switch( mode )
|
switch( mode )
|
||||||
{
|
{
|
||||||
|
#if defined(POLARSSL_CIPHER_PADDING_PKCS7)
|
||||||
case POLARSSL_PADDING_PKCS7:
|
case POLARSSL_PADDING_PKCS7:
|
||||||
ctx->add_padding = add_pkcs_padding;
|
ctx->add_padding = add_pkcs_padding;
|
||||||
ctx->get_padding = get_pkcs_padding;
|
ctx->get_padding = get_pkcs_padding;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#if defined(POLARSSL_CIPHER_PADDING_ONE_AND_ZEROS)
|
||||||
case POLARSSL_PADDING_ONE_AND_ZEROS:
|
case POLARSSL_PADDING_ONE_AND_ZEROS:
|
||||||
ctx->add_padding = add_one_and_zeros_padding;
|
ctx->add_padding = add_one_and_zeros_padding;
|
||||||
ctx->get_padding = get_one_and_zeros_padding;
|
ctx->get_padding = get_one_and_zeros_padding;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#if defined(POLARSSL_CIPHER_PADDING_ZEROS_AND_LEN)
|
||||||
case POLARSSL_PADDING_ZEROS_AND_LEN:
|
case POLARSSL_PADDING_ZEROS_AND_LEN:
|
||||||
ctx->add_padding = add_zeros_and_len_padding;
|
ctx->add_padding = add_zeros_and_len_padding;
|
||||||
ctx->get_padding = get_zeros_and_len_padding;
|
ctx->get_padding = get_zeros_and_len_padding;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#if defined(POLARSSL_CIPHER_PADDING_ZEROS)
|
||||||
case POLARSSL_PADDING_ZEROS:
|
case POLARSSL_PADDING_ZEROS:
|
||||||
ctx->add_padding = add_zeros_padding;
|
ctx->add_padding = add_zeros_padding;
|
||||||
ctx->get_padding = get_zeros_padding;
|
ctx->get_padding = get_zeros_padding;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case POLARSSL_PADDING_NONE:
|
case POLARSSL_PADDING_NONE:
|
||||||
ctx->add_padding = NULL;
|
ctx->add_padding = NULL;
|
||||||
ctx->get_padding = get_no_padding;
|
ctx->get_padding = get_no_padding;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
|
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user