5 ms·
Update on Go 1.1 crypto performance
- wereHamster 14y agoNot really relevant for hashes, but Go also has native implementation of selected ciphers (eg. AES). Are those implementations constant-time? If not then they are vulnerable to timing attacks. People have put a lot effort into making OpenSSL ciphers constant-time. This effort was pushed by people working at Google. This guy works at Google and regularly posts about crypto stuff they are working on: http://www.imperialviolet.org/ http://www.imperialviolet.org/.
- jgrahamc 14y agoThe blog you link to belongs to Adam Langley who works on Go's crypto stuff (he's user agl here). Go has a rather nice crypto/subtle package that contains constant-time implementations of primitives. http://golang.org/pkg/crypto/subtle/ http://golang.org/pkg/crypto/subtle/
- enneff 14y agoAdam doesn't just work on the Go crypto packages. He is almost solely responsible for writing them.
- agl 14y agoI'm afraid that the general AES implementation in Go is not constant-time. If you have a machine with AESNI instructions then they will be used and they are constant time. AES is terribly hard to implement in a performant and constant-time fashion. The OpenSSL work is very impressive but, at least the bits that I'm aware of, are still very platform dependent and sometimes work only for certain modes (i.e. counter mode). Patches to implement Käsper and Schwabe's or Mike Hamburg's AES designs would be welcome, of course! RC4 isn't constant time, but that's not the biggest problem with RC4. All common hash functions are. If you need constant-time crypto and aren't tied to implementing an existing protocol then there is an implementation of NaCl's box[1] and secretbox in the go.crypto subrepo. Otherwise, the modexp isn't constant-time, but RSA secret operations are blinded (hopefully correctly). P-224 is constant time, but P-{256,384,521} are generic code and are not. (I have a Go suitable P-256 design ready if I can find the time.) In general, Go has not had nearly the review that OpenSSL has had and caution is warranted because of that. [1] http://godoc.org/code.google.com/p/go.crypto/nacl/box http://godoc.org/code.google.com/p/go.crypto/nacl/box
- deleted 14y ago[deleted]
- Spooky23 14y agoThere seem to be alot of corner cases where well-intentioned folks who follow the rules, but don't have encryption subject matter expertise can find themselves with some corner-case problem with encryption. Oftentimes we rely on third parties to get it right, but who knows whether they have or not? Are there good best practices or products out there to implement and evaluate encryption implementations? We use FIPS-140 validated modules, but is that enough?
- Jabbles 14y agoWhat did the Go team change to do this? Compiler optimizations or code changes? SIMD instructions?
- jgrahamc 14y agoAMD64 and 386 assembly implementations. My blog post links to the actual changes.
- drivebyacct2 14y agoOh, I assumed some of it was from the GC/scheduler work, or mostly just the asm impls?
- dchest 14y agoWhile not related to these ASM implementations, the code generator for Go code has also been improved: e.g. it now can generate rotatation instructions, which helps SHA-2 and some other crypto primitives.
- kzrdude 14y agoYup that's absolutely essential for most block ciphers and similar crypto (i.e. hash functions).
- minopret 14y agoMy understanding is that all three of these algorithms MD5, SHA1, and RC4 are inherently difficult to parallelize. The result cannot be computed by splitting the input, processing the pieces separately, and then combining the results. So they would not get the benefit of using "goroutines" rather than threads, a benefit which is important to the performance of many Go programs.
- enneff 14y agoGoroutines are not primarily about performance, they are for modelling concurrent processes in a natural way. This can have a performance in some cases, but I wouldn't classify goroutines the way you have.
- rubinelli 14y agoExcuse my ignorance, but could you use goroutines with different algorithms and pick the one that finishes first? Perhaps not in the case of MD5/SHA1, but for problems that have some algorithms that are very fast most of the time, but have a pathological worst case?
- jgrahamc 14y agoYes, you could do that. It would be very simple to give the same channel to two goroutines. Each goroutine would transmit the solution on the channel. You would just wait around to get the first item off the channel. Toy example: http://play.golang.org/p/imM9nOwer_ http://play.golang.org/p/imM9nOwer_
- numbernein 14y agoGo has no way to abort a goroutine so if you tried multiple algorithms you would use total CPU time for all algorithms. Unlike actual threads Go gives no assurance that goroutines are preemptively scheduled, so doing so might take worst case time anyway. Even worse, there is no guarantee that new goroutines run next so doing so could introduce a scheduling delay. So basically it would be a terrible idea to do this in Go. With C/pthreads it might have some use in some really exceptional case. These are all reasons of course why goroutines are a bad idea. They should have just used threads, but apparently they wanted to support 32-bit architectures or some archaic OSes where threads have a high unit cost.
- dchest 14y agoThis post should be called "Go 1.1 old broken crypto performance" ;-) If you're designing a new system, there's no sane reason to use MD5, SHA1, or RC4. These performance improvements, though, are good for the native TLS implementation. There are some small improvements to SHA-2, though, in Go 1.1.
- carbocation 14y ago> This post should be called "Go 1.1 old broken crypto performance" ;-) If you're designing a new system, there's no sane reason to use MD5, SHA1, or RC4.* I think your post is being downvoted because it seems to conflate cryptographic primitives with tools that you can use without modification to safely store a password.
- dchest 14y agoI ported scrypt to Go (https://code.google.com/p/go/source/browse/scrypt/scrypt.go?repo=crypto https://code.google.com/p/go/source/browse/scrypt/scrypt.go?...), so I know how to store passwords ;-) This has nothing to do with passwords. You can read about brokenness of RC4, MD5, or SHA1 in their respective Wikipedia articles.
- carbocation 14y agoFirst, thanks for your contribution. Second, I didn't downvote you. Third, the question was never whether you knew how to store a password. There are many reasons to need to be able to use even 'broken' primitives (esp. for compatibility with legacy apps or conversion), which makes them valuable (or at least necessary) for some apps. This is why I was guessing that your post was focused on passwords.
- dchest 14y agoI understand. I also said that there's no reason to use them for _new_ systems. BTW, suggested reading: http://cr.yp.to/talks.html#2013.03.12 http://cr.yp.to/talks.html#2013.03.12 ("Failures of secret-key cryptography").