cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WLEX Public Key Accelerator (PKA) never completes modular exponentiation

GJone.6
Associate II

I am using the STM32WLE5CC ship on a RAK3172 module.

I am not using the HAL but writing directly to the PKA RAM and registers, to perform a standard Modular Exponention (normal mode) as described in section 22.4.6 of the manual.

The PKA clock has been enabled for normal and sleep mode.

I write the exponent and exponent length, the operand and operand length, and the modulus to the PKA RAM, ensuring I am ending with a 32 bit word set to zero as described by section22.4.1.

I set the PKA Control Register "Start" bit, after ensuring that the "mode" has been set to zero (Montgomery parameter computation then modular exponentiation) and the enable flag is still set.

After setting the start bit in the CR, the "Busy" bit in the status register goes high, as expected.

I poll the status register every 10 microseconds, waiting for it to change - the Busy bit should go to 0 and the PROCENF flag should go high, but it never changes, even after several hours.

I can read back the registers and RAM and they containt he values I expect.

Are there any other clock systems or registers that need to be set for the PKA to operate?

1 ACCEPTED SOLUTION

Accepted Solutions
GJone.6
Associate II

Final solution found.

It appears my code was overwriting the exponent with zeros when putting the operand into the PKA RAM. As anything to the power of zero is one, the PKA was producing the right answer for that scenario.

Ensuring the operand did not overrun the exponent means the system is now working as expected.

View solution in original post

2 REPLIES 2
GJone.6
Associate II

I've got a bit further. I had the wrong size of the operand - it needed to be the same size as the Modulus (in bits), rahter than the size of the base value of the exponent. The operation now completes.

However, the data sheet says the output should be at offset 0x724 in the PKA RAM, but this is always all zeros except the first byte, which contains 0x01. This value is the same regardless of the numbers or the modulus put into the PKA RAM.

If I use the values in the data sheet to do a large number addition or arithmetic multiplication, the operation completes and has the expected values at the expected offset in the PKA RAM offset, so I know the hardware module is turned on and working for some of the operations.

Is there any additional documentation on how to detect errors from the output of the PKA ram to hint at what else I might not be doing correctly?

Are there any known errors in the datasheet for this chipset that have not made it into an errata document?

Is there an example of code showing how to implement a modular exponential operation?

GJone.6
Associate II

Final solution found.

It appears my code was overwriting the exponent with zeros when putting the operand into the PKA RAM. As anything to the power of zero is one, the PKA was producing the right answer for that scenario.

Ensuring the operand did not overrun the exponent means the system is now working as expected.