Examples of FullPolynomial


Examples of com.securityinnovation.jNeo.math.FullPolynomial

    {
        for (int t=0; t<tests.length; t++)
        {
            KeyParams keyParams = KeyParams.getKeyParams(tests[t].oid);
            NtruEncryptKey keys = new NtruEncryptKey(tests[t].oid);
            keys.h = new FullPolynomial(tests[t].h);
            byte sData[] = keys.form_sData(
                tests[t].m, 0, tests[t].m.length, tests[t].b, 0);
            assertArrayEquals(tests[t].sData, sData);
        }
    }
View Full Code Here

Examples of com.securityinnovation.jNeo.math.FullPolynomial

    {
        for (int t=0; t<tests.length; t++)
        {
            KeyParams keyParams = KeyParams.getKeyParams(tests[t].oid);
            NtruEncryptKey keys = new NtruEncryptKey(tests[t].oid);
            keys.h = new FullPolynomial(tests[t].h);

            byte data[] = new byte[tests[t].m.length + tests[t].b.length + 92];
            java.util.Arrays.fill(data, (byte) 23);
            int mOffset = 33;
            int bOffset = 72;
View Full Code Here

Examples of com.securityinnovation.jNeo.math.FullPolynomial

        for (int t=0; t<tests.length; t++)
        {
            KeyParams keyParams = KeyParams.getKeyParams(tests[t].oid);
            NtruEncryptKey keys = new NtruEncryptKey(tests[t].oid);
           
            FullPolynomial Mtrin = new FullPolynomial(tests[t].Mtrin);
            byte out[] = keys.convPolyTrinaryToBinary(Mtrin);
            assertArrayEquals(out, tests[t].Mbin);
        }
    }
View Full Code Here

Examples of com.securityinnovation.jNeo.math.FullPolynomial

    {
        for (int t=0; t<tests.length; t++)
        {
            KeyParams keyParams = KeyParams.getKeyParams(tests[t].oid);
            NtruEncryptKey keys = new NtruEncryptKey(tests[t].oid);
            FullPolynomial R = new FullPolynomial(tests[t].R);
            byte out[] = keys.calcPolyMod4Packed(R);
            assertArrayEquals(out, tests[t].R4);
        }
    }
View Full Code Here

Examples of com.securityinnovation.jNeo.math.FullPolynomial

    {
        for (int t=0; t<tests.length; t++)
        {
            KeyParams keyParams = KeyParams.getKeyParams(tests[t].oid);
            NtruEncryptKey keys = new NtruEncryptKey(tests[t].oid);
            FullPolynomial out =
              keys.calcEncryptionMask(new FullPolynomial(tests[t].R));
            assertArrayEquals(out.p, tests[t].mask);
        }
    }
View Full Code Here

Examples of com.securityinnovation.jNeo.math.FullPolynomial

        NtruEncryptKey keys = new NtruEncryptKey(OID.ees401ep1);

        // Check the ability to count 1's.
        // Verify the boundary case and one case on each side of the dm0 limit
        short threeOnesArray[] = {-1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1};
        FullPolynomial threeOnes = new FullPolynomial(threeOnesArray);
        assertFalse(keys.check_dm0(threeOnes, 4));
        assertTrue(keys.check_dm0(threeOnes, 3));
        assertTrue(keys.check_dm0(threeOnes, 2));

        // Check the ability to count 0's.
        // Verify the boundary case and one case on each side of the dm0 limit
        short threeZerosArray[] = {-1, -1, -1, -1, -1, 0, 0, 0, 1, 1, 1, 1, 1};
        FullPolynomial threeZeros = new FullPolynomial(threeZerosArray);
        assertFalse(keys.check_dm0(threeZeros, 4));
        assertTrue(keys.check_dm0(threeZeros, 3));
        assertTrue(keys.check_dm0(threeZeros, 2));

        // Check the ability to count -1's.
        // Verify the boundary case and one case on each side of the dm0 limit
        short threeNegOnesArray[] = {-1, -1, -1, -1, -10,0,0,0,01,1,1};
        FullPolynomial threeNegOnes = new FullPolynomial(threeNegOnesArray);
        assertFalse(keys.check_dm0(threeNegOnes, 4));
        assertTrue(keys.check_dm0(threeNegOnes, 3));
        assertTrue(keys.check_dm0(threeNegOnes, 2));
    }
View Full Code Here

