Main Page | Data Structures | File List | Data Fields | Globals

des_io.c File Reference


Detailed Description

Defines code used to use the DES hardware.

Author:
Andrew Roca
Code to support DES cryptographic operations as implemented by the DES core in the AXIS hardware. Supplies both access from user space and a possible kernel interface. The DES hardware is a limited resource so the code needs to queue operations at several stages adding to the complexity

#include "des_io.h"
#include "axis_pci.h"
#include "axis.h"

Include dependency graph for des_io.c:

Include dependency graph

Defines

#define NONCE_SIZE   8
#define NONCE_OFFSET_1   (0x38+CONTROL_OFFSET)
#define NONCE_OFFSET_2   (0x3C+CONTROL_OFFSET)
#define SECURITY_CONTROL_REGISTER   (0x14+CONTROL_OFFSET)
#define CLOCK_STOP   (1<<7)
#define VERIFY_OP   (1<<3)
#define USE_NONCE   (1<<15)
#define VERIFY_BIT   (1<<14)
#define HEBER_DES3_BLOCK_SIZE   8
#define HEBER_DES3_KEY_SIZE   24

Functions

void init_axis_des_hardware_key (struct axis_des_hardware_key *ptr, unsigned char *addr, unsigned char *reg, int index)
 Function to initalise hardware key structure prior to use.

void init_axis_des_hardware_channel (struct axis_des_hardware_channel *ptr, unsigned char *reg, unsigned char *buffer, unsigned index)
 Initalise a DES hardware channel structure.

axis_des_keycreate_des_key (void)
 Initalises a DES key structure.

crypto_statecreate_crypto_state (struct axis_pci_device_entry *device)
 creates and initalises a crypto state(session) structure.

void delete_crypto_state (struct crypto_state *ptr)
 delete a crypto state(session) structure.

void delete_des_key (struct axis_des_key *key)
 deletes a des key

axis_des_opcreate_des_op (struct axis_des_key *key, struct axis_pci_device_entry *dev)
 creates a DES op structure

void delete_des_op (struct axis_des_op *op)
 deletes a DES operation

int search_for_free_hardware_key (struct axis_pci_device_entry *device)
 Search for free hardware key slot.

int get_des_hardware_key (struct axis_pci_device_entry *device, struct axis_des_key *key)
 Allocates a 3DES key channel.

int search_for_free_des_channel (struct axis_pci_device_entry *device)
 Linear search for free DES channel.

int get_des_channel (struct axis_des_op *op)
 Finds a free 3DES channel for a 3DES op.

void write_key (unsigned char *address, unsigned char *key)
 write key

int load_des_key (struct axis_des_op *op)
 Moves a key into hardware.

int issue_des_operation (struct axis_des_op *op)
 Sends a DES op to hardware and starts it.

int free_des_channel (struct axis_des_op *op)
 Frees a DES channel so another OP can use it.

int free_des_hardware_key (struct axis_des_op *op)
 make DES key storage available

void init_axis_des_core (struct axis_pci_device_entry *device)
 Performs initalisation of DES structures.

int dispatch_des_op (struct axis_des_op *op)
 Performs a single DES operation.

void do_cryto_op (CRYPTO_OP *user_op, struct crypto_state *state)
 Interprets user crypto requests.

void do_security_op (CRYPTO_OP *user_op, struct crypto_state *state)
 Handles user access to security API.

int axis_crypto_ioctl (struct inode *inode_ptr, struct file *file_ptr, unsigned int type,unsigned long args)
 Provides an interface to allow user land to the DES hardware.

int axis_crypto_open (struct inode *inode_ptr, struct file *file_ptr)
 open function for 3DES crypto supper

int axis_crypto_release (struct inode *inode_ptr, struct file *file_ptr)
 Called by kernel in response to a process closing a device.

int heber_des3_setkey (void *ctx, const u8 *key, unsigned int keylen, u32 *flags)
 Creates crypto state so we can export crypto service to kernel crypto api.

void heber_des3_encrypt (void *ctx, u8 *dst, const u8 *src)
 Encryption call back for kernel crypto API.

void heber_des3_decrypt (void *ctx, u8 *dst, const u8 *src)
 Decryption call back for kernel crypto API.


Variables

crypto_alg heber_des3_alg
file_operations crypto_file_operations
 Define a file operations structure for cryptographic devices.


Define Documentation

#define CLOCK_STOP   (1<<7)
 

#define HEBER_DES3_BLOCK_SIZE   8
 

#define HEBER_DES3_KEY_SIZE   24
 

#define NONCE_OFFSET_1   (0x38+CONTROL_OFFSET)
 

#define NONCE_OFFSET_2   (0x3C+CONTROL_OFFSET)
 

#define NONCE_SIZE   8
 

#define SECURITY_CONTROL_REGISTER   (0x14+CONTROL_OFFSET)
 

#define USE_NONCE   (1<<15)
 

#define VERIFY_BIT   (1<<14)
 

#define VERIFY_OP   (1<<3)
 


Function Documentation

int axis_crypto_ioctl struct inode *  inode_ptr,
struct file *  file_ptr,
unsigned int  type,
unsigned long  args
[static]
 

