beecryptgen.cpp

// $Id: beecryptgen.cpp,v 1.4 2002/04/07 18:44:47 erngui Exp $
//
//  Use the entropy gathering code in the BeeCrypt crypto
//  library (http://sourceforge.net/projects/beecrypt/) written 
//  by Bob Deblier of Virtual Unlimited to generate a data file 
//  for analysis. 
//
//  See the top-level readme.txt file for build instructions.
//  
//  -- Ernesto Guisado (erngui@acm.org)
//  

// start:wav
#include <fstream>
#include <iostream>
#include <windows.h>

typedef UINT32 uint32;

using namespace std;

int main(int argc, char* argv[])
{
  if (argc != 3) {
    cerr << "beecryptgen file size\n";
    return -1;
  }
  ofstream f(argv[1], ios::binary);
  if (!f) {
    cerr << "Cannot open " << argv[1] << endl;
    return -1;
  }
  enum { 
	N = 10240, 
	BYTES = N*sizeof(uint32) 
  };
  int size = atoi(argv[2])/BYTES;

  _putenv("BEECRYPT_ENTROPY=wavein");

  typedef int (*Entropy)(uint32*, int);
  HINSTANCE inst = LoadLibrary("beecrypt");
  if (inst != NULL) { 
    Entropy next = (Entropy)GetProcAddress(inst, "entropyGatherNext"); 
    if (next != 0) {
      uint32 chunk[N];
      for (int i=0; i<size; i++) {
        if (next(chunk, N)!= -1)
	      f.write((char*)chunk, sizeof(chunk));
      }
      FreeLibrary(inst); 
    } else {
      cerr << "beecrypt.dll corrupt?\n";
    }
  } else {
    cerr << "beecrypt.dll not found.\n";
  }

  return 0;
}
// end:wav