]>
Commit | Line | Data |
---|---|---|
84b08eee | 1 | /* |
28428130 | 2 | * Copyright 2011-2018 The OpenSSL Project Authors. All Rights Reserved. |
aa8f3d76 | 3 | * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved |
84b08eee | 4 | * |
a7f182b7 | 5 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
4f22f405 RS |
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 | |
84b08eee | 9 | */ |
4f22f405 | 10 | |
579422c8 P |
11 | /* |
12 | * ECDSA low level APIs are deprecated for public use, but still ok for | |
13 | * internal use. | |
14 | */ | |
15 | #include "internal/deprecated.h" | |
16 | ||
84b08eee DSH |
17 | #include <string.h> |
18 | ||
19 | #include <openssl/err.h> | |
20 | #include <openssl/opensslv.h> | |
21 | ||
706457b7 | 22 | #include "ec_local.h" |
84b08eee | 23 | |
8e3cced7 MC |
24 | int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point, |
25 | const BIGNUM *x, int y_bit, BN_CTX *ctx) | |
0f113f3e | 26 | { |
8e3cced7 | 27 | if (group->meth->point_set_compressed_coordinates == NULL |
0f113f3e | 28 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) { |
8e3cced7 | 29 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES, |
0f113f3e MC |
30 | ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
31 | return 0; | |
32 | } | |
b14e6015 | 33 | if (!ec_point_is_compat(point, group)) { |
8e3cced7 | 34 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES, |
0f113f3e MC |
35 | EC_R_INCOMPATIBLE_OBJECTS); |
36 | return 0; | |
37 | } | |
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, | |
41 | y_bit, ctx); | |
42 | else | |
1acc24a8 | 43 | #ifdef OPENSSL_NO_EC2M |
0f113f3e | 44 | { |
8e3cced7 | 45 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES, |
0f113f3e MC |
46 | EC_R_GF2M_NOT_SUPPORTED); |
47 | return 0; | |
48 | } | |
1acc24a8 | 49 | #else |
0f113f3e MC |
50 | return ec_GF2m_simple_set_compressed_coordinates(group, point, x, |
51 | y_bit, ctx); | |
1acc24a8 | 52 | #endif |
0f113f3e MC |
53 | } |
54 | return group->meth->point_set_compressed_coordinates(group, point, x, | |
55 | y_bit, ctx); | |
56 | } | |
84b08eee | 57 | |
936c2b9e | 58 | #ifndef OPENSSL_NO_DEPRECATED_3_0 |
8e3cced7 MC |
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) | |
62 | { | |
63 | return EC_POINT_set_compressed_coordinates(group, point, x, y_bit, ctx); | |
64 | } | |
65 | ||
50db8163 | 66 | # ifndef OPENSSL_NO_EC2M |
0f113f3e MC |
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) | |
70 | { | |
8e3cced7 | 71 | return EC_POINT_set_compressed_coordinates(group, point, x, y_bit, ctx); |
0f113f3e | 72 | } |
50db8163 | 73 | # endif |
84b08eee DSH |
74 | #endif |
75 | ||
0f113f3e MC |
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) | |
79 | { | |
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); | |
83 | return 0; | |
84 | } | |
b14e6015 | 85 | if (!ec_point_is_compat(point, group)) { |
0f113f3e MC |
86 | ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_INCOMPATIBLE_OBJECTS); |
87 | return 0; | |
88 | } | |
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); | |
92 | else | |
1acc24a8 | 93 | #ifdef OPENSSL_NO_EC2M |
0f113f3e MC |
94 | { |
95 | ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_GF2M_NOT_SUPPORTED); | |
96 | return 0; | |
97 | } | |
1acc24a8 | 98 | #else |
0f113f3e MC |
99 | return ec_GF2m_simple_point2oct(group, point, |
100 | form, buf, len, ctx); | |
1acc24a8 | 101 | #endif |
0f113f3e | 102 | } |
84b08eee | 103 | |
0f113f3e MC |
104 | return group->meth->point2oct(group, point, form, buf, len, ctx); |
105 | } | |
84b08eee DSH |
106 | |
107 | int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point, | |
0f113f3e MC |
108 | const unsigned char *buf, size_t len, BN_CTX *ctx) |
109 | { | |
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); | |
113 | return 0; | |
114 | } | |
b14e6015 | 115 | if (!ec_point_is_compat(point, group)) { |
0f113f3e MC |
116 | ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_INCOMPATIBLE_OBJECTS); |
117 | return 0; | |
118 | } | |
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); | |
122 | else | |
1acc24a8 | 123 | #ifdef OPENSSL_NO_EC2M |
0f113f3e MC |
124 | { |
125 | ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_GF2M_NOT_SUPPORTED); | |
126 | return 0; | |
127 | } | |
1acc24a8 | 128 | #else |
0f113f3e | 129 | return ec_GF2m_simple_oct2point(group, point, buf, len, ctx); |
1acc24a8 | 130 | #endif |
0f113f3e MC |
131 | } |
132 | return group->meth->oct2point(group, point, buf, len, ctx); | |
133 | } | |
981bd8a2 DSH |
134 | |
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) | |
138 | { | |
139 | size_t len; | |
140 | unsigned char *buf; | |
cdb10bae | 141 | |
981bd8a2 DSH |
142 | len = EC_POINT_point2oct(group, point, form, NULL, 0, NULL); |
143 | if (len == 0) | |
144 | return 0; | |
cdb10bae RS |
145 | if ((buf = OPENSSL_malloc(len)) == NULL) { |
146 | ECerr(EC_F_EC_POINT_POINT2BUF, ERR_R_MALLOC_FAILURE); | |
981bd8a2 | 147 | return 0; |
cdb10bae | 148 | } |
981bd8a2 DSH |
149 | len = EC_POINT_point2oct(group, point, form, buf, len, ctx); |
150 | if (len == 0) { | |
151 | OPENSSL_free(buf); | |
152 | return 0; | |
153 | } | |
154 | *pbuf = buf; | |
155 | return len; | |
156 | } |