<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Might I suggest reading the documentation?<div class=""><br class=""></div><div class="">RSA_get0_n() is the function you are wanting.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Pauli<br class=""><div class="">
<div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">-- <br class="">Dr Paul Dale | Distinguished Architect | Cryptographic Foundations <br class="">Phone +61 7 3031 7217<br class="">Oracle Australia</div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><br class=""></div><br class="Apple-interchange-newline"></div><br class="Apple-interchange-newline">
</div>

<div><br class=""><blockquote type="cite" class=""><div class="">On 6 May 2020, at 2:20 pm, Thomas Dwyer III <<a href="mailto:tomiii@tomiii.com" class="">tomiii@tomiii.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">I'm porting some old legacy code from OpenSSL 1.0.2 to OpenSSL 3.0.0. A portion of this code reads X509 certificates, extracts the public key, and passes it to firmware that I cannot modify. Unfortunately, this legacy firmware API was very poorly designed such that the public key is passed in a way similar to:</div><div class=""><br class=""></div><div class=""><span style="font-family:monospace" class="">    RSA *rsa = get_pubkey_from_cert(...)</span></div><div class=""><span style="font-family:monospace" class="">    BIGNUM *bn = rsa->n;</span></div><div class=""><span style="font-family:monospace" class="">    int len = BN_num_bytes(bn);</span></div><div class=""><span style="font-family:monospace" class="">    unsigned char *buf = malloc(len);<br class=""></span></div><div class=""><span style="font-family:monospace" class="">    BN_bn2bin(bn, buf);</span></div><div class=""><span style="font-family:monospace" class="">    pubkey_to_firmware(buf, len);</span></div><div class=""><br class=""></div><div class="">Yuck. Ignoring the fact that this firmware appears to assume a constant exponent 'e', I cannot find a way to extract the modulus 'n' from the RSA key. I understand this is intentional. The only solution I could find is to print the key to a buffer via EVP_PKEY_print_public(), parse the result to extract the modulus into a giant hex string, and then BN_hex2bn() that back into a BIGNUM. Is there a better way?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Tom.III</div><div class=""><br class=""></div></div>
</div></blockquote></div><br class=""></div></body></html>