예제 #1
0
 def test_cbc_symmetric(self):
     for _ in range(100):
         pt = pad2(urandom(randint(0, 16 * 2)), 16)
         iv = urandom(8 * 2)
         ciph = GOST3412Magma(urandom(32))
         ct = cbc_encrypt(ciph.encrypt, 8, pt, iv)
         self.assertSequenceEqual(cbc_decrypt(ciph.decrypt, 8, ct, iv), pt)
예제 #2
0
 def test_cbc_vectors(self):
     ciphtext = ""
     ciphtext += "96d1b05eea683919"
     ciphtext += "aff76129abb937b9"
     ciphtext += "5058b4a1c4bc0019"
     ciphtext += "20b78b1a7cd7e667"
     self.assertSequenceEqual(
         hexenc(
             cbc_encrypt(self.ciph.encrypt, 8, hexdec(self.plaintext),
                         self.iv)),
         ciphtext,
     )
     self.assertSequenceEqual(
         hexenc(cbc_decrypt(self.ciph.decrypt, 8, hexdec(ciphtext),
                            self.iv)),
         self.plaintext,
     )
예제 #3
0
 def test_cbc_vectors(self):
     ciphtext = ""
     ciphtext += "689972d4a085fa4d90e52e3d6d7dcc27"
     ciphtext += "2826e661b478eca6af1e8e448d5ea5ac"
     ciphtext += "fe7babf1e91999e85640e8b0f49d90d0"
     ciphtext += "167688065a895c631a2d9a1560b63970"
     self.assertSequenceEqual(
         hexenc(
             cbc_encrypt(self.ciph.encrypt, 16, hexdec(self.plaintext),
                         self.iv)),
         ciphtext,
     )
     self.assertSequenceEqual(
         hexenc(
             cbc_decrypt(self.ciph.decrypt, 16, hexdec(ciphtext), self.iv)),
         self.plaintext,
     )
예제 #4
0
 def decrypt(self, ctxt):
     res_padded = gost3413.cbc_decrypt(self.dec, self.blen, ctxt, self.iv)
     res = self.unpadding(res_padded)
     return res