File tree Expand file tree Collapse file tree 8 files changed +32
-14
lines changed Expand file tree Collapse file tree 8 files changed +32
-14
lines changed Original file line number Diff line number Diff line change 28
28
#include " mbedtls/debug.h"
29
29
#endif
30
30
31
- #include " mbedtls/platform.h"
32
-
33
31
#include < string.h>
34
32
35
33
const unsigned char Authcrypt::secret_key[16 ] = {
@@ -41,8 +39,9 @@ const char Authcrypt::message[] = "Some things are better left unread";
41
39
42
40
const char Authcrypt::metadata[] = " eg sequence number, routing info" ;
43
41
44
- Authcrypt::Authcrypt ()
42
+ Authcrypt::Authcrypt (mbedtls_platform_context* platform_ctx )
45
43
{
44
+ _platform_ctx = platform_ctx;
46
45
memset (ciphertext, 0 , sizeof (ciphertext));
47
46
memset (decrypted, 0 , sizeof (decrypted));
48
47
Original file line number Diff line number Diff line change 23
23
#include " mbedtls/cipher.h"
24
24
#include " mbedtls/entropy.h"
25
25
#include " mbedtls/ctr_drbg.h"
26
+ #include " mbedtls/platform.h"
26
27
27
28
/* *
28
29
* This class implements the logic to demonstrate authenticated encryption using
@@ -34,7 +35,7 @@ class Authcrypt
34
35
/* *
35
36
* Construct an Authcrypt instance
36
37
*/
37
- Authcrypt ();
38
+ Authcrypt (mbedtls_platform_context* platform_ctx );
38
39
39
40
/* *
40
41
* Free any allocated resources
@@ -103,6 +104,11 @@ class Authcrypt
103
104
* The block cipher configuration
104
105
*/
105
106
mbedtls_cipher_context_t cipher;
107
+
108
+ /* *
109
+ * The platform context
110
+ */
111
+ mbedtls_platform_context* _platform_ctx;
106
112
};
107
113
108
114
#endif /* _AUTHCRYPT_H_ */
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ int main() {
30
30
}
31
31
32
32
int exit_code = MBEDTLS_EXIT_SUCCESS;
33
- Authcrypt *authcrypt = new Authcrypt ();
33
+ Authcrypt *authcrypt = new Authcrypt (&platform_ctx );
34
34
35
35
if (authcrypt->run () != 0 ) {
36
36
exit_code = MBEDTLS_EXIT_FAILURE;
Original file line number Diff line number Diff line change @@ -300,7 +300,7 @@ typedef struct {
300
300
rsa, dhm, ecdsa, ecdh;
301
301
} todo_list;
302
302
303
- static int benchmark ( int argc, char *argv[] )
303
+ static int benchmark ( int argc, char *argv[], mbedtls_platform_context* ctx )
304
304
{
305
305
int i;
306
306
unsigned char tmp[200 ];
@@ -309,7 +309,9 @@ static int benchmark( int argc, char *argv[] )
309
309
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
310
310
unsigned char malloc_buf[HEAP_SIZE] = { 0 };
311
311
#endif
312
-
312
+ // The call below is used to avoid the "unused parameter" warning.
313
+ // The context itself can be used by cryptographic calls which require it.
314
+ (void )ctx;
313
315
if ( argc <= 1 )
314
316
{
315
317
memset ( &todo, 1 , sizeof ( todo ) );
@@ -966,7 +968,7 @@ int main(void) {
966
968
return -1 ;
967
969
}
968
970
969
- int ret = benchmark (0 , NULL );
971
+ int ret = benchmark (0 , NULL , &platform_ctx );
970
972
if (ret != 0 ) {
971
973
mbedtls_printf (" Benchmark failed with error %d\r\n " , ret);
972
974
}
Original file line number Diff line number Diff line change @@ -47,8 +47,12 @@ static const char hello_str[] = "Hello, world!";
47
47
static const unsigned char *hello_buffer = (const unsigned char *) hello_str;
48
48
static const size_t hello_len = strlen(hello_str);
49
49
50
- static int example (void )
50
+ static int example (mbedtls_platform_context* ctx )
51
51
{
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
+ (void )ctx;
55
+
52
56
mbedtls_printf (" \r\n\r\n " );
53
57
54
58
/*
@@ -157,7 +161,7 @@ int main() {
157
161
return -1 ;
158
162
}
159
163
160
- int ret = example ();
164
+ int ret = example (&platform_ctx );
161
165
if (ret != 0 ) {
162
166
mbedtls_printf (" Example failed with error %d\r\n " , ret);
163
167
}
Original file line number Diff line number Diff line change @@ -70,10 +70,12 @@ const char *HelloHttpsClient::HTTP_HELLO_STR = "Hello world!";
70
70
const char *HelloHttpsClient::HTTP_OK_STR = " 200 OK" ;
71
71
72
72
HelloHttpsClient::HelloHttpsClient (const char *in_server_name,
73
- const uint16_t in_server_port) :
73
+ const uint16_t in_server_port,
74
+ mbedtls_platform_context* in_platform_ctx) :
74
75
socket(),
75
76
server_name(in_server_name),
76
- server_port(in_server_port)
77
+ server_port(in_server_port),
78
+ platform_ctx(in_platform_ctx)
77
79
{
78
80
mbedtls_entropy_init (&entropy);
79
81
mbedtls_ctr_drbg_init (&ctr_drbg);
Original file line number Diff line number Diff line change 25
25
#include " TCPSocket.h"
26
26
27
27
#include " mbedtls/config.h"
28
+ #include " mbedtls/platform.h"
28
29
#include " mbedtls/ssl.h"
29
30
#include " mbedtls/entropy.h"
30
31
#include " mbedtls/ctr_drbg.h"
@@ -60,7 +61,8 @@ class HelloHttpsClient
60
61
* The server port
61
62
*/
62
63
HelloHttpsClient (const char *in_server_name,
63
- const uint16_t in_server_port);
64
+ const uint16_t in_server_port,
65
+ mbedtls_platform_context* in_platform_ctx);
64
66
65
67
/* *
66
68
* Free any allocated resources
@@ -223,6 +225,8 @@ class HelloHttpsClient
223
225
* The TLS configuration in use
224
226
*/
225
227
mbedtls_ssl_config ssl_conf;
228
+
229
+ mbedtls_platform_context* platform_ctx;
226
230
};
227
231
228
232
#endif /* _HELLOHTTPSCLIENT_H_ */
Original file line number Diff line number Diff line change @@ -71,7 +71,8 @@ int main()
71
71
#endif /* MBEDTLS_MAJOR_VERSION */
72
72
73
73
/* Allocate a HTTPS client */
74
- client = new (std::nothrow) HelloHttpsClient (SERVER_NAME, SERVER_PORT);
74
+ client = new (std::nothrow) HelloHttpsClient (SERVER_NAME, SERVER_PORT,
75
+ &platform_ctx);
75
76
if (client == NULL ) {
76
77
mbedtls_printf (" Failed to allocate HelloHttpsClient object\n "
77
78
" \n FAIL\n " );
You can’t perform that action at this time.
0 commit comments