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

org.bouncycastle.pqc.crypto.newhope.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 Java 1.8 and later with debug enabled.

The newest version!
package org.bouncycastle.pqc.crypto.newhope;

class Reduce
{
    static final int QInv = 12287; // -inverse_mod(p,2^18)
    static final int RLog = 18;
    static final int RMask = (1 << RLog) - 1;

    static short montgomery(int a)
    {
        int u = a * QInv;
        u &= RMask;
        u *= Params.Q;
        u += a;
        return (short)(u >>> RLog);
    }

    static short barrett(short a)
    {
        int t = a & 0xFFFF;
        int u = (t * 5) >>> 16;
        u *= Params.Q;
        return (short)(t - u);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy