core/src/main/java/org/bouncycastle/pqc/crypto/qtesla/QTESLA.java
/********************************************************************************************************
     * Description:	Checks Whether the Generated Error Polynomial or the Generated Secret Polynomial
     *				Fulfills Certain Properties Needed in Key Generation Algorithm
     *
     * @param        polynomial        Parameter to be Checked
     * @param        offset            Starting Point of the Polynomial to be Checked
     * @param        bound            Threshold of Summation
     * @param        n                Polynomial Degree
     * @param        w                Number of Non-Zero Entries of Output Elements of Encryption
     *
     * @return false            Fulfillment
     * 				true			No Fulfillment
     ********************************************************************************************************/
Checks Whether the Generated Error Polynomial or the Generated Secret Polynomial
Fulfills Certain Properties Needed in Key Generation Algorithm



@return false            Fulfillment
true                    No Fulfillment
Checks Whether the Generated Error Polynomial or the Generated Secret Polynomial Fulfills Certain Properties Needed in Key Generation Algorithm @return false Fulfillment true No Fulfillment
private static boolean checkPolynomial(long[] polynomial, int offset, int bound, int n, int w)
    {
        int summation = 0;
        int limit = n;
        short temporary;
        short mask;
        short[] list = new short[n];
        for (int i = 0; i < n; i++)
        {
            list[i] = (short)absolute(polynomial[offset + i]);
        }
        for (int i = 0; i < w; i++)
        {
            for (short j = 0; j < limit - 1; j++)
            {
                mask = (short)((list[j + 1] - list[j]) >> 15);
                temporary = (short)((list[j + 1] & mask) | (list[j] & (~mask)));
                list[j + 1] = (short)((list[j] & mask) | (list[j + 1] & (~mask)));
                list[j] = temporary;
            }
            summation += list[limit - 1];
            limit--;
        }
        if (summation > bound)
        {
            return true;
        }
        return false;
    }
private static boolean checkPolynomial ( long [ ] polynomial , int offset , int bound , int n , int w ) { int summation = 0 ; int limit = n ; short temporary ; short mask ; short [ ] list = new short [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { list [ i ] = ( short ) absolute ( polynomial [ offset + i ] ) ; } for ( int i = 0 ; i < w ; i ++ ) { for ( short j = 0 ; j < limit - 1 ; j ++ ) { mask = ( short ) ( ( list [ j + 1 ] - list [ j ] ) >> 15 ) ; temporary = ( short ) ( ( list [ j + 1 ] & mask ) | ( list [ j ] & ( ~ mask ) ) ) ; list [ j + 1 ] = ( short ) ( ( list [ j ] & mask ) | ( list [ j + 1 ] & ( ~ mask ) ) ) ; list [ j ] = temporary ; } summation += list [ limit - 1 ] ; limit -- ; } if ( summation > bound ) { return true ; } return false ; }
Description:     Checks Whether the Generated Error Polynomial or the Generated Secret Polynomial
                          Fulfills Certain Properties Needed in Key Generation Algorithm
Description : Checks Whether the Generated Error Polynomial or the Generated Secret Polynomial Fulfills Certain Properties Needed in Key Generation Algorithm