Issues

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

Issue Type: Improvement Created: 2011-03-23T15:24:30.000+0000 Last Updated: 2011-03-24T15:57:16.000+0000 Status: Open Fix version(s): Reporter: Eduardas Kazakas (kamikazik) Assignee: Pádraic Brady (padraic) Tags: - Zend_Crypt

Related issues: Attachments:

Description

Currently Zend_Crypt_DiffieHellman getGenerator and getPrime methods look like this:

<pre class="highlight">
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:

<pre class="highlight">
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

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts