使用Openssl库的编译问题 [英] using Openssl library compilation issue

查看:109
本文介绍了使用Openssl库的编译问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好编码员,

我正在尝试将一些DES加密功能从C ++ NewcamD项目转换为.NET,但是我需要一些帮助,因为它正在使用特定的DES转换,并且我想对其进行正确的测试. C ++使用额外的带有三重DES加密的OPENSSL库.我不需要任何套接字来进行测试,但是我需要加密/解密测试,因此我尝试用C ++创建简单的加密/解密项目,但编译失败,并出现一些错误:


错误5错误LNK2019:在函数专用:无效__thiscall cTripleDes :: SetOddParity(unsigned char *)"中引用了未解析的外部符号_DES_set_odd_parity(?SetOddParity @ cTripleDes @@ AAEXPAE @ Z)cTripleDes.obj NewCamD_test

错误6错误LNK2019:在函数受保护:void __thiscall cTripleDes :: ScheduleKey(void)"中引用了未解析的外部符号_DES_key_sched(?ScheduleKey @ cTripleDes @@ IAEXXZ)cTripleDes.obj NewCamD_test

错误7错误LNK2019:在函数保护:int __thiscall cTripleDes :: PadMessage(unsigned char *,int)"中引用了未解析的外部符号_DES_random_key(?PadMessage @ cTripleDes @@ IAEHPAEH @ Z)cTripleDes.obj NewCamD_test

错误8错误LNK2019:在函数保护:int __thiscall cTripleDes :: PadMessage(unsigned char *,int)"中引用了未解析的外部符号____security_cookie(?PadMessage @ cTripleDes @@ IAEHPAEH @ Z)cTripleDes.obj NewCamD_test

错误9错误LNK2019:在功能受保护的:int __thiscall cTripleDes :: PadMessage(unsigned char *,int)"中引用了未解析的外部符号@__ security_check_cookie @ 4"(?PadMessage @ cTripleDes @@ IAEHPAEH @ Z)cTripleDes.obj NewCamD_test

错误10错误LNK2019:函数_time cTripleDes.obj NewCamD_test
中引用了无法解析的外部符号__imp___time64
错误11错误LNK2019:在函数保护:未签名的字符const * __thiscall cTripleDes :: Encrypt(unsigned char const *,int,unsigned char *)"中引用的未解析的外部符号_DES_ede3_cbc_encrypt. obj NewCamD_test

错误12致命错误LNK1120:7个未解决的外部组件C:\ PROJECTS \ C ++ \ NewCamD_test \ Debug \ NewCamD_test.exe NewCamD_test



有人可以帮助我吗?

谢谢




我的C ++(版本9.0)代码-头文件:
cc.hh

//extern "C" {
//    #include "des.h"
//}


#define L_CC          6
#define L_CC_CORE     LCLASS(L_CC,0x2)
#define L_CC_LOGIN    LCLASS(L_CC,0x4)
#define L_CC_ECM      LCLASS(L_CC,0x8)
#define L_CC_EMM      LCLASS(L_CC,0x10)
#define L_CC_CAMD     LCLASS(L_CC,0x20)
#define L_CC_CAMD35   LCLASS(L_CC,0x40)
#define L_CC_CAMDEXTR LCLASS(L_CC,0x80)
#define L_CC_RDGD     LCLASS(L_CC,0x100)
#define L_CC_NEWCAMD  LCLASS(L_CC,0x200)
#define L_CC_GBOX     LCLASS(L_CC,0x400)

#define L_CC_ALL      LALL(L_CC_GBOX)



mish.h

unsigned char XorSum(const unsigned char *mem, int len);



stdafx.h

#pragma一次

#include"targetver.h"

#include <   stdio.h  > 
#include <   tchar.h  >  



targetver.h

#pragma once

// The following macros define the minimum required platform.  The minimum required platform
// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 
// your application.  The macros work by enabling all features available on platform versions up to and 
// including the version specified.

// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef _WIN32_WINNT            // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600     // Change this to the appropriate value to target other versions of Windows.
#endif



