Coverage Report

Created: 2025-04-22 06:18

/src/openssl/crypto/asn1/d2i_param.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2019-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
#include <stdio.h>
11
#include "internal/cryptlib.h"
12
#include <openssl/evp.h>
13
#include <openssl/asn1.h>
14
#include "internal/asn1.h"
15
#include "crypto/asn1.h"
16
#include "crypto/evp.h"
17
18
EVP_PKEY *d2i_KeyParams(int type, EVP_PKEY **a, const unsigned char **pp,
19
                        long length)
20
0
{
21
0
    EVP_PKEY *ret = NULL;
22
23
0
    if ((a == NULL) || (*a == NULL)) {
24
0
        if ((ret = EVP_PKEY_new()) == NULL)
25
0
            return NULL;
26
0
    } else
27
0
        ret = *a;
28
29
0
    if (type != EVP_PKEY_get_id(ret) && !EVP_PKEY_set_type(ret, type))
30
0
        goto err;
31
32
0
    if (ret->ameth == NULL || ret->ameth->param_decode == NULL) {
33
0
        ERR_raise(ERR_LIB_ASN1, ASN1_R_UNSUPPORTED_TYPE);
34
0
        goto err;
35
0
    }
36
37
0
    if (!ret->ameth->param_decode(ret, pp, length))
38
0
        goto err;
39
40
0
    if (a != NULL)
41
0
        (*a) = ret;
42
0
    return ret;
43
0
err:
44
0
    if (a == NULL || *a != ret)
45
0
        EVP_PKEY_free(ret);
46
0
    return NULL;
47
0
}
48
49
EVP_PKEY *d2i_KeyParams_bio(int type, EVP_PKEY **a, BIO *in)
50
0
{
51
0
    BUF_MEM *b = NULL;
52
0
    const unsigned char *p;
53
0
    void *ret = NULL;
54
0
    int len;
55
56
0
    len = asn1_d2i_read_bio(in, &b);
57
0
    if (len < 0)
58
0
        goto err;
59
60
0
    p = (unsigned char *)b->data;
61
0
    ret = d2i_KeyParams(type, a, &p, len);
62
0
err:
63
0
    BUF_MEM_free(b);
64
0
    return ret;
65
0
}