示例#1
0
 def test_ctr_symmetric(self):
     for _ in range(100):
         pt = urandom(randint(0, 16 * 2))
         iv = urandom(4)
         ciph = GOST3412Magma(urandom(32))
         ct = ctr(ciph.encrypt, 8, pt, iv)
         self.assertSequenceEqual(ctr(ciph.encrypt, 8, ct, iv), pt)
示例#2
0
 def test_ctr_vectors(self):
     ciphtext = ""
     ciphtext += "f195d8bec10ed1dbd57b5fa240bda1b8"
     ciphtext += "85eee733f6a13e5df33ce4b33c45dee4"
     ciphtext += "a5eae88be6356ed3d5e877f13564a3a5"
     ciphtext += "cb91fab1f20cbab6d1c6d15820bdba73"
     iv = self.iv[:8]
     self.assertSequenceEqual(
         hexenc(ctr(self.ciph.encrypt, 16, hexdec(self.plaintext), iv)),
         ciphtext,
     )
     self.assertSequenceEqual(
         hexenc(ctr(self.ciph.encrypt, 16, hexdec(ciphtext), iv)),
         self.plaintext,
     )
示例#3
0
 def test_ctr_vectors(self):
     ciphtext = ""
     ciphtext += "4e98110c97b7b93c"
     ciphtext += "3e250d93d6e85d69"
     ciphtext += "136d868807b2dbef"
     ciphtext += "568eb680ab52a12d"
     iv = self.iv[:4]
     self.assertSequenceEqual(
         hexenc(ctr(self.ciph.encrypt, 8, hexdec(self.plaintext), iv)),
         ciphtext,
     )
     self.assertSequenceEqual(
         hexenc(ctr(self.ciph.encrypt, 8, hexdec(ciphtext), iv)),
         self.plaintext,
     )
示例#4
0
 def decrypt(self, ctxt):
     res = gost3413.ctr(self.enc, self.blen, ctxt, self.iv)
     return res
示例#5
0
 def encrypt(self, text):
     res = gost3413.ctr(self.enc, self.blen, text, self.iv)
     return res