FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* Make an x509 Certificate v3 any key type from cert input, write to buffer */
Make an x509 Certificate v3 any key type from cert input, write to buffer
Make an x509 Certificate v3 any key type from cert input write to buffer
static int MakeAnyCert(Cert* cert, byte* derBuffer, word32 derSz,
                       RsaKey* rsaKey, ecc_key* eccKey, WC_RNG* rng,
                       const byte* ntruKey, word16 ntruSz,
                       ed25519_key* ed25519Key, ed448_key* ed448Key)
{
    int ret;
#ifdef WOLFSSL_SMALL_STACK
    DerCert* der;
#else
    DerCert der[1];
#endif
    if (derBuffer == NULL) {
        return BAD_FUNC_ARG;
    }
    cert->keyType = eccKey ? ECC_KEY : (rsaKey ? RSA_KEY :
            (ed25519Key ? ED25519_KEY : (ed448Key ? ED448_KEY : NTRU_KEY)));
#ifdef WOLFSSL_SMALL_STACK
    der = (DerCert*)XMALLOC(sizeof(DerCert), cert->heap, DYNAMIC_TYPE_TMP_BUFFER);
    if (der == NULL)
        return MEMORY_E;
#endif
    ret = EncodeCert(cert, der, rsaKey, eccKey, rng, ntruKey, ntruSz,
                     ed25519Key, ed448Key);
    if (ret == 0) {
        if (der->total + MAX_SEQ_SZ * 2 > (int)derSz)
            ret = BUFFER_E;
        else
            ret = cert->bodySz = WriteCertBody(der, derBuffer);
    }
#ifdef WOLFSSL_SMALL_STACK
    XFREE(der, cert->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
    return ret;
}
static int MakeAnyCert ( Cert * cert , byte * derBuffer , word32 derSz , RsaKey * rsaKey , ecc_key * eccKey , WC_RNG * rng , const byte * ntruKey , word16 ntruSz , ed25519_key * ed25519Key , ed448_key * ed448Key ) { int ret ; #ifdef WOLFSSL_SMALL_STACK DerCert * der ; #else DerCert der [ 1 ] ; #endif if ( derBuffer == NULL ) { return BAD_FUNC_ARG ; } cert -> keyType = eccKey ? ECC_KEY : ( rsaKey ? RSA_KEY : ( ed25519Key ? ED25519_KEY : ( ed448Key ? ED448_KEY : NTRU_KEY ) ) ) ; #ifdef WOLFSSL_SMALL_STACK der = ( DerCert * ) XMALLOC ( sizeof ( DerCert ) , cert -> heap , DYNAMIC_TYPE_TMP_BUFFER ) ; if ( der == NULL ) return MEMORY_E ; #endif ret = EncodeCert ( cert , der , rsaKey , eccKey , rng , ntruKey , ntruSz , ed25519Key , ed448Key ) ; if ( ret == 0 ) { if ( der -> total + MAX_SEQ_SZ * 2 > ( int ) derSz ) ret = BUFFER_E ; else ret = cert -> bodySz = WriteCertBody ( der , derBuffer ) ; } #ifdef WOLFSSL_SMALL_STACK XFREE ( der , cert -> heap , DYNAMIC_TYPE_TMP_BUFFER ) ; #endif return ret ; }
Make an x509 Certificate v3 any key type from cert input, write to buffer
Make an x509 Certificate v3 any key type from cert input write to buffer