Public Key Encryption Library

This Library provides a set of routines for easier handling of the Public Key Encryption module available on CEC1x02.

Library Routines

pke_status

Prototype

uint32_t pke_status();

Description

The routine returns the status of the PKE block.

Parameters

None.

Returns

The routine returns the PKE block status. The important status bits are listed below :

Bit Number Description
16 PKE Busy Bit. This applies to all operations. (1 if busy, 0 otherwise).
9 This bit only applies to signature verify operations. 0 if signature is valid, 1 otherwise.
5 This bit applies to Elliptic Curve Operations. 0 if EC point not at infinity, 1 otherwise.
5 This bit applies to Elliptic Curve Operations. 0 if EC point is on curve, 1 otherwise.
Requires

Nothing.

Notes

None.

pke_reset

Prototype

void pke_reset();

Description

This routine resets the PKE block.

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Notes

None.

pke_start

Prototype

void pke_start(uint8_t ien);

Description

The function starts the PKE block.

Parameters
  • ien: A Boolean value specifying the interrupt status. The interrupt enable mask if set, enables done and error interrupts.
Returns

Nothing.

Requires

Nothing.

Notes

None.

pke_done_status

Prototype

uint8_t pke_done_status(uint32_t *status_value);

Description

The routine is used to check the done status of the PKE block.

Parameters
  • status_value: pointer where the status value will be stored. Refer to PKE status registerfor bit definitions.
Returns
  • 1 - status is set.
  • 0 - otherwise.
Requires

Nothing.

Notes

None.

pke_clear_scm

Prototype

void pke_clear_scm();

Description

This routine clears the PKE block’s shared crypto memory (1.e. This routine fills the SCM slot with 0’s). The caller must ensure the PKE engine is idle and not in sleep state (clock gated) before calling this routine.

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Notes

Valid only for CEC1302 MCU.

pke_scm_clear_slot

Prototype

void pke_scm_clear_slot(uint8_t slot_num);

Description

This routine clears a specified slot in SCM. That is it fills the specified slot in SCM with 0’s.

Parameters
  • slot_num: specified slot number.
Returns

Nothing.

Requires

Nothing.

Notes

None.

pke_power

Prototype

void pke_power(uint8_t pwr_on);

Description

This routine controls the Gate on/off clocks to PKE block. Before setting PCR PKE sleep enable, write 0 to the PKE control register to stop the engine.

Parameters
  • pwr_on: power parameter. Valid values :
    Value Description
    Non-zero Wakes the block (ungates clocks).
    0 Puts the block in sleep mode (gates clock).
Returns

Nothing.

Requires

Nothing.

Notes

None.

pke_busy

Prototype

uint8_t pke_busy();

Description

This routine returns the PKE busy status. PKE status register bits are read-only and are cleared upon reading. Reading also clears PKE block interrupt signal.

Parameters

None.

Returns
  • 1: if PKE is busy,
  • 0: otherwise.
Requires

Nothing.

Notes

None.

pke_set_operand_slot

Prototype

void pke_set_operand_slot(uint8_t operand, uint8_t slot_num);

Description

This routine sets the slot for the selected operand.

Parameters
  • operand: operand number.
  • slot_num: slot number.
Returns

Nothing.

Requires

Nothing.

Notes

Valid only for CEC1702 MCU.

pke_get_operand_slot

Prototype

void pke_get_operand_slot(uint8_t operand);

Description

This routine returns the slot number for the specified operand.

Parameters
  • operand: operand number.
Returns

Nothing.

Requires

Nothing.

Notes

Valid only for CEC1702 MCU.

pke_set_operand_slots

Prototype

void pke_set_operand_slots(uint32_t operand);

Description

This routine sets the slots for the operand 0, 1, 2.

Parameters
  • operand: variable containing slots for operand 0, 1, 2.
Returns

Nothing.

Requires

Nothing.

Notes

Valid only for CEC1702 MCU.

pke_get_slot_addr

Prototype

uint32_t pke_get_slot_addr(uint8_t slot_num);

Description

