Hello,
> i'm trying to develop a simple application which will encrypt text
> file using triple des. actually i got the code from my friend, and
> he's using openssl 0.9.8a while i'm using 0.9.9b. i faced a problem
> when compiling the source code using borland... i'll always get the
> error msg 
> "[C++ Error] testDes.cpp(45): E2034 Cannot convert 'des_ks_struct
> ( *)[16]' to 'des_ks_struct *'"  and 
> "[C++ Error] testDes.cpp(45): E2342 Type mismatch in parameter
> 'ks1' (wanted 'des_ks_struct *', got 'des_ks_struct ( *)[16]')" 
> 
> can someone please help me? thanks a lot.
> 
> the source code is below:
This source code use ECB mode to encrypt disk file which is not
recommended.
Use CBC or other suggested mode for this encryption.
I do not know Borlad compiler but maybe two attached very simple
examples may be helpful.

After compiling des_enc.c you may decrypt his output for example with:

$ ./des_enc > enc.bin
$ openssl des-ede3-cbc -in enc.bin -K
000102030405060708090A0B0C0D0E0F1011121314151617 -iv 0001020304050607 -d

Best regards,
-- 
Marek Marcola <[EMAIL PROTECTED]>
#include <stdio.h>
#include <string.h>

#include <openssl/des.h>

int main(int argc, char *argv[])
{
	unsigned char key08[] = {0,1,2,3,4,5,6,7};
	unsigned char key16[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
	unsigned char key24[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
	unsigned char key32[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
	unsigned char iv[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

	unsigned char inbuf[1024]="\x25\x64\x6f\x61\xf3\x4b\x55\x86";
	unsigned char outbuf[1024];

	DES_key_schedule sch;
	DES_key_schedule sch2;
	DES_key_schedule sch3;

	memset(outbuf, 0, sizeof(outbuf));

	DES_set_key_unchecked((DES_cblock *)key24,&sch);
	DES_set_key_unchecked((DES_cblock *)(key24+8),&sch2);
	DES_set_key_unchecked((DES_cblock *)(key24+16),&sch3);

	DES_ede3_cbc_encrypt(inbuf, outbuf, 8, &sch, &sch2, &sch3, (DES_cblock *)iv, DES_DECRYPT);
//	DES_ncbc_encrypt(inbuf, outbuf, 8, &sch, (DES_cblock *)iv, DES_ENCRYPT);

	fwrite(outbuf, 1, 8, stdout);

	return(0);
}
#include <stdio.h>
#include <string.h>

#include <openssl/des.h>

int main(int argc, char *argv[])
{
	unsigned char key08[] = {0,1,2,3,4,5,6,7};
	unsigned char key16[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
	unsigned char key24[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
	unsigned char key32[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
	unsigned char iv[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

	unsigned char inbuf[1024]="abcdefg\x01";
	unsigned char outbuf[1024];

	DES_key_schedule sch;
	DES_key_schedule sch2;
	DES_key_schedule sch3;

	memset(outbuf, 0, sizeof(outbuf));

	DES_set_key_unchecked((DES_cblock *)key24,&sch);
	DES_set_key_unchecked((DES_cblock *)(key24+8),&sch2);
	DES_set_key_unchecked((DES_cblock *)(key24+16),&sch3);

	DES_ede3_cbc_encrypt(inbuf, outbuf, 8, &sch, &sch2, &sch3, (DES_cblock *)iv, DES_ENCRYPT);
//	DES_ncbc_encrypt(inbuf, outbuf, 8, &sch, (DES_cblock *)iv, DES_ENCRYPT);

	fwrite(outbuf, 1, 8, stdout);

	return(0);
}

Reply via email to