libtom / libtomcrypt

LibTomCrypt is a fairly comprehensive, modular and portable cryptographic toolkit that provides developers with a vast array of well known published block ciphers, one-way hash functions, chaining modes, pseudo-random number generators, public key cryptography and a plethora of other routines.
https://www.libtom.net
Other
1.55k stars 457 forks source link

Endianness not detected for ARM UWP build #576

Closed mabuchner closed 1 year ago

mabuchner commented 2 years ago

Building libtomcrypt for Windows ARM (UWP) using Visual Studio 2019 fails with the following error

Cannot detect endianness

emitted from

https://github.com/libtom/libtomcrypt/blob/v1.18.2/src/headers/tomcrypt_cfg.h#L191

mabuchner commented 2 years ago

This website is helpful for finding appropriate preprocessor defines for detecting the CPU architecture.

mabuchner commented 2 years ago

Here Microsoft lists their preprocessor defines.

_M_ARM and _M_ARM64 look like good candidates for detecting 32-bit and 64-bit ARM.

mabuchner commented 2 years ago

I've added this block of code to tomcrypt_cfg.h

/* detect ARM 32-bit */
#if defined(_M_ARM)
   #define ENDIAN_LITTLE
   #define ENDIAN_32BITWORD
#endif

/* detect ARM 64-bit */
#if defined(_M_ARM64)
   #define ENDIAN_LITTLE
   #define ENDIAN_64BITWORD
#endif

and now the error is gone.

sjaeckel commented 1 year ago

Can you please check whether #626 correctly fixes this?

mabuchner commented 1 year ago

Sorry, but I can't really test it anymore. Unfortunately, I had to find a new employer. Now I have neither access to my ex-employers codebase nor a Windows system.

I don't know, if LTC_FAST should also be defined for ARM. Apart from that the change looks fine to me.

Thanks for taking the time to fix this issue. I'm sure it will benefit other developers.