mbedtls_rsa_export_raw() function
This function exports core parameters of an RSA key in raw big-endian binary format. If this function runs successfully, the non-NULL buffers pointed to by \p N, \p P, \p Q, \p D, and \p E are fully written, with additional unused space filled leading by zero Bytes. Possible reasons for returning #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED: An alternative RSA implementation is in use, which stores the key externally, and either cannot or should not export it into RAM. A SW or HW implementation might not support a certain deduction. For example, \p P, \p Q from \p N, \p D, and \p E if the former are not part of the implementation. If the function fails due to an unsupported operation, the RSA context stays intact and remains usable.
int mbedtls_rsa_export_raw( const mbedtls_rsa_context *ctx,
unsigned char *N,
size_t N_len,
unsigned char *P,
size_t P_len,
unsigned char *Q,
size_t Q_len,
unsigned char *D,
size_t D_len,
unsigned char *E,
size_t E_len );
Arguments
ctx
The initialized RSA context.
N
The Byte array to store the RSA modulus, or \c NULL if this field need not be exported.
N_len
The size of the buffer for the modulus.
P
The Byte array to hold the first prime factor of \p N, or \c NULL if this field need not be exported.
P_len
The size of the buffer for the first prime factor.
Q
The Byte array to hold the second prime factor of \p N, or \c NULL if this field need not be exported.
Q_len
The size of the buffer for the second prime factor.
D
The Byte array to hold the private exponent, or \c NULL if this field need not be exported.
D_len
The size of the buffer for the private exponent.
E
The Byte array to hold the public exponent, or \c NULL if this field need not be exported.
E_len
The size of the buffer for the public exponent.
Return value
\c 0 on success. #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED if exporting the requested parameters cannot be done due to missing functionality or because of security policies. A non-zero return code on any other failure.
Notes
The length parameters are ignored if the corresponding buffer pointers are NULL.