summaryrefslogblamecommitdiffstats
path: root/vendor/web-token/jwt-util-ecc/ModularArithmetic.php
blob: f4b0e0e883e7a0caa9ea60caca59c41aea0d0049 (plain) (tree)


































                                                                                         
<?php

declare(strict_types=1);

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014-2018 Spomky-Labs
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

namespace Jose\Component\Core\Util\Ecc;

/**
 * @internal
 */
class ModularArithmetic
{
    public static function sub(\GMP $minuend, \GMP $subtrahend, \GMP $modulus): \GMP
    {
        return Math::mod(Math::sub($minuend, $subtrahend), $modulus);
    }

    public static function mul(\GMP $multiplier, \GMP $muliplicand, \GMP $modulus): \GMP
    {
        return Math::mod(Math::mul($multiplier, $muliplicand), $modulus);
    }

    public static function div(\GMP $dividend, \GMP $divisor, \GMP $modulus): \GMP
    {
        return self::mul($dividend, Math::inverseMod($divisor, $modulus), $modulus);
    }
}