Failed Conditions
Push — v7 ( d5cb12...d36fb1 )
by Florent
02:58
created

ModularArithmetic::mul()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2017 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Component\Core\Util\Ecc;
13
14
final class ModularArithmetic
15
{
16
    /**
17
     * @param \GMP $minuend
18
     * @param \GMP $subtrahend
19
     * @param \GMP $modulus
20
     *
21
     * @return \GMP
22
     */
23
    public static function sub(\GMP $minuend, \GMP $subtrahend, \GMP $modulus): \GMP
24
    {
25
        return GmpMath::mod(GmpMath::sub($minuend, $subtrahend), $modulus);
26
    }
27
28
    /**
29
     * @param \GMP $multiplier
30
     * @param \GMP $muliplicand
31
     * @param \GMP $modulus
32
     *
33
     * @return \GMP
34
     */
35
    public static function mul(\GMP $multiplier, \GMP $muliplicand, \GMP $modulus): \GMP
36
    {
37
        return GmpMath::mod(GmpMath::mul($multiplier, $muliplicand), $modulus);
38
    }
39
40
    /**
41
     * @param \GMP $dividend
42
     * @param \GMP $divisor
43
     * @param \GMP $modulus
44
     *
45
     * @return \GMP
46
     */
47
    public static function div(\GMP $dividend, \GMP $divisor, \GMP $modulus): \GMP
48
    {
49
        return self::mul($dividend, GmpMath::inverseMod($divisor, $modulus), $modulus);
50
    }
51
}
52