コード例 #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))
コード例 #2
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))
コード例 #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
コード例 #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))
コード例 #5
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
コード例 #6
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))
コード例 #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)
コード例 #8
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)
コード例 #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))
コード例 #10
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))