14. Public key accelerator (PKA)

The public key accelerator is an AHB slave block dedicated to the computation of cryptographic public key primitives related to ECC (elliptic curve cryptography) using a predefined prime modulus and a predefined curve. The PKA core is clocked by the system clock divided by two and the PKA memory is clocked by system clock.

14.1 Features

The main features of the PKA block are:

14.2 PKA registers

14.2.1 PKA command and status register (PKA_CSR)

Address offset: 0x00

Reset value: 0x0000 0002

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.SFT_RSTRes.Res.Res.Res.Res.READYGO
rw1rw
Bits 31:8Reserved, must be kept at zero
Bit 7

SFT_RST : PKA software reset.

  • Writing 0 clears the bit and releases the PKA block reset.
  • Writing 1 resets the PKA block. The PKA RAM content is not changed.

Note: When the SFT_RST is set, the access to the PKA registers is not blocked, only the core is under reset.

Bits 6:2Reserved, must be kept at zero
Bit 1

READY : PKA readiness status.

  • 0: The PKA is still computing
  • 1: The PKA is ready to start a new calculation

Caution: If READY bit is high, the PKA cannot be accessed through the AHB interface.
The rising edge of the READY bit set the PROC_END flag in the PKA_ISR register.

Bit 0

GO : PKA start processing command.

  • Writing 0 has no effect
  • Writing 1 starts the encryption engine

This bit must be written back to zero before the end of the calculation.

14.2.2 PKA interrupt status register (PKA_ISR)

Address offset: 0x04

Reset value: 0x0000 0000

The PKA_ISR register gives the interrupts status of the PKA block. To clear a pending interrupt, it is necessary to chain two writings in the corresponding bit: write 1'b1 and then 1'b0.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ADD_ERRRAM_ERRRes.PROC_END
rwrwrw
Bits 31:4Reserved, must be kept at reset value
Bit 3

ADD_ERR: AHB Address error interrupt. When read:

  • 0: All AHB read or write access to the PKA RAM occurred in a mapped address range
  • 1: All AHB read or write access to the PKA RAM occurred in an unmapped address range

When written:

To clear the pending interrupt, the user must write this bit to 1 and clear it just after by writing 0. If the write 0 does not occur, the interrupt is generated on next event towards the CPU if enabled in PKA_IER but the flag is seen at 0 when the interrupt handler reads it in this register (as clear action is still active).

Bit 2

RAM_ERR: RAM read / write access error interrupt. When read:

  • 0: All AHB read or write access to the PKA RAM occurred while the PKA was stopped
  • 1: All the AHB read or write access to the PKA RAM occurred while the PKA was operating and using the internal RAM. Those read or write could not succeed as the PKA internal RAM is disconnected from the AHB bus when the PKA is operating (READY bit low).

When written:

To clear the pending interrupt, the user must write this bit to 1 and clear it just after by writing 0. If the write 0 does not occur, the interrupt is generated on next event towards the CPU if enabled in PKA_IER but the flag is seen at 0 when the interrupt handler reads it in this register (as clear action is still active).

Bit 1Reserved, must be kept at reset value
Bit 0

PROC_END: PKA process ending interrupt. When read:

  • 0: No new event detected
  • 1: The PKA process is ended (This bit is set to 1 when the PKA_CSR.READY bit rises.)

When written:

To clear the pending interrupt, the user must write this bit to 1 and clear it just after by writing 0. If the write 0 does not occur, the interrupt is generated on next event towards the CPU if enabled in PKA_IER but the flag is seen at 0 when the interrupt handler reads it in this register (as clear action is still active).

14.2.3 PKA control register (PKA_IEN)

Address offset: 0x08

Reset value: 0x0000 0000

The PKA_IEN register allows enabling of the PKA interrupts.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ADDERR_ENRAMERR_ENRes.READY_EN
r/wr/wr/w
Bits 31:4Reserved, must be kept at reset value
Bit 3ADDERR_EN: AHB Address error interrupt enable.
  • 0: ADD_ERR interrupt is disabled
  • 1: ADD_ERR interrupt is enabled
Bit 2RAMERR_EN: RAM access error interrupt enable.
  • 0: RAM_ERR interrupt is disabled
  • 1: RAM_ERR interrupt is enabled
Bit 1Reserved, must be kept at reset value
Bit 0READY_EN: READY interrupt enable.
  • 0: READY interrupt is disabled
  • 1: READY interrupt is enabled

14.2.4 PKA register map

The device communicates to the PKA via 32-bit-wide control registers accessible via the AMBA™ rev. 2.0 “AHB bus.

Refer to Table 3. STM32WB07xC and STM32WB06xC memory map and peripheral register boundary addresses.

Table 39. PKA register map

OffsetRegister313029282726252423222120191817161514131211109876543210
0x0000PKA_CSRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.SFT_RSTRes.Res.Res.Res.Res.READYGO
Reset value010
0x0004PKA_ISRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ADD_ERRRAM_ERRRes.PROC_END
Reset value000
0x0008PKA_IENRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ADDERR_ENRAMERR_ENRes.READY_EN
Reset value000
STMicroelectronics logo
STMicroelectronics logo

14.3 Programmer model

14.3.1 Basic sequence

The typical sequence to use the PKA block is the following:

  1. 1. Load input data into the PKA internal memory (PKA_RAM).
  2. 2. Assert the GO command by setting the GO bit in the PKA_CSR register.
  3. 3. Wait for READY bit setting (by polling READY bit in PKA_CSR register or through PROC_END interrupt).
  4. 4. Copy back elaboration results from PKA internal memory.

14.3.2 Data location in PKA_RAM

The input and output data have a specific location in PKA_RAM. The locations are specified in Table 40. ECC scalar multiplication data location.

Table 40. ECC scalar multiplication data location

Parameter descriptionMnemonicAddress (decimal)Size (words)PKA_RAM offset address
Input
'k' of kPecc_addr_k27EOS (1)0x6C
Initial point P, coordinates X,Yecc_addr_px ecc_addr_py362*EOS (1)0x90
450xB4
Output
Coordinates X,Y, of the resultsecc_addr_px ecc_addr_py362*EOS (1)0x90
450xB4
Errorecc_addr_kp_error010x00
  1. 1. EOS:ECC operand size.

The error field returns one if the input point is not a valid point so does not satisfy the curve equation. In this case the computation is very short. If the error field is zero at the end of the calculation, then the result should be considered as valid. The maximum length of data is calculated with the following formula:

\[ \text{max. EOS} = (\text{max\_ecc\_size} / \text{word\_size}) + 1. \]

Example 1

If ECC P256 is used, an operand needs \( (256 / 32 + 1) \) words, so 9 words are needed by the PKA core. When loading an input that is represented on 256 bits = 8 words, an additional word is requested and has to be filled with zero.