Coverage Report

Created: 2025-04-22 06:18

/src/openssl/crypto/rsa/rsa_depr.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2002-2020 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
 * NB: This file contains deprecated functions (compatibility wrappers to the
12
 * "new" versions).
13
 */
14
15
/*
16
 * RSA low level APIs are deprecated for public use, but still ok for
17
 * internal use.
18
 */
19
#include "internal/deprecated.h"
20
21
#include <openssl/opensslconf.h>
22
23
#include <stdio.h>
24
#include <time.h>
25
#include "internal/cryptlib.h"
26
#include <openssl/bn.h>
27
#include <openssl/rsa.h>
28
29
RSA *RSA_generate_key(int bits, unsigned long e_value,
30
                      void (*callback) (int, int, void *), void *cb_arg)
31
0
{
32
0
    int i;
33
0
    BN_GENCB *cb = BN_GENCB_new();
34
0
    RSA *rsa = RSA_new();
35
0
    BIGNUM *e = BN_new();
36
37
0
    if (cb == NULL || rsa == NULL || e == NULL)
38
0
        goto err;
39
40
    /*
41
     * The problem is when building with 8, 16, or 32 BN_ULONG, unsigned long
42
     * can be larger
43
     */
44
0
    for (i = 0; i < (int)sizeof(unsigned long) * 8; i++) {
45
0
        if (e_value & (1UL << i))
46
0
            if (BN_set_bit(e, i) == 0)
47
0
                goto err;
48
0
    }
49
50
0
    BN_GENCB_set_old(cb, callback, cb_arg);
51
52
0
    if (RSA_generate_key_ex(rsa, bits, e, cb)) {
53
0
        BN_free(e);
54
0
        BN_GENCB_free(cb);
55
0
        return rsa;
56
0
    }
57
0
 err:
58
0
    BN_free(e);
59
0
    RSA_free(rsa);
60
0
    BN_GENCB_free(cb);
61
0
    return 0;
62
0
}