x917gen.cpp
// $Id: x917gen.cpp,v 1.3 2002/04/07 18:44:49 erngui Exp $
//
// Use Wei Dai's Crypto++ (http://www.eskimo.com/~weidai/cryptlib.html)
// to generate a data files using X9.17, but using AES (Rijndael) as
// encryption cipher instead of DES.
//
// The seed and random key are generated by calculating a SHA256
// hash of a user-provided passphrase.
//
// See the top-level readme.txt file for build instructions.
//
// -- Ernesto Guisado (erngui@acm.org)
//
#include "crypto42/aes.h"
#include "crypto42/rng.h"
#include "crypto42/sha.h"
using namespace CryptoPP;
int main(int argc, char* argv[])
{
if (argc != 3) {
printf("usage: x917gen file size\n");
return 0;
}
int size = atoi(argv[2]);
FILE *f = fopen(argv[1], "wb");
// convert passphrase into 256 bit hash
fprintf(stdout, "Enter passphrase:\n");
char pwd[1025] = { 0 };
fgets(pwd, sizeof(pwd), stdin);
byte digest[SHA256::DIGESTSIZE];
SHA256().CalculateDigest(digest, (byte*)pwd, strlen(pwd));
// setup X9.17 with AES as encryption
AESEncryption* enc = new AESEncryption(digest,
SHA256::DIGESTSIZE/2);
X917RNG rng(enc, digest+SHA256::DIGESTSIZE/2);
// produce prng output
for (int i = 0; i < size; i++) {
byte b = rng.GenerateByte();
fwrite(&b, 1, 1, f);
}
fclose(f);
return 0;
}