Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SHA512 hashing files > 2GB in a Firefox extension - is it possible?

Status
Not open for further replies.
Dec 8, 2003
17,047
GB
I'm working on a Firefox extension at the moment, and one of the things it does is hash files with the SHA512 algorithm, using Fx's nsICryptoHash interface.

It works really well, but I've just discovered that the hashing routines don't appear to work on files bigger than 2,147,483,647 bytes (the maximum value of a 32-bit signed int).

Unfortunately the docs ( are a bit misleading as they say that by passing in PR_UINT32_MAX, the whole file will be read - which is not what I'm seeing for files bigger than that limit.

As soon as I try and hash any file bigger than 2GB, I get the following error:

Code:
Error: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsICryptoHash.updateFromStream]

It occurs on the following line (the whole code sample can be found by visiting the link I gave above):

Code:
ch.updateFromStream(istream, PR_UINT32_MAX);

Even if I pass in a value greater than PR_UINT32_MAX, I still get the same error at the same line.

Which leaves me with two questions:

1) Can anyone think of a way around this problem while still performing the hashing in a Fx extension (that way it should work cross-OS, rather than calling out to an external tool where we have no idea what users will have on their PCs), and

2) If I were to hash smaller portions of the file, is their a way I can combine the individual hashes to still come up with the same checksum overall? I don't know enough about how SHA512 works to know.

Thanks!

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top