@@ -57,7 +57,7 @@ ASN Options:
5757 * WOLFSSL_NO_ASN_STRICT: Disable strict RFC compliance checks to
5858 restore 3.13.0 behavior.
5959 * WOLFSSL_ASN_ALLOW_0_SERIAL: Even if WOLFSSL_NO_ASN_STRICT is not defined,
60- allow a length=1, but zero value serial numnber .
60+ allow a length=1, but zero value serial number .
6161 * WOLFSSL_NO_OCSP_OPTIONAL_CERTS: Skip optional OCSP certs (responder issuer
6262 must still be trusted)
6363 * WOLFSSL_NO_TRUSTED_CERTS_VERIFY: Workaround for situation where entire cert
@@ -12015,34 +12015,38 @@ int wc_EccPublicKeyDerSize(ecc_key* key, int with_AlgCurve)
1201512015
1201612016#ifdef WOLFSSL_ASN_TEMPLATE
1201712017#if defined(WC_ENABLE_ASYM_KEY_EXPORT) || defined(WC_ENABLE_ASYM_KEY_IMPORT)
12018- /* ASN.1 template for Ed25519 and Ed448 public key (SubkectPublicKeyInfo).
12018+ /* ASN.1 template for the SubjectPublicKeyInfo of a general asymmetric key.
12019+ * Used with Ed448/Ed25519, Curve448/Curve25519, SPHINCS+, falcon, dilithium,
12020+ * etc.
12021+ *
12022+ * X.509: RFC 5280, 4.1 - SubjectPublicKeyInfo
1201912023 * RFC 8410, 4 - Subject Public Key Fields
1202012024 */
12021- static const ASNItem edPubKeyASN [] = {
12025+ static const ASNItem publicKeyASN [] = {
1202212026 /* SubjectPublicKeyInfo */
1202312027/* SEQ */ { 0, ASN_SEQUENCE, 1, 1, 0 },
1202412028 /* AlgorithmIdentifier */
1202512029/* ALGOID_SEQ */ { 1, ASN_SEQUENCE, 1, 1, 0 },
12026- /* Ed25519/Ed448 OID */
12030+ /* Ed25519/Ed448 OID, etc. */
1202712031/* ALGOID_OID */ { 2, ASN_OBJECT_ID, 0, 0, 1 },
1202812032 /* Public key stream */
1202912033/* PUBKEY */ { 1, ASN_BIT_STRING, 0, 0, 0 },
1203012034};
1203112035enum {
12032- EDPUBKEYASN_IDX_SEQ = 0,
12033- EDPUBKEYASN_IDX_ALGOID_SEQ ,
12034- EDPUBKEYASN_IDX_ALGOID_OID ,
12035- EDPUBKEYASN_IDX_PUBKEY
12036+ PUBKEYASN_IDX_SEQ = 0,
12037+ PUBKEYASN_IDX_ALGOID_SEQ ,
12038+ PUBKEYASN_IDX_ALGOID_OID ,
12039+ PUBKEYASN_IDX_PUBKEY
1203612040};
1203712041
12038- /* Number of items in ASN.1 template for Ed25519 and Ed448 public key. */
12039- #define edPubKeyASN_Length (sizeof(edPubKeyASN ) / sizeof(ASNItem))
12042+ /* Number of items in ASN.1 template for public key SubjectPublicKeyInfo . */
12043+ #define publicKeyASN_Length (sizeof(publicKeyASN ) / sizeof(ASNItem))
1204012044#endif /* WC_ENABLE_ASYM_KEY_EXPORT || WC_ENABLE_ASYM_KEY_IMPORT */
1204112045#endif /* WOLFSSL_ASN_TEMPLATE */
1204212046
1204312047#ifdef WC_ENABLE_ASYM_KEY_EXPORT
1204412048
12045- /* Build ASN.1 formatted public key based on RFC 8410
12049+ /* Build ASN.1 formatted public key based on RFC 5280 and RFC 8410
1204612050 *
1204712051 * Pass NULL for output to get the size of the encoding.
1204812052 *
@@ -12066,7 +12070,7 @@ int SetAsymKeyDerPublic(const byte* pubKey, word32 pubKeyLen,
1206612070 word32 sz;
1206712071#else
1206812072 int sz = 0;
12069- DECL_ASNSETDATA(dataASN, edPubKeyASN_Length );
12073+ DECL_ASNSETDATA(dataASN, publicKeyASN_Length );
1207012074#endif
1207112075
1207212076 /* validate parameters */
@@ -12118,25 +12122,26 @@ int SetAsymKeyDerPublic(const byte* pubKey, word32 pubKeyLen,
1211812122 }
1211912123#else
1212012124 if (withHeader) {
12121- CALLOC_ASNSETDATA(dataASN, edPubKeyASN_Length , ret, NULL);
12125+ CALLOC_ASNSETDATA(dataASN, publicKeyASN_Length , ret, NULL);
1212212126
1212312127 if (ret == 0) {
1212412128 /* Set the OID. */
12125- SetASN_OID(&dataASN[EDPUBKEYASN_IDX_ALGOID_OID ], (word32)keyType,
12129+ SetASN_OID(&dataASN[PUBKEYASN_IDX_ALGOID_OID ], (word32)keyType,
1212612130 oidKeyType);
1212712131 /* Leave space for public point. */
12128- SetASN_Buffer(&dataASN[EDPUBKEYASN_IDX_PUBKEY ], NULL, pubKeyLen);
12132+ SetASN_Buffer(&dataASN[PUBKEYASN_IDX_PUBKEY ], NULL, pubKeyLen);
1212912133 /* Calculate size of public key encoding. */
12130- ret = SizeASN_Items(edPubKeyASN, dataASN, edPubKeyASN_Length, &sz);
12134+ ret = SizeASN_Items(publicKeyASN, dataASN, publicKeyASN_Length,
12135+ &sz);
1213112136 }
1213212137 if ((ret == 0) && (output != NULL) && (sz > (int)outLen)) {
1213312138 ret = BUFFER_E;
1213412139 }
1213512140 if ((ret == 0) && (output != NULL)) {
1213612141 /* Encode public key. */
12137- SetASN_Items(edPubKeyASN , dataASN, edPubKeyASN_Length , output);
12142+ SetASN_Items(publicKeyASN , dataASN, publicKeyASN_Length , output);
1213812143 /* Set location to encode public point. */
12139- output = (byte*)dataASN[EDPUBKEYASN_IDX_PUBKEY ].data.buffer.data;
12144+ output = (byte*)dataASN[PUBKEYASN_IDX_PUBKEY ].data.buffer.data;
1214012145 }
1214112146
1214212147 FREE_ASNSETDATA(dataASN, NULL);
@@ -35234,7 +35239,7 @@ int DecodeAsymKeyPublic_Assign(const byte* input, word32* inOutIdx, word32 inSz,
3523435239 word32 oid;
3523535240#else
3523635241 word32 len;
35237- DECL_ASNGETDATA(dataASN, edPubKeyASN_Length );
35242+ DECL_ASNGETDATA(dataASN, publicKeyASN_Length );
3523835243#endif
3523935244
3524035245 if (input == NULL || inSz == 0 || inOutIdx == NULL ||
@@ -35269,17 +35274,17 @@ int DecodeAsymKeyPublic_Assign(const byte* input, word32* inOutIdx, word32 inSz,
3526935274#else
3527035275 len = inSz - *inOutIdx;
3527135276
35272- CALLOC_ASNGETDATA(dataASN, edPubKeyASN_Length , ret, NULL);
35277+ CALLOC_ASNGETDATA(dataASN, publicKeyASN_Length , ret, NULL);
3527335278
3527435279 if (ret == 0) {
3527535280 /* Require OID. */
3527635281 word32 oidSz;
3527735282 const byte* oid = OidFromId((word32)keyType, oidKeyType, &oidSz);
3527835283
35279- GetASN_ExpBuffer(&dataASN[EDPUBKEYASN_IDX_ALGOID_OID ], oid, oidSz);
35284+ GetASN_ExpBuffer(&dataASN[PUBKEYASN_IDX_ALGOID_OID ], oid, oidSz);
3528035285 /* Decode Ed25519 private key. */
35281- ret = GetASN_Items(edPubKeyASN , dataASN, edPubKeyASN_Length , 1, input ,
35282- inOutIdx, inSz);
35286+ ret = GetASN_Items(publicKeyASN , dataASN, publicKeyASN_Length , 1,
35287+ input, inOutIdx, inSz);
3528335288 if (ret != 0)
3528435289 ret = ASN_PARSE_E;
3528535290 /* check that input buffer is exhausted */
@@ -35288,12 +35293,12 @@ int DecodeAsymKeyPublic_Assign(const byte* input, word32* inOutIdx, word32 inSz,
3528835293 }
3528935294 /* Check that the all the buffer was used. */
3529035295 if ((ret == 0) &&
35291- (GetASNItem_Length(dataASN[EDPUBKEYASN_IDX_SEQ ], input) != len)) {
35296+ (GetASNItem_Length(dataASN[PUBKEYASN_IDX_SEQ ], input) != len)) {
3529235297 ret = ASN_PARSE_E;
3529335298 }
3529435299 if (ret == 0) {
35295- *pubKeyLen = dataASN[EDPUBKEYASN_IDX_PUBKEY ].data.ref.length;
35296- *pubKey = dataASN[EDPUBKEYASN_IDX_PUBKEY ].data.ref.data;
35300+ *pubKeyLen = dataASN[PUBKEYASN_IDX_PUBKEY ].data.ref.length;
35301+ *pubKey = dataASN[PUBKEYASN_IDX_PUBKEY ].data.ref.data;
3529735302 }
3529835303
3529935304 FREE_ASNGETDATA(dataASN, NULL);
0 commit comments