Merge pull request #1304 from cconlon/dsa1864

DSA 186-4 Key Generation, raw params and key import/export
This commit is contained in:
toddouska
2018-01-11 08:25:27 -08:00
committed by GitHub
8 changed files with 602 additions and 37 deletions

View File

@@ -200,6 +200,9 @@
#ifndef DSA_SIG_SIZE
#define DSA_SIG_SIZE 40
#endif
#ifndef MAX_DSA_PARAM_SIZE
#define MAX_DSA_PARAM_SIZE 256
#endif
#endif
#ifdef WOLFSSL_CMAC
@@ -10690,6 +10693,289 @@ static int test_wc_DsaKeyToDer (void)
} /* END test_wc_DsaKeyToDer */
/*
* Testing wc_DsaImportParamsRaw()
*/
static int test_wc_DsaImportParamsRaw (void)
{
int ret = 0;
#if !defined(NO_DSA)
DsaKey key;
/* [mod = L=1024, N=160], from CAVP KeyPair */
const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
"4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
"5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
"52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
"47123188f8dc551054ee162b634d60f097f719076640e209"
"80a0093113a8bd73";
const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
"138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
"b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
"07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
"61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
"76341a7e7d9";
/* invalid p and q parameters */
const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
const char* invalidQ = "96c5390a";
printf(testingFmt, "wc_DsaImportParamsRaw()");
ret = wc_InitDsaKey(&key);
if (ret == 0) {
ret = wc_DsaImportParamsRaw(&key, p, q, g);
}
/* test bad args */
if (ret == 0) {
/* null key struct */
ret = wc_DsaImportParamsRaw(NULL, p, q, g);
if (ret == BAD_FUNC_ARG) {
/* null param pointers */
ret = wc_DsaImportParamsRaw(&key, NULL, NULL, NULL);
}
if (ret == BAD_FUNC_ARG) {
/* illegal p length */
ret = wc_DsaImportParamsRaw(&key, invalidP, q, g);
}
if (ret == BAD_FUNC_ARG) {
/* illegal q length */
ret = wc_DsaImportParamsRaw(&key, p, invalidQ, g);
if (ret == BAD_FUNC_ARG)
ret = 0;
}
}
printf(resultFmt, ret == 0 ? passed : failed);
wc_FreeDsaKey(&key);
#endif
return ret;
} /* END test_wc_DsaImportParamsRaw */
/*
* Testing wc_DsaExportParamsRaw()
*/
static int test_wc_DsaExportParamsRaw (void)
{
int ret = 0;
#if !defined(NO_DSA)
DsaKey key;
/* [mod = L=1024, N=160], from CAVP KeyPair */
const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
"4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
"5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
"52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
"47123188f8dc551054ee162b634d60f097f719076640e209"
"80a0093113a8bd73";
const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
"138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
"b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
"07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
"61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
"76341a7e7d9";
const char* pCompare = "\xd3\x83\x11\xe2\xcd\x38\x8c\x3e\xd6\x98\xe8\x2f"
"\xdf\x88\xeb\x92\xb5\xa9\xa4\x83\xdc\x88\x00\x5d"
"\x4b\x72\x5e\xf3\x41\xea\xbb\x47\xcf\x8a\x7a\x8a"
"\x41\xe7\x92\xa1\x56\xb7\xce\x97\x20\x6c\x4f\x9c"
"\x5c\xe6\xfc\x5a\xe7\x91\x21\x02\xb6\xb5\x02\xe5"
"\x90\x50\xb5\xb2\x1c\xe2\x63\xdd\xdb\x20\x44\xb6"
"\x52\x23\x6f\x4d\x42\xab\x4b\x5d\x6a\xa7\x31\x89"
"\xce\xf1\xac\xe7\x78\xd7\x84\x5a\x5c\x1c\x1c\x71"
"\x47\x12\x31\x88\xf8\xdc\x55\x10\x54\xee\x16\x2b"
"\x63\x4d\x60\xf0\x97\xf7\x19\x07\x66\x40\xe2\x09"
"\x80\xa0\x09\x31\x13\xa8\xbd\x73";
const char* qCompare = "\x96\xc5\x39\x0a\x8b\x61\x2c\x0e\x42\x2b\xb2\xb0"
"\xea\x19\x4a\x3e\xc9\x35\xa2\x81";
const char* gCompare = "\x06\xb7\x86\x1a\xbb\xd3\x5c\xc8\x9e\x79\xc5\x2f"
"\x68\xd2\x08\x75\x38\x9b\x12\x73\x61\xca\x66\x82"
"\x21\x38\xce\x49\x91\xd2\xb8\x62\x25\x9d\x6b\x45"
"\x48\xa6\x49\x5b\x19\x5a\xa0\xe0\xb6\x13\x7c\xa3"
"\x7e\xb2\x3b\x94\x07\x4d\x3c\x3d\x30\x00\x42\xbd"
"\xf1\x57\x62\x81\x2b\x63\x33\xef\x7b\x07\xce\xba"
"\x78\x60\x76\x10\xfc\xc9\xee\x68\x49\x1d\xbc\x1e"
"\x34\xcd\x12\x61\x54\x74\xe5\x2b\x18\xbc\x93\x4f"
"\xb0\x0c\x61\xd3\x9e\x7d\xa8\x90\x22\x91\xc4\x43"
"\x4a\x4e\x22\x24\xc3\xf4\xfd\x9f\x93\xcd\x6f\x4f"
"\x17\xfc\x07\x63\x41\xa7\xe7\xd9";
byte pOut[MAX_DSA_PARAM_SIZE];
byte qOut[MAX_DSA_PARAM_SIZE];
byte gOut[MAX_DSA_PARAM_SIZE];
word32 pOutSz, qOutSz, gOutSz;
printf(testingFmt, "wc_DsaExportParamsRaw()");
ret = wc_InitDsaKey(&key);
if (ret == 0) {
/* first test using imported raw parameters, for expected */
ret = wc_DsaImportParamsRaw(&key, p, q, g);
}
if (ret == 0) {
pOutSz = sizeof(pOut);
qOutSz = sizeof(qOut);
gOutSz = sizeof(gOut);
ret = wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz,
gOut, &gOutSz);
}
if (ret == 0) {
/* validate exported parameters are correct */
if ((XMEMCMP(pOut, pCompare, pOutSz) != 0) ||
(XMEMCMP(qOut, qCompare, qOutSz) != 0) ||
(XMEMCMP(gOut, gCompare, gOutSz) != 0) ) {
ret = -1;
}
}
/* test bad args */
if (ret == 0) {
/* null key struct */
ret = wc_DsaExportParamsRaw(NULL, pOut, &pOutSz, qOut, &qOutSz,
gOut, &gOutSz);
if (ret == BAD_FUNC_ARG) {
/* null output pointers */
ret = wc_DsaExportParamsRaw(&key, NULL, &pOutSz, NULL, &qOutSz,
NULL, &gOutSz);
}
if (ret == LENGTH_ONLY_E) {
/* null output size pointers */
ret = wc_DsaExportParamsRaw(&key, pOut, NULL, qOut, NULL,
gOut, NULL);
}
if (ret == BAD_FUNC_ARG) {
/* p output buffer size too small */
pOutSz = 1;
ret = wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz,
gOut, &gOutSz);
pOutSz = sizeof(pOut);
}
if (ret == BUFFER_E) {
/* q output buffer size too small */
qOutSz = 1;
ret = wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz,
gOut, &gOutSz);
qOutSz = sizeof(qOut);
}
if (ret == BUFFER_E) {
/* g output buffer size too small */
gOutSz = 1;
ret = wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz,
gOut, &gOutSz);
if (ret == BUFFER_E)
ret = 0;
}
}
printf(resultFmt, ret == 0 ? passed : failed);
wc_FreeDsaKey(&key);
#endif
return ret;
} /* END test_wc_DsaExportParamsRaw */
/*
* Testing wc_DsaExportKeyRaw()
*/
static int test_wc_DsaExportKeyRaw (void)
{
int ret = 0;
#if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
DsaKey key;
WC_RNG rng;
byte xOut[MAX_DSA_PARAM_SIZE];
byte yOut[MAX_DSA_PARAM_SIZE];
word32 xOutSz, yOutSz;
printf(testingFmt, "wc_DsaExportKeyRaw()");
ret = wc_InitRng(&rng);
if (ret == 0) {
ret = wc_InitDsaKey(&key);
}
if (ret == 0) {
ret = wc_MakeDsaParameters(&rng, 1024, &key);
if (ret == 0) {
ret = wc_MakeDsaKey(&rng, &key);
}
}
/* try successful export */
if (ret == 0) {
xOutSz = sizeof(xOut);
yOutSz = sizeof(yOut);
ret = wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz);
}
/* test bad args */
if (ret == 0) {
/* null key struct */
ret = wc_DsaExportKeyRaw(NULL, xOut, &xOutSz, yOut, &yOutSz);
if (ret == BAD_FUNC_ARG) {
/* null output pointers */
ret = wc_DsaExportKeyRaw(&key, NULL, &xOutSz, NULL, &yOutSz);
}
if (ret == LENGTH_ONLY_E) {
/* null output size pointers */
ret = wc_DsaExportKeyRaw(&key, xOut, NULL, yOut, NULL);
}
if (ret == BAD_FUNC_ARG) {
/* x output buffer size too small */
xOutSz = 1;
ret = wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz);
xOutSz = sizeof(xOut);
}
if (ret == BUFFER_E) {
/* y output buffer size too small */
yOutSz = 1;
ret = wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz);
if (ret == BUFFER_E)
ret = 0;
}
}
printf(resultFmt, ret == 0 ? passed : failed);
wc_FreeDsaKey(&key);
wc_FreeRng(&rng);
#endif
return ret;
} /* END test_wc_DsaExportParamsRaw */
/*
* Testing wc_ed25519_make_key().
@@ -15485,6 +15771,9 @@ void ApiTest(void)
AssertIntEQ(test_wc_DsaPublicPrivateKeyDecode(), 0);
AssertIntEQ(test_wc_MakeDsaKey(), 0);
AssertIntEQ(test_wc_DsaKeyToDer(), 0);
AssertIntEQ(test_wc_DsaImportParamsRaw(), 0);
AssertIntEQ(test_wc_DsaExportParamsRaw(), 0);
AssertIntEQ(test_wc_DsaExportKeyRaw(), 0);
#ifdef OPENSSL_EXTRA
/*wolfSSS_EVP_get_cipherbynid test*/

