Example #1
0
def encrypt(_, rt, key):
    start = time.time()
    print "Started at %f." % start

    aes = AES(rt, options.keylength, use_exponentiation=options.exponentiation)

    ciphertext = []

    for i in range(options.count):
        ciphertext += aes.encrypt("a" * 16, key, True,
                                  prepare_at_once=options.at_once)

    opened_ciphertext = [rt.open(c) for c in ciphertext]

    def fin(ciphertext):
        print "Finished after %f sec." % (time.time() - start)
        print "Ciphertext:", [hex(c.value) for c in ciphertext]

        if rt._needed_data and options.preproc:
            print "Missing pre-processed data:"
            for (func, args), pcs in rt._needed_data.iteritems():
                print "* %s%s:" % (func, args)
                print "  " + pformat(pcs).replace("\n", "\n  ")

        if rt._pool:
            print "Unused pre-processed data:"
            pcs = rt._pool.keys()
            pcs.sort()
            print "  " + pformat(pcs).replace("\n", "\n  ")

        rt.shutdown()

    g = gather_shares(opened_ciphertext)
    rt.schedule_complex_callback(g, fin)
Example #2
0
    def test_key_expansion(self, runtime):
        aes = AES(runtime, 256, quiet=True)
        key = []
        ascii_key = []

        for i in xrange(8):
            key.append([])

            for j in xrange(4):
                b = 15 * i + j
                key[i].append(Share(runtime, GF256, GF256(b)))
                ascii_key.append(chr(b))

        result = aes.key_expansion(key)

        r = rijndael(ascii_key)
        expected_result = []

        for round_key in r.Ke:
            for word in round_key:
                split_word = []
                expected_result.append(split_word)

                for j in xrange(4):
                    split_word.insert(0, word % 256)
                    word /= 256

        self.verify(runtime, result, expected_result)
Example #3
0
    def test_encrypt(self, runtime):
        cleartext = "Encrypt this!!!!"
        key = "Supposed to be secret!?!"

        aes = AES(runtime, 192, quiet=True)
        r = rijndael(key)

        result = aes.encrypt(cleartext, key)
        expected = [ord(c) for c in r.encrypt(cleartext)]

        return self.verify(runtime, [result], [expected])
Example #4
0
def invert(rt):
    aes = AES(rt, 192, use_exponentiation=options.exponentiation)
    bytes = [Share(rt, GF256, GF256(random.randint(0, 255)))
             for i in range(options.count)]

    start = time.time()

    done = gather_shares([aes.invert(byte) for byte in bytes])

    def finish(_):
        duration = time.time() - start
        print "Finished after %.3f s." % duration
        print "Time per inversion: %.3f ms" % (1000 * duration / options.count)
        rt.shutdown()

    done.addCallback(finish)
Example #5
0
def invert(rt):
    aes = AES(rt, 192, use_exponentiation=options.exponentiation)
    bytes = [
        Share(rt, GF256, GF256(random.randint(0, 255)))
        for i in range(options.count)
    ]

    start = time.time()

    done = gather_shares([aes.invert(byte) for byte in bytes])

    def finish(_):
        duration = time.time() - start
        print "Finished after %.3f s." % duration
        print "Time per inversion: %.3f ms" % (1000 * duration / options.count)
        rt.shutdown()

    done.addCallback(finish)
Example #6
0
 def test_byte_sub_with_exponentiation(self, runtime):
     self._test_byte_sub(
         runtime, AES(runtime, 128, use_exponentiation=True, quiet=True))