Home | History | Annotate | Download | only in spec
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package tests.security.spec;
     19 
     20 import junit.framework.TestCase;
     21 
     22 import java.math.BigInteger;
     23 import java.security.spec.ECField;
     24 import java.security.spec.ECFieldF2m;
     25 import java.security.spec.ECFieldFp;
     26 import java.security.spec.EllipticCurve;
     27 import java.util.Arrays;
     28 
     29 /**
     30  * Tests for <code>EllipticCurve</code> class fields and methods.
     31  *
     32  */
     33 public class EllipticCurveTest extends TestCase {
     34 
     35     /**
     36      * Test #1 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code>
     37      * constructor<br>
     38      * Assertion: creates instance of EllipticCurve<br>
     39      * Test preconditions: valid parameters passed<br>
     40      * Expected: must pass without any exceptions
     41      */
     42     public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray01() {
     43         // test case 1 parameters set
     44         ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
     45         BigInteger a = BigInteger.ONE;
     46         BigInteger b = BigInteger.valueOf(19L);
     47         byte[] seed = new byte[24];
     48         // perform test case 1
     49         new EllipticCurve(f, a, b, seed);
     50 
     51         // test case 2 parameters set
     52         ECFieldF2m f1 = new ECFieldF2m(5);
     53         a = BigInteger.ZERO;
     54         b = BigInteger.valueOf(23L);
     55         // perform test case 2
     56         new EllipticCurve(f1, a, b, seed);
     57 
     58         // test case 3 parameters set,
     59         // the seed parameter may be null
     60         f = new ECFieldFp(BigInteger.valueOf(23L));
     61         a = BigInteger.ONE;
     62         b = BigInteger.valueOf(19L);
     63         seed = null;
     64         // perform test case 3
     65         new EllipticCurve(f, a, b, seed);
     66     }
     67 
     68     /**
     69      * Test #2 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code>
     70      * constructor<br>
     71      * Assertion: throws <code>NullPointerException</code> if <code>field</code>,
     72      * <code>a</code> or <code>b</code> is <code>null</code><br>
     73      * Test preconditions: pass <code>null</code> as mentioned parameters<br>
     74      * Expected: must throw <code>NullPointerException</code>
     75      */
     76     public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray02() {
     77         // test case 1 parameters set
     78         ECFieldFp f = null;
     79         BigInteger a = BigInteger.ONE;
     80         BigInteger b = BigInteger.valueOf(19L);
     81         byte[] seed = new byte[24];
     82 
     83         // perform test case 1
     84         try {
     85             new EllipticCurve(f, a, b, seed);
     86             fail("#1: Expected NPE not thrown");
     87         } catch (NullPointerException ok) {}
     88 
     89         // test case 2 parameters set,
     90         f = new ECFieldFp(BigInteger.valueOf(23L));
     91         a = null;
     92         b = BigInteger.valueOf(19L);
     93         seed = new byte[24];
     94         // perform test case 2
     95         try {
     96             new EllipticCurve(f, a, b, seed);
     97             fail("#2: Expected NPE not thrown");
     98         } catch (NullPointerException ok) {}
     99 
    100         // test case 3 parameters set,
    101         f = new ECFieldFp(BigInteger.valueOf(23L));
    102         a = BigInteger.ONE;
    103         b = null;
    104         seed = new byte[24];
    105         // perform test case 2
    106         try {
    107             new EllipticCurve(f, a, b, seed);
    108             fail("#3: Expected NPE not thrown");
    109         } catch (NullPointerException ok) {}
    110     }
    111 
    112     /**
    113      * Test #3 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code>
    114      * constructor<br>
    115      * Assertion: throws <code>IllegalArgumentException</code> if
    116      * <code>a</code> or <code>b</code> is not <code>null</code> and not in
    117      * the <code>field</code><br>
    118      * Test preconditions: pass <code>a</code>, <code>b</code> which are
    119      * not in the <code>field</code> of type <code>ECFieldFp</code><br>
    120      * Expected: must throw <code>IllegalArgumentException</code>
    121      */
    122     public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray03() {
    123         // test case 1 parameters set,
    124         // a is not in field
    125         ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    126         BigInteger a = BigInteger.valueOf(24L);
    127         BigInteger b = BigInteger.valueOf(19L);
    128         byte[] seed = new byte[24];
    129 
    130         // perform test case 1
    131         try {
    132             new EllipticCurve(f, a, b, seed);
    133             fail("#1: Expected IAE not thrown");
    134         } catch (IllegalArgumentException ok) {}
    135 
    136         // test case 1.1 parameters set,
    137         // b is not in field
    138         f = new ECFieldFp(BigInteger.valueOf(23L));
    139         a = BigInteger.valueOf(1L);
    140         b = BigInteger.valueOf(23L);
    141         seed = new byte[24];
    142         // perform test case 1.1
    143         try {
    144             new EllipticCurve(f, a, b, seed);
    145             fail("#1.1: Expected IAE not thrown");
    146         } catch (IllegalArgumentException ok) {}
    147 
    148         // test case 2 parameters set,
    149         // b is not in field
    150         f = new ECFieldFp(BigInteger.valueOf(23L));
    151         a = BigInteger.valueOf(19L);
    152         b = BigInteger.valueOf(24L);
    153         seed = new byte[24];
    154         // perform test case 2
    155         try {
    156             new EllipticCurve(f, a, b, seed);
    157             fail("#2: Expected IAE not thrown");
    158         } catch (IllegalArgumentException ok) {}
    159 
    160         // test case 3 parameters set,
    161         // both a and b are not in field
    162         f = new ECFieldFp(BigInteger.valueOf(23L));
    163         a = BigInteger.valueOf(25L);
    164         b = BigInteger.valueOf(240L);
    165         seed = new byte[24];
    166         // perform test case 3
    167         try {
    168             new EllipticCurve(f, a, b, seed);
    169             fail("#3: Expected IAE not thrown");
    170         } catch (IllegalArgumentException ok) {}
    171     }
    172 
    173     /**
    174      * Test #4 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code>
    175      * constructor<br>
    176      * Assertion: throws <code>IllegalArgumentException</code> if
    177      * <code>a</code> or <code>b</code> is not <code>null</code> and not in
    178      * the <code>field</code><br>
    179      * Test preconditions: pass <code>a</code>, <code>b</code> which are
    180      * not in the <code>field</code> of type <code>ECFieldF2m</code><br>
    181      * Expected: must throw <code>IllegalArgumentException</code>
    182      */
    183     public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray04() {
    184         // test case 1 parameters set,
    185         // a is not in field
    186         ECFieldF2m f = new ECFieldF2m(5);
    187         BigInteger a = BigInteger.valueOf(32L);
    188         BigInteger b = BigInteger.valueOf(19L);
    189         byte[] seed = new byte[24];
    190 
    191         // perform test case 1
    192         try {
    193             new EllipticCurve(f, a, b, seed);
    194             fail("#1: Expected IAE not thrown");
    195         } catch (IllegalArgumentException ok) {}
    196 
    197         // test case 2 parameters set,
    198         // b is not in field
    199         f = new ECFieldF2m(5);
    200         a = BigInteger.valueOf(19L);
    201         b = BigInteger.valueOf(32L);
    202         seed = new byte[24];
    203         // perform test case 2
    204         try {
    205             new EllipticCurve(f, a, b, seed);
    206             fail("#2: Expected IAE not thrown");
    207         } catch (IllegalArgumentException ok) {}
    208 
    209         // test case 3 parameters set,
    210         // both a and b are not in field
    211         f = new ECFieldF2m(5);
    212         a = BigInteger.valueOf(32L);
    213         b = BigInteger.valueOf(43L);
    214         seed = new byte[24];
    215         // perform test case 3
    216         try {
    217             new EllipticCurve(f, a, b, seed);
    218             fail("#3: Expected IAE not thrown");
    219         } catch (IllegalArgumentException ok) {}
    220     }
    221 
    222     /**
    223      * Test #5 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code>
    224      * constructor<br>
    225      * Assertion: array <code>seed</code> is copied to prevent subsequent modification<br>
    226      * Test preconditions: pass <code>seed</code> to the ctor then modify it<br>
    227      * Expected: getSeed() must return unmodified array
    228      */
    229     public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray05() {
    230         ECFieldF2m f = new ECFieldF2m(5);
    231         BigInteger a = BigInteger.valueOf(0L);
    232         BigInteger b = BigInteger.valueOf(19L);
    233         byte[] seed = new byte[24];
    234         byte[] seedCopy = seed.clone();
    235         EllipticCurve c = new EllipticCurve(f, a, b, seedCopy);
    236         // modify array passed
    237         seedCopy[0] = (byte) 1;
    238         // check that above modification did not changed
    239         // internal state of test object
    240         assertTrue(Arrays.equals(seed, c.getSeed()));
    241     }
    242 
    243     /**
    244      * Test #1 for <code>EllipticCurve(ECField, BigInteger, BigInteger)</code>
    245      * constructor<br>
    246      * Assertion: creates instance of EllipticCurve<br>
    247      * Test preconditions: valid parameters passed, field type is ECFieldFp<br>
    248      * Expected: must pass without any exceptions
    249      */
    250     public final void testEllipticCurveECFieldBigIntegerBigInteger01() {
    251         // test case 1 parameters set
    252         ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    253         BigInteger a = BigInteger.ONE;
    254         BigInteger b = BigInteger.valueOf(19L);
    255         // perform test case 1
    256         new EllipticCurve(f, a, b);
    257 
    258         // test case 2 parameters set
    259         ECFieldF2m f1 = new ECFieldF2m(5);
    260         a = BigInteger.ZERO;
    261         b = BigInteger.valueOf(23L);
    262         // perform test case 2
    263         new EllipticCurve(f1, a, b);
    264 
    265         // test case 3 parameters set,
    266         // the seed parameter may be null
    267         f = new ECFieldFp(BigInteger.valueOf(23L));
    268         a = BigInteger.ONE;
    269         b = BigInteger.valueOf(19L);
    270         // perform test case 3
    271         new EllipticCurve(f, a, b);
    272     }
    273 
    274     /**
    275      * Test #2 for <code>EllipticCurve(ECField, BigInteger, BigInteger)</code>
    276      * constructor<br>
    277      * Assertion: throws <code>NullPointerException</code> if <code>field</code>,
    278      * <code>a</code> or <code>b</code> is <code>null</code><br>
    279      * Test preconditions: pass <code>null</code> as mentioned parameters<br>
    280      * Expected: must throw <code>NullPointerException</code>
    281      */
    282     public final void testEllipticCurveECFieldBigIntegerBigInteger02() {
    283         // test case 1 parameters set
    284         ECFieldFp f = null;
    285         BigInteger a = BigInteger.ONE;
    286         BigInteger b = BigInteger.valueOf(19L);
    287 
    288         // perform test case 1
    289         try {
    290             new EllipticCurve(f, a, b);
    291             fail("#1: Expected NPE not thrown");
    292         } catch (NullPointerException ok) {}
    293 
    294         // test case 2 parameters set,
    295         f = new ECFieldFp(BigInteger.valueOf(23L));
    296         a = null;
    297         b = BigInteger.valueOf(19L);
    298         // perform test case 2
    299         try {
    300             new EllipticCurve(f, a, b);
    301             fail("#2: Expected NPE not thrown");
    302         } catch (NullPointerException ok) {}
    303 
    304         // test case 3 parameters set,
    305         f = new ECFieldFp(BigInteger.valueOf(23L));
    306         a = BigInteger.ONE;
    307         b = null;
    308         // perform test case 3
    309         try {
    310             new EllipticCurve(f, a, b);
    311             fail("#3: Expected NPE not thrown");
    312         } catch (NullPointerException ok) {}
    313     }
    314 
    315     /**
    316      * Test #3 for <code>EllipticCurve(ECField, BigInteger, BigInteger)</code>
    317      * constructor<br>
    318      * Assertion: throws <code>IllegalArgumentException</code> if
    319      * <code>a</code> or <code>b</code> is not <code>null</code> and not in
    320      * the <code>field</code><br>
    321      * Test preconditions: pass <code>a</code>, <code>b</code> which are
    322      * not in the <code>field</code> of type <code>ECFieldFp</code><br>
    323      * Expected: must throw <code>IllegalArgumentException</code>
    324      */
    325     public final void testEllipticCurveECFieldBigIntegerBigInteger03() {
    326         // test case 1 parameters set,
    327         // a is not in field
    328         ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    329         BigInteger a = BigInteger.valueOf(24L);
    330         BigInteger b = BigInteger.valueOf(19L);
    331 
    332         // perform test case 1
    333         try {
    334             new EllipticCurve(f, a, b);
    335             fail("#1: Expected IAE not thrown");
    336         } catch (IllegalArgumentException ok) {}
    337 
    338         // test case 1.1 parameters set,
    339         // a is not in field
    340         f = new ECFieldFp(BigInteger.valueOf(23L));
    341         a = BigInteger.valueOf(23L);
    342         b = BigInteger.valueOf(19L);
    343         // perform test case 1.1
    344         try {
    345             new EllipticCurve(f, a, b);
    346             fail("#1.1: Expected IAE not thrown");
    347         } catch (IllegalArgumentException ok) {}
    348 
    349         // test case 2 parameters set,
    350         // b is not in field
    351         f = new ECFieldFp(BigInteger.valueOf(23L));
    352         a = BigInteger.valueOf(19L);
    353         b = BigInteger.valueOf(24L);
    354         // perform test case 2
    355         try {
    356             new EllipticCurve(f, a, b);
    357             fail("#2: Expected IAE not thrown");
    358         } catch (IllegalArgumentException ok) {}
    359 
    360         // test case 3 parameters set,
    361         // both a and b are not in field
    362         f = new ECFieldFp(BigInteger.valueOf(23L));
    363         a = BigInteger.valueOf(25L);
    364         b = BigInteger.valueOf(240L);
    365         // perform test case 3
    366         try {
    367             new EllipticCurve(f, a, b);
    368             fail("#3: Expected IAE not thrown");
    369         } catch (IllegalArgumentException ok) {}
    370     }
    371 
    372     /**
    373      * Test #4 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code>
    374      * constructor<br>
    375      * Assertion: throws <code>IllegalArgumentException</code> if
    376      * <code>a</code> or <code>b</code> is not <code>null</code> and not in
    377      * the <code>field</code><br>
    378      * Test preconditions: pass <code>a</code>, <code>b</code> which are
    379      * not in the <code>field</code> of type <code>ECFieldF2m</code><br>
    380      * Expected: must throw <code>IllegalArgumentException</code>
    381      */
    382     public final void testEllipticCurveECFieldBigIntegerBigInteger04() {
    383         // test case 1 parameters set,
    384         // a is not in field
    385         ECFieldF2m f = new ECFieldF2m(5);
    386         BigInteger a = BigInteger.valueOf(32L);
    387         BigInteger b = BigInteger.valueOf(19L);
    388         // perform test case 1
    389         try {
    390             new EllipticCurve(f, a, b);
    391             fail("#1: Expected IAE not thrown");
    392         } catch (IllegalArgumentException ok) {}
    393 
    394         // test case 2 parameters set,
    395         // b is not in field
    396         f = new ECFieldF2m(5);
    397         a = BigInteger.valueOf(19L);
    398         b = BigInteger.valueOf(32L);
    399         // perform test case 2
    400         try {
    401             new EllipticCurve(f, a, b);
    402             fail("#2: Expected IAE not thrown");
    403         } catch (IllegalArgumentException ok) {}
    404 
    405         // test case 3 parameters set,
    406         // both a and b are not in field
    407         f = new ECFieldF2m(5);
    408         a = BigInteger.valueOf(32L);
    409         b = BigInteger.valueOf(43L);
    410         // perform test case 3
    411         try {
    412             new EllipticCurve(f, a, b);
    413             fail("#3: Expected IAE not thrown");
    414         } catch (IllegalArgumentException ok) {}
    415     }
    416 
    417     /**
    418      * Test for <code>getA()</code> method<br>
    419      * Assertion: returns coefficient <code>a</code><br>
    420      * Test preconditions: <code>ECFieldF2m</code> instance
    421      * created using valid parameters<br>
    422      * Expected: must return coefficient <code>a</code> which is equal
    423      * to the one passed to the constructor; (both must refer
    424      * the same object)
    425      */
    426     public final void testGetA() {
    427         ECFieldF2m f = new ECFieldF2m(5);
    428         BigInteger a = BigInteger.valueOf(5L);
    429         BigInteger b = BigInteger.valueOf(19L);
    430         EllipticCurve c = new EllipticCurve(f, a, b);
    431         assertEquals(a, c.getA());
    432         assertSame(a, c.getA());
    433     }
    434 
    435     /**
    436      * java/security/spec/EllipticCurve#EllipticCurve(EcField,BigInteger,BigInteger)
    437      */
    438     public final void testEllipticCurveECFieldBigIntegerBigInteger05() {
    439         // Regression for Harmony-731
    440         EllipticCurve ec = new EllipticCurve(new testECField(), BigInteger
    441                 .valueOf(4L), BigInteger.ONE);
    442         assertEquals("incorrect a", ec.getA(), BigInteger.valueOf(4L));
    443         assertEquals("incorrect b", ec.getB(), BigInteger.ONE);
    444         assertEquals("incorrect size", ec.getField().getFieldSize(), 2);
    445     }
    446 
    447     /**
    448      * Test for <code>getB()</code> method<br>
    449      * Assertion: returns coefficient <code>b</code><br>
    450      * Test preconditions: <code>ECFieldF2m</code> instance
    451      * created using valid parameters<br>
    452      * Expected: must return coefficient <code>b</code> which is equal
    453      * to the one passed to the constructor; (both must refer
    454      * the same object)
    455      */
    456     public final void testGetB() {
    457         ECFieldF2m f = new ECFieldF2m(5);
    458         BigInteger a = BigInteger.valueOf(5L);
    459         BigInteger b = BigInteger.valueOf(19L);
    460         EllipticCurve c = new EllipticCurve(f, a, b);
    461         assertEquals(b, c.getB());
    462         assertSame(b, c.getB());
    463     }
    464 
    465     /**
    466      * Test for <code>getField()</code> method<br>
    467      * Assertion: returns <code>field</code><br>
    468      * Test preconditions: <code>ECFieldF2m</code> instance
    469      * created using valid parameters<br>
    470      * Expected: must return <code>field</code> which is equal
    471      * to the one passed to the constructor; (both must refer
    472      * the same object)
    473      */
    474     public final void testGetField() {
    475         ECFieldF2m f = new ECFieldF2m(5);
    476         BigInteger a = BigInteger.valueOf(5L);
    477         BigInteger b = BigInteger.valueOf(19L);
    478         EllipticCurve c = new EllipticCurve(f, a, b);
    479         assertEquals(f, c.getField());
    480         assertSame(f, c.getField());
    481     }
    482 
    483     /**
    484      * Test #1 for <code>getSeed()</code> method<br>
    485      * Assertion: returns <code>seed</code><br>
    486      * Test preconditions: <code>ECFieldF2m</code> instance
    487      * created using valid parameters<br>
    488      * Expected: must return <code>seed</code> which is equal
    489      * to the one passed to the constructor
    490      */
    491     public final void testGetSeed01() {
    492         ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    493         BigInteger a = BigInteger.ONE;
    494         BigInteger b = BigInteger.valueOf(19L);
    495         byte[] seed = new byte[24];
    496         EllipticCurve c = new EllipticCurve(f, a, b, seed);
    497         byte[] seedRet = c.getSeed();
    498         assertNotNull(seedRet);
    499         assertTrue(Arrays.equals(seed, seedRet));
    500     }
    501 
    502     /**
    503      * Test #2 for <code>getSeed()</code> method<br>
    504      * Assertion: returned array is copied to prevent subsequent modification<br>
    505      * Test preconditions: <code>ECFieldF2m</code> instance
    506      * created using valid parameters; <code>getSeed()</code>
    507      * called and then returned array modified<br>
    508      * Expected: internal state must not be affected by the modification
    509      */
    510     public final void testGetSeed02() {
    511         ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    512         BigInteger a = BigInteger.ONE;
    513         BigInteger b = BigInteger.valueOf(19L);
    514         byte[] seed = new byte[24];
    515         EllipticCurve c = new EllipticCurve(f, a, b, seed.clone());
    516         byte[] seedRet = c.getSeed();
    517         // modify returned array
    518         seedRet[0] = (byte) 1;
    519         // check that above modification did not changed
    520         // internal state of test object
    521         assertTrue(Arrays.equals(seed, c.getSeed()));
    522     }
    523 
    524     /**
    525      * Test #3 for <code>getSeed()</code> method<br>
    526      * Assertion: returned array is copied to prevent subsequent modification<br>
    527      * Test preconditions: <code>ECFieldF2m</code> instance
    528      * created using valid parameters<br>
    529      * Expected: repeated method calls must return different refs
    530      */
    531     public final void testGetSeed03() {
    532         ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    533         BigInteger a = BigInteger.ONE;
    534         BigInteger b = BigInteger.valueOf(19L);
    535         byte[] seed = new byte[24];
    536         EllipticCurve c = new EllipticCurve(f, a, b, seed);
    537         c.getSeed();
    538         assertNotSame(c.getSeed(), c.getSeed());
    539     }
    540 
    541     /**
    542      * java.security.spec.EllipticCurve#getSeed()
    543      * Assertion: null if not specified
    544      */
    545     public final void testGetSeed04() {
    546         //Regression for HARMONY-732
    547         ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    548         BigInteger a = BigInteger.ONE;
    549         assertNull(new EllipticCurve(f, a, a).getSeed());
    550     }
    551 
    552     /**
    553      * Test #1 for <code>equals(Object other)</code> method<br>
    554      * Assertion: return true if this and other objects are equal<br>
    555      * Test preconditions: see test comments<br>
    556      * Expected: all objects in this test must be equal
    557      */
    558     public final void testEqualsObject01() {
    559         // test case 1: must be equal to itself
    560         EllipticCurve c2 = null, c1 = new EllipticCurve(new ECFieldFp(
    561                 BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger
    562                 .valueOf(19L));
    563         assertTrue(c1.equals(c1));
    564 
    565         // test case 2: equal objects
    566         c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)),
    567                 BigInteger.ONE, BigInteger.valueOf(19L));
    568         c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)),
    569                 BigInteger.valueOf(1L), BigInteger.valueOf(19L));
    570         assertTrue(c1.equals(c2) && c2.equals(c1));
    571 
    572         // test case 3: equal objects with seed not null
    573         c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)),
    574                 BigInteger.ONE, BigInteger.valueOf(19L), new byte[24]);
    575         c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)),
    576                 BigInteger.valueOf(1L), BigInteger.valueOf(19L), new byte[24]);
    577         assertTrue(c1.equals(c2) && c2.equals(c1));
    578 
    579         // test case 4: equal object and subclass object
    580         c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)),
    581                 BigInteger.ONE, BigInteger.valueOf(19L), new byte[24]);
    582         MyEllipticCurve c3 = new MyEllipticCurve(new ECFieldFp(BigInteger
    583                 .valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L),
    584                 new byte[24]);
    585         assertTrue(c1.equals(c3) && c3.equals(c1));
    586 
    587         // test case 5: equal objects
    588         c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)),
    589                 BigInteger.ONE, BigInteger.valueOf(19L));
    590         c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)),
    591                 BigInteger.valueOf(1L), BigInteger.valueOf(19L), null);
    592         assertTrue(c1.equals(c2) && c2.equals(c1));
    593     }
    594 
    595     /**
    596      * Test #1 for <code>hashCode()</code> method.<br>
    597      *
    598      * Assertion: must return the same value if invoked
    599      * repeatedly on the same object.
    600      */
    601     public final void testHashCode01() {
    602         int hc = 0;
    603         EllipticCurve f = new EllipticCurve(new ECFieldFp(BigInteger
    604                 .valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L),
    605                 new byte[24]);
    606         hc = f.hashCode();
    607         assertTrue(hc == f.hashCode() && hc == f.hashCode()
    608                 && hc == f.hashCode() && hc == f.hashCode()
    609                 && hc == f.hashCode() && hc == f.hashCode()
    610                 && hc == f.hashCode() && hc == f.hashCode());
    611     }
    612 
    613     /**
    614      * Test #2 for <code>hashCode()</code> method.<br>
    615      *
    616      * Assertion: must return the same value if invoked
    617      * on equal (according to the <code>equals(Object)</code> method) objects.
    618      */
    619     public final void testHashCode02() {
    620         assertEquals(new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)),
    621                 BigInteger.ONE, BigInteger.valueOf(19L), new byte[24])
    622                 .hashCode(), new EllipticCurve(new ECFieldFp(BigInteger
    623                 .valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L),
    624                 new byte[24]).hashCode());
    625     }
    626 
    627     //
    628     // Private stuff
    629     //
    630 
    631     class testECField implements ECField {
    632 
    633         public int getFieldSize() {
    634             return 2;
    635         }
    636     }
    637 
    638     /**
    639      * EllipticCurve subclass for testing purposes
    640      *
    641      */
    642     private static class MyEllipticCurve extends EllipticCurve {
    643 
    644         MyEllipticCurve(ECField f, BigInteger a, BigInteger b, byte[] seed) {
    645             super(f, a, b, seed);
    646         }
    647     }
    648 }
    649