Exemple #1
0
    def _check_encryption(self, rsaObj):
        plaintext = a2b_hex(self.plaintext)
        ciphertext = a2b_hex(self.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))
    def _check_encryption(self, rsaObj):
        plaintext = a2b_hex(self.plaintext)
        ciphertext = a2b_hex(self.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))
Exemple #3
0
    def setUp(self):
        global RSA, Random, bytes_to_long
        from CryptoPlus.PublicKey import RSA
        from CryptoPlus import Random
        from CryptoPlus.Util.number import bytes_to_long, inverse
        self.n = bytes_to_long(a2b_hex(self.modulus))
        self.p = bytes_to_long(a2b_hex(self.prime_factor))

        # Compute q, d, and u from n, e, and p
        self.q = self.n / self.p
        self.d = inverse(self.e, (self.p - 1) * (self.q - 1))
        self.u = inverse(self.p, self.q)  # u = e**-1 (mod q)

        self.rsa = RSA
Exemple #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))
    def setUp(self):
        global RSA, Random, bytes_to_long
        from CryptoPlus.PublicKey import RSA
        from CryptoPlus import Random
        from CryptoPlus.Util.number import bytes_to_long, inverse
        self.n = bytes_to_long(a2b_hex(self.modulus))
        self.p = bytes_to_long(a2b_hex(self.prime_factor))

        # Compute q, d, and u from n, e, and p
        self.q = self.n / self.p
        self.d = inverse(self.e, (self.p-1)*(self.q-1))
        self.u = inverse(self.p, self.q)    # u = e**-1 (mod q)

        self.rsa = RSA
    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))
Exemple #7
0
    def _exercise_public_primitive(self, rsaObj):
        plaintext = a2b_hex(self.plaintext)

        # Test encryption (2 arguments)
        (new_ciphertext2, ) = rsaObj.encrypt(plaintext, "")

        # Test encryption (1 argument)
        if not self.legacy_interface_only:
            (new_ciphertext1, ) = rsaObj.encrypt(plaintext)
            self.assertEqual(new_ciphertext2, new_ciphertext1)
    def _exercise_public_primitive(self, rsaObj):
        plaintext = a2b_hex(self.plaintext)

        # Test encryption (2 arguments)
        (new_ciphertext2,) = rsaObj.encrypt(plaintext, "")

        # Test encryption (1 argument)
        if not self.legacy_interface_only:
            (new_ciphertext1,) = rsaObj.encrypt(plaintext)
            self.assertEqual(new_ciphertext2, new_ciphertext1)
Exemple #9
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))
    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))