aboutsummaryrefslogtreecommitdiff
path: root/miscutils/bc.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-22 23:59:21 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-22 23:59:21 +0100
commit01eb5e9da1546f5410831d3a5a8d268d630d2653 (patch)
treecf5ce1b670b4e5be10640a3752a584ff7bfa2f4b /miscutils/bc.c
parent1acac7f9c596cd447d197039216f7b55c9ee3ab3 (diff)
downloadbusybox-w32-01eb5e9da1546f5410831d3a5a8d268d630d2653.tar.gz
busybox-w32-01eb5e9da1546f5410831d3a5a8d268d630d2653.tar.bz2
busybox-w32-01eb5e9da1546f5410831d3a5a8d268d630d2653.zip
bc: shrink modular exponentiation code
function old new delta zdc_program_modexp 721 694 -27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r--miscutils/bc.c8
1 files 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)
2503{ 2503{
2504 BcStatus s; 2504 BcStatus s;
2505 BcNum base, exp, two, temp; 2505 BcNum base, exp, two, temp;
2506 BcDig two_digs[2];
2506 2507
2507 if (c->len == 0) 2508 if (c->len == 0)
2508 RETURN_STATUS(bc_error("divide by zero")); 2509 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)
2514 bc_num_expand(d, c->len); 2515 bc_num_expand(d, c->len);
2515 bc_num_init(&base, c->len); 2516 bc_num_init(&base, c->len);
2516 bc_num_init(&exp, b->len); 2517 bc_num_init(&exp, b->len);
2517 bc_num_init_DEF_SIZE(&two);
2518 bc_num_init(&temp, b->len); 2518 bc_num_init(&temp, b->len);
2519 2519
2520 two.cap = ARRAY_SIZE(two_digs);
2521 two.num = two_digs;
2520 bc_num_one(&two); 2522 bc_num_one(&two);
2521 two.num[0] = 2; 2523 two_digs[0] = 2;
2524
2522 bc_num_one(d); 2525 bc_num_one(d);
2523 2526
2524 s = zbc_num_rem(a, c, &base, 0); 2527 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)
2543 } 2546 }
2544 err: 2547 err:
2545 bc_num_free(&temp); 2548 bc_num_free(&temp);
2546 bc_num_free(&two);
2547 bc_num_free(&exp); 2549 bc_num_free(&exp);
2548 bc_num_free(&base); 2550 bc_num_free(&base);
2549 RETURN_STATUS(s); 2551 RETURN_STATUS(s);