DES/3DES implementation

Hi All,

  I would like to know how to implement the DES/3DES and MACTriple DES in QNX, I would very appreciated for any source code.

   I use setkey() and encrypt() for a simple testing as following:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
	unsigned char i;
	unsigned char key[64];
	unsigned char blk[64];
	 
	for(i=0;i<64;i++)
	{
		if(i%2)
			key[i]=1;
		else
			key[i]=0;		
	}
	
	for(i=0;i<64;i++)
	{
		if(i%2)
			blk[i]=0;
		else
			blk[i]=1;		
	}
 	
 	printf("Plain:");
 	for(i=0;i<64;i++)
 		printf("%d ",blk[i]);
 	printf("\n");	
 	
 	setkey(key); 	
 	encrypt(blk,0);
 	
 	printf("Encry:");
 	for(i=0;i<64;i++)
 		printf("%d ",blk[i]);
 	printf("\n");
 	
 	setkey(key); 	
 	encrypt(blk,1);
 			
	printf("Decry:");
 	for(i=0;i<64;i++)
 		printf("%d ",blk[i]);
 	printf("\n");
	
	
	return EXIT_SUCCESS;
}

and the result as below:
Plain:1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
Encry:0 0 1 1 0 1 0 0 0 0 1 1 1 0 1 0 0 0 0 0 1 0 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 0 1 0 1 1 0 1 0 1 1 1 0 0 1 1 0 0 1 0 1 0
Decry:0 0 1 1 0 1 0 0 0 0 1 1 1 0 1 0 0 0 0 0 1 0 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 0 1 0 1 1 0 1 0 1 1 1 0 0 1 1 0 0 1 0 1 0

there is no decrypt implmented with encrypt() function.

Thanks a lot

Regards,

Due to the export restrictions, encryption library shipped has the decryption feature stripped. Thus the exported version of encrypt() does encoding but not decoding.

You could probably go to the Internet to find the source code of DES library and compile it for your own use, if the law in your country doesn’t forbid that.

Hi noc,
thanks a lot.
kindly please recommend me some useful website for DES library.

Regards,
Shilunz

No, I don’t have anything to remmend. Have you look at those open source project such as the crypt library in Linux, or search google?