Merge pull request #46 from manuel-domke/master

cleanup on the tests and --help returns with rc=0
This commit is contained in:
Bill
2018-03-01 17:43:15 -08:00
committed by GitHub
19 changed files with 311 additions and 21 deletions

View File

@@ -1,6 +1,15 @@
GIT_VERSION := $(shell git --no-pager describe --tags --always)
GIT_COMMIT := $(shell git rev-parse --verify HEAD)
GIT_DATE := $(firstword $(shell git --no-pager show --date=iso-strict --format="%ad" --name-only))
BUILD_DATE := $(shell date --iso=seconds)
PREFIX = $(DESTDIR)/usr/local
CFLAGS = -Wall -Wextra -Werror -std=c99 -O3 -I Keccak -I /usr/include/libftdi1
CFLAGS = -Wall -Wextra -Werror -std=c99 -O3 -I Keccak -I /usr/include/libftdi1 \
-DGIT_VERSION=\"$(GIT_VERSION)\"\
-DGIT_COMMIT=\"$(GIT_COMMIT)\"\
-DGIT_DATE=\"$(GIT_DATE)\"\
-DBUILD_DATE=\"$(BUILD_DATE)\"
FOUND = $(shell ldconfig -p | grep --silent libftdi.so && echo found)
ifeq ($(FOUND), found)

View File

@@ -0,0 +1,9 @@
post_install() {
systemctl enable infnoise
systemctl restart systemd-udevd
}
pre_remove() {
systemctl disable infnoise
systemctl restart systemd-udevd
}

View File

@@ -0,0 +1,21 @@
# Maintainer: Manuel Domke <info@13-37.org>
pkgname=infnoise
pkgdesc='Infinite Noise TRNG'
license=('open')
url='https://github.com/manuel-domke/infnoise'
depends=('libftdi-compat')
makedepends=()
source=('git+https://github.com/manuel-domke/infnoise.git')
md5sums=('SKIP')
install='INSTALL'
build() {
cd "${srcdir}/infnoise/software/"
make
}
package() {
install -Dvm755 "${srcdir}/infnoise/software/infnoise" "${pkgdir}/usr/bin/infnoise"
install -Dvm644 "${srcdir}/infnoise/software/init_scripts/75-infnoise.rules" "${pkgdir}/etc/udev/rules.d/75-infnoise.rules"
install -Dvm644 "${srcdir}/infnoise/software/init_scripts/infnoise.conf.systemd" "${pkgdir}/etc/infnoise.conf"
install -Dvm644 "${srcdir}/infnoise/software/init_scripts/infnoise.service.bin" "${pkgdir}/etc/systemd/system/infnoise.service"
}

View File

@@ -0,0 +1,21 @@
The scripts need to be run from the software directory like this:
```$ build-scripts/build.sh x86```
and can create packages of the following types:
- DEB (Debian, Ubuntu, Raspbian)
- RPM (CentOS, Fedora)
- ArchLinux
The packages get signed afterwards and made available as Github releases
and via the apt repository described in software/README.
During the build the GitHub release and version information are compiled into the binary.
```
$ infnoise --version
GIT VERSION - 0.2.2
GIT COMMIT - b428787161f7c759c70c081621ffe43f24ca73b1
GIT DATE - 2018-03-01T23:43:26+01:00
BUILD DATE - 2018-03-01T23:50:33+01:00
```

View File

@@ -0,0 +1,31 @@
#!/bin/bash
VERSION=`git --no-pager describe --tags --always | cut -d'-' -f1`
PKGREL=`git --no-pager describe --tags --always | cut -d'-' -f2`
if [ $VERSION == $PKGREL ]; then # this is a release
PKGREL=0
fi
# x86_64
mkdir -p x86_64
cd x86_64
cp ../build-scripts/PKGBUILD.arch PKGBUILD
cp ../build-scripts/INSTALL.arch INSTALL
echo "pkgver=$VERSION" >> PKGBUILD
echo "pkgrel=$PKGREL" >> PKGBUILD
echo "arch=('x86_64')" >> PKGBUILD
ls -lah
makepkg -f --sign --key 975DC25C4E730A3C
cd ..
# x86_64
mkdir -p x86
cd x86
cp ../build-scripts/PKGBUILD.arch PKGBUILD
cp ../build-scripts/INSTALL.arch INSTALL
echo "pkgver=$VERSION" >> PKGBUILD
echo "pkgrel=$PKGREL" >> PKGBUILD
echo "arch=('i686')" >> PKGBUILD
makechrootpkg -r /x86 -U jenkins -- --sign --key 975DC25C4E730A3C

