Coverage Report

Created: 2025-12-10 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/crypto/ec/ecdsa_ossl.c
Line
Count
Source
1
/*
2
 * Copyright 2002-2025 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
/*
11
 * ECDSA low level APIs are deprecated for public use, but still ok for
12
 * internal use.
13
 */
14
#include "internal/deprecated.h"
15
16
#include <string.h>
17
#include <openssl/err.h>
18
#include <openssl/obj_mac.h>
19
#include <openssl/rand.h>
20
#include "crypto/bn.h"
21
#include "ec_local.h"
22
#include "internal/deterministic_nonce.h"
23
24
0
#define MIN_ECDSA_SIGN_ORDERBITS 64
25
/*
26
 * It is highly unlikely that a retry will happen,
27
 * Multiple retries would indicate that something is wrong
28
 * with the group parameters (which would normally only happen
29
 * with a bad custom group).
30
 */
31
0
#define MAX_ECDSA_SIGN_RETRIES 8
32
33
static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in,
34
    BIGNUM **kinvp, BIGNUM **rp,
35
    const unsigned char *dgst, int dlen,
36
    unsigned int nonce_type, const char *digestname,
37
    OSSL_LIB_CTX *libctx, const char *propq);
38
39
int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
40
    BIGNUM **rp)
41
0
{
42
0
    if (eckey->group->meth->ecdsa_sign_setup == NULL) {
43
0
        ERR_raise(ERR_LIB_EC, EC_R_CURVE_DOES_NOT_SUPPORT_ECDSA);
44
0
        return 0;
45
0
    }
46
47
0
    return eckey->group->meth->ecdsa_sign_setup(eckey, ctx_in, kinvp, rp);
48
0
}
49
50
ECDSA_SIG *ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len,
51
    const BIGNUM *in_kinv, const BIGNUM *in_r,
52
    EC_KEY *eckey)
53
0
{
54
0
    if (eckey->group->meth->ecdsa_sign_sig == NULL) {
55
0
        ERR_raise(ERR_LIB_EC, EC_R_CURVE_DOES_NOT_SUPPORT_ECDSA);
56
0
        return NULL;
57
0
    }
58
59
0
    return eckey->group->meth->ecdsa_sign_sig(dgst, dgst_len,
60
0
        in_kinv, in_r, eckey);
61
0
}
62
63
int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,
64
    const ECDSA_SIG *sig, EC_KEY *eckey)
65
0
{
66
0
    if (eckey->group->meth->ecdsa_verify_sig == NULL) {
67
0
        ERR_raise(ERR_LIB_EC, EC_R_CURVE_DOES_NOT_SUPPORT_ECDSA);
68
0
        return 0;
69
0
    }
70
71
0
    return eckey->group->meth->ecdsa_verify_sig(dgst, dgst_len, sig, eckey);
72
0
}
73
74
int ossl_ecdsa_sign(int type, const unsigned char *dgst, int dlen,
75
    unsigned char *sig, unsigned int *siglen,
76
    const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey)
77
0
{
78
0
    ECDSA_SIG *s;
79
80
0
    if (sig == NULL && (kinv == NULL || r == NULL)) {
81
0
        *siglen = ECDSA_size(eckey);
82
0
        return 1;
83
0
    }
84
85
0
    s = ECDSA_do_sign_ex(dgst, dlen, kinv, r, eckey);
86
0
    if (s == NULL) {
87
0
        *siglen = 0;
88
0
        return 0;
89
0
    }
90
0
    *siglen = i2d_ECDSA_SIG(s, sig != NULL ? &sig : NULL);
91
0
    ECDSA_SIG_free(s);
92
0
    return 1;
93
0
}
94
95
int ossl_ecdsa_deterministic_sign(const unsigned char *dgst, int dlen,
96
    unsigned char *sig, unsigned int *siglen,
97
    EC_KEY *eckey, unsigned int nonce_type,
98
    const char *digestname,
99
    OSSL_LIB_CTX *libctx, const char *propq)
