If you create an rsa.PrivateKey, then call json.Marshal, then call json.Unmarshal, the resulting key "works" but is 3X slower for signing operations. The problem is that Go 1.20 added private fields to rsa.PrecomputedValues which do not get round-tripped. The resulting keys need to have key.Precompute() called to restore their performance. The following test fails on Go 1.20, but works on Go 1.19. The included benchmark demonstrates the performance problem.
From Issue #59442 , it seems like we may want to preserve the existing behavior: #59442 (comment)
It seems like any of the obvious solutions involve satisfying the json.Unmarshaler interface, which will require adding a new API, and therefore needs to go through the proposal process. Unless @FiloSottile you had another idea?
@rolandshoemaker How about atomic.Pointer? Is it fine to use it in crypto/rsa?
Edit: Note that this issue might still affect other marshallers (yaml, ...) when only adding custom json.Unmarshaler.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
If you create an
rsa.PrivateKey
, then calljson.Marshal
, then calljson.Unmarshal
, the resulting key "works" but is 3X slower for signing operations. The problem is that Go 1.20 added private fields torsa.PrecomputedValues
which do not get round-tripped. The resulting keys need to havekey.Precompute()
called to restore their performance. The following test fails on Go 1.20, but works on Go 1.19. The included benchmark demonstrates the performance problem.From Issue #59442 , it seems like we may want to preserve the existing behavior: #59442 (comment)
What did you expect to see?
The test should pass, and the benchmark should show the two cases have approximately the same performance, like on Go 1.19:
What did you see instead?
The test fails, showing that the round tripped key has nil fields:
The benchmark shows ~3X slower signing until calling
Precompute()
:The text was updated successfully, but these errors were encountered: