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