PHP Classes

File: src/GroupElement.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   Ristretto PHP   src/GroupElement.php   Download  
File: src/GroupElement.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Ristretto PHP
Manipulate values in type safe way using classes
Author: By
Last change:
Date: 1 year ago
Size: 1,688 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);
namespace
ParagonIE\Ristretto;

use
ParagonIE\HiddenString\HiddenString;
use
SodiumException;

class
GroupElement extends Ristretto
{
   
/**
     * @throws SodiumException
     */
   
public function add(GroupElement $element): GroupElement
   
{
       
$result = sodium_crypto_core_ristretto255_add(
           
$this->bytes->getString(),
           
$element->getBytes()->getString()
        );
        return new
GroupElement(new HiddenString($result));
    }

   
/**
     * @throws SodiumException
     */
   
public static function random(): GroupElement
   
{
        return new
GroupElement(
            new
HiddenString(sodium_crypto_core_ristretto255_random())
        );
    }

   
/**
     * @throws SodiumException
     */
   
public static function fromHash(string $hash): GroupElement
   
{
        return new
GroupElement(
            new
HiddenString(sodium_crypto_core_ristretto255_from_hash($hash))
        );
    }

   
/**
     * @throws SodiumException
     */
   
public function sub(GroupElement $element): GroupElement
   
{
       
$result = sodium_crypto_core_ristretto255_sub(
           
$this->bytes->getString(),
           
$element->getBytes()->getString()
        );
        return new
GroupElement(new HiddenString($result));
    }

   
/**
     * @throws SodiumException
     */
   
public function scalarPointMultiply(ScalarValue $s): GroupElement
   
{
        return new
GroupElement(
            new
HiddenString(
               
sodium_crypto_scalarmult_ristretto255(
                   
$s->getBytes()->getString(),
                   
$this->bytes->getString()
                )
            )
        );
    }
}