Hello,
> Really no help with that? I spend so much time on it and you are my last
> hope...
> 
> Thanks,
> Koza
> 
> 
> Koza wrote:
> > 
> > I'd like to use function des_encrypt1 and I have the following code: 
> > 
> > const_DES_cblock key= {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}; 
> > DES_key_schedule k; 
> > DES_set_key_unchecked(&key,&k); 
> > DES_LONG dataenc1[2]; 
> > dataenc1[0] = 0x01234567; 
> > dataenc1[1] = 0x89abcdef; 
> > DES_encrypt1(dataenc1,&k,1); 
> > 
> > but it doesn't work... instead of 8a5ae1f81ab8f2dd I receive
> > eb0b38b6de16165 
> > DES_ecb_encrypt works fine with that data (8a5ae1f81ab8f2dd is valid test
> > vector for key/plain set above)
> > Any idea how to use that function? 
This is data conversion problem, look at example.

Best regards,
-- 
Marek Marcola <[EMAIL PROTECTED]>
#include <openssl/des.h>

#define c2l(c,l)    (l =((DES_LONG)(*((c)++))), \
             l|=((DES_LONG)(*((c)++)))<< 8L, \
             l|=((DES_LONG)(*((c)++)))<<16L, \
             l|=((DES_LONG)(*((c)++)))<<24L)

#define l2c(l,c)    (*((c)++)=(unsigned char)(((l))&0xff), \
             *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
             *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
             *((c)++)=(unsigned char)(((l)>>24L)&0xff))


int main()
{
	char *in_data = "\x01\x23\x45\x67\x89\xab\xcd\xef";
	unsigned char *in = (unsigned char*)in_data;

	char out_data[8];
	unsigned char *out = (unsigned char*)out_data;

	const_DES_cblock key= {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}; 
	DES_key_schedule k; 
	DES_set_key_unchecked(&key,&k); 
	DES_LONG ll[2]; 
	DES_LONG l;

	int i;

	printf(" in = ");
	for(i=0; i<8; i++){
		printf("%02x ", in_data[i] & 0xFF);
	}
	printf("\n");

	c2l(in,l);
	ll[0] = l;
	c2l(in,l);
	ll[1] = l;

	printf(" in ll[0] = %08lx\n", ll[0]);
	printf(" in ll[1] = %08lx\n", ll[1]);
	
	DES_encrypt1(ll,&k,DES_ENCRYPT); 

	printf("out ll[0] = %08lx\n", ll[0]);
	printf("out ll[1] = %08lx\n", ll[1]);

	l = ll[0];
	l2c(l,out);
	l = ll[1];
	l2c(l,out);

	printf("out = ");
	for(i=0; i<8; i++){
		printf("%02x ", out_data[i] & 0xFF);
	}
	printf("\n");
	
	return(0);
}

Reply via email to