Changeset 1601:52e504c91cbc
- Timestamp:
- 11/04/08 09:27:49
(2 months ago)
- Author:
- Greg Von Kuster <greg@bx.psu.edu>
- branch:
- default
- Message:
Apply James' faster_random patch from Nov 1.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r1600 |
r1601 |
|
| 11 | 11 | |
|---|
| 12 | 12 | if os.path.exists( "/dev/urandom" ): |
|---|
| 13 | | log.debug("###using /dev/urandom....") |
|---|
| 14 | 13 | # We have urandom, use it as the source of random data |
|---|
| 15 | 14 | random_fd = os.open( "/dev/urandom", os.O_RDONLY ) |
|---|
| … | … | |
| 18 | 17 | # Normally we should get as much as we need |
|---|
| 19 | 18 | if len( value ) == nbytes: |
|---|
| 20 | | return value |
|---|
| | 19 | return value.encode( "hex" ) |
|---|
| 21 | 20 | # If we don't, keep reading (this is slow and should never happen) |
|---|
| 22 | 21 | while len( value ) < nbytes: |
|---|
| 23 | 22 | value += os.read( random_fd, nbytes - len( value ) ) |
|---|
| 24 | | return value |
|---|
| | 23 | return value.encode( "hex" ) |
|---|
| 25 | 24 | else: |
|---|
| 26 | 25 | def get_random_bytes( nbytes ): |
|---|
| … | … | |
| 30 | 29 | random_pool.add_event() |
|---|
| 31 | 30 | random_pool.stir() |
|---|
| 32 | | return( str( number.getRandomNumber( nbits, random_pool.get_bytes ) ) ) |
|---|
| | 31 | return str( number.getRandomNumber( nbits, random_pool.get_bytes ) ) |
|---|
| | 32 | |
|---|
| 33 | 33 | |
|---|
| 34 | 34 | class SecurityHelper( object ): |
|---|