@@ -30465,195 +30465,6 @@ int ParseExtKeyUsageStr(const char* value, byte* extKeyUsage, void* heap)
3046530465
3046630466#endif /* WOLFSSL_ASN_PARSE_KEYUSAGE */
3046730467
30468- #if defined(WOLFSSL_CERT_GEN) || defined(HAVE_OCSP_RESPONDER)
30469- /* Make signature from buffer (sz), write to sig (sigSz) */
30470- static int MakeSignature(CertSignCtx* certSignCtx, const byte* buf, word32 sz,
30471- byte* sig, word32 sigSz, RsaKey* rsaKey, ecc_key* eccKey,
30472- ed25519_key* ed25519Key, ed448_key* ed448Key, falcon_key* falconKey,
30473- dilithium_key* dilithiumKey, sphincs_key* sphincsKey, WC_RNG* rng,
30474- word32 sigAlgoType, void* heap)
30475- {
30476- int digestSz = 0, typeH = 0, ret = 0;
30477-
30478- (void)digestSz;
30479- (void)typeH;
30480- (void)buf;
30481- (void)sz;
30482- (void)sig;
30483- (void)sigSz;
30484- (void)rsaKey;
30485- (void)eccKey;
30486- (void)ed25519Key;
30487- (void)ed448Key;
30488- (void)falconKey;
30489- (void)dilithiumKey;
30490- (void)sphincsKey;
30491- (void)rng;
30492- (void)heap;
30493-
30494- switch (certSignCtx->state) {
30495- case CERTSIGN_STATE_BEGIN:
30496- case CERTSIGN_STATE_DIGEST:
30497-
30498- certSignCtx->state = CERTSIGN_STATE_DIGEST;
30499- #ifndef WOLFSSL_NO_MALLOC
30500- certSignCtx->digest = (byte*)XMALLOC(WC_MAX_DIGEST_SIZE, heap,
30501- DYNAMIC_TYPE_TMP_BUFFER);
30502- if (certSignCtx->digest == NULL) {
30503- ret = MEMORY_E; goto exit_ms;
30504- }
30505- #endif
30506-
30507- ret = HashForSignature(buf, sz, sigAlgoType, certSignCtx->digest,
30508- &typeH, &digestSz, 0, NULL,
30509- INVALID_DEVID);
30510- /* set next state, since WC_PENDING_E rentry for these are not "call again" */
30511- certSignCtx->state = CERTSIGN_STATE_ENCODE;
30512- if (ret != 0) {
30513- goto exit_ms;
30514- }
30515- FALL_THROUGH;
30516-
30517- case CERTSIGN_STATE_ENCODE:
30518- #ifndef NO_RSA
30519- if (rsaKey) {
30520- #ifndef WOLFSSL_NO_MALLOC
30521- certSignCtx->encSig = (byte*)XMALLOC(MAX_DER_DIGEST_SZ, heap,
30522- DYNAMIC_TYPE_TMP_BUFFER);
30523- if (certSignCtx->encSig == NULL) {
30524- ret = MEMORY_E; goto exit_ms;
30525- }
30526- #endif
30527-
30528- /* signature */
30529- certSignCtx->encSigSz = (int)wc_EncodeSignature(certSignCtx->encSig,
30530- certSignCtx->digest, (word32)digestSz, typeH);
30531- }
30532- #endif /* !NO_RSA */
30533- FALL_THROUGH;
30534-
30535- case CERTSIGN_STATE_DO:
30536- certSignCtx->state = CERTSIGN_STATE_DO;
30537- ret = -1; /* default to error, reassigned to ALGO_ID_E below. */
30538-
30539- #if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
30540- if (rsaKey) {
30541- /* signature */
30542- ret = wc_RsaSSL_Sign(certSignCtx->encSig,
30543- (word32)certSignCtx->encSigSz,
30544- sig, sigSz, rsaKey, rng);
30545- }
30546- #endif /* !NO_RSA */
30547-
30548- #if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN)
30549- if (!rsaKey && eccKey) {
30550- word32 outSz = sigSz;
30551-
30552- ret = wc_ecc_sign_hash(certSignCtx->digest, (word32)digestSz,
30553- sig, &outSz, rng, eccKey);
30554- if (ret == 0)
30555- ret = (int)outSz;
30556- }
30557- #endif /* HAVE_ECC && HAVE_ECC_SIGN */
30558-
30559- #if defined(HAVE_ED25519) && defined(HAVE_ED25519_SIGN)
30560- if (!rsaKey && !eccKey && ed25519Key) {
30561- word32 outSz = sigSz;
30562-
30563- ret = wc_ed25519_sign_msg(buf, sz, sig, &outSz, ed25519Key);
30564- if (ret == 0)
30565- ret = (int)outSz;
30566- }
30567- #endif /* HAVE_ED25519 && HAVE_ED25519_SIGN */
30568-
30569- #if defined(HAVE_ED448) && defined(HAVE_ED448_SIGN)
30570- if (!rsaKey && !eccKey && !ed25519Key && ed448Key) {
30571- word32 outSz = sigSz;
30572-
30573- ret = wc_ed448_sign_msg(buf, sz, sig, &outSz, ed448Key, NULL, 0);
30574- if (ret == 0)
30575- ret = (int)outSz;
30576- }
30577- #endif /* HAVE_ED448 && HAVE_ED448_SIGN */
30578-
30579- #if defined(HAVE_FALCON)
30580- if (!rsaKey && !eccKey && !ed25519Key && !ed448Key && falconKey) {
30581- word32 outSz = sigSz;
30582- ret = wc_falcon_sign_msg(buf, sz, sig, &outSz, falconKey, rng);
30583- if (ret == 0)
30584- ret = outSz;
30585- }
30586- #endif /* HAVE_FALCON */
30587- #if defined(HAVE_DILITHIUM) && !defined(WOLFSSL_DILITHIUM_NO_SIGN)
30588- if (!rsaKey && !eccKey && !ed25519Key && !ed448Key && !falconKey &&
30589- dilithiumKey) {
30590- word32 outSz = sigSz;
30591- #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
30592- if ((dilithiumKey->params->level == WC_ML_DSA_44_DRAFT) ||
30593- (dilithiumKey->params->level == WC_ML_DSA_65_DRAFT) ||
30594- (dilithiumKey->params->level == WC_ML_DSA_87_DRAFT)) {
30595- ret = wc_dilithium_sign_msg(buf, sz, sig, &outSz, dilithiumKey,
30596- rng);
30597- if (ret == 0)
30598- ret = outSz;
30599- }
30600- else
30601- #endif
30602- {
30603- ret = wc_dilithium_sign_ctx_msg(NULL, 0, buf, sz, sig,
30604- &outSz, dilithiumKey, rng);
30605- if (ret == 0)
30606- ret = outSz;
30607- }
30608- }
30609- #endif /* HAVE_DILITHIUM && !WOLFSSL_DILITHIUM_NO_SIGN */
30610- #if defined(HAVE_SPHINCS)
30611- if (!rsaKey && !eccKey && !ed25519Key && !ed448Key && !falconKey &&
30612- !dilithiumKey && sphincsKey) {
30613- word32 outSz = sigSz;
30614- ret = wc_sphincs_sign_msg(buf, sz, sig, &outSz, sphincsKey, rng);
30615- if (ret == 0)
30616- ret = outSz;
30617- }
30618- #endif /* HAVE_SPHINCS */
30619-
30620- if (ret == -1)
30621- ret = ALGO_ID_E;
30622-
30623- break;
30624- }
30625-
30626- exit_ms:
30627-
30628- #ifdef WOLFSSL_ASYNC_CRYPT
30629- if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
30630- return ret;
30631- }
30632- #endif
30633-
30634- #ifndef WOLFSSL_NO_MALLOC
30635- #ifndef NO_RSA
30636- if (rsaKey) {
30637- XFREE(certSignCtx->encSig, heap, DYNAMIC_TYPE_TMP_BUFFER);
30638- certSignCtx->encSig = NULL;
30639- }
30640- #endif /* !NO_RSA */
30641-
30642- XFREE(certSignCtx->digest, heap, DYNAMIC_TYPE_TMP_BUFFER);
30643- certSignCtx->digest = NULL;
30644- #endif /* !WOLFSSL_NO_MALLOC */
30645-
30646- /* reset state */
30647- certSignCtx->state = CERTSIGN_STATE_BEGIN;
30648-
30649- if (ret < 0) {
30650- WOLFSSL_ERROR_VERBOSE(ret);
30651- }
30652-
30653- return ret;
30654- }
30655- #endif /* WOLFSSL_CERT_GEN || HAVE_OCSP_RESPONDER */
30656-
3065730468#ifdef WOLFSSL_CERT_GEN
3065830469/* Encodes one attribute of the name (issuer/subject)
3065930470 * call we_EncodeName_ex with 0x16, IA5String for email type
0 commit comments