Failed Conditions
Push — master ( 1edcb4...1e22a0 )
by Florent
02:06
created

ModularArithmetic   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

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