linux/drivers/mxc/security/mxc_scc_internals.h File Reference

This is intended to be the file which contains most or all of the code or changes need to port the driver. It also includes other definitions needed by the driver. More...

Data Structures

struct  scc_key_slot

Defines

#define SCC_KEY_SLOTS   20
#define SCC_KEY_SLOTS   0
#define SCC_CALLBACK_SIZE   4
#define CRC_CCITT_START   0xFFFF
#define SCC_SPIN_COUNT   1000
#define SCC_CIPHER_MAX_POLL_COUNT   100
#define SCC_READ_REGISTER(offset)   __raw_readl(scc_base+(offset))
#define SCC_WRITE_REGISTER(offset, value)   (void)__raw_writel(value, scc_base+(offset))
#define SCC_BYTE_OFFSET(bp)   ((uint32_t)(bp) % sizeof(uint32_t))
#define SCC_WORD_PTR(bp)   (((uint32_t)(bp)) & ~(sizeof(uint32_t)-1))
#define SCC_BLOCK_SIZE_BYTES()   scc_configuration.block_size_bytes
#define PADDING_BUFFER_MAX_BYTES   (CRC_SIZE_BYTES + sizeof(scc_block_padding))
#define CRC_SIZE_BYTES   (sizeof(crc_t))
#define CRC_POLYNOMIAL   0x1021
#define CALC_CRC(byte_value, running_crc)
#define SCC_DRIVER_PAD_CHAR   0x80
#define SCC_DRIVER_NAME   "scc"

Typedefs

typedef uint16_t crc_t

Enumerations

enum  scc_status {
  SCC_STATUS_INITIAL,
  SCC_STATUS_CHECKING,
  SCC_STATUS_UNIMPLEMENTED,
  SCC_STATUS_OK,
  SCC_STATUS_FAILED
}

Functions

 OS_DEV_ISR (scc_irq)
static void scc_perform_callbacks (void)
static scc_return_t scc_encrypt (uint32_t count_in_bytes, const uint8_t *data_in, uint32_t scm_control, uint8_t *data_out, int add_crc, unsigned long *count_out_bytes)
static scc_return_t scc_decrypt (uint32_t count_in_bytes, const uint8_t *data_in, uint32_t scm_control, uint8_t *data_out, int verify_crc, unsigned long *count_out_bytes)

Detailed Description

This is intended to be the file which contains most or all of the code or changes need to port the driver. It also includes other definitions needed by the driver.

This header file should only ever be included by scc_driver.c

Compile-time flags minimally needed:

Some changes which could be made when porting this driver: SCC_SPIN_COUNT


Define Documentation

#define CALC_CRC ( byte_value,
running_crc   ) 
Value:
{                                  \
    uint8_t data;                                                            \
    data = (0xff&(byte_value)) ^ (running_crc >> 8);                         \
    running_crc = scc_crc_lookup_table[data] ^ (running_crc << 8);           \
}

Calculate CRC on one byte of data

Parameters:
[in,out] running_crc A value of type crc_t where CRC is kept. This must be an rvalue and an lvalue.
[in] byte_value The byte (uint8_t, char) to be put in the CRC
Returns:
none

Referenced by copy_from_scc(), copy_to_scc(), and scc_decrypt().

#define CRC_CCITT_START   0xFFFF

Initial CRC value for CCITT-CRC calculation.

Referenced by scc_decrypt(), and scc_encrypt().

#define CRC_POLYNOMIAL   0x1021

The polynomial used in CCITT-CRC calculation

Referenced by scc_init_ccitt_crc().

#define CRC_SIZE_BYTES   (sizeof(crc_t))

Shorthand (clearer, anyway) for number of bytes in a CRC.

Referenced by scc_crypt(), scc_decrypt(), and scc_encrypt().

#define PADDING_BUFFER_MAX_BYTES   (CRC_SIZE_BYTES + sizeof(scc_block_padding))

Maximum number of additional bytes which may be added in CRC+padding mode.

Referenced by scc_encrypt().

 
#define SCC_BLOCK_SIZE_BYTES (  )     scc_configuration.block_size_bytes

Determine number of bytes in an SCC block

Returns:
Bytes / block

Referenced by scc_crypt(), scc_decrypt(), scc_decrypt_slot(), scc_do_crypto(), scc_encrypt(), scc_encrypt_slot(), scc_grab_config_values(), and scc_strip_padding().

#define SCC_BYTE_OFFSET ( bp   )     ((uint32_t)(bp) % sizeof(uint32_t))

Calculates the byte offset into a word

Parameters:
bp The byte (char*) pointer
Returns:
The offset (0, 1, 2, or 3)

Referenced by check_register_offset(), copy_from_scc(), and copy_to_scc().

#define SCC_CALLBACK_SIZE   4

The number of function pointers which can be stored in scc_callbacks. Defaults to 4, can be overridden with compile-line argument.

Referenced by scc_cleanup(), scc_init(), scc_monitor_security_failure(), scc_perform_callbacks(), and scc_stop_monitoring_security_failure().

#define SCC_CIPHER_MAX_POLL_COUNT   100

Number of times to polling SCC while waiting for cipher or zeroizing function to complete. See also SCC_SPIN_COUNT.

Referenced by scc_wait_completion().

#define SCC_DRIVER_NAME   "scc"

Name of the driver. Used (on Linux, anyway) when registering interrupts

Referenced by setup_interrupt_handling().

#define SCC_DRIVER_PAD_CHAR   0x80

Value of 'beginning of padding' marker in driver-provided padding

Referenced by scc_strip_padding().

#define SCC_KEY_SLOTS   0

Define the number of Stored Keys which the SCC driver will make available. Value shall be from 0 to 20. Default is zero (0).

#define SCC_KEY_SLOTS   20