100
0
{
101
0
    ECDSA_SIG *s;
102
0
    BIGNUM *kinv = NULL, *r = NULL;
103
0
    int ret = 0;
104
105
0
    if (sig == NULL) {
106
0
        ERR_raise(ERR_LIB_EC, ERR_R_PASSED_NULL_PARAMETER);
107
0
        return 0;
108
0
    }
109
0
    if (digestname == NULL) {
110
0
        ERR_raise(ERR_LIB_EC, EC_R_INVALID_DIGEST);
111
0
        return 0;
112
0
    }
113
114
0
    *siglen = 0;
115
0
    if (!ecdsa_sign_setup(eckey, NULL, &kinv, &r, dgst, dlen,
116
0
            nonce_type, digestname, libctx, propq))
117
0
        return 0;
118
119
0
    s = ECDSA_do_sign_ex(dgst, dlen, kinv, r, eckey);
120
0
    if (s == NULL)
121
0
        goto end;
122
123
0
    *siglen = i2d_ECDSA_SIG(s, &sig);
124
0
    ECDSA_SIG_free(s);
125
0
    ret = 1;
126
0
end:
127
0
    BN_clear_free(kinv);
128
0
    BN_clear_free(r);
129
0
    return ret;
130
0
}
131
132
static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in,
133
    BIGNUM **kinvp, BIGNUM **rp,
134
    const unsigned char *dgst, int dlen,
135
    unsigned int nonce_type, const char *digestname,
136
    OSSL_LIB_CTX *libctx, const char *propq)
137
0
{
138
0
    BN_CTX *ctx = NULL;
139
0
    BIGNUM *k = NULL, *r = NULL, *X = NULL;
140
0
    const BIGNUM *order;
141
0
    EC_POINT *tmp_point = NULL;
142
0
    const EC_GROUP *group;
143
0
    int ret = 0;
144
0
    int order_bits;
145
0
    const BIGNUM *priv_key;
146
147
0
    if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL) {
148
0
        ERR_raise(ERR_LIB_EC, ERR_R_PASSED_NULL_PARAMETER);
149
0
        return 0;
150
0
    }
151
0
    if ((priv_key = EC_KEY_get0_private_key(eckey)) == NULL) {
152
0
        ERR_raise(ERR_LIB_EC, EC_R_MISSING_PRIVATE_KEY);
153
0
        return 0;
154
0
    }
155
156
0
    if (!EC_KEY_can_sign(eckey)) {
157
0
        ERR_raise(ERR_LIB_EC, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);
158
0
        return 0;
159
0
    }
160
161
0
    if ((ctx = ctx_in) == NULL) {
162
0
        if ((ctx = BN_CTX_new_ex(eckey->libctx)) == NULL) {
163
0
            ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
164
0
            return 0;
165
0
        }
166
0
    }
167
168
0
    k = BN_secure_new(); /* this value is later returned in *kinvp */
169
0
    r = BN_new(); /* this value is later returned in *rp */
170
0
    X = BN_new();
171
0
    if (k == NULL || r == NULL || X == NULL) {
172
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
173
0
        goto err;
174
0
    }
175
0
    if ((tmp_point = EC_POINT_new(group)) == NULL) {
176
0
        ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
177
0
        goto err;
178
0
    }
179
180
0
    if ((order = EC_GROUP_get0_order(group)) == NULL) {
181
0
        ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
182
0
        goto err;
183
0
    }
184
185
    /* Preallocate space */
186
0
    order_bits = BN_num_bits(order);
187
    /* Check the number of bits here so that an infinite loop is not possible */
188
0
    if (order_bits < MIN_ECDSA_SIGN_ORDERBITS
189
0
        || !BN_set_bit(k, order_bits)
190
0
        || !BN_set_bit(r, order_bits)
191
0
        || !BN_set_bit(X, order_bits))
192
0
        goto err;
193
194
0
    do {
195
        /* get random or deterministic value of k */
196
0
        do {
197
0
            int res = 0;
198
199
0
            if (dgst != NULL) {
200
0
                if (nonce_type == 1) {
201
0
                    res = ossl_gen_deterministic_nonce_rfc6979(k, order,
202
0
                        priv_key,
203
0
                        dgst, dlen,
204
0
                        digestname,
205
0
                        libctx, propq);
206
0
                } else {
207
0
                    res = ossl_bn_gen_dsa_nonce_fixed_top(k, order, priv_key,
208
0
                        dgst, dlen, ctx);
209
0
                }
210
0
            } else {
211
0
                res = ossl_bn_priv_rand_range_fixed_top(k, order, 0, ctx);
212
0
            }
213
0
            if (!res) {
214
0
                ERR_raise(ERR_LIB_EC, EC_R_RANDOM_NUMBER_GENERATION_FAILED);
215
0
                goto err;
216
0
            }
217
0
        } while (ossl_bn_is_word_fixed_top(k, 0));
218
219
        /* compute r the x-coordinate of generator * k */
220
0
        if (!EC_POINT_mul(group, tmp_point, k, NULL, NULL, ctx)) {
221
0
            ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
222
0
            goto err;
223
0
        }
224
225
0
        if (!EC_POINT_get_affine_coordinates(group, tmp_point, X, NULL, ctx)) {
226
0
            ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
227
0
            goto err;
228
0
        }
229
230
0
        if (!BN_nnmod(r, X, order, ctx)) {
231
0
            ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
232
0
            goto err;
233
0
        }
234
0
    } while (BN_is_zero(r));
