From e4de06145a92d811f060d5aa8fc8042259062340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 23 Jul 2014 17:26:48 +0200 Subject: [PATCH] Fix cookie context usage --- library/ssl_cookie.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/library/ssl_cookie.c b/library/ssl_cookie.c index 5b6a79a36..abf9e15fc 100644 --- a/library/ssl_cookie.c +++ b/library/ssl_cookie.c @@ -106,20 +106,23 @@ int ssl_cookie_setup( ssl_cookie_ctx *ctx, /* * Generate cookie for DTLS ClientHello verification */ -int ssl_cookie_write( void *ctx, +int ssl_cookie_write( void *p_ctx, unsigned char **p, unsigned char *end, const unsigned char *cli_id, size_t cli_id_len ) { int ret; unsigned char hmac_out[HVR_MD_LEN]; - md_context_t *hmac_ctx = (md_context_t *) ctx; + ssl_cookie_ctx *ctx = (ssl_cookie_ctx *) p_ctx; + + if( ctx == NULL ) + return( POLARSSL_ERR_SSL_BAD_INPUT_DATA ); if( (size_t)( end - *p ) < HVR_MD_USE ) return( POLARSSL_ERR_SSL_BAD_INPUT_DATA ); - if( ( ret = md_hmac_reset( hmac_ctx ) ) != 0 || - ( ret = md_hmac_update( hmac_ctx, cli_id, cli_id_len ) ) != 0 || - ( ret = md_hmac_finish( hmac_ctx, hmac_out ) ) != 0 ) + if( ( ret = md_hmac_reset( &ctx->hmac_ctx ) ) != 0 || + ( ret = md_hmac_update( &ctx->hmac_ctx, cli_id, cli_id_len ) ) != 0 || + ( ret = md_hmac_finish( &ctx->hmac_ctx, hmac_out ) ) != 0 ) { return( POLARSSL_ERR_SSL_INTERNAL_ERROR ); } @@ -133,18 +136,17 @@ int ssl_cookie_write( void *ctx, /* * Check a cookie */ -int ssl_cookie_check( void *ctx, +int ssl_cookie_check( void *p_ctx, const unsigned char *cookie, size_t cookie_len, const unsigned char *cli_id, size_t cli_id_len ) { unsigned char ref_cookie[HVR_MD_USE]; unsigned char *p = ref_cookie; - md_context_t *hmac_ctx = (md_context_t *) ctx; if( cookie_len != HVR_MD_USE ) return( -1 ); - if( ssl_cookie_write( hmac_ctx, + if( ssl_cookie_write( p_ctx, &p, p + sizeof( ref_cookie ), cli_id, cli_id_len ) != 0 ) return( -1 );