#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
from pygost.gost28147 import cbc_decrypt
from pygost.gost28147 import cbc_encrypt
from pygost.gost28147 import cfb_decrypt
from pygost.gost28147 import cbc_decrypt
from pygost.gost28147 import cbc_encrypt
from pygost.gost28147 import cfb_decrypt
from pygost.gost28147 import ecb_decrypt
from pygost.gost28147 import ecb_encrypt
from pygost.gost28147 import encrypt
from pygost.gost28147 import ecb_decrypt
from pygost.gost28147 import ecb_encrypt
from pygost.gost28147 import encrypt
from pygost.gost28147 import MESH_MAX_DATA
from pygost.gost28147 import ns2block
from pygost.utils import hexdec
from pygost.gost28147 import MESH_MAX_DATA
from pygost.gost28147 import ns2block
from pygost.utils import hexdec
"""
sbox = "id-Gost28147-89-TestParamSet"
key = hexdec(b"0475f6e05038fbfad2c7c390edb3ca3d1547124291ae1e8a2f79cd9ed2bcefbd")
"""
sbox = "id-Gost28147-89-TestParamSet"
key = hexdec(b"0475f6e05038fbfad2c7c390edb3ca3d1547124291ae1e8a2f79cd9ed2bcefbd")
self.assertSequenceEqual(ecb_encrypt(key, pt, sbox=sbox), ct)
def test_cryptomanager(self):
self.assertSequenceEqual(ecb_encrypt(key, pt, sbox=sbox), ct)
def test_cryptomanager(self):
"""
sbox = "id-GostR3411-94-TestParamSet"
key = hexdec(b"75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B")
"""
sbox = "id-GostR3411-94-TestParamSet"
key = hexdec(b"75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B")
"""
key = hexdec(b"75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B")
sbox = "id-GostR3411-94-TestParamSet"
"""
key = hexdec(b"75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B")
sbox = "id-GostR3411-94-TestParamSet"
for size in (5, 8, 16, 120):
pt = urandom(size)
self.assertSequenceEqual(
for size in (5, 8, 16, 120):
pt = urandom(size)
self.assertSequenceEqual(
"""
sbox = "id-Gost28147-89-TestParamSet"
key = hexdec(b"0475f6e05038fbfad2c7c390edb3ca3d1547124291ae1e8a2f79cd9ed2bcefbd")
"""
sbox = "id-Gost28147-89-TestParamSet"
key = hexdec(b"0475f6e05038fbfad2c7c390edb3ca3d1547124291ae1e8a2f79cd9ed2bcefbd")
"""
sbox = "id-Gost28147-89-TestParamSet"
key = hexdec(b"fc7ad2886f455b50d29008fa622b57d5c65b3c637202025799cadf0768519e8a")
"""
sbox = "id-Gost28147-89-TestParamSet"
key = hexdec(b"fc7ad2886f455b50d29008fa622b57d5c65b3c637202025799cadf0768519e8a")
0x13, 0xcc, 0x55, 0x38, 0xb5, 0x63, 0x32, 0xc5,
0x23, 0xa4, 0xcb, 0x7d, 0x51,
)))
0x13, 0xcc, 0x55, 0x38, 0xb5, 0x63, 0x32, 0xc5,
0x23, 0xa4, 0xcb, 0x7d, 0x51,
)))
encrypted = cnt(key, plaintext, iv=iv, sbox=sbox)
self.assertSequenceEqual(encrypted, ciphertext)
decrypted = cnt(key, encrypted, iv=iv, sbox=sbox)
encrypted = cnt(key, plaintext, iv=iv, sbox=sbox)
self.assertSequenceEqual(encrypted, ciphertext)
decrypted = cnt(key, encrypted, iv=iv, sbox=sbox)
for s in (b"", b"foo", b"foobarbaz"):
with self.assertRaises(ValueError):
cbc_encrypt(key, s, pad=False)
for s in (b"", b"foo", b"foobarbaz"):
with self.assertRaises(ValueError):
cbc_encrypt(key, s, pad=False)
for pt in (b"foo", b"foobarba", b"foobarbaz", 16 * b"x"):
ct = cbc_encrypt(key, pt, iv)
dt = cbc_decrypt(key, ct)
self.assertSequenceEqual(pt, dt)
def test_iv_existence_check(self):
for pt in (b"foo", b"foobarba", b"foobarbaz", 16 * b"x"):
ct = cbc_encrypt(key, pt, iv)
dt = cbc_decrypt(key, ct)
self.assertSequenceEqual(pt, dt)
def test_iv_existence_check(self):
- cbc_decrypt(key, 8 * b"x")
- iv = urandom(8)
- cbc_decrypt(key, cbc_encrypt(key, 8 * b"x", iv))
+ cbc_decrypt(key, BLOCKSIZE * b"x")
+ iv = urandom(BLOCKSIZE)
+ cbc_decrypt(key, cbc_encrypt(key, BLOCKSIZE * b"x", iv))
ct = cbc_encrypt(key, pt)
dt = cbc_decrypt(key, ct)
self.assertSequenceEqual(pt, dt)
ct = cbc_encrypt(key, pt)
dt = cbc_decrypt(key, ct)
self.assertSequenceEqual(pt, dt)