aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/entropy/beos_stats/es_beos.cpp
blob: fb9be6f86b8c02bdcf9aeb8039faf830d985c165 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* BeOS EntropySource
* (C) 1999-2008 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#include <botan/internal/es_beos.h>

#include <kernel/OS.h>
#include <kernel/image.h>
#include <interface/InterfaceDefs.h>

namespace Botan {

/**
* BeOS entropy poll
*/
size_t BeOS_EntropySource::poll(RandomNumberGenerator& rng)
   {
   size_t bits = 0;

   system_info info_sys;
   get_system_info(&info_sys);
   rng.add_entropy(info_sys);

   key_info info_key; // current state of the keyboard
   get_key_info(&info_key);
   rng.add_entropy(info_key);

   team_info info_team;
   int32 cookie_team = 0;

   while(get_next_team_info(&cookie_team, &info_team) == B_OK)
      {
      rng.add_entropy(info_team);

      team_id id = info_team.team;
      int32 cookie = 0;

      thread_info info_thr;
      while(get_next_thread_info(id, &cookie, &info_thr) == B_OK)
         rng.add_entropy(info_thr);

      cookie = 0;
      image_info info_img;
      while(get_next_image_info(id, &cookie, &info_img) == B_OK)
         rng.add_entropy(info_img);

      cookie = 0;
      sem_info info_sem;
      while(get_next_sem_info(id, &cookie, &info_sem) == B_OK)
         rng.add_entropy(info_sem);

      cookie = 0;
      area_info info_area;
      while(get_next_area_info(id, &cookie, &info_area) == B_OK)
         rng.add_entropy(info_area);

      bits += 32;
      }

   return bits;
   }

}