-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
math/big: panic when signing with unusual RSA key sizes #13973
Comments
@rsc is this a new issue that was not backported to 1.5.3? At least for go on tip I can not reproduce a crash with the attached program. |
Here is some code that triggers this panic Go 1.5.3 every time, but not on current tip or Go 1.5.2: package main
import (
"fmt"
"math/big"
)
func main() {
x, _ := new(big.Int).SetString("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000006", 16)
y, _ := new(big.Int).SetString("3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0c", 16)
m, _ := new(big.Int).SetString("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", 16)
r := new(big.Int).Exp(x, y, m)
fmt.Printf("%x\n", r)
} Go 1.5.3:
Go 1.5.2:
Go tip (1f7e3cf):
|
If i edit the panic message:
len(x) != n |
This is fixed in 1.6 and at tip; it appears to occur in 1.5.3 and 1.5.4. See below for a diff for a local fix if desired. The diff is basically the backport of changes to the Montgomery code. Closing.
|
Go version 1.5.3, reproduced both with official
go1.5.3.linux-amd64.tar.gz
package and toolchain built from source also on Linux/AMD64.When I use an RSA key with an unusual size, say 1028 or 1032 bits, I often encounter a panic in math/big:
math/big: mismatched montgomery number lengths
. The frequency of the occurrence seems to depend on the keysize but many such panics can be observed in 100 runs.This does not occur with more common key sizes, say powers of two or small integer multiples of 256. I have attached a small program that can be used to observe and reproduce the issue.
mont.zip
The text was updated successfully, but these errors were encountered: