Bug #75178 [Asn->Csd]: bcpowmod() misbehaves for non-integer base or modulus

From: Date: Sat, 09 Sep 2017 11:46:12 +0000
Subject: Bug #75178 [Asn->Csd]: bcpowmod() misbehaves for non-integer base or modulus
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211017@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75178&edit=1

 ID:                 75178
 Updated by:         cmb@php.net
 Reported by:        cmb@php.net
 Summary:            bcpowmod() misbehaves for non-integer base or
                     modulus
-Status:             Assigned
+Status:             Closed
 Type:               Bug
 Package:            BC math related
 Operating System:   *
 PHP Version:        7.0.23
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=44eec946e8c6c830992572e15e4b63b4dd92abdf
Log: Fixed bug #75178 (bcpowmod() misbehaves for non-integer base or modulus)


Previous Comments:
------------------------------------------------------------------------
[2017-09-09 10:58:54] cmb@php.net

Description:
------------
bcpowmod() accepts non-integral operands, writing a warning to
stderr (see bug #75169) and simply going on for non-integer base
and modulus, while a non-integer exponent is truncated. The
results appear to be nonsensical.

Since bcpowmod() is a simple wrapper for bc_raisemod() which
implements the so called right-to-left binary method for modular
exponentiation[1], the function is unsuitable for non-integral
operands, so the warnings are correct, but base and modulus would
have to be truncated as well.[2]

[1] <https://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method>
[2] <https://github.com/php/php-src/blob/php-7.0.23/ext/bcmath/libbcmath/src/raisemod.c#L69>


Test script:
---------------
<?php
var_dump(bcpowmod('4.1', '4', '3', 3));
var_dump(bcpowmod('4', '4', '3.1', 3));


Expected result:
----------------
bc math warning: non-zero scale in base
string(5) "1.000"
bc math warning: non-zero scale in modulus
string(5) "1.000"


Actual result:
--------------
bc math warning: non-zero scale in base
string(5) "0.276"
bc math warning: non-zero scale in modulus
string(5) "0.250"



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=75178&edit=1


Thread (2 messages)

« previous php.bugs (#211017) next »