Issues

ZF-11217: Change class Zend_Crypt_DiffieHellman methods getGenerator and getPrime to return different types

Description

Currently Zend_Crypt_DiffieHellman getGenerator and getPrime methods look like this:


public function getPrime()
{
    if (!isset($this->_prime)) {
        require_once('Zend/Crypt/DiffieHellman/Exception.php');
        throw new Zend_Crypt_DiffieHellman_Exception('No prime number has been set');
    }
    return $this->_prime;
}

public function getGenerator()
{
    if (!isset($this->_generator)) {
        require_once('Zend/Crypt/DiffieHellman/Exception.php');
        throw new Zend_Crypt_DiffieHellman_Exception('No generator number has been set');
    }
    return $this->_generator;
}

The suggestion would be to slightly change these methods to look like this:


public function getPrime($type = self::NUMBER)
{
    if (!isset($this->_prime)) {
        require_once('Zend/Crypt/DiffieHellman/Exception.php');
        throw new Zend_Crypt_DiffieHellman_Exception('No prime number has been set');
    }
    if ($type == self::NUMBER) {
        return $this->_prime;
    } else if ($type == self::BTWOC) {
        return $this->_math->btwoc($this->_math->toBinary($this->_prime));
    }

    return $this->_math->toBinary($this->_prime);
}

public function getGenerator($type = self::NUMBER)
{
    if (!isset($this->_generator)) {
        require_once('Zend/Crypt/DiffieHellman/Exception.php');
        throw new Zend_Crypt_DiffieHellman_Exception('No generator number has been set');
    }
    if ($type == self::NUMBER) {
        return $this->_generator;
    } else if ($type == self::BTWOC) {
        return $this->_math->btwoc($this->_math->toBinary($this->_generator));
    }
    return $this->_math->toBinary($this->_generator);
}

This is because sometimes you need a different representation of these values, for example OpenID specification states: 8.1.2. Diffie-Hellman Request Parameters <...> * openid.dh_modulus Value: base64(btwoc(p)) * openid.dh_gen Value: base64(btwoc(g)) p - DiffieHellman prime g - DiffieHellman generator

as you may see it is required that prime and generator should be processed by btwoc function before passing them to base64_encode.

This would be a really handy improvement.

Comments

No comments to display