Example #1
0
 def test_tss2(self):
     secret = b'my big fat secret'
     h = (b'\x6c\x53\x71\x42\x9e\xff\xfb\xb2\x5b\x7d\xea\x79\xc0\x50\xee'
          b'\xd3\xed\x83\x30\xfe\x7b\xdf\x4d\x02\x32\x30\x89\x36\x9e\x5c'
          b'\x73\x48')
     shares1 = share_secret(5, 10, secret, 'my-id', Hash.SHA256)
     shares2 = share_secret(5, 10, secret + h, 'my-id', Hash.NONE)
     reconstructed_secret1 = reconstruct_secret(shares1)
     reconstructed_secret2 = reconstruct_secret(shares2)
     self.assertEqual(secret, reconstructed_secret1)
     self.assertEqual(secret + h, reconstructed_secret2)
Example #2
0
 def test_tss2(self):
     secret = b'my big fat secret'
     h = (b'\x6c\x53\x71\x42\x9e\xff\xfb\xb2\x5b\x7d\xea\x79\xc0\x50\xee'
          b'\xd3\xed\x83\x30\xfe\x7b\xdf\x4d\x02\x32\x30\x89\x36\x9e\x5c'
          b'\x73\x48')
     shares1 = share_secret(5, 10, secret, 'my-id', Hash.SHA256)
     shares2 = share_secret(5, 10, secret + h, 'my-id', Hash.NONE)
     reconstructed_secret1 = reconstruct_secret(shares1)
     reconstructed_secret2 = reconstruct_secret(shares2)
     self.assertEqual(secret, reconstructed_secret1)
     self.assertEqual(secret + h, reconstructed_secret2)
 def test_tss1(self):
     # test\0
     secret = b'\x74\x65\x73\x74\x00'
     shares = share_secret(2, 2, secret, 'my-id', Hash.NONE)
     print "%x %x %x %x %x" % (ord(shares[0][-5]), ord(shares[0][-4]), ord(shares[0][-3]), ord(shares[0][-2]), ord(shares[0][-1]))
     print "%x %x %x %x %x" % (ord(shares[1][-5]), ord(shares[1][-4]), ord(shares[1][-3]), ord(shares[1][-2]), ord(shares[1][-1]))
     reconstructed_secret = reconstruct_secret(shares)
     self.assertEqual(secret, reconstructed_secret)
Example #4
0
 def test_tss1(self):
     # test\0
     secret = b'\x74\x65\x73\x74\x00'
     shares = share_secret(2, 2, secret, 'my-id', Hash.NONE)
     print "%x %x %x %x %x" % (ord(shares[0][-5]), ord(
         shares[0][-4]), ord(shares[0][-3]), ord(
             shares[0][-2]), ord(shares[0][-1]))
     print "%x %x %x %x %x" % (ord(shares[1][-5]), ord(
         shares[1][-4]), ord(shares[1][-3]), ord(
             shares[1][-2]), ord(shares[1][-1]))
     reconstructed_secret = reconstruct_secret(shares)
     self.assertEqual(secret, reconstructed_secret)
Example #5
0
 def test_tss4(self):
     secret = b'my big fat secret'
     shares = share_secret(5, 10, secret, 'my-id')
     share_mod = shares[0]
     share_mod = (share_mod[:-4] +
                  tss.b(chr(~tss.byte_to_ord(share_mod[-4]) % 256)) +
                  share_mod[-3:])
     shares[0] = share_mod
     self.assertRaises(TSSError, lambda: reconstruct_secret(shares, True))
     reconstructed_secret = reconstruct_secret(shares, False)
     self.assertEqual(secret, reconstructed_secret)
     self.assertRaises(TSSError,
                       lambda: reconstruct_secret(shares[:5], False))
Example #6
0
 def test_tss4(self):
     secret = b'my big fat secret'
     shares = share_secret(5, 10, secret, 'my-id')
     share_mod = shares[0]
     share_mod = (share_mod[:-4] +
                  tss.b(chr(~tss.byte_to_ord(share_mod[-4]) % 256)) +
                  share_mod[-3:])
     shares[0] = share_mod
     self.assertRaises(TSSError, lambda: reconstruct_secret(shares, True))
     reconstructed_secret = reconstruct_secret(shares, False)
     self.assertEqual(secret, reconstructed_secret)
     self.assertRaises(TSSError,
                       lambda: reconstruct_secret(shares[:5], False))
Example #7
0
def encryptandshare(p, m, keys):

    #Create the shares
    shares = (tss.share_secret(m, (2 * m), p, '', tss.Hash.SHA256))
    #Create instruction table file
    file = open('InstructionTable.txt', 'w')

    #Padding to ensure the key length is a multiple of 16 bytes (as required by AES)
    length = 16 - (len(keys) % 16)
    keys += chr(length) * length

    #Encrypt the shares
    for i in range(0, 2 * m):
        iv = Random.new().read(AES.block_size)
        encryption_suite = AES.new(keys, AES.MODE_CFB, iv)
        cipher_text0 = iv + (encryption_suite.encrypt(shares[i]))
        cipher = base64.b64encode(cipher_text0)
        file.write(cipher + ' ')
        if (i % 2 == 1):
            file.write('\n')
    file.close()
