Skip to content

Commit 52ed0b9

Browse files
committed
Merge remote-tracking branch 'upstream-public/pr/2101' into development
2 parents d07ef47 + 0fbbc64 commit 52ed0b9

File tree

9 files changed

+48
-23
lines changed

9 files changed

+48
-23
lines changed

include/mbedtls/check_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@
137137
#error "MBEDTLS_ECP_C defined, but not all prerequisites"
138138
#endif
139139

140+
#if defined(MBEDTLS_PK_PARSE_C) && !defined(MBEDTLS_ASN1_PARSE_C)
141+
#error "MBEDTLS_PK_PARSE_C defined, but not all prerequesites"
142+
#endif
143+
140144
#if defined(MBEDTLS_ENTROPY_C) && (!defined(MBEDTLS_SHA512_C) && \
141145
!defined(MBEDTLS_SHA256_C))
142146
#error "MBEDTLS_ENTROPY_C defined, but not all prerequisites"

include/mbedtls/pkcs12.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
extern "C" {
4747
#endif
4848

49+
#if defined(MBEDTLS_ASN1_PARSE_C)
50+
4951
/**
5052
* \brief PKCS12 Password Based function (encryption / decryption)
5153
* for pbeWithSHAAnd128BitRC4
@@ -87,6 +89,8 @@ int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode,
8789
const unsigned char *input, size_t len,
8890
unsigned char *output );
8991

92+
#endif /* MBEDTLS_ASN1_PARSE_C */
93+
9094
/**
9195
* \brief The PKCS#12 derivation function uses a password and a salt
9296
* to produce pseudo-random bits for a particular "purpose".

include/mbedtls/pkcs5.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
extern "C" {
4545
#endif
4646

47+
#if defined(MBEDTLS_ASN1_PARSE_C)
48+
4749
/**
4850
* \brief PKCS#5 PBES2 function
4951
*
@@ -62,6 +64,8 @@ int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode,
6264
const unsigned char *data, size_t datalen,
6365
unsigned char *output );
6466

67+
#endif /* MBEDTLS_ASN1_PARSE_C */
68+
6569
/**
6670
* \brief PKCS#5 PBKDF2 using HMAC
6771
*

library/asn1write.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,36 @@ int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start,
331331
return( (int) len );
332332
}
333333

334-
mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data **head,
334+
335+
/* This is a copy of the ASN.1 parsing function mbedtls_asn1_find_named_data(),
336+
* which is replicated to avoid a dependency ASN1_WRITE_C on ASN1_PARSE_C. */
337+
static mbedtls_asn1_named_data *asn1_find_named_data(
338+
mbedtls_asn1_named_data *list,
339+
const char *oid, size_t len )
340+
{
341+
while( list != NULL )
342+
{
343+
if( list->oid.len == len &&
344+
memcmp( list->oid.p, oid, len ) == 0 )
345+
{
346+
break;
347+
}
348+
349+
list = list->next;
350+
}
351+
352+
return( list );
353+
}
354+
355+
mbedtls_asn1_named_data *mbedtls_asn1_store_named_data(
356+
mbedtls_asn1_named_data **head,
335357
const char *oid, size_t oid_len,
336358
const unsigned char *val,
337359
size_t val_len )
338360
{
339361
mbedtls_asn1_named_data *cur;
340362

341-
if( ( cur = mbedtls_asn1_find_named_data( *head, oid, oid_len ) ) == NULL )
363+
if( ( cur = asn1_find_named_data( *head, oid, oid_len ) ) == NULL )
342364
{
343365
// Add new entry if not present yet based on OID
344366
//

library/pkcs12.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#include "mbedtls/des.h"
4949
#endif
5050

51+
#if defined(MBEDTLS_ASN1_PARSE_C)
52+
5153
static int pkcs12_parse_pbe_params( mbedtls_asn1_buf *params,
5254
mbedtls_asn1_buf *salt, int *iterations )
5355
{
@@ -226,6 +228,8 @@ int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode,
226228
return( ret );
227229
}
228230

231+
#endif /* MBEDTLS_ASN1_PARSE_C */
232+
229233
static void pkcs12_fill_buffer( unsigned char *data, size_t data_len,
230234
const unsigned char *filler, size_t fill_len )
231235
{

library/pkcs5.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,7 @@
5454
#define mbedtls_printf printf
5555
#endif
5656

57-
#if !defined(MBEDTLS_ASN1_PARSE_C)
58-
int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode,
59-
const unsigned char *pwd, size_t pwdlen,
60-
const unsigned char *data, size_t datalen,
61-
unsigned char *output )
62-
{
63-
((void) pbe_params);
64-
((void) mode);
65-
((void) pwd);
66-
((void) pwdlen);
67-
((void) data);
68-
((void) datalen);
69-
((void) output);
70-
return( MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE );
71-
}
72-
#else
57+
#if defined(MBEDTLS_ASN1_PARSE_C)
7358
static int pkcs5_parse_pbkdf2_params( const mbedtls_asn1_buf *params,
7459
mbedtls_asn1_buf *salt, int *iterations,
7560
int *keylen, mbedtls_md_type_t *md_type )

programs/pkey/key_app_writer.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@
8787
USAGE_OUT \
8888
"\n"
8989

90-
#if !defined(MBEDTLS_PK_WRITE_C) || !defined(MBEDTLS_FS_IO)
90+
#if !defined(MBEDTLS_PK_PARSE_C) || \
91+
!defined(MBEDTLS_PK_WRITE_C) || \
92+
!defined(MBEDTLS_FS_IO)
9193
int main( void )
9294
{
93-
mbedtls_printf( "MBEDTLS_PK_WRITE_C and/or MBEDTLS_FS_IO not defined.\n" );
95+
mbedtls_printf( "MBEDTLS_PK_PARSE_C and/or MBEDTLS_PK_WRITE_C and/or MBEDTLS_FS_IO not defined.\n" );
9496
return( 0 );
9597
}
9698
#else
@@ -433,4 +435,4 @@ int main( int argc, char *argv[] )
433435

434436
return( exit_code );
435437
}
436-
#endif /* MBEDTLS_PK_WRITE_C && MBEDTLS_FS_IO */
438+
#endif /* MBEDTLS_PK_PARSE_C && MBEDTLS_PK_WRITE_C && MBEDTLS_FS_IO */

tests/suites/test_suite_asn1write.function

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void mbedtls_asn1_write_ia5_string( char * str, data_t * asn1,
7878
}
7979
/* END_CASE */
8080

81-
/* BEGIN_CASE */
81+
/* BEGIN_CASE depends_on:MBEDTLS_ASN1PARSE_C */
8282
void mbedtls_asn1_write_len( int len, data_t * asn1, int buf_len,
8383
int result )
8484
{

tests/suites/test_suite_pkwrite.function

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/* END_HEADER */
66

77
/* BEGIN_DEPENDENCIES
8-
* depends_on:MBEDTLS_PK_WRITE_C:MBEDTLS_BIGNUM_C:MBEDTLS_FS_IO
8+
* depends_on:MBEDTLS_PK_PARSE_C:MBEDTLS_PK_WRITE_C:MBEDTLS_BIGNUM_C:MBEDTLS_FS_IO
99
* END_DEPENDENCIES
1010
*/
1111

0 commit comments

Comments
 (0)