This routine returns the address of the slot in the crypto memory.

Parameters
  • slot_num: slot number.
Returns

Nothing.

Requires

Address of the slot in the crypto memory.

Notes

Valid only for CEC1702 MCU.

pke_fill_slot

Prototype

void pke_fill_slot(const uint8_t slot_num, const uint32_t fill_val);

Description

This routine fills the slot memory with value.

Parameters
  • slot_num: slot number.
  • fill_val: value to fill slot.
Returns

Nothing.

Requires

Nothing.

Notes

Valid only for CEC1702 MCU.

pke_write_scm

Prototype // for CEC1302 MCU :

void pke_write_scm(uint8_t *pdata, uint16_t num_bytes, uint8_t slot_num, uint8_t reverse_byte_order);

// for CEC1702 MCU :

void pke_write_scm(const uint8_t *pdata, uint16_t num_bytes, uint8_t slot_num, uint8_t reverse_byte_order);

Description

This routine is used to write specified amount of data to a specified SCM slot. PKE command register operand size field must be programmed before this routine is called.

Parameters
  • pdata: pointer to data to be written.
  • num_bytes: number of bytes to written.
  • slot_num: slot number.
  • reverse_byte_order: flag which if true writes data in reverse byte order.
Returns

Nothing.

Requires

Nothing.

Notes

None.

pke_write_scm32

Prototype

void pke_write_scm32(uint8_t *pdata, uint16_t num_bytes, uint8_t slot_num, uint8_t reverse_byte_order);

Description

This routine is used to write specified amount of data to a specified SCM slot as dword. PKE command register operand size field must be programmed before this routine is called.

Parameters
  • pdata: pointer to data to be written.
  • num_bytes: number of bytes to written.
  • slot_num: slot number.
  • reverse_byte_order: flag which if true writes data in reverse byte order.
Returns

Nothing.

Requires

Nothing.

Notes

Valid only for CEC1702 MCU.

pke_read_scm

Prototype // for CEC1302 MCU :

uint16_t pke_read_scm(uint16_t *dest, uint16_t nbytes, uint16_t slot_num, uint8_t reverse_byte_order);

// for CEC1702 MCU :

uint16_t pke_read_scm(uint8_t *dest, uint16_t nbytes, uint8_t slot_num, uint8_t reverse_byte_order);

Description

This routine is used to read specified amount of data from a specified SCM slot.

Parameters
  • dest: pointer to the destination where data will be copied to.
  • nbytes: number of bytes to be read.
  • slot_num: slot from which data is to be read.
  • reverse_byte_order: flag which if true reads data in reverse byte order.
Returns

The routine returns the number of bytes copied to the destination.

Requires

Nothing.

Notes

None.

modular_arithm

Prototype

uint8_t modular_arithm(uint8_t op, uint16_t op_bit_len, uint8_t flags);

Description

This routine checks if the modular arithmetic operand.

Parameters
  • op: variable containing operand.
  • op_bit_len: length value to be validated. The valid bit lengths are 256, 512, 1024, 2048, and 4096.
  • flags: The bit definitions of flags are given below:
    Bit Description
    0 Start.
    1 enable PKE interrupts before starting.
    2 0 (field is F(p) prime), 1(Field is F(2^m) binary).
    7:3 0, reserved.
Returns

The routine returns the number of bytes copied to the destination.

Requires

Caller must program operand location using pke_set_operand_slots and program data into operand slots using pke_write_scm.

Notes

Valid only for CEC1702 MCU.

PKE_ists_clear

Prototype

uint32_t pke_ists_clear();

Description

This routine reads and clears Status bit for PKE and the interrupt source bits for PKE block.

Parameters

None.

Returns

The routine returns the status result in which :

Bit Number Description
31:22 Reserved.
21:20 GIRQ16.Source[1:0]
16:0 PKE status register value.
Requires

Caller must program operand location using pke_set_operand_slots and program data into operand slots using pke_write_scm.

Notes

Valid only for CEC1702 MCU.

Copyright (c) 2002-2019 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code