blob: 1a2d0c135b429b53181ed226ef32c9d6710648d1 [file] [log] [blame]
Werner Lewis0c6ea122022-09-30 13:02:16 +01001/* BEGIN_HEADER */
2#include "mbedtls/bignum.h"
3#include "mbedtls/entropy.h"
4#include "bignum_mod.h"
5#include "constant_time_internal.h"
6#include "test/constant_flow.h"
Werner Lewis0c6ea122022-09-30 13:02:16 +01007/* END_HEADER */
8
9/* BEGIN_DEPENDENCIES
10 * depends_on:MBEDTLS_BIGNUM_C
11 * END_DEPENDENCIES
12 */
13
14/* BEGIN_CASE */
15void mpi_mod_setup( int ext_rep, int int_rep, int iret )
16{
17 #define MLIMBS 8
18 mbedtls_mpi_uint mp[MLIMBS];
19 mbedtls_mpi_mod_modulus m;
20 int ret;
21
Minos Galanakis4d4c98b2022-10-27 15:58:02 +010022 memset( mp, 0xFF, sizeof(mp) );
Werner Lewis0c6ea122022-09-30 13:02:16 +010023
24 mbedtls_mpi_mod_modulus_init( &m );
25 ret = mbedtls_mpi_mod_modulus_setup( &m, mp, MLIMBS, ext_rep, int_rep );
26 TEST_EQUAL( ret, iret );
27
Minos Galanakisdd365a52022-10-19 01:48:32 +010028 /* Only test if the constants have been set-up */
29 if ( ret == 0 && int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY )
30 {
31 /* Test that the consts have been calculated */
32 TEST_ASSERT( m.rep.mont.rr != NULL );
33 TEST_ASSERT( m.rep.mont.mm != 0 );
34
Minos Galanakisdd365a52022-10-19 01:48:32 +010035 }
36
Werner Lewis0c6ea122022-09-30 13:02:16 +010037 /* Address sanitiser should catch if we try to free mp */
38 mbedtls_mpi_mod_modulus_free( &m );
39
40 /* Make sure that the modulus doesn't have reference to mp anymore */
41 TEST_ASSERT( m.p != mp );
42
Minos Galanakisdd365a52022-10-19 01:48:32 +010043 /* Only test if the constants have been set-up */
44 if ( ret == 0 && int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY )
45 {
Minos Galanakisdd365a52022-10-19 01:48:32 +010046 /* Verify the data and pointers allocated have been properly wiped */
47 TEST_ASSERT( m.rep.mont.rr == NULL );
48 TEST_ASSERT( m.rep.mont.mm == 0 );
Minos Galanakisdd365a52022-10-19 01:48:32 +010049 }
Werner Lewis0c6ea122022-09-30 13:02:16 +010050exit:
51 /* It should be safe to call an mbedtls free several times */
52 mbedtls_mpi_mod_modulus_free( &m );
53
54 #undef MLIMBS
55}
56/* END_CASE */
Janos Follath5933f692022-11-02 14:35:17 +000057
58/* BEGIN MERGE SLOT 1 */
59
60/* END MERGE SLOT 1 */
61
62/* BEGIN MERGE SLOT 2 */
63
64/* END MERGE SLOT 2 */
65
66/* BEGIN MERGE SLOT 3 */
67
68/* END MERGE SLOT 3 */
69
70/* BEGIN MERGE SLOT 4 */
71
72/* END MERGE SLOT 4 */
73
74/* BEGIN MERGE SLOT 5 */
75
76/* END MERGE SLOT 5 */
77
78/* BEGIN MERGE SLOT 6 */
79
80/* END MERGE SLOT 6 */
81
82/* BEGIN MERGE SLOT 7 */
83
84/* END MERGE SLOT 7 */
85
86/* BEGIN MERGE SLOT 8 */
87
88/* END MERGE SLOT 8 */
89
90/* BEGIN MERGE SLOT 9 */
91
92/* END MERGE SLOT 9 */
93
94/* BEGIN MERGE SLOT 10 */
95
96/* END MERGE SLOT 10 */