FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* Set the DER/BER encoding of the ASN.1 INTEGER element with an mp_int from
 * an RSA key.
 * The number is assumed to be positive.
 *
 * n       Multi-precision integer to encode.
 * output  Buffer to write into.
 * returns BUFFER_E when the data is too long for the buffer.
 *         MP_TO_E when encoding the integer fails.
 *         Otherwise, the number of bytes added to the buffer.
 */
Set the DER/BER encoding of the ASN.1 INTEGER element with an mp_int from
an RSA key.
The number is assumed to be positive.

n       Multi-precision integer to encode.
output  Buffer to write into.
returns BUFFER_E when the data is too long for the buffer.
MP_TO_E when encoding the integer fails.
Otherwise, the number of bytes added to the buffer.
Set the DER / BER encoding of the ASN . 1 INTEGER element with an mp_int from an RSA key . The number is assumed to be positive . n Multi - precision integer to encode . output Buffer to write into . returns BUFFER_E when the data is too long for the buffer . MP_TO_E when encoding the integer fails . Otherwise the number of bytes added to the buffer .
static int SetASNIntRSA(void* n, byte* output)
{
    int idx = 0;
    int leadingBit;
    int length;
    int err;
    leadingBit = wc_Rsa_leading_bit(n);
    length = wc_Rsa_unsigned_bin_size(n);
    idx = SetASNInt(length, leadingBit ? 0x80 : 0x00, output);
    if ((idx + length) > MAX_RSA_INT_SZ)
        return BUFFER_E;
    if (output) {
        err = wc_Rsa_to_unsigned_bin(n, output + idx, length);
        if (err != MP_OKAY)
            return MP_TO_E;
    }
    idx += length;
    return idx;
}
static int SetASNIntRSA ( void * n , byte * output ) { int idx = 0 ; int leadingBit ; int length ; int err ; leadingBit = wc_Rsa_leading_bit ( n ) ; length = wc_Rsa_unsigned_bin_size ( n ) ; idx = SetASNInt ( length , leadingBit ? 0x80 : 0x00 , output ) ; if ( ( idx + length ) > MAX_RSA_INT_SZ ) return BUFFER_E ; if ( output ) { err = wc_Rsa_to_unsigned_bin ( n , output + idx , length ) ; if ( err != MP_OKAY ) return MP_TO_E ; } idx += length ; return idx ; }
Set the DER/BER encoding of the ASN.1 INTEGER element with an mp_int from
 an RSA key.
Set the DER / BER encoding of the ASN . 1 INTEGER element with an mp_int from an RSA key .