Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 1264f65e12a1af0fcfcf5b8f1fc8980d > files > 4

php-pear-Crypt_RSA-1.0.0-10mdv2010.0.noarch.rpm

Tutorial of creating new math wrappers for Crypt_RSA package.

Math wrapper class must have the following name:
    Crypt_RSA_Math_{wrapper_name}
where {wrapper_name} - name of math wrapper. Function getWrapperName() must return this
name (see description of this function below).

This class must be placed into Crypt/RSA/Math/{math_wrapper}.php file


Math wrapper class must provide interface with following functions:
    bin2int($str) - transforms binary representation of large integer into its native form
    int2bin($num) - transforms large integer from native form into binary representation
    powmod($a, $b, $mod) - calculates ($a ^ $b) % $mod
    mul($a, $b) - calculates $a * $b
    cmpAbs($a, $b) - compares abs($a) with abs($b)
    nextPrime($num) - returns next prime, folloing by the $num
    getRand($bits_cnt, $rnd_generator, $is_set_higher_bit) - generates random number with length $bits_cnt
    dec($num) - calculates $num - 1
    isZero($num) - returns true, if $num is zero
    gcd($a, $b) - calculates greatest common divider of $an and $b
    invmod($num, $mod) - calculates number $num1 such as ($num1 * $num) % $mod = 1
    bitOr($a, $b, $start_bit) - calculates bitwise ($a or ($b << $start_bit))
    subint($num, $start, $bit_len) - returns part of number $num, starting at position $start, with length $len
    getWrapperName() - returns wrapper's name

It also must have public string varibale $errstr, which must be set to empty string
by default, or non-empty string with error description on error

See an existing implementations of math wrappers in Crypt/RSA/Math directory for more info.