Created
June 12, 2018 10:12
-
-
Save MrKevinWeiss/cf0dd7830d4ef659ed6cc8941a2002a0 to your computer and use it in GitHub Desktop.
Updated example test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Copyright (C) 2018 Kevin Weiss <kevin.weiss@haw-hamburg.de> | |
# Copyright (C) 2018 Peter Kietzmann <peter.kietzmann@haw-hamburg.de> | |
# | |
# This file is subject to the terms and conditions of the GNU Lesser | |
# General Public License v2.1. See the file LICENSE in the top level | |
# directory for more details. | |
import puf_sram_if | |
import numpy | |
import sys | |
from time import gmtime, strftime | |
import argparse | |
__N = 500 | |
__OFF_TIME = 1 | |
def min_erntropy(all_meas): | |
p1 = numpy.zeros(len(all_meas[0])) | |
# number of ones for each bit | |
for i in range(0, len(all_meas[0])): | |
tmp = list(map(lambda x: int(x[i]), all_meas)) | |
p1[i] = numpy.count_nonzero(tmp) | |
# probability of ones | |
p1 = numpy.divide(p1, float(len(all_meas))) | |
# probability of zeros | |
p0 = 1 - p1 | |
p0_1_max = numpy.maximum(p1, p0) | |
log2_p0_1_max = numpy.log2(p0_1_max) | |
H_min = numpy.sum(-log2_p0_1_max) | |
H_min_rel = 100 * H_min/len(p0_1_max) | |
return [H_min, H_min_rel] | |
print ("Starting puf_sram Test") | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--port", help='Sets Port') | |
parser.add_argument("--board", help='Sets board') | |
parser.add_argument("--ralloc", help='Sets ram allocation') | |
parser.add_argument("--offtime", help='Sets offtime') | |
parser.add_argument("--n", help='Sets sample number') | |
args = parser.parse_args() | |
if args.port is not None: | |
puf_sram = puf_sram_if.PufSram(port=args.port) | |
else: | |
puf_sram = puf_sram_if.PufSram() | |
if args.board is not None: | |
__BOARD = args.board | |
else: | |
__BOARD = '?' | |
if args.ralloc is not None: | |
__RALLOC = args.ralloc | |
else: | |
__RALLOC = '?' | |
if args.offtime is not None: | |
__OFF_TIME = int(args.offtime, 0) | |
if args.n is not None: | |
__N = int(args.n, 0) | |
time = strftime("%Y-%m-%d-%H-%M-%S", gmtime()) | |
sys.stdout = open('puf_sram_test(%s)' % time, 'w') | |
print ("Starting puf_sram Test at %s" % time) | |
print ("Number of samples = %d" % __N) | |
print ("Off Time = %d(s)" % __OFF_TIME) | |
print ("Board = %s" % __BOARD) | |
print ("Ram Allocation = %s" % __RALLOC) | |
seeds = puf_sram.get_seed_list(n=__N, off_time=__OFF_TIME, allow_print=True) | |
seeds=[format( x, '0>32b') for x in seeds] | |
H_min, H_min_rel = min_erntropy(seeds) | |
print ("Number of seeds: %i " % len(seeds)) | |
print ("Seed length : %i Bit " % len(seeds[0])) | |
print ("Abs. Entropy : %02.02f Bit " % H_min) | |
print ("Rel. Entropy : %02.02f perc. " % H_min_rel) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment