Skip to content

Commit 82bdf07

Browse files
committed
Mbed TLS: Fix wrong MPI N in ECP Curve448 curve
In loading Curve448, MPI N is in uninitialized state and its sign flag N.s isn't initialized to 1. Following most other code, this can be fixed by invoking mbedtls_mpi_lset() on it.
1 parent 1ab98de commit 82bdf07

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

connectivity/mbedtls/source/ecp_curves.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,15 @@ static int ecp_use_curve448( mbedtls_ecp_group *grp )
745745
mbedtls_mpi_free( &grp->G.Y );
746746

747747
/* N = 2^446 - 13818066809895115352007386748515426880336692474882178609894547503885 */
748+
/* Fix wrong sign flag grp->N.s
749+
*
750+
* grp->N is in uninitialized state due to caller's having invoked
751+
* mbedtls_ecp_group_free(grp) before. In uninitialized state, grp->N.s
752+
* is not initialized to 1 to indicate positive. This can fix by
753+
* re-initializing through mbedtls_mpi_lset(&grp->N, 0), following
754+
* most other code.
755+
*/
756+
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &grp->N, 0 ) );
748757
MBEDTLS_MPI_CHK( mbedtls_mpi_set_bit( &grp->N, 446, 1 ) );
749758
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &Ns, 16,
750759
"8335DC163BB124B65129C96FDE933D8D723A70AADC873D6D54A7BB0D" ) );

0 commit comments

Comments
 (0)