235
236
    /* compute the inverse of k */
237
0
    if (!ossl_ec_group_do_inverse_ord(group, k, k, ctx)) {
238
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
239
0
        goto err;
240
0
    }
241
242
    /* clear old values if necessary */
243
0
    BN_clear_free(*rp);
244
0
    BN_clear_free(*kinvp);
245
    /* save the pre-computed values  */
246
0
    *rp = r;
247
0
    *kinvp = k;
248
0
    ret = 1;
249
0
err:
250
0
    if (!ret) {
251
0
        BN_clear_free(k);
252
0
        BN_clear_free(r);
253
0
    }
254
0
    if (ctx != ctx_in)
255
0
        BN_CTX_free(ctx);
256
0
    EC_POINT_free(tmp_point);
257
0
    BN_clear_free(X);
258
0
    return ret;
259
0
}
260
261
int ossl_ecdsa_simple_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
262
    BIGNUM **rp)
263
0
{
264
0
    return ecdsa_sign_setup(eckey, ctx_in, kinvp, rp, NULL, 0,
265
0
        0, NULL, NULL, NULL);
266
0
}
267
268
ECDSA_SIG *ossl_ecdsa_simple_sign_sig(const unsigned char *dgst, int dgst_len,
269
    const BIGNUM *in_kinv, const BIGNUM *in_r,
270
    EC_KEY *eckey)
271
0
{
272
0
    int ok = 0, i;
273
0
    int retries = 0;
274
0
    BIGNUM *kinv = NULL, *s, *m = NULL;
275
0
    const BIGNUM *order, *ckinv;
276
0
    BN_CTX *ctx = NULL;
277
0
    const EC_GROUP *group;
278
0
    ECDSA_SIG *ret;
279
0
    const BIGNUM *priv_key;
280
281
0
    group = EC_KEY_get0_group(eckey);
282
0
    priv_key = EC_KEY_get0_private_key(eckey);
283
284
0
    if (group == NULL) {
285
0
        ERR_raise(ERR_LIB_EC, ERR_R_PASSED_NULL_PARAMETER);
286
0
        return NULL;
287
0
    }
288
0
    if (priv_key == NULL) {
289
0
        ERR_raise(ERR_LIB_EC, EC_R_MISSING_PRIVATE_KEY);
290
0
        return NULL;
291
0
    }
292
293
0
    if (!EC_KEY_can_sign(eckey)) {
294
0
        ERR_raise(ERR_LIB_EC, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);
295
0
        return NULL;
296
0
    }
297
298
0
    ret = ECDSA_SIG_new();
299
0
    if (ret == NULL) {
300
0
        ERR_raise(ERR_LIB_EC, ERR_R_ECDSA_LIB);
301
0
        return NULL;
302
0
    }
303
0
    ret->r = BN_new();
304
0
    ret->s = BN_new();
305
0
    if (ret->r == NULL || ret->s == NULL) {
306
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
307
0
        goto err;
308
0
    }
309
0
    s = ret->s;
310
311
0
    if ((ctx = BN_CTX_new_ex(eckey->libctx)) == NULL
312
0
        || (m = BN_new()) == NULL) {
313
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
314
0
        goto err;
315
0
    }
316
317
0
    if ((order = EC_GROUP_get0_order(group)) == NULL) {
318
0
        ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
319
0
        goto err;
320
0
    }
321
322
0
    i = BN_num_bits(order);
323
    /*
324
     * Need to truncate digest if it is too long: first truncate whole bytes.
325
     */
326
0
    if (8 * dgst_len > i)
327
0
        dgst_len = (i + 7) / 8;
328
0
    if (!BN_bin2bn(dgst, dgst_len, m)) {
329
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
330
0
        goto err;
331
0
    }
332
    /* If still too long, truncate remaining bits with a shift */
333
0
    if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) {
334
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
335
0
        goto err;
336
0
    }
