Skip to content

Commit e3bb3b8

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 714adc8 commit e3bb3b8

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\r\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\r\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
@@ -300,13 +300,9 @@ typedef struct {
300300
rsa, dhm, ecdsa, ecdh;
301301
} todo_list;
302302

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

312308
#if defined(MBEDTLS_MD4_C)
@@ -341,14 +337,10 @@ static int test_md( const todo_list * todo, mbedtls_platform_context* ctx )
341337
return ( 0 );
342338
}
343339

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

354346
#if defined(MBEDTLS_ARC4_C)
@@ -573,13 +565,9 @@ static int test_crypt( const todo_list * todo, mbedtls_platform_context* ctx )
573565
return ( 0 );
574566
}
575567

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

585573
#if defined(MBEDTLS_HAVEGE_C)
@@ -669,14 +657,10 @@ static int test_rng( const todo_list * todo, mbedtls_platform_context* ctx )
669657
return (0 );
670658
}
671659

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

682666
#if defined(MBEDTLS_RSA_C) && \
@@ -915,7 +899,7 @@ static int test_pk( const todo_list * todo, mbedtls_platform_context* ctx )
915899

916900
}
917901

918-
static int benchmark( int argc, char *argv[], mbedtls_platform_context* ctx )
902+
static int benchmark( int argc, char *argv[] )
919903
{
920904
int i;
921905
todo_list todo;
@@ -996,13 +980,13 @@ static int benchmark( int argc, char *argv[], mbedtls_platform_context* ctx )
996980
#endif
997981
memset( buf, 0xAA, sizeof( buf ) );
998982

999-
if( test_md( &todo, ctx ) != 0)
983+
if( test_md( &todo ) != 0)
1000984
return ( 1 );
1001-
if( test_crypt( &todo, ctx ) != 0)
985+
if( test_crypt( &todo ) != 0)
1002986
return ( 1 );
1003-
if( test_rng( &todo, ctx ) != 0)
987+
if( test_rng( &todo ) != 0)
1004988
return ( 1 );
1005-
if( test_pk( &todo, ctx ) != 0)
989+
if( test_pk( &todo ) != 0)
1006990
return ( 1 );
1007991

1008992
mbedtls_printf("\r\nDONE\r\n");
@@ -1015,20 +999,19 @@ static int benchmark( int argc, char *argv[], mbedtls_platform_context* ctx )
1015999
}
10161000

10171001
int main(void) {
1018-
mbedtls_platform_context platform_ctx;
10191002
int exit_code = MBEDTLS_EXIT_FAILURE;
10201003

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

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

1032-
mbedtls_platform_teardown(&platform_ctx);
1015+
mbedtls_platform_teardown(NULL);
10331016
return exit_code;
10341017
}

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("\r\n\r\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\r\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\r\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)