forked from wolfSSL/wolfssl
update to ECC key parsing custom curves for Windows
This commit is contained in:
@ -14373,9 +14373,25 @@ int wc_EccPublicKeyDecode(const byte* input, word32* inOutIdx,
|
|||||||
ret = ASN_PARSE_E;
|
ret = ASN_PARSE_E;
|
||||||
}
|
}
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
char* p = NULL;
|
||||||
SkipObjectId(input, inOutIdx, inSz);
|
SkipObjectId(input, inOutIdx, inSz);
|
||||||
ret = ASNToHexString(input, inOutIdx, (char**)&curve->prime, inSz,
|
ret = ASNToHexString(input, inOutIdx, &p, inSz,
|
||||||
key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
|
#ifndef USE_WINDOWS_API
|
||||||
|
curve->prime = p;
|
||||||
|
#else
|
||||||
|
if (ret == 0 && p != NULL) {
|
||||||
|
length = XSTRLEN(p) + 1;
|
||||||
|
if (length > MAX_ECC_STRING) {
|
||||||
|
WOLFSSL_MSG("Prime too large for buffer");
|
||||||
|
ret = BUFFER_E;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
XSTRNCPY(curve->prime, p, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XFREE(p, key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
curve->size = (int)XSTRLEN(curve->prime) / 2;
|
curve->size = (int)XSTRLEN(curve->prime) / 2;
|
||||||
@ -14384,12 +14400,45 @@ int wc_EccPublicKeyDecode(const byte* input, word32* inOutIdx,
|
|||||||
ret = ASN_PARSE_E;
|
ret = ASN_PARSE_E;
|
||||||
}
|
}
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
ret = ASNToHexString(input, inOutIdx, (char**)&curve->Af, inSz,
|
char* af = NULL;
|
||||||
|
ret = ASNToHexString(input, inOutIdx, &af, inSz,
|
||||||
key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
|
#ifndef USE_WINDOWS_API
|
||||||
|
curve->Af = af;
|
||||||
|
#else
|
||||||
|
if (ret == 0 && af != NULL) {
|
||||||
|
length = XSTRLEN(af) + 1;
|
||||||
|
if (length > MAX_ECC_STRING) {
|
||||||
|
WOLFSSL_MSG("Af too large for buffer");
|
||||||
|
ret = BUFFER_E;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
XSTRNCPY(curve->Af, af, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XFREE(af, key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
ret = ASNToHexString(input, inOutIdx, (char**)&curve->Bf, inSz,
|
char* bf = NULL;
|
||||||
|
ret = ASNToHexString(input, inOutIdx, &bf, inSz,
|
||||||
key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
|
#ifndef USE_WINDOWS_API
|
||||||
|
curve->Bf = bf;
|
||||||
|
#else
|
||||||
|
if (ret == 0 && bf != NULL) {
|
||||||
|
length = XSTRLEN(bf) + 1;
|
||||||
|
if (length > MAX_ECC_STRING) {
|
||||||
|
WOLFSSL_MSG("Bf too large for buffer");
|
||||||
|
ret = BUFFER_E;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
XSTRNCPY(curve->Bf, bf, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XFREE(bf, key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
localIdx = *inOutIdx;
|
localIdx = *inOutIdx;
|
||||||
@ -14430,14 +14479,32 @@ int wc_EccPublicKeyDecode(const byte* input, word32* inOutIdx,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
char* o = NULL;
|
||||||
|
|
||||||
XMEMCPY((char*)curve->Gx, point + 2, curve->size * 2);
|
XMEMCPY((char*)curve->Gx, point + 2, curve->size * 2);
|
||||||
XMEMCPY((char*)curve->Gy, point + curve->size * 2 + 2,
|
XMEMCPY((char*)curve->Gy, point + curve->size * 2 + 2,
|
||||||
curve->size * 2);
|
curve->size * 2);
|
||||||
((char*)curve->Gx)[curve->size * 2] = '\0';
|
((char*)curve->Gx)[curve->size * 2] = '\0';
|
||||||
((char*)curve->Gy)[curve->size * 2] = '\0';
|
((char*)curve->Gy)[curve->size * 2] = '\0';
|
||||||
XFREE(point, key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
XFREE(point, key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
ret = ASNToHexString(input, inOutIdx, (char**)&curve->order, inSz,
|
ret = ASNToHexString(input, inOutIdx, &o, inSz,
|
||||||
key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
|
|
||||||
|
#ifndef USE_WINDOWS_API
|
||||||
|
curve->order = o;
|
||||||
|
#else
|
||||||
|
if (ret == 0 && o != NULL) {
|
||||||
|
length = XSTRLEN(o) + 1;
|
||||||
|
if (length > MAX_ECC_STRING) {
|
||||||
|
WOLFSSL_MSG("Order too large for buffer");
|
||||||
|
ret = BUFFER_E;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
XSTRNCPY(curve->order, o, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XFREE(o, key->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
curve->cofactor = GetInteger7Bit(input, inOutIdx, inSz);
|
curve->cofactor = GetInteger7Bit(input, inOutIdx, inSz);
|
||||||
|
@ -5127,6 +5127,7 @@ int wc_ecc_sign_set_k(const byte* k, word32 klen, ecc_key* key)
|
|||||||
#ifdef WOLFSSL_CUSTOM_CURVES
|
#ifdef WOLFSSL_CUSTOM_CURVES
|
||||||
void wc_ecc_free_curve(const ecc_set_type* curve, void* heap)
|
void wc_ecc_free_curve(const ecc_set_type* curve, void* heap)
|
||||||
{
|
{
|
||||||
|
#ifndef USE_WINDOWS_API
|
||||||
if (curve->prime != NULL)
|
if (curve->prime != NULL)
|
||||||
XFREE((void*)curve->prime, heap, DYNAMIC_TYPE_ECC_BUFFER);
|
XFREE((void*)curve->prime, heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
if (curve->Af != NULL)
|
if (curve->Af != NULL)
|
||||||
@ -5139,6 +5140,7 @@ void wc_ecc_free_curve(const ecc_set_type* curve, void* heap)
|
|||||||
XFREE((void*)curve->Gx, heap, DYNAMIC_TYPE_ECC_BUFFER);
|
XFREE((void*)curve->Gx, heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
if (curve->Gy != NULL)
|
if (curve->Gy != NULL)
|
||||||
XFREE((void*)curve->Gy, heap, DYNAMIC_TYPE_ECC_BUFFER);
|
XFREE((void*)curve->Gy, heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
|
#endif
|
||||||
|
|
||||||
XFREE((void*)curve, heap, DYNAMIC_TYPE_ECC_BUFFER);
|
XFREE((void*)curve, heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user