Hi,

First off let me apologise if my code sytle and question are REALL lame, I've not done any C/C++ for a long time.   I've been trying to impliment a SHA (or even CBC_MAC) for a file which I have read into a char or byte buffer.  The problem is that this thing refuses point blank to compile under Linux (Mandrake 10.1, g++ --version is 3.41

I'm using  g++ -g -msse2 -pipe codetest.cpp -o a.out   where codetest.cpp is in the same folder as everything from the unzipped crypto++ libraries.

The code is:
--------------------
#define CRYPTOPP_CBCMAC_H
//#include "stdafx.h"
#include "seckey.h"
#include "secblock.h"
#include "pch.h"
#include "cryptlib.h"
#include "cbcmac.h"
#include "sha.h"
#include "hmac.h"
#include <iostream>
#include <fstream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "md5.h"
#include "filters.h"
#include "files.h"
#include "hex.h"
using namespace std;
using namespace CryptoPP;

int main()
{
    FILE* pinfile;            //Associates the pointer with a file to read in
    FILE* poutfile;            //and out
    FILE* keyfile;
    FILE* hashkey;
    byte * buffery;
    char * buffer2;
    char filein[32];
    long lSize;
    int x, y;
    int anykey;
    byte * thekey;
    byte keylength;

    cout << "To hash a file press 1 +  ENTER" <<std::endl;
    cin >> anykey;

    /*****************************
********
                 ENCRYPTION
    *************************************/
    if (anykey == 1)
    {
        cout << "What is the file to encrypt:" <<std::endl;
        cin >> filein;
       
        //Open the file and the key in read only mode
        pinfile = fopen ( filein , "rb" );
        if (pinfile==NULL) exit (1);
        hashkey = fopen ( "key.txt" , "rb" );
        if (hashkey==NULL) exit (1);

        // obtain file size.
        fseek (pinfile , 0 , SEEK_END);
        lSize = ftell (pinfile);
        rewind (pinfile);

        fseek (hashkey , 0 , SEEK_END);
        keylength = ftell (hashkey);
        rewind (hashkey);

        // DANGER WILL ROBINSON DANGER
        // allocate memory to contain the whole file.
        buffery = (byte*) malloc (lSize);
        buffer2 = (char*) malloc (8);
        thekey = (byte*) malloc(keylength);
        if (buffery == NULL) exit (2);

        // DANGER WILL ROBINSON DANGER
        // whole file copied into buffer.
        fread (buffery,1,lSize,pinfile);

    byte * bufferzz9;
    bufferzz9 = (byte*) malloc (2 * SHA::DIGESTSIZE);
   
      HMAC<SHA > mac;
      mac.SetKey(thekey, keylength);
      mac.Update(buffery, lSize);
      mac.Final(bufferzz9);

//TRIED WITH CBC_MAC No joy either
//CBC_MAC_Base<CBC_MAC>(thekey, keylength).CalculateDigest(bufferzz9, buffery, lSize);
//                                        )) or ) here?   
        // Clear up mess made
        fclose (pinfile);
        free (buffery);
        free (buffer2);

    }
    return 0;
}
----------

The error begins:


/home/dev/cryptopp521/seckey.h:145: undefined reference to `vtable for CryptoPP::HMAC_Base'
/home/dev/tmp/cclsTN2o.o(.gnu.linkonce.t._ZN8CryptoPP9HMAC_BaseD2Ev+0x17): In function `CryptoPP::HMAC_Base::~HMAC_Base()':
/home/dev/cryptopp521/JpegCoder2.cpp:93: undefined reference to `vtable for CryptoPP::HMAC_Base'
/home/dev/tmp/cclsTN2o.o(.gnu.linkonce.t._ZN8CryptoPP25SimpleKeyedTransformationINS_18HashTransformationEED2Ev+0xb): In function

And goes on for about 100 lines.

It seems tro be a linking issue as using  g++ -g -msse2 -pipe -c codetest.cpp -o a.out  produces no problems

How can I basically read in a file and generate a MAC for it.  I'd like to know both SHA and CBC_MAC really for education purposes.

Thanks

T Gecko

Reply via email to