Defines | |
#define | FALSE 0 |
#define | TRUE 1 |
Functions | |
OS_DEV_INIT (shw_init) | |
OS_DEV_SHUTDOWN (shw_shutdown) | |
static void | shw_cleanup (void) |
OS_DEV_OPEN (shw_open) | |
OS_DEV_IOCTL (shw_ioctl) | |
OS_DEV_MMAP (shw_mmap) | |
OS_DEV_CLOSE (shw_release) | |
static void | shw_user_callback (fsl_shw_uco_t *user_ctx) |
static os_error_code | shw_setup_user_driver_interaction (void) |
static os_error_code | init_uco (fsl_shw_uco_t *user_ctx, void *user_mode_uco) |
static void * | copy_array (void *userloc, void *userend, void *data_start, unsigned element_size, unsigned element_count) |
static os_error_code | copy_fsl_code (void *user_header, fsl_shw_return_t result_code) |
static os_error_code | get_capabilities (fsl_shw_uco_t *user_ctx, void *user_mode_pco_request) |
static os_error_code | get_results (fsl_shw_uco_t *user_ctx, void *user_mode_results_req) |
static void | process_hdr (fsl_shw_uco_t *user_ctx, struct shw_req_header *hdr) |
static os_error_code | get_random (fsl_shw_uco_t *user_ctx, void *user_mode_get_random_req) |
static os_error_code | add_entropy (fsl_shw_uco_t *user_ctx, void *user_mode_add_entropy_req) |
fsl_shw_return_t | fsl_shw_register_user (fsl_shw_uco_t *user_ctx) |
fsl_shw_return_t | fsl_shw_deregister_user (fsl_shw_uco_t *user_ctx) |
fsl_shw_pco_t * | fsl_shw_get_capabilities (fsl_shw_uco_t *user_ctx) |
fsl_shw_return_t | fsl_shw_get_random (fsl_shw_uco_t *user_ctx, uint32_t length, uint8_t *data) |
fsl_shw_return_t | fsl_shw_add_entropy (fsl_shw_uco_t *user_ctx, uint32_t length, uint8_t *data) |
fsl_shw_return_t | fsl_shw_hash (fsl_shw_uco_t *user_ctx, fsl_shw_hco_t *hash_ctx, const uint8_t *msg, uint32_t length, uint8_t *result, uint32_t result_len) |
fsl_shw_return_t | fsl_shw_hmac_precompute (fsl_shw_uco_t *user_ctx, fsl_shw_sko_t *key_info, fsl_shw_hmco_t *hmac_ctx) |
fsl_shw_return_t | fsl_shw_hmac (fsl_shw_uco_t *user_ctx, fsl_shw_sko_t *key_info, fsl_shw_hmco_t *hmac_ctx, const uint8_t *msg, uint32_t length, uint8_t *result, uint32_t result_len) |
fsl_shw_return_t | do_scc_encrypt_region (fsl_shw_uco_t *user_ctx, void *partition_base, uint32_t offset_bytes, uint32_t byte_count, uint8_t *black_data, uint32_t *IV, fsl_shw_cypher_mode_t cypher_mode) |
fsl_shw_return_t | do_scc_decrypt_region (fsl_shw_uco_t *user_ctx, void *partition_base, uint32_t offset_bytes, uint32_t byte_count, const uint8_t *black_data, uint32_t *IV, fsl_shw_cypher_mode_t cypher_mode) |
void * | fsl_shw_smalloc (fsl_shw_uco_t *user_ctx, uint32_t size, const uint8_t *UMID, uint32_t permissions) |
fsl_shw_return_t | fsl_shw_sfree (fsl_shw_uco_t *user_ctx, void *address) |
fsl_shw_return_t | fsl_shw_diminish_perms (fsl_shw_uco_t *user_ctx, void *address, uint32_t permissions) |
fsl_shw_return_t | fsl_shw_gen_encrypt (fsl_shw_uco_t *user_ctx, fsl_shw_acco_t *auth_ctx, fsl_shw_sko_t *cipher_key_info, fsl_shw_sko_t *auth_key_info, uint32_t auth_data_length, const uint8_t *auth_data, uint32_t payload_length, const uint8_t *payload, uint8_t *ct, uint8_t *auth_value) |
fsl_shw_return_t | fsl_shw_auth_decrypt (fsl_shw_uco_t *user_ctx, fsl_shw_acco_t *auth_ctx, fsl_shw_sko_t *cipher_key_info, fsl_shw_sko_t *auth_key_info, uint32_t auth_data_length, const uint8_t *auth_data, uint32_t payload_length, const uint8_t *ct, const uint8_t *auth_value, uint8_t *payload) |
fsl_shw_return_t | fsl_shw_gen_random_pf_key (fsl_shw_uco_t *user_ctx) |
Variables | |
static int | shw_major_node = SHW_MAJOR_NODE |
static int | shw_device_registered = 0 |
static os_driver_reg_t | reg_handle |
fsl_shw_uco_t * | user_list |
os_lock_t | shw_queue_lock = NULL |
static fsl_shw_key_alg_t | pf_syms [] |
static fsl_shw_sym_mode_t | pf_modes [] |
static fsl_shw_hash_alg_t | pf_hashes [] |
static fsl_shw_pco_t | cap |
Its interaction with the Linux kernel is from calls to shw_init() when the driver is loaded, and shw_shutdown() should the driver be unloaded.
The User API (driver interface) is handled by the following functions:
The life of the driver starts at boot (or module load) time, with a call by the kernel to shw_init().
The life of the driver ends when the kernel is shutting down (or the driver is being unloaded). At this time, shw_shutdown() is called. No function will ever be called after that point.
In the case that the driver is reloaded, a new copy of the driver, with fresh global values, etc., is loaded, and there will be a new call to shw_init().
In user mode, the user's fsl_shw_register_user() call causes an open() event on the driver followed by a ioctl() with the registration information. Any subsequent API calls by the user are handled through the ioctl() function and shuffled off to the appropriate routine (or driver) for service. The fsl_shw_deregister_user() call by the user results in a close() function call on the driver.
In kernel mode, the driver provides the functions fsl_shw_register_user(), fsl_shw_deregister_user(), fsl_shw_get_capabilities(), and fsl_shw_get_results(). Other parts of the API are provided by other drivers, if available, to support the cryptographic functions.
#define FALSE 0 |
Not true. Guaranteed to be zero.
#define TRUE 1 |
True. Guaranteed to be non-zero.
static os_error_code add_entropy | ( | fsl_shw_uco_t * | user_ctx, | |
void * | user_mode_add_entropy_req | |||
) | [static] |
Handle user-mode Add Entropy request
user_ctx | Pointer to the kernel version of user's context | |
user_mode_add_entropy_req | Address of user-space request |
References copy_fsl_code(), fsl_shw_add_entropy(), os_alloc_memory(), os_copy_from_user(), OS_ERROR_OK_S, and os_free_memory().
Referenced by OS_DEV_IOCTL().
static void* copy_array | ( | void * | userloc, | |
void * | userend, | |||
void * | data_start, | |||
unsigned | element_size, | |||
unsigned | element_count | |||
) | [inline, static] |
Copy array from kernel to user space.
This routine will check bounds before trying to copy, and return failure on bounds violation or error during the copy.
userloc | Location in userloc to place data. If NULL, the function will do nothing (except return NULL). | |
userend | Address beyond allowed copy region at userloc . | |
data_start | Location of data to be copied | |
element_size | sizeof() an element | |
element_count | Number of elements of size element_size to copy. |
References OS_ERROR_OK_S.
Referenced by get_capabilities().
static os_error_code copy_fsl_code | ( | void * | user_header, | |
fsl_shw_return_t | result_code | |||
) | [inline, static] |
Send an FSL SHW API return code up into the user-space request structure.
user_header | User address of request block / request header | |
result_code | The FSL SHW API code to be placed at header.code |
References os_copy_to_user().
Referenced by add_entropy(), get_capabilities(), get_random(), and get_results().
static os_error_code get_capabilities | ( | fsl_shw_uco_t * | user_ctx, | |
void * | user_mode_pco_request | |||
) | [static] |
Handle user-mode Get Capabilities request
Right now, this function can only have a failure if the user has failed to provide a pointer to a location in user space with enough room to hold the fsl_shw_pco_t structure and any associated data. It will treat this failure as an ioctl failure and return an ioctl error code, instead of treating it as an API failure.
user_ctx | The kernel version of user's context | |
user_mode_pco_request | Pointer to user-space request |
References copy_array(), copy_fsl_code(), FSL_RETURN_OK_S, fsl_shw_pco_t::hash_algorithm_count, fsl_shw_pco_t::hash_algorithms, os_copy_from_user(), os_copy_to_user(), OS_ERROR_BAD_ADDRESS_S, OS_ERROR_OK_S, fsl_shw_pco_t::sym_algorithm_count, fsl_shw_pco_t::sym_algorithms, fsl_shw_pco_t::sym_mode_count, and fsl_shw_pco_t::sym_modes.
Referenced by fsl_shw_get_capabilities(), and OS_DEV_IOCTL().
static os_error_code get_random | ( | fsl_shw_uco_t * | user_ctx, | |
void * | user_mode_get_random_req | |||
) | [static] |
Handle user-mode Get Random request
user_ctx | The kernel version of user's context | |
user_mode_get_random_req | Pointer to user-space request |
References copy_fsl_code(), fsl_shw_get_random(), FSL_UCO_BLOCKING_MODE, os_copy_from_user(), OS_ERROR_OK_S, and process_hdr().
Referenced by OS_DEV_IOCTL().
static os_error_code get_results | ( | fsl_shw_uco_t * | user_ctx, | |
void * | user_mode_results_req | |||
) | [static] |
Handle user-mode Get Results request
Get arguments from user space into kernel space, then call fsl_shw_get_results, and then copy its return code and any results from kernel space back to user space.
user_ctx | The kernel version of user's context | |
user_mode_results_req | Pointer to user-space request |
References copy_fsl_code(), FSL_RETURN_OK_S, fsl_shw_get_results(), os_alloc_memory(), os_copy_from_user(), os_copy_to_user(), OS_ERROR_NO_MEMORY_S, OS_ERROR_OK_S, and os_free_memory().
Referenced by OS_DEV_IOCTL().
static os_error_code init_uco | ( | fsl_shw_uco_t * | user_ctx, | |
void * | user_mode_uco | |||
) | [static] |
Initialze kernel User Context Object from User-space version.
Copy user UCO into kernel UCO, set flags and fields for operation within kernel space. Add user to driver's list of users.
user_ctx | Pointer to kernel space UCO | |
user_mode_uco | User pointer to user space version |
References fsl_shw_uco_t::callback, fsl_shw_uco_t::flags, FSL_UCO_USERMODE_USER, os_copy_from_user(), OS_ERROR_OK_S, os_get_process_handle(), SHW_ADD_USER(), and shw_user_callback().
Referenced by OS_DEV_IOCTL().
OS_DEV_CLOSE | ( | shw_release | ) |
Handle close()
call from user. This is a Linux device driver interface routine.
References fsl_shw_deregister_user(), os_dev_close_return(), os_dev_get_user_private(), os_dev_set_user_private(), OS_ERROR_OK_S, and os_free_memory().
OS_DEV_INIT | ( | shw_init | ) |
Initialize the driver.
This routine is called during kernel init or module load (insmod).
References scc_config_t::black_ram_size_blocks, scc_config_t::block_size_bytes, fsl_shw_pco_t::block_size_bytes, scc_config_t::driver_major_version, scc_config_t::driver_minor_version, FSL_RETURN_OK_S, fsl_shw_establish_keystore(), fsl_shw_init_keystore_default(), os_dev_init_return(), OS_ERROR_FAIL_S, OS_ERROR_NO_MEMORY_S, OS_ERROR_OK_S, os_lock_alloc_init(), scc_config_t::partition_count, scc_config_t::partition_size_bytes, scc_config_t::red_ram_size_blocks, fsl_shw_pco_t::scc2_info, fsl_shw_pco_t::scc_driver_major, fsl_shw_pco_t::scc_driver_minor, fsl_shw_pco_t::scc_info, scc_config_t::scm_version, fsl_shw_pco_t::scm_version, shw_cleanup(), shw_queue_lock, shw_setup_user_driver_interaction(), scc_config_t::smn_version, fsl_shw_pco_t::smn_version, and fsl_shw_pco_t::u.
OS_DEV_IOCTL | ( | shw_ioctl | ) |
Process an ioctl() request from user-mode API.
This code determines which of the API requests the user has made and then sends the request off to the appropriate function.
References add_entropy(), get_capabilities(), get_random(), get_results(), init_uco(), os_alloc_memory(), os_dev_get_ioctl_arg(), os_dev_get_ioctl_op(), os_dev_get_user_private(), os_dev_ioctl_return(), os_dev_set_user_private(), OS_ERROR_FAIL_S, OS_ERROR_NO_MEMORY_S, OS_ERROR_OK_S, os_free_memory(), SHW_IOCTL_REQUEST, SHW_REMOVE_USER(), SHW_USER_REQ_ADD_ENTROPY, SHW_USER_REQ_DEREGISTER_USER, SHW_USER_REQ_DROP_PERMS, SHW_USER_REQ_GET_CAPABILITIES, SHW_USER_REQ_GET_RANDOM, SHW_USER_REQ_GET_RESULTS, SHW_USER_REQ_REGISTER_USER, SHW_USER_REQ_SCC_DECRYPT, SHW_USER_REQ_SCC_ENCRYPT, SHW_USER_REQ_SFREE, and SHW_USER_REQ_SSTATUS.
OS_DEV_MMAP | ( | shw_mmap | ) |
This function implements the smalloc() function for userspace programs, by making a call to the SCC2 mmap() function that acquires a region of secure memory on behalf of the user, and then maps it into the users memory space. Currently, the only memory size supported is that of a single SCC2 partition. Requests for other sized memory regions will fail.
References FALSE, FSL_RETURN_OK_S, fsl_shw_register_user(), os_alloc_memory(), os_dev_get_user_private(), os_dev_set_user_private(), OS_ERROR_BAD_ARG_S, OS_ERROR_FAIL_S, OS_ERROR_NO_MEMORY_S, OS_ERROR_OK_S, scc_config_t::partition_size_bytes, and TRUE.
OS_DEV_OPEN | ( | shw_open | ) |
Handle open()
call from user.
References os_dev_open_return(), os_dev_set_user_private(), and OS_ERROR_OK_S.
OS_DEV_SHUTDOWN | ( | shw_shutdown | ) |
Prepare driver for exit.
This is called during rmmod
when the driver is unloading or when the kernel is shutting down.
Calls shw_cleanup() to do all work to undo anything that happened during initialization or while driver was running.
References os_dev_shutdown_return(), OS_ERROR_OK_S, and shw_cleanup().
static void process_hdr | ( | fsl_shw_uco_t * | user_ctx, | |
struct shw_req_header * | hdr | |||
) | [inline, static] |
Process header of user-mode request.
Mark header as User Mode request. Update UCO's flags and reference fields with current versions from the header.
user_ctx | Pointer to kernel version of UCO. | |
hdr | Pointer to common part of user request. |
References fsl_shw_uco_t::flags, FSL_UCO_USERMODE_USER, and fsl_shw_uco_t::user_ref.
Referenced by get_random().
static void shw_cleanup | ( | void | ) | [static] |
Prepare driver for shutdown.
Remove the driver registration.
References os_driver_remove_registration(), os_lock_deallocate(), reg_handle, shw_device_registered, and shw_queue_lock.
Referenced by OS_DEV_INIT(), and OS_DEV_SHUTDOWN().
static os_error_code shw_setup_user_driver_interaction | ( | void | ) | [static] |
Register the driver with the kernel as the driver for shw_major_node. Note that this value may be zero, in which case the major number will be assigned by the OS. shw_major_node is never modified.
The open(), ioctl(), and close() handles for the driver ned to be registered with the kernel. Upon success, shw_device_registered will be true;
References OS_DEV_CLOSE_REF(), OS_DEV_IOCTL_REF(), OS_DEV_MMAP_REF(), OS_DEV_OPEN_REF(), os_driver_add_registration(), os_driver_complete_registration(), os_driver_get_major(), os_driver_init_registration(), OS_ERROR_OK_S, OS_FN_CLOSE, OS_FN_IOCTL, OS_FN_MMAP, OS_FN_OPEN, reg_handle, shw_device_registered, SHW_DRIVER_NAME, shw_major_node, and TRUE.
Referenced by OS_DEV_INIT().
static void shw_user_callback | ( | fsl_shw_uco_t * | user_ctx | ) | [static] |
FSL SHW User callback function.
This function is set in the kernel version of the user context as the callback function when the user mode user wants a callback. Its job is to inform the user process that results (may) be available. It does this by sending a SIGUSR2 signal which is then caught by the user-mode FSL SHW library.
user_ctx | Kernel version of uco associated with the request. |
References os_send_signal().
Referenced by init_uco().
fsl_shw_pco_t cap [static] |
Initial value:
{ 1, 3, 2, 3, sizeof(pf_syms) / sizeof(fsl_shw_key_alg_t), pf_syms, sizeof(pf_modes) / sizeof(fsl_shw_sym_mode_t), pf_modes, sizeof(pf_hashes) / sizeof(fsl_shw_hash_alg_t), pf_hashes, { {0, 0, 0, 0} , {0, 0, 0, 0} , {0, 0, 0, 0} , {0, 0, 0, 0} , {0, 0, 0, 0} } , 0, 0, 0, 0, 0, {{0, 0} } , }
Referenced by run_user_wrap(), and run_wrap().
fsl_shw_hash_alg_t pf_hashes[] [static] |
Initial value:
{ }
fsl_shw_sym_mode_t pf_modes[] [static] |
Initial value:
{ }
fsl_shw_key_alg_t pf_syms[] [static] |
Initial value:
{ }
os_driver_reg_t reg_handle [static] |
OS-dependent handle used for registering user interface of a driver.
Referenced by OS_DEV_SHUTDOWN(), rng_test_setup_user_driver_interaction(), shw_cleanup(), and shw_setup_user_driver_interaction().
int shw_device_registered = 0 [static] |
Flag to know whether the driver has been associated with its user device node (e.g. /dev/shw).
Referenced by shw_cleanup(), and shw_setup_user_driver_interaction().
int shw_major_node = SHW_MAJOR_NODE [static] |
Major node (user/device interaction value) of this driver.
Referenced by shw_setup_user_driver_interaction().
os_lock_t shw_queue_lock = NULL |
This is the lock for all user request pools. H/W component drivers may also use it for their own work queues.
Referenced by fsl_shw_deregister_user(), fsl_shw_get_results(), OS_DEV_INIT(), SHW_ADD_USER(), shw_cleanup(), and SHW_REMOVE_USER().
Linked List of registered users of the API
Referenced by SHW_ADD_USER(), and SHW_REMOVE_USER().
© Freescale Semiconductor, Inc., 2007.
All rights reserved. Freescale Confidential Proprietary NDA Required |
![]() |