Esempio n. 1
0
 def test_ofb_symmetric(self):
     for _ in range(100):
         pt = urandom(randint(0, 16 * 2))
         iv = urandom(8 * 2)
         ciph = GOST3412Magma(urandom(32))
         ct = ofb(ciph.encrypt, 8, pt, iv)
         self.assertSequenceEqual(ofb(ciph.encrypt, 8, ct, iv), pt)
Esempio n. 2
0
 def test_ofb_vectors(self):
     iv = self.iv[:16]
     ciphtext = ""
     ciphtext += "db37e0e266903c83"
     ciphtext += "0d46644c1f9a089c"
     ciphtext += "a0f83062430e327e"
     ciphtext += "c824efb8bd4fdb05"
     self.assertSequenceEqual(
         hexenc(ofb(self.ciph.encrypt, 8, hexdec(self.plaintext), iv)),
         ciphtext,
     )
     self.assertSequenceEqual(
         hexenc(ofb(self.ciph.encrypt, 8, hexdec(ciphtext), iv)),
         self.plaintext,
     )
Esempio n. 3
0
 def test_ofb_vectors(self):
     ciphtext = ""
     ciphtext += "81800a59b1842b24ff1f795e897abd95"
     ciphtext += "ed5b47a7048cfab48fb521369d9326bf"
     ciphtext += "66a257ac3ca0b8b1c80fe7fc10288a13"
     ciphtext += "203ebbc066138660a0292243f6903150"
     self.assertSequenceEqual(
         hexenc(ofb(self.ciph.encrypt, 16, hexdec(self.plaintext),
                    self.iv)),
         ciphtext,
     )
     self.assertSequenceEqual(
         hexenc(ofb(self.ciph.encrypt, 16, hexdec(ciphtext), self.iv)),
         self.plaintext,
     )
Esempio n. 4
0
 def test_ofb_manual(self):
     iv = [urandom(16) for _ in range(randint(2, 10))]
     pt = [urandom(16) for _ in range(len(iv), len(iv) + randint(1, 10))]
     ciph = GOST3412Kuznechik(urandom(32))
     r = [ciph.encrypt(i) for i in iv]
     for i in range(len(pt) - len(iv)):
         r.append(ciph.encrypt(r[i]))
     ct = [strxor(g, r) for g, r in zip(pt, r)]
     self.assertSequenceEqual(
         ofb(ciph.encrypt, 16, b"".join(pt), b"".join(iv)),
         b"".join(ct),
     )
Esempio n. 5
0
 def decrypt(self, ctxt):
     res = gost3413.ofb(self.enc, self.blen, ctxt, self.iv)
     return res
Esempio n. 6
0
 def encrypt(self, text):
     res = gost3413.ofb(self.enc, self.blen, text, self.iv)
     return res