User guide

68 MPC184/MPC185 Security Co-Processor Software User’s Guide MOTOROLA
PRELIMINARY—SUBJECT TO CHANGE WITHOUT NOTICE
Sample Code Sample Code
5 Sample Code
The following sections provide sample codes for DES and IPSec.
5.1 DES Sample
/* define the User Structure */
DES_LOADCTX_CRYPT_REQ desencReq;
.
.
.
/* fill the User Request structure with appropriate pointers */
desencReq.opId = DPD_TDES_CBC_ENCRYPT_SA_LDCTX_CRYPT ;
desencReq.channel = 0; /* dynamic channel */
desencReq.notify = (void*) notifyDes; /* callback function */
desencReq.notify_on_error = (void*) notifyDes; /* callback in case of
errors only */
desencReq.status = 0;
desencReq.ivBytes = 8; /* input iv length */
desencReq.ivData = iv_in; /* pointer to input iv */
desencReq.keyBytes = 24; /* key length */
desencReq.keyData = DesKey; /* pointer to key */
desencReq.inBytes = packet_length; /* data length */
desencReq.inData = DesData; /* pointer to data */
desencReq.outData = desEncResult; /* pointer to results */
desencReq.nextReq = 0; /* no descriptor chained */
/* call the driver */
status = Ioctl(device, IOCTL_PROC_REQ, &desencReq);
/* First Level Error Checking */
if (status != 0) {
.
.
}
.
.
.
void notifyDes (void)
{
/* Second Level Error Checking */
if (desencReq.status != 0) {
.
.
}
.
.
)