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

BigInt have no binary interface to be used in crypto #10103

Open
dlangBugzillaToGithub opened this issue Dec 1, 2014 · 6 comments
Open

BigInt have no binary interface to be used in crypto #10103

dlangBugzillaToGithub opened this issue Dec 1, 2014 · 6 comments

Comments

@dlangBugzillaToGithub
Copy link

golovanov_alexey reported this on 2014-12-01T16:33:08Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=13804

CC List

  • bearophile_hugs
  • jonathan
  • n8sh.secondary
  • tkook11

Description

We have no properties and methods in BigInt to work with binary data to use BigInt in crypto (for example in RSA).

BigInt have no constructor from binary data - ubyte[], uint[], etc.

To use BigInt in crypto, we need ability:
1 - create BigInt from bytes;
2 - make calculations;
3 - get bytes from result BigInt.

In step (2) we need access to underlying data BigDigit[] to implement absent powMod method "(a pow b) mod c").

Programmers cant't use std.bigint and forced to reimplement biguintcore.d and bigint.d .

For example https://github.com/apartridge/crypto/tree/master/crypto/asymmetric .
@dlangBugzillaToGithub
Copy link
Author

bearophile_hugs commented on 2014-12-01T16:44:49Z

(In reply to Alexey G from comment #0)

> In step (2) we need access to underlying data BigDigit[] to implement absent
> powMod method "(a pow b) mod c").

Beside the binary interface, having a powMod in std.bigint is very useful for all kind of usages.

@dlangBugzillaToGithub
Copy link
Author

clugdbug commented on 2014-12-02T09:54:04Z

(In reply to bearophile_hugs from comment #1)
> (In reply to Alexey G from comment #0)
> 
> > In step (2) we need access to underlying data BigDigit[] to implement absent
> > powMod method "(a pow b) mod c").
> 
> Beside the binary interface, having a powMod in std.bigint is very useful
> for all kind of usages.

Agreed. The intention was always to have powMod in std.bigint. I believe there are even some comments in the code. Some quite amazing optimizations are possible,
you can easily eliminate most of the multiplications.

@dlangBugzillaToGithub
Copy link
Author

tkook11 commented on 2016-08-07T20:18:02Z

+1 because I need to serialize bigints over networks.

@dlangBugzillaToGithub
Copy link
Author

jonathan commented on 2018-03-27T01:03:24Z

I am currently implementing a bytes() accessor for std.bigint. I will try to submit the pull request soon. Once done with that, I will create a bytes mutator for std.bigint. I just need to test on a big-endian system now, then I should be about ready to push it. I will close this issue when done, or if the idea is completely rejected.

Per the comments below, I will create a separate issue for implementing powMod. No promises, but I will *probably* implement that one, too.

@dlangBugzillaToGithub
Copy link
Author

jonathan commented on 2018-04-09T00:52:40Z

Pull request #6437 submitted. Since it's the first commit, odds are, it will get rejected.

https://github.com/dlang/phobos/pull/6437

@dlangBugzillaToGithub
Copy link
Author

n8sh.secondary commented on 2019-08-24T00:22:39Z

powmod (capitalized like that instead of "powMod" for consistency with std.math) was added in https://github.com/dlang/phobos/pull/7035 but the other things described still are not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants