FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* build DER formatted ED448 key,
 * return length on success, negative on error */
build DER formatted ED448 key,
return length on success, negative on error
build DER formatted ED448 key return length on success negative on error
static int wc_BuildEd448KeyDer(ed448_key* key, byte* output, word32 inLen,
                               int pubOut)
{
    byte   algoArray[MAX_ALGO_SZ];
    byte   ver[MAX_VERSION_SZ];
    byte   seq[MAX_SEQ_SZ];
    int    ret;
    word32 idx = 0, seqSz, verSz, algoSz, privSz, pubSz = 0;
    if (key == NULL || output == NULL || inLen == 0)
        return BAD_FUNC_ARG;
    if (pubOut) {
        pubSz = 2 + 2 + ED448_PUB_KEY_SIZE;
    }
    privSz = 2 + 2 + ED448_KEY_SIZE;
    algoSz = SetAlgoID(ED448k, algoArray, oidKeyType, 0);
    verSz  = SetMyVersion(0, ver, FALSE);
    seqSz  = SetSequence(verSz + algoSz + privSz + pubSz, seq);
    if (seqSz + verSz + algoSz + privSz + pubSz > inLen)
        return BAD_FUNC_ARG;
    XMEMCPY(output + idx, seq, seqSz);
    idx = seqSz;
    XMEMCPY(output + idx, ver, verSz);
    idx += verSz;
    XMEMCPY(output + idx, algoArray, algoSz);
    idx += algoSz;
    idx += SetOctetString(2 + ED448_KEY_SIZE, output + idx);
    idx += SetOctetString(ED448_KEY_SIZE, output + idx);
    ret = wc_ed448_export_private_only(key, output + idx, &privSz);
    if (ret != 0)
        return ret;
    idx += privSz;
    if (pubOut) {
        idx += SetExplicit(1, 2 + ED448_PUB_KEY_SIZE, output + idx);
        idx += SetOctetString(ED448_KEY_SIZE, output + idx);
        ret = wc_ed448_export_public(key, output + idx, &pubSz);
        if (ret != 0)
            return ret;
        idx += pubSz;
    }
    return idx;
}
static int wc_BuildEd448KeyDer ( ed448_key * key , byte * output , word32 inLen , int pubOut ) { byte algoArray [ MAX_ALGO_SZ ] ; byte ver [ MAX_VERSION_SZ ] ; byte seq [ MAX_SEQ_SZ ] ; int ret ; word32 idx = 0 , seqSz , verSz , algoSz , privSz , pubSz = 0 ; if ( key == NULL || output == NULL || inLen == 0 ) return BAD_FUNC_ARG ; if ( pubOut ) { pubSz = 2 + 2 + ED448_PUB_KEY_SIZE ; } privSz = 2 + 2 + ED448_KEY_SIZE ; algoSz = SetAlgoID ( ED448k , algoArray , oidKeyType , 0 ) ; verSz = SetMyVersion ( 0 , ver , FALSE ) ; seqSz = SetSequence ( verSz + algoSz + privSz + pubSz , seq ) ; if ( seqSz + verSz + algoSz + privSz + pubSz > inLen ) return BAD_FUNC_ARG ; XMEMCPY ( output + idx , seq , seqSz ) ; idx = seqSz ; XMEMCPY ( output + idx , ver , verSz ) ; idx += verSz ; XMEMCPY ( output + idx , algoArray , algoSz ) ; idx += algoSz ; idx += SetOctetString ( 2 + ED448_KEY_SIZE , output + idx ) ; idx += SetOctetString ( ED448_KEY_SIZE , output + idx ) ; ret = wc_ed448_export_private_only ( key , output + idx , & privSz ) ; if ( ret != 0 ) return ret ; idx += privSz ; if ( pubOut ) { idx += SetExplicit ( 1 , 2 + ED448_PUB_KEY_SIZE , output + idx ) ; idx += SetOctetString ( ED448_KEY_SIZE , output + idx ) ; ret = wc_ed448_export_public ( key , output + idx , & pubSz ) ; if ( ret != 0 ) return ret ; idx += pubSz ; } return idx ; }
build DER formatted ED448 key,
 return length on success, negative on error
build DER formatted ED448 key return length on success negative on error
/* write out */ /* seq */ /* ver */ /* algo */ /* privKey */ /* pubKey */