Provides an interface to allow user land to the DES hardware.

Parameters:
inode_ptr - devices inode
file_ptr - pointer to kernel file structure for open device
type- identifies the IOCTL operation requested
args- unspecified parameter supplied by user program meaning depends on type
Returns:
0 on success error number otherwise

To allow user applications options other then read / write the driver support IOCTL calls the type constants are defined in axis.h DES ops are manipulated via this IOCTL call

Here is the call graph for this function:

int axis_crypto_open struct inode *  inode_ptr,
struct file *  file_ptr
[static]
 

open function for 3DES crypto supper

Parameters:
inode_ptr - pointer to inode structure the kernel will associate with this instance
file_ptr - pointer to the file structure the kernel uses to track this open instance
Returns:
0 on sucess error code otherwise

This open is called from the general open after its worked out what type of subdevice user space has requested opens the crypto device and creates and associates a crypto state with it

Here is the call graph for this function:

int axis_crypto_release struct inode *  inode_ptr,
struct file *  file_ptr
[static]
 

Called by kernel in response to a process closing a device.

Parameters:
inode_ptr 
file_ptr 
Returns:
0 on success

Called by kernel if user application closes device, needs to destroy crypto state associated with open state

Here is the call graph for this function:

struct crypto_state * create_crypto_state struct axis_pci_device_entry device  )  [inline, static]
 

creates and initalises a crypto state(session) structure.

Parameters:
device - hardware master structure
Returns:
pointer to new crypto_state

Creates and zeros a new crypto_state structure

struct axis_des_key * create_des_key void   )  [inline, static]
 

Initalises a DES key structure.

Returns:
ptr to new key

Creates and zeros a new axis_des_key structure

struct axis_des_op * create_des_op struct axis_des_key key,
struct axis_pci_device_entry dev
[inline, static]
 

creates a DES op structure

Parameters:
key - key to use
dev - hardware master structure
Returns:
new axis_des_op structure

Creates a new DES op structure. Used to submit 3DES operations to the 3DES core code

void delete_crypto_state struct crypto_state ptr  )  [inline, static]
 

delete a crypto state(session) structure.

Parameters:
ptr - pointer to cryto_state structure to delete
Returns:
none

Deletes a crypto state structure if structure owns a hardware key it frees it

void delete_des_key struct axis_des_key key  )  [inline, static]
 

deletes a des key

Parameters:
key - key to delete
Returns:
none

Deletes a crypto state structure if structure owns a hardware key it frees it

void delete_des_op struct axis_des_op op  )  [inline, static]
 

deletes a DES operation

Parameters:
op - structure to delete
Returns:
none

deletes a DES operation

int dispatch_des_op struct axis_des_op op  ) 
 

Performs a single DES operation.

Parameters:
op - des op structure to perform
Returns:
zero on success

Performs a des operation, it gets a key slot loads the key into the slot decrypting it if nessary and then gets a des slot loads the data to be operated on into and issue the command. The operation waits for an interrupt to signal comletion returns the transformed data and frees the DES slot marking the key slot as available for reuse.

Here is the call graph for this function:

void do_cryto_op CRYPTO_OP user_op,
struct crypto_state state
[inline, static]
 

Interprets user crypto requests.

Parameters:
user_op - the user operation as despatched from user land
state - the crypto state associated with the open file handle
Returns:
none

Copies data to and from user space and cuts it up into nice easy slices and performs a cryto operation on each slice

Here is the call graph for this function:

void do_security_op CRYPTO_OP user_op,
struct crypto_state state
[inline, static]
 

Handles user access to security API.

Parameters:
user_op - the user operation as despatched from user land
state - the crypto state associated with the open file handle
Returns:
none

Allows a user space application to access the (encrypted) FPGA Nonce value. The user application submits the encrypted nonce to a trusted third party that decypts the nonce modifies it and returns the encrypted new value. User space then submits this value and we have to issue it to the FPGA

Here is the call graph for this function:

int free_des_channel struct axis_des_op op  )  [inline, static]
 

Frees a DES channel so another OP can use it.

Parameters:
op- DES op that owns the channel
Returns:
zero on success

Free FPGA DES channel after we have finished

int free_des_hardware_key struct axis_des_op op  )  [inline, static]
 

make DES key storage available

Parameters:
op - 3DES op that owns hardware key
Returns:
zero on success

make DES key storage available

int get_des_channel struct axis_des_op op  )  [inline, static]
 

Finds a free 3DES channel for a 3DES op.

Parameters:
op - DES op that wants channel
Returns:
none

Search for a free DES channel queue if one not available

Here is the call graph for this function:

int get_des_hardware_key struct axis_pci_device_entry device,
struct axis_des_key key
[inline, static]
 

Allocates a 3DES key channel.

Parameters:
device - hardware master structure
key - software key that hardware key is to be associated with
Returns:
free keys index -1 if failed

Need to acquire a hardware key channel for the DES op to proceed. Function acquires and locks key prior to returning it. These are a finite resource and the DES operation may need to queue until one becomes free.