337
0
    do {
338
0
        if (in_kinv == NULL || in_r == NULL) {
339
0
            if (!ecdsa_sign_setup(eckey, ctx, &kinv, &ret->r, dgst, dgst_len,
340
0
                    0, NULL, NULL, NULL)) {
341
0
                ERR_raise(ERR_LIB_EC, ERR_R_ECDSA_LIB);
342
0
                goto err;
343
0
            }
344
0
            ckinv = kinv;
345
0
        } else {
346
0
            ckinv = in_kinv;
347
0
            if (BN_copy(ret->r, in_r) == NULL) {
348
0
                ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
349
0
                goto err;
350
0
            }
351
0
        }
352
353
        /*
354
         * With only one multiplicant being in Montgomery domain
355
         * multiplication yields real result without post-conversion.
356
         * Also note that all operations but last are performed with
357
         * zero-padded vectors. Last operation, BN_mod_mul_montgomery
358
         * below, returns user-visible value with removed zero padding.
359
         */
360
0
        if (!bn_to_mont_fixed_top(s, ret->r, group->mont_data, ctx)
361
0
            || !bn_mul_mont_fixed_top(s, s, priv_key, group->mont_data, ctx)) {
362
0
            ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
363
0
            goto err;
364
0
        }
365
0
        if (!bn_mod_add_fixed_top(s, s, m, order)) {
366
0
            ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
367
0
            goto err;
368
0
        }
369
        /*
370
         * |s| can still be larger than modulus, because |m| can be. In
371
         * such case we count on Montgomery reduction to tie it up.
372
         */
373
0
        if (!bn_to_mont_fixed_top(s, s, group->mont_data, ctx)
374
0
            || !BN_mod_mul_montgomery(s, s, ckinv, group->mont_data, ctx)) {
375
0
            ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
376
0
            goto err;
377
0
        }
378
379
0
        if (BN_is_zero(s)) {
380
            /*
381
             * if kinv and r have been supplied by the caller, don't
382
             * generate new kinv and r values
383
             */
384
0
            if (in_kinv != NULL && in_r != NULL) {
385
0
                ERR_raise(ERR_LIB_EC, EC_R_NEED_NEW_SETUP_VALUES);
386
0
                goto err;
387
0
            }
388
            /* Avoid infinite loops cause by invalid group parameters */
389
0
            if (retries++ > MAX_ECDSA_SIGN_RETRIES) {
390
0
                ERR_raise(ERR_LIB_EC, EC_R_TOO_MANY_RETRIES);
391
0
                goto err;
392
0
            }
393
0
        } else {
394
            /* s != 0 => we have a valid signature */
395
0
            break;
396
0
        }
397
0
    } while (1);
398
399
0
    ok = 1;
400
0
err:
401
0
    if (!ok) {
402
0
        ECDSA_SIG_free(ret);
403
0
        ret = NULL;
404
0
    }
405
0
    BN_CTX_free(ctx);
406
0
    BN_clear_free(m);
407
0
    BN_clear_free(kinv);
408
0
    return ret;
409
0
}
410
411
/*-
412
 * returns
413
 *      1: correct signature
414
 *      0: incorrect signature
415
 *     -1: error
416
 */
417
int ossl_ecdsa_verify(int type, const unsigned char *dgst, int dgst_len,
418
    const unsigned char *sigbuf, int sig_len, EC_KEY *eckey)
419
0
{
420
0
    ECDSA_SIG *s;
421
0
    const unsigned char *p = sigbuf;
422
0
    unsigned char *der = NULL;
423
0
    int derlen = -1;
424
0
    int ret = -1;
425
426
0
    s = ECDSA_SIG_new();
427
0
    if (s == NULL)
428
0
        return ret;
429
0
    if (d2i_ECDSA_SIG(&s, &p, sig_len) == NULL)
430
0
        goto err;
431
    /* Ensure signature uses DER and doesn't have trailing garbage */
432
0
    derlen = i2d_ECDSA_SIG(s, &der);
433
0
    if (derlen != sig_len || memcmp(sigbuf, der, derlen) != 0)
434
0
        goto err;
435
0
    ret = ECDSA_do_verify(dgst, dgst_len, s, eckey);
436
0
err:
437
0
    OPENSSL_free(der);
438
0
    ECDSA_SIG_free(s);
439
0
    return ret;
440
0
}
441
442
int ossl_ecdsa_simple_verify_sig(const unsigned char *dgst, int dgst_len,
443
    const ECDSA_SIG *sig, EC_KEY *eckey)
