srp.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. /* srp.c SRP unit tests
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #ifndef WOLFSSL_USER_SETTINGS
  25. #include <wolfssl/options.h>
  26. #endif
  27. #include <wolfssl/wolfcrypt/settings.h>
  28. #include <tests/unit.h>
  29. #include <wolfssl/wolfcrypt/sha512.h>
  30. #include <wolfssl/wolfcrypt/srp.h>
  31. #if defined(WOLFCRYPT_HAVE_SRP) && defined(WOLFSSL_SHA512)
  32. static byte username[] = "user";
  33. static word32 usernameSz = 4;
  34. static byte srp_N[] = {
  35. 0xD4, 0xC7, 0xF8, 0xA2, 0xB3, 0x2C, 0x11, 0xB8, 0xFB, 0xA9, 0x58, 0x1E,
  36. 0xC4, 0xBA, 0x4F, 0x1B, 0x04, 0x21, 0x56, 0x42, 0xEF, 0x73, 0x55, 0xE3,
  37. 0x7C, 0x0F, 0xC0, 0x44, 0x3E, 0xF7, 0x56, 0xEA, 0x2C, 0x6B, 0x8E, 0xEB,
  38. 0x75, 0x5A, 0x1C, 0x72, 0x30, 0x27, 0x66, 0x3C, 0xAA, 0x26, 0x5E, 0xF7,
  39. 0x85, 0xB8, 0xFF, 0x6A, 0x9B, 0x35, 0x22, 0x7A, 0x52, 0xD8, 0x66, 0x33,
  40. 0xDB, 0xDF, 0xCA, 0x43
  41. };
  42. static byte srp_g[] = {
  43. 0x02
  44. };
  45. static byte srp_salt[] = {
  46. 0x80, 0x66, 0x61, 0x5B, 0x7D, 0x33, 0xA2, 0x2E, 0x79, 0x18
  47. };
  48. #ifdef NO_SHA
  49. #define SRP_TYPE_TEST_DEFAULT SRP_TYPE_SHA256
  50. #else /* SHA-1 */
  51. #define SRP_TYPE_TEST_DEFAULT SRP_TYPE_SHA
  52. static byte password[] = "password";
  53. static word32 passwordSz = 8;
  54. static byte srp_verifier[] = {
  55. 0x24, 0x5F, 0xA5, 0x1B, 0x2A, 0x28, 0xF8, 0xFF, 0xE2, 0xA0, 0xF8, 0x61,
  56. 0x7B, 0x0F, 0x3C, 0x05, 0xD6, 0x4A, 0x55, 0xDF, 0x74, 0x31, 0x54, 0x47,
  57. 0xA1, 0xFA, 0x9D, 0x25, 0x7B, 0x02, 0x88, 0x0A, 0xE8, 0x5A, 0xBA, 0x8B,
  58. 0xA2, 0xD3, 0x8A, 0x62, 0x46, 0x8C, 0xEC, 0x52, 0xBE, 0xDE, 0xFC, 0x75,
  59. 0xF5, 0xDB, 0x9C, 0x8C, 0x9B, 0x34, 0x7A, 0xE7, 0x4A, 0x5F, 0xBB, 0x96,
  60. 0x38, 0x19, 0xAB, 0x24
  61. };
  62. static byte srp_a[] = {
  63. 0x37, 0x95, 0xF2, 0xA6, 0xF1, 0x6F, 0x0D, 0x58, 0xBF, 0xED, 0x44, 0x87,
  64. 0xE0, 0xB6, 0xCC, 0x1C, 0xA0, 0x50, 0xC6, 0x61, 0xBB, 0x36, 0xE0, 0x9A,
  65. 0xF3, 0xF7, 0x1E, 0x7A, 0x61, 0x86, 0x5A, 0xF5
  66. };
  67. static byte srp_A[] = {
  68. 0x8D, 0x28, 0xC5, 0x6A, 0x46, 0x5C, 0x82, 0xDB, 0xC7, 0xF6, 0x8B, 0x62,
  69. 0x1A, 0xAD, 0xA1, 0x76, 0x1B, 0x55, 0xFF, 0xAB, 0x10, 0x2F, 0xFF, 0x4A,
  70. 0xAA, 0x46, 0xAD, 0x33, 0x64, 0xDE, 0x28, 0x2E, 0x82, 0x7A, 0xBE, 0xEA,
  71. 0x32, 0xFC, 0xD6, 0x14, 0x01, 0x71, 0xE6, 0xC8, 0xC9, 0x53, 0x69, 0x55,
  72. 0xE1, 0xF8, 0x3D, 0xDD, 0xC7, 0xD5, 0x21, 0xCE, 0xFF, 0x17, 0xFC, 0x23,
  73. 0xBF, 0xCF, 0x2D, 0xB0
  74. };
  75. static byte srp_b[] = {
  76. 0x2B, 0xDD, 0x30, 0x30, 0x53, 0xAF, 0xD8, 0x3A, 0xE7, 0xE0, 0x17, 0x82,
  77. 0x39, 0x44, 0x2C, 0xDB, 0x30, 0x88, 0x0F, 0xC8, 0x88, 0xC2, 0xB2, 0xC1,
  78. 0x78, 0x43, 0x2F, 0xD5, 0x60, 0xD4, 0xDA, 0x43
  79. };
  80. static byte srp_B[] = {
  81. 0xB5, 0x80, 0x36, 0x7F, 0x50, 0x89, 0xC1, 0x04, 0x42, 0x98, 0xD7, 0x6A,
  82. 0x37, 0x8E, 0xF1, 0x81, 0x52, 0xC5, 0x7A, 0xA1, 0xD5, 0xB7, 0x66, 0x84,
  83. 0xA1, 0x3E, 0x32, 0x82, 0x2B, 0x3A, 0xB5, 0xD7, 0x3D, 0x50, 0xF1, 0x58,
  84. 0xBD, 0x89, 0x75, 0xC7, 0x51, 0xCF, 0x6C, 0x03, 0xD4, 0xCA, 0xD5, 0x6E,
  85. 0x97, 0x4D, 0xA3, 0x1E, 0x19, 0x0B, 0xF0, 0xAA, 0x7D, 0x14, 0x90, 0x80,
  86. 0x0E, 0xC7, 0x92, 0xAD
  87. };
  88. static byte srp_key[] = {
  89. 0x66, 0x00, 0x9D, 0x58, 0xB3, 0xD2, 0x0D, 0x4B, 0x69, 0x7F, 0xCF, 0x48,
  90. 0xFF, 0x8F, 0x15, 0x81, 0x4C, 0x4B, 0xFE, 0x9D, 0x85, 0x77, 0x88, 0x60,
  91. 0x1D, 0x1E, 0x51, 0xCF, 0x75, 0xCC, 0x58, 0x00, 0xE7, 0x8D, 0x22, 0x87,
  92. 0x13, 0x6C, 0x88, 0x55
  93. };
  94. static byte srp_client_proof[] = {
  95. 0x0D, 0x49, 0xE1, 0x9C, 0x3A, 0x88, 0x43, 0x15, 0x45, 0xA8, 0xAC, 0xAB,
  96. 0xEA, 0x15, 0x1A, 0xEE, 0xF9, 0x38, 0x4D, 0x21
  97. };
  98. static byte srp_server_proof[] = {
  99. 0xBD, 0xB1, 0x20, 0x70, 0x46, 0xC9, 0xD6, 0xCC, 0xE2, 0x1D, 0x75, 0xA2,
  100. 0xD0, 0xAF, 0xC5, 0xBC, 0xAE, 0x12, 0xFC, 0x75
  101. };
  102. #endif /* SHA-1 */
  103. static void test_SrpInit(void)
  104. {
  105. Srp srp;
  106. /* invalid params */
  107. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpInit(NULL, SRP_TYPE_TEST_DEFAULT,
  108. SRP_CLIENT_SIDE));
  109. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  110. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpInit(&srp, (SrpType)255, SRP_CLIENT_SIDE));
  111. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpInit(&srp, SRP_TYPE_TEST_DEFAULT,
  112. (SrpSide)255));
  113. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  114. /* success */
  115. AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_TEST_DEFAULT, SRP_CLIENT_SIDE));
  116. wc_SrpTerm(&srp);
  117. }
  118. static void test_SrpSetUsername(void)
  119. {
  120. Srp srp;
  121. AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_TEST_DEFAULT, SRP_CLIENT_SIDE));
  122. /* invalid params */
  123. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpSetUsername(NULL, username, usernameSz));
  124. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpSetUsername(&srp, NULL, usernameSz));
  125. /* success */
  126. AssertIntEQ(0, wc_SrpSetUsername(&srp, username, usernameSz));
  127. AssertIntEQ((int) usernameSz, srp.userSz);
  128. AssertIntEQ(0, XMEMCMP(srp.user, username, usernameSz));
  129. wc_SrpTerm(&srp);
  130. }
  131. static void test_SrpSetParams(void)
  132. {
  133. Srp srp;
  134. AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_TEST_DEFAULT, SRP_CLIENT_SIDE));
  135. /* invalid call order */
  136. AssertIntEQ(WC_NO_ERR_TRACE(SRP_CALL_ORDER_E), wc_SrpSetParams(&srp,
  137. srp_N, sizeof(srp_N),
  138. srp_g, sizeof(srp_g),
  139. srp_salt, sizeof(srp_salt)));
  140. /* fix call order */
  141. AssertIntEQ(0, wc_SrpSetUsername(&srp, username, usernameSz));
  142. /* invalid params */
  143. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpSetParams(NULL,
  144. srp_N, sizeof(srp_N),
  145. srp_g, sizeof(srp_g),
  146. srp_salt, sizeof(srp_salt)));
  147. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpSetParams(&srp,
  148. NULL, sizeof(srp_N),
  149. srp_g, sizeof(srp_g),
  150. srp_salt, sizeof(srp_salt)));
  151. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpSetParams(&srp,
  152. srp_N, sizeof(srp_N),
  153. NULL, sizeof(srp_g),
  154. srp_salt, sizeof(srp_salt)));
  155. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpSetParams(&srp,
  156. srp_N, sizeof(srp_N),
  157. srp_g, sizeof(srp_g),
  158. NULL, sizeof(srp_salt)));
  159. /* success */
  160. AssertIntEQ(0, wc_SrpSetParams(&srp, srp_N, sizeof(srp_N),
  161. srp_g, sizeof(srp_g),
  162. srp_salt, sizeof(srp_salt)));
  163. AssertIntEQ(sizeof(srp_salt), srp.saltSz);
  164. AssertIntEQ(0, XMEMCMP(srp.salt, srp_salt, srp.saltSz));
  165. wc_SrpTerm(&srp);
  166. }
  167. #ifndef NO_SHA
  168. static void test_SrpSetPassword(void)
  169. {
  170. Srp srp;
  171. byte v[64];
  172. word32 vSz = 0;
  173. XMEMSET(v, 0, sizeof(v));
  174. AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
  175. AssertIntEQ(0, wc_SrpSetUsername(&srp, username, usernameSz));
  176. /* invalid call order */
  177. AssertIntEQ(WC_NO_ERR_TRACE(SRP_CALL_ORDER_E),
  178. wc_SrpSetPassword(&srp, password, passwordSz));
  179. AssertIntEQ(WC_NO_ERR_TRACE(SRP_CALL_ORDER_E),
  180. wc_SrpGetVerifier(&srp, v, &vSz));
  181. /* fix call order */
  182. AssertIntEQ(0, wc_SrpSetParams(&srp, srp_N, sizeof(srp_N),
  183. srp_g, sizeof(srp_g),
  184. srp_salt, sizeof(srp_salt)));
  185. /* invalid params */
  186. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpSetPassword(NULL, password, passwordSz));
  187. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpSetPassword(&srp, NULL, passwordSz));
  188. /* success */
  189. AssertIntEQ(0, wc_SrpSetPassword(&srp, password, passwordSz));
  190. /* invalid params */
  191. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpGetVerifier(NULL, v, &vSz));
  192. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpGetVerifier(&srp, NULL, &vSz));
  193. AssertIntEQ(WC_NO_ERR_TRACE(BUFFER_E), wc_SrpGetVerifier(&srp, v, &vSz));
  194. /* success */
  195. vSz = sizeof(v);
  196. AssertIntEQ(0, wc_SrpGetVerifier(&srp, v, &vSz));
  197. AssertIntEQ(vSz, sizeof(srp_verifier));
  198. AssertIntEQ(0, XMEMCMP(srp_verifier, v, vSz));
  199. /* invalid params - client side srp */
  200. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpSetVerifier(&srp, v, vSz));
  201. wc_SrpTerm(&srp);
  202. AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_SERVER_SIDE));
  203. /* invalid params */
  204. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpSetVerifier(NULL, v, vSz));
  205. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpSetVerifier(&srp, NULL, vSz));
  206. /* success */
  207. AssertIntEQ(0, wc_SrpSetVerifier(&srp, v, vSz));
  208. wc_SrpTerm(&srp);
  209. }
  210. static void test_SrpGetPublic(void)
  211. {
  212. Srp srp;
  213. byte pub[64];
  214. word32 pubSz = 0;
  215. XMEMSET(pub, 0, sizeof(pub));
  216. AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
  217. AssertIntEQ(0, wc_SrpSetUsername(&srp, username, usernameSz));
  218. AssertIntEQ(0, wc_SrpSetParams(&srp, srp_N, sizeof(srp_N),
  219. srp_g, sizeof(srp_g),
  220. srp_salt, sizeof(srp_salt)));
  221. /* invalid call order */
  222. AssertIntEQ(WC_NO_ERR_TRACE(SRP_CALL_ORDER_E), wc_SrpGetPublic(&srp, pub, &pubSz));
  223. /* fix call order */
  224. AssertIntEQ(0, wc_SrpSetPassword(&srp, password, passwordSz));
  225. /* invalid params */
  226. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpGetPublic(NULL, pub, &pubSz));
  227. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpGetPublic(&srp, NULL, &pubSz));
  228. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpGetPublic(&srp, pub, NULL));
  229. AssertIntEQ(WC_NO_ERR_TRACE(BUFFER_E), wc_SrpGetPublic(&srp, pub, &pubSz));
  230. /* success */
  231. pubSz = sizeof(pub);
  232. AssertIntEQ(0, wc_SrpSetPrivate(&srp, srp_a, sizeof(srp_a)));
  233. AssertIntEQ(0, wc_SrpGetPublic(&srp, pub, &pubSz));
  234. AssertIntEQ(pubSz, sizeof(srp_A));
  235. AssertIntEQ(0, XMEMCMP(pub, srp_A, pubSz));
  236. wc_SrpTerm(&srp);
  237. AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_SERVER_SIDE));
  238. AssertIntEQ(0, wc_SrpSetUsername(&srp, username, usernameSz));
  239. AssertIntEQ(0, wc_SrpSetParams(&srp, srp_N, sizeof(srp_N),
  240. srp_g, sizeof(srp_g),
  241. srp_salt, sizeof(srp_salt)));
  242. /* invalid call order */
  243. AssertIntEQ(WC_NO_ERR_TRACE(SRP_CALL_ORDER_E), wc_SrpGetPublic(&srp, pub, &pubSz));
  244. /* fix call order */
  245. AssertIntEQ(0, wc_SrpSetVerifier(&srp, srp_verifier, sizeof(srp_verifier)));
  246. /* success */
  247. AssertIntEQ(0, wc_SrpSetPrivate(&srp, srp_b, sizeof(srp_b)));
  248. AssertIntEQ(0, wc_SrpGetPublic(&srp, pub, &pubSz));
  249. AssertIntEQ(pubSz, sizeof(srp_B));
  250. AssertIntEQ(0, XMEMCMP(pub, srp_B, pubSz));
  251. wc_SrpTerm(&srp);
  252. }
  253. static void test_SrpComputeKey(void)
  254. {
  255. Srp cli, srv;
  256. byte clientPubKey[64];
  257. byte serverPubKey[64];
  258. word32 clientPubKeySz = 64;
  259. word32 serverPubKeySz = 64;
  260. XMEMSET(clientPubKey, 0, sizeof(clientPubKey));
  261. XMEMSET(serverPubKey, 0, sizeof(serverPubKey));
  262. AssertIntEQ(0, wc_SrpInit(&cli, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
  263. AssertIntEQ(0, wc_SrpInit(&srv, SRP_TYPE_SHA, SRP_SERVER_SIDE));
  264. /* invalid call order */
  265. AssertIntEQ(WC_NO_ERR_TRACE(SRP_CALL_ORDER_E), wc_SrpComputeKey(&cli,
  266. clientPubKey, clientPubKeySz,
  267. serverPubKey, serverPubKeySz));
  268. /* fix call order */
  269. AssertIntEQ(0, wc_SrpSetUsername(&cli, username, usernameSz));
  270. AssertIntEQ(0, wc_SrpSetUsername(&srv, username, usernameSz));
  271. AssertIntEQ(0, wc_SrpSetParams(&cli, srp_N, sizeof(srp_N),
  272. srp_g, sizeof(srp_g),
  273. srp_salt, sizeof(srp_salt)));
  274. AssertIntEQ(0, wc_SrpSetParams(&srv, srp_N, sizeof(srp_N),
  275. srp_g, sizeof(srp_g),
  276. srp_salt, sizeof(srp_salt)));
  277. AssertIntEQ(0, wc_SrpSetPassword(&cli, password, passwordSz));
  278. AssertIntEQ(0, wc_SrpSetVerifier(&srv, srp_verifier, sizeof(srp_verifier)));
  279. AssertIntEQ(0, wc_SrpSetPrivate(&cli, srp_a, sizeof(srp_a)));
  280. AssertIntEQ(0, wc_SrpGetPublic(&cli, clientPubKey, &clientPubKeySz));
  281. AssertIntEQ(0, XMEMCMP(clientPubKey, srp_A, clientPubKeySz));
  282. AssertIntEQ(0, wc_SrpSetPrivate(&srv, srp_b, sizeof(srp_b)));
  283. AssertIntEQ(0, wc_SrpGetPublic(&srv, serverPubKey, &serverPubKeySz));
  284. AssertIntEQ(0, XMEMCMP(serverPubKey, srp_B, serverPubKeySz));
  285. /* invalid params */
  286. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpComputeKey(NULL,
  287. clientPubKey, clientPubKeySz,
  288. serverPubKey, serverPubKeySz));
  289. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpComputeKey(&cli,
  290. NULL, clientPubKeySz,
  291. serverPubKey, serverPubKeySz));
  292. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpComputeKey(&cli,
  293. clientPubKey, 0,
  294. serverPubKey, serverPubKeySz));
  295. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpComputeKey(&cli,
  296. clientPubKey, clientPubKeySz,
  297. NULL, serverPubKeySz));
  298. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpComputeKey(&cli,
  299. clientPubKey, clientPubKeySz,
  300. serverPubKey, 0));
  301. /* success */
  302. AssertIntEQ(0, wc_SrpComputeKey(&cli, clientPubKey, clientPubKeySz,
  303. serverPubKey, serverPubKeySz));
  304. AssertIntEQ(0, wc_SrpComputeKey(&srv, clientPubKey, clientPubKeySz,
  305. serverPubKey, serverPubKeySz));
  306. AssertIntEQ(0, XMEMCMP(cli.key, srp_key, sizeof(srp_key)));
  307. AssertIntEQ(0, XMEMCMP(srv.key, srp_key, sizeof(srp_key)));
  308. wc_SrpTerm(&cli);
  309. wc_SrpTerm(&srv);
  310. }
  311. static void test_SrpGetProofAndVerify(void)
  312. {
  313. Srp cli, srv;
  314. byte clientPubKey[64];
  315. byte serverPubKey[64];
  316. word32 clientPubKeySz = 64;
  317. word32 serverPubKeySz = 64;
  318. byte clientProof[SRP_MAX_DIGEST_SIZE];
  319. byte serverProof[SRP_MAX_DIGEST_SIZE];
  320. word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
  321. word32 serverProofSz = SRP_MAX_DIGEST_SIZE;
  322. XMEMSET(clientPubKey, 0, sizeof(clientPubKey));
  323. XMEMSET(serverPubKey, 0, sizeof(serverPubKey));
  324. XMEMSET(clientProof, 0, sizeof(clientProof));
  325. XMEMSET(serverProof, 0, sizeof(serverProof));
  326. AssertIntEQ(0, wc_SrpInit(&cli, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
  327. AssertIntEQ(0, wc_SrpInit(&srv, SRP_TYPE_SHA, SRP_SERVER_SIDE));
  328. AssertIntEQ(0, wc_SrpSetUsername(&cli, username, usernameSz));
  329. AssertIntEQ(0, wc_SrpSetUsername(&srv, username, usernameSz));
  330. AssertIntEQ(0, wc_SrpSetParams(&cli, srp_N, sizeof(srp_N),
  331. srp_g, sizeof(srp_g),
  332. srp_salt, sizeof(srp_salt)));
  333. AssertIntEQ(0, wc_SrpSetParams(&srv, srp_N, sizeof(srp_N),
  334. srp_g, sizeof(srp_g),
  335. srp_salt, sizeof(srp_salt)));
  336. AssertIntEQ(0, wc_SrpSetPassword(&cli, password, passwordSz));
  337. AssertIntEQ(0, wc_SrpSetVerifier(&srv, srp_verifier, sizeof(srp_verifier)));
  338. AssertIntEQ(0, wc_SrpSetPrivate(&cli, srp_a, sizeof(srp_a)));
  339. AssertIntEQ(0, wc_SrpGetPublic(&cli, clientPubKey, &clientPubKeySz));
  340. AssertIntEQ(0, XMEMCMP(clientPubKey, srp_A, clientPubKeySz));
  341. AssertIntEQ(0, wc_SrpSetPrivate(&srv, srp_b, sizeof(srp_b)));
  342. AssertIntEQ(0, wc_SrpGetPublic(&srv, serverPubKey, &serverPubKeySz));
  343. AssertIntEQ(0, XMEMCMP(serverPubKey, srp_B, serverPubKeySz));
  344. AssertIntEQ(0, wc_SrpComputeKey(&cli, clientPubKey, clientPubKeySz,
  345. serverPubKey, serverPubKeySz));
  346. AssertIntEQ(0, XMEMCMP(cli.key, srp_key, sizeof(srp_key)));
  347. AssertIntEQ(0, wc_SrpComputeKey(&srv, clientPubKey, clientPubKeySz,
  348. serverPubKey, serverPubKeySz));
  349. AssertIntEQ(0, XMEMCMP(srv.key, srp_key, sizeof(srp_key)));
  350. /* invalid params */
  351. serverProofSz = 0;
  352. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpGetProof(NULL, clientProof,&clientProofSz));
  353. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpGetProof(&cli, NULL, &clientProofSz));
  354. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SrpGetProof(&cli, clientProof,NULL));
  355. AssertIntEQ(WC_NO_ERR_TRACE(BUFFER_E), wc_SrpGetProof(&srv, serverProof,&serverProofSz));
  356. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG),
  357. wc_SrpVerifyPeersProof(NULL, clientProof, clientProofSz));
  358. AssertIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG),
  359. wc_SrpVerifyPeersProof(&cli, NULL, clientProofSz));
  360. AssertIntEQ(WC_NO_ERR_TRACE(BUFFER_E),
  361. wc_SrpVerifyPeersProof(&srv, serverProof, serverProofSz));
  362. serverProofSz = SRP_MAX_DIGEST_SIZE;
  363. /* success */
  364. AssertIntEQ(0, wc_SrpGetProof(&cli, clientProof, &clientProofSz));
  365. AssertIntEQ(0, XMEMCMP(clientProof, srp_client_proof,
  366. sizeof(srp_client_proof)));
  367. AssertIntEQ(0, wc_SrpVerifyPeersProof(&srv, clientProof, clientProofSz));
  368. AssertIntEQ(0, wc_SrpGetProof(&srv, serverProof, &serverProofSz));
  369. AssertIntEQ(0, XMEMCMP(serverProof, srp_server_proof,
  370. sizeof(srp_server_proof)));
  371. AssertIntEQ(0, wc_SrpVerifyPeersProof(&cli, serverProof, serverProofSz));
  372. wc_SrpTerm(&cli);
  373. wc_SrpTerm(&srv);
  374. }
  375. #endif /* !NO_SHA */
  376. static int sha512_key_gen(Srp* srp, byte* secret, word32 size)
  377. {
  378. wc_Sha512 hash;
  379. int r;
  380. srp->key = (byte*)XMALLOC(WC_SHA512_DIGEST_SIZE, NULL, DYNAMIC_TYPE_SRP);
  381. if (srp->key == NULL)
  382. return MEMORY_E;
  383. srp->keySz = WC_SHA512_DIGEST_SIZE;
  384. r = wc_InitSha512(&hash);
  385. if (!r) r = wc_Sha512Update(&hash, secret, size);
  386. if (!r) r = wc_Sha512Final(&hash, srp->key);
  387. wc_Sha512Free(&hash);
  388. XMEMSET(&hash, 0, sizeof(wc_Sha512));
  389. return r;
  390. }
  391. static void test_SrpKeyGenFunc_cb(void)
  392. {
  393. Srp cli, srv;
  394. byte clientPubKey[1024];
  395. byte serverPubKey[1024];
  396. word32 clientPubKeySz = 1024;
  397. word32 serverPubKeySz = 1024;
  398. byte clientProof[SRP_MAX_DIGEST_SIZE];
  399. byte serverProof[SRP_MAX_DIGEST_SIZE];
  400. word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
  401. word32 serverProofSz = SRP_MAX_DIGEST_SIZE;
  402. byte username_[] = "alice";
  403. word32 usernameSz_ = 5;
  404. byte password_[] = "password123";
  405. word32 passwordSz_ = 11;
  406. #if !defined(FP_MAX_BITS) || FP_MAX_BITS > 3072 * 2
  407. byte N_[] = {
  408. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2,
  409. 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
  410. 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6,
  411. 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
  412. 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D,
  413. 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
  414. 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9,
  415. 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
  416. 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11,
  417. 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D,
  418. 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36,
  419. 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
  420. 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56,
  421. 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D,
  422. 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08,
  423. 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
  424. 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2,
  425. 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9,
  426. 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C,
  427. 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
  428. 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D,
  429. 0x04, 0x50, 0x7A, 0x33, 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64,
  430. 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, 0x8A, 0xEA, 0x71, 0x57,
  431. 0x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7,
  432. 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0,
  433. 0x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B,
  434. 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73,
  435. 0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C,
  436. 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0,
  437. 0xBA, 0xD9, 0x46, 0xE2, 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31,
  438. 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B, 0x82, 0xD1, 0x20,
  439. 0xA9, 0x3A, 0xD2, 0xCA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  440. };
  441. byte g_[] = {
  442. 0x05
  443. };
  444. byte salt_[] = {
  445. 0xBE, 0xB2, 0x53, 0x79, 0xD1, 0xA8, 0x58, 0x1E, 0xB5, 0xA7, 0x27, 0x67,
  446. 0x3A, 0x24, 0x41, 0xEE
  447. };
  448. byte verifier_[] = {
  449. 0x9B, 0x5E, 0x06, 0x17, 0x01, 0xEA, 0x7A, 0xEB, 0x39, 0xCF, 0x6E, 0x35,
  450. 0x19, 0x65, 0x5A, 0x85, 0x3C, 0xF9, 0x4C, 0x75, 0xCA, 0xF2, 0x55, 0x5E,
  451. 0xF1, 0xFA, 0xF7, 0x59, 0xBB, 0x79, 0xCB, 0x47, 0x70, 0x14, 0xE0, 0x4A,
  452. 0x88, 0xD6, 0x8F, 0xFC, 0x05, 0x32, 0x38, 0x91, 0xD4, 0xC2, 0x05, 0xB8,
  453. 0xDE, 0x81, 0xC2, 0xF2, 0x03, 0xD8, 0xFA, 0xD1, 0xB2, 0x4D, 0x2C, 0x10,
  454. 0x97, 0x37, 0xF1, 0xBE, 0xBB, 0xD7, 0x1F, 0x91, 0x24, 0x47, 0xC4, 0xA0,
  455. 0x3C, 0x26, 0xB9, 0xFA, 0xD8, 0xED, 0xB3, 0xE7, 0x80, 0x77, 0x8E, 0x30,
  456. 0x25, 0x29, 0xED, 0x1E, 0xE1, 0x38, 0xCC, 0xFC, 0x36, 0xD4, 0xBA, 0x31,
  457. 0x3C, 0xC4, 0x8B, 0x14, 0xEA, 0x8C, 0x22, 0xA0, 0x18, 0x6B, 0x22, 0x2E,
  458. 0x65, 0x5F, 0x2D, 0xF5, 0x60, 0x3F, 0xD7, 0x5D, 0xF7, 0x6B, 0x3B, 0x08,
  459. 0xFF, 0x89, 0x50, 0x06, 0x9A, 0xDD, 0x03, 0xA7, 0x54, 0xEE, 0x4A, 0xE8,
  460. 0x85, 0x87, 0xCC, 0xE1, 0xBF, 0xDE, 0x36, 0x79, 0x4D, 0xBA, 0xE4, 0x59,
  461. 0x2B, 0x7B, 0x90, 0x4F, 0x44, 0x2B, 0x04, 0x1C, 0xB1, 0x7A, 0xEB, 0xAD,
  462. 0x1E, 0x3A, 0xEB, 0xE3, 0xCB, 0xE9, 0x9D, 0xE6, 0x5F, 0x4B, 0xB1, 0xFA,
  463. 0x00, 0xB0, 0xE7, 0xAF, 0x06, 0x86, 0x3D, 0xB5, 0x3B, 0x02, 0x25, 0x4E,
  464. 0xC6, 0x6E, 0x78, 0x1E, 0x3B, 0x62, 0xA8, 0x21, 0x2C, 0x86, 0xBE, 0xB0,
  465. 0xD5, 0x0B, 0x5B, 0xA6, 0xD0, 0xB4, 0x78, 0xD8, 0xC4, 0xE9, 0xBB, 0xCE,
  466. 0xC2, 0x17, 0x65, 0x32, 0x6F, 0xBD, 0x14, 0x05, 0x8D, 0x2B, 0xBD, 0xE2,
  467. 0xC3, 0x30, 0x45, 0xF0, 0x38, 0x73, 0xE5, 0x39, 0x48, 0xD7, 0x8B, 0x79,
  468. 0x4F, 0x07, 0x90, 0xE4, 0x8C, 0x36, 0xAE, 0xD6, 0xE8, 0x80, 0xF5, 0x57,
  469. 0x42, 0x7B, 0x2F, 0xC0, 0x6D, 0xB5, 0xE1, 0xE2, 0xE1, 0xD7, 0xE6, 0x61,
  470. 0xAC, 0x48, 0x2D, 0x18, 0xE5, 0x28, 0xD7, 0x29, 0x5E, 0xF7, 0x43, 0x72,
  471. 0x95, 0xFF, 0x1A, 0x72, 0xD4, 0x02, 0x77, 0x17, 0x13, 0xF1, 0x68, 0x76,
  472. 0xDD, 0x05, 0x0A, 0xE5, 0xB7, 0xAD, 0x53, 0xCC, 0xB9, 0x08, 0x55, 0xC9,
  473. 0x39, 0x56, 0x64, 0x83, 0x58, 0xAD, 0xFD, 0x96, 0x64, 0x22, 0xF5, 0x24,
  474. 0x98, 0x73, 0x2D, 0x68, 0xD1, 0xD7, 0xFB, 0xEF, 0x10, 0xD7, 0x80, 0x34,
  475. 0xAB, 0x8D, 0xCB, 0x6F, 0x0F, 0xCF, 0x88, 0x5C, 0xC2, 0xB2, 0xEA, 0x2C,
  476. 0x3E, 0x6A, 0xC8, 0x66, 0x09, 0xEA, 0x05, 0x8A, 0x9D, 0xA8, 0xCC, 0x63,
  477. 0x53, 0x1D, 0xC9, 0x15, 0x41, 0x4D, 0xF5, 0x68, 0xB0, 0x94, 0x82, 0xDD,
  478. 0xAC, 0x19, 0x54, 0xDE, 0xC7, 0xEB, 0x71, 0x4F, 0x6F, 0xF7, 0xD4, 0x4C,
  479. 0xD5, 0xB8, 0x6F, 0x6B, 0xD1, 0x15, 0x81, 0x09, 0x30, 0x63, 0x7C, 0x01,
  480. 0xD0, 0xF6, 0x01, 0x3B, 0xC9, 0x74, 0x0F, 0xA2, 0xC6, 0x33, 0xBA, 0x89
  481. };
  482. byte a_[] = {
  483. 0x60, 0x97, 0x55, 0x27, 0x03, 0x5C, 0xF2, 0xAD, 0x19, 0x89, 0x80, 0x6F,
  484. 0x04, 0x07, 0x21, 0x0B, 0xC8, 0x1E, 0xDC, 0x04, 0xE2, 0x76, 0x2A, 0x56,
  485. 0xAF, 0xD5, 0x29, 0xDD, 0xDA, 0x2D, 0x43, 0x93
  486. };
  487. byte A_[] = {
  488. 0xFA, 0xB6, 0xF5, 0xD2, 0x61, 0x5D, 0x1E, 0x32, 0x35, 0x12, 0xE7, 0x99,
  489. 0x1C, 0xC3, 0x74, 0x43, 0xF4, 0x87, 0xDA, 0x60, 0x4C, 0xA8, 0xC9, 0x23,
  490. 0x0F, 0xCB, 0x04, 0xE5, 0x41, 0xDC, 0xE6, 0x28, 0x0B, 0x27, 0xCA, 0x46,
  491. 0x80, 0xB0, 0x37, 0x4F, 0x17, 0x9D, 0xC3, 0xBD, 0xC7, 0x55, 0x3F, 0xE6,
  492. 0x24, 0x59, 0x79, 0x8C, 0x70, 0x1A, 0xD8, 0x64, 0xA9, 0x13, 0x90, 0xA2,
  493. 0x8C, 0x93, 0xB6, 0x44, 0xAD, 0xBF, 0x9C, 0x00, 0x74, 0x5B, 0x94, 0x2B,
  494. 0x79, 0xF9, 0x01, 0x2A, 0x21, 0xB9, 0xB7, 0x87, 0x82, 0x31, 0x9D, 0x83,
  495. 0xA1, 0xF8, 0x36, 0x28, 0x66, 0xFB, 0xD6, 0xF4, 0x6B, 0xFC, 0x0D, 0xDB,
  496. 0x2E, 0x1A, 0xB6, 0xE4, 0xB4, 0x5A, 0x99, 0x06, 0xB8, 0x2E, 0x37, 0xF0,
  497. 0x5D, 0x6F, 0x97, 0xF6, 0xA3, 0xEB, 0x6E, 0x18, 0x20, 0x79, 0x75, 0x9C,
  498. 0x4F, 0x68, 0x47, 0x83, 0x7B, 0x62, 0x32, 0x1A, 0xC1, 0xB4, 0xFA, 0x68,
  499. 0x64, 0x1F, 0xCB, 0x4B, 0xB9, 0x8D, 0xD6, 0x97, 0xA0, 0xC7, 0x36, 0x41,
  500. 0x38, 0x5F, 0x4B, 0xAB, 0x25, 0xB7, 0x93, 0x58, 0x4C, 0xC3, 0x9F, 0xC8,
  501. 0xD4, 0x8D, 0x4B, 0xD8, 0x67, 0xA9, 0xA3, 0xC1, 0x0F, 0x8E, 0xA1, 0x21,
  502. 0x70, 0x26, 0x8E, 0x34, 0xFE, 0x3B, 0xBE, 0x6F, 0xF8, 0x99, 0x98, 0xD6,
  503. 0x0D, 0xA2, 0xF3, 0xE4, 0x28, 0x3C, 0xBE, 0xC1, 0x39, 0x3D, 0x52, 0xAF,
  504. 0x72, 0x4A, 0x57, 0x23, 0x0C, 0x60, 0x4E, 0x9F, 0xBC, 0xE5, 0x83, 0xD7,
  505. 0x61, 0x3E, 0x6B, 0xFF, 0xD6, 0x75, 0x96, 0xAD, 0x12, 0x1A, 0x87, 0x07,
  506. 0xEE, 0xC4, 0x69, 0x44, 0x95, 0x70, 0x33, 0x68, 0x6A, 0x15, 0x5F, 0x64,
  507. 0x4D, 0x5C, 0x58, 0x63, 0xB4, 0x8F, 0x61, 0xBD, 0xBF, 0x19, 0xA5, 0x3E,
  508. 0xAB, 0x6D, 0xAD, 0x0A, 0x18, 0x6B, 0x8C, 0x15, 0x2E, 0x5F, 0x5D, 0x8C,
  509. 0xAD, 0x4B, 0x0E, 0xF8, 0xAA, 0x4E, 0xA5, 0x00, 0x88, 0x34, 0xC3, 0xCD,
  510. 0x34, 0x2E, 0x5E, 0x0F, 0x16, 0x7A, 0xD0, 0x45, 0x92, 0xCD, 0x8B, 0xD2,
  511. 0x79, 0x63, 0x93, 0x98, 0xEF, 0x9E, 0x11, 0x4D, 0xFA, 0xAA, 0xB9, 0x19,
  512. 0xE1, 0x4E, 0x85, 0x09, 0x89, 0x22, 0x4D, 0xDD, 0x98, 0x57, 0x6D, 0x79,
  513. 0x38, 0x5D, 0x22, 0x10, 0x90, 0x2E, 0x9F, 0x9B, 0x1F, 0x2D, 0x86, 0xCF,
  514. 0xA4, 0x7E, 0xE2, 0x44, 0x63, 0x54, 0x65, 0xF7, 0x10, 0x58, 0x42, 0x1A,
  515. 0x01, 0x84, 0xBE, 0x51, 0xDD, 0x10, 0xCC, 0x9D, 0x07, 0x9E, 0x6F, 0x16,
  516. 0x04, 0xE7, 0xAA, 0x9B, 0x7C, 0xF7, 0x88, 0x3C, 0x7D, 0x4C, 0xE1, 0x2B,
  517. 0x06, 0xEB, 0xE1, 0x60, 0x81, 0xE2, 0x3F, 0x27, 0xA2, 0x31, 0xD1, 0x84,
  518. 0x32, 0xD7, 0xD1, 0xBB, 0x55, 0xC2, 0x8A, 0xE2, 0x1F, 0xFC, 0xF0, 0x05,
  519. 0xF5, 0x75, 0x28, 0xD1, 0x5A, 0x88, 0x88, 0x1B, 0xB3, 0xBB, 0xB7, 0xFE
  520. };
  521. byte b_[] = {
  522. 0xE4, 0x87, 0xCB, 0x59, 0xD3, 0x1A, 0xC5, 0x50, 0x47, 0x1E, 0x81, 0xF0,
  523. 0x0F, 0x69, 0x28, 0xE0, 0x1D, 0xDA, 0x08, 0xE9, 0x74, 0xA0, 0x04, 0xF4,
  524. 0x9E, 0x61, 0xF5, 0xD1, 0x05, 0x28, 0x4D, 0x20
  525. };
  526. byte B_[] = {
  527. 0x40, 0xF5, 0x70, 0x88, 0xA4, 0x82, 0xD4, 0xC7, 0x73, 0x33, 0x84, 0xFE,
  528. 0x0D, 0x30, 0x1F, 0xDD, 0xCA, 0x90, 0x80, 0xAD, 0x7D, 0x4F, 0x6F, 0xDF,
  529. 0x09, 0xA0, 0x10, 0x06, 0xC3, 0xCB, 0x6D, 0x56, 0x2E, 0x41, 0x63, 0x9A,
  530. 0xE8, 0xFA, 0x21, 0xDE, 0x3B, 0x5D, 0xBA, 0x75, 0x85, 0xB2, 0x75, 0x58,
  531. 0x9B, 0xDB, 0x27, 0x98, 0x63, 0xC5, 0x62, 0x80, 0x7B, 0x2B, 0x99, 0x08,
  532. 0x3C, 0xD1, 0x42, 0x9C, 0xDB, 0xE8, 0x9E, 0x25, 0xBF, 0xBD, 0x7E, 0x3C,
  533. 0xAD, 0x31, 0x73, 0xB2, 0xE3, 0xC5, 0xA0, 0xB1, 0x74, 0xDA, 0x6D, 0x53,
  534. 0x91, 0xE6, 0xA0, 0x6E, 0x46, 0x5F, 0x03, 0x7A, 0x40, 0x06, 0x25, 0x48,
  535. 0x39, 0xA5, 0x6B, 0xF7, 0x6D, 0xA8, 0x4B, 0x1C, 0x94, 0xE0, 0xAE, 0x20,
  536. 0x85, 0x76, 0x15, 0x6F, 0xE5, 0xC1, 0x40, 0xA4, 0xBA, 0x4F, 0xFC, 0x9E,
  537. 0x38, 0xC3, 0xB0, 0x7B, 0x88, 0x84, 0x5F, 0xC6, 0xF7, 0xDD, 0xDA, 0x93,
  538. 0x38, 0x1F, 0xE0, 0xCA, 0x60, 0x84, 0xC4, 0xCD, 0x2D, 0x33, 0x6E, 0x54,
  539. 0x51, 0xC4, 0x64, 0xCC, 0xB6, 0xEC, 0x65, 0xE7, 0xD1, 0x6E, 0x54, 0x8A,
  540. 0x27, 0x3E, 0x82, 0x62, 0x84, 0xAF, 0x25, 0x59, 0xB6, 0x26, 0x42, 0x74,
  541. 0x21, 0x59, 0x60, 0xFF, 0xF4, 0x7B, 0xDD, 0x63, 0xD3, 0xAF, 0xF0, 0x64,
  542. 0xD6, 0x13, 0x7A, 0xF7, 0x69, 0x66, 0x1C, 0x9D, 0x4F, 0xEE, 0x47, 0x38,
  543. 0x26, 0x03, 0xC8, 0x8E, 0xAA, 0x09, 0x80, 0x58, 0x1D, 0x07, 0x75, 0x84,
  544. 0x61, 0xB7, 0x77, 0xE4, 0x35, 0x6D, 0xDA, 0x58, 0x35, 0x19, 0x8B, 0x51,
  545. 0xFE, 0xEA, 0x30, 0x8D, 0x70, 0xF7, 0x54, 0x50, 0xB7, 0x16, 0x75, 0xC0,
  546. 0x8C, 0x7D, 0x83, 0x02, 0xFD, 0x75, 0x39, 0xDD, 0x1F, 0xF2, 0xA1, 0x1C,
  547. 0xB4, 0x25, 0x8A, 0xA7, 0x0D, 0x23, 0x44, 0x36, 0xAA, 0x42, 0xB6, 0xA0,
  548. 0x61, 0x5F, 0x3F, 0x91, 0x5D, 0x55, 0xCC, 0x3B, 0x96, 0x6B, 0x27, 0x16,
  549. 0xB3, 0x6E, 0x4D, 0x1A, 0x06, 0xCE, 0x5E, 0x5D, 0x2E, 0xA3, 0xBE, 0xE5,
  550. 0xA1, 0x27, 0x0E, 0x87, 0x51, 0xDA, 0x45, 0xB6, 0x0B, 0x99, 0x7B, 0x0F,
  551. 0xFD, 0xB0, 0xF9, 0x96, 0x2F, 0xEE, 0x4F, 0x03, 0xBE, 0xE7, 0x80, 0xBA,
  552. 0x0A, 0x84, 0x5B, 0x1D, 0x92, 0x71, 0x42, 0x17, 0x83, 0xAE, 0x66, 0x01,
  553. 0xA6, 0x1E, 0xA2, 0xE3, 0x42, 0xE4, 0xF2, 0xE8, 0xBC, 0x93, 0x5A, 0x40,
  554. 0x9E, 0xAD, 0x19, 0xF2, 0x21, 0xBD, 0x1B, 0x74, 0xE2, 0x96, 0x4D, 0xD1,
  555. 0x9F, 0xC8, 0x45, 0xF6, 0x0E, 0xFC, 0x09, 0x33, 0x8B, 0x60, 0xB6, 0xB2,
  556. 0x56, 0xD8, 0xCA, 0xC8, 0x89, 0xCC, 0xA3, 0x06, 0xCC, 0x37, 0x0A, 0x0B,
  557. 0x18, 0xC8, 0xB8, 0x86, 0xE9, 0x5D, 0xA0, 0xAF, 0x52, 0x35, 0xFE, 0xF4,
  558. 0x39, 0x30, 0x20, 0xD2, 0xB7, 0xF3, 0x05, 0x69, 0x04, 0x75, 0x90, 0x42
  559. };
  560. byte key_[] = {
  561. 0x5C, 0xBC, 0x21, 0x9D, 0xB0, 0x52, 0x13, 0x8E, 0xE1, 0x14, 0x8C, 0x71,
  562. 0xCD, 0x44, 0x98, 0x96, 0x3D, 0x68, 0x25, 0x49, 0xCE, 0x91, 0xCA, 0x24,
  563. 0xF0, 0x98, 0x46, 0x8F, 0x06, 0x01, 0x5B, 0xEB, 0x6A, 0xF2, 0x45, 0xC2,
  564. 0x09, 0x3F, 0x98, 0xC3, 0x65, 0x1B, 0xCA, 0x83, 0xAB, 0x8C, 0xAB, 0x2B,
  565. 0x58, 0x0B, 0xBF, 0x02, 0x18, 0x4F, 0xEF, 0xDF, 0x26, 0x14, 0x2F, 0x73,
  566. 0xDF, 0x95, 0xAC, 0x50
  567. };
  568. #else
  569. byte N_[] = {
  570. 0xAC, 0x6B, 0xDB, 0x41, 0x32, 0x4A, 0x9A, 0x9B, 0xF1, 0x66, 0xDE, 0x5E,
  571. 0x13, 0x89, 0x58, 0x2F, 0xAF, 0x72, 0xB6, 0x65, 0x19, 0x87, 0xEE, 0x07,
  572. 0xFC, 0x31, 0x92, 0x94, 0x3D, 0xB5, 0x60, 0x50, 0xA3, 0x73, 0x29, 0xCB,
  573. 0xB4, 0xA0, 0x99, 0xED, 0x81, 0x93, 0xE0, 0x75, 0x77, 0x67, 0xA1, 0x3D,
  574. 0xD5, 0x23, 0x12, 0xAB, 0x4B, 0x03, 0x31, 0x0D, 0xCD, 0x7F, 0x48, 0xA9,
  575. 0xDA, 0x04, 0xFD, 0x50, 0xE8, 0x08, 0x39, 0x69, 0xED, 0xB7, 0x67, 0xB0,
  576. 0xCF, 0x60, 0x95, 0x17, 0x9A, 0x16, 0x3A, 0xB3, 0x66, 0x1A, 0x05, 0xFB,
  577. 0xD5, 0xFA, 0xAA, 0xE8, 0x29, 0x18, 0xA9, 0x96, 0x2F, 0x0B, 0x93, 0xB8,
  578. 0x55, 0xF9, 0x79, 0x93, 0xEC, 0x97, 0x5E, 0xEA, 0xA8, 0x0D, 0x74, 0x0A,
  579. 0xDB, 0xF4, 0xFF, 0x74, 0x73, 0x59, 0xD0, 0x41, 0xD5, 0xC3, 0x3E, 0xA7,
  580. 0x1D, 0x28, 0x1E, 0x44, 0x6B, 0x14, 0x77, 0x3B, 0xCA, 0x97, 0xB4, 0x3A,
  581. 0x23, 0xFB, 0x80, 0x16, 0x76, 0xBD, 0x20, 0x7A, 0x43, 0x6C, 0x64, 0x81,
  582. 0xF1, 0xD2, 0xB9, 0x07, 0x87, 0x17, 0x46, 0x1A, 0x5B, 0x9D, 0x32, 0xE6,
  583. 0x88, 0xF8, 0x77, 0x48, 0x54, 0x45, 0x23, 0xB5, 0x24, 0xB0, 0xD5, 0x7D,
  584. 0x5E, 0xA7, 0x7A, 0x27, 0x75, 0xD2, 0xEC, 0xFA, 0x03, 0x2C, 0xFB, 0xDB,
  585. 0xF5, 0x2F, 0xB3, 0x78, 0x61, 0x60, 0x27, 0x90, 0x04, 0xE5, 0x7A, 0xE6,
  586. 0xAF, 0x87, 0x4E, 0x73, 0x03, 0xCE, 0x53, 0x29, 0x9C, 0xCC, 0x04, 0x1C,
  587. 0x7B, 0xC3, 0x08, 0xD8, 0x2A, 0x56, 0x98, 0xF3, 0xA8, 0xD0, 0xC3, 0x82,
  588. 0x71, 0xAE, 0x35, 0xF8, 0xE9, 0xDB, 0xFB, 0xB6, 0x94, 0xB5, 0xC8, 0x03,
  589. 0xD8, 0x9F, 0x7A, 0xE4, 0x35, 0xDE, 0x23, 0x6D, 0x52, 0x5F, 0x54, 0x75,
  590. 0x9B, 0x65, 0xE3, 0x72, 0xFC, 0xD6, 0x8E, 0xF2, 0x0F, 0xA7, 0x11, 0x1F,
  591. 0x9E, 0x4A, 0xFF, 0x73
  592. };
  593. byte g_[] = {
  594. 0x02
  595. };
  596. byte salt_[] = {
  597. 0xBE, 0xB2, 0x53, 0x79, 0xD1, 0xA8, 0x58, 0x1E, 0xB5, 0xA7, 0x27, 0x67,
  598. 0x3A, 0x24, 0x41, 0xEE
  599. };
  600. byte verifier_[] = {
  601. 0xab, 0x58, 0xc3, 0x49, 0x79, 0xda, 0x9c, 0x1c, 0x0c, 0x5f, 0x6a, 0xe8,
  602. 0xa1, 0xc4, 0x20, 0x78, 0x16, 0xe0, 0x29, 0x6f, 0xdc, 0x09, 0x62, 0xe7,
  603. 0x5d, 0x49, 0x09, 0xd2, 0xd3, 0x48, 0x0b, 0x03, 0xbb, 0xf4, 0x96, 0x58,
  604. 0x93, 0xa5, 0x69, 0xd4, 0x89, 0x10, 0x7f, 0xe2, 0x23, 0x73, 0xf2, 0x8c,
  605. 0xc6, 0x5b, 0x52, 0x5d, 0x2a, 0x2b, 0xa5, 0x23, 0x27, 0xa6, 0x5c, 0xf7,
  606. 0x8d, 0x65, 0x1f, 0xcf, 0x5e, 0x18, 0x70, 0xb7, 0xfd, 0x08, 0x4e, 0xa8,
  607. 0x42, 0xbe, 0x5f, 0x73, 0xf4, 0x8b, 0xa0, 0x4a, 0xf6, 0xfa, 0x85, 0xd2,
  608. 0xd7, 0xf6, 0x4f, 0xc0, 0xc5, 0xba, 0x42, 0x32, 0xc5, 0xbb, 0x57, 0xb2,
  609. 0x60, 0xdb, 0xc4, 0x27, 0x28, 0x4a, 0x7c, 0xdc, 0x5f, 0x64, 0x8a, 0xc2,
  610. 0x51, 0x47, 0x96, 0xd9, 0x9f, 0xd7, 0x64, 0x29, 0x30, 0xe3, 0x64, 0xfa,
  611. 0xd2, 0x42, 0xfa, 0x8b, 0xc9, 0xa0, 0x78, 0xc5, 0xcf, 0x3b, 0x1b, 0x60,
  612. 0x2a, 0xcd, 0x35, 0x8b, 0xfd, 0xbd, 0x62, 0xd6, 0x3b, 0x22, 0x29, 0x1d,
  613. 0xb0, 0xeb, 0xaa, 0x00, 0xdf, 0x99, 0x1f, 0x82, 0xef, 0x9d, 0x1a, 0xad,
  614. 0xe2, 0x4d, 0xa1, 0xca, 0xb2, 0x8f, 0x1d, 0xed, 0x5e, 0xc2, 0xbc, 0x48,
  615. 0xae, 0xe8, 0x5f, 0x52, 0xad, 0xb3, 0xcb, 0xa5, 0x4e, 0xff, 0x52, 0x8c,
  616. 0x9b, 0x11, 0x58, 0xe2, 0xd9, 0x94, 0xcd, 0x6c, 0x66, 0x87, 0xf8, 0xc1,
  617. 0x3c, 0x94, 0x87, 0xce, 0x2c, 0x4a, 0x05, 0x66, 0xc3, 0x20, 0x62, 0x67,
  618. 0x79, 0xc0, 0x33, 0xf1, 0x6e, 0x3f, 0xee, 0xc8, 0xbe, 0x8e, 0x56, 0xc6,
  619. 0x98, 0x72, 0x0e, 0x37, 0x4b, 0x89, 0x4c, 0xba, 0xd9, 0x45, 0xf4, 0x9e,
  620. 0x78, 0x7a, 0x6e, 0x1e, 0xdf, 0xff, 0x23, 0xcf, 0xef, 0xdc, 0x7d, 0x1c,
  621. 0xf1, 0x96, 0x70, 0x2a, 0xa8, 0x6c, 0x20, 0xde, 0xce, 0x6e, 0x3e, 0x89,
  622. 0x11, 0x44, 0x2b, 0x02
  623. };
  624. byte a_[] = {
  625. 0x60, 0x97, 0x55, 0x27, 0x03, 0x5C, 0xF2, 0xAD, 0x19, 0x89, 0x80, 0x6F,
  626. 0x04, 0x07, 0x21, 0x0B, 0xC8, 0x1E, 0xDC, 0x04, 0xE2, 0x76, 0x2A, 0x56,
  627. 0xAF, 0xD5, 0x29, 0xDD, 0xDA, 0x2D, 0x43, 0x93
  628. };
  629. byte A_[] = {
  630. 0x4b, 0x70, 0x0f, 0x8d, 0x48, 0xe6, 0x9c, 0x9a, 0xae, 0x40, 0xc6, 0x84,
  631. 0xac, 0x7c, 0x7c, 0x03, 0x12, 0x1e, 0x2b, 0x76, 0x02, 0xeb, 0x4c, 0x35,
  632. 0x14, 0x80, 0x4c, 0xca, 0xda, 0x0e, 0xd4, 0x01, 0x91, 0x93, 0xa3, 0x51,
  633. 0xec, 0xc6, 0x5a, 0x6f, 0x85, 0x4e, 0xde, 0x91, 0xeb, 0x09, 0x6e, 0x72,
  634. 0x1b, 0x22, 0xd7, 0x01, 0xc7, 0xad, 0xc6, 0x4e, 0x9c, 0xed, 0xac, 0xd7,
  635. 0x5f, 0x2e, 0x26, 0xbb, 0x2f, 0x5e, 0x45, 0xdd, 0x53, 0xdc, 0x8d, 0xbe,
  636. 0xaf, 0xff, 0xe8, 0x2a, 0xa4, 0x9f, 0xca, 0x05, 0x73, 0x44, 0x46, 0x91,
  637. 0x21, 0x25, 0x37, 0xa7, 0x3c, 0xf8, 0x0e, 0x25, 0x03, 0x92, 0x58, 0x20,
  638. 0x5a, 0x7e, 0xdf, 0x47, 0x49, 0xb3, 0x0a, 0xda, 0xf2, 0x58, 0x77, 0xc6,
  639. 0x2f, 0xcd, 0x09, 0xd6, 0x61, 0x35, 0x98, 0xbc, 0xd4, 0xba, 0xf2, 0xa9,
  640. 0x72, 0x7a, 0x53, 0x70, 0x6a, 0x27, 0x81, 0x48, 0x99, 0x2b, 0x2a, 0xbb,
  641. 0x23, 0xad, 0x5d, 0x51, 0x2d, 0x26, 0x9e, 0x16, 0xca, 0x11, 0xbc, 0x08,
  642. 0x95, 0xb5, 0xa3, 0xb5, 0xec, 0x47, 0x21, 0xcd, 0xe4, 0x0a, 0x8c, 0x39,
  643. 0xc7, 0x96, 0xe9, 0x4f, 0x0b, 0xe8, 0x6d, 0xbb, 0xeb, 0x33, 0xda, 0x70,
  644. 0x37, 0x01, 0x89, 0x83, 0x92, 0x1a, 0xba, 0x3f, 0x50, 0x53, 0x19, 0x5d,
  645. 0x5a, 0xc1, 0xda, 0x4e, 0x56, 0x7e, 0x3c, 0x0e, 0x75, 0xd9, 0xe0, 0x60,
  646. 0x9f, 0x92, 0xe8, 0x50, 0x65, 0x7b, 0x2b, 0xe4, 0x77, 0x1f, 0x41, 0x5b,
  647. 0x9c, 0xac, 0xc5, 0xc1, 0xec, 0xed, 0xc3, 0x01, 0x33, 0xbf, 0x64, 0x74,
  648. 0xf5, 0x02, 0x2c, 0x65, 0x19, 0xd7, 0x80, 0x76, 0x0c, 0xa4, 0xd8, 0xd3,
  649. 0xb9, 0x66, 0xb0, 0x34, 0xbd, 0x73, 0x87, 0x7c, 0x1b, 0x3b, 0x33, 0xf4,
  650. 0x74, 0xb9, 0xc3, 0xc5, 0x29, 0x9a, 0x19, 0x68, 0xf3, 0xe6, 0xcd, 0x3b,
  651. 0xfe, 0x84, 0x44, 0x5a
  652. };
  653. byte b_[] = {
  654. 0xE4, 0x87, 0xCB, 0x59, 0xD3, 0x1A, 0xC5, 0x50, 0x47, 0x1E, 0x81, 0xF0,
  655. 0x0F, 0x69, 0x28, 0xE0, 0x1D, 0xDA, 0x08, 0xE9, 0x74, 0xA0, 0x04, 0xF4,
  656. 0x9E, 0x61, 0xF5, 0xD1, 0x05, 0x28, 0x4D, 0x20
  657. };
  658. byte B_[] = {
  659. 0x03, 0xaf, 0xa6, 0xe2, 0x14, 0xf3, 0x63, 0x35, 0xf5, 0x51, 0x1d, 0xae,
  660. 0x57, 0x34, 0x24, 0xf4, 0xc2, 0x18, 0xaf, 0x11, 0xf8, 0xef, 0xc7, 0x14,
  661. 0x44, 0xa6, 0x52, 0x19, 0x7b, 0xae, 0x65, 0xe9, 0x86, 0x5f, 0x45, 0x33,
  662. 0xae, 0xeb, 0x71, 0xd3, 0xfe, 0xa9, 0x7d, 0x26, 0xe0, 0xc9, 0xc7, 0xf2,
  663. 0x2e, 0x4f, 0x95, 0xea, 0xb0, 0x83, 0x1d, 0xad, 0x77, 0xca, 0x32, 0x82,
  664. 0x01, 0x21, 0x00, 0xc5, 0x47, 0x52, 0x67, 0xf1, 0x1b, 0x5c, 0x64, 0xd3,
  665. 0xae, 0x61, 0x1a, 0x7d, 0x76, 0x0e, 0x7d, 0x23, 0x1e, 0x9c, 0xa0, 0x02,
  666. 0x7c, 0x44, 0xa8, 0x6f, 0xf9, 0x27, 0x52, 0xd0, 0xa9, 0xc7, 0xd4, 0xbb,
  667. 0x31, 0x69, 0x39, 0xfc, 0xb7, 0xa7, 0xcd, 0x86, 0xa1, 0x55, 0x71, 0x8a,
  668. 0xb7, 0x48, 0x02, 0x73, 0x16, 0xf5, 0x9d, 0x83, 0x2f, 0xa8, 0x7e, 0x08,
  669. 0x2f, 0x2d, 0xc4, 0xc3, 0xae, 0x6c, 0x65, 0x72, 0x42, 0xc1, 0x74, 0xd9,
  670. 0x95, 0xd0, 0x10, 0xa1, 0x25, 0x9c, 0x5a, 0xf9, 0xa5, 0x08, 0x0d, 0xa2,
  671. 0xed, 0x3a, 0xf1, 0xf7, 0x69, 0xc6, 0x29, 0xf4, 0x47, 0x43, 0x40, 0x7e,
  672. 0x6d, 0x8b, 0xff, 0xae, 0x04, 0xf0, 0x09, 0x1d, 0x5f, 0x64, 0xd4, 0x7c,
  673. 0xb8, 0x47, 0xf3, 0x84, 0xf2, 0x0f, 0x4a, 0x16, 0x32, 0xd1, 0xaf, 0x80,
  674. 0x5a, 0xd6, 0x0b, 0xd8, 0xc5, 0xa4, 0x07, 0x0e, 0xbe, 0x52, 0x35, 0x99,
  675. 0x9a, 0xa1, 0x4f, 0x44, 0x5d, 0xb7, 0x4d, 0x5d, 0xb1, 0xe2, 0xf9, 0x84,
  676. 0x33, 0x6c, 0x51, 0xd6, 0xff, 0x27, 0x64, 0x86, 0x45, 0x56, 0xab, 0x73,
  677. 0x1e, 0xb0, 0x21, 0x6e, 0x65, 0x19, 0x21, 0xf9, 0x97, 0x09, 0xb3, 0xec,
  678. 0x32, 0x38, 0x79, 0x28, 0xe2, 0xd2, 0x03, 0x3a, 0x8d, 0xed, 0x8b, 0x34,
  679. 0xa7, 0xf8, 0x0e, 0x26, 0x5b, 0x60, 0x20, 0x76, 0x43, 0x67, 0xe9, 0xea,
  680. 0x3b, 0x0b, 0xbf, 0x25
  681. };
  682. byte key_[] = {
  683. 0x25, 0x9f, 0xb6, 0xab, 0x17, 0xc4, 0xd8, 0x08, 0x07, 0x57, 0xa4, 0x90,
  684. 0x57, 0x5a, 0x31, 0xff, 0x15, 0x98, 0xb4, 0x2e, 0x86, 0x4e, 0x7a, 0xcd,
  685. 0xe3, 0x02, 0x58, 0x6f, 0xa8, 0x4b, 0x5c, 0xab, 0xcc, 0x91, 0xad, 0x8a,
  686. 0xbd, 0xbe, 0x49, 0x51, 0x75, 0xed, 0x2d, 0xe9, 0x15, 0x8c, 0xfe, 0x19,
  687. 0x68, 0x4a, 0xbf, 0x74, 0xf6, 0xe2, 0x60, 0xa7, 0xad, 0x89, 0x92, 0xdf,
  688. 0x9d, 0x6d, 0x66, 0x4c
  689. };
  690. #endif
  691. XMEMSET(clientPubKey, 0, sizeof(clientPubKey));
  692. XMEMSET(serverPubKey, 0, sizeof(serverPubKey));
  693. XMEMSET(clientProof, 0, sizeof(clientProof));
  694. XMEMSET(serverProof, 0, sizeof(serverProof));
  695. AssertIntEQ(0, wc_SrpInit(&cli, SRP_TYPE_SHA512, SRP_CLIENT_SIDE));
  696. AssertIntEQ(0, wc_SrpInit(&srv, SRP_TYPE_SHA512, SRP_SERVER_SIDE));
  697. AssertIntEQ(0, wc_SrpSetUsername(&cli, username_, usernameSz_));
  698. AssertIntEQ(0, wc_SrpSetUsername(&srv, username_, usernameSz_));
  699. AssertIntEQ(0, wc_SrpSetParams(&cli, N_, sizeof(N_),
  700. g_, sizeof(g_),
  701. salt_, sizeof(salt_)));
  702. AssertIntEQ(0, wc_SrpSetParams(&srv, N_, sizeof(N_),
  703. g_, sizeof(g_),
  704. salt_, sizeof(salt_)));
  705. AssertIntEQ(0, wc_SrpSetPassword(&cli, password_, passwordSz_));
  706. AssertIntEQ(0, wc_SrpSetVerifier(&srv, verifier_, sizeof(verifier_)));
  707. AssertIntEQ(0, wc_SrpSetPrivate(&cli, a_, sizeof(a_)));
  708. AssertIntEQ(0, wc_SrpGetPublic(&cli, clientPubKey, &clientPubKeySz));
  709. AssertIntEQ(0, XMEMCMP(clientPubKey, A_, clientPubKeySz));
  710. AssertIntEQ(0, wc_SrpSetPrivate(&srv, b_, sizeof(b_)));
  711. AssertIntEQ(0, wc_SrpGetPublic(&srv, serverPubKey, &serverPubKeySz));
  712. AssertIntEQ(0, XMEMCMP(serverPubKey, B_, serverPubKeySz));
  713. cli.keyGenFunc_cb = sha512_key_gen;
  714. AssertIntEQ(0, wc_SrpComputeKey(&cli, clientPubKey, clientPubKeySz,
  715. serverPubKey, serverPubKeySz));
  716. AssertIntEQ(0, XMEMCMP(cli.key, key_, sizeof(key_)));
  717. srv.keyGenFunc_cb = sha512_key_gen;
  718. AssertIntEQ(0, wc_SrpComputeKey(&srv, clientPubKey, clientPubKeySz,
  719. serverPubKey, serverPubKeySz));
  720. AssertIntEQ(0, XMEMCMP(srv.key, key_, sizeof(key_)));
  721. AssertIntEQ(0, wc_SrpGetProof(&cli, clientProof, &clientProofSz));
  722. AssertIntEQ(0, wc_SrpVerifyPeersProof(&srv, clientProof, clientProofSz));
  723. AssertIntEQ(0, wc_SrpGetProof(&srv, serverProof, &serverProofSz));
  724. AssertIntEQ(0, wc_SrpVerifyPeersProof(&cli, serverProof, serverProofSz));
  725. wc_SrpTerm(&cli);
  726. wc_SrpTerm(&srv);
  727. }
  728. #endif
  729. void SrpTest(void)
  730. {
  731. #if defined(WOLFCRYPT_HAVE_SRP) && defined(WOLFSSL_SHA512)
  732. wolfCrypt_Init();
  733. test_SrpInit();
  734. test_SrpSetUsername();
  735. test_SrpSetParams();
  736. #ifndef NO_SHA
  737. test_SrpSetPassword();
  738. test_SrpGetPublic();
  739. test_SrpComputeKey();
  740. test_SrpGetProofAndVerify();
  741. #endif /* !NO_SHA */
  742. test_SrpKeyGenFunc_cb();
  743. wolfCrypt_Cleanup();
  744. #endif
  745. }