Exemplo n.º 1
0
 def test_generate_2arg(self):
     """RSA (default implementation) generated key (2 arguments)"""
     rsaObj = self.rsa.generate(1024, Random.new().read)
     self._check_private_key(rsaObj)
     self._exercise_primitive(rsaObj)
     pub = rsaObj.publickey()
     self._check_public_key(pub)
     self._exercise_public_primitive(rsaObj)
Exemplo n.º 2
0
 def runTest(self):
     """CryptoPlus.Random.new()"""
     # Import the OSRNG module and try to use it
     from CryptoPlus import Random
     randobj = Random.new()
     x = randobj.read(16)
     y = randobj.read(16)
     self.assertNotEqual(x, y)
Exemplo n.º 3
0
 def test_generate_2arg(self):
     """RSA (default implementation) generated key (2 arguments)"""
     rsaObj = self.rsa.generate(1024, Random.new().read)
     self._check_private_key(rsaObj)
     self._exercise_primitive(rsaObj)
     pub = rsaObj.publickey()
     self._check_public_key(pub)
     self._exercise_public_primitive(rsaObj)
Exemplo n.º 4
0
    def _check_decryption(self, rsaObj):
        plaintext = a2b_hex(self.plaintext)
        ciphertext = a2b_hex(self.ciphertext)

        # Test plain decryption
        new_plaintext = rsaObj.decrypt((ciphertext, ))
        self.assertEqual(b2a_hex(plaintext), b2a_hex(new_plaintext))

        # Test blinded decryption
        blinding_factor = Random.new().read(len(ciphertext) - 1)
        blinded_ctext = rsaObj.blind(ciphertext, blinding_factor)
        blinded_ptext = rsaObj.decrypt((blinded_ctext, ))
        unblinded_plaintext = rsaObj.unblind(blinded_ptext, blinding_factor)
        self.assertEqual(b2a_hex(plaintext), b2a_hex(unblinded_plaintext))
Exemplo n.º 5
0
    def _check_decryption(self, rsaObj):
        plaintext = a2b_hex(self.plaintext)
        ciphertext = a2b_hex(self.ciphertext)

        # Test plain decryption
        new_plaintext = rsaObj.decrypt((ciphertext,))
        self.assertEqual(b2a_hex(plaintext), b2a_hex(new_plaintext))

        # Test blinded decryption
        blinding_factor = Random.new().read(len(ciphertext)-1)
        blinded_ctext = rsaObj.blind(ciphertext, blinding_factor)
        blinded_ptext = rsaObj.decrypt((blinded_ctext,))
        unblinded_plaintext = rsaObj.unblind(blinded_ptext, blinding_factor)
        self.assertEqual(b2a_hex(plaintext), b2a_hex(unblinded_plaintext))
Exemplo n.º 6
0
    def _exercise_primitive(self, rsaObj):
        # Since we're using a randomly-generated key, we can't check the test
        # vector, but we can make sure encryption and decryption are inverse
        # operations.
        ciphertext = a2b_hex(self.ciphertext)

        # Test decryption
        plaintext = rsaObj.decrypt((ciphertext, ))

        # Test encryption (2 arguments)
        (new_ciphertext2, ) = rsaObj.encrypt(plaintext, "")
        self.assertEqual(b2a_hex(ciphertext), b2a_hex(new_ciphertext2))

        # Test encryption (1 argument)
        if not self.legacy_interface_only:
            (new_ciphertext1, ) = rsaObj.encrypt(plaintext)
            self.assertEqual(b2a_hex(ciphertext), b2a_hex(new_ciphertext1))

        # Test blinded decryption
        blinding_factor = Random.new().read(len(ciphertext) - 1)
        blinded_ctext = rsaObj.blind(ciphertext, blinding_factor)
        blinded_ptext = rsaObj.decrypt((blinded_ctext, ))
        unblinded_plaintext = rsaObj.unblind(blinded_ptext, blinding_factor)
        self.assertEqual(b2a_hex(plaintext), b2a_hex(unblinded_plaintext))
Exemplo n.º 7
0
    def _exercise_primitive(self, rsaObj):
        # Since we're using a randomly-generated key, we can't check the test
        # vector, but we can make sure encryption and decryption are inverse
        # operations.
        ciphertext = a2b_hex(self.ciphertext)

        # Test decryption
        plaintext = rsaObj.decrypt((ciphertext,))

        # Test encryption (2 arguments)
        (new_ciphertext2,) = rsaObj.encrypt(plaintext, "")
        self.assertEqual(b2a_hex(ciphertext), b2a_hex(new_ciphertext2))

        # Test encryption (1 argument)
        if not self.legacy_interface_only:
            (new_ciphertext1,) = rsaObj.encrypt(plaintext)
            self.assertEqual(b2a_hex(ciphertext), b2a_hex(new_ciphertext1))

        # Test blinded decryption
        blinding_factor = Random.new().read(len(ciphertext)-1)
        blinded_ctext = rsaObj.blind(ciphertext, blinding_factor)
        blinded_ptext = rsaObj.decrypt((blinded_ctext,))
        unblinded_plaintext = rsaObj.unblind(blinded_ptext, blinding_factor)
        self.assertEqual(b2a_hex(plaintext), b2a_hex(unblinded_plaintext))