summaryrefslogtreecommitdiffstats
path: root/vendor/web-token/jwt-util-ecc/ModularArithmetic.php
blob: 29be145bc3c4ce9798a6679419276d669aa6000c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?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);
    }
}