Skip to content

Commit 4a300f2

Browse files
author
Ryan Helinski
committed
Version 1.2 approved for release.
Signed-off-by: Ryan Helinski <rhelins@sandia.gov>
1 parent 918337b commit 4a300f2

18 files changed

+7299
-340
lines changed

COPYRIGHT.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Copyright (2014) Sandia Corporation. Under the terms of Contract
2+
DE-AC04-94AL85000, there is a non-exclusive license for use of this
3+
work by or on behalf of the U.S. Government. Export of this program
4+
may require a license from the United States Government.

GPLv3.txt

Lines changed: 619 additions & 0 deletions
Large diffs are not rendered by default.

LICENSE

Lines changed: 0 additions & 340 deletions
This file was deleted.

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (2014) Sandia Corporation. Under the terms of Contract
2+
# DE-AC04-94AL85000, there is a non-exclusive license for use of this
3+
# work by or on behalf of the U.S. Government. Export of this program
4+
# may require a license from the United States Government.
5+
6+
NOTICES := license.txt README.txt COPYRIGHT.txt
7+
8+
SOURCES := simulator/__init__.py simulator/abstractsimulator.py simulator/ropuf.py bch_code.py bitstring.py bitstringutils.py chipidentify.py spat.py quartus.py randomness.py sigfile.py
9+
10+
EXTRAS := spat.bat Makefile
11+
12+
clean:
13+
find . -name "*.py[oc]" -exec rm {} \;
14+
rm *~ *.bak *.swp
15+
.PHONY: clean
16+
17+
linecount:
18+
wc -l ${SOURCES}
19+
20+
DIST_NAME := spat-dist
21+
22+
tgz: ${DIST_NAME}.tar.gz
23+
tar.gz: ${DIST_NAME}.tar.gz
24+
${DIST_NAME}.tar.gz: ${SOURCES} ${NOTICES} ${EXTRAS}
25+
tar -cvzf ${DIST_NAME}.tar.gz ${SOURCES} ${NOTICES} ${EXTRAS}
26+
27+
zip: ${DIST_NAME}.zip
28+
${DIST_NAME}.zip: ${SOURCES} ${NOTICES} ${EXTRAS}
29+
zip ${DIST_NAME}.zip ${SOURCES} ${NOTICES} ${EXTRAS}
30+
31+
7z: ${DIST_NAME}.7z
32+
${DIST_NAME}.7z: ${SOURCES} ${NOTICES} ${EXTRAS}
33+
7z a ${DIST_NAME}.7z ${SOURCES} ${NOTICES} ${EXTRAS}
34+

README.md

Lines changed: 359 additions & 0 deletions
Large diffs are not rendered by default.

bch_code.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# bch_code.py
2+
# Copyright (2014) Sandia Corporation. Under the terms of Contract
3+
# DE-AC04-94AL85000, there is a non-exclusive license for use of this
4+
# work by or on behalf of the U.S. Government. Export of this program
5+
# may require a license from the United States Government.
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
import os, bitstring, random, math
21+
import subprocess
22+
23+
from bitstringutils import *
24+
25+
class bch_code(object):
26+
"""An error-correcting class"""
27+
28+
def __init__(self, nb=1024, fileName='bch_code_log.dat'):
29+
self.nb = nb
30+
self.bit_flips = None
31+
self.logFileName = fileName
32+
self.logFile = open(self.logFileName, 'ab')
33+
34+
def __destroy__(self):
35+
self.close()
36+
37+
def close(self):
38+
if (not self.logFile.closed):
39+
self.logFile.flush()
40+
self.logFile.close()
41+
42+
def setup(self, first_measurement, MM=13, TT=20, KK=1024, PP=8):
43+
"""A function to enroll the PUF with the error corrector object
44+
45+
Arguments:
46+
MM <field>: Galois field, GF, for code. Code length is 2^<field>-1.
47+
The default value is 13 for a code length 8191. If the parameter is
48+
set to 0, the program will estimate the value based upon the values
49+
chosen for k and t.
50+
TT <correct>: Correction power of the code. Default = 4
51+
KK <data bits>: Number of data bits to be encoded. Must divide 4.
52+
The default value is the maximum supported by the code which
53+
depends upon the field (-m) and the correction (-t) chosen.
54+
PP <parallel>: Parallelism in encoder. Does not effect results but
55+
does change the algorithm used to generate them. Default = 8"""
56+
57+
self.m = MM; self.t = TT; self.k = KK; self.p = PP
58+
p = subprocess.Popen("bch_encoder.exe -m %d -t %d -k %d -p %d" % (self.m, self.t, self.k, self.p), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
59+
p.stdin.write(first_measurement.hex)
60+
output, errors = p.communicate()
61+
codeword, syndrome = output.split()
62+
self.syndrome = syndrome
63+
return self.syndrome
64+
65+
def decode(self, response):
66+
p = subprocess.Popen("bch_decoder.exe -m %d -t %d -k %d -p %d" % (self.m, self.t, self.k, self.p), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
67+
p.stdin.write(response.hex + self.syndrome + "\n")
68+
p.stdin.flush()
69+
p.stdin.close()
70+
output, errors = p.communicate()
71+
if len (output.strip()) != self.nb / 4:
72+
raise ValueError ("Invalid signature returned from decoder")
73+
74+
return bitstring.Bits(hex="0x"+output.strip())
75+
76+
if __name__=="__main__":
77+
print "Running self-test"
78+
79+
import simulator
80+
mySim = simulator.Simulator()
81+
mySim.setup()
82+
83+
firstMeasurement = mySim.next()
84+
print firstMeasurement.hex
85+
myCoder = bch_code()
86+
helper_data = myCoder.setup(firstMeasurement) # setup with defaults
87+
88+
print "Syndrome: " + myCoder.syndrome
89+
90+
newMeasurement = mySim.next()
91+
print "(Possibly-) Errored Measurement:\n" + newMeasurement.hex
92+
print "Errors: " + str(hd(firstMeasurement, newMeasurement))
93+
print "Recovered:\n" + myCoder.decode(newMeasurement).hex
94+
print "Reduced errors: " + str(hd(firstMeasurement, myCoder.decode(newMeasurement)))
95+
96+
print "Done!"
97+

0 commit comments

Comments
 (0)