diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/ec/ec_print.c | 119 |
1 files changed, 51 insertions, 68 deletions
diff --git a/src/lib/libcrypto/ec/ec_print.c b/src/lib/libcrypto/ec/ec_print.c index 1655332c3c..84a78903b3 100644 --- a/src/lib/libcrypto/ec/ec_print.c +++ b/src/lib/libcrypto/ec/ec_print.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -56,29 +56,25 @@ | |||
56 | #include <openssl/crypto.h> | 56 | #include <openssl/crypto.h> |
57 | #include "ec_lcl.h" | 57 | #include "ec_lcl.h" |
58 | 58 | ||
59 | BIGNUM *EC_POINT_point2bn(const EC_GROUP *group, | 59 | BIGNUM * |
60 | const EC_POINT *point, | 60 | EC_POINT_point2bn(const EC_GROUP * group, const EC_POINT * point, |
61 | point_conversion_form_t form, | 61 | point_conversion_form_t form, BIGNUM * ret, BN_CTX * ctx) |
62 | BIGNUM *ret, | 62 | { |
63 | BN_CTX *ctx) | 63 | size_t buf_len = 0; |
64 | { | ||
65 | size_t buf_len=0; | ||
66 | unsigned char *buf; | 64 | unsigned char *buf; |
67 | 65 | ||
68 | buf_len = EC_POINT_point2oct(group, point, form, | 66 | buf_len = EC_POINT_point2oct(group, point, form, |
69 | NULL, 0, ctx); | 67 | NULL, 0, ctx); |
70 | if (buf_len == 0) | 68 | if (buf_len == 0) |
71 | return NULL; | 69 | return NULL; |
72 | 70 | ||
73 | if ((buf = malloc(buf_len)) == NULL) | 71 | if ((buf = malloc(buf_len)) == NULL) |
74 | return NULL; | 72 | return NULL; |
75 | 73 | ||
76 | if (!EC_POINT_point2oct(group, point, form, buf, buf_len, ctx)) | 74 | if (!EC_POINT_point2oct(group, point, form, buf, buf_len, ctx)) { |
77 | { | ||
78 | free(buf); | 75 | free(buf); |
79 | return NULL; | 76 | return NULL; |
80 | } | 77 | } |
81 | |||
82 | ret = BN_bin2bn(buf, buf_len, ret); | 78 | ret = BN_bin2bn(buf, buf_len, ret); |
83 | 79 | ||
84 | free(buf); | 80 | free(buf); |
@@ -86,103 +82,90 @@ BIGNUM *EC_POINT_point2bn(const EC_GROUP *group, | |||
86 | return ret; | 82 | return ret; |
87 | } | 83 | } |
88 | 84 | ||
89 | EC_POINT *EC_POINT_bn2point(const EC_GROUP *group, | 85 | EC_POINT * |
90 | const BIGNUM *bn, | 86 | EC_POINT_bn2point(const EC_GROUP * group, |
91 | EC_POINT *point, | 87 | const BIGNUM * bn, EC_POINT * point, BN_CTX * ctx) |
92 | BN_CTX *ctx) | 88 | { |
93 | { | 89 | size_t buf_len = 0; |
94 | size_t buf_len=0; | ||
95 | unsigned char *buf; | 90 | unsigned char *buf; |
96 | EC_POINT *ret; | 91 | EC_POINT *ret; |
97 | 92 | ||
98 | if ((buf_len = BN_num_bytes(bn)) == 0) return NULL; | 93 | if ((buf_len = BN_num_bytes(bn)) == 0) |
94 | return NULL; | ||
99 | buf = malloc(buf_len); | 95 | buf = malloc(buf_len); |
100 | if (buf == NULL) | 96 | if (buf == NULL) |
101 | return NULL; | 97 | return NULL; |
102 | 98 | ||
103 | if (!BN_bn2bin(bn, buf)) | 99 | if (!BN_bn2bin(bn, buf)) { |
104 | { | ||
105 | free(buf); | 100 | free(buf); |
106 | return NULL; | 101 | return NULL; |
107 | } | 102 | } |
108 | 103 | if (point == NULL) { | |
109 | if (point == NULL) | 104 | if ((ret = EC_POINT_new(group)) == NULL) { |
110 | { | ||
111 | if ((ret = EC_POINT_new(group)) == NULL) | ||
112 | { | ||
113 | free(buf); | 105 | free(buf); |
114 | return NULL; | 106 | return NULL; |
115 | } | ||
116 | } | 107 | } |
117 | else | 108 | } else |
118 | ret = point; | 109 | ret = point; |
119 | 110 | ||
120 | if (!EC_POINT_oct2point(group, ret, buf, buf_len, ctx)) | 111 | if (!EC_POINT_oct2point(group, ret, buf, buf_len, ctx)) { |
121 | { | ||
122 | if (point == NULL) | 112 | if (point == NULL) |
123 | EC_POINT_clear_free(ret); | 113 | EC_POINT_clear_free(ret); |
124 | free(buf); | 114 | free(buf); |
125 | return NULL; | 115 | return NULL; |
126 | } | 116 | } |
127 | |||
128 | free(buf); | 117 | free(buf); |
129 | return ret; | 118 | return ret; |
130 | } | 119 | } |
131 | 120 | ||
132 | static const char *HEX_DIGITS = "0123456789ABCDEF"; | 121 | static const char *HEX_DIGITS = "0123456789ABCDEF"; |
133 | 122 | ||
134 | /* the return value must be freed (using free()) */ | 123 | /* the return value must be freed (using free()) */ |
135 | char *EC_POINT_point2hex(const EC_GROUP *group, | 124 | char * |
136 | const EC_POINT *point, | 125 | EC_POINT_point2hex(const EC_GROUP * group, const EC_POINT * point, |
137 | point_conversion_form_t form, | 126 | point_conversion_form_t form, BN_CTX * ctx) |
138 | BN_CTX *ctx) | 127 | { |
139 | { | 128 | char *ret, *p; |
140 | char *ret, *p; | 129 | size_t buf_len = 0, i; |
141 | size_t buf_len=0,i; | ||
142 | unsigned char *buf, *pbuf; | 130 | unsigned char *buf, *pbuf; |
143 | 131 | ||
144 | buf_len = EC_POINT_point2oct(group, point, form, | 132 | buf_len = EC_POINT_point2oct(group, point, form, |
145 | NULL, 0, ctx); | 133 | NULL, 0, ctx); |
146 | if (buf_len == 0) | 134 | if (buf_len == 0) |
147 | return NULL; | 135 | return NULL; |
148 | 136 | ||
149 | if ((buf = malloc(buf_len)) == NULL) | 137 | if ((buf = malloc(buf_len)) == NULL) |
150 | return NULL; | 138 | return NULL; |
151 | 139 | ||
152 | if (!EC_POINT_point2oct(group, point, form, buf, buf_len, ctx)) | 140 | if (!EC_POINT_point2oct(group, point, form, buf, buf_len, ctx)) { |
153 | { | ||
154 | free(buf); | 141 | free(buf); |
155 | return NULL; | 142 | return NULL; |
156 | } | 143 | } |
157 | 144 | ret = (char *) malloc(buf_len * 2 + 2); | |
158 | ret = (char *)malloc(buf_len*2+2); | 145 | if (ret == NULL) { |
159 | if (ret == NULL) | ||
160 | { | ||
161 | free(buf); | 146 | free(buf); |
162 | return NULL; | 147 | return NULL; |
163 | } | 148 | } |
164 | p = ret; | 149 | p = ret; |
165 | pbuf = buf; | 150 | pbuf = buf; |
166 | for (i=buf_len; i > 0; i--) | 151 | for (i = buf_len; i > 0; i--) { |
167 | { | 152 | int v = (int) *(pbuf++); |
168 | int v = (int) *(pbuf++); | 153 | *(p++) = HEX_DIGITS[v >> 4]; |
169 | *(p++)=HEX_DIGITS[v>>4]; | 154 | *(p++) = HEX_DIGITS[v & 0x0F]; |
170 | *(p++)=HEX_DIGITS[v&0x0F]; | 155 | } |
171 | } | 156 | *p = '\0'; |
172 | *p='\0'; | ||
173 | 157 | ||
174 | free(buf); | 158 | free(buf); |
175 | 159 | ||
176 | return ret; | 160 | return ret; |
177 | } | 161 | } |
178 | 162 | ||
179 | EC_POINT *EC_POINT_hex2point(const EC_GROUP *group, | 163 | EC_POINT * |
180 | const char *buf, | 164 | EC_POINT_hex2point(const EC_GROUP * group, const char *buf, |
181 | EC_POINT *point, | 165 | EC_POINT * point, BN_CTX * ctx) |
182 | BN_CTX *ctx) | 166 | { |
183 | { | 167 | EC_POINT *ret = NULL; |
184 | EC_POINT *ret=NULL; | 168 | BIGNUM *tmp_bn = NULL; |
185 | BIGNUM *tmp_bn=NULL; | ||
186 | 169 | ||
187 | if (!BN_hex2bn(&tmp_bn, buf)) | 170 | if (!BN_hex2bn(&tmp_bn, buf)) |
188 | return NULL; | 171 | return NULL; |
@@ -192,4 +175,4 @@ EC_POINT *EC_POINT_hex2point(const EC_GROUP *group, | |||
192 | BN_clear_free(tmp_bn); | 175 | BN_clear_free(tmp_bn); |
193 | 176 | ||
194 | return ret; | 177 | return ret; |
195 | } | 178 | } |