1

I have some sample code that I was editing in Visual Studio 2010 to encrypt and decrypt using DES. For some reason, when I compile the code i keep getting these two LNK2019 errors that are referring to the des_encrypt1() function and the des_set_key_checked() function. As seen in my code, I made sure to include the des.h file and that file lists the definitions for both of those functions. I am new to C so I am not sure if it is something simple that I am overlooking but any help would be greatly appreciated. I'm not sure how to correctly attach code here so sorry if the format looks weird but the bolded include below should say #include des.h.

#include <des.h>


#define ENC 1
#define DEC 0

//extern des_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc);

//void des_set_key_checked(const_des_block *key, des_key_schedule *schedule)



int main()
{

int k;
long    in[2];
static unsigned char cbc_key[8] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
des_key_schedule key;
//struct timeval start, end;
//double t1, t2, t3, t4;

if ((k = des_set_key_checked(&cbc_key,key)) != 0)
    printf("\nkey error\n");

in[0] = 3212314;
in[1] = 1231233;

printf("DES Clear Text: %ld%ld\n",in[0],in[1]);
//gettimeofday(&start, NULL);
//t1=start.tv_sec+(start.tv_usec/1000000.0);
des_encrypt1(in,key,ENC);
//gettimeofday(&end, NULL);
//t2=end.tv_sec+(end.tv_usec/1000000.0);
//printf("Time for Encryption\n", t2-t1);

printf("DES Encryption: %u%u\n",in[0],in[1]);
//gettimeofday(&start, NULL);
//t3=start.tv_sec+(start.tv_usec/1000000.0);
des_encrypt1(in,key,DEC);
//gettimeofday(&end, NULL);
//t4=end.tv_sec+(end.tv_usec/1000000.0);
//printf("Time for Decryption\n", t4-t3);
}
Joshua
  • 11
  • 2
  • You need to indent the code block by four spaces and also have a blank line above the start of the code block. Then it will be displayed correctly. – Daniel Rose Jan 21 '11 at 08:52

2 Answers2

0

you need to include des.h from openssl/

#include <openssl/des.h>
Yash
  • 1
0

If you are compiling the code as C++, but the header is written for C, you need to include it as follows:

extern "C" {
    #include "des.h"
}
Daniel Rose
  • 17,233
  • 9
  • 65
  • 88
  • Thanks for your help. That definitely got rid of the LNK errors, but now it is saying that des_key_scheduler is an undeclared identifier and that it believes it is missing a ';' before key (as in des_key_schedule key;) any ideas? – Joshua Jan 21 '11 at 09:12
  • 1
    you should probably use `struct des_key_schedule key;` not just `des_key_schedule key;` – nos Jan 21 '11 at 09:42
  • Thanks. That removed a lot of the undeclared identifier messages for 'key' but now it's complaining that key is using an undefined struct des_key_schedule. – Joshua Jan 21 '11 at 09:57
  • actually ignore that last part, i just figured out how to fix that error. Daniel Rose and nos, thanks so much for your help! – Joshua Jan 21 '11 at 09:59
  • is there any reason why this line (extern "C") would return this error (error C2059: syntax error: 'string')? – Joshua Jan 21 '11 at 10:06
  • @Joshua It's an error in C, not in C++, so perhaps you're compiling the code as C ? – nos Jan 21 '11 at 20:48