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))
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 _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 _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))