-
Notifications
You must be signed in to change notification settings - Fork 215
Addition of mp_radix_size_overestimate (behaviour like the function in GMP) #343
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
997d47f
Addition of mp_radix_size_overestimate (behaviour like the function m…
czurnieden 1191eab
compute all bases of a power of two in the same way
czurnieden cb17f0e
moved check for zero to an earlier point
czurnieden ad0e800
cleaned up a bit and added testing of negative values in demo/test.c
czurnieden 542ca51
more clean-ups and some adjustments for the new mp_to_radix
czurnieden f4a0424
corrected demo/test.c
czurnieden 2bf351b
version minimale
czurnieden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #include "tommath_private.h" | ||
| #ifdef BN_MP_RADIX_SIZE_OVERESTIMATE_C | ||
| /* LibTomMath, multiple-precision integer library -- Tom St Denis */ | ||
| /* SPDX-License-Identifier: Unlicense */ | ||
|
|
||
|
|
||
| /* | ||
| Table of {0, log_2([1..64])} times 2^p where p is the scale | ||
| factor defined in LTM_RADIX_SIZE_SCALE. | ||
| */ | ||
| /* *INDENT-OFF* */ | ||
| #define LTM_RADIX_SIZE_SCALE 13 | ||
| static const uint16_t logbases[65] = { | ||
| 0u, 0u, 8192u, 12984u, 16384u, | ||
| 19021u, 21176u, 22997u, 24576u, 25968u, | ||
| 27213u, 28339u, 29368u, 30314u, 31189u, | ||
| 32005u, 32768u, 33484u, 34160u, 34799u, | ||
| 35405u, 35981u, 36531u, 37057u, 37560u, | ||
| 38042u, 38506u, 38952u, 39381u, 39796u, | ||
| 40197u, 40584u, 40960u, 41323u, 41676u, | ||
| 42019u, 42352u, 42675u, 42991u, 43298u, | ||
| 43597u, 43889u, 44173u, 44451u, 44723u, | ||
| 44989u, 45249u, 45503u, 45752u, 45995u, | ||
| 46234u, 46468u, 46698u, 46923u, 47144u, | ||
| 47360u, 47573u, 47783u, 47988u, 48190u, | ||
| 48389u, 48584u, 48776u, 48965u, 49152u | ||
| }; | ||
| /* *INDENT-ON* */ | ||
| mp_err mp_radix_size_overestimate(const mp_int *a, const int radix, int *size) | ||
| { | ||
| mp_int bi_bit_count, bi_k; | ||
| int bit_count; | ||
| mp_err err = MP_OKAY; | ||
|
|
||
| *size = 0; | ||
|
|
||
| if ((radix < 2) || (radix > 64)) { | ||
| return MP_VAL; | ||
| } | ||
|
|
||
| bit_count = mp_count_bits(a) + 1; | ||
|
|
||
| if (bit_count == 0) { | ||
minad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| *size = 2; | ||
| return MP_OKAY; | ||
sjaeckel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if ((err = mp_init_multi(&bi_bit_count, &bi_k, NULL)) != MP_OKAY) { | ||
| return err; | ||
| } | ||
|
|
||
| mp_set_l(&bi_bit_count, bit_count); | ||
| mp_set_u32(&bi_k, logbases[radix]); | ||
| if ((err = mp_mul_2d(&bi_bit_count, LTM_RADIX_SIZE_SCALE, &bi_bit_count)) != MP_OKAY) goto LTM_ERR; | ||
| if ((err = mp_div(&bi_bit_count, &bi_k, &bi_bit_count, NULL)) != MP_OKAY) goto LTM_ERR; | ||
|
|
||
| *size = (int)mp_get_l(&bi_bit_count) + 4; | ||
| #if ( (defined MP_8BIT) && (INT_MAX > 0xFFFF)) | ||
| *size += 3; | ||
| #endif | ||
|
|
||
| LTM_ERR: | ||
| mp_clear_multi(&bi_bit_count, &bi_k, NULL); | ||
| return err; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.