2024-09-11 10:01 AM - edited 2024-09-12 06:26 AM
stm32L476VC + CubeMX + IAR + X-CUBE-CRYPTOLIB STM32CubeExpansion_Crypto_V4.2.0
i copy the example from "NUCLEO-L476RG\Applications\ECC\EDDSA_SignVerify" to my project, cmox_eddsa_sign will cause HardFault:
The processor has escalated a configurable-priority exception to HardFault.
A precise data access error has occurred (CFSR.PRECISERR, BFAR)
At data address 0x58024c00.
An imprecise data access error has occurred (CFSR.IMPRECISERR, BFAR)
At data address 0x58024c00.
Exception occurred at PC = 0x800901e, LR = 0x20002cc4
call stack:
HardFault_Handler()
<Exception frame>
[cmox_md_generateTag + 0x51]
other api work well (cmox_rsa_pkcs1v15_verify, cmox_ecdsa_sign ...)
Solved! Go to Solution.
2024-09-13 10:19 AM
Hello @lll ,
I could reproduce a crash but it was located in the internal crypto allocator.
In your code you forgot to increase the stack size. Setting stack size to 0x600 in the icf file should solve your issue.
Best regards
Jocelyn
2024-09-11 10:34 AM
It's like you've bound the wrong library.
This is the CRC Peripheral address for the STM32H7, that's going to fail on the STM32L4 series
2024-09-11 10:55 AM
Use libSTM32Cryptographic_CM4.a, not libSTM32Cryptographic_CM7.a ??
Or if there's a variable in the initialization / context passing in CRC_BASE address
CM3
cmox_md_generateTag
0x00000000: e92d4ffc -..O PUSH {r2-r11,lr}
0x00000004: 4602 .F MOV r2,r0
0x00000006: b085 .. SUB sp,sp,#0x14
0x00000008: 68d0 .h LDR r0,[r2,#0xc]
0x0000000a: 6913 .i LDR r3,[r2,#0x10]
0x0000000c: f8dfc16c ..l. LDR r12,[pc,#364] ; [cmox_table = 0x17c] = 0
0x00000010: f8df816c ..l. LDR r8,[pc,#364] ; [0x180] = 0
0x00000014: eba00a03 .... SUB r10,r0,r3
0x00000018: 6850 Ph LDR r0,[r2,#4]
0x0000001a: f0400004 @... ORR r0,r0,#4
0x0000001e: 6050 P` STR r0,[r2,#4]
0x00000020: 2700 .' MOVS r7,#0
0x00000022: a803 .. ADD r0,sp,#0xc
0x00000024: 9002 .. STR r0,[sp,#8]
0x00000026: f10d0e0c .... ADD lr,sp,#0xc
0x0000002a: e9d83400 ...4 LDRD r3,r4,[r8,#0]
0x0000002e: a803 .. ADD r0,sp,#0xc
0x00000030: 4d54 TM LDR r5,[pc,#336] ; [cmox_init_ctxi = 0x184] = 0
0x00000032: e9c03400 ...4 STRD r3,r4,[r0,#0]
0x00000036: 7828 (x LDRB r0,[r5,#0]
0x00000038: 4d53 SM LDR r5,[pc,#332] ; [0x188] = 0x9310c55f
0x0000003a: 2800 .( CMP r0,#0
0x0000003c: bf0c .. ITE EQ
0x0000003e: 2300 .# MOVEQ r3,#0
0x00000040: 2304 .# MOVNE r3,#4
0x00000042: 4699 .F MOV r9,r3
0x00000044: f85c3003 \..0 LDR r3,[r12,r3]
0x00000048: f85e4009 ^..@ LDR r4,[lr,r9]
0x0000004c: 4423 #D ADD r3,r3,r4
0x0000004e: 2601 .& MOVS r6,#1
0x00000050: 601d .` STR r5,[r3,#0]
0x00000052: 681c .h LDR r4,[r3,#0]
0x00000054: 609e .` STR r6,[r3,#8]
0x00000056: f8dc3004 ...0 LDR r3,[r12,#4]
0x0000005a: 9d03 .. LDR r5,[sp,#0xc]
0x0000005c: f8dc9000 .... LDR r9,[r12,#0]
0x00000060: f8de6004 ...` LDR r6,[lr,#4]
0x00000064: 405d ]@ EORS r5,r5,r3
0x00000066: 4065 e@ EORS r5,r5,r4
0x00000068: 4c48 HL LDR r4,[pc,#288] ; [0x18c] = 0x12008504
0x0000006a: 4065 e@ EORS r5,r5,r4
0x0000006c: ea890606 .... EOR r6,r9,r6
0x00000070: 4c47 GL LDR r4,[pc,#284] ; [0x190] = 0x7a0168fc
0x00000072: 4066 f@ EORS r6,r6,r4
0x00000074: 1975 u. ADDS r5,r6,r5
0x00000076: 4c47 GL LDR r4,[pc,#284] ; [0x194] = 0xff24f5c0
0x00000078: 4065 e@ EORS r5,r5,r4
...
CM7
cmox_md_generateTag
0x00000000: e92d4ffc -..O PUSH {r2-r11,lr}
0x00000004: b085 .. SUB sp,sp,#0x14
0x00000006: 4602 .F MOV r2,r0
0x00000008: 68d0 .h LDR r0,[r2,#0xc]
0x0000000a: 6913 .i LDR r3,[r2,#0x10]
0x0000000c: 2700 .' MOVS r7,#0
0x0000000e: f8dfc178 ..x. LDR r12,[pc,#376] ; [cmox_table = 0x188] = 0
0x00000012: f10d0e0c .... ADD lr,sp,#0xc
0x00000016: f8df8174 ..t. LDR r8,[pc,#372] ; [0x18c] = 0
0x0000001a: eba00903 .... SUB r9,r0,r3
0x0000001e: 6853 Sh LDR r3,[r2,#4]
0x00000020: a803 .. ADD r0,sp,#0xc
0x00000022: f0430304 C... ORR r3,r3,#4
0x00000026: 6053 S` STR r3,[r2,#4]
0x00000028: 9002 .. STR r0,[sp,#8]
0x0000002a: a803 .. ADD r0,sp,#0xc
0x0000002c: 4d58 XM LDR r5,[pc,#352] ; [cmox_init_ctxi = 0x190] = 0
0x0000002e: e9d83400 ...4 LDRD r3,r4,[r8,#0]
0x00000032: e9c03400 ...4 STRD r3,r4,[r0,#0]
0x00000036: 7828 (x LDRB r0,[r5,#0]
0x00000038: 4d56 VM LDR r5,[pc,#344] ; [0x194] = 0x9310c55f
0x0000003a: f8dfb15c ..\. LDR r11,[pc,#348] ; [0x198] = 0x7a0168fc
0x0000003e: 2800 .( CMP r0,#0
0x00000040: bf0c .. ITE EQ
0x00000042: 2300 .# MOVEQ r3,#0
0x00000044: 2304 .# MOVNE r3,#4
0x00000046: 461c .F MOV r4,r3
0x00000048: f85c3003 \..0 LDR r3,[r12,r3]
0x0000004c: f85e4004 ^..@ LDR r4,[lr,r4]
0x00000050: 18e3 .. ADDS r3,r4,r3
0x00000052: 2401 .$ MOVS r4,#1
0x00000054: 601d .` STR r5,[r3,#0]
0x00000056: 681e .h LDR r6,[r3,#0]
0x00000058: 609c .` STR r4,[r3,#8]
0x0000005a: f8dc3004 ...0 LDR r3,[r12,#4]
0x0000005e: 9d03 .. LDR r5,[sp,#0xc]
0x00000060: f8dc4000 ...@ LDR r4,[r12,#0]
0x00000064: 405d ]@ EORS r5,r5,r3
0x00000066: 4075 u@ EORS r5,r5,r6
0x00000068: 4e4c LN LDR r6,[pc,#304] ; [0x19c] = 0x12008504
0x0000006a: 4075 u@ EORS r5,r5,r6
0x0000006c: f8de6004 ...` LDR r6,[lr,#4]
0x00000070: 4066 f@ EORS r6,r6,r4
0x00000072: ea8b0606 .... EOR r6,r11,r6
0x00000076: 4435 5D ADD r5,r5,r6
0x00000078: 4e49 IN LDR r6,[pc,#292] ; [0x1a0] = 0xff24f5c0
0x0000007a: 4075 u@ EORS r5,r5,r6
0x0000007c: 2800 .( CMP r0,#0
...
2024-09-11 06:14 PM
i use libSTM32Cryptographic_CM4.a, and active crc in CubeMX, maybe there is something wrong in the lib
0x800'9052: 0x9a09 LDR R2, [SP, #0x24]
0x800'9054: 0xa901 ADD R1, SP, #0x4
0x800'9056: 0x4648 MOV R0, R9
0x800'9058: 0xf7f9 0xffbe BL cmox_membuf_free ; 0x800'2fd8
0x800'905c: 0x9804 LDR R0, [SP, #0x10]
0x800'905e: 0xb00b ADD SP, SP, #0x2c
0x800'9060: 0xe8bd 0x8ff0 POP.W {R4-R11, PC}
cmox_md_generateTag:
0x800'9064: 0xe92d 0x4ffc PUSH.W {R2-R11, LR}
0x800'9068: 0x4602 MOV R2, R0
0x800'906a: 0xb085 SUB SP, SP, #0x14
0x800'906c: 0x68d0 LDR R0, [R2, #0xc]
0x800'906e: 0x6913 LDR R3, [R2, #0x10]
0x800'9070: 0xf8df 0xc16c LDR.W R12, [PC, #0x16c] ; cmox_table
0x800'9074: 0xf8df 0x816c LDR.W R8, [PC, #0x16c] ; 0x800'9d04
0x800'9076: 0x816c STRH R4, [R5, #0xa]
0x800'9078: 0xeba0 0x0a03 SUB.W R10, R0, R3
0x800'907c: 0x6850 LDR R0, [R2, #0x4]
0x800'907e: 0xf040 0x0004 ORR.W R0, R0, #4
0x800'9082: 0x6050 STR R0, [R2, #0x4]
0x800'9084: 0x2700 MOVS R7, #0
0x800'9086: 0xa803 ADD R0, SP, #0xc
0x800'9088: 0x9002 STR R0, [SP, #0x8]
0x800'908a: 0xf10d 0x0e0c ADD.W LR, SP, #12 ; 0xc
0x800'908e: 0xe9d8 0x3400 LDRD R3, R4, [R8]
0x800'9092: 0xa803 ADD R0, SP, #0xc
0x800'9094: 0x4d54 LDR.N R5, [PC, #0x150] ; cmox_init_ctxi
0x800'9096: 0xe9c0 0x3400 STRD R3, R4, [R0]
0x800'909a: 0x7828 LDRB R0, [R5]
0x800'909c: 0x4d53 LDR.N R5, [PC, #0x14c] ; 0x9310'c55f
0x800'909e: 0x2800 CMP R0, #0
0x800'90a0: 0xbf0c ITE EQ
0x800'90a2: 0x2300 MOVEQ R3, #0
0x800'90a4: 0x2304 MOVNE R3, #4
0x800'90a6: 0x4699 MOV R9, R3
0x800'90a8: 0xf85c 0x3003 LDR.W R3, [R12, R3]
0x800'90ac: 0xf85e 0x4009 LDR.W R4, [LR, R9]
0x800'90b0: 0x4423 ADD R3, R3, R4
0x800'90b2: 0x2601 MOVS R6, #1
0x800'90b4: 0x601d STR R5, [R3]
0x800'90b6: 0x681c LDR R4, [R3]
0x800'90b8: 0x609e STR R6, [R3, #0x8]
0x800'90ba: 0xf8dc 0x3004 LDR.W R3, [R12, #0x4]
0x800'90be: 0x9d03 LDR R5, [SP, #0xc]
0x800'90c0: 0xf8dc 0x9000 LDR.W R9, [R12]
0x800'90c4: 0xf8de 0x6004 LDR.W R6, [LR, #0x4]
0x800'90c8: 0x405d EORS R5, R5, R3
0x800'90ca: 0x4065 EORS R5, R5, R4
0x800'90cc: 0x4c48 LDR.N R4, [PC, #0x120] ; 0x1200'8504
0x800'90ce: 0x4065 EORS R5, R5, R4
0x800'90d0: 0xea89 0x0606 EOR.W R6, R9, R6
0x800'90d4: 0x4c47 LDR.N R4, [PC, #0x11c] ; 0x7a01'68fc
0x800'90d6: 0x4066 EORS R6, R6, R4
0x800'90d8: 0x1975 ADDS R5, R6, R5
0x800'90da: 0x4c47 LDR.N R4, [PC, #0x11c] ; 0xff24'f5c0
2024-09-12 06:40 AM
2024-09-13 05:47 AM
Hello @lll ,
you are using CM4 library, so no issue here.
Pointing on this specific address (0x58024c00) that is actual CRC address of the STM32H7 exactly at the place where you should have STM32L4 address, may be related to your project setup. I don't know how though
Could you please check your project usage of cmsis files ? This address must have been introduced somewhere.
Also, if you can share your project I could have a look.
Best regards
Jocelyn
2024-09-13 05:59 AM
How does the library make a determination of the CRC peripheral address? Seen multiple reports of this issue, so a root-cause needs to be determined.
This seems like an internal thing. A thing that ST's doing, purposely, and at some point becomes a liability.
How does Hard Faulting play into Operational Safety?
2024-09-13 06:04 AM
>>This address must have been introduced somewhere
It's coming from the library, it's being used to muddle / obfuscate initialization constants, keys, etc. as part of a strategy to limit the libraries to STM32 cores.
2024-09-13 06:52 AM
2024-09-13 10:19 AM
Hello @lll ,
I could reproduce a crash but it was located in the internal crypto allocator.
In your code you forgot to increase the stack size. Setting stack size to 0x600 in the icf file should solve your issue.
Best regards
Jocelyn