From b22ae9de4c87299b90682f29d0b0028746fc05f1 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 5 Jan 2018 11:56:59 -0700 Subject: [PATCH] add DH callback to example server and client --- tests/api.c | 2 +- wolfssl/test.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/api.c b/tests/api.c index 60d3dd283..e91fde627 100644 --- a/tests/api.c +++ b/tests/api.c @@ -15087,7 +15087,7 @@ static int my_DhCallback(WOLFSSL* ssl, struct DhKey* key, }; static void test_dh_ctx_setup(WOLFSSL_CTX* ctx) { - wolfSSL_CTX_SetDhAgreeCb(ctx, &my_DhCallback); + wolfSSL_CTX_SetDhAgreeCb(ctx, my_DhCallback); AssertIntEQ(wolfSSL_CTX_set_cipher_list(ctx, "DHE-RSA-AES128-SHA256"), WOLFSSL_SUCCESS); } diff --git a/wolfssl/test.h b/wolfssl/test.h index 577fe4571..376d54532 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -2013,6 +2013,21 @@ static INLINE int myX25519SharedSecret(WOLFSSL* ssl, curve25519_key* otherKey, #endif /* HAVE_ECC */ +#ifndef NO_DH +static INLINE int myDhCallback(WOLFSSL* ssl, struct DhKey* key, + const unsigned char* priv, unsigned int privSz, + const unsigned char* pubKeyDer, unsigned int pubKeySz, + unsigned char* out, unsigned int* outlen, + void* ctx) +{ + (void)ctx; + (void)ssl; + /* return 0 on success */ + return wc_DhAgree(key, out, outlen, priv, privSz, pubKeyDer, pubKeySz); +}; + +#endif /* !NO_DH */ + #ifndef NO_RSA static INLINE int myRsaSign(WOLFSSL* ssl, const byte* in, word32 inSz, @@ -2244,6 +2259,9 @@ static INLINE void SetupPkCallbacks(WOLFSSL_CTX* ctx, WOLFSSL* ssl) wolfSSL_CTX_SetEccVerifyCb(ctx, myEccVerify); wolfSSL_CTX_SetEccSharedSecretCb(ctx, myEccSharedSecret); #endif /* HAVE_ECC */ + #ifndef NO_DH + wolfSSL_CTX_SetDhAgreeCb(ctx, myDhCallback); + #endif #ifdef HAVE_ED25519 wolfSSL_CTX_SetEd25519SignCb(ctx, myEd25519Sign); wolfSSL_CTX_SetEd25519VerifyCb(ctx, myEd25519Verify);