mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-02 07:20:26 +00:00
programs_dh_server: Updated to use mbedtls_dhm_set_group()
& mbedtls_dhm_get_len()
.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
This commit is contained in:
parent
12abdde951
commit
e29c868ca4
@ -66,7 +66,7 @@ int main(void)
|
|||||||
mbedtls_dhm_context dhm;
|
mbedtls_dhm_context dhm;
|
||||||
mbedtls_aes_context aes;
|
mbedtls_aes_context aes;
|
||||||
|
|
||||||
mbedtls_mpi N, P, Q, D, E;
|
mbedtls_mpi N, P, Q, D, E, dhm_P, dhm_G;
|
||||||
|
|
||||||
mbedtls_net_init(&listen_fd);
|
mbedtls_net_init(&listen_fd);
|
||||||
mbedtls_net_init(&client_fd);
|
mbedtls_net_init(&client_fd);
|
||||||
@ -75,8 +75,8 @@ int main(void)
|
|||||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||||
|
|
||||||
mbedtls_mpi_init(&N); mbedtls_mpi_init(&P); mbedtls_mpi_init(&Q);
|
mbedtls_mpi_init(&N); mbedtls_mpi_init(&P); mbedtls_mpi_init(&Q);
|
||||||
mbedtls_mpi_init(&D); mbedtls_mpi_init(&E);
|
mbedtls_mpi_init(&D); mbedtls_mpi_init(&E); mbedtls_mpi_init(&dhm_P);
|
||||||
|
mbedtls_mpi_init(&dhm_G);
|
||||||
/*
|
/*
|
||||||
* 1. Setup the RNG
|
* 1. Setup the RNG
|
||||||
*/
|
*/
|
||||||
@ -141,8 +141,9 @@ int main(void)
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mbedtls_mpi_read_file(&dhm.MBEDTLS_PRIVATE(P), 16, f) != 0 ||
|
if ((ret = mbedtls_mpi_read_file(&dhm_P, 16, f)) != 0 ||
|
||||||
mbedtls_mpi_read_file(&dhm.MBEDTLS_PRIVATE(G), 16, f) != 0) {
|
(ret = mbedtls_mpi_read_file(&dhm_G, 16, f)) != 0 ||
|
||||||
|
(ret = mbedtls_dhm_set_group(&dhm, &dhm_P, &dhm_G) != 0)) {
|
||||||
mbedtls_printf(" failed\n ! Invalid DH parameter file\n\n");
|
mbedtls_printf(" failed\n ! Invalid DH parameter file\n\n");
|
||||||
fclose(f);
|
fclose(f);
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -176,7 +177,7 @@ int main(void)
|
|||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
|
|
||||||
if ((ret =
|
if ((ret =
|
||||||
mbedtls_dhm_make_params(&dhm, (int) mbedtls_mpi_size(&dhm.MBEDTLS_PRIVATE(P)), buf, &n,
|
mbedtls_dhm_make_params(&dhm, (int) mbedtls_dhm_get_len(&dhm), buf, &n,
|
||||||
mbedtls_ctr_drbg_random, &ctr_drbg)) != 0) {
|
mbedtls_ctr_drbg_random, &ctr_drbg)) != 0) {
|
||||||
mbedtls_printf(" failed\n ! mbedtls_dhm_make_params returned %d\n\n", ret);
|
mbedtls_printf(" failed\n ! mbedtls_dhm_make_params returned %d\n\n", ret);
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -286,7 +287,8 @@ int main(void)
|
|||||||
exit:
|
exit:
|
||||||
|
|
||||||
mbedtls_mpi_free(&N); mbedtls_mpi_free(&P); mbedtls_mpi_free(&Q);
|
mbedtls_mpi_free(&N); mbedtls_mpi_free(&P); mbedtls_mpi_free(&Q);
|
||||||
mbedtls_mpi_free(&D); mbedtls_mpi_free(&E);
|
mbedtls_mpi_free(&D); mbedtls_mpi_free(&E); mbedtls_mpi_free(&dhm_P);
|
||||||
|
mbedtls_mpi_free(&dhm_G);
|
||||||
|
|
||||||
mbedtls_net_free(&client_fd);
|
mbedtls_net_free(&client_fd);
|
||||||
mbedtls_net_free(&listen_fd);
|
mbedtls_net_free(&listen_fd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user