Skip to content

Commit d47269d

Browse files
Ron EldorRon Eldor
Ron Eldor
authored and
Ron Eldor
committed
Change mbedtls_platform_context parameter to NULL
`mbedtls_platform_setup()` and `mbedtls_platform_teardown()` now ignore the context parameter, since #mbed-os/7099 was merged. Changing the sent parameter to NULL, to avoid misleading.
1 parent 51ab191 commit d47269d

File tree

8 files changed

+28
-71
lines changed

8 files changed

+28
-71
lines changed

authcrypt/authcrypt.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ const char Authcrypt::message[] = "Some things are better left unread";
3939

4040
const char Authcrypt::metadata[] = "eg sequence number, routing info";
4141

42-
Authcrypt::Authcrypt(mbedtls_platform_context* platform_ctx)
42+
Authcrypt::Authcrypt()
4343
{
44-
// The platform context can be used by cryptographic calls which require it.
45-
// Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more information.
46-
_platform_ctx = platform_ctx;
4744
memset(ciphertext, 0, sizeof(ciphertext));
4845
memset(decrypted, 0, sizeof(decrypted));
4946

authcrypt/authcrypt.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Authcrypt
3535
/**
3636
* Construct an Authcrypt instance
3737
*/
38-
Authcrypt(mbedtls_platform_context* platform_ctx);
38+
Authcrypt();
3939

4040
/**
4141
* Free any allocated resources
@@ -104,11 +104,6 @@ class Authcrypt
104104
* The block cipher configuration
105105
*/
106106
mbedtls_cipher_context_t cipher;
107-
108-
/**
109-
* The platform context
110-
*/
111-
mbedtls_platform_context* _platform_ctx;
112107
};
113108

114109
#endif /* _AUTHCRYPT_H_ */

authcrypt/main.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@
2424
#include "mbedtls/platform.h"
2525

