FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* import RSA public key elements (n, e) into RsaKey structure (key) */
import RSA public key elements (n, e) into RsaKey structure (key)
import RSA public key elements ( n e ) into RsaKey structure ( key )
int wc_RsaPublicKeyDecodeRaw(const byte* n, word32 nSz, const byte* e,
                             word32 eSz, RsaKey* key)
{
    if (n == NULL || e == NULL || key == NULL)
        return BAD_FUNC_ARG;
    key->type = RSA_PUBLIC;
    if (mp_init(&key->n) != MP_OKAY)
        return MP_INIT_E;
    if (mp_read_unsigned_bin(&key->n, n, nSz) != 0) {
        mp_clear(&key->n);
        return ASN_GETINT_E;
    }
#ifdef HAVE_WOLF_BIGINT
    if ((int)nSz > 0 && wc_bigint_from_unsigned_bin(&key->n.raw, n, nSz) != 0) {
        mp_clear(&key->n);
        return ASN_GETINT_E;
    }
#endif 
    if (mp_init(&key->e) != MP_OKAY) {
        mp_clear(&key->n);
        return MP_INIT_E;
    }
    if (mp_read_unsigned_bin(&key->e, e, eSz) != 0) {
        mp_clear(&key->n);
        mp_clear(&key->e);
        return ASN_GETINT_E;
    }
#ifdef HAVE_WOLF_BIGINT
    if ((int)eSz > 0 && wc_bigint_from_unsigned_bin(&key->e.raw, e, eSz) != 0) {
        mp_clear(&key->n);
        mp_clear(&key->e);
        return ASN_GETINT_E;
    }
#endif 
#ifdef WOLFSSL_XILINX_CRYPT
    if (wc_InitRsaHw(key) != 0) {
        return BAD_STATE_E;
    }
#endif
    return 0;
}
int wc_RsaPublicKeyDecodeRaw ( const byte * n , word32 nSz , const byte * e , word32 eSz , RsaKey * key ) { if ( n == NULL || e == NULL || key == NULL ) return BAD_FUNC_ARG ; key -> type = RSA_PUBLIC ; if ( mp_init ( & key -> n ) != MP_OKAY ) return MP_INIT_E ; if ( mp_read_unsigned_bin ( & key -> n , n , nSz ) != 0 ) { mp_clear ( & key -> n ) ; return ASN_GETINT_E ; } #ifdef HAVE_WOLF_BIGINT if ( ( int ) nSz > 0 && wc_bigint_from_unsigned_bin ( & key -> n . raw , n , nSz ) != 0 ) { mp_clear ( & key -> n ) ; return ASN_GETINT_E ; } #endif if ( mp_init ( & key -> e ) != MP_OKAY ) { mp_clear ( & key -> n ) ; return MP_INIT_E ; } if ( mp_read_unsigned_bin ( & key -> e , e , eSz ) != 0 ) { mp_clear ( & key -> n ) ; mp_clear ( & key -> e ) ; return ASN_GETINT_E ; } #ifdef HAVE_WOLF_BIGINT if ( ( int ) eSz > 0 && wc_bigint_from_unsigned_bin ( & key -> e . raw , e , eSz ) != 0 ) { mp_clear ( & key -> n ) ; mp_clear ( & key -> e ) ; return ASN_GETINT_E ; } #endif #ifdef WOLFSSL_XILINX_CRYPT if ( wc_InitRsaHw ( key ) != 0 ) { return BAD_STATE_E ; } #endif return 0 ; }
import RSA public key elements (n, e) into RsaKey structure (key)
import RSA public key elements ( n e ) into RsaKey structure ( key )
/* HAVE_WOLF_BIGINT */ /* HAVE_WOLF_BIGINT */