Results 1 to 6 of 6
  1. #1
    faceofdevil's Avatar
    Join Date
    Jul 2009
    Gender
    female
    Posts
    77
    Reputation
    9
    Thanks
    6

    [Help] typedef structure

    i've got a typedef struct built into a header file and im trying to link it 2 seperate .cpp files..


    crypt.cpp

    Code:
    #include "crypt.h"
    #define MAX_RC5_KEY				16
    
    RC5_32_KEY RC5_32_KEY_TABLE[MAX_RC5_KEY];
    
    BYTE SY_KEY_TABLE[16][4]=
    {
    	{ 0x17,0xb3,0x67,0xaa },	//0
    	{ 0x53,0xf2,0x74,0xb1 },	//1
    	{ 0x8c,0x72,0x59,0x32 },	//2
    	{ 0x98,0xea,0x55,0x29 },	//3
    	{ 0x4B,0x1C,0x15,0x11 },	//4
    	{ 0xE8,0x9B,0x3A,0x8A },	//5
    	{ 0x0F,0xAD,0x37,0x6C },	//6
    	{ 0xD9,0x64,0x28,0x5C },	//7
    	{ 0xB3,0xB7,0xEC,0x7B },	//8
    	{ 0x9C,0x13,0xFE,0xF5 },	//9
    	{ 0x5C,0x55,0x6A,0xD8 },	//10
    	{ 0x6C,0xA9,0xDB,0x64 },	//11
    	{ 0x5A,0xBE,0xF2,0xF6 },	//12
    	{ 0xA6,0x4D,0x8F,0xB9 },	//13
    	{ 0x67,0x9F,0x7D,0xF6 },	//14
    	{ 0xCA,0x6A,0xA9,0xEF },	//15
    };
    
    BYTE SY_RKEY_TABLE[16][4]=
    {
    	{ 0xC0,0x3C,0x06,0xEA },	//0
    	{ 0xB9,0x78,0xB3,0x45 },	//1
    	{ 0x88,0x48,0xC0,0x71 },	//2
    	{ 0x85,0x4C,0xB6,0xE7 },	//3
    	{ 0x98,0xAE,0xD9,0xBF },	//4
    	{ 0x2D,0x83,0x06,0x55 },	//5
    	{ 0x44,0x95,0xAF,0x99 },	//6
    	{ 0x43,0xC8,0x53,0x63 },	//7
    	{ 0x3B,0xB1,0x60,0x0B },	//8
    	{ 0x19,0x2D,0x57,0xC6 },	//9
    	{ 0x68,0xCC,0x56,0x3A },	//10
    	{ 0x5C,0xF8,0x90,0x4A },	//11
    	{ 0xA1,0x8A,0x0B,0x70 },	//12
    	{ 0x28,0x45,0x80,0xB1 },	//13
    	{ 0x71,0x9D,0x4A,0x80 },	//14
    	{ 0x54,0x1B,0x0F,0x9C },	//15
    };
    
    CCrypt::CCrypt( )
    {
    	RC5_32_KEY*   rc532Key  = RC5_32_KEY_TABLE;		//
    	unsigned char tiv1[ 4 ] = {'n','o','o','b'};	//
    	unsigned char tiv2[ 4 ] = {'n','o','o','b'};	//
    	DWORD         skey[ 2 ];						// 4Byte * 2  = 64bit
    
    	memset( RC5_32_KEY_TABLE, 0, sizeof(RC5_32_KEY_TABLE) );
    
    	for ( int i = 0; i < MAX_RC5_KEY; i++, rc532Key++ )
    	{
    		skey[ 0 ] = (*(DWORD*)(SY_RKEY_TABLE + i)) ^ (*(DWORD*)tiv1);
    		skey[ 1 ] = (*(DWORD*)(SY_RKEY_TABLE + i)) ^ (*(DWORD*)tiv2);
    
    		RC5_32_set_key( rc532Key, sizeof(skey), (unsigned char*)&skey, RC5_8_ROUNDS );
    	}
    	Log( MSG_INFO, "Key table has been created!" );
    }
    
    CCrypt::~CCrypt( )
    {
    }
    
    void CCrypt::Decrypt(BYTE* ptr, RC5_32_KEY key)
    {
    	
    	unsigned char tiv[8] = {'n','o','o','b','n','o','o','b'};
    	int           num    = 0;
    
    	LONG  decryptlen = ((CPacket*)ptr)->Size;
    	BYTE* decryptptr = ptr;
    
    	decryptlen -= PHLen;
    	decryptptr += PHLen;
    
    	if ( decryptlen > 0 )
    	{
    		RC5_32_cfb64_encrypt( decryptptr, decryptptr, decryptlen, &key, tiv, &num, RC5_DECRYPT );
    	}
    }
    
    void CCrypt::Encrypt(BYTE* ptr, RC5_32_KEY key)
    {
    	CPacket* pak;
    	unsigned char tiv[8] = {'n','o','o','b','n','o','o','b'};
    	int           num    = 0;
    
    	LONG  encryptlen = ((CPacket*)ptr)->Size;
    	BYTE* encryptptr = ptr;
    
    	encryptlen -= PHLen;
    	encryptptr += PHLen;
    
    	if ( encryptlen > 0 )
    	{
    		RC5_32_cfb64_encrypt( encryptptr, encryptptr, encryptlen, &key, tiv, &num, RC5_ENCRYPT);
    	}
    }
    crypt.h

    Code:
    #ifndef __CRYPT_
    #define __CRYPT_
    
    #include "rc5.h"
    
    class CCrypt
    {
    public:
    	CCrypt( );
    	~CCrypt( );
    
    	
    	void Decrypt( BYTE* ptr, RC5_32_KEY key );
    	void Encrypt(BYTE* ptr, RC5_32_KEY key);
    	
    	
    };
    Now here is my problem.


    main.cpp
    Code:
    unsigned char* buffer;
    Decrypt( buffer, RC5_32_KEY_TABLE[ 0 ] );
    now of course we get this error

    error C2065: 'RC5_32_KEY_TABLE' : undeclared identifier

    wich means theres no refence to it inside the .cpp

    how can i call the refence to 'RC5_32_KEY_TABLE' without calling it twice wich you cant do.

  2. #2
    -Raz0r-'s Avatar
    Join Date
    Aug 2010
    Gender
    male
    Location
    Australia
    Posts
    117
    Reputation
    15
    Thanks
    38
    My Mood
    Lurking
    RC5_32_KEY_TABLE doesn't exist in that context.
    You'll need to hint to the compiler/linker that it exists in another file. Look up the 'extern' keyword
    Languages: C, C++, x86 ASM, PHP, Lua

  3. #3
    faceofdevil's Avatar
    Join Date
    Jul 2009
    Gender
    female
    Posts
    77
    Reputation
    9
    Thanks
    6
    how would i go about extern a typedef a struct.

    Code:
    typedef struct rc5_key_st
    {
    	/* Number of rounds */
    	int rounds;
    	RC5_32_INT data[2*(RC5_16_ROUNDS+1)];
    } RC5_32_KEY;
    is it possible to extern
    Code:
     RC5_32_KEY RC5_32_KEY_TABLE[MAX_RC5_KEY];
    Last edited by faceofdevil; 12-15-2010 at 07:57 AM.

  4. #4
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    extern RC5_32_KEY RC5_32_KEY_TABLE[MAX_RC5_KEY]; ?
    Ah we-a blaze the fyah, make it bun dem!

  5. #5
    faceofdevil's Avatar
    Join Date
    Jul 2009
    Gender
    female
    Posts
    77
    Reputation
    9
    Thanks
    6
    1>crypt.obj : error LNK2001: unresolved external symbol "struct rc5_key_st * RC5_32_KEY_TABLE" (?RC5_32_KEY_TABLE@@3PAUrc5_key_st@@A)

  6. #6
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    new header(dfksfj.h)
    Code:
    #pragma once
    
    typedef struct rc5_key_st
    {
    	/* Number of rounds */
    	int rounds;
    	RC5_32_INT data[2*(RC5_16_ROUNDS+1)];
    } RC5_32_KEY;
    
    RC5_32_KEY RC5_32_KEY_TABLE[MAX_RC5_KEY];
    Whereever you need the RC5_32_KEY_TABLE:
    Code:
    #include "dfksfj.h"
    ...
    Ah we-a blaze the fyah, make it bun dem!