• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package org.conscrypt;
18 
19 import java.math.BigInteger;
20 import java.security.spec.ECPoint;
21 
22 final class OpenSSLECPointContext {
23     private final OpenSSLECGroupContext group;
24     private final NativeRef.EC_POINT pointCtx;
25 
OpenSSLECPointContext(OpenSSLECGroupContext group, NativeRef.EC_POINT pointCtx)26     OpenSSLECPointContext(OpenSSLECGroupContext group, NativeRef.EC_POINT pointCtx) {
27         this.group = group;
28         this.pointCtx = pointCtx;
29     }
30 
31     @Override
equals(Object o)32     public boolean equals(Object o) {
33         throw new IllegalArgumentException("OpenSSLECPointContext.equals is not defined.");
34     }
35 
getECPoint()36     public ECPoint getECPoint() {
37         final byte[][] generatorCoords = NativeCrypto.EC_POINT_get_affine_coordinates(
38                 group.getNativeRef(), pointCtx);
39         final BigInteger x = new BigInteger(generatorCoords[0]);
40         final BigInteger y = new BigInteger(generatorCoords[1]);
41         return new ECPoint(x, y);
42     }
43 
44     @Override
hashCode()45     public int hashCode() {
46         // TODO Auto-generated method stub
47         return super.hashCode();
48     }
49 
getNativeRef()50     public NativeRef.EC_POINT getNativeRef() {
51         return pointCtx;
52     }
53 
getInstance(int curveType, OpenSSLECGroupContext group, ECPoint javaPoint)54     public static OpenSSLECPointContext getInstance(int curveType, OpenSSLECGroupContext group,
55             ECPoint javaPoint) {
56         OpenSSLECPointContext point = new OpenSSLECPointContext(group, new NativeRef.EC_POINT(
57                 NativeCrypto.EC_POINT_new(group.getNativeRef())));
58         NativeCrypto.EC_POINT_set_affine_coordinates(group.getNativeRef(),
59                 point.getNativeRef(), javaPoint.getAffineX().toByteArray(),
60                 javaPoint.getAffineY().toByteArray());
61         return point;
62     }
63 }
64