All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.pqc.crypto.crystals.kyber.Reduce Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.8 and up.

There is a newer version: 1.78.1
Show newest version
package org.bouncycastle.pqc.crypto.crystals.kyber;

class Reduce
{

    public static short montgomeryReduce(int a)
    {
        int t;
        short u;

        u = (short)(a * KyberEngine.KyberQinv);
        t = (int)(u * KyberEngine.KyberQ);
        t = a - t;
        t >>= 16;
        return (short)t;
    }

    public static short barretReduce(short a)
    {
        short t;
        long shift = (((long)1) << 26);
        short v = (short)((shift + (KyberEngine.KyberQ / 2)) / KyberEngine.KyberQ);
        t = (short)((v * a) >> 26);
        t = (short)(t * KyberEngine.KyberQ);
        return (short)(a - t);
    }

    public static short conditionalSubQ(short a)
    {
        a -= KyberEngine.KyberQ;
        a += (a >> 15) & KyberEngine.KyberQ;
        return a;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy