I am a master student writing my thesis and want to use the crypto library in my work.
I am using a device with ARM Cortex M23 core, and Keil as IDE. The device has 30720 bytes FLSAH and 3072 bytes RAM. No operating system on this device (I try to avoid OS as well).
At the beginning I was using this Sha256 APIs and things were fine. I generate sha256 hash value in the way https://github.com/wolfSSL/wolfssl/blob … est/test.c "sha256_test" does:
ret = wc_Sha256Update(&sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen);
if (ret != 0) {
ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
}
ret = wc_Sha256GetHash(&sha, hashcopy);
if (ret != 0)
and here is my user_settings:
/* only use crypto lib */
#define WOLFCRYPT_ONLY
/* no ARM crypto HW*/
//#define WOLFSSL_ARMASM_NO_HW_CRYPTO
/* single threaded, to avoid including pthread.h (which cannot be found by any means)*/
#define SINGLE_THREADED
/* no file system is used*/
#define NO_FILESYSTEM
/* enable SHA512 */
#define WOLFSSL_SHA512
Everything was fine, then I moved to sha512 with the same settings. Still, I try to generate the hash value in the same way as test does:
ret = wc_Sha512Update(&sha, data, len);
if (ret != 0) {
/* error code */
gen_status = false;
}
ret = wc_Sha512GetHash(&sha, hash);
if (ret != 0) {
/* error code */
gen_status = false;
}
Keil reported these to me:
Build started: Project: ciphers
*** Using Compiler 'V6.19', folder: 'C:\Keil_v5\ARM\ARMCLANG\Bin'
Build target 'ciphers'
Note: source file '.\ciphers\cmac.c' - object file renamed from '.\obj\cmac.o' to '.\obj\cmac_1.o'.
Note: source file '.\wolfssl-5.6.3\wolfcrypt\src\sha256.c' - object file renamed from '.\obj\sha256.o' to '.\obj\sha256_1.o'.
compiling sp_arm32.c...
compiling main.c...
compiling sha256.c...
compiling sha256.c...
compiling sha512.c...
linking...
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching sha512.o(.text._Transform_Sha512).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching sha512.o(.rodata.K512).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching sha512.o(.text.Sha512_Family_Final).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching sha512.o(.text.wc_Sha512Update).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching sha512.o(.text.wc_InitSha512_ex).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching sha512.o(.text.InitSha512).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching main.o(.text.main).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching startup.o(.text).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching sha512.o(.text.wc_Sha512GetHash).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching memcpya.o(.text).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching memseta.o(.text).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching init.o(.text).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching sha512.o(.text.wc_Sha512Final).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching entry9a.o(.ARM.Collect$$$$0000000B).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching system.o(.text.System_init).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching test_table.o(test_table).
.\obj\ciphers.axf: Error: L6406E: No space in execution regions with .ANY selector matching anon$$obj.o(Region$$Table).
.\obj\ciphers.axf: Error: L6407E: Sections of aggregate size 0x2968 bytes could not fit into .ANY selector(s).
Not enough information to list image symbols.
Not enough information to list load addresses in the image map.
Finished: 2 information, 0 warning and 18 error messages.
".\obj\ciphers.axf" - 18 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed: 00:00:02
I guess it's because the RAM is too small. So I got another implementation of sha512 on Github. To my surprise, it worked. So I am sure that the RAM size is enough for sha512 operations.
Then I went through the code can found that the difference between sha256 and sha512 was that, sha256 uses word32, but sha512 uses word64, like
static int _Transform_Sha512(wc_Sha512* sha512)
{
const word64* K = K512;
word32 j;
word64 T[8];
I guess the problem might be here? Therefore, I added this setting to my user_settings
/* 32-bit CPU */
#define WC_32BIT_CPU
Unfortunately noting happened, so I tried
/* 16-bit CPU */
#define WC_16BIT_CPU
New errors appeared
Note: source file '.\ciphers\cmac.c' - object file renamed from '.\obj\cmac.o' to '.\obj\cmac_1.o'.
Note: source file '.\wolfssl-5.6.3\wolfcrypt\src\sha256.c' - object file renamed from '.\obj\sha256.o' to '.\obj\sha256_1.o'.
wolfssl-5.6.3/wolfcrypt/src/sha512.c(770): error: call to undeclared function 'rotrFixed64'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
R( 0); R( 1); R( 2); R( 3);
^
wolfssl-5.6.3/wolfcrypt/src/sha512.c(728): note: expanded from macro 'R'
h(i) += S1(e(i)) + Ch(e(i),f(i),g(i)) + K[(i)+j] + (j ? blk2(i) : blk0(i)); \
^
wolfssl-5.6.3/wolfcrypt/src/sha512.c(723): note: expanded from macro 'S1'
#define S1(x) (rotrFixed64(x,14) ^ rotrFixed64(x,18) ^ rotrFixed64(x,41))
^
wolfssl-5.6.3/wolfcrypt/src/sha512.c(770): note: did you mean 'rotrFixed'?
wolfssl-5.6.3/wolfcrypt/src/sha512.c(728): note: expanded from macro 'R'
h(i) += S1(e(i)) + Ch(e(i),f(i),g(i)) + K[(i)+j] + (j ? blk2(i) : blk0(i)); \
^
wolfssl-5.6.3/wolfcrypt/src/sha512.c(723): note: expanded from macro 'S1'
#define S1(x) (rotrFixed64(x,14) ^ rotrFixed64(x,18) ^ rotrFixed64(x,41))
^
wolfssl-5.6.3\wolfcrypt/src/misc.c(111): note: 'rotrFixed' declared here
WC_MISC_STATIC WC_INLINE word32 rotrFixed(word32 x, word32 y)
^
wolfssl-5.6.3/wolfcrypt/src/sha512.c(840): error: call to undeclared function 'ByteReverseWords64'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
ByteReverseWords64(sha512->buffer, sha512->buffer,
^
wolfssl-5.6.3/wolfcrypt/src/sha512.c(840): note: did you mean 'ByteReverseWords'?
wolfssl-5.6.3\wolfcrypt/src/misc.c(181): note: 'ByteReverseWords' declared here
WC_MISC_STATIC WC_INLINE void ByteReverseWords(word32* out, const word32* in,
^
wolfssl-5.6.3/wolfcrypt/src/sha512.c(913): error: call to undeclared function 'ByteReverseWords64'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
ByteReverseWords64(sha512->buffer, sha512->buffer,
^
wolfssl-5.6.3/wolfcrypt/src/sha512.c(1019): error: call to undeclared function 'ByteReverseWords64'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
ByteReverseWords64(sha512->buffer,sha512->buffer,
^
wolfssl-5.6.3/wolfcrypt/src/sha512.c(1061): error: call to undeclared function 'ByteReverseWords64'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
ByteReverseWords64(sha512->buffer, sha512->buffer, WC_SHA512_PAD_SIZE);
^
wolfssl-5.6.3/wolfcrypt/src/sha512.c(1132): error: call to undeclared function 'ByteReverseWords64'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
ByteReverseWords64((word64*)digest, (word64*)sha512->digest,
^
6 errors generated.
I am so confused. Is 32-bit CPU a problem? If yes, what settings should I use?
I have also read the user_settings of the MDK5_ARM CryptBenckmark project, but I did not get any hint about this.
Thanks in advance for all reply and advice. Let me know if more info is needed.