2 * Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 /* ====================================================================
11 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
12 * Binary polynomial ECC support in OpenSSL originally developed by
13 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
18 #include <openssl/err.h>
19 #include <openssl/opensslv.h>
23 int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP
*group
,
24 EC_POINT
*point
, const BIGNUM
*x
,
25 int y_bit
, BN_CTX
*ctx
)
27 if (group
->meth
->point_set_compressed_coordinates
== 0
28 && !(group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
)) {
29 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP
,
30 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
33 if (group
->meth
!= point
->meth
) {
34 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP
,
35 EC_R_INCOMPATIBLE_OBJECTS
);
38 if (group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
) {
39 if (group
->meth
->field_type
== NID_X9_62_prime_field
)
40 return ec_GFp_simple_set_compressed_coordinates(group
, point
, x
,
43 #ifdef OPENSSL_NO_EC2M
45 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP
,
46 EC_R_GF2M_NOT_SUPPORTED
);
50 return ec_GF2m_simple_set_compressed_coordinates(group
, point
, x
,
54 return group
->meth
->point_set_compressed_coordinates(group
, point
, x
,
58 #ifndef OPENSSL_NO_EC2M
59 int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP
*group
,
60 EC_POINT
*point
, const BIGNUM
*x
,
61 int y_bit
, BN_CTX
*ctx
)
63 if (group
->meth
->point_set_compressed_coordinates
== 0
64 && !(group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
)) {
65 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M
,
66 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
69 if (group
->meth
!= point
->meth
) {
70 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M
,
71 EC_R_INCOMPATIBLE_OBJECTS
);
74 if (group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
) {
75 if (group
->meth
->field_type
== NID_X9_62_prime_field
)
76 return ec_GFp_simple_set_compressed_coordinates(group
, point
, x
,
79 return ec_GF2m_simple_set_compressed_coordinates(group
, point
, x
,
82 return group
->meth
->point_set_compressed_coordinates(group
, point
, x
,
87 size_t EC_POINT_point2oct(const EC_GROUP
*group
, const EC_POINT
*point
,
88 point_conversion_form_t form
, unsigned char *buf
,
89 size_t len
, BN_CTX
*ctx
)
91 if (group
->meth
->point2oct
== 0
92 && !(group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
)) {
93 ECerr(EC_F_EC_POINT_POINT2OCT
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
96 if (group
->meth
!= point
->meth
) {
97 ECerr(EC_F_EC_POINT_POINT2OCT
, EC_R_INCOMPATIBLE_OBJECTS
);
100 if (group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
) {
101 if (group
->meth
->field_type
== NID_X9_62_prime_field
)
102 return ec_GFp_simple_point2oct(group
, point
, form
, buf
, len
, ctx
);
104 #ifdef OPENSSL_NO_EC2M
106 ECerr(EC_F_EC_POINT_POINT2OCT
, EC_R_GF2M_NOT_SUPPORTED
);
110 return ec_GF2m_simple_point2oct(group
, point
,
111 form
, buf
, len
, ctx
);
115 return group
->meth
->point2oct(group
, point
, form
, buf
, len
, ctx
);
118 int EC_POINT_oct2point(const EC_GROUP
*group
, EC_POINT
*point
,
119 const unsigned char *buf
, size_t len
, BN_CTX
*ctx
)
121 if (group
->meth
->oct2point
== 0
122 && !(group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
)) {
123 ECerr(EC_F_EC_POINT_OCT2POINT
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
126 if (group
->meth
!= point
->meth
) {
127 ECerr(EC_F_EC_POINT_OCT2POINT
, EC_R_INCOMPATIBLE_OBJECTS
);
130 if (group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
) {
131 if (group
->meth
->field_type
== NID_X9_62_prime_field
)
132 return ec_GFp_simple_oct2point(group
, point
, buf
, len
, ctx
);
134 #ifdef OPENSSL_NO_EC2M
136 ECerr(EC_F_EC_POINT_OCT2POINT
, EC_R_GF2M_NOT_SUPPORTED
);
140 return ec_GF2m_simple_oct2point(group
, point
, buf
, len
, ctx
);
143 return group
->meth
->oct2point(group
, point
, buf
, len
, ctx
);
146 size_t EC_POINT_point2buf(const EC_GROUP
*group
, const EC_POINT
*point
,
147 point_conversion_form_t form
,
148 unsigned char **pbuf
, BN_CTX
*ctx
)
152 len
= EC_POINT_point2oct(group
, point
, form
, NULL
, 0, NULL
);
155 buf
= OPENSSL_malloc(len
);
158 len
= EC_POINT_point2oct(group
, point
, form
, buf
, len
, ctx
);