[git commit] bc: shrink modular exponentiation code
Denys Vlasenko
vda.linux at googlemail.com
Sat Dec 22 22:59:21 UTC 2018
commit: https://git.busybox.net/busybox/commit/?id=01eb5e9da1546f5410831d3a5a8d268d630d2653
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
function old new delta
zdc_program_modexp 721 694 -27
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
miscutils/bc.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 8cd67b0f5..25150a9eb 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -2503,6 +2503,7 @@ static BC_STATUS zdc_num_modexp(BcNum *a, BcNum *b, BcNum *c, BcNum *restrict d)
{
BcStatus s;
BcNum base, exp, two, temp;
+ BcDig two_digs[2];
if (c->len == 0)
RETURN_STATUS(bc_error("divide by zero"));
@@ -2514,11 +2515,13 @@ static BC_STATUS zdc_num_modexp(BcNum *a, BcNum *b, BcNum *c, BcNum *restrict d)
bc_num_expand(d, c->len);
bc_num_init(&base, c->len);
bc_num_init(&exp, b->len);
- bc_num_init_DEF_SIZE(&two);
bc_num_init(&temp, b->len);
+ two.cap = ARRAY_SIZE(two_digs);
+ two.num = two_digs;
bc_num_one(&two);
- two.num[0] = 2;
+ two_digs[0] = 2;
+
bc_num_one(d);
s = zbc_num_rem(a, c, &base, 0);
@@ -2543,7 +2546,6 @@ static BC_STATUS zdc_num_modexp(BcNum *a, BcNum *b, BcNum *c, BcNum *restrict d)
}
err:
bc_num_free(&temp);
- bc_num_free(&two);
bc_num_free(&exp);
bc_num_free(&base);
RETURN_STATUS(s);
More information about the busybox-cvs
mailing list