Coverage Report

Created: 2025-07-18 06:52

/src/dropbear/src/crypto_desc.c
Line
Count
Source (jump to first uncovered line)
1
#include "includes.h"
2
#include "dbutil.h"
3
#include "crypto_desc.h"
4
#include "ltc_prng.h"
5
#include "ecc.h"
6
#include "dbrandom.h"
7
8
#if DROPBEAR_LTC_PRNG
9
  int dropbear_ltc_prng = -1;
10
#endif
11
12
/* Wrapper for libtommath */
13
0
static mp_err dropbear_rand_source(void* out, size_t size) {
14
0
  genrandom((unsigned char*)out, (unsigned int)size);
15
0
  return MP_OKAY;
16
0
}
17
18
19
/* Register the compiled in ciphers.
20
 * This should be run before using any of the ciphers/hashes */
21
4
void crypto_init() {
22
23
4
  const struct ltc_cipher_descriptor *regciphers[] = {
24
4
#if DROPBEAR_AES
25
4
    &aes_desc,
26
4
#endif
27
#if DROPBEAR_3DES
28
    &des3_desc,
29
#endif
30
4
    NULL
31
4
  };
32
33
4
  const struct ltc_hash_descriptor *reghashes[] = {
34
#if DROPBEAR_SHA1_HMAC
35
    &sha1_desc,
36
#endif
37
4
#if DROPBEAR_SHA256
38
4
    &sha256_desc,
39
4
#endif
40
4
#if DROPBEAR_SHA384
41
4
    &sha384_desc,
42
4
#endif
43
4
#if DROPBEAR_SHA512
44
4
    &sha512_desc,
45
4
#endif
46
4
    NULL
47
4
  };
48
4
  int i;
49
50
8
  for (i = 0; regciphers[i] != NULL; i++) {
51
4
    if (register_cipher(regciphers[i]) == -1) {
52
0
      dropbear_exit("Error registering crypto");
53
0
    }
54
4
  }
55
56
16
  for (i = 0; reghashes[i] != NULL; i++) {
57
12
    if (register_hash(reghashes[i]) == -1) {
58
0
      dropbear_exit("Error registering crypto");
59
0
    }
60
12
  }
61
62
4
#if DROPBEAR_LTC_PRNG
63
4
  dropbear_ltc_prng = register_prng(&dropbear_prng_desc);
64
4
  if (dropbear_ltc_prng == -1) {
65
0
    dropbear_exit("Error registering crypto");
66
0
  }
67
4
#endif
68
69
4
  mp_rand_source(dropbear_rand_source);
70
71
4
#if DROPBEAR_ECC
72
4
  ltc_mp = ltm_desc;
73
4
  dropbear_ecc_fill_dp();
74
4
#endif
75
4
}
76