Why, after using 'CryptSetHashParam', can I no longer add data to my MD5 hash object?

You can't do it because it doesn't make any sense. CryptGetHashParam with the HP_HASHVAL option finalizes the hash, so there is no way to add data to it. If you want to "fork" the hash so that you can finalize it at some point as well as add data to it, you must duplicate the hash object prior to finalizing.

Then you add the data to one of the hash objects and finalize the other. For example, you might do this if you wanted record a cumulative hash after every 1024 bytes of a data stream. You should not call CryptSetHashParam on the hash object that you are continuing to add data to.

You can't do it because it doesn't make any sense. CryptGetHashParam with the HP_HASHVAL option finalizes the hash, so there is no way to add data to it. If you want to "fork" the hash so that you can finalize it at some point as well as add data to it, you must duplicate the hash object prior to finalizing.

Then you add the data to one of the hash objects and finalize the other. For example, you might do this if you wanted record a cumulative hash after every 1024 bytes of a data stream. You should not call CryptSetHashParam on the hash object that you are continuing to add data to.

CryptSetHashParam with the HP_HASHVAL option is a brutal hack to overcome a limitation in the CryptoAPI. The CryptoAPI will only sign a hash object, so if you want to sign some data that might have been hashed or generated outside of CAPI, you have to "jam" it into a hash object. EDIT: Based on your comment, I think you are looking for a way to serialize the hash object.

I cannot find any evidence that CryptoAPI supports this. There are alternatives, however, that are basically variants of my "1024 bytes" example above. If you are hashing a sequence of files, you could simply compute and save the hash of each file.

If you really need to boil it down to one value, then you can compute a modified hash where the first piece of data you hash for file I is the finalized hash for files 0, 1, 2, ..., i-1. So: H-1 = empty, = MD5 (-1 || filei) As you go along, you can save the last successfully computed In case of interruption, you can restart at file i+1. Note that, like any message digest, the above is completely sensitive to both order and content.

This is something to consider on a dynamically changing file system. If files can be added or changed during the hashing operation, the meaning of the hash value will be affected. It might be rendered meaningless.

You might want to be certain that both the sequence and content of the files you are hashing is frozen during the entire duration of the hash.

I suppose I should explain why I am trying to initialise a hash object with a pre-defined starting hash value to highlight the problem I am trying to overcome. Data I am hashing is coming from a NAS contained in potentialy hundreds of files. After hashing the data in each file, I am looking to preserve the MD5 hash locally so that if the hashing application suffers an interuption and is restarted, a new hash object is initialised with the hash value at the point of interuption thus preventing the need to start hashing from the beginning of the NAS again.Is there a way to do this?

– Graham Schofield Feb 11 '10 at 9:20 If no more files were added to the NAS and MD5 hashing was performed on all of the data contained in all the files without interruption, wouldn't the resulting hash value be different if all the data was hashed again, but this time with interruptions encountered. If I interpreted what was said before correctly, you are suggesting that the hash value that was computed prior to an interruption is fed into the hash object prior to the next file data. Wouldn't that result in a hash being computed on the hash data, resulting in a different final hash value to that of uninterrupted hashing?

– Graham Schofield Feb 12 '10 at 10:46 You keep track of the last successfully hashed file. When an interruption occurs in the middle of hashing file i+1, you simply discard the partial result and start over, recomputing MD5(H_i || file_{i+1}) = H_{i+1}. – GregS Feb 13 '10 at 0:51.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions