jdk/src/share/classes/java/security/spec/ECFieldF2m.java
author juh
Tue, 25 Jun 2013 14:41:46 -0700
changeset 18552 005e115dc6ee
parent 5506 202f599c92aa
child 21278 ef8a3a2a72f2
permissions -rw-r--r--
8017326: Cleanup of the javadoc <code> tag in java.security.spec Summary: Convert javadoc <code> and <tt> tags to {@code ...} Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.security.spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * This immutable class defines an elliptic curve (EC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * characteristic 2 finite field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @see ECField
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @author Valerie Peng
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class ECFieldF2m implements ECField {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private int m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private int[] ks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private BigInteger rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * Creates an elliptic curve characteristic 2 finite
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    48
     * field which has 2^{@code m} elements with normal basis.
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    49
     * @param m with 2^{@code m} being the number of elements.
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    50
     * @exception IllegalArgumentException if {@code m}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * is not positive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public ECFieldF2m(int m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        if (m <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            throw new IllegalArgumentException("m is not positive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        this.m = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this.ks = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        this.rp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Creates an elliptic curve characteristic 2 finite
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    64
     * field which has 2^{@code m} elements with
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * polynomial basis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * The reduction polynomial for this field is based
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    67
     * on {@code rp} whose i-th bit correspondes to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * the i-th coefficient of the reduction polynomial.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Note: A valid reduction polynomial is either a
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    70
     * trinomial (X^{@code m} + X^{@code k} + 1
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    71
     * with {@code m} &gt; {@code k} &gt;= 1) or a
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    72
     * pentanomial (X^{@code m} + X^{@code k3}
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    73
     * + X^{@code k2} + X^{@code k1} + 1 with
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    74
     * {@code m} &gt; {@code k3} &gt; {@code k2}
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    75
     * &gt; {@code k1} &gt;= 1).
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    76
     * @param m with 2^{@code m} being the number of elements.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param rp the BigInteger whose i-th bit corresponds to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * the i-th coefficient of the reduction polynomial.
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    79
     * @exception NullPointerException if {@code rp} is null.
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    80
     * @exception IllegalArgumentException if {@code m}
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
    81
     * is not positive, or {@code rp} does not represent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * a valid reduction polynomial.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public ECFieldF2m(int m, BigInteger rp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // check m and rp
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        this.m = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        this.rp = rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (m <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            throw new IllegalArgumentException("m is not positive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        int bitCount = this.rp.bitCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (!this.rp.testBit(0) || !this.rp.testBit(m) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            ((bitCount != 3) && (bitCount != 5))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                ("rp does not represent a valid reduction polynomial");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        // convert rp into ks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        BigInteger temp = this.rp.clearBit(0).clearBit(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.ks = new int[bitCount-2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        for (int i = this.ks.length-1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            int index = temp.getLowestSetBit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            this.ks[i] = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            temp = temp.clearBit(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Creates an elliptic curve characteristic 2 finite
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   109
     * field which has 2^{@code m} elements with
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * polynomial basis. The reduction polynomial for this
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   111
     * field is based on {@code ks} whose content
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * contains the order of the middle term(s) of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * reduction polynomial.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Note: A valid reduction polynomial is either a
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   115
     * trinomial (X^{@code m} + X^{@code k} + 1
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   116
     * with {@code m} &gt; {@code k} &gt;= 1) or a
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   117
     * pentanomial (X^{@code m} + X^{@code k3}
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   118
     * + X^{@code k2} + X^{@code k1} + 1 with
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   119
     * {@code m} &gt; {@code k3} &gt; {@code k2}
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   120
     * &gt; {@code k1} &gt;= 1), so {@code ks} should
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * have length 1 or 3.
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   122
     * @param m with 2^{@code m} being the number of elements.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param ks the order of the middle term(s) of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * reduction polynomial. Contents of this array are copied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * to protect against subsequent modification.
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   126
     * @exception NullPointerException if {@code ks} is null.
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   127
     * @exception IllegalArgumentException if{@code m}
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   128
     * is not positive, or the length of {@code ks}
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   129
     * is neither 1 nor 3, or values in {@code ks}
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   130
     * are not between {@code m}-1 and 1 (inclusive)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * and in descending order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public ECFieldF2m(int m, int[] ks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // check m and ks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        this.m = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        this.ks = ks.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (m <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            throw new IllegalArgumentException("m is not positive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if ((this.ks.length != 1) && (this.ks.length != 3)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                ("length of ks is neither 1 nor 3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        for (int i = 0; i < this.ks.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            if ((this.ks[i] < 1) || (this.ks[i] > m-1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    ("ks["+ i + "] is out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            if ((i != 0) && (this.ks[i] >= this.ks[i-1])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    ("values in ks are not in descending order");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        // convert ks into rp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        this.rp = BigInteger.ONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        this.rp = rp.setBit(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        for (int j = 0; j < this.ks.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            rp = rp.setBit(this.ks[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   163
     * Returns the field size in bits which is {@code m}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * for this characteristic 2 finite field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @return the field size in bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public int getFieldSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   172
     * Returns the value {@code m} of this characteristic
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * 2 finite field.
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   174
     * @return {@code m} with 2^{@code m} being the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * number of elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public int getM() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        return m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Returns a BigInteger whose i-th bit corresponds to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * i-th coefficient of the reduction polynomial for polynomial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * basis or null for normal basis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @return a BigInteger whose i-th bit corresponds to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * i-th coefficient of the reduction polynomial for polynomial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * basis or null for normal basis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public BigInteger getReductionPolynomial() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Returns an integer array which contains the order of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * middle term(s) of the reduction polynomial for polynomial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * basis or null for normal basis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @return an integer array which contains the order of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * middle term(s) of the reduction polynomial for polynomial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * basis or null for normal basis. A new array is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * each time this method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public int[] getMidTermsOfReductionPolynomial() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (ks == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            return ks.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Compares this finite field for equality with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param obj the object to be compared.
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   214
     * @return true if {@code obj} is an instance
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 5506
diff changeset
   215
     * of ECFieldF2m and both {@code m} and the reduction
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * polynomial match, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (this == obj) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (obj instanceof ECFieldF2m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            // no need to compare rp here since ks and rp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            // should be equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            return ((m == ((ECFieldF2m)obj).m) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    (Arrays.equals(ks, ((ECFieldF2m) obj).ks)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Returns a hash code value for this characteristic 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * finite field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @return a hash code value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        int value = m << 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        value += (rp==null? 0:rp.hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        // no need to involve ks here since ks and rp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        // should be equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
}