mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-22 00:40:41 +00:00
pem.c: add internal macro to increase code readability
*** Comparing before-default -> after-default *** x509parse: total 723; skipped 26 -> 26 x509write: total 41; skipped 8 -> 8 pem: total 13; skipped 0 -> 0 oid: total 28; skipped 0 -> 0 *** Comparing before-full -> after-full *** x509parse: total 723; skipped 25 -> 25 x509write: total 41; skipped 0 -> 0 pem: total 13; skipped 0 -> 0 oid: total 28; skipped 0 -> 0 *** Comparing reference -> drivers *** x509parse: total 723; skipped 89 -> 89 x509write: total 41; skipped 3 -> 3 pem: total 13; skipped 0 -> 0 oid: total 28; skipped 0 -> 0 Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
parent
bc0509a36b
commit
4092ff9ba9
@ -46,14 +46,19 @@
|
|||||||
|
|
||||||
#include "legacy_or_psa.h"
|
#include "legacy_or_psa.h"
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_HAS_ALG_MD5_VIA_MD_OR_PSA_BASED_ON_USE_PSA) && defined(MBEDTLS_CIPHER_MODE_CBC) && \
|
||||||
|
( defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) )
|
||||||
|
#define PEM_RFC1421
|
||||||
|
#endif /* MBEDTLS_HAS_ALG_MD5_VIA_MD_OR_PSA_BASED_ON_USE_PSA && MBEDTLS_CIPHER_MODE_CBC &&
|
||||||
|
( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
|
||||||
|
|
||||||
#if defined(MBEDTLS_PEM_PARSE_C)
|
#if defined(MBEDTLS_PEM_PARSE_C)
|
||||||
void mbedtls_pem_init( mbedtls_pem_context *ctx )
|
void mbedtls_pem_init( mbedtls_pem_context *ctx )
|
||||||
{
|
{
|
||||||
memset( ctx, 0, sizeof( mbedtls_pem_context ) );
|
memset( ctx, 0, sizeof( mbedtls_pem_context ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_HAS_ALG_MD5_VIA_MD_OR_PSA_BASED_ON_USE_PSA) && defined(MBEDTLS_CIPHER_MODE_CBC) && \
|
#if defined(PEM_RFC1421 )
|
||||||
( defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) )
|
|
||||||
/*
|
/*
|
||||||
* Read a 16-byte hex string and convert it to binary
|
* Read a 16-byte hex string and convert it to binary
|
||||||
*/
|
*/
|
||||||
@ -340,8 +345,7 @@ exit:
|
|||||||
}
|
}
|
||||||
#endif /* MBEDTLS_AES_C */
|
#endif /* MBEDTLS_AES_C */
|
||||||
|
|
||||||
#endif /* MBEDTLS_HAS_ALG_MD5_VIA_MD_OR_PSA_BASED_ON_USE_PSA && MBEDTLS_CIPHER_MODE_CBC &&
|
#endif /* PEM_RFC1421 */
|
||||||
( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
|
|
||||||
|
|
||||||
int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const char *footer,
|
int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const char *footer,
|
||||||
const unsigned char *data, const unsigned char *pwd,
|
const unsigned char *data, const unsigned char *pwd,
|
||||||
@ -351,15 +355,13 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
|||||||
size_t len;
|
size_t len;
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
const unsigned char *s1, *s2, *end;
|
const unsigned char *s1, *s2, *end;
|
||||||
#if defined(MBEDTLS_HAS_ALG_MD5_VIA_MD_OR_PSA_BASED_ON_USE_PSA) && defined(MBEDTLS_CIPHER_MODE_CBC) && \
|
#if defined(PEM_RFC1421 )
|
||||||
( defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) )
|
|
||||||
unsigned char pem_iv[16];
|
unsigned char pem_iv[16];
|
||||||
mbedtls_cipher_type_t enc_alg = MBEDTLS_CIPHER_NONE;
|
mbedtls_cipher_type_t enc_alg = MBEDTLS_CIPHER_NONE;
|
||||||
#else
|
#else
|
||||||
((void) pwd);
|
((void) pwd);
|
||||||
((void) pwdlen);
|
((void) pwdlen);
|
||||||
#endif /* MBEDTLS_HAS_ALG_MD5_VIA_MD_OR_PSA_BASED_ON_USE_PSA && MBEDTLS_CIPHER_MODE_CBC &&
|
#endif /* PEM_RFC1421 */
|
||||||
( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
|
|
||||||
|
|
||||||
if( ctx == NULL )
|
if( ctx == NULL )
|
||||||
return( MBEDTLS_ERR_PEM_BAD_INPUT_DATA );
|
return( MBEDTLS_ERR_PEM_BAD_INPUT_DATA );
|
||||||
@ -391,8 +393,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
|||||||
|
|
||||||
if( s2 - s1 >= 22 && memcmp( s1, "Proc-Type: 4,ENCRYPTED", 22 ) == 0 )
|
if( s2 - s1 >= 22 && memcmp( s1, "Proc-Type: 4,ENCRYPTED", 22 ) == 0 )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_HAS_ALG_MD5_VIA_MD_OR_PSA_BASED_ON_USE_PSA) && defined(MBEDTLS_CIPHER_MODE_CBC) && \
|
#if defined(PEM_RFC1421 )
|
||||||
( defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) )
|
|
||||||
enc++;
|
enc++;
|
||||||
|
|
||||||
s1 += 22;
|
s1 += 22;
|
||||||
@ -454,8 +455,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
|||||||
else return( MBEDTLS_ERR_PEM_INVALID_DATA );
|
else return( MBEDTLS_ERR_PEM_INVALID_DATA );
|
||||||
#else
|
#else
|
||||||
return( MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE );
|
return( MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE );
|
||||||
#endif /* MBEDTLS_HAS_ALG_MD5_VIA_MD_OR_PSA_BASED_ON_USE_PSA && MBEDTLS_CIPHER_MODE_CBC &&
|
#endif /* PEM_RFC1421 */
|
||||||
( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( s1 >= s2 )
|
if( s1 >= s2 )
|
||||||
@ -478,8 +478,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
|||||||
|
|
||||||
if( enc != 0 )
|
if( enc != 0 )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_HAS_ALG_MD5_VIA_MD_OR_PSA_BASED_ON_USE_PSA) && defined(MBEDTLS_CIPHER_MODE_CBC) && \
|
#if defined(PEM_RFC1421 )
|
||||||
( defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) )
|
|
||||||
if( pwd == NULL )
|
if( pwd == NULL )
|
||||||
{
|
{
|
||||||
mbedtls_platform_zeroize( buf, len );
|
mbedtls_platform_zeroize( buf, len );
|
||||||
@ -527,8 +526,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
|||||||
mbedtls_platform_zeroize( buf, len );
|
mbedtls_platform_zeroize( buf, len );
|
||||||
mbedtls_free( buf );
|
mbedtls_free( buf );
|
||||||
return( MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE );
|
return( MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE );
|
||||||
#endif /* MBEDTLS_HAS_ALG_MD5_VIA_MD_OR_PSA_BASED_ON_USE_PSA && MBEDTLS_CIPHER_MODE_CBC &&
|
#endif /* PEM_RFC1421 */
|
||||||
( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->buf = buf;
|
ctx->buf = buf;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user