title: OpenSSL PEM_read_bio_X509() function across different architectures
body: <p>I have a certificate and I am using <strong>PEM_read_bio_X509()</strong> function to parse this certificate and using some other functions (ie: <strong>X509_get_pubkey</strong>) to extract required information from the certificate. </p>
  
  <p>You can find the code block below that I am using. That code block is working well on an x86_64 architecture however the same code generates errors and not running. It seems there is a problem across different architecture, however I cannot find an appropriate solution. </p>
  
  <p>The generated error string for ARM architecture is as following:</p>
  
  <pre><code>ErrorMessage: error:0906D064:lib(9):func(109):reason(100)
  </code></pre>
  
  <p>Looking to <strong>pem.h</strong> file, the equivalents for error codes are as following:</p>
  
  <pre><code>func(109):
  # define PEM_F_PEM_READ_BIO                               109
  reason(100):
  # define PEM_R_BAD_BASE64_DECODE                          100
  </code></pre>
  
  <p>I am using the following code snippet to read from a buffer and extract a pointer to X509 structure:</p>
  
  <pre><code>BIO * bio = BIO_new(BIO_s_mem());
  BIO_write(bio, createdMemory, buffSize);
  X509 * certificate = PEM_read_bio_X509(bio,NULL,0,NULL) ;
  unsigned long errCode = ERR_peek_last_error();
  char errBuffer[16384];
  ERR_error_string_n(errCode, errBuffer, 16384);
  std::string errBufferStr(errBuffer);
  std::cout &lt;&lt; "ErrorMessage: " &lt;&lt; errBufferStr &lt;&lt; std::endl;
  </code></pre>
  
  <p>Here <code>createdMemory</code> is a char array that holds the certificate content like:</p>
  
  <pre><code>-----BEGIN CERTIFICATE-----
  Certificate content encoded with base64
  -----END CERTIFICATE-----
  </code></pre>
  
  <p>System Configuration:
  ARM Side: 
  3.14.38-6UL_ga+ge4944a5 #1 SMP PREEMPT Tue Jun 14 15:05:40 EEST 2016 armv7l GNU/Linux
  This is an imx6 Evaluation Kit, cross toolchain and the filesystem is generated using Yocto. </p>
  
  <p>x86_64 Side: 
  3.13.0-88-generic #135-Ubuntu SMP Wed Jun 8 21:10:42 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux</p>
  
  <p>Any help will be appreciated.
  Regards.</p>