I promise this is my last lame question if I can get this annoy CBC_MAC to work...

Using the kindly provided
g++ -o a.out -g -msse2 -pipe JpegCoder2.cpp -L. -lcryptopp

The code compiles with just the HMAC<SHA stuff  indeed it runs fine and as expected, but CBC_MAC throws the following:

JpegCoder2.cpp: In function `int main()':
JpegCoder2.cpp:123: error: `CBC_MAC' undeclared (first use this function)
JpegCoder2.cpp:123: error: (Each undeclared identifier is reported only once for each function it appears in.)
JpegCoder2.cpp:123: error: expected primary-_expression_ before '>' token
JpegCoder2.cpp:123: error: `cbcmac' undeclared (first use this function)
JpegCoder2.cpp:125: error: `TestFilter' undeclared (first use this function)


Any ideas?




-------code-----------
#define CRYPTOPP_CBCMAC_H

#include "seckey.h"
#include "secblock.h"
#include "pch.h"
#include <iostream>
#include <fstream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "base32.h"
#include "base64.h"
#include "cbcmac.h"
#include "cryptlib.h"
#include "des.h"
#include "files.h"
#include "filters.h"
#include "hex.h"
#include "hmac.h"
#include "md5.h"
#include "modes.h"
#include "rijndael.h"
#include "sha.h"
#include "validate.h"

//#include "stdafx.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 ENTER" <<std::endl;
    //cin >> anykey;
    anykey =1;
    /*************************************
                 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);
        fread (thekey,1,lSize,hashkey);

    //************WORKS****************
    byte * bufferzz9;
    bufferzz9 = (byte*) malloc (2 * SHA::DIGESTSIZE);

       HMAC<SHA > mac;
       mac.SetKey(thekey, keylength);
       mac.Update(buffery, lSize);
       mac.Final(bufferzz9);
       cout<<"HMAC<SHA: "<<bufferzz9<<std::endl;
    //************WORKS****************
   
          
   
  bool pass;
  bool fail;

// Copies from validat1.cpp wont compile
        const byte plain[] = {    // "7654321 Now is the time for "
            0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20,
            0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
            0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20,
            0x66, 0x6f, 0x72, 0x20};
        const byte mac1[] = {    // from FIPS 113
            0xf1, 0xd3, 0x0f, 0x68, 0x49, 0x31, 0x2c, 0xa4};
        const byte mac2[] = {    // generated with Crypto++
            0x35, 0x80, 0xC5, 0xC4, 0x6B, 0x81, 0x24, 0xE2};
           
        CBC_MAC<DES> cbcmac(thekey);
        HashFilter cbcmacFilter(cbcmac);
        fail = !TestFilter(cbcmacFilter, plain, sizeof(plain), mac1, sizeof(mac1));
        pass = pass && !fail;

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



Reply via email to