2017 © Pedro Peláez
 

library php-dh

A DiffieHellman implementation in PHP

image

querdos/php-dh

A DiffieHellman implementation in PHP

  • Sunday, April 16, 2017
  • by querdos
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 20 % Grown

The README.md

DiffieHellman-PHP

Build Status, (*1)

A Diffie Helmann implementation in PHP written by Hamza ESSAYEGH, (*2)

Installation

First of all, download and install Composer by following the official instructions and the php-gmp library for your distribution, (*3)

# Debian like installation
$ sudo apt-get install php-gmp

Then, you can install this implementation by running the following command:, (*4)

$ composer require querdos/php-dh

Usage

Simple example on how to generate a shared secret, (*5)

<?php
require_once 'vendor/autoload.php';

use Querdos\DiffieHellman;

// alice and bob generate their data and exchange public ones
$dh_bob   = new DiffieHellman();
$dh_alice = new DiffieHellman(null, $dh_bob->getModulus(), $dh_bob->getBase());

// first initialization for both alice and bob (private and public keys generation)
$dh_bob->init();
$dh_alice->init();

// generating a shared secret with corresponding public keys
$dh_alice->compute_secret($dh_bob->getPublic());
$dh_bob->compute_secret($dh_alice->getPublic());

if (0 == gmp_cmp($dh_alice->getSecret(), $dh_bob->getSecret())) {
    echo "Alice and Bob share the same secret" . PHP_EOL;
} else {
    echo "Alice and Bob don't share the same secret" . PHP_EOL;
}

Predefined values for the modulus and the base

In order to compute the secret and according to the corresponding RFC, there is a set of predefined values for g and p. You can specify which one you want in the constructor:, (*6)

<?php
$dh = new DiffieHellman();                      // no value, 1536bits by default
$dh = new DiffieHellman(self::PREDEFINED_1536); // 1536bits length
$dh = new DiffieHellman(self::PREDEFINED_3072); // 3072bits length 
$dh = new DiffieHellman(self::PREDEFINED_4096); // 4096bits length
$dh = new DiffieHellman(self::PREDEFINED_6144); // 6144bits length
$dh = new DiffieHellman(self::PREDEFINED_8192); // 8192bits length

The Versions

16/04 2017

dev-master

9999999-dev

A DiffieHellman implementation in PHP

  Sources   Download

MIT

The Requires

 

by Hamza ESSAYEGH

16/04 2017

v1

1.0.0.0

A DiffieHellman implementation in PHP

  Sources   Download

MIT

The Requires

 

by Hamza ESSAYEGH