Define the number of Stored Keys which the SCC driver will make available. Value shall be from 0 to 20. Default is zero (0).

Referenced by scc_alloc_slot(), and scc_init().

#define SCC_READ_REGISTER ( offset   )     __raw_readl(scc_base+(offset))

Read a 32-bit value from an SCC register. Macro which depends upon scc_base. Linux readl()/writel() macros operate on 32-bit quantities, as do SCC register reads/writes.

Parameters:
offset Register offset within SCC.
Returns:
The value from the SCC's register.

Referenced by copy_from_scc(), copy_to_scc(), is_cipher_done(), OS_DEV_ISR(), scc_do_crypto(), scc_encrypt(), scc_grab_config_values(), scc_read_register(), scc_update_state(), scc_write_register(), and scc_zeroize_memories().

#define SCC_SPIN_COUNT   1000

Number of times to spin between polling of SCC while waiting for cipher or zeroizing function to complete. See also SCC_CIPHER_MAX_POLL_COUNT.

#define SCC_WORD_PTR ( bp   )     (((uint32_t)(bp)) & ~(sizeof(uint32_t)-1))

Converts (by rounding down) a byte pointer into a word pointer

Parameters:
bp The byte (char*) pointer
Returns:
The word (uint32_t) as though it were an aligned (uint32_t*)

Referenced by copy_from_scc(), and copy_to_scc().

#define SCC_WRITE_REGISTER ( offset,
value   )     (void)__raw_writel(value, scc_base+(offset))

Write a 32-bit value to an SCC register. Macro depends upon scc_base. Linux readl()/writel() macros operate on 32-bit quantities, as do SCC register reads/writes.

Parameters:
offset Register offset within SCC.
value 32-bit value to store into the register
Returns:
(void)

Referenced by copy_from_scc(), copy_to_scc(), OS_DEV_ISR(), scc_cleanup(), scc_crypt(), scc_dealloc_slot(), scc_decrypt(), scc_decrypt_slot(), scc_do_crypto(), scc_encrypt(), scc_encrypt_slot(), scc_init(), scc_set_sw_alarm(), scc_update_state(), scc_write_register(), scc_zeroize_memories(), and setup_interrupt_handling().


Typedef Documentation

typedef uint16_t crc_t

Provide a typedef for the CRC which can be used in encrypt/decrypt


Enumeration Type Documentation

enum scc_status

Gives high-level view of state of the SCC

Enumerator:
SCC_STATUS_INITIAL 

State of driver before ever checking

SCC_STATUS_CHECKING 

Transient state while driver loading

SCC_STATUS_UNIMPLEMENTED 

SCC is non-existent or unuseable

SCC_STATUS_OK 

SCC is in Secure or Default state

SCC_STATUS_FAILED 

In Failed state


Function Documentation

OS_DEV_ISR ( scc_irq   ) 

This is the interrupt handler for the SCC.

This function checks the SMN Status register to see whether it generated the interrupt, then it checks the SCM Status register to see whether it needs attention.

If an SMN Interrupt is active, then the SCC state set to failure, and scc_perform_callbacks() is invoked to notify any interested parties.

The SCM Interrupt should be masked, as this driver uses polling to determine when the SCM has completed a crypto or zeroing operation. Therefore, if the interrupt is active, the driver will just clear the interrupt and (re)mask.

References IRQ_RETVAL, os_dev_get_irq, SCC_READ_REGISTER, scc_update_state(), SCC_WRITE_REGISTER, SCM_INTERRUPT_CTRL, SCM_INTERRUPT_CTRL_CLEAR_INTERRUPT, SCM_INTERRUPT_CTRL_MASK_INTERRUPTS, SCM_STATUS, SMN_COMMAND, SMN_COMMAND_CLEAR_INTERRUPT, and SMN_STATUS_SMN_STATUS_IRQ.

static scc_return_t scc_decrypt ( uint32_t  count_in_bytes,
const uint8_t *  data_in,
uint32_t  scm_control,
uint8_t *  data_out,
int  verify_crc,
unsigned long *  count_out_bytes 
) [static]

Perform a decryption on the input. If verify_crc is true, the last block (maybe the two last blocks) is special - it should contain a CRC and padding. These must be stripped and verified.

Parameters:
[in] count_in_bytes Count of bytes of ciphertext
[in] data_in Pointer to the ciphertext
[in] scm_control Bit values for the SCM_CONTROL register
[in,out] data_out Pointer for storing plaintext
[in] verify_crc Flag for running CRC - 0 no, else yes
[in,out] count_out_bytes Number of bytes available at data_out
static scc_return_t scc_encrypt ( uint32_t  count_in_bytes,
const uint8_t *  data_in,
uint32_t  scm_control,
uint8_t *  data_out,
int  add_crc,
unsigned long *  count_out_bytes 
) [static]

Perform an encryption on the input. If verify_crc is true, a CRC must be calculated on the plaintext, and appended, with padding, before computing the ciphertext.

Parameters:
[in] count_in_bytes Count of bytes of plaintext
[in] data_in Pointer to the plaintext
[in] scm_control Bit values for the SCM_CONTROL register
[in,out] data_out Pointer for storing ciphertext
[in] add_crc Flag for computing CRC - 0 no, else yes
[in,out] count_out_bytes Number of bytes available at data_out
static void scc_perform_callbacks ( void   )  [static]

Perform callbacks registered by scc_monitor_security_failure().

Make sure callbacks only happen once... Since there may be some reason why the interrupt isn't generated, this routine could be called from base(task) level.

One at a time, go through scc_callbacks[] and call any non-null pointers.

footer
©  Freescale Semiconductor, Inc., 2007.  All rights reserved.
Freescale Confidential Proprietary
NDA Required
doxygen