title: Python cryptography RSASSA PSS signature returns not valid when check with pycrypto APIs
body: <p>I'm trying to build a wrapper program around Crypto modules of python for testing and generation of test vectors for a hardware implementation. On the hardware RSASSA_PSS with SHA256 data hash and MGF1 SHA1 identifier is used.</p>
  
  <p>I get a valid signature response from the signature generated by pycrypto while the signature seems to be invalid in case of cryptography module.</p>
  
  <p>The below implementation is for pycrpto:</p>
  
  <pre><code>from Crypto.Hash import SHA256
  from Crypto.Signature import PKCS1_PSS
  import binascii
  
  string = "ABCD"
  message = bytes.fromhex(string)
  digest = SHA256.new()
  digest.update(message)
  print(digest.hexdigest())
  private_key = False
  
  with open ("RSATest_private.pem", "rb") as myfile:
      private_key = RSA.importKey(myfile.read())
  
  # Load private key and sign message
  signer = PKCS1_PSS.new(private_key)
  sig = signer.sign(digest)
  print(binascii.hexlify(sig))
  </code></pre>
  
  <p>and the below implementation is for cryptogrpahy module:</p>
  
  <pre><code>from cryptography.hazmat.backends import default_backend
  from cryptography.hazmat.primitives import serialization
  from cryptography.hazmat.primitives.asymmetric import padding
  from cryptography.hazmat.primitives.asymmetric import utils
  from cryptography.hazmat.primitives import hashes
  import binascii
  
  digestAlg_obj = hashes.SHA256()
  digest_obj = hashes.Hash(self.digestAlg_obj, backend = default_backend())
  digest_obj.update(bytes.fromhex('ABCD'))
  digest_bytv = digest_obj.finalize()
  print(binascii.hexlify(sha256_data))
  
  with open(RSATest_private.pem, "rb") as key_file:
      self.prvKey_obj = serialization.load_pem_private_key(key_file.read(),password=None,backend=default_backend())
  signature_bytv = self.prvKey_obj.sign(digest_bytv,padding.PSS(mgf = padding.MGF1(hashes.SHA1()),salt_length=padding.PSS.MAX_LENGTH),utils.Prehashed(hashes.SHA256()))
  print(binascii.hexlify(signature_bytv))
  </code></pre>
  
  <p>I understand that the signatures obtained are not the same due to the randomness involved in the generation for PSS algorithm. The algorithm setting in both the cases is the same.</p>
  
  <p>The HASH value from SHA256 for the data match in both the modules, but the signature generated when checked on the hardware returns invalid in case of cryptography module.</p>
  
  <p> </p>
  
  <p>Is something wrong with the parameter usage in case of cryptography module?</p>
  
  <p>From the documentation of the pycrypto module, I see that SHA1 is used for mgf1 and the salt length also equals the maximum length of the hash algorithm.</p>
  
  <p>So using the same values in cryptography module should provide me a valid signature.</p>
  
  <p>Also verifying the signature generated by cryptography APIs return sign invalid when checked using the corresponding public key with the pycrypto APIs.</p>
  
  <p>I have tried to generate signature with mgf1 with hash Alg of sha256 as well just to check with the latest predominant embedded hardware implementations but with no progress here as well.</p>
  
  <p>Used python3.6, pycrypto v2.6.1 and cryptography v2.2.2</p>