Examples of com.securityinnovation.jNeo.math.FullPolynomial

        {
            KeyParams keyParams = KeyParams.getKeyParams(tests[t].oid);
            NtruEncryptKey keys = new NtruEncryptKey(tests[t].oid);

            // Set f, h.
            keys.h = new FullPolynomial(tests[t].h);
            keys.f = new FullPolynomial(tests[t].f);

            // Do encryption
            ByteArrayInputStream prng = new ByteArrayInputStream(tests[t].b);
            byte ciphertext[] = keys.encrypt(tests[t].m, prng);
View Full Code Here

Examples of com.securityinnovation.jNeo.math.FullPolynomial

        // Check input length
        if (keyParams.maxMsgLenBytes < message.length)
          throw new PlaintextBadLengthException(
              message.length, keyParams.maxMsgLenBytes);

        FullPolynomial mPrime, R;
        do {
            // Form M = b | len | message | p0
            byte M[] = generateM(message, rng);
           
            // Form Mtrin = trinary poly derived from M
            FullPolynomial Mtrin = new FullPolynomial(
                convPolyBinaryToTrinary(keyParams.N, M));
           
            // Form sData = OID | m | b | hTrunc
            byte sData[] = form_sData(message, 0, message.length, M, 0);
           
            // Form r from sData.
            IGF2 igf = new IGF2(
                keyParams.N, keyParams.c, keyParams.igfHash, keyParams.minCallsR,
                sData, 0, sData.length);
            FullPolynomial r = BPGM3.genTrinomial(
                keyParams.N, keyParams.dr, keyParams.dr, igf);
            igf.close();
           
            // Calculate R = r * h mod q
            R = FullPolynomial.convolution(r, h, keyParams.q);
           
            // calculate R4 = R mod 4, form octet string
            // calc mask = MGF1(R4, N, minCallsMask)
            FullPolynomial mask = calcEncryptionMask(R);
           
            // calc m' = M + mask mod p
            mPrime =
              FullPolynomial.addAndRecenter(Mtrin, mask, keyParams.p, -1);

            // count #1s, #0s, #-1s in m', discard if less than dm0
        } while (!check_dm0(mPrime, keyParams.dm0));

        // e = R + m' mod q
        FullPolynomial e = FullPolynomial.add(R, mPrime, keyParams.q);

        // Bit-pack e into the ciphertext and return.
        int cLen = BitPack.pack(e.p.length, keyParams.q);
        byte ciphertext[] = new byte[cLen];
        BitPack.pack(e.p.length, keyParams.q, e.p, 0, ciphertext, 0);
View Full Code Here

Examples of com.securityinnovation.jNeo.math.FullPolynomial

              ciphertext.length, expectedCTLength);

        boolean fail = false;

        // Unpack ciphertext into the polynomial e.
        FullPolynomial e = new FullPolynomial(keyParams.N);
        int numUnpacked = BitPack.unpack(
            keyParams.N, keyParams.q, ciphertext, 0, e.p, 0);
        if (numUnpacked != ciphertext.length)
          throw new CiphertextBadLengthException(
              ciphertext.length, BitPack.pack(keyParams.N, keyParams.q));

        // a = f*e with coefficients reduced to range [A..A+q-1], where
        // A = lower bound decryption coefficient (-q/2 in all param sets)
        FullPolynomial ci = FullPolynomial.convolution(f, e, keyParams.q);
        for (int i=0; i<ci.p.length; i++)
          if (ci.p[i] >= keyParams.q/2)
            ci.p[i] -= keyParams.q;
       
        // Calculate ci = message candidate = a mod p in [-1,0,1]
        for (int i=0; i<keyParams.N; i++)
        {
            ci.p[i] = (byte) (ci.p[i] % keyParams.p);
            if (ci.p[i] == 2)
              ci.p[i] = -1;
            else if (ci.p[i] == -2)
              ci.p[i] = 1;
        }
       
        // Count the number of 1's, -1's, and 0's in ci. Fail if any
        // count is less than dm0.
        if (!check_dm0(ci, keyParams.dm0))
          fail = true;

        // Calculate the candidate for r*h: cR = e - ci;
        FullPolynomial cR = FullPolynomial.subtract(e, ci, keyParams.q);

        // Calculate cR4 = cR mod 4
        // Generate masking polynomial mask by calling the given MGF with
        // inputs (cR4, N, minCallsMask
        FullPolynomial mask = calcEncryptionMask(cR);

        // Form cMtrin by polynomial subtraction of cm' and mask mod p
        // Note: cm' is actually called ci everywhere else in the spec.
        FullPolynomial cMtrin =
          FullPolynomial.subtractAndRecenter(ci, mask, keyParams.p, -1);

        // Convert cMtrin to cMbin. Discard trailing bits
        byte cM[] = convPolyTrinaryToBinary(cMtrin);

        // Parse cMbin as b || l || m || p0. Fail if does not match.
        int mOffset = (keyParams.db)/8 + keyParams.lLen;
        int mLen = verifyMFormat(cM);
        if (mLen < 0)
        {
            // Set mLen to 1 so that later steps won't have to deal
            // with an invalid value.
            mLen = 1;
            fail = true;
        }

        // Form sData from OID, m, b, hTrunc
        // Note: b is the leading bytes of cM.
        byte sData[] = form_sData(cM, mOffset, mLen, cM, 0);

        // Calc cr from sData
        IGF2 igf = new IGF2(
            keyParams.N, keyParams.c, keyParams.igfHash, keyParams.minCallsR,
            sData, 0, sData.length);
        FullPolynomial cr = BPGM3.genTrinomial(
            keyParams.N, keyParams.dr, keyParams.dr, igf);
        igf.close();

        // Calculate cR' = h * cr mod q
        FullPolynomial cRPrime = FullPolynomial.convolution(cr, h, keyParams.q);
        // If cR != cR', fail
        if (!cR.equals(cRPrime))
          fail = true;

        if (fail)
View Full Code Here

Examples of com.securityinnovation.jNeo.math.FullPolynomial

        FullPolynomial R)
    {
        byte R4[] = calcPolyMod4Packed(R);
        MGF1 mgf = new MGF1(keyParams.mgfHash, keyParams.minCallsMask, true,
                            R4, 0, R4.length);
        FullPolynomial p = MGF_TP_1.genTrinomial(keyParams.N, mgf);
        mgf.close();
        return p;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.