源文件:
cTripleDes.cpp

#include"stdafx.h"
#include <   iostream  > 
#include <   cstdio  > 
#include <   windows.h  > 
#include <   time.h  > 
#include <   process.h  > 
#include <   stdlib.h  > 
#include <   malloc.h  > 
//#include"cTripleDes.h"

#include <   stdio.h  > 
#include <   string.h  > 
#include <   stdlib.h  > 
//#include <   crypt.h  > 
//#include <   byteswap.h  > 

//#include <   vdr/thread.h  > ; 

#include"cc.h"
//#include"network.h"
#include"misc.h"
//#include"parse.h"

#include <   openssl/des.h  > 

#定义CWS_NETMSGSIZE 240

//-cTripleDes --------------------------------------------- ------------------

类cTripleDes {
私人的:
  DES_key_schedule ks1;
  DES_key_schedule ks2;
  //
  void SetOddParity(unsigned char * key); //密钥必须为16个字节!
受保护的:
  unsigned char desKey [16];
  //
  void ScheduleKey(void);
  int PadMessage(unsigned char * data,int len);
  void Expand(unsigned char * expanded,const unsigned char * normal); //14个字节的按键输入,16个字节的扩展输出
  无效Decrypt(unsigned char * data,int len);
  const unsigned char * Encrypt(const unsigned char * data,int len,unsigned char * crypt);
  };

无效cTripleDes :: SetOddParity(unsigned char * key)
{
  DES_set_odd_parity((DES_cblock *)& key [0]); //在两个键上设置奇数奇偶校验
  DES_set_odd_parity((DES_cblock *)& key [8]); //
}

无效cTripleDes :: ScheduleKey(void)
{
  DES_key_sched((DES_cblock *)& desKey [0],& ks1);
  DES_key_sched((DES_cblock *)& desKey [8],& ks2);
}

void cTripleDes :: Expand(unsigned char * expand,const unsigned char * normal)
{
  expand [0] =普通[0]& 0xfe;
  expand [1] =((normal [0] <  <   7)  |    (normal [1]    > > 1))& 0xfe;
  expand [2] =((normal [1] <  <   6)  |    (normal [2]    > > 2))& 0xfe;
  expand [3] =((normal [2] <  <   5)  |    (普通[3]    > > 3))& 0xfe;
  expand [4] =((normal [3] <  <   4)  |    (normal [4]    > > 4))& 0xfe;
  expand [5] =((normal [4] <  <   3)  |    (普通[5]    > > 5))& 0xfe;
  expand [6] =((normal [5] <  <   2)  |    (normal [6]    > > 6))& 0xfe;
  expand [7] =普通[6] <  <     1;  
 
      expand [8]       =  &   0xfe;  
 
      expand [9]       =  <<   7)     (normal [8]    > > 1))& 0xfe;
  expand [10] =((normal [8] <  <   6)    |    (普通[9]    > > 2))& 0xfe;
  expand [11] =((normal [9] <  <   5)    |    (普通[10]    > > 3))& 0xfe;
  expand [12] =((normal [10] <  <   4)  |    (normal [11]    > > 4))& 0xfe;
  expand [13] =((normal [11] <  <   3)  |    (普通[12]    > > 5))& 0xfe;
  expand [14] =((normal [12] <  <   2)  |    (普通[13]    > > 6))& 0xfe;
  expand [15] =普通[13] <  <     1;  
 
      SetOddParity(expand);  
 
 }  
 
 
 
  int     cTripleDes :: PadMessage(unsigned     char     *数据,    int   len) 
  { 
 
      DES_cblock     padBytes;  
 
     未签名    char     noPadBytes;  
 
 
 
      noPadBytes     =  (8      -    1)       8))       8;  
 
      if(len + noPadBytes + 1    >  = CWS_NETMSGSIZE-8){
    /* printf(L_CC_NEWCAMD,"cTripleDes :: PadMessage中的消息溢出"); */
      printf("cTripleDes :: PadMessage中的消息溢出");
    返回-1;
    }

  srand(time(NULL)); //确保随机数生成器已初始化
  DES_random_key((DES_cblock *)padBytes);
  memcpy(data + len,padBytes,noPadBytes); len + = noPadBytes;
  data [len] = XorSum(data + 2,len-2);
  返回len + 1;
}

