I am looking for sample code on how to encrypt a string with 3DES. I am using the following code that I got from the NEX_GenCRYPT_programming_guide.pdf:
void encryptdata(char *key1, char *key2, char *key3,
char *in, char *out, int len)
{
NGCkey64 convkey;
NGCdesctx ks1, ks2, ks3;
int i;
/* initialise context /
ngcDES_ConvKey((NGCkey56)key1, &convkey);
ngcDES_Init(&ks1, &convkey,0);
ngcDES_ConvKey((NGCkey56*)key2, &convkey);
ngcDES_Init(&ks2, &convkey,0);
ngcDES_ConvKey((NGCkey56*)key3, &convkey);
ngcDES_Init(&ks3, &convkey,0);
/* encrypt data (assuming len is multiple of 8) */
for (i=0; i<len; i+=8)
{
ngc3DES_ECB_Crypt(&ks1, &ks2, &ks3, in+i, out+i, NGC_DES_ENCRYPT);
}
}
void decryptdata(char *key1, char *key2, char *key3,
char *in, char *out, int len)
{
NGCkey64 convkey;
NGCdesctx ks1, ks2, ks3;
int i;
/* initialise context /
ngcDES_ConvKey((NGCkey56)key1, &convkey);
ngcDES_Init(&ks1, &convkey,0);
ngcDES_ConvKey((NGCkey56*)key2, &convkey);
ngcDES_Init(&ks2, &convkey,0);
ngcDES_ConvKey((NGCkey56*)key3, &convkey);
ngcDES_Init(&ks3, &convkey,0);
/* decrypt data (assuming len is multiple of 8) */
for (i=0; i<len; i+=8)
ngc3DES_ECB_Crypt(&ks1, &ks2, &ks3, in+i, out+i, NGC_DES_DECRYPT);
}
void adl_main ( adl_InitType_e InitType )
{
TRACE (( 1, “Embedded Application : Main” ));
char *out_1;
char *in_1;
in_1 = "hello123";
encryptdata("getBla92","geteee92","getrrr92",in_1,out_1,8);
adl_atSendResponse ( ADL_AT_UNS, out_1);
}
When I run the program on the Q2686 and start the application it runs up to this line:
/* encrypt data (assuming len is multiple of 8) */
for (i=0; i<len; i+=8)
{
ngc3DES_ECB_Crypt(&ks1, &ks2, &ks3, in+i, out+i, NGC_DES_ENCRYPT);
}
It then restarts, this then continues.
Can anyone help my on how to use 3DES, by telling me what I am doing wrong or giving me another example. The security plug in is enabled on the hardware.
Riaan Pieters
mail@cellremote.co.za