Package com.securityinnovation.jNeo.ntruencrypt

Examples of com.securityinnovation.jNeo.ntruencrypt.NtruEncryptKey


    // Test that the primitive that converts 3 bits to 2 trits works correctly.
    @Test public void test_convPolyBinaryToTrinaryHelper()
        throws NtruException
    {
        NtruEncryptKey keys = new NtruEncryptKey(OID.ees401ep1);

        short out[] = new short[16];
        java.util.Arrays.fill(out, (short) 22);   // init to invalid data

        // Check each bit pattern in [0..8).
        keys.convPolyBinaryToTrinaryHelper(out.length, 0, out, 7);
        keys.convPolyBinaryToTrinaryHelper(out.length, 2, out, 6);
        keys.convPolyBinaryToTrinaryHelper(out.length, 4, out, 5);
        keys.convPolyBinaryToTrinaryHelper(out.length, 6, out, 4);
        keys.convPolyBinaryToTrinaryHelper(out.length, 8, out, 3);
        keys.convPolyBinaryToTrinaryHelper(out.length, 10, out, 2);
        keys.convPolyBinaryToTrinaryHelper(out.length, 12, out, 1);
        keys.convPolyBinaryToTrinaryHelper(out.length, 14, out, 0);

        // Manually computed expected output
        short expectedOut[] = {
            -1, 1,   -1, 0,    1, -1,    1, 1,    1, 0,   0, -1,   0, 1,   0, 0
        };
View Full Code Here


    // Test that the primitive that converts a block of bits to a block
    // of trits works correctly (1 block == 16 trits == 24 bits (3 bytes)).
    @Test public void test_convPolyBinaryToTrinaryHelper2_a()
        throws NtruException
    {
        NtruEncryptKey keys = new NtruEncryptKey(OID.ees401ep1);

        short out[] = new short[19];
        java.util.Arrays.fill(out, (short) 22);   // init to invalid data

        keys.convPolyBinaryToTrinaryHelper2(out.length, 3, out, 0x00e1e83a);
        short expectedOut[] = {
            22, 22, 22,
            -1, 1, 0, 0, 1, 0, -1, 0, 1, 1, 0, 0, -1, 1, 0, -1
        };
View Full Code Here

    // of trits works correctly (1 block == 16 trits == 24 bits (3 bytes)).
    // with a different sample input than the _a() version.
    @Test public void test_convPolyBinaryToTrinaryHelper2_b()
        throws NtruException
    {
        NtruEncryptKey keys = new NtruEncryptKey(OID.ees401ep1);
        short out[] = new short[16];
        java.util.Arrays.fill(out, (short) 22);   // init to invalid data
        keys.convPolyBinaryToTrinaryHelper2(out.length, 0, out, 0x00c8a669);

        short expectedOut[] = {
            -1, 0, 0, -1, 0, 1, 0, -1, 1, 0, 0, 1, 1, -1, 0, 1
        };
        assertArrayEquals(out, expectedOut);
View Full Code Here

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

    // Test that the primitive that converts 2 trits to 3 bits works correctly.
    @Test public void test_convPolyTritToBitHelper()
        throws NtruException
    {
        // the particular OID doesn't matter here, we just need an object
        NtruEncryptKey keys = new NtruEncryptKey(OID.ees401ep1);

        assertEquals((byte) 0, keys.convPolyTritToBitHelper( 00));
        assertEquals((byte) 1, keys.convPolyTritToBitHelper( 01));
        assertEquals((byte) 2, keys.convPolyTritToBitHelper( 0, -1));
        assertEquals((byte) 3, keys.convPolyTritToBitHelper( 10));
        assertEquals((byte) 4, keys.convPolyTritToBitHelper( 11));
        assertEquals((byte) 5, keys.convPolyTritToBitHelper( 1, -1));
        assertEquals((byte) 6, keys.convPolyTritToBitHelper(-10));
        assertEquals((byte) 7, keys.convPolyTritToBitHelper(-11));
        assertEquals((byte) -1, keys.convPolyTritToBitHelper(-1, -1));

        // Other invalid values
        assertEquals((byte) -1, keys.convPolyTritToBitHelper(0, 3));
    }
View Full Code Here

    // of bits works correctly (1 block == 16 trits == 24 bits (3 bytes)).
    @Test public void test_convPolyTritToBitBlockHelper()
        throws NtruException
    {
        // the particular OID doesn't matter here, we just need an object
        NtruEncryptKey keys = new NtruEncryptKey(OID.ees401ep1);

        short trits[] = {
            1, -100, -1111,
            00100111};
        byte expectedBits[] = {(byte)0xa3, (byte)0xc0, (byte)0xcc};
        byte bits[] = new byte[3];

        keys.convPolyTrinaryToBinaryBlockHelper(0, trits, 0, bits);
        assertArrayEquals(bits, expectedBits);
    }
View Full Code Here

    // of bits works with non-zero offsets for both the bit and trit arrays.
    @Test public void test_convPolyTritToBitBlockHelper_withOffset()
        throws NtruException
    {
        // the particular OID doesn't matter here, we just need an object
        NtruEncryptKey keys = new NtruEncryptKey(OID.ees401ep1);

        short trits[] = {
            00000000,
            00000000,
            1, -100, -1111,
            00100111};
        byte expectedBits[] = {22, 22, 22, (byte)0xa3, (byte)0xc0, (byte)0xcc};
        byte bits[] = new byte[6];
        java.util.Arrays.fill(bits, (byte)22);

        keys.convPolyTrinaryToBinaryBlockHelper(16, trits, 3, bits);
        assertArrayEquals(bits, expectedBits);
    }
View Full Code Here

    // of bits won't overrun the end of the output buffer.
    @Test public void test_convPolyTritToBitBlockHelper_withOffset_truncate()
        throws NtruException
    {
        // the particular OID doesn't matter here, we just need an object
        NtruEncryptKey keys = new NtruEncryptKey(OID.ees401ep1);

        short trits[] = {
            00000000,
            00000000,
            1, -100, -1111,
            00100111};
        byte expectedBits[] = {22, 22, 22, (byte)0xa3, (byte)0xc0};
        byte bits[] = new byte[5];
        java.util.Arrays.fill(bits, (byte)22);

        keys.convPolyTrinaryToBinaryBlockHelper(16, trits, 3, bits);
        assertArrayEquals(bits, expectedBits);
    }
View Full Code Here

    // behave as if the input were padded with 0's.
    @Test public void test_convPolyTritToBitBlockHelper_withOffset_short_inbuf()
        throws NtruException
    {
        // the particular OID doesn't matter here, we just need an object
        NtruEncryptKey keys = new NtruEncryptKey(OID.ees401ep1);

        short trits[] = {
            00000000,
            00000000,
            00100111,
            1, -100, -1}; // missing last 11 trits,
        byte expectedBits[] = {22, 22, 22, (byte)0xa3, (byte)0x00, (byte)0x00};
        byte bits[] = new byte[6];
        java.util.Arrays.fill(bits, (byte)22);

        keys.convPolyTrinaryToBinaryBlockHelper(24, trits, 3, bits);
        assertArrayEquals(bits, expectedBits);
    }
View Full Code Here

        throws NtruException
    {
        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

TOP

Related Classes of com.securityinnovation.jNeo.ntruencrypt.NtruEncryptKey

Copyright © 2018 www.massapicom. 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.