diff options
Diffstat (limited to 'src/lib/libcrypto/ec/ec_oct.c')
| -rw-r--r-- | src/lib/libcrypto/ec/ec_oct.c | 133 |
1 files changed, 62 insertions, 71 deletions
diff --git a/src/lib/libcrypto/ec/ec_oct.c b/src/lib/libcrypto/ec/ec_oct.c index fd9db0798d..e0fb62fee2 100644 --- a/src/lib/libcrypto/ec/ec_oct.c +++ b/src/lib/libcrypto/ec/ec_oct.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -57,7 +57,7 @@ | |||
| 57 | */ | 57 | */ |
| 58 | /* ==================================================================== | 58 | /* ==================================================================== |
| 59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
| 60 | * Binary polynomial ECC support in OpenSSL originally developed by | 60 | * Binary polynomial ECC support in OpenSSL originally developed by |
| 61 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | 61 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. |
| 62 | */ | 62 | */ |
| 63 | 63 | ||
| @@ -68,132 +68,123 @@ | |||
| 68 | 68 | ||
| 69 | #include "ec_lcl.h" | 69 | #include "ec_lcl.h" |
| 70 | 70 | ||
| 71 | int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point, | 71 | int |
| 72 | const BIGNUM *x, int y_bit, BN_CTX *ctx) | 72 | EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP * group, EC_POINT * point, |
| 73 | { | 73 | const BIGNUM * x, int y_bit, BN_CTX * ctx) |
| 74 | { | ||
| 74 | if (group->meth->point_set_compressed_coordinates == 0 | 75 | if (group->meth->point_set_compressed_coordinates == 0 |
| 75 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) | 76 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) { |
| 76 | { | ||
| 77 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 77 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
| 78 | return 0; | 78 | return 0; |
| 79 | } | 79 | } |
| 80 | if (group->meth != point->meth) | 80 | if (group->meth != point->meth) { |
| 81 | { | ||
| 82 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS); | 81 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS); |
| 83 | return 0; | 82 | return 0; |
| 84 | } | 83 | } |
| 85 | if(group->meth->flags & EC_FLAGS_DEFAULT_OCT) | 84 | if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) { |
| 86 | { | ||
| 87 | if (group->meth->field_type == NID_X9_62_prime_field) | 85 | if (group->meth->field_type == NID_X9_62_prime_field) |
| 88 | return ec_GFp_simple_set_compressed_coordinates( | 86 | return ec_GFp_simple_set_compressed_coordinates( |
| 89 | group, point, x, y_bit, ctx); | 87 | group, point, x, y_bit, ctx); |
| 90 | else | 88 | else |
| 91 | #ifdef OPENSSL_NO_EC2M | 89 | #ifdef OPENSSL_NO_EC2M |
| 92 | { | 90 | { |
| 93 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_GF2M_NOT_SUPPORTED); | 91 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_GF2M_NOT_SUPPORTED); |
| 94 | return 0; | 92 | return 0; |
| 95 | } | 93 | } |
| 96 | #else | 94 | #else |
| 97 | return ec_GF2m_simple_set_compressed_coordinates( | 95 | return ec_GF2m_simple_set_compressed_coordinates( |
| 98 | group, point, x, y_bit, ctx); | 96 | group, point, x, y_bit, ctx); |
| 99 | #endif | 97 | #endif |
| 100 | } | ||
| 101 | return group->meth->point_set_compressed_coordinates(group, point, x, y_bit, ctx); | ||
| 102 | } | 98 | } |
| 99 | return group->meth->point_set_compressed_coordinates(group, point, x, y_bit, ctx); | ||
| 100 | } | ||
| 103 | 101 | ||
| 104 | #ifndef OPENSSL_NO_EC2M | 102 | #ifndef OPENSSL_NO_EC2M |
| 105 | int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, EC_POINT *point, | 103 | int |
| 106 | const BIGNUM *x, int y_bit, BN_CTX *ctx) | 104 | EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP * group, EC_POINT * point, |
| 107 | { | 105 | const BIGNUM * x, int y_bit, BN_CTX * ctx) |
| 106 | { | ||
| 108 | if (group->meth->point_set_compressed_coordinates == 0 | 107 | if (group->meth->point_set_compressed_coordinates == 0 |
| 109 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) | 108 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) { |
| 110 | { | ||
| 111 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 109 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
| 112 | return 0; | 110 | return 0; |
| 113 | } | 111 | } |
| 114 | if (group->meth != point->meth) | 112 | if (group->meth != point->meth) { |
| 115 | { | ||
| 116 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS); | 113 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS); |
| 117 | return 0; | 114 | return 0; |
| 118 | } | 115 | } |
| 119 | if(group->meth->flags & EC_FLAGS_DEFAULT_OCT) | 116 | if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) { |
| 120 | { | ||
| 121 | if (group->meth->field_type == NID_X9_62_prime_field) | 117 | if (group->meth->field_type == NID_X9_62_prime_field) |
| 122 | return ec_GFp_simple_set_compressed_coordinates( | 118 | return ec_GFp_simple_set_compressed_coordinates( |
| 123 | group, point, x, y_bit, ctx); | 119 | group, point, x, y_bit, ctx); |
| 124 | else | 120 | else |
| 125 | return ec_GF2m_simple_set_compressed_coordinates( | 121 | return ec_GF2m_simple_set_compressed_coordinates( |
| 126 | group, point, x, y_bit, ctx); | 122 | group, point, x, y_bit, ctx); |
| 127 | } | ||
| 128 | return group->meth->point_set_compressed_coordinates(group, point, x, y_bit, ctx); | ||
| 129 | } | 123 | } |
| 124 | return group->meth->point_set_compressed_coordinates(group, point, x, y_bit, ctx); | ||
| 125 | } | ||
| 130 | #endif | 126 | #endif |
| 131 | 127 | ||
| 132 | size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, point_conversion_form_t form, | 128 | size_t |
| 133 | unsigned char *buf, size_t len, BN_CTX *ctx) | 129 | EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, |
| 134 | { | 130 | point_conversion_form_t form, |
| 131 | unsigned char *buf, size_t len, BN_CTX *ctx) | ||
| 132 | { | ||
| 135 | if (group->meth->point2oct == 0 | 133 | if (group->meth->point2oct == 0 |
| 136 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) | 134 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) { |
| 137 | { | ||
| 138 | ECerr(EC_F_EC_POINT_POINT2OCT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 135 | ECerr(EC_F_EC_POINT_POINT2OCT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
| 139 | return 0; | 136 | return 0; |
| 140 | } | 137 | } |
| 141 | if (group->meth != point->meth) | 138 | if (group->meth != point->meth) { |
| 142 | { | ||
| 143 | ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_INCOMPATIBLE_OBJECTS); | 139 | ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_INCOMPATIBLE_OBJECTS); |
| 144 | return 0; | 140 | return 0; |
| 145 | } | 141 | } |
| 146 | if(group->meth->flags & EC_FLAGS_DEFAULT_OCT) | 142 | if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) { |
| 147 | { | ||
| 148 | if (group->meth->field_type == NID_X9_62_prime_field) | 143 | if (group->meth->field_type == NID_X9_62_prime_field) |
| 149 | return ec_GFp_simple_point2oct(group, point, | 144 | return ec_GFp_simple_point2oct(group, point, |
| 150 | form, buf, len, ctx); | 145 | form, buf, len, ctx); |
| 151 | else | 146 | else |
| 152 | #ifdef OPENSSL_NO_EC2M | 147 | #ifdef OPENSSL_NO_EC2M |
| 153 | { | 148 | { |
| 154 | ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_GF2M_NOT_SUPPORTED); | 149 | ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_GF2M_NOT_SUPPORTED); |
| 155 | return 0; | 150 | return 0; |
| 156 | } | 151 | } |
| 157 | #else | 152 | #else |
| 158 | return ec_GF2m_simple_point2oct(group, point, | 153 | return ec_GF2m_simple_point2oct(group, point, |
| 159 | form, buf, len, ctx); | 154 | form, buf, len, ctx); |
| 160 | #endif | 155 | #endif |
| 161 | } | ||
| 162 | |||
| 163 | return group->meth->point2oct(group, point, form, buf, len, ctx); | ||
| 164 | } | 156 | } |
| 157 | return group->meth->point2oct(group, point, form, buf, len, ctx); | ||
| 158 | } | ||
| 165 | 159 | ||
| 166 | 160 | ||
| 167 | int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point, | 161 | int |
| 168 | const unsigned char *buf, size_t len, BN_CTX *ctx) | 162 | EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point, |
| 169 | { | 163 | const unsigned char *buf, size_t len, BN_CTX *ctx) |
| 170 | if (group->meth->oct2point == 0 | 164 | { |
| 171 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) | 165 | if (group->meth->oct2point == 0 && |
| 172 | { | 166 | !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) { |
| 173 | ECerr(EC_F_EC_POINT_OCT2POINT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 167 | ECerr(EC_F_EC_POINT_OCT2POINT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
| 174 | return 0; | 168 | return 0; |
| 175 | } | 169 | } |
| 176 | if (group->meth != point->meth) | 170 | if (group->meth != point->meth) { |
| 177 | { | ||
| 178 | ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_INCOMPATIBLE_OBJECTS); | 171 | ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_INCOMPATIBLE_OBJECTS); |
| 179 | return 0; | 172 | return 0; |
| 180 | } | 173 | } |
| 181 | if(group->meth->flags & EC_FLAGS_DEFAULT_OCT) | 174 | if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) { |
| 182 | { | ||
| 183 | if (group->meth->field_type == NID_X9_62_prime_field) | 175 | if (group->meth->field_type == NID_X9_62_prime_field) |
| 184 | return ec_GFp_simple_oct2point(group, point, | 176 | return ec_GFp_simple_oct2point(group, point, |
| 185 | buf, len, ctx); | 177 | buf, len, ctx); |
| 186 | else | 178 | else |
| 187 | #ifdef OPENSSL_NO_EC2M | 179 | #ifdef OPENSSL_NO_EC2M |
| 188 | { | 180 | { |
| 189 | ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_GF2M_NOT_SUPPORTED); | 181 | ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_GF2M_NOT_SUPPORTED); |
| 190 | return 0; | 182 | return 0; |
| 191 | } | 183 | } |
| 192 | #else | 184 | #else |
| 193 | return ec_GF2m_simple_oct2point(group, point, | 185 | return ec_GF2m_simple_oct2point(group, point, |
| 194 | buf, len, ctx); | 186 | buf, len, ctx); |
| 195 | #endif | 187 | #endif |
| 196 | } | ||
| 197 | return group->meth->oct2point(group, point, buf, len, ctx); | ||
| 198 | } | 188 | } |
| 199 | 189 | return group->meth->oct2point(group, point, buf, len, ctx); | |
| 190 | } | ||
