Ed ASN template: change for IMPLICIT public key in private key

Fix KATs in test.c to match new expected format.
This commit is contained in:
Sean Parkinson
2022-07-14 10:19:43 +10:00
parent 2d5bc72c9b
commit b69af856de
2 changed files with 22 additions and 28 deletions

View File

@@ -29661,9 +29661,7 @@ static const ASNItem edKeyASN[] = {
/* attributes */
/* ATTRS */ { 1, ASN_CONTEXT_SPECIFIC | ASN_ASYMKEY_ATTRS, 1, 1, 1 },
/* publicKey */
/* PUBKEY */ { 1, ASN_CONTEXT_SPECIFIC | ASN_ASYMKEY_PUBKEY, 1, 1, 1 },
/* Public value */
/* PUBKEY_VAL */ { 2, ASN_OCTET_STRING, 0, 0, 0 }
/* PUBKEY */ { 1, ASN_CONTEXT_SPECIFIC | ASN_ASYMKEY_PUBKEY, 0, 0, 1 },
};
enum {
EDKEYASN_IDX_SEQ = 0,
@@ -29674,7 +29672,6 @@ enum {
EDKEYASN_IDX_PKEY_CURVEPKEY,
EDKEYASN_IDX_ATTRS,
EDKEYASN_IDX_PUBKEY,
EDKEYASN_IDX_PUBKEY_VAL,
};
/* Number of items in ASN.1 template for Ed25519 and Ed448 private key. */
@@ -29756,10 +29753,7 @@ static int DecodeAsymKey(const byte* input, word32* inOutIdx, word32 inSz,
}
if (GetASNHeader(input, ASN_CONTEXT_SPECIFIC | ASN_ASYMKEY_PUBKEY | 1,
inOutIdx, &length, inSz) < 0) {
return ASN_PARSE_E;
}
if (GetOctetString(input, inOutIdx, &pubSz, inSz) < 0) {
inOutIdx, &pubSz, inSz) < 0) {
return ASN_PARSE_E;
}
@@ -29811,7 +29805,7 @@ static int DecodeAsymKey(const byte* input, word32* inOutIdx, word32 inSz,
}
else if ((ret == 0) &&
(pubKeyLen != NULL) &&
(dataASN[EDKEYASN_IDX_PUBKEY_VAL].data.ref.length > *pubKeyLen)) {
(dataASN[EDKEYASN_IDX_PUBKEY].data.ref.length > *pubKeyLen)) {
ret = ASN_PARSE_E;
}
else if (ret == 0) {
@@ -29820,9 +29814,9 @@ static int DecodeAsymKey(const byte* input, word32* inOutIdx, word32 inSz,
XMEMCPY(privKey, dataASN[EDKEYASN_IDX_PKEY_CURVEPKEY].data.ref.data,
*privKeyLen);
if (pubKeyLen != NULL)
*pubKeyLen = dataASN[EDKEYASN_IDX_PUBKEY_VAL].data.ref.length;
*pubKeyLen = dataASN[EDKEYASN_IDX_PUBKEY].data.ref.length;
if (pubKey != NULL && pubKeyLen != NULL)
XMEMCPY(pubKey, dataASN[EDKEYASN_IDX_PUBKEY_VAL].data.ref.data,
XMEMCPY(pubKey, dataASN[EDKEYASN_IDX_PUBKEY].data.ref.data,
*pubKeyLen);
}
@@ -30101,7 +30095,7 @@ static int SetAsymKeyDer(const byte* privKey, word32 privKeyLen,
dataASN[EDKEYASN_IDX_ATTRS].noOut = 1;
if (pubKey) {
/* Leave space for public key. */
SetASN_Buffer(&dataASN[EDKEYASN_IDX_PUBKEY_VAL], NULL, pubKeyLen);
SetASN_Buffer(&dataASN[EDKEYASN_IDX_PUBKEY], NULL, pubKeyLen);
}
else {
/* Don't put out public part. */
@@ -30127,7 +30121,7 @@ static int SetAsymKeyDer(const byte* privKey, word32 privKeyLen,
if (pubKey != NULL) {
/* Put public value into space provided. */
XMEMCPY((byte*)dataASN[EDKEYASN_IDX_PUBKEY_VAL].data.buffer.data,
XMEMCPY((byte*)dataASN[EDKEYASN_IDX_PUBKEY].data.buffer.data,
pubKey, pubKeyLen);
}
}

View File

@@ -27290,17 +27290,17 @@ WOLFSSL_TEST_SUBROUTINE int ed25519_test(void)
0x00 /* add an additional byte to make the pubkey appear bigger */
};
static byte privPubEd25519[] = {
0x30,0x52,0x02,0x01,0x00,0x30,0x05,0x06,
0x30,0x50,0x02,0x01,0x00,0x30,0x05,0x06,
0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
0xa1,0x22,0x04,0x20,0xd7,0x5a,0x98,0x01,
0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
0xf7,0x07,0x51,0x1a
0x81,0x20,0xd7,0x5a,0x98,0x01,0x82,0xb1,
0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,0xc9,0x64,
0x07,0x3a,0x0e,0xe1,0x72,0xf3,0xda,0xa6,
0x23,0x25,0xaf,0x02,0x1a,0x68,0xf7,0x07,
0x51,0x1a
};
word32 idx;
@@ -28713,7 +28713,7 @@ WOLFSSL_TEST_SUBROUTINE int ed448_test(void)
0xaf, 0xe8, 0x25, 0x61, 0x80
};
static const byte privPubEd448[] = {
0x30, 0x81, 0x84, 0x02, 0x01, 0x00, 0x30, 0x05,
0x30, 0x81, 0x82, 0x02, 0x01, 0x00, 0x30, 0x05,
0x06, 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04,
0x39, 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d,
0x10, 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e,
@@ -28722,14 +28722,14 @@ WOLFSSL_TEST_SUBROUTINE int ed448_test(void)
0xa3, 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04,
0x4e, 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f,
0x8f, 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98,
0xf9, 0x5b, 0xa1, 0x3b, 0x04, 0x39, 0x5f, 0xd7,
0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7,
0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1,
0x34, 0x24, 0x85, 0xa7, 0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