Ejemplo n.º 1
0
def test_pad_pkcs5_non_blocksize_multiple():
    bs = [' ']
    num_bytes = len(bs)
    res = P.pad_pkcs5(bs, P.DEFAULT_BLOCKSIZE)
    delta = len(res) - num_bytes
    assert len(res) == P.DEFAULT_BLOCKSIZE
    assert delta + num_bytes == P.DEFAULT_BLOCKSIZE
    assert res[0] == ' '
    padding = res[num_bytes:]
    assert len(padding) == delta
    assert res[1:] == [chr(delta)] * delta
Ejemplo n.º 2
0
def aes_pad(plaintext_bytes):
    num_bytes = len(plaintext_bytes)
    plaintext_bytes = pad_pkcs5(plaintext_bytes, blocksize=BLOCKSIZE)
    assert len(plaintext_bytes) > num_bytes
    return plaintext_bytes
Ejemplo n.º 3
0
def test_pad_pkcs5_bytestring():
    bs = ''.join([chr(0)] * (P.DEFAULT_BLOCKSIZE // 2))
    res = P.pad_pkcs5(bs, P.DEFAULT_BLOCKSIZE)
    exp = ''.join([chr(0)] * (P.DEFAULT_BLOCKSIZE // 2) +
                  [chr(P.DEFAULT_BLOCKSIZE // 2)] * (P.DEFAULT_BLOCKSIZE // 2))
    assert res == exp
Ejemplo n.º 4
0
def test_pad_pkcs5_fullblock():
    bs = [chr(0)] * P.DEFAULT_BLOCKSIZE
    res = P.pad_pkcs5(bs, P.DEFAULT_BLOCKSIZE)
    assert res == ([chr(0)] * P.DEFAULT_BLOCKSIZE +
                   [chr(P.DEFAULT_BLOCKSIZE)] * P.DEFAULT_BLOCKSIZE)
Ejemplo n.º 5
0
def test_pad_pkcs5_emptyblock():
    bs = []
    res = P.pad_pkcs5(bs, P.DEFAULT_BLOCKSIZE)
    assert res == [chr(P.DEFAULT_BLOCKSIZE)] * P.DEFAULT_BLOCKSIZE
Ejemplo n.º 6
0
def aes_pad(plaintext_bytes):
    num_bytes = len(plaintext_bytes)
    plaintext_bytes = pad_pkcs5(plaintext_bytes, blocksize=BLOCKSIZE)
    assert len(plaintext_bytes) > num_bytes
    return plaintext_bytes