wolfSSL 3.11.1 for TLS1.3 beta

Fork of wolfSSL by wolf SSL

Committer:
wolfSSL
Date:
Tue May 30 06:16:19 2017 +0000
Revision:
13:80fb167dafdf
wolfSSL 3.11.1: TLS1.3 Beta

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 13:80fb167dafdf 1 /* dh.c
wolfSSL 13:80fb167dafdf 2 *
wolfSSL 13:80fb167dafdf 3 * Copyright (C) 2006-2016 wolfSSL Inc.
wolfSSL 13:80fb167dafdf 4 *
wolfSSL 13:80fb167dafdf 5 * This file is part of wolfSSL.
wolfSSL 13:80fb167dafdf 6 *
wolfSSL 13:80fb167dafdf 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 13:80fb167dafdf 8 * it under the terms of the GNU General Public License as published by
wolfSSL 13:80fb167dafdf 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 13:80fb167dafdf 10 * (at your option) any later version.
wolfSSL 13:80fb167dafdf 11 *
wolfSSL 13:80fb167dafdf 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 13:80fb167dafdf 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 13:80fb167dafdf 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 13:80fb167dafdf 15 * GNU General Public License for more details.
wolfSSL 13:80fb167dafdf 16 *
wolfSSL 13:80fb167dafdf 17 * You should have received a copy of the GNU General Public License
wolfSSL 13:80fb167dafdf 18 * along with this program; if not, write to the Free Software
wolfSSL 13:80fb167dafdf 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 13:80fb167dafdf 20 */
wolfSSL 13:80fb167dafdf 21
wolfSSL 13:80fb167dafdf 22
wolfSSL 13:80fb167dafdf 23 #ifdef HAVE_CONFIG_H
wolfSSL 13:80fb167dafdf 24 #include <config.h>
wolfSSL 13:80fb167dafdf 25 #endif
wolfSSL 13:80fb167dafdf 26
wolfSSL 13:80fb167dafdf 27 #include <wolfssl/wolfcrypt/settings.h>
wolfSSL 13:80fb167dafdf 28
wolfSSL 13:80fb167dafdf 29 #ifndef NO_DH
wolfSSL 13:80fb167dafdf 30
wolfSSL 13:80fb167dafdf 31 #include <wolfssl/wolfcrypt/dh.h>
wolfSSL 13:80fb167dafdf 32 #include <wolfssl/wolfcrypt/error-crypt.h>
wolfSSL 13:80fb167dafdf 33 #include <wolfssl/wolfcrypt/logging.h>
wolfSSL 13:80fb167dafdf 34
wolfSSL 13:80fb167dafdf 35 #ifdef NO_INLINE
wolfSSL 13:80fb167dafdf 36 #include <wolfssl/wolfcrypt/misc.h>
wolfSSL 13:80fb167dafdf 37 #else
wolfSSL 13:80fb167dafdf 38 #define WOLFSSL_MISC_INCLUDED
wolfSSL 13:80fb167dafdf 39 #include <wolfcrypt/src/misc.c>
wolfSSL 13:80fb167dafdf 40 #endif
wolfSSL 13:80fb167dafdf 41
wolfSSL 13:80fb167dafdf 42
wolfSSL 13:80fb167dafdf 43 #if !defined(USER_MATH_LIB) && !defined(WOLFSSL_DH_CONST)
wolfSSL 13:80fb167dafdf 44 #include <math.h>
wolfSSL 13:80fb167dafdf 45 #define XPOW(x,y) pow((x),(y))
wolfSSL 13:80fb167dafdf 46 #define XLOG(x) log((x))
wolfSSL 13:80fb167dafdf 47 #else
wolfSSL 13:80fb167dafdf 48 /* user's own math lib */
wolfSSL 13:80fb167dafdf 49 #endif
wolfSSL 13:80fb167dafdf 50
wolfSSL 13:80fb167dafdf 51 #ifdef HAVE_FFDHE_2048
wolfSSL 13:80fb167dafdf 52 static const byte dh_ffdhe2048_p[] = {
wolfSSL 13:80fb167dafdf 53 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
wolfSSL 13:80fb167dafdf 54 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A,
wolfSSL 13:80fb167dafdf 55 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1,
wolfSSL 13:80fb167dafdf 56 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95,
wolfSSL 13:80fb167dafdf 57 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB,
wolfSSL 13:80fb167dafdf 58 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9,
wolfSSL 13:80fb167dafdf 59 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8,
wolfSSL 13:80fb167dafdf 60 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A,
wolfSSL 13:80fb167dafdf 61 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61,
wolfSSL 13:80fb167dafdf 62 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0,
wolfSSL 13:80fb167dafdf 63 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3,
wolfSSL 13:80fb167dafdf 64 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35,
wolfSSL 13:80fb167dafdf 65 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77,
wolfSSL 13:80fb167dafdf 66 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72,
wolfSSL 13:80fb167dafdf 67 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35,
wolfSSL 13:80fb167dafdf 68 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A,
wolfSSL 13:80fb167dafdf 69 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61,
wolfSSL 13:80fb167dafdf 70 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB,
wolfSSL 13:80fb167dafdf 71 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68,
wolfSSL 13:80fb167dafdf 72 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4,
wolfSSL 13:80fb167dafdf 73 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19,
wolfSSL 13:80fb167dafdf 74 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70,
wolfSSL 13:80fb167dafdf 75 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC,
wolfSSL 13:80fb167dafdf 76 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61,
wolfSSL 13:80fb167dafdf 77 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF,
wolfSSL 13:80fb167dafdf 78 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83,
wolfSSL 13:80fb167dafdf 79 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73,
wolfSSL 13:80fb167dafdf 80 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05,
wolfSSL 13:80fb167dafdf 81 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2,
wolfSSL 13:80fb167dafdf 82 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA,
wolfSSL 13:80fb167dafdf 83 0x88, 0x6B, 0x42, 0x38, 0x61, 0x28, 0x5C, 0x97,
wolfSSL 13:80fb167dafdf 84 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
wolfSSL 13:80fb167dafdf 85 };
wolfSSL 13:80fb167dafdf 86 static const byte dh_ffdhe2048_g[] = { 0x02 };
wolfSSL 13:80fb167dafdf 87
wolfSSL 13:80fb167dafdf 88 const DhParams* wc_Dh_ffdhe2048_Get(void)
wolfSSL 13:80fb167dafdf 89 {
wolfSSL 13:80fb167dafdf 90 static const DhParams ffdhe2048 = {
wolfSSL 13:80fb167dafdf 91 dh_ffdhe2048_p, sizeof(dh_ffdhe2048_p),
wolfSSL 13:80fb167dafdf 92 dh_ffdhe2048_g, sizeof(dh_ffdhe2048_g)
wolfSSL 13:80fb167dafdf 93 };
wolfSSL 13:80fb167dafdf 94 return &ffdhe2048;
wolfSSL 13:80fb167dafdf 95 }
wolfSSL 13:80fb167dafdf 96 #endif
wolfSSL 13:80fb167dafdf 97
wolfSSL 13:80fb167dafdf 98 #ifdef HAVE_FFDHE_3072
wolfSSL 13:80fb167dafdf 99 static const byte dh_ffdhe3072_p[] = {
wolfSSL 13:80fb167dafdf 100 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
wolfSSL 13:80fb167dafdf 101 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A,
wolfSSL 13:80fb167dafdf 102 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1,
wolfSSL 13:80fb167dafdf 103 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95,
wolfSSL 13:80fb167dafdf 104 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB,
wolfSSL 13:80fb167dafdf 105 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9,
wolfSSL 13:80fb167dafdf 106 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8,
wolfSSL 13:80fb167dafdf 107 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A,
wolfSSL 13:80fb167dafdf 108 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61,
wolfSSL 13:80fb167dafdf 109 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0,
wolfSSL 13:80fb167dafdf 110 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3,
wolfSSL 13:80fb167dafdf 111 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35,
wolfSSL 13:80fb167dafdf 112 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77,
wolfSSL 13:80fb167dafdf 113 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72,
wolfSSL 13:80fb167dafdf 114 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35,
wolfSSL 13:80fb167dafdf 115 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A,
wolfSSL 13:80fb167dafdf 116 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61,
wolfSSL 13:80fb167dafdf 117 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB,
wolfSSL 13:80fb167dafdf 118 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68,
wolfSSL 13:80fb167dafdf 119 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4,
wolfSSL 13:80fb167dafdf 120 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19,
wolfSSL 13:80fb167dafdf 121 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70,
wolfSSL 13:80fb167dafdf 122 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC,
wolfSSL 13:80fb167dafdf 123 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61,
wolfSSL 13:80fb167dafdf 124 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF,
wolfSSL 13:80fb167dafdf 125 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83,
wolfSSL 13:80fb167dafdf 126 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73,
wolfSSL 13:80fb167dafdf 127 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05,
wolfSSL 13:80fb167dafdf 128 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2,
wolfSSL 13:80fb167dafdf 129 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA,
wolfSSL 13:80fb167dafdf 130 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC,
wolfSSL 13:80fb167dafdf 131 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B,
wolfSSL 13:80fb167dafdf 132 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38,
wolfSSL 13:80fb167dafdf 133 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07,
wolfSSL 13:80fb167dafdf 134 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE,
wolfSSL 13:80fb167dafdf 135 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C,
wolfSSL 13:80fb167dafdf 136 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70,
wolfSSL 13:80fb167dafdf 137 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44,
wolfSSL 13:80fb167dafdf 138 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3,
wolfSSL 13:80fb167dafdf 139 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF,
wolfSSL 13:80fb167dafdf 140 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E,
wolfSSL 13:80fb167dafdf 141 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D,
wolfSSL 13:80fb167dafdf 142 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA,
wolfSSL 13:80fb167dafdf 143 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E,
wolfSSL 13:80fb167dafdf 144 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF,
wolfSSL 13:80fb167dafdf 145 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C,
wolfSSL 13:80fb167dafdf 146 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0xC6, 0x2E, 0x37,
wolfSSL 13:80fb167dafdf 147 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
wolfSSL 13:80fb167dafdf 148 };
wolfSSL 13:80fb167dafdf 149 static const byte dh_ffdhe3072_g[] = { 0x02 };
wolfSSL 13:80fb167dafdf 150
wolfSSL 13:80fb167dafdf 151 const DhParams* wc_Dh_ffdhe3072_Get(void)
wolfSSL 13:80fb167dafdf 152 {
wolfSSL 13:80fb167dafdf 153 static const DhParams ffdhe3072 = {
wolfSSL 13:80fb167dafdf 154 dh_ffdhe3072_p, sizeof(dh_ffdhe3072_p),
wolfSSL 13:80fb167dafdf 155 dh_ffdhe3072_g, sizeof(dh_ffdhe3072_g)
wolfSSL 13:80fb167dafdf 156 };
wolfSSL 13:80fb167dafdf 157 return &ffdhe3072;
wolfSSL 13:80fb167dafdf 158 }
wolfSSL 13:80fb167dafdf 159 #endif
wolfSSL 13:80fb167dafdf 160
wolfSSL 13:80fb167dafdf 161 #ifdef HAVE_FFDHE_4096
wolfSSL 13:80fb167dafdf 162 static const byte dh_ffdhe4096_p[] = {
wolfSSL 13:80fb167dafdf 163 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
wolfSSL 13:80fb167dafdf 164 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A,
wolfSSL 13:80fb167dafdf 165 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1,
wolfSSL 13:80fb167dafdf 166 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95,
wolfSSL 13:80fb167dafdf 167 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB,
wolfSSL 13:80fb167dafdf 168 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9,
wolfSSL 13:80fb167dafdf 169 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8,
wolfSSL 13:80fb167dafdf 170 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A,
wolfSSL 13:80fb167dafdf 171 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61,
wolfSSL 13:80fb167dafdf 172 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0,
wolfSSL 13:80fb167dafdf 173 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3,
wolfSSL 13:80fb167dafdf 174 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35,
wolfSSL 13:80fb167dafdf 175 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77,
wolfSSL 13:80fb167dafdf 176 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72,
wolfSSL 13:80fb167dafdf 177 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35,
wolfSSL 13:80fb167dafdf 178 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A,
wolfSSL 13:80fb167dafdf 179 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61,
wolfSSL 13:80fb167dafdf 180 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB,
wolfSSL 13:80fb167dafdf 181 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68,
wolfSSL 13:80fb167dafdf 182 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4,
wolfSSL 13:80fb167dafdf 183 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19,
wolfSSL 13:80fb167dafdf 184 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70,
wolfSSL 13:80fb167dafdf 185 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC,
wolfSSL 13:80fb167dafdf 186 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61,
wolfSSL 13:80fb167dafdf 187 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF,
wolfSSL 13:80fb167dafdf 188 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83,
wolfSSL 13:80fb167dafdf 189 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73,
wolfSSL 13:80fb167dafdf 190 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05,
wolfSSL 13:80fb167dafdf 191 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2,
wolfSSL 13:80fb167dafdf 192 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA,
wolfSSL 13:80fb167dafdf 193 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC,
wolfSSL 13:80fb167dafdf 194 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B,
wolfSSL 13:80fb167dafdf 195 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38,
wolfSSL 13:80fb167dafdf 196 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07,
wolfSSL 13:80fb167dafdf 197 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE,
wolfSSL 13:80fb167dafdf 198 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C,
wolfSSL 13:80fb167dafdf 199 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70,
wolfSSL 13:80fb167dafdf 200 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44,
wolfSSL 13:80fb167dafdf 201 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3,
wolfSSL 13:80fb167dafdf 202 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF,
wolfSSL 13:80fb167dafdf 203 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E,
wolfSSL 13:80fb167dafdf 204 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D,
wolfSSL 13:80fb167dafdf 205 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA,
wolfSSL 13:80fb167dafdf 206 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E,
wolfSSL 13:80fb167dafdf 207 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF,
wolfSSL 13:80fb167dafdf 208 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C,
wolfSSL 13:80fb167dafdf 209 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1,
wolfSSL 13:80fb167dafdf 210 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB,
wolfSSL 13:80fb167dafdf 211 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6,
wolfSSL 13:80fb167dafdf 212 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18,
wolfSSL 13:80fb167dafdf 213 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04,
wolfSSL 13:80fb167dafdf 214 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A,
wolfSSL 13:80fb167dafdf 215 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A,
wolfSSL 13:80fb167dafdf 216 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32,
wolfSSL 13:80fb167dafdf 217 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4,
wolfSSL 13:80fb167dafdf 218 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38,
wolfSSL 13:80fb167dafdf 219 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A,
wolfSSL 13:80fb167dafdf 220 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C,
wolfSSL 13:80fb167dafdf 221 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC,
wolfSSL 13:80fb167dafdf 222 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF,
wolfSSL 13:80fb167dafdf 223 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B,
wolfSSL 13:80fb167dafdf 224 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1,
wolfSSL 13:80fb167dafdf 225 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x65, 0x5F, 0x6A,
wolfSSL 13:80fb167dafdf 226 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
wolfSSL 13:80fb167dafdf 227 };
wolfSSL 13:80fb167dafdf 228 static const byte dh_ffdhe4096_g[] = { 0x02 };
wolfSSL 13:80fb167dafdf 229
wolfSSL 13:80fb167dafdf 230 const DhParams* wc_Dh_ffdhe4096_Get(void)
wolfSSL 13:80fb167dafdf 231 {
wolfSSL 13:80fb167dafdf 232 static const DhParams ffdhe4096 = {
wolfSSL 13:80fb167dafdf 233 dh_ffdhe4096_p, sizeof(dh_ffdhe4096_p),
wolfSSL 13:80fb167dafdf 234 dh_ffdhe4096_g, sizeof(dh_ffdhe4096_g)
wolfSSL 13:80fb167dafdf 235 };
wolfSSL 13:80fb167dafdf 236 return &ffdhe4096;
wolfSSL 13:80fb167dafdf 237 }
wolfSSL 13:80fb167dafdf 238 #endif
wolfSSL 13:80fb167dafdf 239
wolfSSL 13:80fb167dafdf 240 #ifdef HAVE_FFDHE_6144
wolfSSL 13:80fb167dafdf 241 static const byte dh_ffdhe6144_p[] = {
wolfSSL 13:80fb167dafdf 242 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
wolfSSL 13:80fb167dafdf 243 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A,
wolfSSL 13:80fb167dafdf 244 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1,
wolfSSL 13:80fb167dafdf 245 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95,
wolfSSL 13:80fb167dafdf 246 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB,
wolfSSL 13:80fb167dafdf 247 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9,
wolfSSL 13:80fb167dafdf 248 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8,
wolfSSL 13:80fb167dafdf 249 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A,
wolfSSL 13:80fb167dafdf 250 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61,
wolfSSL 13:80fb167dafdf 251 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0,
wolfSSL 13:80fb167dafdf 252 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3,
wolfSSL 13:80fb167dafdf 253 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35,
wolfSSL 13:80fb167dafdf 254 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77,
wolfSSL 13:80fb167dafdf 255 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72,
wolfSSL 13:80fb167dafdf 256 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35,
wolfSSL 13:80fb167dafdf 257 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A,
wolfSSL 13:80fb167dafdf 258 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61,
wolfSSL 13:80fb167dafdf 259 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB,
wolfSSL 13:80fb167dafdf 260 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68,
wolfSSL 13:80fb167dafdf 261 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4,
wolfSSL 13:80fb167dafdf 262 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19,
wolfSSL 13:80fb167dafdf 263 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70,
wolfSSL 13:80fb167dafdf 264 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC,
wolfSSL 13:80fb167dafdf 265 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61,
wolfSSL 13:80fb167dafdf 266 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF,
wolfSSL 13:80fb167dafdf 267 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83,
wolfSSL 13:80fb167dafdf 268 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73,
wolfSSL 13:80fb167dafdf 269 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05,
wolfSSL 13:80fb167dafdf 270 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2,
wolfSSL 13:80fb167dafdf 271 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA,
wolfSSL 13:80fb167dafdf 272 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC,
wolfSSL 13:80fb167dafdf 273 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B,
wolfSSL 13:80fb167dafdf 274 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38,
wolfSSL 13:80fb167dafdf 275 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07,
wolfSSL 13:80fb167dafdf 276 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE,
wolfSSL 13:80fb167dafdf 277 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C,
wolfSSL 13:80fb167dafdf 278 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70,
wolfSSL 13:80fb167dafdf 279 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44,
wolfSSL 13:80fb167dafdf 280 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3,
wolfSSL 13:80fb167dafdf 281 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF,
wolfSSL 13:80fb167dafdf 282 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E,
wolfSSL 13:80fb167dafdf 283 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D,
wolfSSL 13:80fb167dafdf 284 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA,
wolfSSL 13:80fb167dafdf 285 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E,
wolfSSL 13:80fb167dafdf 286 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF,
wolfSSL 13:80fb167dafdf 287 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C,
wolfSSL 13:80fb167dafdf 288 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1,
wolfSSL 13:80fb167dafdf 289 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB,
wolfSSL 13:80fb167dafdf 290 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6,
wolfSSL 13:80fb167dafdf 291 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18,
wolfSSL 13:80fb167dafdf 292 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04,
wolfSSL 13:80fb167dafdf 293 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A,
wolfSSL 13:80fb167dafdf 294 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A,
wolfSSL 13:80fb167dafdf 295 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32,
wolfSSL 13:80fb167dafdf 296 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4,
wolfSSL 13:80fb167dafdf 297 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38,
wolfSSL 13:80fb167dafdf 298 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A,
wolfSSL 13:80fb167dafdf 299 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C,
wolfSSL 13:80fb167dafdf 300 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC,
wolfSSL 13:80fb167dafdf 301 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF,
wolfSSL 13:80fb167dafdf 302 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B,
wolfSSL 13:80fb167dafdf 303 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1,
wolfSSL 13:80fb167dafdf 304 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02,
wolfSSL 13:80fb167dafdf 305 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, 0x7A,
wolfSSL 13:80fb167dafdf 306 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A,
wolfSSL 13:80fb167dafdf 307 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6,
wolfSSL 13:80fb167dafdf 308 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8,
wolfSSL 13:80fb167dafdf 309 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C,
wolfSSL 13:80fb167dafdf 310 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A,
wolfSSL 13:80fb167dafdf 311 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71,
wolfSSL 13:80fb167dafdf 312 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F,
wolfSSL 13:80fb167dafdf 313 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77,
wolfSSL 13:80fb167dafdf 314 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10,
wolfSSL 13:80fb167dafdf 315 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8,
wolfSSL 13:80fb167dafdf 316 0xA0, 0x0E, 0xF0, 0x92, 0x35, 0x05, 0x11, 0xE3,
wolfSSL 13:80fb167dafdf 317 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E,
wolfSSL 13:80fb167dafdf 318 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3,
wolfSSL 13:80fb167dafdf 319 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4,
wolfSSL 13:80fb167dafdf 320 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1,
wolfSSL 13:80fb167dafdf 321 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92,
wolfSSL 13:80fb167dafdf 322 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6,
wolfSSL 13:80fb167dafdf 323 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82,
wolfSSL 13:80fb167dafdf 324 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE,
wolfSSL 13:80fb167dafdf 325 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C,
wolfSSL 13:80fb167dafdf 326 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E,
wolfSSL 13:80fb167dafdf 327 0x62, 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46,
wolfSSL 13:80fb167dafdf 328 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A,
wolfSSL 13:80fb167dafdf 329 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17,
wolfSSL 13:80fb167dafdf 330 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03,
wolfSSL 13:80fb167dafdf 331 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04,
wolfSSL 13:80fb167dafdf 332 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6,
wolfSSL 13:80fb167dafdf 333 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69,
wolfSSL 13:80fb167dafdf 334 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1,
wolfSSL 13:80fb167dafdf 335 0xA4, 0x1D, 0x57, 0x0D, 0x79, 0x38, 0xDA, 0xD4,
wolfSSL 13:80fb167dafdf 336 0xA4, 0x0E, 0x32, 0x9C, 0xD0, 0xE4, 0x0E, 0x65,
wolfSSL 13:80fb167dafdf 337 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
wolfSSL 13:80fb167dafdf 338 };
wolfSSL 13:80fb167dafdf 339 static const byte dh_ffdhe6144_g[] = { 0x02 };
wolfSSL 13:80fb167dafdf 340
wolfSSL 13:80fb167dafdf 341 const DhParams* wc_Dh_ffdhe6144_Get(void)
wolfSSL 13:80fb167dafdf 342 {
wolfSSL 13:80fb167dafdf 343 static const DhParams ffdhe6144 = {
wolfSSL 13:80fb167dafdf 344 dh_ffdhe6144_p, sizeof(dh_ffdhe6144_p),
wolfSSL 13:80fb167dafdf 345 dh_ffdhe6144_g, sizeof(dh_ffdhe6144_g)
wolfSSL 13:80fb167dafdf 346 };
wolfSSL 13:80fb167dafdf 347 return &ffdhe6144;
wolfSSL 13:80fb167dafdf 348 }
wolfSSL 13:80fb167dafdf 349 #endif
wolfSSL 13:80fb167dafdf 350
wolfSSL 13:80fb167dafdf 351 #ifdef HAVE_FFDHE_8192
wolfSSL 13:80fb167dafdf 352 static const byte dh_ffdhe8192_p[] = {
wolfSSL 13:80fb167dafdf 353 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
wolfSSL 13:80fb167dafdf 354 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A,
wolfSSL 13:80fb167dafdf 355 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1,
wolfSSL 13:80fb167dafdf 356 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95,
wolfSSL 13:80fb167dafdf 357 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB,
wolfSSL 13:80fb167dafdf 358 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9,
wolfSSL 13:80fb167dafdf 359 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8,
wolfSSL 13:80fb167dafdf 360 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A,
wolfSSL 13:80fb167dafdf 361 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61,
wolfSSL 13:80fb167dafdf 362 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0,
wolfSSL 13:80fb167dafdf 363 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3,
wolfSSL 13:80fb167dafdf 364 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35,
wolfSSL 13:80fb167dafdf 365 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77,
wolfSSL 13:80fb167dafdf 366 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72,
wolfSSL 13:80fb167dafdf 367 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35,
wolfSSL 13:80fb167dafdf 368 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A,
wolfSSL 13:80fb167dafdf 369 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61,
wolfSSL 13:80fb167dafdf 370 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB,
wolfSSL 13:80fb167dafdf 371 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68,
wolfSSL 13:80fb167dafdf 372 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4,
wolfSSL 13:80fb167dafdf 373 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19,
wolfSSL 13:80fb167dafdf 374 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70,
wolfSSL 13:80fb167dafdf 375 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC,
wolfSSL 13:80fb167dafdf 376 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61,
wolfSSL 13:80fb167dafdf 377 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF,
wolfSSL 13:80fb167dafdf 378 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83,
wolfSSL 13:80fb167dafdf 379 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73,
wolfSSL 13:80fb167dafdf 380 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05,
wolfSSL 13:80fb167dafdf 381 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2,
wolfSSL 13:80fb167dafdf 382 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA,
wolfSSL 13:80fb167dafdf 383 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC,
wolfSSL 13:80fb167dafdf 384 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B,
wolfSSL 13:80fb167dafdf 385 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38,
wolfSSL 13:80fb167dafdf 386 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07,
wolfSSL 13:80fb167dafdf 387 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE,
wolfSSL 13:80fb167dafdf 388 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C,
wolfSSL 13:80fb167dafdf 389 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70,
wolfSSL 13:80fb167dafdf 390 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44,
wolfSSL 13:80fb167dafdf 391 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3,
wolfSSL 13:80fb167dafdf 392 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF,
wolfSSL 13:80fb167dafdf 393 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E,
wolfSSL 13:80fb167dafdf 394 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D,
wolfSSL 13:80fb167dafdf 395 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA,
wolfSSL 13:80fb167dafdf 396 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E,
wolfSSL 13:80fb167dafdf 397 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF,
wolfSSL 13:80fb167dafdf 398 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C,
wolfSSL 13:80fb167dafdf 399 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1,
wolfSSL 13:80fb167dafdf 400 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB,
wolfSSL 13:80fb167dafdf 401 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6,
wolfSSL 13:80fb167dafdf 402 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18,
wolfSSL 13:80fb167dafdf 403 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04,
wolfSSL 13:80fb167dafdf 404 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A,
wolfSSL 13:80fb167dafdf 405 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A,
wolfSSL 13:80fb167dafdf 406 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32,
wolfSSL 13:80fb167dafdf 407 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4,
wolfSSL 13:80fb167dafdf 408 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38,
wolfSSL 13:80fb167dafdf 409 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A,
wolfSSL 13:80fb167dafdf 410 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C,
wolfSSL 13:80fb167dafdf 411 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC,
wolfSSL 13:80fb167dafdf 412 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF,
wolfSSL 13:80fb167dafdf 413 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B,
wolfSSL 13:80fb167dafdf 414 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1,
wolfSSL 13:80fb167dafdf 415 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02,
wolfSSL 13:80fb167dafdf 416 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, 0x7A,
wolfSSL 13:80fb167dafdf 417 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A,
wolfSSL 13:80fb167dafdf 418 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6,
wolfSSL 13:80fb167dafdf 419 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8,
wolfSSL 13:80fb167dafdf 420 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C,
wolfSSL 13:80fb167dafdf 421 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A,
wolfSSL 13:80fb167dafdf 422 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71,
wolfSSL 13:80fb167dafdf 423 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F,
wolfSSL 13:80fb167dafdf 424 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77,
wolfSSL 13:80fb167dafdf 425 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10,
wolfSSL 13:80fb167dafdf 426 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8,
wolfSSL 13:80fb167dafdf 427 0xA0, 0x0E, 0xF0, 0x92, 0x35, 0x05, 0x11, 0xE3,
wolfSSL 13:80fb167dafdf 428 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E,
wolfSSL 13:80fb167dafdf 429 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3,
wolfSSL 13:80fb167dafdf 430 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4,
wolfSSL 13:80fb167dafdf 431 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1,
wolfSSL 13:80fb167dafdf 432 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92,
wolfSSL 13:80fb167dafdf 433 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6,
wolfSSL 13:80fb167dafdf 434 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82,
wolfSSL 13:80fb167dafdf 435 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE,
wolfSSL 13:80fb167dafdf 436 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C,
wolfSSL 13:80fb167dafdf 437 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E,
wolfSSL 13:80fb167dafdf 438 0x62, 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46,
wolfSSL 13:80fb167dafdf 439 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A,
wolfSSL 13:80fb167dafdf 440 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17,
wolfSSL 13:80fb167dafdf 441 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03,
wolfSSL 13:80fb167dafdf 442 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04,
wolfSSL 13:80fb167dafdf 443 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6,
wolfSSL 13:80fb167dafdf 444 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69,
wolfSSL 13:80fb167dafdf 445 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1,
wolfSSL 13:80fb167dafdf 446 0xA4, 0x1D, 0x57, 0x0D, 0x79, 0x38, 0xDA, 0xD4,
wolfSSL 13:80fb167dafdf 447 0xA4, 0x0E, 0x32, 0x9C, 0xCF, 0xF4, 0x6A, 0xAA,
wolfSSL 13:80fb167dafdf 448 0x36, 0xAD, 0x00, 0x4C, 0xF6, 0x00, 0xC8, 0x38,
wolfSSL 13:80fb167dafdf 449 0x1E, 0x42, 0x5A, 0x31, 0xD9, 0x51, 0xAE, 0x64,
wolfSSL 13:80fb167dafdf 450 0xFD, 0xB2, 0x3F, 0xCE, 0xC9, 0x50, 0x9D, 0x43,
wolfSSL 13:80fb167dafdf 451 0x68, 0x7F, 0xEB, 0x69, 0xED, 0xD1, 0xCC, 0x5E,
wolfSSL 13:80fb167dafdf 452 0x0B, 0x8C, 0xC3, 0xBD, 0xF6, 0x4B, 0x10, 0xEF,
wolfSSL 13:80fb167dafdf 453 0x86, 0xB6, 0x31, 0x42, 0xA3, 0xAB, 0x88, 0x29,
wolfSSL 13:80fb167dafdf 454 0x55, 0x5B, 0x2F, 0x74, 0x7C, 0x93, 0x26, 0x65,
wolfSSL 13:80fb167dafdf 455 0xCB, 0x2C, 0x0F, 0x1C, 0xC0, 0x1B, 0xD7, 0x02,
wolfSSL 13:80fb167dafdf 456 0x29, 0x38, 0x88, 0x39, 0xD2, 0xAF, 0x05, 0xE4,
wolfSSL 13:80fb167dafdf 457 0x54, 0x50, 0x4A, 0xC7, 0x8B, 0x75, 0x82, 0x82,
wolfSSL 13:80fb167dafdf 458 0x28, 0x46, 0xC0, 0xBA, 0x35, 0xC3, 0x5F, 0x5C,
wolfSSL 13:80fb167dafdf 459 0x59, 0x16, 0x0C, 0xC0, 0x46, 0xFD, 0x82, 0x51,
wolfSSL 13:80fb167dafdf 460 0x54, 0x1F, 0xC6, 0x8C, 0x9C, 0x86, 0xB0, 0x22,
wolfSSL 13:80fb167dafdf 461 0xBB, 0x70, 0x99, 0x87, 0x6A, 0x46, 0x0E, 0x74,
wolfSSL 13:80fb167dafdf 462 0x51, 0xA8, 0xA9, 0x31, 0x09, 0x70, 0x3F, 0xEE,
wolfSSL 13:80fb167dafdf 463 0x1C, 0x21, 0x7E, 0x6C, 0x38, 0x26, 0xE5, 0x2C,
wolfSSL 13:80fb167dafdf 464 0x51, 0xAA, 0x69, 0x1E, 0x0E, 0x42, 0x3C, 0xFC,
wolfSSL 13:80fb167dafdf 465 0x99, 0xE9, 0xE3, 0x16, 0x50, 0xC1, 0x21, 0x7B,
wolfSSL 13:80fb167dafdf 466 0x62, 0x48, 0x16, 0xCD, 0xAD, 0x9A, 0x95, 0xF9,
wolfSSL 13:80fb167dafdf 467 0xD5, 0xB8, 0x01, 0x94, 0x88, 0xD9, 0xC0, 0xA0,
wolfSSL 13:80fb167dafdf 468 0xA1, 0xFE, 0x30, 0x75, 0xA5, 0x77, 0xE2, 0x31,
wolfSSL 13:80fb167dafdf 469 0x83, 0xF8, 0x1D, 0x4A, 0x3F, 0x2F, 0xA4, 0x57,
wolfSSL 13:80fb167dafdf 470 0x1E, 0xFC, 0x8C, 0xE0, 0xBA, 0x8A, 0x4F, 0xE8,
wolfSSL 13:80fb167dafdf 471 0xB6, 0x85, 0x5D, 0xFE, 0x72, 0xB0, 0xA6, 0x6E,
wolfSSL 13:80fb167dafdf 472 0xDE, 0xD2, 0xFB, 0xAB, 0xFB, 0xE5, 0x8A, 0x30,
wolfSSL 13:80fb167dafdf 473 0xFA, 0xFA, 0xBE, 0x1C, 0x5D, 0x71, 0xA8, 0x7E,
wolfSSL 13:80fb167dafdf 474 0x2F, 0x74, 0x1E, 0xF8, 0xC1, 0xFE, 0x86, 0xFE,
wolfSSL 13:80fb167dafdf 475 0xA6, 0xBB, 0xFD, 0xE5, 0x30, 0x67, 0x7F, 0x0D,
wolfSSL 13:80fb167dafdf 476 0x97, 0xD1, 0x1D, 0x49, 0xF7, 0xA8, 0x44, 0x3D,
wolfSSL 13:80fb167dafdf 477 0x08, 0x22, 0xE5, 0x06, 0xA9, 0xF4, 0x61, 0x4E,
wolfSSL 13:80fb167dafdf 478 0x01, 0x1E, 0x2A, 0x94, 0x83, 0x8F, 0xF8, 0x8C,
wolfSSL 13:80fb167dafdf 479 0xD6, 0x8C, 0x8B, 0xB7, 0xC5, 0xC6, 0x42, 0x4C,
wolfSSL 13:80fb167dafdf 480 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
wolfSSL 13:80fb167dafdf 481 };
wolfSSL 13:80fb167dafdf 482 static const byte dh_ffdhe8192_g[] = { 0x02 };
wolfSSL 13:80fb167dafdf 483
wolfSSL 13:80fb167dafdf 484 const DhParams* wc_Dh_ffdhe8192_Get(void)
wolfSSL 13:80fb167dafdf 485 {
wolfSSL 13:80fb167dafdf 486 static const DhParams ffdhe8192 = {
wolfSSL 13:80fb167dafdf 487 dh_ffdhe8192_p, sizeof(dh_ffdhe8192_p),
wolfSSL 13:80fb167dafdf 488 dh_ffdhe8192_g, sizeof(dh_ffdhe8192_g)
wolfSSL 13:80fb167dafdf 489 };
wolfSSL 13:80fb167dafdf 490 return &ffdhe8192;
wolfSSL 13:80fb167dafdf 491 }
wolfSSL 13:80fb167dafdf 492 #endif
wolfSSL 13:80fb167dafdf 493
wolfSSL 13:80fb167dafdf 494 int wc_InitDhKey_ex(DhKey* key, void* heap, int devId)
wolfSSL 13:80fb167dafdf 495 {
wolfSSL 13:80fb167dafdf 496 int ret = 0;
wolfSSL 13:80fb167dafdf 497
wolfSSL 13:80fb167dafdf 498 if (key == NULL)
wolfSSL 13:80fb167dafdf 499 return BAD_FUNC_ARG;
wolfSSL 13:80fb167dafdf 500
wolfSSL 13:80fb167dafdf 501 key->heap = heap; /* for XMALLOC/XFREE in future */
wolfSSL 13:80fb167dafdf 502
wolfSSL 13:80fb167dafdf 503 if (mp_init_multi(&key->p, &key->g, NULL, NULL, NULL, NULL) != MP_OKAY)
wolfSSL 13:80fb167dafdf 504 return MEMORY_E;
wolfSSL 13:80fb167dafdf 505
wolfSSL 13:80fb167dafdf 506 #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_DH)
wolfSSL 13:80fb167dafdf 507 /* handle as async */
wolfSSL 13:80fb167dafdf 508 ret = wolfAsync_DevCtxInit(&key->asyncDev, WOLFSSL_ASYNC_MARKER_DH,
wolfSSL 13:80fb167dafdf 509 key->heap, devId);
wolfSSL 13:80fb167dafdf 510 #else
wolfSSL 13:80fb167dafdf 511 (void)devId;
wolfSSL 13:80fb167dafdf 512 #endif
wolfSSL 13:80fb167dafdf 513
wolfSSL 13:80fb167dafdf 514 return ret;
wolfSSL 13:80fb167dafdf 515 }
wolfSSL 13:80fb167dafdf 516
wolfSSL 13:80fb167dafdf 517 int wc_InitDhKey(DhKey* key)
wolfSSL 13:80fb167dafdf 518 {
wolfSSL 13:80fb167dafdf 519 return wc_InitDhKey_ex(key, NULL, INVALID_DEVID);
wolfSSL 13:80fb167dafdf 520 }
wolfSSL 13:80fb167dafdf 521
wolfSSL 13:80fb167dafdf 522
wolfSSL 13:80fb167dafdf 523 void wc_FreeDhKey(DhKey* key)
wolfSSL 13:80fb167dafdf 524 {
wolfSSL 13:80fb167dafdf 525 if (key) {
wolfSSL 13:80fb167dafdf 526 mp_clear(&key->p);
wolfSSL 13:80fb167dafdf 527 mp_clear(&key->g);
wolfSSL 13:80fb167dafdf 528
wolfSSL 13:80fb167dafdf 529 #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_DH)
wolfSSL 13:80fb167dafdf 530 wolfAsync_DevCtxFree(&key->asyncDev, WOLFSSL_ASYNC_MARKER_DH);
wolfSSL 13:80fb167dafdf 531 #endif
wolfSSL 13:80fb167dafdf 532 }
wolfSSL 13:80fb167dafdf 533 }
wolfSSL 13:80fb167dafdf 534
wolfSSL 13:80fb167dafdf 535
wolfSSL 13:80fb167dafdf 536 /* if defined to not use floating point values do not compile in */
wolfSSL 13:80fb167dafdf 537 #ifndef WOLFSSL_DH_CONST
wolfSSL 13:80fb167dafdf 538 static word32 DiscreteLogWorkFactor(word32 n)
wolfSSL 13:80fb167dafdf 539 {
wolfSSL 13:80fb167dafdf 540 /* assuming discrete log takes about the same time as factoring */
wolfSSL 13:80fb167dafdf 541 if (n < 5)
wolfSSL 13:80fb167dafdf 542 return 0;
wolfSSL 13:80fb167dafdf 543 else
wolfSSL 13:80fb167dafdf 544 return (word32)(2.4 * XPOW((double)n, 1.0/3.0) *
wolfSSL 13:80fb167dafdf 545 XPOW(XLOG((double)n), 2.0/3.0) - 5);
wolfSSL 13:80fb167dafdf 546 }
wolfSSL 13:80fb167dafdf 547 #endif /* WOLFSSL_DH_CONST*/
wolfSSL 13:80fb167dafdf 548
wolfSSL 13:80fb167dafdf 549
wolfSSL 13:80fb167dafdf 550 /* if not using fixed points use DiscreteLogWorkFactor function for unsual size
wolfSSL 13:80fb167dafdf 551 otherwise round up on size needed */
wolfSSL 13:80fb167dafdf 552 #ifndef WOLFSSL_DH_CONST
wolfSSL 13:80fb167dafdf 553 #define WOLFSSL_DH_ROUND(x)
wolfSSL 13:80fb167dafdf 554 #else
wolfSSL 13:80fb167dafdf 555 #define WOLFSSL_DH_ROUND(x) \
wolfSSL 13:80fb167dafdf 556 do { \
wolfSSL 13:80fb167dafdf 557 if (x % 128) { \
wolfSSL 13:80fb167dafdf 558 x &= 0xffffff80;\
wolfSSL 13:80fb167dafdf 559 x += 128; \
wolfSSL 13:80fb167dafdf 560 } \
wolfSSL 13:80fb167dafdf 561 } \
wolfSSL 13:80fb167dafdf 562 while (0)
wolfSSL 13:80fb167dafdf 563 #endif
wolfSSL 13:80fb167dafdf 564
wolfSSL 13:80fb167dafdf 565
wolfSSL 13:80fb167dafdf 566 static int GeneratePrivateDh(DhKey* key, WC_RNG* rng, byte* priv, word32* privSz)
wolfSSL 13:80fb167dafdf 567 {
wolfSSL 13:80fb167dafdf 568 int ret = 0;
wolfSSL 13:80fb167dafdf 569 word32 sz = mp_unsigned_bin_size(&key->p);
wolfSSL 13:80fb167dafdf 570
wolfSSL 13:80fb167dafdf 571 /* Table of predetermined values from the operation
wolfSSL 13:80fb167dafdf 572 2 * DiscreteLogWorkFactor(sz * WOLFSSL_BIT_SIZE) / WOLFSSL_BIT_SIZE + 1
wolfSSL 13:80fb167dafdf 573 Sizes in table checked against RFC 3526
wolfSSL 13:80fb167dafdf 574 */
wolfSSL 13:80fb167dafdf 575 WOLFSSL_DH_ROUND(sz); /* if using fixed points only, then round up */
wolfSSL 13:80fb167dafdf 576 switch (sz) {
wolfSSL 13:80fb167dafdf 577 case 128: sz = 21; break;
wolfSSL 13:80fb167dafdf 578 case 256: sz = 29; break;
wolfSSL 13:80fb167dafdf 579 case 384: sz = 34; break;
wolfSSL 13:80fb167dafdf 580 case 512: sz = 39; break;
wolfSSL 13:80fb167dafdf 581 case 640: sz = 42; break;
wolfSSL 13:80fb167dafdf 582 case 768: sz = 46; break;
wolfSSL 13:80fb167dafdf 583 case 896: sz = 49; break;
wolfSSL 13:80fb167dafdf 584 case 1024: sz = 52; break;
wolfSSL 13:80fb167dafdf 585 default:
wolfSSL 13:80fb167dafdf 586 #ifndef WOLFSSL_DH_CONST
wolfSSL 13:80fb167dafdf 587 /* if using floating points and size of p is not in table */
wolfSSL 13:80fb167dafdf 588 sz = min(sz, 2 * DiscreteLogWorkFactor(sz * WOLFSSL_BIT_SIZE) /
wolfSSL 13:80fb167dafdf 589 WOLFSSL_BIT_SIZE + 1);
wolfSSL 13:80fb167dafdf 590 break;
wolfSSL 13:80fb167dafdf 591 #else
wolfSSL 13:80fb167dafdf 592 return BAD_FUNC_ARG;
wolfSSL 13:80fb167dafdf 593 #endif
wolfSSL 13:80fb167dafdf 594 }
wolfSSL 13:80fb167dafdf 595
wolfSSL 13:80fb167dafdf 596 ret = wc_RNG_GenerateBlock(rng, priv, sz);
wolfSSL 13:80fb167dafdf 597
wolfSSL 13:80fb167dafdf 598 if (ret == 0) {
wolfSSL 13:80fb167dafdf 599 priv[0] |= 0x0C;
wolfSSL 13:80fb167dafdf 600 *privSz = sz;
wolfSSL 13:80fb167dafdf 601 }
wolfSSL 13:80fb167dafdf 602
wolfSSL 13:80fb167dafdf 603 return ret;
wolfSSL 13:80fb167dafdf 604 }
wolfSSL 13:80fb167dafdf 605
wolfSSL 13:80fb167dafdf 606
wolfSSL 13:80fb167dafdf 607 static int GeneratePublicDh(DhKey* key, byte* priv, word32 privSz,
wolfSSL 13:80fb167dafdf 608 byte* pub, word32* pubSz)
wolfSSL 13:80fb167dafdf 609 {
wolfSSL 13:80fb167dafdf 610 int ret = 0;
wolfSSL 13:80fb167dafdf 611 mp_int x;
wolfSSL 13:80fb167dafdf 612 mp_int y;
wolfSSL 13:80fb167dafdf 613
wolfSSL 13:80fb167dafdf 614 if (mp_init_multi(&x, &y, 0, 0, 0, 0) != MP_OKAY)
wolfSSL 13:80fb167dafdf 615 return MP_INIT_E;
wolfSSL 13:80fb167dafdf 616
wolfSSL 13:80fb167dafdf 617 if (mp_read_unsigned_bin(&x, priv, privSz) != MP_OKAY)
wolfSSL 13:80fb167dafdf 618 ret = MP_READ_E;
wolfSSL 13:80fb167dafdf 619
wolfSSL 13:80fb167dafdf 620 if (ret == 0 && mp_exptmod(&key->g, &x, &key->p, &y) != MP_OKAY)
wolfSSL 13:80fb167dafdf 621 ret = MP_EXPTMOD_E;
wolfSSL 13:80fb167dafdf 622
wolfSSL 13:80fb167dafdf 623 if (ret == 0 && mp_to_unsigned_bin(&y, pub) != MP_OKAY)
wolfSSL 13:80fb167dafdf 624 ret = MP_TO_E;
wolfSSL 13:80fb167dafdf 625
wolfSSL 13:80fb167dafdf 626 if (ret == 0)
wolfSSL 13:80fb167dafdf 627 *pubSz = mp_unsigned_bin_size(&y);
wolfSSL 13:80fb167dafdf 628
wolfSSL 13:80fb167dafdf 629 mp_clear(&y);
wolfSSL 13:80fb167dafdf 630 mp_clear(&x);
wolfSSL 13:80fb167dafdf 631
wolfSSL 13:80fb167dafdf 632 return ret;
wolfSSL 13:80fb167dafdf 633 }
wolfSSL 13:80fb167dafdf 634
wolfSSL 13:80fb167dafdf 635 static int wc_DhGenerateKeyPair_Sync(DhKey* key, WC_RNG* rng,
wolfSSL 13:80fb167dafdf 636 byte* priv, word32* privSz, byte* pub, word32* pubSz)
wolfSSL 13:80fb167dafdf 637 {
wolfSSL 13:80fb167dafdf 638 int ret;
wolfSSL 13:80fb167dafdf 639
wolfSSL 13:80fb167dafdf 640 if (key == NULL || rng == NULL || priv == NULL || privSz == NULL ||
wolfSSL 13:80fb167dafdf 641 pub == NULL || pubSz == NULL) {
wolfSSL 13:80fb167dafdf 642 return BAD_FUNC_ARG;
wolfSSL 13:80fb167dafdf 643 }
wolfSSL 13:80fb167dafdf 644
wolfSSL 13:80fb167dafdf 645 ret = GeneratePrivateDh(key, rng, priv, privSz);
wolfSSL 13:80fb167dafdf 646
wolfSSL 13:80fb167dafdf 647 return (ret != 0) ? ret : GeneratePublicDh(key, priv, *privSz, pub, pubSz);
wolfSSL 13:80fb167dafdf 648 }
wolfSSL 13:80fb167dafdf 649
wolfSSL 13:80fb167dafdf 650 #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_DH)
wolfSSL 13:80fb167dafdf 651 static int wc_DhGenerateKeyPair_Async(DhKey* key, WC_RNG* rng,
wolfSSL 13:80fb167dafdf 652 byte* priv, word32* privSz, byte* pub, word32* pubSz)
wolfSSL 13:80fb167dafdf 653 {
wolfSSL 13:80fb167dafdf 654 int ret;
wolfSSL 13:80fb167dafdf 655
wolfSSL 13:80fb167dafdf 656 #if defined(HAVE_INTEL_QA)
wolfSSL 13:80fb167dafdf 657 mp_int x;
wolfSSL 13:80fb167dafdf 658
wolfSSL 13:80fb167dafdf 659 ret = mp_init(&x);
wolfSSL 13:80fb167dafdf 660 if (ret != MP_OKAY)
wolfSSL 13:80fb167dafdf 661 return ret;
wolfSSL 13:80fb167dafdf 662
wolfSSL 13:80fb167dafdf 663 ret = GeneratePrivateDh(key, rng, priv, privSz);
wolfSSL 13:80fb167dafdf 664 if (ret == 0)
wolfSSL 13:80fb167dafdf 665 ret = mp_read_unsigned_bin(&x, priv, *privSz);
wolfSSL 13:80fb167dafdf 666 if (ret == MP_OKAY)
wolfSSL 13:80fb167dafdf 667 ret = wc_mp_to_bigint(&x, &x.raw);
wolfSSL 13:80fb167dafdf 668 if (ret == MP_OKAY)
wolfSSL 13:80fb167dafdf 669 ret = wc_mp_to_bigint(&key->p, &key->p.raw);
wolfSSL 13:80fb167dafdf 670 if (ret == MP_OKAY)
wolfSSL 13:80fb167dafdf 671 ret = wc_mp_to_bigint(&key->g, &key->g.raw);
wolfSSL 13:80fb167dafdf 672 if (ret == MP_OKAY)
wolfSSL 13:80fb167dafdf 673 ret = IntelQaDhKeyGen(&key->asyncDev, &key->p.raw, &key->g.raw,
wolfSSL 13:80fb167dafdf 674 &x.raw, pub, pubSz);
wolfSSL 13:80fb167dafdf 675 mp_clear(&x);
wolfSSL 13:80fb167dafdf 676
wolfSSL 13:80fb167dafdf 677 #else
wolfSSL 13:80fb167dafdf 678
wolfSSL 13:80fb167dafdf 679 #if defined(HAVE_CAVIUM)
wolfSSL 13:80fb167dafdf 680 /* TODO: Not implemented - use software for now */
wolfSSL 13:80fb167dafdf 681
wolfSSL 13:80fb167dafdf 682 #else /* WOLFSSL_ASYNC_CRYPT_TEST */
wolfSSL 13:80fb167dafdf 683 WC_ASYNC_TEST* testDev = &key->asyncDev.test;
wolfSSL 13:80fb167dafdf 684 if (testDev->type == ASYNC_TEST_NONE) {
wolfSSL 13:80fb167dafdf 685 testDev->type = ASYNC_TEST_DH_GEN;
wolfSSL 13:80fb167dafdf 686 testDev->dhGen.key = key;
wolfSSL 13:80fb167dafdf 687 testDev->dhGen.rng = rng;
wolfSSL 13:80fb167dafdf 688 testDev->dhGen.priv = priv;
wolfSSL 13:80fb167dafdf 689 testDev->dhGen.privSz = privSz;
wolfSSL 13:80fb167dafdf 690 testDev->dhGen.pub = pub;
wolfSSL 13:80fb167dafdf 691 testDev->dhGen.pubSz = pubSz;
wolfSSL 13:80fb167dafdf 692 return WC_PENDING_E;
wolfSSL 13:80fb167dafdf 693 }
wolfSSL 13:80fb167dafdf 694 #endif
wolfSSL 13:80fb167dafdf 695
wolfSSL 13:80fb167dafdf 696 ret = wc_DhGenerateKeyPair_Sync(key, rng, priv, privSz, pub, pubSz);
wolfSSL 13:80fb167dafdf 697
wolfSSL 13:80fb167dafdf 698 #endif /* HAVE_INTEL_QA */
wolfSSL 13:80fb167dafdf 699
wolfSSL 13:80fb167dafdf 700 return ret;
wolfSSL 13:80fb167dafdf 701 }
wolfSSL 13:80fb167dafdf 702 #endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_DH */
wolfSSL 13:80fb167dafdf 703
wolfSSL 13:80fb167dafdf 704
wolfSSL 13:80fb167dafdf 705 /* Check DH Public Key for invalid numbers
wolfSSL 13:80fb167dafdf 706 *
wolfSSL 13:80fb167dafdf 707 * key DH key group parameters.
wolfSSL 13:80fb167dafdf 708 * pub Public Key.
wolfSSL 13:80fb167dafdf 709 * pubSz Public Key size.
wolfSSL 13:80fb167dafdf 710 *
wolfSSL 13:80fb167dafdf 711 * returns 0 on success or error code
wolfSSL 13:80fb167dafdf 712 */
wolfSSL 13:80fb167dafdf 713 int wc_DhCheckPubKey(DhKey* key, const byte* pub, word32 pubSz)
wolfSSL 13:80fb167dafdf 714 {
wolfSSL 13:80fb167dafdf 715 int ret = 0;
wolfSSL 13:80fb167dafdf 716
wolfSSL 13:80fb167dafdf 717 mp_int x;
wolfSSL 13:80fb167dafdf 718 mp_int y;
wolfSSL 13:80fb167dafdf 719
wolfSSL 13:80fb167dafdf 720 if (key == NULL || pub == NULL) {
wolfSSL 13:80fb167dafdf 721 return BAD_FUNC_ARG;
wolfSSL 13:80fb167dafdf 722 }
wolfSSL 13:80fb167dafdf 723
wolfSSL 13:80fb167dafdf 724 if (mp_init_multi(&x, &y, NULL, NULL, NULL, NULL) != MP_OKAY) {
wolfSSL 13:80fb167dafdf 725 return MP_INIT_E;
wolfSSL 13:80fb167dafdf 726 }
wolfSSL 13:80fb167dafdf 727
wolfSSL 13:80fb167dafdf 728 if (mp_read_unsigned_bin(&x, pub, pubSz) != MP_OKAY) {
wolfSSL 13:80fb167dafdf 729 ret = MP_READ_E;
wolfSSL 13:80fb167dafdf 730 }
wolfSSL 13:80fb167dafdf 731
wolfSSL 13:80fb167dafdf 732 /* pub should not be 0 or 1 */
wolfSSL 13:80fb167dafdf 733 if (ret == 0 && mp_cmp_d(&x, 2) == MP_LT) {
wolfSSL 13:80fb167dafdf 734 ret = MP_CMP_E;
wolfSSL 13:80fb167dafdf 735 }
wolfSSL 13:80fb167dafdf 736
wolfSSL 13:80fb167dafdf 737 /* pub shouldn't be greater than or equal to p - 1 */
wolfSSL 13:80fb167dafdf 738 if (ret == 0 && mp_copy(&key->p, &y) != MP_OKAY) {
wolfSSL 13:80fb167dafdf 739 ret = MP_INIT_E;
wolfSSL 13:80fb167dafdf 740 }
wolfSSL 13:80fb167dafdf 741 if (ret == 0 && mp_sub_d(&y, 2, &y) != MP_OKAY) {
wolfSSL 13:80fb167dafdf 742 ret = MP_SUB_E;
wolfSSL 13:80fb167dafdf 743 }
wolfSSL 13:80fb167dafdf 744 if (ret == 0 && mp_cmp(&x, &y) == MP_GT) {
wolfSSL 13:80fb167dafdf 745 ret = MP_CMP_E;
wolfSSL 13:80fb167dafdf 746 }
wolfSSL 13:80fb167dafdf 747
wolfSSL 13:80fb167dafdf 748 mp_clear(&y);
wolfSSL 13:80fb167dafdf 749 mp_clear(&x);
wolfSSL 13:80fb167dafdf 750
wolfSSL 13:80fb167dafdf 751 return ret;
wolfSSL 13:80fb167dafdf 752 }
wolfSSL 13:80fb167dafdf 753
wolfSSL 13:80fb167dafdf 754
wolfSSL 13:80fb167dafdf 755 int wc_DhGenerateKeyPair(DhKey* key, WC_RNG* rng,
wolfSSL 13:80fb167dafdf 756 byte* priv, word32* privSz, byte* pub, word32* pubSz)
wolfSSL 13:80fb167dafdf 757 {
wolfSSL 13:80fb167dafdf 758 int ret;
wolfSSL 13:80fb167dafdf 759
wolfSSL 13:80fb167dafdf 760 if (key == NULL || rng == NULL || priv == NULL || privSz == NULL ||
wolfSSL 13:80fb167dafdf 761 pub == NULL || pubSz == NULL) {
wolfSSL 13:80fb167dafdf 762 return BAD_FUNC_ARG;
wolfSSL 13:80fb167dafdf 763 }
wolfSSL 13:80fb167dafdf 764
wolfSSL 13:80fb167dafdf 765 #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_DH)
wolfSSL 13:80fb167dafdf 766 if (key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_DH) {
wolfSSL 13:80fb167dafdf 767 ret = wc_DhGenerateKeyPair_Async(key, rng, priv, privSz, pub, pubSz);
wolfSSL 13:80fb167dafdf 768 }
wolfSSL 13:80fb167dafdf 769 else
wolfSSL 13:80fb167dafdf 770 #endif
wolfSSL 13:80fb167dafdf 771 {
wolfSSL 13:80fb167dafdf 772 ret = wc_DhGenerateKeyPair_Sync(key, rng, priv, privSz, pub, pubSz);
wolfSSL 13:80fb167dafdf 773 }
wolfSSL 13:80fb167dafdf 774
wolfSSL 13:80fb167dafdf 775 return ret;
wolfSSL 13:80fb167dafdf 776 }
wolfSSL 13:80fb167dafdf 777
wolfSSL 13:80fb167dafdf 778
wolfSSL 13:80fb167dafdf 779 static int wc_DhAgree_Sync(DhKey* key, byte* agree, word32* agreeSz,
wolfSSL 13:80fb167dafdf 780 const byte* priv, word32 privSz, const byte* otherPub, word32 pubSz)
wolfSSL 13:80fb167dafdf 781 {
wolfSSL 13:80fb167dafdf 782 int ret = 0;
wolfSSL 13:80fb167dafdf 783 mp_int x;
wolfSSL 13:80fb167dafdf 784 mp_int y;
wolfSSL 13:80fb167dafdf 785 mp_int z;
wolfSSL 13:80fb167dafdf 786
wolfSSL 13:80fb167dafdf 787 if (wc_DhCheckPubKey(key, otherPub, pubSz) != 0) {
wolfSSL 13:80fb167dafdf 788 WOLFSSL_MSG("wc_DhAgree wc_DhCheckPubKey failed");
wolfSSL 13:80fb167dafdf 789 return DH_CHECK_PUB_E;
wolfSSL 13:80fb167dafdf 790 }
wolfSSL 13:80fb167dafdf 791
wolfSSL 13:80fb167dafdf 792 if (mp_init_multi(&x, &y, &z, 0, 0, 0) != MP_OKAY)
wolfSSL 13:80fb167dafdf 793 return MP_INIT_E;
wolfSSL 13:80fb167dafdf 794
wolfSSL 13:80fb167dafdf 795 if (mp_read_unsigned_bin(&x, priv, privSz) != MP_OKAY)
wolfSSL 13:80fb167dafdf 796 ret = MP_READ_E;
wolfSSL 13:80fb167dafdf 797
wolfSSL 13:80fb167dafdf 798 if (ret == 0 && mp_read_unsigned_bin(&y, otherPub, pubSz) != MP_OKAY)
wolfSSL 13:80fb167dafdf 799 ret = MP_READ_E;
wolfSSL 13:80fb167dafdf 800
wolfSSL 13:80fb167dafdf 801 if (ret == 0 && mp_exptmod(&y, &x, &key->p, &z) != MP_OKAY)
wolfSSL 13:80fb167dafdf 802 ret = MP_EXPTMOD_E;
wolfSSL 13:80fb167dafdf 803
wolfSSL 13:80fb167dafdf 804 if (ret == 0 && mp_to_unsigned_bin(&z, agree) != MP_OKAY)
wolfSSL 13:80fb167dafdf 805 ret = MP_TO_E;
wolfSSL 13:80fb167dafdf 806
wolfSSL 13:80fb167dafdf 807 if (ret == 0)
wolfSSL 13:80fb167dafdf 808 *agreeSz = mp_unsigned_bin_size(&z);
wolfSSL 13:80fb167dafdf 809
wolfSSL 13:80fb167dafdf 810 mp_clear(&z);
wolfSSL 13:80fb167dafdf 811 mp_clear(&y);
wolfSSL 13:80fb167dafdf 812 mp_forcezero(&x);
wolfSSL 13:80fb167dafdf 813
wolfSSL 13:80fb167dafdf 814 return ret;
wolfSSL 13:80fb167dafdf 815 }
wolfSSL 13:80fb167dafdf 816
wolfSSL 13:80fb167dafdf 817 #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_DH)
wolfSSL 13:80fb167dafdf 818 static int wc_DhAgree_Async(DhKey* key, byte* agree, word32* agreeSz,
wolfSSL 13:80fb167dafdf 819 const byte* priv, word32 privSz, const byte* otherPub, word32 pubSz)
wolfSSL 13:80fb167dafdf 820 {
wolfSSL 13:80fb167dafdf 821 int ret;
wolfSSL 13:80fb167dafdf 822
wolfSSL 13:80fb167dafdf 823 #ifdef HAVE_CAVIUM
wolfSSL 13:80fb167dafdf 824 /* TODO: Not implemented - use software for now */
wolfSSL 13:80fb167dafdf 825 ret = wc_DhAgree_Sync(key, agree, agreeSz, priv, privSz, otherPub, pubSz);
wolfSSL 13:80fb167dafdf 826
wolfSSL 13:80fb167dafdf 827 #elif defined(HAVE_INTEL_QA)
wolfSSL 13:80fb167dafdf 828 ret = wc_mp_to_bigint(&key->p, &key->p.raw);
wolfSSL 13:80fb167dafdf 829 if (ret == MP_OKAY)
wolfSSL 13:80fb167dafdf 830 ret = IntelQaDhAgree(&key->asyncDev, &key->p.raw,
wolfSSL 13:80fb167dafdf 831 agree, agreeSz, priv, privSz, otherPub, pubSz);
wolfSSL 13:80fb167dafdf 832 #else /* WOLFSSL_ASYNC_CRYPT_TEST */
wolfSSL 13:80fb167dafdf 833 WC_ASYNC_TEST* testDev = &key->asyncDev.test;
wolfSSL 13:80fb167dafdf 834 if (testDev->type == ASYNC_TEST_NONE) {
wolfSSL 13:80fb167dafdf 835 testDev->type = ASYNC_TEST_DH_AGREE;
wolfSSL 13:80fb167dafdf 836 testDev->dhAgree.key = key;
wolfSSL 13:80fb167dafdf 837 testDev->dhAgree.agree = agree;
wolfSSL 13:80fb167dafdf 838 testDev->dhAgree.agreeSz = agreeSz;
wolfSSL 13:80fb167dafdf 839 testDev->dhAgree.priv = priv;
wolfSSL 13:80fb167dafdf 840 testDev->dhAgree.privSz = privSz;
wolfSSL 13:80fb167dafdf 841 testDev->dhAgree.otherPub = otherPub;
wolfSSL 13:80fb167dafdf 842 testDev->dhAgree.pubSz = pubSz;
wolfSSL 13:80fb167dafdf 843 return WC_PENDING_E;
wolfSSL 13:80fb167dafdf 844 }
wolfSSL 13:80fb167dafdf 845 ret = wc_DhAgree_Sync(key, agree, agreeSz, priv, privSz, otherPub, pubSz);
wolfSSL 13:80fb167dafdf 846 #endif
wolfSSL 13:80fb167dafdf 847
wolfSSL 13:80fb167dafdf 848 return ret;
wolfSSL 13:80fb167dafdf 849 }
wolfSSL 13:80fb167dafdf 850 #endif /* WOLFSSL_ASYNC_CRYPT */
wolfSSL 13:80fb167dafdf 851
wolfSSL 13:80fb167dafdf 852 int wc_DhAgree(DhKey* key, byte* agree, word32* agreeSz, const byte* priv,
wolfSSL 13:80fb167dafdf 853 word32 privSz, const byte* otherPub, word32 pubSz)
wolfSSL 13:80fb167dafdf 854 {
wolfSSL 13:80fb167dafdf 855 int ret = 0;
wolfSSL 13:80fb167dafdf 856
wolfSSL 13:80fb167dafdf 857 if (key == NULL || agree == NULL || agreeSz == NULL || priv == NULL ||
wolfSSL 13:80fb167dafdf 858 otherPub == NULL) {
wolfSSL 13:80fb167dafdf 859 return BAD_FUNC_ARG;
wolfSSL 13:80fb167dafdf 860 }
wolfSSL 13:80fb167dafdf 861
wolfSSL 13:80fb167dafdf 862 #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_DH)
wolfSSL 13:80fb167dafdf 863 if (key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_DH) {
wolfSSL 13:80fb167dafdf 864 ret = wc_DhAgree_Async(key, agree, agreeSz, priv, privSz, otherPub, pubSz);
wolfSSL 13:80fb167dafdf 865 }
wolfSSL 13:80fb167dafdf 866 else
wolfSSL 13:80fb167dafdf 867 #endif
wolfSSL 13:80fb167dafdf 868 {
wolfSSL 13:80fb167dafdf 869 ret = wc_DhAgree_Sync(key, agree, agreeSz, priv, privSz, otherPub, pubSz);
wolfSSL 13:80fb167dafdf 870 }
wolfSSL 13:80fb167dafdf 871
wolfSSL 13:80fb167dafdf 872 return ret;
wolfSSL 13:80fb167dafdf 873 }
wolfSSL 13:80fb167dafdf 874
wolfSSL 13:80fb167dafdf 875
wolfSSL 13:80fb167dafdf 876 /* not in asn anymore since no actual asn types used */
wolfSSL 13:80fb167dafdf 877 int wc_DhSetKey(DhKey* key, const byte* p, word32 pSz, const byte* g,
wolfSSL 13:80fb167dafdf 878 word32 gSz)
wolfSSL 13:80fb167dafdf 879 {
wolfSSL 13:80fb167dafdf 880 if (key == NULL || p == NULL || g == NULL || pSz == 0 || gSz == 0) {
wolfSSL 13:80fb167dafdf 881 return BAD_FUNC_ARG;
wolfSSL 13:80fb167dafdf 882 }
wolfSSL 13:80fb167dafdf 883
wolfSSL 13:80fb167dafdf 884 /* may have leading 0 */
wolfSSL 13:80fb167dafdf 885 if (p[0] == 0) {
wolfSSL 13:80fb167dafdf 886 pSz--; p++;
wolfSSL 13:80fb167dafdf 887 }
wolfSSL 13:80fb167dafdf 888
wolfSSL 13:80fb167dafdf 889 if (g[0] == 0) {
wolfSSL 13:80fb167dafdf 890 gSz--; g++;
wolfSSL 13:80fb167dafdf 891 }
wolfSSL 13:80fb167dafdf 892
wolfSSL 13:80fb167dafdf 893 if (mp_init(&key->p) != MP_OKAY)
wolfSSL 13:80fb167dafdf 894 return MP_INIT_E;
wolfSSL 13:80fb167dafdf 895 if (mp_read_unsigned_bin(&key->p, p, pSz) != 0) {
wolfSSL 13:80fb167dafdf 896 mp_clear(&key->p);
wolfSSL 13:80fb167dafdf 897 return ASN_DH_KEY_E;
wolfSSL 13:80fb167dafdf 898 }
wolfSSL 13:80fb167dafdf 899
wolfSSL 13:80fb167dafdf 900 if (mp_init(&key->g) != MP_OKAY) {
wolfSSL 13:80fb167dafdf 901 mp_clear(&key->p);
wolfSSL 13:80fb167dafdf 902 return MP_INIT_E;
wolfSSL 13:80fb167dafdf 903 }
wolfSSL 13:80fb167dafdf 904 if (mp_read_unsigned_bin(&key->g, g, gSz) != 0) {
wolfSSL 13:80fb167dafdf 905 mp_clear(&key->g);
wolfSSL 13:80fb167dafdf 906 mp_clear(&key->p);
wolfSSL 13:80fb167dafdf 907 return ASN_DH_KEY_E;
wolfSSL 13:80fb167dafdf 908 }
wolfSSL 13:80fb167dafdf 909
wolfSSL 13:80fb167dafdf 910 return 0;
wolfSSL 13:80fb167dafdf 911 }
wolfSSL 13:80fb167dafdf 912
wolfSSL 13:80fb167dafdf 913 #endif /* NO_DH */
wolfSSL 13:80fb167dafdf 914