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 .
(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.
(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.
+1 because I need to serialize bigints over networks.
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.
Pull request #6437 submitted. Since it's the first commit, odds are, it will get rejected. https://github.com/dlang/phobos/pull/6437
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.
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