-
Notifications
You must be signed in to change notification settings - Fork 0
/
etausraw.c
83 lines (76 loc) · 3.14 KB
/
etausraw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* etausraw.c - random raw bit stream generator Version 1.0.0 */
/* Copyright (C) 2016 aquila62 at github.com */
/* This program is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU General Public License as */
/* published by the Free Software Foundation; either version 2 of */
/* the License, or (at your option) any later version. */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to: */
/* Free Software Foundation, Inc. */
/* 59 Temple Place - Suite 330 */
/* Boston, MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <malloc.h>
#include <time.h>
#include <sys/times.h>
#include "etaus.h"
/* write one million bytes to stdout */
void putblk(unsigned char *blk, int len)
{
int rslt;
rslt = write(1,blk,len);
if (rslt != len)
{
fprintf(stderr,"putblk: write error\n");
exit(1);
} /* write error */
} /* putblk */
int main(void)
{
unsigned int i; /* output block length counter */
unsigned char *p; /* pointer to the output block */
unsigned char *blk; /* output bit stream */
etfmt *et; /* etaus structure */
et = (etfmt *) etausinit();
/***************************************/
/* allocate memory for the output */
/* bit stream */
/***************************************/
blk = (unsigned char *) malloc(1048576 + 100);
if (blk == NULL)
{
fprintf(stderr,"main: out of memory "
"allocating blk\n");
exit(1);
} /* out of mem */
/***************************************/
/* point to the beginning of the output bit stream block */
p = (unsigned char *) blk;
i = 0; /* initialize the length of the output block */
/* the output bit stream is piped into a following program */
/* when the down stream program ends, this program ends */
while (1) /* infinite loop */
{
i++; /* counter for block length */
/* append a random byte to the end of the output block */
*p++ = (unsigned char) etauspwr(et,8);
if (i >= 1048576) /* if output block is filled */
{
putblk(blk,i); /* write output block to stdout */
i = 0; /* reset block length to zero */
/* point to beginning of output block */
p = (unsigned char *) blk;
} /* output filled block */
} /* for each random bit produced */
free(et->state);
free(et);
free(blk);
/* the compiler requires a return statement */
return(0); /* normal end of job */
} /* main */