View File

@@ -0,0 +1,24 @@
#!/bin/bash
VERSION=`git --no-pager describe --tags --always | cut -d'-' -f1`
RELEASE=`git --no-pager describe --tags --always | cut -d'-' -f2`
if [ $VERSION == $RELEASE ]; then # this is a release
RELEASE=0
fi
ARCH=$2
PATH=$PATH:/sbin/
mkdir -p SOURCES
tar -czf SOURCES/infnoise.tar.gz . --exclude="SOURCES"
mkdir -p BUILD SPECS RPMS SRPMS
cp build-scripts/infnoise.spec SPECS
sed -i -- 's/__VERSION__/'$VERSION'/g' SPECS/infnoise.spec
sed -i -- 's/__RELEASE__/'$RELEASE'/g' SPECS/infnoise.spec
rpmbuild --define "_topdir `pwd`" -ba SPECS/infnoise.spec

36
software/build-scripts/build.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/bin/bash
ARCH=$1
VERSION=`git --no-pager describe --tags --always`
PATH=$PATH:/sbin/
make clean
make
rm -rf build
mkdir -p build/DEBIAN
cp build-scripts/control.debian.$ARCH build/DEBIAN/control
cp build-scripts/infnoise.postinst build/DEBIAN/postinst
chmod 775 build/DEBIAN/postinst
echo "Version: $VERSION" >> build/DEBIAN/control
mkdir -p build/usr/sbin/
mkdir -p build/etc/udev/rules.d/
mkdir -p build/etc/systemd/system/
cp infnoise build/usr/sbin/
cp init_scripts/infnoise.conf.systemd build/etc/infnoise.conf
cp init_scripts/75-infnoise.rules build/etc/udev/rules.d/75-infnoise.rules
cp init_scripts/infnoise.service.sbin build/etc/systemd/system/infnoise.service
if [ ! -e build/usr/sbin/infnoise ] ; then
echo "$2 binary missing"
exit 1;
fi
# debuild -b -uc -us
dpkg -b build/ infnoise_${VERSION}_${ARCH}.deb
#debbuild -uc -us
rm -r build

View File

@@ -0,0 +1 @@
Version: v0.2.1

View File

@@ -0,0 +1,9 @@
Package: infnoise
Architecture: amd64
Essential: no
Section: security
Priority: optional
Depends: libftdi1
Maintainer: Manuel Domke
Installed-Size: 12K
Description: Infinite Noise TRNG driver.

View File

@@ -0,0 +1,9 @@
Package: infnoise
Architecture: armhf
Essential: no
Section: security
Priority: optional
Depends: libftdi1
Maintainer: Manuel Domke
Installed-Size: 12K
Description: Infinite Noise TRNG driver.

View File

@@ -0,0 +1,9 @@
Package: infnoise
Architecture: i386
Essential: no
Section: security
Priority: optional
Depends: libftdi1
Maintainer: Manuel Domke
Installed-Size: 12K
Description: Infinite Noise TRNG driver.

View File

@@ -0,0 +1,7 @@
#!/bin/sh
systemctl daemon-reload
systemctl enable infnoise
#service infnoise start
service udev reload

View File

@@ -0,0 +1,37 @@
Name: infnoise
Version: __VERSION__
Release: __RELEASE__
Summary: Infinite Noise TRNG
Group: Applications/Security
License: GPL
URL: https://github.com/manuel-domke/infnoise
Vendor: 13-37.org
Source: infnoise.tar.gz
Prefix: %{_prefix}
Packager: Manuel Domke
BuildRoot: %{_tmppath}/%{name}-root
%description
%prep
tar -xzf ../SOURCES/infnoise.tar.gz
%build
make
%install
#make DESTDIR=$RPM_BUILD_ROOT install
install -Dvm755 "infnoise" "$RPM_BUILD_ROOT/usr/bin/infnoise"
install -Dvm644 "init_scripts/infnoise.conf.systemd" "$RPM_BUILD_ROOT/etc/infnoise.conf"
install -Dvm644 "init_scripts/75-infnoise.rules" "$RPM_BUILD_ROOT/usr/lib/udev/rules.d/75-infnoise.rules"
install -Dvm644 "init_scripts/infnoise.service.bin" "$RPM_BUILD_ROOT/usr/lib/systemd/system/infnoise.service"
%clean
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%{_bindir}/infnoise
/etc/infnoise.conf
%{_prefix}/lib/udev/rules.d/75-infnoise.rules
%{_prefix}/lib/systemd/system/infnoise.service

