Issue 13804 - BigInt have no binary interface to be used in crypto
Summary: BigInt have no binary interface to be used in crypto
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: Jonathan Wilbur
URL: https://github.com/dlang/phobos/blob/...
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-01 16:33 UTC by Alexey G
Modified: 2024-12-01 16:23 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Alexey G 2014-12-01 16:33:08 UTC
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 .
Comment 1 bearophile_hugs 2014-12-01 16:44:49 UTC
(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.
Comment 2 Don 2014-12-02 09:54:04 UTC
(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.
Comment 3 tkook11 2016-08-07 20:18:02 UTC
+1 because I need to serialize bigints over networks.
Comment 4 Jonathan Wilbur 2018-03-27 01:03:24 UTC
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.
Comment 5 Jonathan Wilbur 2018-04-09 00:52:40 UTC
Pull request #6437 submitted. Since it's the first commit, odds are, it will get rejected.

https://github.com/dlang/phobos/pull/6437
Comment 6 Nathan S. 2019-08-24 00:22:39 UTC
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.
Comment 7 dlangBugzillaToGithub 2024-12-01 16:23:11 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10103

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB