Bug 13804 – BigInt have no binary interface to be used in crypto

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-12-01T16:33:08Z
Last change time
2024-12-01T16:23:11Z
Assigned to
Jonathan Wilbur
Creator
Alexey G
See also
https://issues.dlang.org/show_bug.cgi?id=20889
Moved to GitHub: phobos#10103 →

Comments

Comment #0 by golovanov_alexey — 2014-12-01T16:33:08Z
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 by bearophile_hugs — 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.
Comment #2 by clugdbug — 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.
Comment #3 by tkook11 — 2016-08-07T20:18:02Z
+1 because I need to serialize bigints over networks.
Comment #4 by jonathan — 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.
Comment #5 by jonathan — 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
Comment #6 by n8sh.secondary — 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.
Comment #7 by robert.schadek — 2024-12-01T16:23:11Z
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