Endianness and C API's: Specifically OpenSSL.
Posted
by Hassan Syed
on Stack Overflow
See other posts from Stack Overflow
or by Hassan Syed
Published on 2010-05-10T15:20:16Z
Indexed on
2010/05/10
15:24 UTC
Read the original article
Hit count: 255
I have an algorithm that uses the following OpenSSL calls:
HMAC_update() / HMAC_final() // ripe160
EVP_CipherUpdate() / EVP_CipherFinal() // cbc_blowfish
These algorithm take a unsigned char *
into the "plain text". My input data is comes from a C++ std::string::c_str()
which originate from a protocol buffer object as a encoded UTF-8 string. UTF-8 strings are meant to be endian neutrial. However I'm a bit paranoid about how OpenSSL may perform operations on the data.
My understanding is that encryption algorithms work on 8-bit blocks of data, and if a unsigned char *
is used for pointer arithmetic when the operations are performed the algorithms should be endian neutral and I do not need to worry about anything. My uncertainty is compounded by the fact that I am working on a little-endian machine and have never done any real cross-architecture programming.
My beliefs/reasoning are/is based on the following two properties
- std::string (not wstring) internally uses a 8-bit ptr and a the resulting
c_str()
ptr will itterate the same way regardless of the CPU architecture. - Encryption algorithms are either by design, or by implementation, endian neutral.
I know the best way to get a definitive answer is to use QEMU and do some cross-platform unit tests (which I plan to do). My question is a request for comments on my reasoning, and perhaps will assist other programmers when faced with similar problems.
© Stack Overflow or respective owner