예제 #1
0
def test_aes_ctr_incr_nist():
    nist_iv = 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff'
    nonce, ctr = [b16decode(s, True) for s in split_at(nist_iv,
                                                       len(nist_iv) // 2)]
    ctr2 = A.aes_ctr_incr(ctr)
    assert B.bytes_to_int(ctr) + 1 == B.bytes_to_int(ctr2)
    ctr3 = A.aes_ctr_incr(ctr2)
    assert B.bytes_to_int(ctr2) + 1 == B.bytes_to_int(ctr3)
예제 #2
0
def test_aes_ctr_incr_nist():
    nist_iv = 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff'
    nonce, ctr = [
        b16decode(s, True) for s in split_at(nist_iv,
                                             len(nist_iv) // 2)
    ]
    ctr2 = A.aes_ctr_incr(ctr)
    assert B.bytes_to_int(ctr) + 1 == B.bytes_to_int(ctr2)
    ctr3 = A.aes_ctr_incr(ctr2)
    assert B.bytes_to_int(ctr2) + 1 == B.bytes_to_int(ctr3)
예제 #3
0
def test_aes_ctr_incr_wraparound():
    n = (2 ** 64) - 2
    print('n=%s' % n)
    bs = B.int_to_byte_ints(n)
    print('bs=%s' % bs)
    ctr = ''.join(map(chr, bs))
    assert B.bytes_to_int(bs) == n
    assert len(bs) == A.BLOCKSIZE // 2
    ctr2 = A.aes_ctr_incr(ctr)
    assert isinstance(ctr2, str)
    assert n + 1 == B.bytes_to_int(ctr2)
    ctr3 = A.aes_ctr_incr(ctr2)
    assert isinstance(ctr3, str)
    assert 0 == B.bytes_to_int(ctr3)
예제 #4
0
def test_aes_ctr_incr_wraparound():
    n = (2**64) - 2
    print('n=%s' % n)
    bs = B.int_to_byte_ints(n)
    print('bs=%s' % bs)
    ctr = ''.join(map(chr, bs))
    assert B.bytes_to_int(bs) == n
    assert len(bs) == A.BLOCKSIZE // 2
    ctr2 = A.aes_ctr_incr(ctr)
    assert isinstance(ctr2, str)
    assert n + 1 == B.bytes_to_int(ctr2)
    ctr3 = A.aes_ctr_incr(ctr2)
    assert isinstance(ctr3, str)
    assert 0 == B.bytes_to_int(ctr3)
예제 #5
0
def incrhack(bytes, n):
    bytes = b16decode(bytes, True)
    head, tail = split_at(bytes)
    assert head + tail == bytes
    assert len(head) == A.BLOCKSIZE // 2
    assert len(tail) == A.BLOCKSIZE // 2
    for i in range(n):
        tail = A.aes_ctr_incr(tail)
    return b16encode(head + tail)
예제 #6
0
def test_aes_ctr_incr0():
    bs = map(chr, [0, 0, 0, 0, 0, 0, 0, 1])
    n = 1
    assert n == B.bytes_to_int(bs)
    ctr = ''.join(bs)
    assert b16encode(ctr) == '0000000000000001'
    ctr2 = A.aes_ctr_incr(ctr)
    assert b16encode(ctr2) == '0000000000000002'
    assert B.bytes_to_int(ctr2) == n + 1
예제 #7
0
def test_aes_ctr_incr():
    bs = map(chr, [1, 1, 1, 1, 1, 1, 1, 1])
    n = 1
    for i in range(len(bs) - 1):
        n = 256 * n + 1
    assert n == B.bytes_to_int(bs)
    ctr = ''.join(bs)
    ctr2 = A.aes_ctr_incr(ctr)
    assert B.bytes_to_int(ctr2) == n + 1
예제 #8
0
def incrhack(bytes, n):
    bytes = b16decode(bytes, True)
    head, tail = split_at(bytes)
    assert head + tail == bytes
    assert len(head) == A.BLOCKSIZE // 2
    assert len(tail) == A.BLOCKSIZE // 2
    for i in range(n):
        tail = A.aes_ctr_incr(tail)
    return b16encode(head + tail)
예제 #9
0
def test_aes_ctr_incr0():
    bs = map(chr, [0, 0, 0, 0, 0, 0, 0, 1])
    n = 1
    assert n == B.bytes_to_int(bs)
    ctr = ''.join(bs)
    assert b16encode(ctr) == '0000000000000001'
    ctr2 = A.aes_ctr_incr(ctr)
    assert b16encode(ctr2) == '0000000000000002'
    assert B.bytes_to_int(ctr2) == n + 1
예제 #10
0
def test_aes_ctr_incr():
    bs = map(chr, [1, 1, 1, 1, 1, 1, 1, 1])
    n = 1
    for i in range(len(bs) - 1):
        n = 256 * n + 1
    assert n == B.bytes_to_int(bs)
    ctr = ''.join(bs)
    ctr2 = A.aes_ctr_incr(ctr)
    assert B.bytes_to_int(ctr2) == n + 1