View File

@@ -97,68 +97,133 @@ void wc_FreeDsaKey(DsaKey* key)
mp_clear(&key->p);
}
/* validate that (L,N) match allowed sizes from FIPS 186-4, Section 4.2.
* modLen - represents L, the size of p (prime modulus) in bits
* divLen - represents N, the size of q (prime divisor) in bits
* return 0 on success, -1 on error */
static int CheckDsaLN(int modLen, int divLen)
{
int ret = -1;
switch (modLen) {
case 1024:
if (divLen == 160)
ret = 0;
break;
case 2048:
if (divLen == 224 || divLen == 256)
ret = 0;
break;
case 3072:
if (divLen == 256)
ret = 0;
break;
default:
break;
}
return ret;
}
#ifdef WOLFSSL_KEY_GEN
/* Create DSA key pair (&dsa->x, &dsa->y)
*
* Based on NIST FIPS 186-4,
* "B.1.1 Key Pair Generation Using Extra Random Bits"
*
* rng - pointer to initialized WC_RNG structure
* dsa - pointer to initialized DsaKey structure, will hold generated key
*
* return 0 on success, negative on error */
int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa)
{
unsigned char *buf;
int qsize, err;
byte* cBuf;
int qSz, pSz, cSz, err;
mp_int tmpQ;
if (rng == NULL || dsa == NULL)
return BAD_FUNC_ARG;
qsize = mp_unsigned_bin_size(&dsa->q);
if (qsize == 0)
qSz = mp_unsigned_bin_size(&dsa->q);
pSz = mp_unsigned_bin_size(&dsa->p);
/* verify (L,N) pair bit lengths */
if (CheckDsaLN(pSz * WOLFSSL_BIT_SIZE, qSz * WOLFSSL_BIT_SIZE) != 0)
return BAD_FUNC_ARG;
/* allocate ram */
buf = (unsigned char *)XMALLOC(qsize, dsa->heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (buf == NULL)
/* generate extra 64 bits so that bias from mod function is negligible */
cSz = qSz + (64 / WOLFSSL_BIT_SIZE);
cBuf = (byte*)XMALLOC(cSz, dsa->heap, DYNAMIC_TYPE_TMP_BUFFER);
if (cBuf == NULL) {
return MEMORY_E;
}
if (mp_init(&dsa->x) != MP_OKAY) {
XFREE(buf, dsa->heap, DYNAMIC_TYPE_TMP_BUFFER);
return MP_INIT_E;
if ((err = mp_init_multi(&dsa->x, &dsa->y, &tmpQ, NULL, NULL, NULL))
!= MP_OKAY) {
XFREE(cBuf, dsa->heap, DYNAMIC_TYPE_TMP_BUFFER);
return err;
}
do {
/* make a random exponent mod q */
err = wc_RNG_GenerateBlock(rng, buf, qsize);
/* generate N+64 bits (c) from RBG into &dsa->x, making sure positive.
* Hash_DRBG uses SHA-256 which matches maximum
* requested_security_strength of (L,N) */
err = wc_RNG_GenerateBlock(rng, cBuf, cSz);
if (err != MP_OKAY) {
mp_clear(&dsa->x);
XFREE(buf, dsa->heap, DYNAMIC_TYPE_TMP_BUFFER);
mp_clear(&dsa->y);
mp_clear(&tmpQ);
XFREE(cBuf, dsa->heap, DYNAMIC_TYPE_TMP_BUFFER);
return err;
}
err = mp_read_unsigned_bin(&dsa->x, buf, qsize);
err = mp_read_unsigned_bin(&dsa->x, cBuf, cSz);
if (err != MP_OKAY) {
mp_clear(&dsa->x);
XFREE(buf, dsa->heap, DYNAMIC_TYPE_TMP_BUFFER);
mp_clear(&dsa->y);
mp_clear(&tmpQ);
XFREE(cBuf, dsa->heap, DYNAMIC_TYPE_TMP_BUFFER);
return err;
}
} while (mp_cmp_d(&dsa->x, 1) != MP_GT);
XFREE(buf, dsa->heap, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(cBuf, dsa->heap, DYNAMIC_TYPE_TMP_BUFFER);
if (mp_init(&dsa->y) != MP_OKAY) {
mp_clear(&dsa->x);
return MP_INIT_E;
}
/* tmpQ = q - 1 */
if (err == MP_OKAY)
err = mp_copy(&dsa->q, &tmpQ);
if (err == MP_OKAY)
err = mp_sub_d(&tmpQ, 1, &tmpQ);
/* x = c mod (q-1), &dsa->x holds c */
if (err == MP_OKAY)
err = mp_mod(&dsa->x, &tmpQ, &dsa->x);
/* x = c mod (q-1) + 1 */
if (err == MP_OKAY)
err = mp_add_d(&dsa->x, 1, &dsa->x);
/* public key : y = g^x mod p */
err = mp_exptmod(&dsa->g, &dsa->x, &dsa->p, &dsa->y);
if (err == MP_OKAY)
err = mp_exptmod(&dsa->g, &dsa->x, &dsa->p, &dsa->y);
if (err == MP_OKAY)
dsa->type = DSA_PRIVATE;
if (err != MP_OKAY) {
mp_clear(&dsa->x);
mp_clear(&dsa->y);
return err;
}
mp_clear(&tmpQ);
dsa->type = DSA_PRIVATE;
return MP_OKAY;
return err;
}
/* modulus_size in bits */
int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa)
{
@@ -188,7 +253,7 @@ int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa)
}
/* modulus size in bytes */
msize = modulus_size / 8;
msize = modulus_size / WOLFSSL_BIT_SIZE;
/* allocate ram */
buf = (unsigned char *)XMALLOC(msize - qsize,
@@ -361,6 +426,199 @@ int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa)
#endif /* WOLFSSL_KEY_GEN */
/* Import raw DSA parameters into DsaKey structure for use with wc_MakeDsaKey(),
* input parameters (p,q,g) should be represented as ASCII hex values.
*
* dsa - pointer to initialized DsaKey structure
* p - DSA (p) parameter, ASCII hex string
* pSz - length of p
* q - DSA (q) parameter, ASCII hex string
* qSz - length of q
* g - DSA (g) parameter, ASCII hex string
* gSz - length of g
*
* returns 0 on success, negative upon failure
*/
int wc_DsaImportParamsRaw(DsaKey* dsa, const char* p, const char* q,
const char* g)
{
int err;
word32 pSz, qSz;
if (dsa == NULL || p == NULL || q == NULL || g == NULL)
return BAD_FUNC_ARG;
/* read p */
err = mp_read_radix(&dsa->p, p, MP_RADIX_HEX);
/* read q */
if (err == MP_OKAY)
err = mp_read_radix(&dsa->q, q, MP_RADIX_HEX);
/* read g */
if (err == MP_OKAY)
err = mp_read_radix(&dsa->g, g, MP_RADIX_HEX);
/* verify (L,N) pair bit lengths */
pSz = mp_unsigned_bin_size(&dsa->p);
qSz = mp_unsigned_bin_size(&dsa->q);
if (CheckDsaLN(pSz * WOLFSSL_BIT_SIZE, qSz * WOLFSSL_BIT_SIZE) != 0) {
WOLFSSL_MSG("Invalid DSA p or q parameter size");
err = BAD_FUNC_ARG;
}
if (err != MP_OKAY) {
mp_clear(&dsa->p);
mp_clear(&dsa->q);
mp_clear(&dsa->g);
}
return err;
}
/* Export raw DSA parameters from DsaKey structure
*
* dsa - pointer to initialized DsaKey structure
* p - output location for DSA (p) parameter
* pSz - [IN/OUT] size of output buffer for p, size of p
* q - output location for DSA (q) parameter
* qSz - [IN/OUT] size of output buffer for q, size of q
* g - output location for DSA (g) parameter
* gSz - [IN/OUT] size of output buffer for g, size of g
*
* If p, q, and g pointers are all passed in as NULL, the function
* will set pSz, qSz, and gSz to the required output buffer sizes for p,
* q, and g. In this case, the function will return LENGTH_ONLY_E.
*
* returns 0 on success, negative upon failure
*/
int wc_DsaExportParamsRaw(DsaKey* dsa, byte* p, word32* pSz,
byte* q, word32* qSz, byte* g, word32* gSz)
{
int err;
word32 pLen, qLen, gLen;
if (dsa == NULL || pSz == NULL || qSz == NULL || gSz == NULL)
return BAD_FUNC_ARG;
/* get required output buffer sizes */
pLen = mp_unsigned_bin_size(&dsa->p);
qLen = mp_unsigned_bin_size(&dsa->q);
gLen = mp_unsigned_bin_size(&dsa->g);
/* return buffer sizes and LENGTH_ONLY_E if buffers are NULL */
if (p == NULL && q == NULL && g == NULL) {
*pSz = pLen;
*qSz = qLen;
*gSz = gLen;
return LENGTH_ONLY_E;
}
if (p == NULL || q == NULL || g == NULL)
return BAD_FUNC_ARG;
/* export p */
if (*pSz < pLen) {
WOLFSSL_MSG("Output buffer for DSA p parameter too small, "
"required size placed into pSz");
*pSz = pLen;
return BUFFER_E;
}
*pSz = pLen;
err = mp_to_unsigned_bin(&dsa->p, p);
/* export q */
if (err == MP_OKAY) {
if (*qSz < qLen) {
WOLFSSL_MSG("Output buffer for DSA q parameter too small, "
"required size placed into qSz");
*qSz = qLen;
return BUFFER_E;
}
*qSz = qLen;
err = mp_to_unsigned_bin(&dsa->q, q);
}
/* export g */
if (err == MP_OKAY) {
if (*gSz < gLen) {
WOLFSSL_MSG("Output buffer for DSA g parameter too small, "
"required size placed into gSz");
*gSz = gLen;
return BUFFER_E;
}
*gSz = gLen;
err = mp_to_unsigned_bin(&dsa->g, g);
}
return err;
}
/* Export raw DSA key (x, y) from DsaKey structure
*
* dsa - pointer to initialized DsaKey structure
* x - output location for private key
* xSz - [IN/OUT] size of output buffer for x, size of x
* y - output location for public key
* ySz - [IN/OUT] size of output buffer for y, size of y
*
* If x and y pointers are all passed in as NULL, the function
* will set xSz and ySz to the required output buffer sizes for x
* and y. In this case, the function will return LENGTH_ONLY_E.
*
* returns 0 on success, negative upon failure
*/
int wc_DsaExportKeyRaw(DsaKey* dsa, byte* x, word32* xSz, byte* y, word32* ySz)
{
int err;
word32 xLen, yLen;
if (dsa == NULL || xSz == NULL || ySz == NULL)
return BAD_FUNC_ARG;
/* get required output buffer sizes */
xLen = mp_unsigned_bin_size(&dsa->x);
yLen = mp_unsigned_bin_size(&dsa->y);
/* return buffer sizes and LENGTH_ONLY_E if buffers are NULL */
if (x == NULL && y == NULL) {
*xSz = xLen;
*ySz = yLen;
return LENGTH_ONLY_E;
}
if (x == NULL || y == NULL)
return BAD_FUNC_ARG;
/* export x */
if (*xSz < xLen) {
WOLFSSL_MSG("Output buffer for DSA private key (x) too small, "
"required size placed into xSz");
*xSz = xLen;
return BUFFER_E;
}
*xSz = xLen;
err = mp_to_unsigned_bin(&dsa->x, x);
/* export y */
if (err == MP_OKAY) {
if (*ySz < yLen) {
WOLFSSL_MSG("Output buffer to DSA public key (y) too small, "
"required size placed into ySz");
*ySz = yLen;
return BUFFER_E;
}
*ySz = yLen;
err = mp_to_unsigned_bin(&dsa->y, y);
}
return err;
}
int wc_DsaSign(const byte* digest, byte* out, DsaKey* key, WC_RNG* rng)
{
mp_int k, kInv, r, s, H;

View File

@@ -4729,15 +4729,16 @@ LBL_U:mp_clear (&v);
#endif /* WOLFSSL_KEY_GEN */
#if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY) || \
defined(WOLFSSL_DEBUG_MATH) || defined(DEBUG_WOLFSSL)
#if !defined(NO_DSA) || defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || \
defined(HAVE_COMP_KEY) || defined(WOLFSSL_DEBUG_MATH) || \
defined(DEBUG_WOLFSSL)
/* chars used in radix conversions */
const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz+/";
#endif
#ifdef HAVE_ECC
#if !defined(NO_DSA) || defined(HAVE_ECC)
/* read a string [ASCII] in a given radix */
int mp_read_radix (mp_int * a, const char *str, int radix)
{
@@ -4807,7 +4808,7 @@ int mp_read_radix (mp_int * a, const char *str, int radix)
}
return MP_OKAY;
}
#endif /* HAVE_ECC */
#endif /* !defined(NO_DSA) || defined(HAVE_ECC) */
#if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY) || \
defined(WOLFSSL_DEBUG_MATH) || defined(DEBUG_WOLFSSL)

View File

@@ -3076,15 +3076,16 @@ int mp_add_d(fp_int *a, fp_digit b, fp_int *c)
#endif /* HAVE_ECC || !NO_PWDBASED */
#if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY) || \
defined(WOLFSSL_DEBUG_MATH) || defined(DEBUG_WOLFSSL)
#if !defined(NO_DSA) || defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || \
defined(HAVE_COMP_KEY) || defined(WOLFSSL_DEBUG_MATH) || \
defined(DEBUG_WOLFSSL)
/* chars used in radix conversions */
static const char* const fp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz+/";
#endif
#ifdef HAVE_ECC
#if !defined(NO_DSA) || defined(HAVE_ECC)
#if DIGIT_BIT == 64 || DIGIT_BIT == 32
static int fp_read_radix_16(fp_int *a, const char *str)
{
@@ -3197,6 +3198,10 @@ int mp_read_radix(mp_int *a, const char *str, int radix)
return fp_read_radix(a, str, radix);
}
#endif /* !defined(NO_DSA) || defined(HAVE_ECC) */
#ifdef HAVE_ECC
/* fast math conversion */
int mp_sqr(fp_int *A, fp_int *B)
{

View File

@@ -74,6 +74,14 @@ WOLFSSL_API int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa);
WOLFSSL_API int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa);
#endif
/* raw export functions */
WOLFSSL_API int wc_DsaImportParamsRaw(DsaKey* dsa, const char* p,
const char* q, const char* g);
WOLFSSL_API int wc_DsaExportParamsRaw(DsaKey* dsa, byte* p, word32* pSz,
byte* q, word32* qSz, byte* g,
word32* gSz);
WOLFSSL_API int wc_DsaExportKeyRaw(DsaKey* dsa, byte* x, word32* xSz, byte* y,
word32* ySz);
#ifdef __cplusplus
} /* extern "C" */
#endif