View File

@@ -187,7 +187,6 @@ static bool initializeUSB(struct ftdi_context *ftdic, char **message, char *seri
} else {
// serial specified
rc = ftdi_usb_open_desc(ftdic, INFNOISE_VENDOR_ID, INFNOISE_PRODUCT_ID, INFNOISE_DESCRIPTION, serial);
if (rc < 0) {
if(!isSuperUser()) {
*message = "Can't find Infinite Noise Multiplier. Try running as super user?\n";
@@ -241,7 +240,8 @@ static void initOpts(struct opt_struct *opts) {
opts->noOutput =
opts->listDevices =
opts->raw = false;
opts->help = false;
opts->none = false;
opts->pidFileName =
opts->serial = NULL;
}
@@ -299,7 +299,17 @@ int main(int argc, char **argv)
opts.daemon = true;
} else if(!strcmp(argv[xArg], "--list-devices")) {
opts.listDevices = true;
} else if(!strcmp(argv[xArg], "--version") || !strcmp(argv[xArg], "-v")) {
opts.version = true;
} else if(!strcmp(argv[xArg], "--help") || !strcmp(argv[xArg], "-h")) {
opts.help = true;
} else {
opts.help = true;
opts.none = true;
}
}
if (opts.help) {
fputs("Usage: infnoise [options]\n"
"Options are:\n"
" --debug - turn on some debug output\n"
@@ -311,11 +321,17 @@ int main(int argc, char **argv)
" --pidfile <file> - write process ID to file\n"
" --daemon - run in the background\n"
" --serial <serial> - use specified device\n"
" --list-devices - list available devices\n", stderr);
" --list-devices - list available devices\n"
" --version - show version information\n"
" --help - this help output\n", stdout);
if (opts.none) {
return 1;
} else {
return 0;
}
}
// read environment variables, not overriding command line options
if (opts.serial == NULL) {
if (getenv("INFNOISE_SERIAL") != NULL) {
@@ -347,6 +363,14 @@ int main(int argc, char **argv)
opts.outputMultiplier = 2u; // Don't throw away entropy when writing to /dev/random unless told to do so
}
if (opts.version) {
printf("GIT VERSION - %s\n", GIT_VERSION);
printf("GIT COMMIT - %s\n", GIT_COMMIT);
printf("GIT DATE - %s\n", GIT_DATE);
printf("BUILD DATE - %s\n", BUILD_DATE);
return 0;
}
if (opts.listDevices) {
listUSBDevices(&ftdic);
return 0;

View File

@@ -38,7 +38,10 @@ struct opt_struct {
bool devRandom; // Feed /dev/random?
bool noOutput; // Supress output?
bool listDevices; // List possible USB-devices?
bool help; // Show help
bool none; // set to true when no valid arguments where detected
bool raw; // No whitening?
bool version; // Show version
char *pidFileName; // Name of optional PID-file
char *serial; // Name of selected device
};

View File

@@ -22,7 +22,7 @@ resulting in 100.000 FIPS blocks with 20.000 bit each - and took two weeks.
| Multiplier/Mode | raw | failed blocks (SHA-3) | failed blocks /dev/random |
|-----------------|------|--------------|--------------|
| 0 | 9999 | 70 (0,07 %) | 81 (0,08 %) |
| 0 | 99999| 70 (0,07 %) | 81 (0,08 %) |
| 1 | - | 78 (0,08 %) | 73 (0,07 %) |
| 10 | - | 87 (0,09 %) | 89 (0,09 %) |
| 100 | - | 87 (0,09 %) | 95 (0,1 %) |
@@ -44,7 +44,6 @@ Make sure you have the following tools installed:
- python (numpy, matplotlib)
- infnoise driver
In the header of the script, you can define the test parameters:
```
declare -a TEST_KBYTES=('25000')

View File

@@ -2,9 +2,13 @@
import numpy as np
import matplotlib.pyplot as plt
import sys
from matplotlib import cm
filename='infnoise.bin'
if sys.argv[1]:
filename=sys.argv[1]
else:
filename='infnoise.bin'
nx = 1000
ny = 1000
@@ -25,4 +29,4 @@ cbar = plt.colorbar(cax, ticks=[255, 127, 0])
cbar.ax.set_yticklabels(['255', '127', '0'])
plt.savefig(filename + '-colormap.png')
plt.show()
plt.show()

View File

@@ -2,8 +2,13 @@
import matplotlib.pyplot as plt
import numpy as np
import sys
if sys.argv[1]:
filename=sys.argv[1]
else:
filename='infnoise.bin'
filename='infnoise.bin'
bp = np.dtype([('byte1',np.uint8),('byte2',np.uint8)]) # 'struct' byte pairs

View File

@@ -13,6 +13,47 @@ ENT=1
DIEHARDER=1
GRAPHS=1
function checkCommand {
$1 $2 >/dev/null
if [ $? -ne 0 ]; then
echo "$1 not installed. Exiting.."
exit 1
fi
}
function checkPythonModule {
python -c "import $1" >/dev/null
if [ $? -ne 0 ]; then
echo "python module $1 not installed. Exiting.."
exit 1
fi
}
function makePlots {
python plots/colormap.py $1 &
python plots/scatterplot.py $1 &
sleep 3
mv results/data/$1-colormap.png results/plots/
mv results/data/$1-scatter.png results/plots/
}
checkCommand "pv" "-h"
checkCommand "infnoise" "-h"
if [ $RNGTEST -eq 1 ] ; then
checkCommand "rngtest" "--help"
fi
if [ $ENT -eq 1 ] ; then
checkCommand "ent" "-u"
fi
if [ $DIEHARDER -eq 1 ] ; then
checkCommand "dieharder"
fi
if [ $GRAPHS -eq 1 ] ; then
checkCommand "python" "-h"
checkPythonModule "numpy"
checkPythonModule "matplotlib"
fi
mkdir -p results/data
mkdir -p results/plots
@@ -32,10 +73,7 @@ do
dieharder -a -f results/data/raw-$kbytes\K.out > results/raw-$kbytes\K-dieharder.txt
fi
if [ $GRAPHS -eq 1 ] ; then
python plots/colormap.py results/data/raw-$kbytes\K.out &
python plots/scatterplot.py results/data/raw-$kbytes\K.out &
mv results/data/raw-$kbytes\K.out-colormap.png results/plots/
mv results/data/raw-$kbytes\K.out-scatter.png results/plots/
makePlots "results/data/raw-$kbytes\K.out"
fi
echo "---"
@@ -55,10 +93,7 @@ do
dieharder -a -f results/data/whitened-$multiplier-$kbytes\K.out > results/whitened-$multiplier-$kbytes\K-dieharder.txt
fi
if [ $GRAPHS -eq 1 ] ; then
python plots/colormap.py results/data/whitened-$multiplier-$kbytes\K.out &
python plots/scatterplot.py results/data/whitened-$multiplier-$kbytes\K.out &
mv results/data/whitened-$multiplier-$kbytes\K.out-colormap.png results/plots/
mv results/data/whitened-$multiplier-$kbytes\K.out-scatter.png results/plots/
makePlots "results/data/whitened-$multiplier-$kbytes\K.out"
fi
echo "---"
@@ -82,10 +117,7 @@ do
dieharder -a -f results/data/devrandom-$multiplier-$kbytes\K.out > results/devrandom-$multiplier-$kbytes\K-dieharder.txt
fi
if [ $GRAPHS -eq 1 ] ; then
python plots/colormap.py results/data/devrandom-$multiplier-$kbytes\K.out &
python plots/scatterplot.py results/data/devrandom-$multiplier-$kbytes\K.out &
mv results/data/devrandom-$multiplier-$kbytes\K.out-colormap.png results/plots/
mv results/data/devrandom-$multiplier-$kbytes\K.out-scatter.png results/plots/
makePlots "results/data/devrandom-$multiplier-$kbytes\K.out"
fi
echo "---"
done