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 ERR_raise(ERR_LIB_EC
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
32 if (!ec_point_is_compat(point
, group
)) {
33 ERR_raise(ERR_LIB_EC
, EC_R_INCOMPATIBLE_OBJECTS
);
36 if (group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
) {
37 if (group
->meth
->field_type
== NID_X9_62_prime_field
)
38 return ec_GFp_simple_set_compressed_coordinates(group
, point
, x
,
41 #ifdef OPENSSL_NO_EC2M
43 ERR_raise(ERR_LIB_EC
, EC_R_GF2M_NOT_SUPPORTED
);
47 return ec_GF2m_simple_set_compressed_coordinates(group
, point
, x
,
51 return group
->meth
->point_set_compressed_coordinates(group
, point
, x
,
55 #ifndef OPENSSL_NO_DEPRECATED_3_0
56 int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP
*group
,
57 EC_POINT
*point
, const BIGNUM
*x
,
58 int y_bit
, BN_CTX
*ctx
)
60 return EC_POINT_set_compressed_coordinates(group
, point
, x
, y_bit
, ctx
);
63 # ifndef OPENSSL_NO_EC2M
64 int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP
*group
,
65 EC_POINT
*point
, const BIGNUM
*x
,
66 int y_bit
, BN_CTX
*ctx
)
68 return EC_POINT_set_compressed_coordinates(group
, point
, x
, y_bit
, ctx
);
73 size_t EC_POINT_point2oct(const EC_GROUP
*group
, const EC_POINT
*point
,
74 point_conversion_form_t form
, unsigned char *buf
,
75 size_t len
, BN_CTX
*ctx
)
77 if (group
->meth
->point2oct
== 0
78 && !(group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
)) {
79 ERR_raise(ERR_LIB_EC
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
82 if (!ec_point_is_compat(point
, group
)) {
83 ERR_raise(ERR_LIB_EC
, EC_R_INCOMPATIBLE_OBJECTS
);
86 if (group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
) {
87 if (group
->meth
->field_type
== NID_X9_62_prime_field
)
88 return ec_GFp_simple_point2oct(group
, point
, form
, buf
, len
, ctx
);
90 #ifdef OPENSSL_NO_EC2M
92 ERR_raise(ERR_LIB_EC
, EC_R_GF2M_NOT_SUPPORTED
);
96 return ec_GF2m_simple_point2oct(group
, point
,
101 return group
->meth
->point2oct(group
, point
, form
, buf
, len
, ctx
);
104 int EC_POINT_oct2point(const EC_GROUP
*group
, EC_POINT
*point
,
105 const unsigned char *buf
, size_t len
, BN_CTX
*ctx
)
107 if (group
->meth
->oct2point
== 0
108 && !(group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
)) {
109 ERR_raise(ERR_LIB_EC
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
112 if (!ec_point_is_compat(point
, group
)) {
113 ERR_raise(ERR_LIB_EC
, EC_R_INCOMPATIBLE_OBJECTS
);
116 if (group
->meth
->flags
& EC_FLAGS_DEFAULT_OCT
) {
117 if (group
->meth
->field_type
== NID_X9_62_prime_field
)
118 return ec_GFp_simple_oct2point(group
, point
, buf
, len
, ctx
);
120 #ifdef OPENSSL_NO_EC2M
122 ERR_raise(ERR_LIB_EC
, EC_R_GF2M_NOT_SUPPORTED
);
126 return ec_GF2m_simple_oct2point(group
, point
, buf
, len
, ctx
);
129 return group
->meth
->oct2point(group
, point
, buf
, len
, ctx
);
132 size_t EC_POINT_point2buf(const EC_GROUP
*group
, const EC_POINT
*point
,
133 point_conversion_form_t form
,
134 unsigned char **pbuf
, BN_CTX
*ctx
)
139 len
= EC_POINT_point2oct(group
, point
, form
, NULL
, 0, NULL
);
142 if ((buf
= OPENSSL_malloc(len
)) == NULL
) {
143 ERR_raise(ERR_LIB_EC
, ERR_R_MALLOC_FAILURE
);
146 len
= EC_POINT_point2oct(group
, point
, form
, buf
, len
, ctx
);