From b813accf8463c042e7904aa89d0b8eb1947be1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 15 Sep 2015 15:34:09 +0200 Subject: [PATCH] Add mbedtls_ecjpake_check(), tells if set up This will be used in SSL to avoid the computation-heavy processing of EC J-PAKE hello extensions in case we don't have an EC J-PAKE password --- include/mbedtls/ecjpake.h | 10 ++++++++++ library/ecjpake.c | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/mbedtls/ecjpake.h b/include/mbedtls/ecjpake.h index 809684831..c1aa8cf1b 100644 --- a/include/mbedtls/ecjpake.h +++ b/include/mbedtls/ecjpake.h @@ -115,6 +115,16 @@ int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx, const unsigned char *secret, size_t len ); +/* + * \brief Check if a context is ready for use + * + * \param ctx Context to check + * + * \return 0 if the context is ready for use, + * MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise + */ +int mbedtls_ecjpake_check( const mbedtls_ecjpake_context *ctx ); + /** * \brief Generate and write the first round message * (TLS: contents of the Client/ServerHello extension, diff --git a/library/ecjpake.c b/library/ecjpake.c index f5863bc4c..0535a570f 100644 --- a/library/ecjpake.c +++ b/library/ecjpake.c @@ -119,6 +119,21 @@ cleanup: return( ret ); } +/* + * Check if context is ready for use + */ +int mbedtls_ecjpake_check( const mbedtls_ecjpake_context *ctx ) +{ + if( ctx->md_info == NULL || + ctx->grp.id == MBEDTLS_ECP_DP_NONE || + ctx->s.p == NULL ) + { + return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + } + + return( 0 ); +} + /* * Write a point plus its length to a buffer */