Skip to content
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

Proposal: Interested in writing a modular exponentiation function in the Math package #39430

Closed
brayo-pip opened this issue Jun 5, 2020 · 4 comments
Labels
Milestone

Comments

@brayo-pip
Copy link

@brayo-pip brayo-pip commented Jun 5, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.2 windows/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

I recently implemented RSA in go and discovered that Go does not have a modular exponentiation function in its math package. Am willing to write the code, I just don't know why it was not intially included. Is there something that am missing, really open to any suggestions and advice

@brayo-pip brayo-pip changed the title Interested in writing an modular exponentiation function the Math package Interested in writing a modular exponentiation function the Math package Jun 5, 2020
@brayo-pip brayo-pip changed the title Interested in writing a modular exponentiation function the Math package Interested in writing a modular exponentiation function in the Math package Jun 5, 2020
@brayo-pip brayo-pip changed the title Interested in writing a modular exponentiation function in the Math package Proposal: Interested in writing a modular exponentiation function in the Math package Jun 5, 2020
@gopherbot gopherbot added this to the Proposal milestone Jun 5, 2020
@gopherbot gopherbot added the Proposal label Jun 5, 2020
@randall77
Copy link
Contributor

@randall77 randall77 commented Jun 5, 2020

math/big.Exp has a modular exponentiation mode.

@brayo-pip
Copy link
Author

@brayo-pip brayo-pip commented Jun 7, 2020

@randall77 it doesn't work with normal integers

@randall77
Copy link
Contributor

@randall77 randall77 commented Jun 7, 2020

I'm not sure what you mean by "normal integers". Do you mean the built in type int? True, but if you're doing RSA you certainly want more bits than int can contain.

The math package is for floats, not ints.

You can always do x**y%m with big.NewInt(0).Exp(big.NewInt(x), big.NewInt(y), big.NewInt(m)).Int64().

@rsc
Copy link
Contributor

@rsc rsc commented Jun 10, 2020

As Keith mentioned, the answer is to use math/big (and if you are doing crypto, use numbers larger than 64 bits, or better don't roll your own crypto).

As Keith also said, the math package is for floats, where modular exponentiation is not terribly useful.

Closing this issue (feature already exists).

@rsc rsc closed this Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.