Added PKCS8 support for ED25519.

This commit is contained in:
David Garske
2020-01-15 09:56:32 -08:00
parent 7707234901
commit 40c8562dc2
3 changed files with 17 additions and 16 deletions

View File

@@ -5497,12 +5497,19 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
/* ASN1 (DER) or RAW (NTRU) */ /* ASN1 (DER) or RAW (NTRU) */
int length = (int)sz; int length = (int)sz;
if (format == WOLFSSL_FILETYPE_ASN1) { if (format == WOLFSSL_FILETYPE_ASN1) {
/* get length of der (read sequence) */ /* get length of der (read sequence or octet string) */
word32 inOutIdx = 0; word32 inOutIdx = 0;
if (GetSequence(buff, &inOutIdx, &length, (word32)sz) < 0) { if (GetSequence(buff, &inOutIdx, &length, (word32)sz) >= 0) {
length += inOutIdx; /* include leading sequence */
}
/* get length using octect string (allowed for private key types) */
else if (type == PRIVATEKEY_TYPE &&
GetOctetString(buff, &inOutIdx, &length, (word32)sz) >= 0) {
length += inOutIdx; /* include leading oct string */
}
else {
ret = ASN_PARSE_E; ret = ASN_PARSE_E;
} }
length += inOutIdx; /* include leading sequence */
} }
info->consumed = length; info->consumed = length;

View File

@@ -423,7 +423,7 @@ static int SetBoolean(int val, byte* output)
* invalid. * invalid.
* Otherwise, the number of bytes in the ASN.1 data. * Otherwise, the number of bytes in the ASN.1 data.
*/ */
static int GetOctetString(const byte* input, word32* inOutIdx, int* len, int GetOctetString(const byte* input, word32* inOutIdx, int* len,
word32 maxIdx) word32 maxIdx)
{ {
return GetASNHeader(input, ASN_OCTET_STRING, inOutIdx, len, maxIdx); return GetASNHeader(input, ASN_OCTET_STRING, inOutIdx, len, maxIdx);
@@ -10385,14 +10385,8 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
if (ret >= 0) { if (ret >= 0) {
der->length = ret; der->length = ret;
if ((algId == ECDSAk) && (keyFormat != NULL)) if (keyFormat)
*keyFormat = ECDSAk; *keyFormat = algId;
else if ((algId == DSAk) && (keyFormat != NULL))
*keyFormat = DSAk;
#if defined(WOLFSSL_QT) || defined(OPENSSL_ALL)
else if ((algId == DHk) && (keyFormat != NULL))
*keyFormat = DHk;
#endif
ret = 0; ret = 0;
} }
#else #else

View File

@@ -432,10 +432,8 @@ enum Key_Sum {
RSAk = 645, RSAk = 645,
NTRUk = 274, NTRUk = 274,
ECDSAk = 518, ECDSAk = 518,
ED25519k = 256 ED25519k = 256,
#if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) DHk = 647, /* dhKeyAgreement OID: 1.2.840.113549.1.3.1 */
,DHk = 647 /* dhKeyAgreement OID: 1.2.840.113549.1.3.1 */
#endif
}; };
#if !defined(NO_AES) || defined(HAVE_PKCS7) #if !defined(NO_AES) || defined(HAVE_PKCS7)
@@ -1114,6 +1112,8 @@ WOLFSSL_LOCAL int GetSequence(const byte* input, word32* inOutIdx, int* len,
word32 maxIdx); word32 maxIdx);
WOLFSSL_LOCAL int GetSequence_ex(const byte* input, word32* inOutIdx, int* len, WOLFSSL_LOCAL int GetSequence_ex(const byte* input, word32* inOutIdx, int* len,
word32 maxIdx, int check); word32 maxIdx, int check);
WOLFSSL_LOCAL int GetOctetString(const byte* input, word32* inOutIdx, int* len,
word32 maxIdx);
WOLFSSL_LOCAL int GetSet(const byte* input, word32* inOutIdx, int* len, WOLFSSL_LOCAL int GetSet(const byte* input, word32* inOutIdx, int* len,
word32 maxIdx); word32 maxIdx);
WOLFSSL_LOCAL int GetSet_ex(const byte* input, word32* inOutIdx, int* len, WOLFSSL_LOCAL int GetSet_ex(const byte* input, word32* inOutIdx, int* len,