FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* Write a public ECC key to output */
Write a public ECC key to output
Write a public ECC key to output
static int SetEd448PublicKey(byte* output, ed448_key* key, int with_header)
{
    byte bitString[1 + MAX_LENGTH_SZ + 1];
    int  algoSz;
    int  bitStringSz;
    int  idx;
    word32 pubSz = ED448_PUB_KEY_SIZE;
#ifdef WOLFSSL_SMALL_STACK
    byte* algo = NULL;
    byte* pub = NULL;
#else
    byte algo[MAX_ALGO_SZ];
    byte pub[ED448_PUB_KEY_SIZE];
#endif
#ifdef WOLFSSL_SMALL_STACK
    pub = (byte*)XMALLOC(ECC_BUFSIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
    if (pub == NULL)
        return MEMORY_E;
#endif
    idx = wc_ed448_export_public(key, pub, &pubSz);
    if (idx != 0) {
#ifdef WOLFSSL_SMALL_STACK
        XFREE(pub, key->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
        return idx;
    }
    if (with_header) {
#ifdef WOLFSSL_SMALL_STACK
        algo = (byte*)XMALLOC(MAX_ALGO_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER);
        if (algo == NULL) {
            XFREE(pub, key->heap, DYNAMIC_TYPE_TMP_BUFFER);
            return MEMORY_E;
        }
#endif
        algoSz  = SetAlgoID(ED448k, algo, oidKeyType, 0);
        bitStringSz = SetBitString(pubSz, 0, bitString);
        idx = SetSequence(pubSz + bitStringSz + algoSz, output);
        XMEMCPY(output + idx, algo, algoSz);
        idx += algoSz;
        XMEMCPY(output + idx, bitString, bitStringSz);
        idx += bitStringSz;
    }
    else
        idx = 0;
    XMEMCPY(output + idx, pub, pubSz);
    idx += pubSz;
#ifdef WOLFSSL_SMALL_STACK
    if (with_header) {
        XFREE(algo, NULL, DYNAMIC_TYPE_TMP_BUFFER);
    }
    XFREE(pub, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
    return idx;
}
static int SetEd448PublicKey ( byte * output , ed448_key * key , int with_header ) { byte bitString [ 1 + MAX_LENGTH_SZ + 1 ] ; int algoSz ; int bitStringSz ; int idx ; word32 pubSz = ED448_PUB_KEY_SIZE ; #ifdef WOLFSSL_SMALL_STACK byte * algo = NULL ; byte * pub = NULL ; #else byte algo [ MAX_ALGO_SZ ] ; byte pub [ ED448_PUB_KEY_SIZE ] ; #endif #ifdef WOLFSSL_SMALL_STACK pub = ( byte * ) XMALLOC ( ECC_BUFSIZE , NULL , DYNAMIC_TYPE_TMP_BUFFER ) ; if ( pub == NULL ) return MEMORY_E ; #endif idx = wc_ed448_export_public ( key , pub , & pubSz ) ; if ( idx != 0 ) { #ifdef WOLFSSL_SMALL_STACK XFREE ( pub , key -> heap , DYNAMIC_TYPE_TMP_BUFFER ) ; #endif return idx ; } if ( with_header ) { #ifdef WOLFSSL_SMALL_STACK algo = ( byte * ) XMALLOC ( MAX_ALGO_SZ , NULL , DYNAMIC_TYPE_TMP_BUFFER ) ; if ( algo == NULL ) { XFREE ( pub , key -> heap , DYNAMIC_TYPE_TMP_BUFFER ) ; return MEMORY_E ; } #endif algoSz = SetAlgoID ( ED448k , algo , oidKeyType , 0 ) ; bitStringSz = SetBitString ( pubSz , 0 , bitString ) ; idx = SetSequence ( pubSz + bitStringSz + algoSz , output ) ; XMEMCPY ( output + idx , algo , algoSz ) ; idx += algoSz ; XMEMCPY ( output + idx , bitString , bitStringSz ) ; idx += bitStringSz ; } else idx = 0 ; XMEMCPY ( output + idx , pub , pubSz ) ; idx += pubSz ; #ifdef WOLFSSL_SMALL_STACK if ( with_header ) { XFREE ( algo , NULL , DYNAMIC_TYPE_TMP_BUFFER ) ; } XFREE ( pub , NULL , DYNAMIC_TYPE_TMP_BUFFER ) ; #endif return idx ; }
Write a public ECC key to output
Write a public ECC key to output
/* headers */ /* algo */ /* bit string */ /* pub */