Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
LSH
lsh
Commits
0d0b1ae9
Commit
0d0b1ae9
authored
Nov 14, 2001
by
Niels Möller
Browse files
(get_dev_random): Implement reading of
/dev/random. Rev: src/lsh-make-seed.c:1.3
parent
4ec78bd1
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/lsh-make-seed.c
View file @
0d0b1ae9
...
...
@@ -31,7 +31,9 @@
#include
"nettle/yarrow.h"
#include
<errno.h>
#include
<stdlib.h>
#include
<string.h>
#include
<sys/stat.h>
#include
<sys/types.h>
...
...
@@ -162,10 +164,50 @@ enum source_type
NSOURCES
};
#define DEVRANDOM_SIZE 40
static
void
get_dev_random
(
struct
yarrow256_ctx
*
ctx
,
enum
source_type
source
)
{
static
const
char
*
names
[]
=
{
"/dev/random"
,
"/dev/urandom"
,
NULL
};
int
fd
=
-
1
;
unsigned
i
;
int
res
;
char
buffer
[
DEVRANDOM_SIZE
];
for
(
i
=
0
;
names
[
i
];
i
++
)
{
fd
=
open
(
"/dev/random"
,
O_RDONLY
);
if
(
fd
>=
0
)
break
;
}
if
(
fd
<
0
)
return
;
verbose
(
"Reading %z
\n
"
,
names
[
i
]);
do
{
res
=
read
(
fd
,
buffer
,
DEVRANDOM_SIZE
);
}
while
(
(
res
<
0
)
&&
(
errno
==
EINTR
));
if
(
res
<
0
)
werror
(
"Reading from %z failed (errno = %i): %z
\n
"
,
names
[
i
],
errno
,
STRERROR
(
errno
));
else
if
(
res
>
0
)
{
/* Count 4 bits of entropy for each byte. */
yarrow256_update
(
ctx
,
source
,
res
*
4
,
res
,
buffer
);
}
else
werror
(
"unix_random.c: No data available on %z
\n
"
,
names
[
i
]);
close
(
fd
);
}
static
void
...
...
@@ -315,6 +357,7 @@ get_system(struct yarrow256_ctx *ctx, enum source_type source)
static
void
get_interact
(
struct
yarrow256_ctx
*
ctx
,
enum
source_type
source
)
{
werror
(
"Please type some random data.
\n
"
);
}
int
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment