Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 320719
b: refs/heads/master
c: c2557a3
h: refs/heads/master
i:
  320717: 32356d2
  320715: 9d8cc65
  320711: 1cd7719
  320703: 394a752
v: v3
  • Loading branch information
Theodore Ts'o committed Jul 15, 2012
1 parent df74597 commit ef2a993
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e6d4947b12e8ad947add1032dd754803c6004824
refs/heads/master: c2557a303ab6712bb6e09447df828c557c710ac9
29 changes: 24 additions & 5 deletions trunk/drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,17 +1038,34 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,

/*
* This function is the exported kernel interface. It returns some
* number of good random numbers, suitable for seeding TCP sequence
* numbers, etc.
* number of good random numbers, suitable for key generation, seeding
* TCP sequence numbers, etc. It does not use the hw random number
* generator, if available; use get_random_bytes_arch() for that.
*/
void get_random_bytes(void *buf, int nbytes)
{
extract_entropy(&nonblocking_pool, buf, nbytes, 0, 0);
}
EXPORT_SYMBOL(get_random_bytes);

/*
* This function will use the architecture-specific hardware random
* number generator if it is available. The arch-specific hw RNG will
* almost certainly be faster than what we can do in software, but it
* is impossible to verify that it is implemented securely (as
* opposed, to, say, the AES encryption of a sequence number using a
* key known by the NSA). So it's useful if we need the speed, but
* only if we're willing to trust the hardware manufacturer not to
* have put in a back door.
*/
void get_random_bytes_arch(void *buf, int nbytes)
{
char *p = buf;

while (nbytes) {
unsigned long v;
int chunk = min(nbytes, (int)sizeof(unsigned long));

if (!arch_get_random_long(&v))
break;

Expand All @@ -1057,9 +1074,11 @@ void get_random_bytes(void *buf, int nbytes)
nbytes -= chunk;
}

extract_entropy(&nonblocking_pool, p, nbytes, 0, 0);
if (nbytes)
extract_entropy(&nonblocking_pool, p, nbytes, 0, 0);
}
EXPORT_SYMBOL(get_random_bytes);
EXPORT_SYMBOL(get_random_bytes_arch);


/*
* init_std_data - initialize pool with system data
Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
extern void add_interrupt_randomness(int irq, int irq_flags);

extern void get_random_bytes(void *buf, int nbytes);
extern void get_random_bytes_arch(void *buf, int nbytes);
void generate_random_uuid(unsigned char uuid_out[16]);

#ifndef MODULE
Expand Down

0 comments on commit ef2a993

Please sign in to comment.