News for hackers. Stuff that matters.
Re:Whatever happened to SHA-256 support in Git? by donatj on Thursday June 23, 2022 @01:45PM (#31852651)
Potentially stupid question, would it be reasonable to use SHA-256 truncated to the first 40 digits?

It seems like that could ease much of the migration problems if it's not a problem?

Re:Whatever happened to SHA-256 support in Git? by Zamicol on Thursday June 23, 2022 @02:50PM (#31853570)
I don't believe the length is a major issue. It's "upgrading" references to a new hashing algorithm that's the issue.

If for some reason length was an issue, a base64 encoded 256 bit string, like a SHA-256 digest, is 43 characters. That too can be truncated to 40 characters, which has 238 bits of security. SHA-256 is not only a better hashing algorithm than SHA-1 but it could also result in higher effective security even when truncated.

Re:Whatever happened to SHA-256 support in Git? by stingraycharles on Thursday June 23, 2022 @02:04PM (#31852915)
I found this, which says that the SHA algorithm allows for truncation: https://csrc.nist.gov/publications/detail/sp/800-107/rev-1/f...
Re:Whatever happened to SHA-256 support in Git? by Dylan16807 on Thursday June 23, 2022 @02:35PM (#31853366)
Not just allows, it becomes more secure when you truncate.
Re:Whatever happened to SHA-256 support in Git? by tatersolid on Thursday June 23, 2022 @02:59PM (#31853678)
Truncated SHA-* hashes are more secure against length-extension attacks, but are very much less secure against collision and pre-image attacks (which are more important in most scenarios).
Re:Whatever happened to SHA-256 support in Git? by Dylan16807 on Thursday June 23, 2022 @03:20PM (#31853973)
But also, 256 is overkill for collisions and pre-image.

There's a point where truncating starts to make it weaker, but when you first start chopping off bytes the benefits outweigh the drawbacks.

Re:Whatever happened to SHA-256 support in Git? by neon_electro on Thursday June 23, 2022 @02:50PM (#31853559)
Care to elaborate? This is not something I would've intuited.
Re:Whatever happened to SHA-256 support in Git? by bawolff on Thursday June 23, 2022 @02:56PM (#31853630)
Presumably they are referring to length extension attacks. You can't pull them off if you truncate. https://en.m.wikipedia.org/wiki/Length_extension_attack

Generally though length ext attacks have a solution - HMAC, which is much more secure than truncate.

The more you truncate, the more vulnerable you are to birthday attacks (practically speaking you would have to truncate quite a lot)

Re:Whatever happened to SHA-256 support in Git? by kzrdude on Thursday June 23, 2022 @03:15PM (#31853905)
The canonical solution is SHA-512/256 i.e 512 truncated to 256 bits where "nothing is lost" compared to SHA-256 and something is gained. It might even be faster (due to the 64-bit word formulation of SHA-512) in some implementations.
Re:Whatever happened to SHA-256 support in Git? by NovemberWhiskey on Thursday June 23, 2022 @03:35PM (#31854168)
Generally is faster (fewer rounds per byte). If you have 256 bits available for your hash and you're on a 64 bit architecture, I've yet to see a case where you're not better off for performance and security choosing SHA-512/256 over SHA-256, assuming you have the choice.
Re:Whatever happened to SHA-256 support in Git? by ztorkelson on Thursday June 23, 2022 @05:41PM (#31855498)
Is this still true? I understood SHA256 to be faster than SHA512 due to hardware acceleration on current CPUs; dedicated instructions exist for the former but not the latter.
Re:Whatever happened to SHA-256 support in Git? by NovemberWhiskey on Friday June 24, 2022 @01:19PM (#31866026)
It seems like it's not true on a MacBook with the Apple M1 processor; SHA-256 is now significantly faster. It still seems to be true on a couple of Intel machines I have access to.
Re:Whatever happened to SHA-256 support in Git? by bawolff on Friday June 24, 2022 @08:02PM (#31871042)
Googling i noticed there seems to be a bug in openssl where it does not use optimized sha-512 on m1 (but does for sha256) - https://github.com/openssl/openssl/issues/14897 so that might be the explanation.

Also i think the length of the input matters when comparing sha256 vs sha512.

Re:Whatever happened to SHA-256 support in Git? by jjtheblunt on Thursday June 23, 2022 @03:30PM (#31854109)
that makes collisions more likely
Re:Whatever happened to SHA-256 support in Git? by pornel on Thursday June 23, 2022 @03:47PM (#31854279)
Sigh, no it doesn't in any meaningful way.

160 bit output, without a cryptographic weakness, is good for about 30 trillion commits per second continuously for 1000 years.

For SHA the cryptographic strength isn't primarily from the length of the hash, but from the internal number of rounds is (e.g. 160-bit SHA-1 with fewer rounds has been badly broken way earlier, and 160-bit SHA-1 with more rounds would be safer).

Cryptographic hashes are designed to be safe to truncate and still have all the safety the truncated length can provide. It's basically a requirement for them being cryptographically strong. Even in the SHA-2 family, the SHA-224 and SHA-384 are just truncated versions of larger hashes.

Re:Whatever happened to SHA-256 support in Git? by dspillett on Thursday June 23, 2022 @03:58PM (#31854407)
It makes random collisions more likely when comparing truncated SHA256 to pure SHA256, but given the collisions and pre-image attacks shown so far is truncated SHA256 still safer than SHA1 in that respect? I have seen an article that claimed so (sorry, I can't re-find it ATM so I can't offer it for criticism, if anyone else has good information either way please respond with relevant links), and it is immune to extension attacks which is a significant advantage if this is part of your threat sensitivity surface and SHA1 is used without other protective wrappers like HMAC.
Re:Whatever happened to SHA-256 support in Git? by bawolff on Thursday June 23, 2022 @04:44PM (#31854909)
Truncated sha256 is safer than sha-1 (depending of course on how much you truncate it, but given context lets assume truncating to size of sha-1 - 160 bits).

SHA-1 is quite broken at this point. SHA-256 is not. There aren't any practical non-generic attacks on full sha-256 and thus there wouldn't be any on the truncated version. The Wikipedia article goes into the different attacks on the two algorithms.

That said, if your concern is length extension attacks - strongly reccomend using sha-512/256 instead of trying to do your own custom thing.