@@ -6882,8 +6882,9 @@ static const ASNItem pkcs8KeyASN[] = {
68826882/* PKEY_ALGO_PARAM_SEQ */ { 2, ASN_SEQUENCE, 1, 0, 1 },
68836883#endif
68846884/* PKEY_DATA */ { 1, ASN_OCTET_STRING, 0, 0, 0 },
6885- /* attributes [0] Attributes OPTIONAL */
6886- /* [[2: publicKey [1] PublicKey OPTIONAL ]] */
6885+ /* OPTIONAL Attributes IMPLICIT [0] */
6886+ { 1, ASN_CONTEXT_SPECIFIC | 0, 1, 0, 1 },
6887+ /* [[2: publicKey [1] PublicKey OPTIONAL ]] */
68876888};
68886889enum {
68896890 PKCS8KEYASN_IDX_SEQ = 0,
@@ -6896,6 +6897,7 @@ enum {
68966897 PKCS8KEYASN_IDX_PKEY_ALGO_PARAM_SEQ,
68976898#endif
68986899 PKCS8KEYASN_IDX_PKEY_DATA,
6900+ PKCS8KEYASN_IDX_PKEY_ATTRIBUTES,
68996901 WOLF_ENUM_DUMMY_LAST_ELEMENT(PKCS8KEYASN_IDX)
69006902};
69016903
@@ -7306,7 +7308,9 @@ int wc_CreatePKCS8Key(byte* out, word32* outSz, byte* key, word32 keySz,
73067308 *outSz = tmpSz + sz;
73077309 return (int)(tmpSz + sz);
73087310#else
7309- DECL_ASNSETDATA(dataASN, pkcs8KeyASN_Length);
7311+ /* pkcs8KeyASN_Length-1, the -1 is because we are not adding the optional
7312+ * set of attributes */
7313+ DECL_ASNSETDATA(dataASN, pkcs8KeyASN_Length-1);
73107314 int sz = 0;
73117315 int ret = 0;
73127316 word32 keyIdx = 0;
@@ -7327,7 +7331,7 @@ int wc_CreatePKCS8Key(byte* out, word32* outSz, byte* key, word32 keySz,
73277331 ret = ASN_PARSE_E;
73287332 }
73297333
7330- CALLOC_ASNSETDATA(dataASN, pkcs8KeyASN_Length, ret, NULL);
7334+ CALLOC_ASNSETDATA(dataASN, pkcs8KeyASN_Length-1 , ret, NULL);
73317335
73327336 if (ret == 0) {
73337337 /* Only support default PKCS #8 format - v0. */
@@ -7353,7 +7357,7 @@ int wc_CreatePKCS8Key(byte* out, word32* outSz, byte* key, word32 keySz,
73537357 SetASN_Buffer(&dataASN[PKCS8KEYASN_IDX_PKEY_DATA], key, keySz);
73547358
73557359 /* Get the size of the DER encoding. */
7356- ret = SizeASN_Items(pkcs8KeyASN, dataASN, pkcs8KeyASN_Length, &sz);
7360+ ret = SizeASN_Items(pkcs8KeyASN, dataASN, pkcs8KeyASN_Length-1 , &sz);
73577361 }
73587362 if (ret == 0) {
73597363 /* Always return the calculated size. */
@@ -7366,7 +7370,7 @@ int wc_CreatePKCS8Key(byte* out, word32* outSz, byte* key, word32 keySz,
73667370 }
73677371 if (ret == 0) {
73687372 /* Encode PKCS #8 key into buffer. */
7369- SetASN_Items(pkcs8KeyASN, dataASN, pkcs8KeyASN_Length, out);
7373+ SetASN_Items(pkcs8KeyASN, dataASN, pkcs8KeyASN_Length-1 , out);
73707374 ret = sz;
73717375 }
73727376
0 commit comments