View File

@@ -364,7 +364,7 @@ MP_API int mp_radix_size (mp_int * a, int radix, int *size);
#if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
MP_API int mp_sqrmod(mp_int* a, mp_int* b, mp_int* c);
#endif
#if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
#if !defined(NO_DSA) || defined(HAVE_ECC)
MP_API int mp_read_radix(mp_int* a, const char* str, int radix);
#endif

View File

@@ -703,8 +703,11 @@ MP_API int mp_radix_size (mp_int * a, int radix, int *size);
#define mp_dump(desc, a, verbose)
#endif
#ifdef HAVE_ECC
#if !defined(NO_DSA) || defined(HAVE_ECC)
MP_API int mp_read_radix(mp_int* a, const char* str, int radix);
#endif
#ifdef HAVE_ECC
MP_API int mp_sqr(fp_int *a, fp_int *b);
MP_API int mp_montgomery_reduce(fp_int *a, fp_int *m, fp_digit mp);
MP_API int mp_montgomery_setup(fp_int *a, fp_digit *rho);

View File

@@ -350,7 +350,8 @@
#ifndef CTYPE_USER
#include <ctype.h>
#if defined(HAVE_ECC) || defined(HAVE_OCSP) || defined(WOLFSSL_KEY_GEN)
#if defined(HAVE_ECC) || defined(HAVE_OCSP) || \
defined(WOLFSSL_KEY_GEN) || !defined(NO_DSA)
#define XTOUPPER(c) toupper((c))
#define XISALPHA(c) isalpha((c))
#endif