summary refs log tree commit diff
path: root/crypto/src/pqc/crypto/crystals/dilithium/Reduce.cs
blob: 0f8b95ef1fb0e69fcdd8ef67c3b9916e3a983793 (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
namespace Org.BouncyCastle.Pqc.Crypto.Crystals.Dilithium
{
    internal class Reduce
    {
        public static int MontgomeryReduce(long a)
        {
            int t;
            t = (int)(a * DilithiumEngine.QInv);
            t = (int)((a - (long)((long)t * (long)DilithiumEngine.Q)) >> 32);
            //Console.Write("{0}, ", t);
            return t;
        }

        public static int Reduce32(int a)
        {
            int t;
            t = (a + (1 << 22)) >> 23;
            t = a - t * DilithiumEngine.Q;
            return t;
        }
        
        public static int ConditionalAddQ(int a)
        {
            a += (a >> 31) & DilithiumEngine.Q;
            return a;
        }


    }
}