444
0
{
445
0
    int ret = -1, i;
446
0
    BN_CTX *ctx;
447
0
    const BIGNUM *order;
448
0
    BIGNUM *u1, *u2, *m, *X;
449
0
    EC_POINT *point = NULL;
450
0
    const EC_GROUP *group;
451
0
    const EC_POINT *pub_key;
452
453
    /* check input values */
454
0
    if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL || (pub_key = EC_KEY_get0_public_key(eckey)) == NULL || sig == NULL) {
455
0
        ERR_raise(ERR_LIB_EC, EC_R_MISSING_PARAMETERS);
456
0
        return -1;
457
0
    }
458
459
0
    if (!EC_KEY_can_sign(eckey)) {
460
0
        ERR_raise(ERR_LIB_EC, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);
461
0
        return -1;
462
0
    }
463
464
0
    ctx = BN_CTX_new_ex(eckey->libctx);
465
0
    if (ctx == NULL) {
466
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
467
0
        return -1;
468
0
    }
469
0
    BN_CTX_start(ctx);
470
0
    u1 = BN_CTX_get(ctx);
471
0
    u2 = BN_CTX_get(ctx);
472
0
    m = BN_CTX_get(ctx);
473
0
    X = BN_CTX_get(ctx);
474
0
    if (X == NULL) {
475
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
476
0
        goto err;
477
0
    }
478
479
0
    order = EC_GROUP_get0_order(group);
480
0
    if (order == NULL) {
481
0
        ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
482
0
        goto err;
483
0
    }
484
485
0
    if (BN_is_zero(sig->r) || BN_is_negative(sig->r) || BN_ucmp(sig->r, order) >= 0 || BN_is_zero(sig->s) || BN_is_negative(sig->s) || BN_ucmp(sig->s, order) >= 0) {
486
0
        ERR_raise(ERR_LIB_EC, EC_R_BAD_SIGNATURE);
487
0
        ret = 0; /* signature is invalid */
488
0
        goto err;
489
0
    }
490
    /* calculate tmp1 = inv(S) mod order */
491
0
    if (!ossl_ec_group_do_inverse_ord(group, u2, sig->s, ctx)) {
492
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
493
0
        goto err;
494
0
    }
495
    /* digest -> m */
496
0
    i = BN_num_bits(order);
497
    /*
498
     * Need to truncate digest if it is too long: first truncate whole bytes.
499
     */
500
0
    if (8 * dgst_len > i)
501
0
        dgst_len = (i + 7) / 8;
502
0
    if (!BN_bin2bn(dgst, dgst_len, m)) {
503
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
504
0
        goto err;
505
0
    }
506
    /* If still too long truncate remaining bits with a shift */
507
0
    if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) {
508
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
509
0
        goto err;
510
0
    }
511
    /* u1 = m * tmp mod order */
512
0
    if (!BN_mod_mul(u1, m, u2, order, ctx)) {
513
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
514
0
        goto err;
515
0
    }
516
    /* u2 = r * w mod q */
517
0
    if (!BN_mod_mul(u2, sig->r, u2, order, ctx)) {
518
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
519
0
        goto err;
520
0
    }
521
522
0
    if ((point = EC_POINT_new(group)) == NULL) {
523
0
        ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
524
0
        goto err;
525
0
    }
526
0
    if (!EC_POINT_mul(group, point, u1, pub_key, u2, ctx)) {
527
0
        ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
528
0
        goto err;
529
0
    }
530
531
0
    if (!EC_POINT_get_affine_coordinates(group, point, X, NULL, ctx)) {
532
0
        ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
533
0
        goto err;
534
0
    }
535
536
0
    if (!BN_nnmod(u1, X, order, ctx)) {
537
0
        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
538
0
        goto err;
539
0
    }
540
    /*  if the signature is correct u1 is equal to sig->r */
541
0
    ret = (BN_ucmp(u1, sig->r) == 0);
542
0
err:
543
0
    BN_CTX_end(ctx);
544
0
    BN_CTX_free(ctx);
545
0
    EC_POINT_free(point);
546
0
    return ret;
547
0
}