2626
int main() {
27-
mbedtls_platform_context platform_ctx;
2827
int exit_code = MBEDTLS_EXIT_FAILURE;
2928

30-
if((exit_code = mbedtls_platform_setup(&platform_ctx)) != 0) {
29+
if((exit_code = mbedtls_platform_setup(NULL)) != 0) {
3130
printf("Platform initialization failed with error %d\n", exit_code);
3231
return MBEDTLS_EXIT_FAILURE;
3332
}
3433

35-
Authcrypt *authcrypt = new Authcrypt(&platform_ctx);
34+
Authcrypt *authcrypt = new Authcrypt();
3635

3736
if ((exit_code = authcrypt->run()) != 0) {
3837
mbedtls_printf("Example failed with error %d\n", exit_code);
@@ -41,6 +40,6 @@ int main() {
4140

4241
delete authcrypt;
4342

44-
mbedtls_platform_teardown(&platform_ctx);
43+
mbedtls_platform_teardown(NULL);
4544
return exit_code;
4645
}

benchmark/main.cpp

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,9 @@ typedef struct {
299299
rsa, dhm, ecdsa, ecdh;
300300
} todo_list;
301301

302-
static int test_md( const todo_list * todo, mbedtls_platform_context* ctx )
302+
static int test_md( const todo_list * todo )
303303
{
304304
unsigned char tmp[200];
305-
// The call below is used to avoid the "unused parameter" warning.
306-
// The context itself can be used by cryptographic calls which require it.
307-
// Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more information.
308-
(void)ctx;
309305
memset( tmp, 0xBB, sizeof( tmp ) );
310306

311307
#if defined(MBEDTLS_MD4_C)
@@ -340,14 +336,10 @@ static int test_md( const todo_list * todo, mbedtls_platform_context* ctx )
340336
return ( 0 );
341337
}
342338

343-
static int test_crypt( const todo_list * todo, mbedtls_platform_context* ctx )
339+
static int test_crypt( const todo_list * todo )
344340
{
345341
unsigned char tmp[200];
346342
char title[TITLE_LEN];
347-
// The call below is used to avoid the "unused parameter" warning.
348-
// The context itself can be used by cryptographic calls which require it.
349-
// Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more information.
350-
(void)ctx;
351343
memset( tmp, 0xBB, sizeof( tmp ) );
352344

353345
#if defined(MBEDTLS_ARC4_C)
@@ -572,13 +564,9 @@ static int test_crypt( const todo_list * todo, mbedtls_platform_context* ctx )
572564
return ( 0 );
573565
}
574566

575-
static int test_rng( const todo_list * todo, mbedtls_platform_context* ctx )
567+
static int test_rng( const todo_list * todo )
576568
{
577569
unsigned char tmp[200];
578-
// The call below is used to avoid the "unused parameter" warning.
579-
// The context itself can be used by cryptographic calls which require it.
580-
// Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more information.
581-
(void)ctx;
582570
memset( tmp, 0xBB, sizeof( tmp ) );
583571

584572
#if defined(MBEDTLS_HAVEGE_C)
@@ -668,14 +656,10 @@ static int test_rng( const todo_list * todo, mbedtls_platform_context* ctx )
668656
return (0 );
669657
}
670658

671-
static int test_pk( const todo_list * todo, mbedtls_platform_context* ctx )
659+
static int test_pk( const todo_list * todo )
672660
{
673661
unsigned char tmp[200];
674662
char title[TITLE_LEN];
675-
// The call below is used to avoid the "unused parameter" warning.
676-
// The context itself can be used by cryptographic calls which require it.
677-
// Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more information.
678-
(void)ctx;
679663
memset( tmp, 0xBB, sizeof( tmp ) );
680664

681665
#if defined(MBEDTLS_RSA_C) && \
@@ -914,7 +898,7 @@ static int test_pk( const todo_list * todo, mbedtls_platform_context* ctx )
914898

915899
}
916900

917-
static int benchmark( int argc, char *argv[], mbedtls_platform_context* ctx )
901+
static int benchmark( int argc, char *argv[] )
918902
{
919903
int i;
920904
todo_list todo;
@@ -995,13 +979,13 @@ static int benchmark( int argc, char *argv[], mbedtls_platform_context* ctx )
995979
#endif
996980
memset( buf, 0xAA, sizeof( buf ) );
997981

998-
if( test_md( &todo, ctx ) != 0)
982+
if( test_md( &todo ) != 0)
999983
return ( 1 );
1000-
if( test_crypt( &todo, ctx ) != 0)
984+
if( test_crypt( &todo ) != 0)
1001985
return ( 1 );
1002-
if( test_rng( &todo, ctx ) != 0)
986+
if( test_rng( &todo ) != 0)
1003987
return ( 1 );
1004-
if( test_pk( &todo, ctx ) != 0)
988+
if( test_pk( &todo ) != 0)
1005989
return ( 1 );
1006990

1007991
mbedtls_printf("\nDONE\n");
@@ -1014,20 +998,19 @@ static int benchmark( int argc, char *argv[], mbedtls_platform_context* ctx )
1014998
}
1015999

10161000
int main(void) {
1017-
mbedtls_platform_context platform_ctx;
10181001
int exit_code = MBEDTLS_EXIT_FAILURE;
10191002

1020-
if((exit_code = mbedtls_platform_setup(&platform_ctx)) != 0) {
1003+
if((exit_code = mbedtls_platform_setup(NULL)) != 0) {
10211004
printf("Platform initialization failed with error %d\n", exit_code);
10221005
return MBEDTLS_EXIT_FAILURE;
10231006
}
10241007

1025-
exit_code = benchmark(0, NULL, &platform_ctx);
1008+
exit_code = benchmark(0, NULL);
10261009
if (exit_code != 0) {
10271010
mbedtls_printf("Benchmark failed with error %d\n", exit_code);
10281011
exit_code = MBEDTLS_EXIT_FAILURE;
10291012
}
10301013

1031-
mbedtls_platform_teardown(&platform_ctx);
1014+
mbedtls_platform_teardown(NULL);
10321015
return exit_code;
10331016
}

hashing/main.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,8 @@ static const char hello_str[] = "Hello, world!";
4747
static const unsigned char *hello_buffer = (const unsigned char *) hello_str;
4848
static const size_t hello_len = strlen(hello_str);
4949

50-
static int example(mbedtls_platform_context* ctx)
50+
static int example()
5151
{
52-
// The call below is used to avoid the "unused parameter" warning.
53-
// The context itself can be used by cryptographic calls which require it.
54-
// Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more information.
55-
(void)ctx;
56-
5752
mbedtls_printf("\n\n");
5853

5954
/*
@@ -157,20 +152,19 @@ static int example(mbedtls_platform_context* ctx)
157152
}
158153

159154
int main() {
160-
mbedtls_platform_context platform_ctx;
161155
int exit_code = MBEDTLS_EXIT_FAILURE;
162156

163-
if((exit_code = mbedtls_platform_setup(&platform_ctx)) != 0) {
157+
if((exit_code = mbedtls_platform_setup(NULL)) != 0) {
164158
printf("Platform initialization failed with error %d\n", exit_code);
165159
return MBEDTLS_EXIT_FAILURE;
166160
}
167161

168-
exit_code = example(&platform_ctx);
162+
exit_code = example();
169163
if (exit_code != 0) {
170164
mbedtls_printf("Example failed with error %d\n", exit_code);
171165
exit_code = MBEDTLS_EXIT_FAILURE;
172166
}
173167

174-
mbedtls_platform_teardown(&platform_ctx);
168+
mbedtls_platform_teardown(NULL);
175169
return exit_code;
176170
}

tls-client/HelloHttpsClient.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,11 @@ const char *HelloHttpsClient::HTTP_OK_STR = "200 OK";
7171

7272
HelloHttpsClient::HelloHttpsClient(const char *in_server_name,
7373
const char *in_server_addr,
74-
const uint16_t in_server_port,
75-
mbedtls_platform_context* in_platform_ctx) :
74+
const uint16_t in_server_port) :
7675
socket(),
7776
server_name(in_server_name),
7877
server_addr(in_server_addr),
79-
server_port(in_server_port),
80-
/* The platform context is passed just in case any crypto calls need it.
81-
* Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more
82-
* information. */
83-
platform_ctx(in_platform_ctx)
78+
server_port(in_server_port)
8479
{
8580
mbedtls_entropy_init(&entropy);
8681
mbedtls_ctr_drbg_init(&ctr_drbg);

tls-client/HelloHttpsClient.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "TCPSocket.h"
2626

2727
#include "mbedtls/config.h"
28-
#include "mbedtls/platform.h"
2928
#include "mbedtls/ssl.h"
3029
#include "mbedtls/entropy.h"
3130
#include "mbedtls/ctr_drbg.h"
@@ -64,8 +63,7 @@ class HelloHttpsClient
6463
*/
6564
HelloHttpsClient(const char *in_server_name,
6665
const char *in_server_addr,
67-
const uint16_t in_server_port,
68-
mbedtls_platform_context* in_platform_ctx);
66+
const uint16_t in_server_port);
6967

7068
/**
7169
* Free any allocated resources
@@ -233,8 +231,6 @@ class HelloHttpsClient
233231
* The TLS configuration in use
234232
*/
235233
mbedtls_ssl_config ssl_conf;
236-
237-
mbedtls_platform_context* platform_ctx;
238234
};
239235

240236
#endif /* _HELLOHTTPSCLIENT_H_ */

tls-client/main.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ const int SERVER_PORT = 443;
5050
*/
5151
int main()
5252
{
53-
mbedtls_platform_context platform_ctx;
5453
int exit_code = MBEDTLS_EXIT_FAILURE;
5554

56-
if((exit_code = mbedtls_platform_setup(&platform_ctx)) != 0) {
55+
if((exit_code = mbedtls_platform_setup(NULL)) != 0) {
5756
printf("Platform initialization failed with error %d\r\n", exit_code);
5857
return MBEDTLS_EXIT_FAILURE;
5958
}
@@ -74,13 +73,12 @@ int main()
7473
#endif /* MBEDTLS_MAJOR_VERSION */
7574

7675
/* Allocate a HTTPS client */
77-
client = new (std::nothrow) HelloHttpsClient(SERVER_NAME, SERVER_ADDR, SERVER_PORT,
78-
&platform_ctx);
76+
client = new (std::nothrow) HelloHttpsClient(SERVER_NAME, SERVER_ADDR, SERVER_PORT);
7977

8078
if (client == NULL) {
8179
mbedtls_printf("Failed to allocate HelloHttpsClient object\n"
8280
"\nFAIL\n");
83-
mbedtls_platform_teardown(&platform_ctx);
81+
mbedtls_platform_teardown(NULL);
8482
return exit_code;
8583
}
8684

@@ -94,6 +92,6 @@ int main()
9492

9593
delete client;
9694

97-
mbedtls_platform_teardown(&platform_ctx);
95+
mbedtls_platform_teardown(NULL);
9896
return exit_code;
9997
}

0 commit comments

Comments
 (0)