Here is the call graph for this function:

void heber_des3_decrypt void *  ctx,
u8 *  dst,
const u8 *  src
[static]
 

Decryption call back for kernel crypto API.

Parameters:
ctx - user data from crypto api
dst - where to write encrypted data
src - source data
Returns:
none

Define a crypto algorithm for the Heber DES core This is a lousy way of using the DES core but it is compatible with the current kernel crypto system. The cryto system only calls the algorithm one block at a time rather than block at once. This makes using the system in cbc mode easier but I suspect the cost of setting up the DES transaction will exceed the benefits of using hardware.

Here is the call graph for this function:

void heber_des3_encrypt void *  ctx,
u8 *  dst,
const u8 *  src
[static]
 

Encryption call back for kernel crypto API.

Parameters:
ctx - user data from crypto api
dst - where to write encrypted data
src - source data
Returns:
none

Define a crypto algorithm for the Heber DES core This is a lousy way of using the DES core but it is compatible with the current kernel crypto system. The cryto system only calls the algorithm one block at a time rather than block at once. This makes using the system in cbc mode easier but I suspect the cost of setting up the DES transaction will exceed the benefits of using hardware.

Here is the call graph for this function:

int heber_des3_setkey void *  ctx,
const u8 *  key,
unsigned int  keylen,
u32 *  flags
[static]
 

Creates crypto state so we can export crypto service to kernel crypto api.

Parameters:
ctx -
key -
keylen- 
flags -
Returns:
zero on success

Converts a crypto api key to one suitable for 3DES stuff

Here is the call graph for this function:

void init_axis_des_core struct axis_pci_device_entry device  ) 
 

Performs initalisation of DES structures.

Parameters:
device - hardware master structure
Returns:
none

Performs initalisation of the DES structures in the master structure

Here is the call graph for this function:

void init_axis_des_hardware_channel struct axis_des_hardware_channel ptr,
unsigned char *  reg,
unsigned char *  buffer,
unsigned  index
 

Initalise a DES hardware channel structure.

Parameters:
ptr - structure to initalise
reg - address of control register associated with DES channel
buffer - address of channels storage in Axis device
index - DES channels id number
Returns:
none

Initalise a DES hardware channel structure, called as part of the initialisation of a new instance of Axis hardware

void init_axis_des_hardware_key struct axis_des_hardware_key ptr,
unsigned char *  addr,
unsigned char *  reg,
int  index
 

Function to initalise hardware key structure prior to use.

Parameters:
ptr - structure to initalise
addr - address of key in Axis device
reg - address of control register associated with key
index - keys id number
Returns:
none

Function to initalise hardware key structure prior to use, called as part of the initialisation of a new instance of Axis hardware

int issue_des_operation struct axis_des_op op  )  [inline, static]
 

Sends a DES op to hardware and starts it.

Parameters:
op - the operation to perform
Returns:
zero on success

Despatch data and command to DES hardware wait for interrupt to signal completion

int load_des_key struct axis_des_op op  )  [inline, static]
 

Moves a key into hardware.

Parameters:
op - DES operation to setup
Returns:
0 on success

Load Key into key storage allow for keys being encrypted

Here is the call graph for this function:

int search_for_free_des_channel struct axis_pci_device_entry device  )  [inline, static]
 

Linear search for free DES channel.

Parameters:
device - hardware master structure
Returns:
index of channel found, -1 if failed

Simple search for an unused DES channel only call after setting channel lock

int search_for_free_hardware_key struct axis_pci_device_entry device  )  [inline, static]
 

Search for free hardware key slot.

Parameters:
device - hardware master structure
Returns:
free keys index

Simple search for a free hardware key slot. This needs to be called from code protected by the des_key_lock semaphore present in the axis_pci_device master structure. Otherwise a race condition is likely.

void write_key unsigned char *  address,
unsigned char *  key
[inline, static]
 

write key

Parameters:
address - target
key - source
Returns:
none

Sort out any possible endian problems with key


Variable Documentation

struct file_operations crypto_file_operations
 

Initial value:

{

    ioctl:           axis_crypto_ioctl,
    open:            axis_crypto_open,
    release:         axis_crypto_release,
}
Define a file operations structure for cryptographic devices.

struct crypto_alg heber_des3_alg [static]
 

Initial value:

 {
        .cra_name               =       "heber_des3",
        .cra_flags              =       CRYPTO_ALG_TYPE_CIPHER,
        .cra_blocksize          =        8 ,
        .cra_ctxsize            =       sizeof(struct crypto_state),
        .cra_module             =       THIS_MODULE,
        .cra_list               =       LIST_HEAD_INIT(heber_des3_alg.cra_list),
        .cra_u                  =       { .cipher = {
        .cia_min_keysize        =        24 ,
        .cia_max_keysize        =        24 ,
        .cia_setkey             =       heber_des3_setkey,
        .cia_encrypt            =       heber_des3_encrypt,
        .cia_decrypt            =       heber_des3_decrypt } }
}


Generated on Fri Jan 28 12:36:15 2005 for Axis Kernel Driver by doxygen 1.3.6