mbed TLS Build
tests/suites/test_suite_ecjpake.function@0:cdf462088d13, 2017-01-05 (annotated)
- Committer:
- markrad
- Date:
- Thu Jan 05 00:18:44 2017 +0000
- Revision:
- 0:cdf462088d13
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
markrad | 0:cdf462088d13 | 1 | /* BEGIN_HEADER */ |
markrad | 0:cdf462088d13 | 2 | #include "mbedtls/ecjpake.h" |
markrad | 0:cdf462088d13 | 3 | |
markrad | 0:cdf462088d13 | 4 | #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) && defined(MBEDTLS_SHA256_C) |
markrad | 0:cdf462088d13 | 5 | static const unsigned char ecjpake_test_x1[] = { |
markrad | 0:cdf462088d13 | 6 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, |
markrad | 0:cdf462088d13 | 7 | 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, |
markrad | 0:cdf462088d13 | 8 | 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x21 |
markrad | 0:cdf462088d13 | 9 | }; |
markrad | 0:cdf462088d13 | 10 | |
markrad | 0:cdf462088d13 | 11 | static const unsigned char ecjpake_test_x2[] = { |
markrad | 0:cdf462088d13 | 12 | 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, |
markrad | 0:cdf462088d13 | 13 | 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, |
markrad | 0:cdf462088d13 | 14 | 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x81 |
markrad | 0:cdf462088d13 | 15 | }; |
markrad | 0:cdf462088d13 | 16 | |
markrad | 0:cdf462088d13 | 17 | static const unsigned char ecjpake_test_x3[] = { |
markrad | 0:cdf462088d13 | 18 | 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, |
markrad | 0:cdf462088d13 | 19 | 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, |
markrad | 0:cdf462088d13 | 20 | 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x81 |
markrad | 0:cdf462088d13 | 21 | }; |
markrad | 0:cdf462088d13 | 22 | |
markrad | 0:cdf462088d13 | 23 | static const unsigned char ecjpake_test_x4[] = { |
markrad | 0:cdf462088d13 | 24 | 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, |
markrad | 0:cdf462088d13 | 25 | 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, |
markrad | 0:cdf462088d13 | 26 | 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe1 |
markrad | 0:cdf462088d13 | 27 | }; |
markrad | 0:cdf462088d13 | 28 | |
markrad | 0:cdf462088d13 | 29 | static const unsigned char ecjpake_test_X1[] = { |
markrad | 0:cdf462088d13 | 30 | 0x04, 0xac, 0xcf, 0x01, 0x06, 0xef, 0x85, 0x8f, 0xa2, 0xd9, 0x19, 0x33, |
markrad | 0:cdf462088d13 | 31 | 0x13, 0x46, 0x80, 0x5a, 0x78, 0xb5, 0x8b, 0xba, 0xd0, 0xb8, 0x44, 0xe5, |
markrad | 0:cdf462088d13 | 32 | 0xc7, 0x89, 0x28, 0x79, 0x14, 0x61, 0x87, 0xdd, 0x26, 0x66, 0xad, 0xa7, |
markrad | 0:cdf462088d13 | 33 | 0x81, 0xbb, 0x7f, 0x11, 0x13, 0x72, 0x25, 0x1a, 0x89, 0x10, 0x62, 0x1f, |
markrad | 0:cdf462088d13 | 34 | 0x63, 0x4d, 0xf1, 0x28, 0xac, 0x48, 0xe3, 0x81, 0xfd, 0x6e, 0xf9, 0x06, |
markrad | 0:cdf462088d13 | 35 | 0x07, 0x31, 0xf6, 0x94, 0xa4 |
markrad | 0:cdf462088d13 | 36 | }; |
markrad | 0:cdf462088d13 | 37 | |
markrad | 0:cdf462088d13 | 38 | static const unsigned char ecjpake_test_X2[] = { |
markrad | 0:cdf462088d13 | 39 | 0x04, 0x7e, 0xa6, 0xe3, 0xa4, 0x48, 0x70, 0x37, 0xa9, 0xe0, 0xdb, 0xd7, |
markrad | 0:cdf462088d13 | 40 | 0x92, 0x62, 0xb2, 0xcc, 0x27, 0x3e, 0x77, 0x99, 0x30, 0xfc, 0x18, 0x40, |
markrad | 0:cdf462088d13 | 41 | 0x9a, 0xc5, 0x36, 0x1c, 0x5f, 0xe6, 0x69, 0xd7, 0x02, 0xe1, 0x47, 0x79, |
markrad | 0:cdf462088d13 | 42 | 0x0a, 0xeb, 0x4c, 0xe7, 0xfd, 0x65, 0x75, 0xab, 0x0f, 0x6c, 0x7f, 0xd1, |
markrad | 0:cdf462088d13 | 43 | 0xc3, 0x35, 0x93, 0x9a, 0xa8, 0x63, 0xba, 0x37, 0xec, 0x91, 0xb7, 0xe3, |
markrad | 0:cdf462088d13 | 44 | 0x2b, 0xb0, 0x13, 0xbb, 0x2b |
markrad | 0:cdf462088d13 | 45 | }; |
markrad | 0:cdf462088d13 | 46 | |
markrad | 0:cdf462088d13 | 47 | static const unsigned char ecjpake_test_X3[] = { |
markrad | 0:cdf462088d13 | 48 | 0x04, 0x7e, 0xa6, 0xe3, 0xa4, 0x48, 0x70, 0x37, 0xa9, 0xe0, 0xdb, 0xd7, |
markrad | 0:cdf462088d13 | 49 | 0x92, 0x62, 0xb2, 0xcc, 0x27, 0x3e, 0x77, 0x99, 0x30, 0xfc, 0x18, 0x40, |
markrad | 0:cdf462088d13 | 50 | 0x9a, 0xc5, 0x36, 0x1c, 0x5f, 0xe6, 0x69, 0xd7, 0x02, 0xe1, 0x47, 0x79, |
markrad | 0:cdf462088d13 | 51 | 0x0a, 0xeb, 0x4c, 0xe7, 0xfd, 0x65, 0x75, 0xab, 0x0f, 0x6c, 0x7f, 0xd1, |
markrad | 0:cdf462088d13 | 52 | 0xc3, 0x35, 0x93, 0x9a, 0xa8, 0x63, 0xba, 0x37, 0xec, 0x91, 0xb7, 0xe3, |
markrad | 0:cdf462088d13 | 53 | 0x2b, 0xb0, 0x13, 0xbb, 0x2b |
markrad | 0:cdf462088d13 | 54 | }; |
markrad | 0:cdf462088d13 | 55 | |
markrad | 0:cdf462088d13 | 56 | static const unsigned char ecjpake_test_X4[] = { |
markrad | 0:cdf462088d13 | 57 | 0x04, 0x19, 0x0a, 0x07, 0x70, 0x0f, 0xfa, 0x4b, 0xe6, 0xae, 0x1d, 0x79, |
markrad | 0:cdf462088d13 | 58 | 0xee, 0x0f, 0x06, 0xae, 0xb5, 0x44, 0xcd, 0x5a, 0xdd, 0xaa, 0xbe, 0xdf, |
markrad | 0:cdf462088d13 | 59 | 0x70, 0xf8, 0x62, 0x33, 0x21, 0x33, 0x2c, 0x54, 0xf3, 0x55, 0xf0, 0xfb, |
markrad | 0:cdf462088d13 | 60 | 0xfe, 0xc7, 0x83, 0xed, 0x35, 0x9e, 0x5d, 0x0b, 0xf7, 0x37, 0x7a, 0x0f, |
markrad | 0:cdf462088d13 | 61 | 0xc4, 0xea, 0x7a, 0xce, 0x47, 0x3c, 0x9c, 0x11, 0x2b, 0x41, 0xcc, 0xd4, |
markrad | 0:cdf462088d13 | 62 | 0x1a, 0xc5, 0x6a, 0x56, 0x12 |
markrad | 0:cdf462088d13 | 63 | }; |
markrad | 0:cdf462088d13 | 64 | |
markrad | 0:cdf462088d13 | 65 | /* Load my private and public keys, and peer's public keys */ |
markrad | 0:cdf462088d13 | 66 | static int ecjpake_test_load( mbedtls_ecjpake_context *ctx, |
markrad | 0:cdf462088d13 | 67 | const unsigned char *xm1, size_t len_xm1, |
markrad | 0:cdf462088d13 | 68 | const unsigned char *xm2, size_t len_xm2, |
markrad | 0:cdf462088d13 | 69 | const unsigned char *Xm1, size_t len_Xm1, |
markrad | 0:cdf462088d13 | 70 | const unsigned char *Xm2, size_t len_Xm2, |
markrad | 0:cdf462088d13 | 71 | const unsigned char *Xp1, size_t len_Xp1, |
markrad | 0:cdf462088d13 | 72 | const unsigned char *Xp2, size_t len_Xp2 ) |
markrad | 0:cdf462088d13 | 73 | { |
markrad | 0:cdf462088d13 | 74 | int ret; |
markrad | 0:cdf462088d13 | 75 | |
markrad | 0:cdf462088d13 | 76 | MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->xm1, xm1, len_xm1 ) ); |
markrad | 0:cdf462088d13 | 77 | MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->xm2, xm2, len_xm2 ) ); |
markrad | 0:cdf462088d13 | 78 | |
markrad | 0:cdf462088d13 | 79 | MBEDTLS_MPI_CHK( mbedtls_ecp_point_read_binary( &ctx->grp, |
markrad | 0:cdf462088d13 | 80 | &ctx->Xm1, Xm1, len_Xm1 ) ); |
markrad | 0:cdf462088d13 | 81 | MBEDTLS_MPI_CHK( mbedtls_ecp_point_read_binary( &ctx->grp, |
markrad | 0:cdf462088d13 | 82 | &ctx->Xm2, Xm2, len_Xm2 ) ); |
markrad | 0:cdf462088d13 | 83 | MBEDTLS_MPI_CHK( mbedtls_ecp_point_read_binary( &ctx->grp, |
markrad | 0:cdf462088d13 | 84 | &ctx->Xp1, Xp1, len_Xp1 ) ); |
markrad | 0:cdf462088d13 | 85 | MBEDTLS_MPI_CHK( mbedtls_ecp_point_read_binary( &ctx->grp, |
markrad | 0:cdf462088d13 | 86 | &ctx->Xp2, Xp2, len_Xp2 ) ); |
markrad | 0:cdf462088d13 | 87 | |
markrad | 0:cdf462088d13 | 88 | cleanup: |
markrad | 0:cdf462088d13 | 89 | return( ret ); |
markrad | 0:cdf462088d13 | 90 | } |
markrad | 0:cdf462088d13 | 91 | |
markrad | 0:cdf462088d13 | 92 | #define ADD_SIZE( x ) x, sizeof( x ) |
markrad | 0:cdf462088d13 | 93 | #endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED && MBEDTLS_SHA256_C */ |
markrad | 0:cdf462088d13 | 94 | /* END_HEADER */ |
markrad | 0:cdf462088d13 | 95 | |
markrad | 0:cdf462088d13 | 96 | /* BEGIN_DEPENDENCIES |
markrad | 0:cdf462088d13 | 97 | * depends_on:MBEDTLS_ECJPAKE_C |
markrad | 0:cdf462088d13 | 98 | * END_DEPENDENCIES |
markrad | 0:cdf462088d13 | 99 | */ |
markrad | 0:cdf462088d13 | 100 | |
markrad | 0:cdf462088d13 | 101 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
markrad | 0:cdf462088d13 | 102 | void ecjpake_selftest() |
markrad | 0:cdf462088d13 | 103 | { |
markrad | 0:cdf462088d13 | 104 | TEST_ASSERT( mbedtls_ecjpake_self_test( 1 ) == 0 ); |
markrad | 0:cdf462088d13 | 105 | } |
markrad | 0:cdf462088d13 | 106 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 107 | |
markrad | 0:cdf462088d13 | 108 | /* BEGIN_CASE depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C */ |
markrad | 0:cdf462088d13 | 109 | void read_round_one( int role, char *data, int ref_ret ) |
markrad | 0:cdf462088d13 | 110 | { |
markrad | 0:cdf462088d13 | 111 | mbedtls_ecjpake_context ctx; |
markrad | 0:cdf462088d13 | 112 | const unsigned char pw[] = {}; |
markrad | 0:cdf462088d13 | 113 | unsigned char *msg; |
markrad | 0:cdf462088d13 | 114 | size_t len; |
markrad | 0:cdf462088d13 | 115 | |
markrad | 0:cdf462088d13 | 116 | mbedtls_ecjpake_init( &ctx ); |
markrad | 0:cdf462088d13 | 117 | |
markrad | 0:cdf462088d13 | 118 | msg = unhexify_alloc( data, &len ); |
markrad | 0:cdf462088d13 | 119 | TEST_ASSERT( msg != NULL ); |
markrad | 0:cdf462088d13 | 120 | |
markrad | 0:cdf462088d13 | 121 | TEST_ASSERT( mbedtls_ecjpake_setup( &ctx, role, |
markrad | 0:cdf462088d13 | 122 | MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, 0 ) == 0 ); |
markrad | 0:cdf462088d13 | 123 | |
markrad | 0:cdf462088d13 | 124 | TEST_ASSERT( mbedtls_ecjpake_read_round_one( &ctx, msg, len ) == ref_ret ); |
markrad | 0:cdf462088d13 | 125 | |
markrad | 0:cdf462088d13 | 126 | exit: |
markrad | 0:cdf462088d13 | 127 | mbedtls_ecjpake_free( &ctx ); |
markrad | 0:cdf462088d13 | 128 | mbedtls_free( msg ); |
markrad | 0:cdf462088d13 | 129 | } |
markrad | 0:cdf462088d13 | 130 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 131 | |
markrad | 0:cdf462088d13 | 132 | /* BEGIN_CASE depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C */ |
markrad | 0:cdf462088d13 | 133 | void read_round_two_cli( char *data, int ref_ret ) |
markrad | 0:cdf462088d13 | 134 | { |
markrad | 0:cdf462088d13 | 135 | mbedtls_ecjpake_context ctx; |
markrad | 0:cdf462088d13 | 136 | const unsigned char pw[] = {}; |
markrad | 0:cdf462088d13 | 137 | unsigned char *msg; |
markrad | 0:cdf462088d13 | 138 | size_t len; |
markrad | 0:cdf462088d13 | 139 | |
markrad | 0:cdf462088d13 | 140 | mbedtls_ecjpake_init( &ctx ); |
markrad | 0:cdf462088d13 | 141 | |
markrad | 0:cdf462088d13 | 142 | msg = unhexify_alloc( data, &len ); |
markrad | 0:cdf462088d13 | 143 | TEST_ASSERT( msg != NULL ); |
markrad | 0:cdf462088d13 | 144 | |
markrad | 0:cdf462088d13 | 145 | TEST_ASSERT( mbedtls_ecjpake_setup( &ctx, MBEDTLS_ECJPAKE_CLIENT, |
markrad | 0:cdf462088d13 | 146 | MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, 0 ) == 0 ); |
markrad | 0:cdf462088d13 | 147 | |
markrad | 0:cdf462088d13 | 148 | TEST_ASSERT( ecjpake_test_load( &ctx, |
markrad | 0:cdf462088d13 | 149 | ADD_SIZE( ecjpake_test_x1 ), ADD_SIZE( ecjpake_test_x2 ), |
markrad | 0:cdf462088d13 | 150 | ADD_SIZE( ecjpake_test_X1 ), ADD_SIZE( ecjpake_test_X2 ), |
markrad | 0:cdf462088d13 | 151 | ADD_SIZE( ecjpake_test_X3 ), ADD_SIZE( ecjpake_test_X4 ) ) |
markrad | 0:cdf462088d13 | 152 | == 0 ); |
markrad | 0:cdf462088d13 | 153 | |
markrad | 0:cdf462088d13 | 154 | TEST_ASSERT( mbedtls_ecjpake_read_round_two( &ctx, msg, len ) == ref_ret ); |
markrad | 0:cdf462088d13 | 155 | |
markrad | 0:cdf462088d13 | 156 | exit: |
markrad | 0:cdf462088d13 | 157 | mbedtls_ecjpake_free( &ctx ); |
markrad | 0:cdf462088d13 | 158 | mbedtls_free( msg ); |
markrad | 0:cdf462088d13 | 159 | } |
markrad | 0:cdf462088d13 | 160 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 161 | |
markrad | 0:cdf462088d13 | 162 | /* BEGIN_CASE depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C */ |
markrad | 0:cdf462088d13 | 163 | void read_round_two_srv( char *data, int ref_ret ) |
markrad | 0:cdf462088d13 | 164 | { |
markrad | 0:cdf462088d13 | 165 | mbedtls_ecjpake_context ctx; |
markrad | 0:cdf462088d13 | 166 | const unsigned char pw[] = {}; |
markrad | 0:cdf462088d13 | 167 | unsigned char *msg; |
markrad | 0:cdf462088d13 | 168 | size_t len; |
markrad | 0:cdf462088d13 | 169 | |
markrad | 0:cdf462088d13 | 170 | mbedtls_ecjpake_init( &ctx ); |
markrad | 0:cdf462088d13 | 171 | |
markrad | 0:cdf462088d13 | 172 | msg = unhexify_alloc( data, &len ); |
markrad | 0:cdf462088d13 | 173 | TEST_ASSERT( msg != NULL ); |
markrad | 0:cdf462088d13 | 174 | |
markrad | 0:cdf462088d13 | 175 | TEST_ASSERT( mbedtls_ecjpake_setup( &ctx, MBEDTLS_ECJPAKE_SERVER, |
markrad | 0:cdf462088d13 | 176 | MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, 0 ) == 0 ); |
markrad | 0:cdf462088d13 | 177 | |
markrad | 0:cdf462088d13 | 178 | TEST_ASSERT( ecjpake_test_load( &ctx, |
markrad | 0:cdf462088d13 | 179 | ADD_SIZE( ecjpake_test_x3 ), ADD_SIZE( ecjpake_test_x4 ), |
markrad | 0:cdf462088d13 | 180 | ADD_SIZE( ecjpake_test_X3 ), ADD_SIZE( ecjpake_test_X4 ), |
markrad | 0:cdf462088d13 | 181 | ADD_SIZE( ecjpake_test_X1 ), ADD_SIZE( ecjpake_test_X2 ) ) |
markrad | 0:cdf462088d13 | 182 | == 0 ); |
markrad | 0:cdf462088d13 | 183 | |
markrad | 0:cdf462088d13 | 184 | TEST_ASSERT( mbedtls_ecjpake_read_round_two( &ctx, msg, len ) == ref_ret ); |
markrad | 0:cdf462088d13 | 185 | |
markrad | 0:cdf462088d13 | 186 | exit: |
markrad | 0:cdf462088d13 | 187 | mbedtls_ecjpake_free( &ctx ); |
markrad | 0:cdf462088d13 | 188 | mbedtls_free( msg ); |
markrad | 0:cdf462088d13 | 189 | } |
markrad | 0:cdf462088d13 | 190 | /* END_CASE */ |