-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
need native modInverse and powMod function for big integer #23502
Comments
sorry about the typo, it's modInverse not modeInverse. |
Have you tried using the modPow function in int? See https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:core.int#id_modPow |
cc @sgmitrovic. |
oh, it's great to see modPow is implemented. I was looking for powMod and didn't realize it's already there. |
I updated modPow to native integer implementation, and the performance of the connection handshake in our application is almost the same. |
attached file is a screenshot of the observatory, most dart cpu usage is caused by modInverse. and even in the 34% native code cpu usage, most of them are caused by bitint allocation from modInverse Attachment: |
This comment was originally written by @rinick I implemented modInverse in sdk/runtime/lib/bigint.dart ( for now it only works when modulus is positive and odd) the above test case now takes 3.1 seconds on my PC, the cpu time cost on native code BigInt allocation is almost gone. but the total time spent by dart code is still 5 times slower than java :( |
Rick, Thanks, |
Thanks for the update, @crelier ! |
@crelier we don't need even modInverse at the momenet, but the algorithm in my implementation is same as this one |
Added tests. See #23502 R=srdjan@google.com Review URL: https://codereview.chromium.org//1174513004.
in that case). See #23502 Review URL: https://codereview.chromium.org//1177063002.
after this change, native modInverse is about 8 times faster than the custom modeInverse implementation. |
Thanks @crelier ! |
Should we update the CHANGELOG for the SDK? https://github.com/dart-lang/sdk/blob/master/CHANGELOG.md cc @kevmoo |
Only if these 4 cls are going to be cherry picked for 1.11 (decision is Otherwise for 1.12, sure. The sdk change is this addition to class int:
By the time we ship 1.12, we should also have a gcd method. Cheers, On Thu, Jun 18, 2015 at 11:30 AM, Seth Ladd notifications@github.com
|
right now we are not able to use 1.12, since it doesn't support the dart2dart compiler. which means all the dart app deployed on our customer's site will have to be open sourced. We really hope native modInverse feature can be part of 1.11 |
Ivan, Please, see Rick's message below regarding the integration of modInverse Cheers, On Thu, Jun 18, 2015 at 3:05 PM, Rick Zhou notifications@github.com wrote:
|
Added tests. See #23502 R=srdjan@google.com Review URL: https://codereview.chromium.org//1174513004.
in that case). See #23502 Review URL: https://codereview.chromium.org//1177063002.
Update test. Fixes #23502 R=srdjan@google.com Review URL: https://codereview.chromium.org//1188843004.
What steps will reproduce the problem?
this is a dart file which I implemented modeInverse function with native dart big int
https://gist.github.com/rinick/9f1f285dc1e2a18d2d75
this is a java file that's doing the same thing, except it's using the builtin java modInverse function.
https://gist.github.com/samrg472/8f0bae6d291ef2bc2b95
What is the expected output? What do you see instead?
it takes 650ms to run the java on my pc, and about 8 seconds to run the dart version (11 seconds in checked mode)
To make dart's native big integer really usable for cryptography purpose, I think it's necessary to have these functions implemented in dartvm. not in dart code:
modInverse, powMod, gcd. it would also be nice if toByteArray and fromByteArray can be implemented too.
The text was updated successfully, but these errors were encountered: