title: How to convert openssl RSA key to Android bootloader RSA key format?
body: <p>I need to convert a RSA public key generated using openssl into the format specified in Android boot loader code. 
  The format specified in the Android code base is </p>
  
  <pre><code>typedef struct RSAPublicKeyInstance {
    int len;  // Length of n[] in number of uint32_t
    uint32_t n0inv;  // -1 / n[0] mod 2^32
    uint32_t n[RSANUMWORDS];  // modulus as little endian array
    uint32_t rr[RSANUMWORDS];  // R^2 as little endian array
  } RSAPublicKeyInstance;
  </code></pre>
  
  <p>Please find the original code <a href="https://code.google.com/p/android-source-browsing/source/browse/libc/rsa.h?repo=platform--bootable--bootloader--legacy&amp;r=b1fde5cd7d5158b8e6876139ca76a341d0e49708" rel="nofollow">here</a>.
  The related C source file rsa.c can be found <a href="https://code.google.com/p/android-source-browsing/source/browse/libc/rsa.c?repo=platform--bootable--bootloader--legacy&amp;r=b1fde5cd7d5158b8e6876139ca76a341d0e49708" rel="nofollow">here</a>.</p>
  
  <p>How do I convert the modulus, recovered from a openssl generated public key thus</p>
  
  <pre><code>openssl rsa -pubin -inform PEM -text -noout &lt; public.key
  
  Modulus (2048 bit):
  00:98:10:23:16:ff:b6:f4:26:a2:42:a6:19:23:0e:
  0f:27:4a:b9:43:3d:a0:4b:b9:1b:1a:57:92:dd:a8:
  bc:5d:b8:6e:e6:7f:0f:2e:89:a5:77:16:d1:cf:44:
  69:74:2b:b1:a9:dd:72:bd:a8:9c:aa:90:ca:7b:f4:
  d3:d3:db:11:98:bd:61:f1:2c:77:41:ad:c4:42:6a:
  88:d1:37:04:12:a9:36:ec:09:34:0d:31:71:b9:5a:
  ea:ed:ce:61:1c:1e:5f:6c:9e:28:ee:21:2a:e4:c6:
  1f:75:29:78:a5:96:b1:53:17:4d:bf:88:d1:12:5c:
  a6:75:aa:7c:fe:23:a8:dd:25:35:46:c6:8a:eb:2e:
  e4:a3:1d:7f:b6:6d:9c:7d:66:59:84:c9:51:15:82:
  67:a6:85:e9:c8:d6:2b:a7:e6:28:08:d2:b1:99:92:
  67:32:c4:ba:f7:c9:1a:16:30:e5:cb:39:cb:96:28:
  70:32:ba:18:d2:64:2f:74:3e:dd:09:e0:68:56:57:
  cf:50:63:c0:95:a9:b0:5b:2a:ad:21:4f:bd:e7:15:
  64:4a:9d:e4:c5:c3:5c:35:bf:e6:78:f4:8a:40:83:
  da:7d:0d:6c:02:60:4a:3f:0c:9c:03:fd:48:e6:72:
  f3:0d:5b:90:6b:de:59:58:c9:f4:26:4a:61:b4:52:
  21:1d
  Exponent: 65537 (0x10001)
  </code></pre>
  
  <p>into the above structure's format? How do I store information about the public exponent in the structure? Please note that I am mostly concerned with how to store the modulus and public exponent. The rr[RSANUMWORDS] is inconsequential for me. </p>
  
  <p>Thanks a lot! Any help is appreciated. </p>