2 * Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
5 * Licensed under the Apache License 2.0 (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
12 * ECDSA low level APIs are deprecated for public use, but still ok for
15 #include "internal/deprecated.h"
19 #include <openssl/err.h>
20 #include <openssl/opensslv.h>
24 int EC_POINT_set_compressed_coordinates(const EC_GROUP
*group
, EC_POINT
*point
,
25 const BIGNUM
*x
, int y_bit
, BN_CTX
*ctx
)
27 if (group
->meth
->point_set_compressed_coordinates
== NULL
28 && !(group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
)) {
29 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES
,
30 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
33 if (!ec_point_is_compat(point
, group
)) {
34 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES
,
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
,
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_DEPRECATED_3_0
59 int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP
*group
,
60 EC_POINT
*point
, const BIGNUM
*x
,
61 int y_bit
, BN_CTX
*ctx
)
63 return EC_POINT_set_compressed_coordinates(group
, point
, x
, y_bit
, ctx
);
66 # ifndef OPENSSL_NO_EC2M
67 int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP
*group
,
68 EC_POINT
*point
, const BIGNUM
*x
,
69 int y_bit
, BN_CTX
*ctx
)
71 return EC_POINT_set_compressed_coordinates(group
, point
, x
, y_bit
, ctx
);
76 size_t EC_POINT_point2oct(const EC_GROUP
*group
, const EC_POINT
*point
,
77 point_conversion_form_t form
, unsigned char *buf
,
78 size_t len
, BN_CTX
*ctx
)
80 if (group
->meth
->point2oct
== 0
81 && !(group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
)) {
82 ECerr(EC_F_EC_POINT_POINT2OCT
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
85 if (!ec_point_is_compat(point
, group
)) {
86 ECerr(EC_F_EC_POINT_POINT2OCT
, EC_R_INCOMPATIBLE_OBJECTS
);
89 if (group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
) {
90 if (group
->meth
->field_type
== NID_X9_62_prime_field
)
91 return ec_GFp_simple_point2oct(group
, point
, form
, buf
, len
, ctx
);
93 #ifdef OPENSSL_NO_EC2M
95 ECerr(EC_F_EC_POINT_POINT2OCT
, EC_R_GF2M_NOT_SUPPORTED
);
99 return ec_GF2m_simple_point2oct(group
, point
,
100 form
, buf
, len
, ctx
);
104 return group
->meth
->point2oct(group
, point
, form
, buf
, len
, ctx
);
107 int EC_POINT_oct2point(const EC_GROUP
*group
, EC_POINT
*point
,
108 const unsigned char *buf
, size_t len
, BN_CTX
*ctx
)
110 if (group
->meth
->oct2point
== 0
111 && !(group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
)) {
112 ECerr(EC_F_EC_POINT_OCT2POINT
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
115 if (!ec_point_is_compat(point
, group
)) {
116 ECerr(EC_F_EC_POINT_OCT2POINT
, EC_R_INCOMPATIBLE_OBJECTS
);
119 if (group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
) {
120 if (group
->meth
->field_type
== NID_X9_62_prime_field
)
121 return ec_GFp_simple_oct2point(group
, point
, buf
, len
, ctx
);
123 #ifdef OPENSSL_NO_EC2M
125 ECerr(EC_F_EC_POINT_OCT2POINT
, EC_R_GF2M_NOT_SUPPORTED
);
129 return ec_GF2m_simple_oct2point(group
, point
, buf
, len
, ctx
);
132 return group
->meth
->oct2point(group
, point
, buf
, len
, ctx
);
135 size_t EC_POINT_point2buf(const EC_GROUP
*group
, const EC_POINT
*point
,
136 point_conversion_form_t form
,
137 unsigned char **pbuf
, BN_CTX
*ctx
)
142 len
= EC_POINT_point2oct(group
, point
, form
, NULL
, 0, NULL
);
145 if ((buf
= OPENSSL_malloc(len
)) == NULL
) {
146 ECerr(EC_F_EC_POINT_POINT2BUF
, ERR_R_MALLOC_FAILURE
);
149 len
= EC_POINT_point2oct(group
, point
, form
, buf
, len
, ctx
);