示例#1
0
    import random

    inputs = []
    randIndex = random.sample(range(n), k)
    for i in randIndex:
        f = outputs[i]
        s = f.getvalue().encode("hex")
        print str(i) + ": " + s
        inputs.append(f)
    print ""

    print "decoding shares "
    for i in inputs:
        print i.getvalue().encode("hex")
    output = StringIO.StringIO()
    rvsuccess = s4_decode(inputs, output)
    print ""

    print "decoding insufficient shares "
    inputs.pop()
    for i in inputs:
        print i.getvalue().encode("hex")
    badoutput = StringIO.StringIO()
    rvfail = s4_decode(inputs, badoutput)
    badoutput = badoutput.getvalue()
    print ""

    print "input  text: %s" % input.getvalue()
    print "output text: %s\n\treturn value %d (should be %d)" % (output.getvalue(), rvsuccess, True)
    print "short decode return value %d (should be %d)" % (rvfail, False)
示例#2
0
	if num_bad:
		wrong = shares[0].getvalue().encode('hex')
		wrong = wrong[::-1]
		wrong = wrong.decode('hex')
		shares.append(StringIO.StringIO())
		shares[-1].write(wrong)

	# test all-fragments (5), over-determined (4), sufficient (3), insufficient (2)
	while True:
		i = len(shares)
		if ((i - num_bad) < (num_needed - 1)):
			break

		output = StringIO.StringIO()
		try: # decode returns True for success, False for failure
			status = s4_decode(shares,output)
		except: # catch math, IO exceptions and simply mark the test as failed
			status = False

		# expected results:
		# (m <= x <= n) fragments will allow for reassembly
		# (x < m) fragments do not allow for reassembly
		# the presence of incorrect fragments prevents reassembly
		expected = True if ((i >= num_needed) and (num_bad == 0)) else False
		if (status == expected):
			statusmsg = "PASS"
		else:
			exitcode = 1
			statusmsg = "FAIL"

		print "n=%d split=%d/%d bad %d %s" % ((i - num_bad), num_needed, num_shares, num_bad, statusmsg)
示例#3
0
  print "randomly selecting %d shares" % k
  import random
  inputs = []
  randIndex = random.sample(range(n), k)
  for i in randIndex:
    f = outputs[i]
    s = f.getvalue().encode('hex')
    print str(i)+": "+s
    inputs.append(f)
  print ""

  print "decoding shares "
  for i in inputs:
    print i.getvalue().encode('hex')
  output = StringIO.StringIO()
  rvsuccess = s4_decode(inputs,output)
  print ""

  print "decoding insufficient shares "
  inputs.pop()
  for i in inputs:
    print i.getvalue().encode('hex')
  badoutput = StringIO.StringIO()
  rvfail = s4_decode(inputs,badoutput)
  badoutput = badoutput.getvalue()
  print ""

  print "input  text: %s" % input.getvalue()
  print "output text: %s\n\treturn value %d (should be %d)" % (output.getvalue(), rvsuccess, True)
  print "short decode return value %d (should be %d)" % (rvfail, False)
示例#4
0
#!/usr/bin/env python

#  Copyright 2014 Chris Kuethe

import StringIO
from pysssslib import s4_decode


inbuf = []
x = '4dd42fd883c62f3f7d4bb8d715663976500e2895f578e251591355c44b11ad1573a9d68faab458d0e9b5e4fccf6ef41fdd5aa00695ec9324deba9213b29ee6e8'.decode('hex')
inbuf.append(StringIO.StringIO(x))
x = '475c32bf6f61c424dcea3482230091c644954b9ac0b324324155d5a55ffc45c447c6afe5cff109022e95495626afdc2527a7e869f9d5ea54c686ab507a849501'.decode('hex')
inbuf.append(StringIO.StringIO(x))
x = '5eb3fcabf808887e8abc9797b065342c7b03b0cecb95759727caad5d41ea696e8942d43446ea8e0835333269de06ee71f06663498d8bf47f56f528729fedf781'.decode('hex')
inbuf.append(StringIO.StringIO(x))

outbuf = StringIO.StringIO()
status = s4_decode(inbuf, outbuf) # Only 2 of 3 shares required for this demo
computed = outbuf.getvalue()
expected = "Too many secrets, Marty!"

# generated by code pyssslib ID 4c51de6e4b26a0332857f71d4c13048b700d32af
if computed == expected and status == True:
	print "compatibility test PASS"
else:
	print "compatibility test FAIL"
示例#5
0
#!/usr/bin/env python

#  Copyright 2014 Chris Kuethe

import StringIO
from pysssslib import s4_decode

inbuf = []
x = '4dd42fd883c62f3f7d4bb8d715663976500e2895f578e251591355c44b11ad1573a9d68faab458d0e9b5e4fccf6ef41fdd5aa00695ec9324deba9213b29ee6e8'.decode(
    'hex')
inbuf.append(StringIO.StringIO(x))
x = '475c32bf6f61c424dcea3482230091c644954b9ac0b324324155d5a55ffc45c447c6afe5cff109022e95495626afdc2527a7e869f9d5ea54c686ab507a849501'.decode(
    'hex')
inbuf.append(StringIO.StringIO(x))
x = '5eb3fcabf808887e8abc9797b065342c7b03b0cecb95759727caad5d41ea696e8942d43446ea8e0835333269de06ee71f06663498d8bf47f56f528729fedf781'.decode(
    'hex')
inbuf.append(StringIO.StringIO(x))

outbuf = StringIO.StringIO()
status = s4_decode(inbuf, outbuf)  # Only 2 of 3 shares required for this demo
computed = outbuf.getvalue()
expected = "Too many secrets, Marty!"

# generated by code pyssslib ID 4c51de6e4b26a0332857f71d4c13048b700d32af
if computed == expected and status == True:
    print "compatibility test PASS"
else:
    print "compatibility test FAIL"