Coverage Report

Created: 2025-07-11 06:08

/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
1
void crypto_init() {
22
23
1
  const struct ltc_cipher_descriptor *regciphers[] = {
24
1
#if DROPBEAR_AES
25
1
    &aes_desc,
26
1
#endif
27
#if DROPBEAR_3DES
28
    &des3_desc,
29
#endif
30
1
    NULL
31
1
  };
32
33
1
  const struct ltc_hash_descriptor *reghashes[] = {
34
#if DROPBEAR_SHA1_HMAC
35
    &sha1_desc,
36
#endif
37
1
#if DROPBEAR_SHA256
38
1
    &sha256_desc,
39
1
#endif
40
1
#if DROPBEAR_SHA384
41
1
    &sha384_desc,
42
1
#endif
43
1
#if DROPBEAR_SHA512
44
1
    &sha512_desc,
45
1
#endif
46
1
    NULL
47
1
  };
48
1
  int i;
49
50
2
  for (i = 0; regciphers[i] != NULL; i++) {
51
1
    if (register_cipher(regciphers[i]) == -1) {
52
0
      dropbear_exit("Error registering crypto");
53
0
    }
54
1
  }
55
56
4
  for (i = 0; reghashes[i] != NULL; i++) {
57
3
    if (register_hash(reghashes[i]) == -1) {
58
0
      dropbear_exit("Error registering crypto");
59
0
    }
60
3
  }
61
62
1
#if DROPBEAR_LTC_PRNG
63
1
  dropbear_ltc_prng = register_prng(&dropbear_prng_desc);
64
1
  if (dropbear_ltc_prng == -1) {
65
0
    dropbear_exit("Error registering crypto");
66
0
  }
67
1
#endif
68
69
1
  mp_rand_source(dropbear_rand_source);
70
71
1
#if DROPBEAR_ECC
72
1
  ltc_mp = ltm_desc;
73
1
  dropbear_ecc_fill_dp();
74
1
#endif
75
1
}
76