|
@@ -0,0 +1,696 @@
|
|
|
+/* srp.c SRP unit tests
|
|
|
+ *
|
|
|
+ * Copyright (C) 2006-2015 wolfSSL Inc.
|
|
|
+ *
|
|
|
+ * This file is part of wolfSSL. (formerly known as CyaSSL)
|
|
|
+ *
|
|
|
+ * wolfSSL is free software; you can redistribute it and/or modify
|
|
|
+ * it under the terms of the GNU Geteral Public License as published by
|
|
|
+ * the Free Software Foundation; either version 2 of the License, or
|
|
|
+ * (at your option) any later version.
|
|
|
+ *
|
|
|
+ * wolfSSL is distributed in the hope that it will be useful,
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+ * GNU Geteral Public License for more details.
|
|
|
+ *
|
|
|
+ * You should have received a copy of the GNU Geteral Public License
|
|
|
+ * along with this program; if not, write to the Free Software
|
|
|
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
+ */
|
|
|
+
|
|
|
+#ifdef HAVE_CONFIG_H
|
|
|
+ #include <config.h>
|
|
|
+#endif
|
|
|
+
|
|
|
+#include <wolfssl/wolfcrypt/settings.h>
|
|
|
+
|
|
|
+#include <tests/unit.h>
|
|
|
+#include <wolfssl/wolfcrypt/sha512.h>
|
|
|
+#include <wolfssl/wolfcrypt/srp.h>
|
|
|
+
|
|
|
+#ifdef WOLFCRYPT_HAVE_SRP
|
|
|
+
|
|
|
+static byte username[] = "user";
|
|
|
+static word32 usernameSz = 4;
|
|
|
+
|
|
|
+static byte password[] = "password";
|
|
|
+static word32 passwordSz = 8;
|
|
|
+
|
|
|
+static byte N[] = {
|
|
|
+ 0xD4, 0xC7, 0xF8, 0xA2, 0xB3, 0x2C, 0x11, 0xB8, 0xFB, 0xA9, 0x58, 0x1E,
|
|
|
+ 0xC4, 0xBA, 0x4F, 0x1B, 0x04, 0x21, 0x56, 0x42, 0xEF, 0x73, 0x55, 0xE3,
|
|
|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0x89, 0x75, 0xC7, 0x51, 0xCF, 0x6C, 0x03, 0xD4, 0xCA, 0xD5, 0x6E,
|
|
|
+ 0x97, 0x4D, 0xA3, 0x1E, 0x19, 0x0B, 0xF0, 0xAA, 0x7D, 0x14, 0x90, 0x80,
|
|
|
+ 0x0E, 0xC7, 0x92, 0xAD
|
|
|
+};
|
|
|
+
|
|
|
+static byte key[] = {
|
|
|
+ 0x66, 0x00, 0x9D, 0x58, 0xB3, 0xD2, 0x0D, 0x4B, 0x69, 0x7F, 0xCF, 0x48,
|
|
|
+ 0xFF, 0x8F, 0x15, 0x81, 0x4C, 0x4B, 0xFE, 0x9D, 0x85, 0x77, 0x88, 0x60,
|
|
|
+ 0x1D, 0x1E, 0x51, 0xCF, 0x75, 0xCC, 0x58, 0x00, 0xE7, 0x8D, 0x22, 0x87,
|
|
|
+ 0x13, 0x6C, 0x88, 0x55
|
|
|
+};
|
|
|
+
|
|
|
+static byte client_proof[] = {
|
|
|
+ 0x0D, 0x49, 0xE1, 0x9C, 0x3A, 0x88, 0x43, 0x15, 0x45, 0xA8, 0xAC, 0xAB,
|
|
|
+ 0xEA, 0x15, 0x1A, 0xEE, 0xF9, 0x38, 0x4D, 0x21
|
|
|
+};
|
|
|
+
|
|
|
+static byte server_proof[] = {
|
|
|
+ 0xBD, 0xB1, 0x20, 0x70, 0x46, 0xC9, 0xD6, 0xCC, 0xE2, 0x1D, 0x75, 0xA2,
|
|
|
+ 0xD0, 0xAF, 0xC5, 0xBC, 0xAE, 0x12, 0xFC, 0x75
|
|
|
+};
|
|
|
+
|
|
|
+static void test_SrpInit(void)
|
|
|
+{
|
|
|
+ Srp srp;
|
|
|
+
|
|
|
+ /* invalid params */
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpInit(NULL, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpInit(&srp, 255, SRP_CLIENT_SIDE));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpInit(&srp, SRP_TYPE_SHA, 255 ));
|
|
|
+
|
|
|
+ /* success */
|
|
|
+ AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
|
|
|
+
|
|
|
+ wc_SrpTerm(&srp);
|
|
|
+}
|
|
|
+
|
|
|
+static void test_SrpSetUsername(void)
|
|
|
+{
|
|
|
+ Srp srp;
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
|
|
|
+
|
|
|
+ /* invalid params */
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpSetUsername(NULL, username, usernameSz));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpSetUsername(&srp, NULL, usernameSz));
|
|
|
+
|
|
|
+ /* success */
|
|
|
+ AssertIntEQ(0, wc_SrpSetUsername(&srp, username, usernameSz));
|
|
|
+ AssertIntEQ((int) usernameSz, srp.userSz);
|
|
|
+ AssertIntEQ(0, XMEMCMP(srp.user, username, usernameSz));
|
|
|
+
|
|
|
+ wc_SrpTerm(&srp);
|
|
|
+}
|
|
|
+
|
|
|
+static void test_SrpSetParams(void)
|
|
|
+{
|
|
|
+ Srp srp;
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
|
|
|
+
|
|
|
+ /* invalid call order */
|
|
|
+ AssertIntEQ(SRP_CALL_ORDER_E, wc_SrpSetParams(&srp, N, sizeof(N),
|
|
|
+ g, sizeof(g),
|
|
|
+ salt, sizeof(salt)));
|
|
|
+
|
|
|
+ /* fix call order */
|
|
|
+ AssertIntEQ(0, wc_SrpSetUsername(&srp, username, usernameSz));
|
|
|
+
|
|
|
+ /* invalid params */
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpSetParams(NULL, N, sizeof(N),
|
|
|
+ g, sizeof(g),
|
|
|
+ salt, sizeof(salt)));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpSetParams(&srp, NULL, sizeof(N),
|
|
|
+ g, sizeof(g),
|
|
|
+ salt, sizeof(salt)));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpSetParams(&srp, N, sizeof(N),
|
|
|
+ NULL, sizeof(g),
|
|
|
+ salt, sizeof(salt)));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpSetParams(&srp, N, sizeof(N),
|
|
|
+ g, sizeof(g),
|
|
|
+ NULL, sizeof(salt)));
|
|
|
+
|
|
|
+ /* success */
|
|
|
+ AssertIntEQ(0, wc_SrpSetParams(&srp, N, sizeof(N),
|
|
|
+ g, sizeof(g),
|
|
|
+ salt, sizeof(salt)));
|
|
|
+
|
|
|
+ AssertIntEQ(sizeof(salt), srp.saltSz);
|
|
|
+ AssertIntEQ(0, XMEMCMP(srp.salt, salt, srp.saltSz));
|
|
|
+
|
|
|
+ wc_SrpTerm(&srp);
|
|
|
+}
|
|
|
+
|
|
|
+static void test_SrpSetPassword(void)
|
|
|
+{
|
|
|
+ Srp srp;
|
|
|
+ byte v[64];
|
|
|
+ word32 vSz = 0;
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
|
|
|
+ AssertIntEQ(0, wc_SrpSetUsername(&srp, username, usernameSz));
|
|
|
+
|
|
|
+ /* invalid call order */
|
|
|
+ AssertIntEQ(SRP_CALL_ORDER_E,
|
|
|
+ wc_SrpSetPassword(&srp, password, passwordSz));
|
|
|
+ AssertIntEQ(SRP_CALL_ORDER_E,
|
|
|
+ wc_SrpGetVerifier(&srp, v, &vSz));
|
|
|
+
|
|
|
+ /* fix call order */
|
|
|
+ AssertIntEQ(0, wc_SrpSetParams(&srp, N, sizeof(N),
|
|
|
+ g, sizeof(g),
|
|
|
+ salt, sizeof(salt)));
|
|
|
+
|
|
|
+ /* invalid params */
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpSetPassword(NULL, password, passwordSz));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpSetPassword(&srp, NULL, passwordSz));
|
|
|
+
|
|
|
+ /* success */
|
|
|
+ AssertIntEQ(0, wc_SrpSetPassword(&srp, password, passwordSz));
|
|
|
+
|
|
|
+ /* invalid params */
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpGetVerifier(NULL, v, &vSz));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpGetVerifier(&srp, NULL, &vSz));
|
|
|
+ AssertIntEQ(BUFFER_E, wc_SrpGetVerifier(&srp, v, &vSz));
|
|
|
+
|
|
|
+ /* success */
|
|
|
+ vSz = sizeof(v);
|
|
|
+ AssertIntEQ(0, wc_SrpGetVerifier(&srp, v, &vSz));
|
|
|
+ AssertIntEQ(vSz, sizeof(verifier));
|
|
|
+ AssertIntEQ(0, XMEMCMP(verifier, v, vSz));
|
|
|
+
|
|
|
+ /* invalid params - client side srp */
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpSetVerifier(&srp, v, vSz));
|
|
|
+
|
|
|
+ wc_SrpTerm(&srp);
|
|
|
+ AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_SERVER_SIDE));
|
|
|
+
|
|
|
+ /* invalid params */
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpSetVerifier(NULL, v, vSz));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpSetVerifier(&srp, NULL, vSz));
|
|
|
+
|
|
|
+ /* success */
|
|
|
+ AssertIntEQ(0, wc_SrpSetVerifier(&srp, v, vSz));
|
|
|
+
|
|
|
+ wc_SrpTerm(&srp);
|
|
|
+}
|
|
|
+
|
|
|
+static void test_SrpGetPublic(void)
|
|
|
+{
|
|
|
+ Srp srp;
|
|
|
+ byte public[64];
|
|
|
+ word32 publicSz = 0;
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
|
|
|
+ AssertIntEQ(0, wc_SrpSetUsername(&srp, username, usernameSz));
|
|
|
+ AssertIntEQ(0, wc_SrpSetParams(&srp, N, sizeof(N),
|
|
|
+ g, sizeof(g),
|
|
|
+ salt, sizeof(salt)));
|
|
|
+
|
|
|
+ /* invalid call order */
|
|
|
+ AssertIntEQ(SRP_CALL_ORDER_E, wc_SrpGetPublic(&srp, public, &publicSz));
|
|
|
+
|
|
|
+ /* fix call order */
|
|
|
+ AssertIntEQ(0, wc_SrpSetPassword(&srp, password, passwordSz));
|
|
|
+
|
|
|
+ /* invalid params */
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpGetPublic(NULL, public, &publicSz));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpGetPublic(&srp, NULL, &publicSz));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpGetPublic(&srp, public, NULL));
|
|
|
+ AssertIntEQ(BUFFER_E, wc_SrpGetPublic(&srp, public, &publicSz));
|
|
|
+
|
|
|
+ /* success */
|
|
|
+ publicSz = sizeof(public);
|
|
|
+ AssertIntEQ(0, wc_SrpSetPrivate(&srp, a, sizeof(a)));
|
|
|
+ AssertIntEQ(0, wc_SrpGetPublic(&srp, public, &publicSz));
|
|
|
+ AssertIntEQ(publicSz, sizeof(A));
|
|
|
+ AssertIntEQ(0, XMEMCMP(public, A, publicSz));
|
|
|
+
|
|
|
+ wc_SrpTerm(&srp);
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_SERVER_SIDE));
|
|
|
+ AssertIntEQ(0, wc_SrpSetUsername(&srp, username, usernameSz));
|
|
|
+ AssertIntEQ(0, wc_SrpSetParams(&srp, N, sizeof(N),
|
|
|
+ g, sizeof(g),
|
|
|
+ salt, sizeof(salt)));
|
|
|
+
|
|
|
+ /* invalid call order */
|
|
|
+ AssertIntEQ(SRP_CALL_ORDER_E, wc_SrpGetPublic(&srp, public, &publicSz));
|
|
|
+
|
|
|
+ /* fix call order */
|
|
|
+ AssertIntEQ(0, wc_SrpSetVerifier(&srp, verifier, sizeof(verifier)));
|
|
|
+
|
|
|
+ /* success */
|
|
|
+ AssertIntEQ(0, wc_SrpSetPrivate(&srp, b, sizeof(b)));
|
|
|
+ AssertIntEQ(0, wc_SrpGetPublic(&srp, public, &publicSz));
|
|
|
+ AssertIntEQ(publicSz, sizeof(B));
|
|
|
+ AssertIntEQ(0, XMEMCMP(public, B, publicSz));
|
|
|
+
|
|
|
+ wc_SrpTerm(&srp);
|
|
|
+}
|
|
|
+
|
|
|
+static void test_SrpComputeKey(void)
|
|
|
+{
|
|
|
+ Srp cli, srv;
|
|
|
+ byte clientPubKey[64];
|
|
|
+ byte serverPubKey[64];
|
|
|
+ word32 clientPubKeySz = 64;
|
|
|
+ word32 serverPubKeySz = 64;
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpInit(&cli, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
|
|
|
+ AssertIntEQ(0, wc_SrpInit(&srv, SRP_TYPE_SHA, SRP_SERVER_SIDE));
|
|
|
+
|
|
|
+ /* invalid call order */
|
|
|
+ AssertIntEQ(SRP_CALL_ORDER_E, wc_SrpComputeKey(&cli,
|
|
|
+ clientPubKey, clientPubKeySz,
|
|
|
+ serverPubKey, serverPubKeySz));
|
|
|
+
|
|
|
+ /* fix call order */
|
|
|
+ AssertIntEQ(0, wc_SrpSetUsername(&cli, username, usernameSz));
|
|
|
+ AssertIntEQ(0, wc_SrpSetUsername(&srv, username, usernameSz));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpSetParams(&cli, N, sizeof(N),
|
|
|
+ g, sizeof(g),
|
|
|
+ salt, sizeof(salt)));
|
|
|
+ AssertIntEQ(0, wc_SrpSetParams(&srv, N, sizeof(N),
|
|
|
+ g, sizeof(g),
|
|
|
+ salt, sizeof(salt)));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpSetPassword(&cli, password, passwordSz));
|
|
|
+ AssertIntEQ(0, wc_SrpSetVerifier(&srv, verifier, sizeof(verifier)));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpSetPrivate(&cli, a, sizeof(a)));
|
|
|
+ AssertIntEQ(0, wc_SrpGetPublic(&cli, clientPubKey, &clientPubKeySz));
|
|
|
+ AssertIntEQ(0, XMEMCMP(clientPubKey, A, clientPubKeySz));
|
|
|
+ AssertIntEQ(0, wc_SrpSetPrivate(&srv, b, sizeof(b)));
|
|
|
+ AssertIntEQ(0, wc_SrpGetPublic(&srv, serverPubKey, &serverPubKeySz));
|
|
|
+ AssertIntEQ(0, XMEMCMP(serverPubKey, B, serverPubKeySz));
|
|
|
+
|
|
|
+ /* invalid params */
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpComputeKey(NULL,
|
|
|
+ clientPubKey, clientPubKeySz,
|
|
|
+ serverPubKey, serverPubKeySz));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpComputeKey(&cli,
|
|
|
+ NULL, clientPubKeySz,
|
|
|
+ serverPubKey, serverPubKeySz));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpComputeKey(&cli,
|
|
|
+ clientPubKey, 0,
|
|
|
+ serverPubKey, serverPubKeySz));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpComputeKey(&cli,
|
|
|
+ clientPubKey, clientPubKeySz,
|
|
|
+ NULL, serverPubKeySz));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpComputeKey(&cli,
|
|
|
+ clientPubKey, clientPubKeySz,
|
|
|
+ serverPubKey, 0));
|
|
|
+
|
|
|
+ /* success */
|
|
|
+ AssertIntEQ(0, wc_SrpComputeKey(&cli, clientPubKey, clientPubKeySz,
|
|
|
+ serverPubKey, serverPubKeySz));
|
|
|
+ AssertIntEQ(0, wc_SrpComputeKey(&srv, clientPubKey, clientPubKeySz,
|
|
|
+ serverPubKey, serverPubKeySz));
|
|
|
+ AssertIntEQ(0, XMEMCMP(cli.key, key, sizeof(key)));
|
|
|
+ AssertIntEQ(0, XMEMCMP(srv.key, key, sizeof(key)));
|
|
|
+
|
|
|
+ wc_SrpTerm(&cli);
|
|
|
+ wc_SrpTerm(&srv);
|
|
|
+}
|
|
|
+
|
|
|
+static void test_SrpGetProofAndVerify(void)
|
|
|
+{
|
|
|
+ Srp cli, srv;
|
|
|
+ byte clientPubKey[64];
|
|
|
+ byte serverPubKey[64];
|
|
|
+ word32 clientPubKeySz = 64;
|
|
|
+ word32 serverPubKeySz = 64;
|
|
|
+ byte clientProof[SRP_MAX_DIGEST_SIZE];
|
|
|
+ byte serverProof[SRP_MAX_DIGEST_SIZE];
|
|
|
+ word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
|
|
|
+ word32 serverProofSz = SRP_MAX_DIGEST_SIZE;
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpInit(&cli, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
|
|
|
+ AssertIntEQ(0, wc_SrpInit(&srv, SRP_TYPE_SHA, SRP_SERVER_SIDE));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpSetUsername(&cli, username, usernameSz));
|
|
|
+ AssertIntEQ(0, wc_SrpSetUsername(&srv, username, usernameSz));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpSetParams(&cli, N, sizeof(N),
|
|
|
+ g, sizeof(g),
|
|
|
+ salt, sizeof(salt)));
|
|
|
+ AssertIntEQ(0, wc_SrpSetParams(&srv, N, sizeof(N),
|
|
|
+ g, sizeof(g),
|
|
|
+ salt, sizeof(salt)));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpSetPassword(&cli, password, passwordSz));
|
|
|
+ AssertIntEQ(0, wc_SrpSetVerifier(&srv, verifier, sizeof(verifier)));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpSetPrivate(&cli, a, sizeof(a)));
|
|
|
+ AssertIntEQ(0, wc_SrpGetPublic(&cli, clientPubKey, &clientPubKeySz));
|
|
|
+ AssertIntEQ(0, XMEMCMP(clientPubKey, A, clientPubKeySz));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpSetPrivate(&srv, b, sizeof(b)));
|
|
|
+ AssertIntEQ(0, wc_SrpGetPublic(&srv, serverPubKey, &serverPubKeySz));
|
|
|
+ AssertIntEQ(0, XMEMCMP(serverPubKey, B, serverPubKeySz));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpComputeKey(&cli, clientPubKey, clientPubKeySz,
|
|
|
+ serverPubKey, serverPubKeySz));
|
|
|
+ AssertIntEQ(0, XMEMCMP(cli.key, key, sizeof(key)));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpComputeKey(&srv, clientPubKey, clientPubKeySz,
|
|
|
+ serverPubKey, serverPubKeySz));
|
|
|
+ AssertIntEQ(0, XMEMCMP(srv.key, key, sizeof(key)));
|
|
|
+
|
|
|
+ /* invalid params */
|
|
|
+ serverProofSz = 0;
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpGetProof(NULL, clientProof,&clientProofSz));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpGetProof(&cli, NULL, &clientProofSz));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG, wc_SrpGetProof(&cli, clientProof,NULL));
|
|
|
+ AssertIntEQ(BUFFER_E, wc_SrpGetProof(&srv, serverProof,&serverProofSz));
|
|
|
+
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG,
|
|
|
+ wc_SrpVerifyPeersProof(NULL, clientProof, clientProofSz));
|
|
|
+ AssertIntEQ(BAD_FUNC_ARG,
|
|
|
+ wc_SrpVerifyPeersProof(&cli, NULL, clientProofSz));
|
|
|
+ AssertIntEQ(BUFFER_E,
|
|
|
+ wc_SrpVerifyPeersProof(&srv, serverProof, serverProofSz));
|
|
|
+ serverProofSz = SRP_MAX_DIGEST_SIZE;
|
|
|
+
|
|
|
+ /* success */
|
|
|
+ AssertIntEQ(0, wc_SrpGetProof(&cli, clientProof, &clientProofSz));
|
|
|
+ AssertIntEQ(0, XMEMCMP(clientProof, client_proof, sizeof(client_proof)));
|
|
|
+ AssertIntEQ(0, wc_SrpVerifyPeersProof(&srv, clientProof, clientProofSz));
|
|
|
+ AssertIntEQ(0, wc_SrpGetProof(&srv, serverProof, &serverProofSz));
|
|
|
+ AssertIntEQ(0, XMEMCMP(serverProof, server_proof, sizeof(server_proof)));
|
|
|
+ AssertIntEQ(0, wc_SrpVerifyPeersProof(&cli, serverProof, serverProofSz));
|
|
|
+
|
|
|
+ wc_SrpTerm(&cli);
|
|
|
+ wc_SrpTerm(&srv);
|
|
|
+}
|
|
|
+
|
|
|
+static int sha512_key_gen(Srp* srp, byte* secret, word32 size)
|
|
|
+{
|
|
|
+ Sha512 hash;
|
|
|
+ int r;
|
|
|
+
|
|
|
+ srp->key = (byte*)XMALLOC(SHA512_DIGEST_SIZE, NULL, DYNAMIC_TYPE_SRP);
|
|
|
+ if (srp->key == NULL)
|
|
|
+ return MEMORY_E;
|
|
|
+
|
|
|
+ srp->keySz = SHA512_DIGEST_SIZE;
|
|
|
+
|
|
|
+ r = wc_InitSha512(&hash);
|
|
|
+ if (!r) r = wc_Sha512Update(&hash, secret, size);
|
|
|
+ if (!r) r = wc_Sha512Final(&hash, srp->key);
|
|
|
+
|
|
|
+ XMEMSET(&hash, 0, sizeof(Sha512));
|
|
|
+
|
|
|
+ return r;
|
|
|
+}
|
|
|
+
|
|
|
+static void test_SrpKeyGenFunc_cb(void)
|
|
|
+{
|
|
|
+ Srp cli, srv;
|
|
|
+ byte clientPubKey[1024];
|
|
|
+ byte serverPubKey[1024];
|
|
|
+ word32 clientPubKeySz = 1024;
|
|
|
+ word32 serverPubKeySz = 1024;
|
|
|
+ byte clientProof[SRP_MAX_DIGEST_SIZE];
|
|
|
+ byte serverProof[SRP_MAX_DIGEST_SIZE];
|
|
|
+ word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
|
|
|
+ word32 serverProofSz = SRP_MAX_DIGEST_SIZE;
|
|
|
+
|
|
|
+ byte username_[] = "alice";
|
|
|
+ word32 usernameSz_ = 5;
|
|
|
+
|
|
|
+ byte password_[] = "password123";
|
|
|
+ word32 passwordSz_ = 11;
|
|
|
+
|
|
|
+ byte N_[] = {
|
|
|
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2,
|
|
|
+ 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
|
|
|
+ 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6,
|
|
|
+ 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
|
|
|
+ 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D,
|
|
|
+ 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
|
|
|
+ 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9,
|
|
|
+ 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
|
|
|
+ 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11,
|
|
|
+ 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D,
|
|
|
+ 0xC2, 0x00, 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E_SHA512, SRP_CLIENT_SIDE));
|
|
|
+ AssertIntEQ(0, wc_SrpInit(&srv, SRP_TYPE_SHA512, SRP_SERVER_SIDE));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpSetUsername(&cli, username_, usernameSz_));
|
|
|
+ AssertIntEQ(0, wc_SrpSetUsername(&srv, username_, usernameSz_));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpSetParams(&cli, N_, sizeof(N_),
|
|
|
+ g_, sizeof(g_),
|
|
|
+ salt_, sizeof(salt_)));
|
|
|
+ AssertIntEQ(0, wc_SrpSetParams(&srv, N_, sizeof(N_),
|
|
|
+ g_, sizeof(g_),
|
|
|
+ salt_, sizeof(salt_)));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpSetPassword(&cli, password_, passwordSz_));
|
|
|
+ AssertIntEQ(0, wc_SrpSetVerifier(&srv, verifier_, sizeof(verifier_)));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpSetPrivate(&cli, a_, sizeof(a_)));
|
|
|
+ AssertIntEQ(0, wc_SrpGetPublic(&cli, clientPubKey, &clientPubKeySz));
|
|
|
+ AssertIntEQ(0, XMEMCMP(clientPubKey, A_, clientPubKeySz));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpSetPrivate(&srv, b_, sizeof(b_)));
|
|
|
+ AssertIntEQ(0, wc_SrpGetPublic(&srv, serverPubKey, &serverPubKeySz));
|
|
|
+ AssertIntEQ(0, XMEMCMP(serverPubKey, B_, serverPubKeySz));
|
|
|
+
|
|
|
+ cli.keyGenFunc_cb = sha512_key_gen;
|
|
|
+ AssertIntEQ(0, wc_SrpComputeKey(&cli, clientPubKey, clientPubKeySz,
|
|
|
+ serverPubKey, serverPubKeySz));
|
|
|
+ AssertIntEQ(0, XMEMCMP(cli.key, key_, sizeof(key_)));
|
|
|
+
|
|
|
+ srv.keyGenFunc_cb = sha512_key_gen;
|
|
|
+ AssertIntEQ(0, wc_SrpComputeKey(&srv, clientPubKey, clientPubKeySz,
|
|
|
+ serverPubKey, serverPubKeySz));
|
|
|
+ AssertIntEQ(0, XMEMCMP(srv.key, key_, sizeof(key_)));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpGetProof(&cli, clientProof, &clientProofSz));
|
|
|
+ AssertIntEQ(0, wc_SrpVerifyPeersProof(&srv, clientProof, clientProofSz));
|
|
|
+
|
|
|
+ AssertIntEQ(0, wc_SrpGetProof(&srv, serverProof, &serverProofSz));
|
|
|
+ AssertIntEQ(0, wc_SrpVerifyPeersProof(&cli, serverProof, serverProofSz));
|
|
|
+
|
|
|
+ wc_SrpTerm(&cli);
|
|
|
+ wc_SrpTerm(&srv);
|
|
|
+}
|
|
|
+
|
|
|
+#endif
|
|
|
+
|
|
|
+void SrpTest(void)
|
|
|
+{
|
|
|
+#ifdef WOLFCRYPT_HAVE_SRP
|
|
|
+ test_SrpInit();
|
|
|
+ test_SrpSetUsername();
|
|
|
+ test_SrpSetParams();
|
|
|
+ test_SrpSetPassword();
|
|
|
+ test_SrpGetPublic();
|
|
|
+ test_SrpComputeKey();
|
|
|
+ test_SrpGetProofAndVerify();
|
|
|
+ test_SrpKeyGenFunc_cb();
|
|
|
+#endif
|
|
|
+}
|