FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* returns the size of buffer used, the public ECC key in DER format is stored
   in output buffer
   with_AlgCurve is a flag for when to include a header that has the Algorithm
   and Curve information */
returns the size of buffer used, the public ECC key in DER format is stored
in output buffer
with_AlgCurve is a flag for when to include a header that has the Algorithm
and Curve information
returns the size of buffer used the public ECC key in DER format is stored in output buffer with_AlgCurve is a flag for when to include a header that has the Algorithm and Curve information
int wc_EccPublicKeyToDer(ecc_key* key, byte* output, word32 inLen,
                                                              int with_AlgCurve)
{
    word32 infoSz = 0;
    word32 keySz  = 0;
    int ret;
    if (key == NULL) {
        return BAD_FUNC_ARG;
    }
    if (with_AlgCurve) {
        infoSz += MAX_SEQ_SZ;
        infoSz += 2 * MAX_ALGO_SZ;
        infoSz += MAX_SEQ_SZ;
        infoSz += TRAILING_ZERO;
    }
#if defined(HAVE_SELFTEST) || defined(HAVE_FIPS)
    if (key != NULL && key->dp == NULL) {
        keySz = 1 + 2 * MAX_ECC_BYTES;
        ret = LENGTH_ONLY_E;
    }
    else {
        ret = wc_ecc_export_x963(key, NULL, &keySz);
    }
#else
    ret = wc_ecc_export_x963(key, NULL, &keySz);
#endif
    if (ret != LENGTH_ONLY_E) {
        WOLFSSL_MSG("Error in getting ECC public key size");
        return ret;
    }
    if (output == NULL) {
        return keySz + infoSz;
    }
    if (inLen < keySz + infoSz) {
        return BUFFER_E;
    }
    return SetEccPublicKey(output, key, with_AlgCurve);
}
int wc_EccPublicKeyToDer ( ecc_key * key , byte * output , word32 inLen , int with_AlgCurve ) { word32 infoSz = 0 ; word32 keySz = 0 ; int ret ; if ( key == NULL ) { return BAD_FUNC_ARG ; } if ( with_AlgCurve ) { infoSz += MAX_SEQ_SZ ; infoSz += 2 * MAX_ALGO_SZ ; infoSz += MAX_SEQ_SZ ; infoSz += TRAILING_ZERO ; } #if defined ( HAVE_SELFTEST ) || defined ( HAVE_FIPS ) if ( key != NULL && key -> dp == NULL ) { keySz = 1 + 2 * MAX_ECC_BYTES ; ret = LENGTH_ONLY_E ; } else { ret = wc_ecc_export_x963 ( key , NULL , & keySz ) ; } #else ret = wc_ecc_export_x963 ( key , NULL , & keySz ) ; #endif if ( ret != LENGTH_ONLY_E ) { WOLFSSL_MSG ( " " ) ; return ret ; } if ( output == NULL ) { return keySz + infoSz ; } if ( inLen < keySz + infoSz ) { return BUFFER_E ; } return SetEccPublicKey ( output , key , with_AlgCurve ) ; }
returns the size of buffer used, the public ECC key in DER format is stored
in output buffer
with_AlgCurve is a flag for when to include a header that has the Algorithm
and Curve information
returns the size of buffer used the public ECC key in DER format is stored in output buffer with_AlgCurve is a flag for when to include a header that has the Algorithm and Curve information
/* buffer space for algorithm/curve */ /* buffer space for public key sequence */ /* older version of ecc.c can not handle dp being NULL */ /* if output null then just return size */