PHP Classes

File: src/ScalarValue.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   Ristretto PHP   src/ScalarValue.php   Download  
File: src/ScalarValue.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: 2,901 bytes
 

Contents

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

use
ParagonIE\HiddenString\HiddenString;
use
SodiumException;

class
ScalarValue extends Ristretto
{
   
/**
     * @throws SodiumException
     */
   
public static function random(): ScalarValue
   
{
        return new
ScalarValue(
            new
HiddenString(sodium_crypto_core_ristretto255_scalar_random())
        );
    }

   
/**
     * @throws SodiumException
     */
   
public function add(ScalarValue $other): ScalarValue
   
{
       
$result = sodium_crypto_core_ristretto255_scalar_add(
           
$this->bytes->getString(),
           
$other->getBytes()->getString()
        );
        return new
ScalarValue(new HiddenString($result));
    }

   
/**
     * @throws SodiumException
     */
   
public function complement(): ScalarValue
   
{
        return new
ScalarValue(
            new
HiddenString(
               
sodium_crypto_core_ristretto255_scalar_complement($this->bytes->getString())
            )
        );
    }

   
/**
     * @throws SodiumException
     */
   
public function mul(ScalarValue $other): ScalarValue
   
{
       
$result = sodium_crypto_core_ristretto255_scalar_mul(
           
$this->bytes->getString(),
           
$other->getBytes()->getString()
        );
        return new
ScalarValue(new HiddenString($result));
    }

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

   
/**
     * @throws SodiumException
     */
   
public function multBase(): GroupElement
   
{
        return new
GroupElement(
            new
HiddenString(
               
sodium_crypto_scalarmult_ristretto255_base($this->bytes->getString())
            )
        );
    }

   
/**
     * @throws SodiumException
     */
   
public function invert(): ScalarValue
   
{
        return new
ScalarValue(
            new
HiddenString(
               
sodium_crypto_core_ristretto255_scalar_invert($this->bytes->getString())
            )
        );
    }

   
/**
     * @throws SodiumException
     */
   
public function negate(): ScalarValue
   
{
        return new
ScalarValue(
            new
HiddenString(
               
sodium_crypto_core_ristretto255_scalar_negate($this->bytes->getString())
            )
        );
    }

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