Coverage Report

Created: 2026-03-11 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/u-boot/net/net_rand.h
Line
Count
Source
1
/* SPDX-License-Identifier: GPL-2.0-only */
2
/*
3
 *  Copied from LiMon - BOOTP.
4
 *
5
 *  Copyright 1994, 1995, 2000 Neil Russell.
6
 *  Copyright 2000 Paolo Scaffardi
7
 */
8
9
#ifndef __NET_RAND_H__
10
#define __NET_RAND_H__
11
12
#include <dm/uclass.h>
13
#include <rng.h>
14
15
/*
16
 * Return a seed for the PRNG derived from the eth0 MAC address.
17
 */
18
static inline unsigned int seed_mac(void)
19
0
{
20
0
  unsigned char enetaddr[ARP_HLEN];
21
0
  unsigned int seed;
22
23
  /* get our mac */
24
0
  memcpy(enetaddr, eth_get_ethaddr(), ARP_HLEN);
25
26
0
  seed = enetaddr[5];
27
0
  seed ^= enetaddr[4] << 8;
28
0
  seed ^= enetaddr[3] << 16;
29
0
  seed ^= enetaddr[2] << 24;
30
0
  seed ^= enetaddr[1];
31
0
  seed ^= enetaddr[0] << 8;
32
33
0
  return seed;
34
0
}
Unexecuted instantiation: link_local.c:seed_mac
Unexecuted instantiation: net.c:seed_mac
Unexecuted instantiation: dhcpv6.c:seed_mac
35
36
/*
37
 * Seed the random number generator using the eth0 MAC address.
38
 */
39
static inline void srand_mac(void)
40
0
{
41
0
  int ret;
42
0
  struct udevice *devp;
43
0
  u32 randv = 0;
44
45
0
  if (CONFIG_IS_ENABLED(DM_RNG)) {
46
0
    ret = uclass_get_device(UCLASS_RNG, 0, &devp);
47
0
    if (ret) {
48
0
      ret = dm_rng_read(devp, &randv, sizeof(randv));
49
0
      if (ret < 0)
50
0
        randv = 0;
51
0
    }
52
0
  }
53
0
  if (randv)
54
0
    srand(randv);
55
0
  else
56
0
    srand(seed_mac());
57
0
}
Unexecuted instantiation: link_local.c:srand_mac
Unexecuted instantiation: net.c:srand_mac
Unexecuted instantiation: dhcpv6.c:srand_mac
58
59
#endif /* __NET_RAND_H__ */