The size is mandatory when creating a file but optional when verifying
it, unless \-\-entire is specified. If \fBSIZE\fR not specified when
writing-then-verifying, it is as if \fB\-\-entire\fR was specified.
+.PP
+A fixed default seed is used if no seed or seed file is specified.
.SH OPTIONS
.TP
.B --seed\fR, \fB-s \fISEED
Specifies the random seed to use.
Optional.
.TP
+.B --seed-file\fR, \fB-S \fISEED-FILE
+Specifies wehre the random seed should be read from. The
+first \fISEED-LENGTH\fR bytes will be used, or the whole file
+if it is shorter.
+.TP
+.B --seed-length\fR, \fB-L \fISEED-LENGTH
+Specifies the (maximum) seed length in bytes.
+Optional; default is 2048.
+.TP
.B --both\fR, \fB-b
Selects both mode.
\fIPATH\fR will be filled with \fISIZE\fR psuedo-random bytes and
#include <sys/stat.h>
#include "Arcfour.h"
+#define DEFAULT_SEED_LENGTH 2048;
+
// Command line options
const struct option opts[] = {
{ "seed", required_argument, 0, 's' },
+ { "seed-file", required_argument, 0, 'S' },
+ { "seed-length", required_argument, 0, 'L' },
{ "both", no_argument, 0, 'b' },
{ "verify", no_argument, 0, 'v' },
{ "create", no_argument, 0, 'c' },
" vbig [--seed SEED] --verify|--create PATH [SIZE]\n"
"\n"
"Options:\n"
- " --seed, -s Specify random seed\n"
+ " --seed, -s Specify random seed as string\n"
+ " --seed-file, -S Read random seed from (start of) this file\n"
+ " --seed-length, -L Set (maximum) seed length to read from file\n"
" --verify, -v Verify that PATH contains the expected contents\n"
" --create, -c Create PATH with psuedo-random contents\n"
" --flush, -f Flush cache\n"
static long long execute(mode_type mode, bool entire, const char *show);
static const char default_seed[] = "hexapodia as the key insight";
-static const void *seed;
+static void *seed;
static size_t seedlen;
+static const char *seedpath;
static const char *path;
static bool entireopt = false;
static bool flush = false;
int main(int argc, char **argv) {
mode_type mode = BOTH;
int n;
- while((n = getopt_long(argc, argv, "+s:vcefhV", opts, 0)) >= 0) {
+ char *ep;
+ while((n = getopt_long(argc, argv, "+s:S:L:vcefhV", opts, 0)) >= 0) {
switch(n) {
case 's': seed = optarg; seedlen = strlen(optarg); break;
+ case 'S': seedpath = optarg; break;
+ case 'L':
+ seedlen = strtoul(optarg,&ep,0);
+ if(ep==optarg || *ep) fatal(0, "bad number for -S");
+ break;
case 'b': mode = BOTH; break;
case 'v': mode = VERIFY; break;
case 'c': mode = CREATE; break;
if(argc < (mode == VERIFY ? 1 : 2))
fatal(0, "insufficient arguments");
}
+ if(seed && seedpath)
+ fatal(0, "both --seed and --seed-file specified");
+ if(seedpath) {
+ if(!seedlen)
+ seedlen = DEFAULT_SEED_LENGTH;
+ FILE *seedfile = fopen(seedpath, "rb");
+ if(!seedfile)
+ fatal(errno, "%s", seedpath);
+ seed = malloc(seedlen);
+ if(!seed)
+ fatal(errno, "allocate seed");
+ seedlen = fread(seed, 1, seedlen, seedfile);
+ if(ferror(seedfile))
+ fatal(errno, "read %s", seedpath);
+ fclose(seedfile);
+ }
if (!seed) {
- seed = default_seed;
+ seed = (void*)default_seed;
seedlen = sizeof(default_seed)-1;
}
path = argv[0];