Community articleHash_Hash function
Added by IBM contributorIBM on July 26, 2013
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

Description

This function hashes a message using the hashing algorithm of your choice.

Function

   r_error Hash_Hash(
      Hash *theHashObject,
      r_byte *theMessage,
      r_long messageSize,
      r_byte **hashedMessage,
      r_long *hashedSize);


Parameters

Table 1. hash parameters
ExpressionTypeDescription
theHashObject Hash*The hash object you are using to hash the message.
theMessager_byte*The message you want to hash.
messageSize r_longThe size of the message you want to hash, in bytes.
hashedMessage r_byte**The hashed message that is generated by the function. Note that this string must be freed.
hashedSize r_long*The size of the hashed message, in bytes.


Returns

OK on success or an error code on failure.

Example

The following example uses UFLGetSignature and Signature_GetDataByPath to get the signer's identity from the signature object. It then retrieves the signer's shared secret from a database, and hashes that secret using the Hash_Hash function. Next, it calls UFLValidateHMACWithHashedSecret to validate the signature. Finally, it releases the signature object.
   r_error checkSignature(formNodeP theSignatureNode, Certificate *theServerCert, 
      Hash *theHashObject, 
   r_short *validation)
   {
   Signature *theSignatureObject;
   r_charP theSecret;
   r_charP signerCommonName;
   r_boolean encodedData;
   r_byte *theSecret;
   r_long secretSize;
   r_byte *hashedSecret;
   r_long hashedSize;
   SecurityUserStatusType theStatus;
   r_error error;
 
'      if ((error = UFLGetSignature(theSignatureNode, &theSignatureObject))
         != OK)
      {
         fprintf(stderr, "UFLGetSignature error %ld.\n", error);
         return(error);
      }
      if ((error = Signature_GetDataByPath(theSignatureObject, 
         "SigningCert: Subject: CN", NOTOK, &encodedData, 
         &signerCommonName)) != OK)
      {
         fprintf(stderr, "Signature_GetDataByPath error %ld./n", error);
         return(error);
      }
 
      /* Include external code that matches the signer's identity to a 
         shared secret, sets *theSecret to match, and sets secretSize to 
         the size of the secret.  This is most likely a database 
         lookup. */
 
      if ((error = Hash_Hash(theHashObject, theSecret, secretSize, 
         &hashedSecret, &hashedSize)) != OK)
      {
         frprintf(stderr, "Hash_Hash error %hd./n", error);
         return(NOTOK);
      }
      
      if ((error = UFLValidateHMACWithHashedSecret(theSignature, 
         hashedSecret, hashedSize, theServerCert, &theStatus, validation)) 
         != OK)
      {
         fprintf(stderr, "UFLValidateHMACWithHashedSecret error %hd.\n", 
            error);
         return(NOTOK);
      }
 
      /* Check the status in case the process required user input. */
 
      if (theStatus != SUSTATUS_OK)
      {
         fprintf(stderr, "User input required to sign form./n");
         return(NOTOK);
      }
 
      cp_free(signerCommonName);
      cp_free(hashedSecret);
 
      /* Release the reference to the signature object. */
 
      IFSObject_ReleaseRef((IFSObject*)theSignature);
 
      return(OK);
   }


Parent topic:
Hash functions