const unsigned char * cTripleDes :: Encrypt(const unsigned char * data,int len,unsigned char * crypt)
{
  DES_cblock ivec;
  DES_random_key((DES_cblock *)ivec);
  memcpy(crypt + len,ivec,sizeof(ivec));
  DES_ede2_cbc_encrypt(data + 2,crypt + 2,len-2,& ks1,& ks2,(DES_cblock *)ivec,DES_ENCRYPT);
  返回地穴;
}

void cTripleDes :: Decrypt(unsigned char * data,int len)
{
  if((len-2)%8 ||(len-2)<   16)    { 
 
         //printf(L_CC_NEWCAMD,警告: 加密   数据   大小   不匹配);  
 
              printf( 警告: 加密 数据   大小 不匹配");  
 
         返回;  
 
         }  
 
      DES_cblock     ivec;  
 
      len-  =   sizeof(ivec);   memcpy(ivec,    data + len,     sizeof(ivec));  
 
      DES_ede2_cbc_encrypt(data + 2,data + 2,len-2,& ks1,& ks2,(DES_cblock     *)ivec,DES_DECRYPT) ;  
 
 }  
 
 
 
 
 
 //未签名    char     XorSum(const         * mem     int     len) 
 
 //{ 
 
 //     未签名    char   cs   0;
 
 //      while(len  >  0){cs ^ = * mem ++; len--; }
//返回cs;
//} 



misc.cpp

#include " 
#include " 

未签名的字符 XorSum( const  unsigned  char  *内存, int  len)
{
  unsigned 字符 cs =  0 ;
   while (len> 0){cs ^ = * mem ++; len--; }
  返回 cs;
} 



stdafx.cpp

//stdafx.cpp:仅包含标准的源文件包括
//NewCamD_test.pch将是预编译的头
//stdafx.obj将包含预编译的类型信息

#include " 

//TODO:在STDAFX.H中 中引用您需要的任何其他标头
// 不是 在此文件中 


NewcamD_Test.cpp(主控制台文件)

 //  NewCamD_test.cpp:定义控制台应用程序的入口点.
//  

#include " 
#include< iostream>
使用 命名空间 std;

 int  _tmain( int  argc,_TCHAR * argv [])
{
     int  hr;
    printf(" ,hr);
    系统(" );
    返回  0 ;
} 




要求:
http://207.44.152.197/vdr-sc-0.8.5.tar.gz [ 链接进行转换];
OpenSSL( http://www.openssl.org/ [链接])


谢谢大卫,
该问题出现在我无法为OpenSSL配置的ActivePerl中.但是我确实发现在使用选项1将它们添加到项目中之后,提供的链接和错误列表上的lib文件现在似乎已经缩小了范围.

错误4错误LNK2019:在函数受保护:未签名的字符const * __thiscall cTripleDes :: Encrypt(unsigned char const *,int,unsigned char *)"中引用的未解析的外部符号___security_cookie(?Encrypt @ cTripleDes @@ IAEPBEPBEHPAE @ Z)cTripleDes. obj NewCamD_test

错误5错误LNK2019:在功能受保护的:unsigned char const * __thiscall cTripleDes :: Encrypt(unsigned char const *,int,unsigned char *)"中引用了未解析的外部符号@__ security_check_cookie @ 4"(?Encrypt @ cTripleDes @@ IAEPBEPBEHPAE @ Z )cTripleDes.obj NewCamD_test

错误6致命错误LNK1120:2个未解决的外部组件C:\ PROJECTS \ C ++ \ NewCamD_test \ Debug \ NewCamD_test.exe 1 NewCamD_test

解决方案

您确定要链接到OpenSSL库吗?这些未解析的外部符号是OpenSSL函数...

选项1:
您需要将OpenSSL库添加到项目链接程序依赖项中:
连结器->输入->其他依赖项

选项2:
或者,您可以将其添加到您的cTripleDes.cpp文件中:
#pragma comment(lib,"ssleay32.lib")
#pragma comment(lib,"libeay32.lib")

如果使用选项2,请确保将这些lib文件添加到lib路径中的目录中.您可能应该使用选项1 ...,以便学习如何在项目中正确设置lib路径.

如果您没有OpenSSL库,请下载它们: http://www.openssl.org/related/binaries.html [^ ]

另外...请确保使用正确的运行时库 [ ^ ].从OpenSSL站点下载的库将包含每个运行时的库.

最好的祝福,
-大卫·德劳恩(David Delaune)


Hello coders,

I am trying to convert few DES encryption functions from C++ NewcamD project to .NET but I need some help as it is using specific DES convertion and I want test it properly. C++ uses extra OPENSSL library with Triple DES encryption. I don''t need any sockets for testing but I need encryption/decryption testing so I''ve tried to create simple encryption/decryption project in C++ but it fails on compilation with some errors:


Error 5 error LNK2019: unresolved external symbol _DES_set_odd_parity referenced in function "private: void __thiscall cTripleDes::SetOddParity(unsigned char *)" (?SetOddParity@cTripleDes@@AAEXPAE@Z) cTripleDes.obj NewCamD_test

Error 6 error LNK2019: unresolved external symbol _DES_key_sched referenced in function "protected: void __thiscall cTripleDes::ScheduleKey(void)" (?ScheduleKey@cTripleDes@@IAEXXZ) cTripleDes.obj NewCamD_test

Error 7 error LNK2019: unresolved external symbol _DES_random_key referenced in function "protected: int __thiscall cTripleDes::PadMessage(unsigned char *,int)" (?PadMessage@cTripleDes@@IAEHPAEH@Z) cTripleDes.obj NewCamD_test

Error 8 error LNK2019: unresolved external symbol ___security_cookie referenced in function "protected: int __thiscall cTripleDes::PadMessage(unsigned char *,int)" (?PadMessage@cTripleDes@@IAEHPAEH@Z) cTripleDes.obj NewCamD_test

Error 9 error LNK2019: unresolved external symbol @__security_check_cookie@4 referenced in function "protected: int __thiscall cTripleDes::PadMessage(unsigned char *,int)" (?PadMessage@cTripleDes@@IAEHPAEH@Z) cTripleDes.obj NewCamD_test

Error 10 error LNK2019: unresolved external symbol __imp___time64 referenced in function _time cTripleDes.obj NewCamD_test

Error 11 error LNK2019: unresolved external symbol _DES_ede3_cbc_encrypt referenced in function "protected: unsigned char const * __thiscall cTripleDes::Encrypt(unsigned char const *,int,unsigned char *)" (?Encrypt@cTripleDes@@IAEPBEPBEHPAE@Z) cTripleDes.obj NewCamD_test

Error 12 fatal error LNK1120: 7 unresolved externals C:\PROJECTS\C++\NewCamD_test\Debug\NewCamD_test.exe NewCamD_test



Does anyone could help me?

Thanks




MY C++ (ver 9.0) CODE - HEADER FILES:
cc.hh

//extern "C" {
//    #include "des.h"
//}


#define L_CC          6
#define L_CC_CORE     LCLASS(L_CC,0x2)
#define L_CC_LOGIN    LCLASS(L_CC,0x4)
#define L_CC_ECM      LCLASS(L_CC,0x8)
#define L_CC_EMM      LCLASS(L_CC,0x10)
#define L_CC_CAMD     LCLASS(L_CC,0x20)
#define L_CC_CAMD35   LCLASS(L_CC,0x40)
#define L_CC_CAMDEXTR LCLASS(L_CC,0x80)
#define L_CC_RDGD     LCLASS(L_CC,0x100)
#define L_CC_NEWCAMD  LCLASS(L_CC,0x200)
#define L_CC_GBOX     LCLASS(L_CC,0x400)

#define L_CC_ALL      LALL(L_CC_GBOX)



mish.h

unsigned char XorSum(const unsigned char *mem, int len);



stdafx.h

#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>



targetver.h

#pragma once

// The following macros define the minimum required platform.  The minimum required platform
// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 
// your application.  The macros work by enabling all features available on platform versions up to and 
// including the version specified.

// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef _WIN32_WINNT            // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600     // Change this to the appropriate value to target other versions of Windows.
#endif



SOURCE FILES:
cTripleDes.cpp

#include "stdafx.h"
#include <iostream>
#include <cstdio>
#include <windows.h>
#include <time.h>
#include <process.h>
#include <stdlib.h>
#include <malloc.h>
//#include "cTripleDes.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <crypt.h>
//#include <byteswap.h>

//#include <vdr/thread.h>

#include "cc.h"
//#include "network.h"
#include "misc.h"
//#include "parse.h"

#include <openssl/des.h>

#define CWS_NETMSGSIZE 240

// -- cTripleDes ---------------------------------------------------------------

class cTripleDes {
private:
  DES_key_schedule ks1;
  DES_key_schedule ks2;
  //
  void SetOddParity(unsigned char *key); // key must be 16 bytes!
protected:
  unsigned char desKey[16];
  //
  void ScheduleKey(void);
  int PadMessage(unsigned char *data, int len);
  void Expand(unsigned char *expanded, const unsigned char *normal); // 14 byte key input, 16 byte expanded output
  void Decrypt(unsigned char *data, int len);
  const unsigned char *Encrypt(const unsigned char *data, int len, unsigned char *crypt);
  };

void cTripleDes::SetOddParity(unsigned char *key)
{
  DES_set_odd_parity((DES_cblock *)&key[0]); // set odd parity on both keys
  DES_set_odd_parity((DES_cblock *)&key[8]); //
}

void cTripleDes::ScheduleKey(void)
{
  DES_key_sched((DES_cblock *)&desKey[0],&ks1);
  DES_key_sched((DES_cblock *)&desKey[8],&ks2);
}

void cTripleDes::Expand(unsigned char *expand, const unsigned char *normal)
{
  expand[0]  =   normal[0] & 0xfe;
  expand[1]  = ((normal[0] << 7) | (normal[1] >> 1)) & 0xfe;
  expand[2]  = ((normal[1] << 6) | (normal[2] >> 2)) & 0xfe;
  expand[3]  = ((normal[2] << 5) | (normal[3] >> 3)) & 0xfe;
  expand[4]  = ((normal[3] << 4) | (normal[4] >> 4)) & 0xfe;
  expand[5]  = ((normal[4] << 3) | (normal[5] >> 5)) & 0xfe;
  expand[6]  = ((normal[5] << 2) | (normal[6] >> 6)) & 0xfe;
  expand[7]  =   normal[6] << 1;

  expand[8]  =   normal[7] & 0xfe;

  expand[9]  = ((normal[7] << 7)  | (normal[8] >> 1)) & 0xfe;
  expand[10] = ((normal[8] << 6)  | (normal[9] >> 2)) & 0xfe;
  expand[11] = ((normal[9] << 5)  | (normal[10] >> 3)) & 0xfe;
  expand[12] = ((normal[10] << 4) | (normal[11] >> 4)) & 0xfe;
  expand[13] = ((normal[11] << 3) | (normal[12] >> 5)) & 0xfe;
  expand[14] = ((normal[12] << 2) | (normal[13] >> 6)) & 0xfe;
  expand[15] =   normal[13] << 1;

  SetOddParity(expand);

}



int cTripleDes::PadMessage(unsigned char *data, int len)

{

  DES_cblock padBytes;

  unsigned char noPadBytes;



  noPadBytes = (8 - ((len - 1) % 8)) % 8;

  if(len+noPadBytes+1 >= CWS_NETMSGSIZE-8) {
    /*printf(L_CC_NEWCAMD,"message overflow in cTripleDes::PadMessage");*/
      printf("message overflow in cTripleDes::PadMessage");
    return -1;
    }

  srand(time(NULL)); // make sure the random generator is initialized
  DES_random_key((DES_cblock *)padBytes);
  memcpy(data+len,padBytes,noPadBytes); len+=noPadBytes;
  data[len]=XorSum(data+2,len-2);
  return len+1;
}

const unsigned char *cTripleDes::Encrypt(const unsigned char *data, int len, unsigned char *crypt)
{
  DES_cblock ivec;
  DES_random_key((DES_cblock *)ivec);
  memcpy(crypt+len,ivec,sizeof(ivec));
  DES_ede2_cbc_encrypt(data+2,crypt+2,len-2,&ks1,&ks2,(DES_cblock *)ivec,DES_ENCRYPT);
  return crypt;
}

void cTripleDes::Decrypt(unsigned char *data, int len)
{
  if((len-2) % 8 || (len-2)<16) {

    //printf(L_CC_NEWCAMD,"warning: encrypted data size mismatch");

      printf("warning: encrypted data size mismatch");

    return;

    }

  DES_cblock ivec;

  len-=sizeof(ivec); memcpy(ivec, data+len, sizeof(ivec));

  DES_ede2_cbc_encrypt(data+2,data+2,len-2,&ks1,&ks2,(DES_cblock *)ivec,DES_DECRYPT);

}





//unsigned char XorSum(const unsigned char *mem, int len)

//{

//  unsigned char cs=0;

//  while(len>0) { cs ^= *mem++; len--; }
//  return cs;
//}



misc.cpp

#include "stdafx.h"
#include "misc.h"

unsigned char XorSum(const unsigned char *mem, int len)
{
  unsigned char cs=0;
  while(len>0) { cs ^= *mem++; len--; }
  return cs;
}



stdafx.cpp

// stdafx.cpp : source file that includes just the standard includes
// NewCamD_test.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file




NewcamD_Test.cpp (main console file)

// NewCamD_test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    int hr;
    printf("\nCannot put author info: %x\n", hr );
    system("pause");
    return 0;
}




Requirements:
http://207.44.152.197/vdr-sc-0.8.5.tar.gz[link];
OpenSSL (http://www.openssl.org/[link])


Thanks David,
The problem appears in ActivePerl which I am unable to configure for OpenSSL. But I did found lib files on provided link and error list now seems to be narrowed down after adding them to the project using Option 1:


Error 4 error LNK2019: unresolved external symbol ___security_cookie referenced in function "protected: unsigned char const * __thiscall cTripleDes::Encrypt(unsigned char const *,int,unsigned char *)" (?Encrypt@cTripleDes@@IAEPBEPBEHPAE@Z) cTripleDes.obj NewCamD_test

Error 5 error LNK2019: unresolved external symbol @__security_check_cookie@4 referenced in function "protected: unsigned char const * __thiscall cTripleDes::Encrypt(unsigned char const *,int,unsigned char *)" (?Encrypt@cTripleDes@@IAEPBEPBEHPAE@Z) cTripleDes.obj NewCamD_test

Error 6 fatal error LNK1120: 2 unresolved externals C:\PROJECTS\C++\NewCamD_test\Debug\NewCamD_test.exe 1 NewCamD_test

解决方案

Are you sure that you are linking with the OpenSSL library? Those unresolved external symbols are OpenSSL functions...

Option 1:
You need to add the OpenSSL libs to your project linker dependencies:
Linker -> Input -> Additional Dependencies

Option 2:
Alternatively you could add this to your cTripleDes.cpp file:
#pragma comment(lib, "ssleay32.lib")
#pragma comment(lib, "libeay32.lib")

If you use option 2 make sure that you add those lib files to the directory in your lib path. You should probably use option 1... so you learn how to correctly setup lib paths within your projects.

If you do not have the OpenSSL libraries then download them: http://www.openssl.org/related/binaries.html[^]

Also... make sure that you use the correct Run-Time Library[^]. The libs downloaded from the OpenSSL site will contain a library for each run-time.

Best Wishes,
-David Delaune


这篇关于使用Openssl库的编译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