1/* BEGIN_HEADER */
2#include <mbedtls/ssl.h>
3#include <mbedtls/ssl_internal.h>
4/* END_HEADER */
5
6/* BEGIN_DEPENDENCIES
7 * depends_on:MBEDTLS_SSL_TLS_C
8 * END_DEPENDENCIES
9 */
10
11/* BEGIN_CASE depends_on:MBEDTLS_SSL_DTLS_ANTI_REPLAY */
12void ssl_dtls_replay( char *prevs, char *new, int ret )
13{
14    mbedtls_ssl_context ssl;
15    mbedtls_ssl_config conf;
16    char *end_prevs = prevs + strlen( prevs ) + 1;
17
18    mbedtls_ssl_init( &ssl );
19    mbedtls_ssl_config_init( &conf );
20
21    TEST_ASSERT( mbedtls_ssl_config_defaults( &conf,
22                 MBEDTLS_SSL_IS_CLIENT,
23                 MBEDTLS_SSL_TRANSPORT_DATAGRAM,
24                 MBEDTLS_SSL_PRESET_DEFAULT ) == 0 );
25    TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
26
27    /* Read previous record numbers */
28    for( ; end_prevs - prevs >= 13; prevs += 13 )
29    {
30        prevs[12] = '\0';
31        unhexify( ssl.in_ctr + 2, prevs );
32        mbedtls_ssl_dtls_replay_update( &ssl );
33    }
34
35    /* Check new number */
36    unhexify( ssl.in_ctr + 2, new );
37    TEST_ASSERT( mbedtls_ssl_dtls_replay_check( &ssl ) == ret );
38
39    mbedtls_ssl_free( &ssl );
40    mbedtls_ssl_config_free( &conf );
41}
42/* END_CASE */
43