1 /* |
1 /* |
2 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
43 private int[] ks; |
43 private int[] ks; |
44 private BigInteger rp; |
44 private BigInteger rp; |
45 |
45 |
46 /** |
46 /** |
47 * Creates an elliptic curve characteristic 2 finite |
47 * Creates an elliptic curve characteristic 2 finite |
48 * field which has 2^<code>m</code> elements with normal basis. |
48 * field which has 2^{@code m} elements with normal basis. |
49 * @param m with 2^<code>m</code> being the number of elements. |
49 * @param m with 2^{@code m} being the number of elements. |
50 * @exception IllegalArgumentException if <code>m</code> |
50 * @exception IllegalArgumentException if {@code m} |
51 * is not positive. |
51 * is not positive. |
52 */ |
52 */ |
53 public ECFieldF2m(int m) { |
53 public ECFieldF2m(int m) { |
54 if (m <= 0) { |
54 if (m <= 0) { |
55 throw new IllegalArgumentException("m is not positive"); |
55 throw new IllegalArgumentException("m is not positive"); |
59 this.rp = null; |
59 this.rp = null; |
60 } |
60 } |
61 |
61 |
62 /** |
62 /** |
63 * Creates an elliptic curve characteristic 2 finite |
63 * Creates an elliptic curve characteristic 2 finite |
64 * field which has 2^<code>m</code> elements with |
64 * field which has 2^{@code m} elements with |
65 * polynomial basis. |
65 * polynomial basis. |
66 * The reduction polynomial for this field is based |
66 * The reduction polynomial for this field is based |
67 * on <code>rp</code> whose i-th bit correspondes to |
67 * on {@code rp} whose i-th bit correspondes to |
68 * the i-th coefficient of the reduction polynomial.<p> |
68 * the i-th coefficient of the reduction polynomial.<p> |
69 * Note: A valid reduction polynomial is either a |
69 * Note: A valid reduction polynomial is either a |
70 * trinomial (X^<code>m</code> + X^<code>k</code> + 1 |
70 * trinomial (X^{@code m} + X^{@code k} + 1 |
71 * with <code>m</code> > <code>k</code> >= 1) or a |
71 * with {@code m} > {@code k} >= 1) or a |
72 * pentanomial (X^<code>m</code> + X^<code>k3</code> |
72 * pentanomial (X^{@code m} + X^{@code k3} |
73 * + X^<code>k2</code> + X^<code>k1</code> + 1 with |
73 * + X^{@code k2} + X^{@code k1} + 1 with |
74 * <code>m</code> > <code>k3</code> > <code>k2</code> |
74 * {@code m} > {@code k3} > {@code k2} |
75 * > <code>k1</code> >= 1). |
75 * > {@code k1} >= 1). |
76 * @param m with 2^<code>m</code> being the number of elements. |
76 * @param m with 2^{@code m} being the number of elements. |
77 * @param rp the BigInteger whose i-th bit corresponds to |
77 * @param rp the BigInteger whose i-th bit corresponds to |
78 * the i-th coefficient of the reduction polynomial. |
78 * the i-th coefficient of the reduction polynomial. |
79 * @exception NullPointerException if <code>rp</code> is null. |
79 * @exception NullPointerException if {@code rp} is null. |
80 * @exception IllegalArgumentException if <code>m</code> |
80 * @exception IllegalArgumentException if {@code m} |
81 * is not positive, or <code>rp</code> does not represent |
81 * is not positive, or {@code rp} does not represent |
82 * a valid reduction polynomial. |
82 * a valid reduction polynomial. |
83 */ |
83 */ |
84 public ECFieldF2m(int m, BigInteger rp) { |
84 public ECFieldF2m(int m, BigInteger rp) { |
85 // check m and rp |
85 // check m and rp |
86 this.m = m; |
86 this.m = m; |
104 } |
104 } |
105 } |
105 } |
106 |
106 |
107 /** |
107 /** |
108 * Creates an elliptic curve characteristic 2 finite |
108 * Creates an elliptic curve characteristic 2 finite |
109 * field which has 2^<code>m</code> elements with |
109 * field which has 2^{@code m} elements with |
110 * polynomial basis. The reduction polynomial for this |
110 * polynomial basis. The reduction polynomial for this |
111 * field is based on <code>ks</code> whose content |
111 * field is based on {@code ks} whose content |
112 * contains the order of the middle term(s) of the |
112 * contains the order of the middle term(s) of the |
113 * reduction polynomial. |
113 * reduction polynomial. |
114 * Note: A valid reduction polynomial is either a |
114 * Note: A valid reduction polynomial is either a |
115 * trinomial (X^<code>m</code> + X^<code>k</code> + 1 |
115 * trinomial (X^{@code m} + X^{@code k} + 1 |
116 * with <code>m</code> > <code>k</code> >= 1) or a |
116 * with {@code m} > {@code k} >= 1) or a |
117 * pentanomial (X^<code>m</code> + X^<code>k3</code> |
117 * pentanomial (X^{@code m} + X^{@code k3} |
118 * + X^<code>k2</code> + X^<code>k1</code> + 1 with |
118 * + X^{@code k2} + X^{@code k1} + 1 with |
119 * <code>m</code> > <code>k3</code> > <code>k2</code> |
119 * {@code m} > {@code k3} > {@code k2} |
120 * > <code>k1</code> >= 1), so <code>ks</code> should |
120 * > {@code k1} >= 1), so {@code ks} should |
121 * have length 1 or 3. |
121 * have length 1 or 3. |
122 * @param m with 2^<code>m</code> being the number of elements. |
122 * @param m with 2^{@code m} being the number of elements. |
123 * @param ks the order of the middle term(s) of the |
123 * @param ks the order of the middle term(s) of the |
124 * reduction polynomial. Contents of this array are copied |
124 * reduction polynomial. Contents of this array are copied |
125 * to protect against subsequent modification. |
125 * to protect against subsequent modification. |
126 * @exception NullPointerException if <code>ks</code> is null. |
126 * @exception NullPointerException if {@code ks} is null. |
127 * @exception IllegalArgumentException if<code>m</code> |
127 * @exception IllegalArgumentException if{@code m} |
128 * is not positive, or the length of <code>ks</code> |
128 * is not positive, or the length of {@code ks} |
129 * is neither 1 nor 3, or values in <code>ks</code> |
129 * is neither 1 nor 3, or values in {@code ks} |
130 * are not between <code>m</code>-1 and 1 (inclusive) |
130 * are not between {@code m}-1 and 1 (inclusive) |
131 * and in descending order. |
131 * and in descending order. |
132 */ |
132 */ |
133 public ECFieldF2m(int m, int[] ks) { |
133 public ECFieldF2m(int m, int[] ks) { |
134 // check m and ks |
134 // check m and ks |
135 this.m = m; |
135 this.m = m; |
158 rp = rp.setBit(this.ks[j]); |
158 rp = rp.setBit(this.ks[j]); |
159 } |
159 } |
160 } |
160 } |
161 |
161 |
162 /** |
162 /** |
163 * Returns the field size in bits which is <code>m</code> |
163 * Returns the field size in bits which is {@code m} |
164 * for this characteristic 2 finite field. |
164 * for this characteristic 2 finite field. |
165 * @return the field size in bits. |
165 * @return the field size in bits. |
166 */ |
166 */ |
167 public int getFieldSize() { |
167 public int getFieldSize() { |
168 return m; |
168 return m; |
169 } |
169 } |
170 |
170 |
171 /** |
171 /** |
172 * Returns the value <code>m</code> of this characteristic |
172 * Returns the value {@code m} of this characteristic |
173 * 2 finite field. |
173 * 2 finite field. |
174 * @return <code>m</code> with 2^<code>m</code> being the |
174 * @return {@code m} with 2^{@code m} being the |
175 * number of elements. |
175 * number of elements. |
176 */ |
176 */ |
177 public int getM() { |
177 public int getM() { |
178 return m; |
178 return m; |
179 } |
179 } |
209 |
209 |
210 /** |
210 /** |
211 * Compares this finite field for equality with the |
211 * Compares this finite field for equality with the |
212 * specified object. |
212 * specified object. |
213 * @param obj the object to be compared. |
213 * @param obj the object to be compared. |
214 * @return true if <code>obj</code> is an instance |
214 * @return true if {@code obj} is an instance |
215 * of ECFieldF2m and both <code>m</code> and the reduction |
215 * of ECFieldF2m and both {@code m} and the reduction |
216 * polynomial match, false otherwise. |
216 * polynomial match, false otherwise. |
217 */ |
217 */ |
218 public boolean equals(Object obj) { |
218 public boolean equals(Object obj) { |
219 if (this == obj) return true; |
219 if (this == obj) return true; |
220 if (obj instanceof ECFieldF2m) { |
220 if (obj instanceof ECFieldF2m) { |