Is using two different hash functions a good way to check file integrity?

I have a website where users can upload their files; they are stored on the server and their metadata recorded in the database. I perform some simple integrity checks, i.e. "Is the contents of this file byte by byte identical, as when downloading it?"

Example: for the content, the userfile.jpghash is MD5 39f9031a154dc7ba105eb4f76f1a0fd4, and SHA-1 hash 878d8d667721e356bf6646bd2ec21fff50cdd4a9. If the contents of this file change, but has the same MD5 hash before and after, is it possible that the SHA-1 hash will also remain the same? (With hashing, sometimes you can get a hash collision - can this happen with two different hashing algorithms at the same time?)

Or does it compute two different hashes for a file without meaning (and I should try a different integrity checker)?


Edit: I am not really worried about accidental damage, but I have to prevent users from quietly changing the file ( birthday attack and friends).

I'll probably go with one hash, SHA-512 - checks do not happen, which is often a performance bottleneck, and anyway, "As Bruce Schneier says, there are quite fast and insecure systems there. - @MichaelGG in the comments."

+5
source share
6 answers

MD5, , , , . , , SHA256 SHA512, .

: , ; , , . , MD5 (, , ?), , , SHA256.

2: , -, : 1/2 ^ n. 1/2 ^ (/2). , 128- , , 2 ^ 64. . .

+7

MD5 . , , SHA1. , -, , MD5 .

, .

+4

(, / ) . 128 = 2 -128 , .

(, , - ), , .

MD5 "" , , ( " " MD5 ).

( ) "" , X, - Y , search (MD5 " " ). ( , ​​, ​​, .)

MD5 , , - MD5 arbritrary SHA1 .

: " " " ". , , , , . 256- 128- . (, , SHA1 - 160 , ). , - , 256- isn . , , .

, , MD5 .

: : 1 2 3, MD5 , RFC4270, NIST SHA-3 " SHA-3 ".

+2

, MD5 , SHA1 ( ) . , , ( , ), , , , .

, , , ; ( , ), , , .

: , ; - , . , , , , , , , .

+1

MD5 1/(2 ^ 128), SHA-1 1/(2 ^ 160), 1/(2 ^ 128) 1/(2 ^ 288), , 1/(2 ^ 288), .

, .

EDIT: , MD5 1 , MD5 SHA-1 . SHA-1 2 ^ 69 .

+1

-, MD5- SHA-1 , . (ballpark) 2 ^ 128, 2 ^ 256.

, .

This is the equivalent of moving from 128-bit to 256-bit encryption to avoid accidentally guessing your 128-bit key.

+1
source

All Articles