Coverage Report

Created: 2025-04-22 06:18

/src/openssl/crypto/ec/ec_deprecated.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2002-2021 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
 * Suppress deprecation warnings for EC low level implementations that are
12
 * kept until removal.
13
 */
14
#define OPENSSL_SUPPRESS_DEPRECATED
15
16
#include <openssl/crypto.h>
17
#include <openssl/err.h>
18
#include <openssl/ec.h>
19
20
#ifndef OPENSSL_NO_DEPRECATED_3_0
21
BIGNUM *EC_POINT_point2bn(const EC_GROUP *group,
22
                          const EC_POINT *point,
23
                          point_conversion_form_t form,
24
                          BIGNUM *ret, BN_CTX *ctx)
25
0
{
26
0
    size_t buf_len = 0;
27
0
    unsigned char *buf;
28
29
0
    buf_len = EC_POINT_point2buf(group, point, form, &buf, ctx);
30
31
0
    if (buf_len == 0)
32
0
        return NULL;
33
34
0
    ret = BN_bin2bn(buf, buf_len, ret);
35
36
0
    OPENSSL_free(buf);
37
38
0
    return ret;
39
0
}
40
41
EC_POINT *EC_POINT_bn2point(const EC_GROUP *group,
42
                            const BIGNUM *bn, EC_POINT *point, BN_CTX *ctx)
43
0
{
44
0
    size_t buf_len = 0;
45
0
    unsigned char *buf;
46
0
    EC_POINT *ret;
47
48
0
    if ((buf_len = BN_num_bytes(bn)) == 0)
49
0
        buf_len = 1;
50
0
    if ((buf = OPENSSL_malloc(buf_len)) == NULL) {
51
0
        ECerr(EC_F_EC_POINT_BN2POINT, ERR_R_MALLOC_FAILURE);
52
0
        return NULL;
53
0
    }
54
55
0
    if (BN_bn2binpad(bn, buf, buf_len) < 0) {
56
0
        OPENSSL_free(buf);
57
0
        return NULL;
58
0
    }
59
60
0
    if (point == NULL) {
61
0
        if ((ret = EC_POINT_new(group)) == NULL) {
62
0
            OPENSSL_free(buf);
63
0
            return NULL;
64
0
        }
65
0
    } else
66
0
        ret = point;
67
68
0
    if (!EC_POINT_oct2point(group, ret, buf, buf_len, ctx)) {
69
0
        if (ret != point)
70
0
            EC_POINT_clear_free(ret);
71
0
        OPENSSL_free(buf);
72
0
        return NULL;
73
0
    }
74
75
0
    OPENSSL_free(buf);
76
0
    return ret;
77
0
}
78
#endif /* OPENSSL_NO_DEPRECATED_3_0 */