Skip to content

Commit 1157b14

Browse files
authored
Merge pull request #199 from RonEld/set_NULL_as_platform_context
Change mbedtls_platform_context parameter to NULL
2 parents 97321fb + 9fff2bb commit 1157b14

File tree

8 files changed

+18
-47
lines changed

8 files changed

+18
-47
lines changed

authcrypt/authcrypt.cpp

+1-4
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

+1-6
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

+3-4
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

+2-5
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ MBED_NOINLINE static int benchmark_sha512()
343343
}
344344
#endif /* MBEDTLS_SHA512_C */
345345

346-
347346
#if defined(MBEDTLS_ARC4_C)
348347
MBED_NOINLINE static int benchmark_arc4()
349348
{
@@ -1316,13 +1315,12 @@ MBED_NOINLINE static int benchmark_ecdh_curve22519()
13161315

13171316
int main()
13181317
{
1319-
mbedtls_platform_context platform_ctx;
13201318
int exit_code = MBEDTLS_EXIT_SUCCESS;
13211319

13221320
memset(buf, 0xAA, sizeof(buf));
13231321
memset(tmp, 0xBB, sizeof(tmp));
13241322

1325-
if ((exit_code = mbedtls_platform_setup(&platform_ctx)) != 0) {
1323+
if ((exit_code = mbedtls_platform_setup(NULL)) != 0) {
13261324
mbedtls_printf("Platform initialization failed with error %d\r\n",
13271325
exit_code);
13281326
return MBEDTLS_EXIT_FAILURE;
@@ -1482,7 +1480,6 @@ int main()
14821480

14831481
mbedtls_printf("DONE\n");
14841482

1485-
mbedtls_platform_teardown(&platform_ctx);
1486-
1483+
mbedtls_platform_teardown(NULL);
14871484
return exit_code;
14881485
}

hashing/main.cpp

+4-10
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

+2-7
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

+1-5
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

+4-6
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)