Does BIO_read() behave differently on diff architectures?
andrew.lynch at atos.net
Fri Aug 9 12:48:02 UTC 2019
Your issue is not with BIO_read(), but with the differing signedness of the char type on your two platforms.
On your PPC platform the char type defaults to unsigned, on your x86 platform it is signed. The %x format expects an unsigned int, so on x86 the signed char values are being sign-extended to int which adds the ffffff to any values where the high bit is set (i.e. seen as negative).
One possible fix: Change "char *ptr = buf;" to "unsigned char *ptr = buf;", then you should get the expected output.
From: openssl-users [mailto:openssl-users-bounces at openssl.org] On Behalf Of Venkata Veldanda via openssl-users
Sent: Friday, August 09, 2019 11:20 AM
To: openssl-users at openssl.org
Subject: Does BIO_read() behave differently on diff architectures?
I am using openssl 1.0.2
I recently moved my app from a PPC to x86 platform (application is compiled on the respective platform) where I met an issue with BIO_read().
I read a 20bytes of data using BIO_read like following..
int res = BIO_read(bio, buf, 20);
char *ptr = buf;
The content that I send as input is a signed file content that I get from a different source. The issue is that the output 'buf' is not as expected on my x86. The behavior is different on different architectures.
For e.g. on intel x86 platform I get the following output with additional 0xffffff padded.>> For me this is not the expected result.
This is what I was getting on my PPC platform which is as expected with the same app code.
Ofcourse, I need to further check on the source where/how the signed file was generated, but does anyone have any idea if BIO_read() has any specific handling with repsect to architectures?. I'd rule out the endianess factor as I would expect the entire byte order to be reversed if so.
I print the above output using the following code.
INFO( STR(" ..> Header@%02d: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,"
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the openssl-users