system = bp.simplify_across(system)

bp.store_string('./structures/sha_1_no_assignments.txt', system)

H = bp.get_words('H.txt')
for i in range(len(H)):
    for j in range(wl):
        system = system.replace(bp.bit('H' + bp.fi(0) + bp.fi(i), j),\
                str(bool(H[i] >> j & 1)).lower())

system = bp.simplify_across(system)

bp.store_string('./structures/sha_1_first_block.txt', system)

W = bp.words_from_string(wl, "Chiara")

system = bp.xor_in_standard_syntax(system)
system = bp.not_in_python_syntax(system)

for i in range(len(W)):
    for j in range(wl):
        system = system.replace(bp.bit('W' + bp.fi(0) + bp.fi(i), j),\
                str(bool(W[i] >> j & 1)))

exec(system)

Z = [0] * 5
for i in range(wl):
    Z[0] ^= eval(bp.bit('Z' + bp.fi(0) + bp.fi(0), i)) << i
    Z[1] ^= eval(bp.bit('Z' + bp.fi(0) + bp.fi(1), i)) << i
Beispiel #2
0
    file_id
        an identification for the files 'block' and 'states'
        (consider an integer)
'''

import sys
import re
import bitpy as bp

wl = int(sys.argv[1])
mode = sys.argv[2]
string = sys.argv[3]
file_id = sys.argv[4]

if mode == '0':
    W = bp.words_from_string(wl, string)
else:
    if mode == '1':
        W = bp.get_words(string)

system = bp.get_string('./structures/sha_1.txt')
system = bp.xor_in_standard_syntax(system)
system = bp.not_in_python_syntax(system)

#K = bp.get_words('K.txt')
H = bp.get_words('H.txt')

#for i in range(len(K)):
#    for j in range(wl):
#        system = system.replace(bp.bit('K' + bp.fi(i), j),\
#                str(bool(K[i] >> j & 1)))
Beispiel #3
0
sha_1 = '\n'.join(systems)
bp.store_string('./structures/sha_1_' + str(n) + '_blocks.txt', sha_1)
H = bp.get_words('H.txt')
for i in range(len(H)):
    for j in range(wl):
        sha_1 = sha_1.replace(bp.bit('H' + bp.fi(0) + bp.fi(i), j),\
                str(bool(H[i] >> j & 1)))

test_check = input('Do you want to test it? [y/n] ')
if test_check == 'y':
    low = 56 + (n - 2) * 64
    high = 119 + (n - 2) * 64
    string = input('Type a string (escapes not allowed) with a x number of ' +\
            'chars such that ' + str(low) + ' ≤ x ≤ ' + str(high) + '.\n')
    W = bp.words_from_string(32, string)
    for i in range(n):
        for j in range(16):
            for k in range(wl):
                sha_1 = sha_1.replace(bp.bit('W' + bp.fi(i) + bp.fi(j), k),\
                        str(bool(W[i * 16 + j] >> k & 1)))

    sha_1 = bp.xor_in_standard_syntax(sha_1)
    sha_1 = bp.not_in_python_syntax(sha_1)

    exec(sha_1)

    digest = 0
    for i in range(wl):
        digest ^= eval(bp.bit('Z' + bp.fi(n - 1) + bp.fi(0), i)) << i + 4 * wl
        digest ^= eval(bp.bit('Z' + bp.fi(n - 1) + bp.fi(1), i)) << i + 3 * wl
                str(bool(H[i] >> j & 1)).lower())

system0 = system0.replace('_', bp.fi(0))
system0 = bp.simplify_across(system0)
bp.store_string('./structures/hmac_sha_1_00.txt', system0)

system0 = bp.xor_in_standard_syntax(system0)
system0 = bp.not_in_python_syntax(system0)
for i in range(16):
    for j in range(wl):
        system0 = system0.replace(bp.bit('W' + bp.fi(0) + bp.fi(i), j),\
                str(bool(W[i] >> j & 1)))

## system1

W = bp.words_from_string(wl, value)
W[15] = 0x00000230
for i in range(len(W)):
    for j in range(wl):
        system1 = system1.replace(bp.bit('W_' + bp.fi(i), j),\
                str(bool(W[i] >> j & 1)).lower())

system1 = system1.replace('H_', 'Z' + bp.fi(0))
system1 = system1.replace('_', bp.fi(1))
system1 = bp.simplify_across(system1)
bp.store_string('./structures/hmac_sha_1_01.txt', system1)

system1 = bp.xor_in_standard_syntax(system1)
system1 = bp.not_in_python_syntax(system1)

## system2