def shamir():
    secret = ciphertextAES
    print("Input to Shamir's Secret:")
    print(secret)
    print(len(secret))
    global t
    t = 2
    s = 3

    if len(sys.argv) > 1:
        secret = str(sys.argv[1])
    if len(sys.argv) > 2:
        t = int(sys.argv[2])
    if len(sys.argv) > 3:
        s = int(sys.argv[3])

    global shares
    shares = tss.share_secret(t, s, secret, 'my-id', Hash.NONE)
    print("\n~~~~~ Key Split in 3 Shares ~~~~~")
    for x in range(0, s):
        print(shares[x])

    global constructedShamir
    constructedShamir = True
Example #9
0
 def test_tss1(self):
     # test\0
     secret = b'\x74\x65\x73\x74\x00'
     shares = share_secret(2, 2, secret, 'my-id', Hash.NONE)
     reconstructed_secret = reconstruct_secret(shares)
     self.assertEqual(secret, reconstructed_secret)
Example #10
0
 def test_tss1(self):
     # test\0
     secret = b'\x74\x65\x73\x74\x00'
     shares = share_secret(2, 2, secret, 'my-id', Hash.NONE)
     reconstructed_secret = reconstruct_secret(shares)
     self.assertEqual(secret, reconstructed_secret)
Example #11
0
def crypto_keys(k, n, seed):
    shares = tss.share_secret(k, n, seed, "no", tss.Hash.SHA256)
    keys = []
    for i in shares:
        keys.append(serialize_shamir(i))
    return keys
Example #12
0
def create_inst_table(password, hpwd):
    password = password.strip('\n')
    flag = list()
    u_mean = mean(hpwd)             # calculating mean by calling mean function
    std = standard_deviation(hpwd)  # calculating standard_deviation by calling standard_deviation function
    q = 626436561503166578967805515819693654293211766937  # binary 160 bits Prime No.- 0110110110111010011000110000110111111101001000000111110001110100100010110110000000011101110011000100001111101110000110000101001100001101100110111110000010011001
    hard_pwd = Decimal(random.random() * q)  # Generate a Random hardened password after each successful login attempt
    hard_pwd = str(hard_pwd)[0:32]         #padding
    hard_pwd = int(hard_pwd)
    shares = (tss.share_secret(m, (2 * m), hard_pwd, '', tss.Hash.SHA256))  # defining that m shares are needed from 2m shares to sucessfully create hard_pwd
    update_history(feature_val,hpwd,hard_pwd)              # calling update_history function
    file = open('InstructionTable.txt', 'w')               # opening InstructionTable file
    file.truncate()                                        # deleting previous entries from file
    length = 16 - (len(password) % 16)                     # Padding to ensure the key length is a multiple of 16 bytes (as required by AES)
    password += chr(length) * length
    for i in range(0, m):
        if (u_mean[i] + (k * std[i])) < t:                 # checking conditions to choose where the user is fast or slow for ith feature, here features are taken from zero as i start from 0.
            flag.append(0)
        elif (u_mean[i] - (k * std[i])) > t:
            flag.append(1)
        else:
            flag.append(-1)
    for i in range(0, m):                                  # encrypting m shares from password and storing according its place in instruction table,i.e left or right
        if (flag[i] == 0):
            iv = Random.new().read(AES.block_size)
            encryption_suite = AES.new(password, AES.MODE_CFB, iv)
            cipher_text0 = iv + (encryption_suite.encrypt(shares[2 * i]))  # creating correct share and storing it to left column of instruction table
            cipher = base64.b64encode(cipher_text0)
            file.write(cipher + ' ')
            iv = Random.new().read(AES.block_size)
            keyrand = str(rstr.digits(5))
            length = 16 - (len(keyrand) % 16)
            keyrand += chr(length) * length
            encryption_suite = AES.new(keyrand, AES.MODE_CFB, iv)
            cipher_text0 = iv + (encryption_suite.encrypt(shares[(2 * i) + 1]))  # creating random vague share and storing it to right column of instruction table
            cipher = base64.b64encode(cipher_text0)
            file.write(cipher + ' ')
            file.write('\n')
        if (flag[i] == 1):
            iv = Random.new().read(AES.block_size)
            keyrand = str(rstr.digits(5))
            length = 16 - (len(keyrand) % 16)
            keyrand += chr(length) * length
            encryption_suite = AES.new(keyrand, AES.MODE_CFB, iv)
            cipher_text0 = iv + (encryption_suite.encrypt(shares[2 * i]))  # creating random vague share and storing it to left column of instruction table
            cipher = base64.b64encode(cipher_text0)
            file.write(cipher + ' ')
            iv = Random.new().read(AES.block_size)
            encryption_suite = AES.new(password, AES.MODE_CFB, iv)
            cipher_text0 = iv + (encryption_suite.encrypt(shares[(2 * i) + 1]))  # creating correct share and storing it to right column of instruction table
            cipher = base64.b64encode(cipher_text0)
            file.write(cipher + ' ')
            file.write('\n')
        if (flag[i] == -1):
            iv = Random.new().read(AES.block_size)
            iv = Random.new().read(AES.block_size)
            encryption_suite = AES.new(password, AES.MODE_CFB, iv)
            cipher_text0 = iv + (encryption_suite.encrypt(shares[2 * i]))     # creating correct share and storing it to left column of instruction table
            cipher = base64.b64encode(cipher_text0)
            file.write(cipher + ' ')
            iv = Random.new().read(AES.block_size)
            encryption_suite = AES.new(password, AES.MODE_CFB, iv)
            cipher_text0 = iv + (encryption_suite.encrypt(shares[(2 * i) + 1]))  # creating correct share and storing it to right column of instruction table
            cipher = base64.b64encode(cipher_text0)
            file.write(cipher + ' ')
            file.write('\n')                                                     # closing  InstructionTable after updating file
    file.close()