2 * Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
5 * Licensed under the OpenSSL license (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
13 #include <openssl/err.h>
14 #include <openssl/opensslv.h>
18 int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group,
19 EC_POINT *point, const BIGNUM *x,
20 int y_bit, BN_CTX *ctx)
22 if (group->meth->point_set_compressed_coordinates == 0
23 && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {
24 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP,
25 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
28 if (group->meth != point->meth) {
29 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP,
30 EC_R_INCOMPATIBLE_OBJECTS);
33 if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
34 if (group->meth->field_type == NID_X9_62_prime_field)
35 return ec_GFp_simple_set_compressed_coordinates(group, point, x,
38 #ifdef OPENSSL_NO_EC2M
40 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP,
41 EC_R_GF2M_NOT_SUPPORTED);
45 return ec_GF2m_simple_set_compressed_coordinates(group, point, x,
49 return group->meth->point_set_compressed_coordinates(group, point, x,
53 #ifndef OPENSSL_NO_EC2M
54 int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group,
55 EC_POINT *point, const BIGNUM *x,
56 int y_bit, BN_CTX *ctx)
58 if (group->meth->point_set_compressed_coordinates == 0
59 && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {
60 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M,
61 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
64 if (group->meth != point->meth) {
65 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M,
66 EC_R_INCOMPATIBLE_OBJECTS);
69 if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
70 if (group->meth->field_type == NID_X9_62_prime_field)
71 return ec_GFp_simple_set_compressed_coordinates(group, point, x,
74 return ec_GF2m_simple_set_compressed_coordinates(group, point, x,
77 return group->meth->point_set_compressed_coordinates(group, point, x,
82 size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point,
83 point_conversion_form_t form, unsigned char *buf,
84 size_t len, BN_CTX *ctx)
86 if (group->meth->point2oct == 0
87 && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {
88 ECerr(EC_F_EC_POINT_POINT2OCT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
91 if (group->meth != point->meth) {
92 ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_INCOMPATIBLE_OBJECTS);
95 if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
96 if (group->meth->field_type == NID_X9_62_prime_field)
97 return ec_GFp_simple_point2oct(group, point, form, buf, len, ctx);
99 #ifdef OPENSSL_NO_EC2M
101 ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_GF2M_NOT_SUPPORTED);
105 return ec_GF2m_simple_point2oct(group, point,
106 form, buf, len, ctx);
110 return group->meth->point2oct(group, point, form, buf, len, ctx);
113 int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
114 const unsigned char *buf, size_t len, BN_CTX *ctx)
116 if (group->meth->oct2point == 0
117 && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {
118 ECerr(EC_F_EC_POINT_OCT2POINT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
121 if (group->meth != point->meth) {
122 ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_INCOMPATIBLE_OBJECTS);
125 if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
126 if (group->meth->field_type == NID_X9_62_prime_field)
127 return ec_GFp_simple_oct2point(group, point, buf, len, ctx);
129 #ifdef OPENSSL_NO_EC2M
131 ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_GF2M_NOT_SUPPORTED);
135 return ec_GF2m_simple_oct2point(group, point, buf, len, ctx);
138 return group->meth->oct2point(group, point, buf, len, ctx);
141 size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point,
142 point_conversion_form_t form,
143 unsigned char **pbuf, BN_CTX *ctx)
147 len = EC_POINT_point2oct(group, point, form, NULL, 0, NULL);
150 buf = OPENSSL_malloc(len);
153 len = EC_POINT_point2oct(group, point, form, buf, len, ctx);