aboutsummaryrefslogtreecommitdiff
path: root/src/channels.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2011-08-25 17:08:04 +0300
committerAris Adamantiadis <aris@0xbadc0de.be>2011-09-02 11:42:59 +0300
commit510c74122938549aaf53718e1fc05741e75ead41 (patch)
tree517c12bdf5fb8013da0a0ce6eee844732dd4ef48 /src/channels.c
parentf9dad9ad682639f8cd0d2599ef4bb42300e095d7 (diff)
downloadlibssh-510c74122938549aaf53718e1fc05741e75ead41.tar.gz
libssh-510c74122938549aaf53718e1fc05741e75ead41.tar.xz
libssh-510c74122938549aaf53718e1fc05741e75ead41.zip
channels: use hard random for the X11 cookie
We are in a security library or we are not.
Diffstat (limited to 'src/channels.c')
-rw-r--r--src/channels.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/channels.c b/src/channels.c
index be59b78a..622cefcb 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -1769,11 +1769,13 @@ int ssh_channel_request_sftp( ssh_channel channel){
static ssh_string generate_cookie(void) {
static const char *hex = "0123456789abcdef";
char s[36];
+ char rnd[16];
int i;
- srand ((unsigned int)time(NULL));
- for (i = 0; i < 32; i++) {
- s[i] = hex[rand() % 16];
+ ssh_get_random(rnd,sizeof(rnd),0);
+ for (i = 0; i < 16; i++) {
+ s[i*2] = hex[rnd[i] & 0x0f];
+ s[i*2+1] = hex[rnd[i] >> 4];
}
s[32] = '\0';
return ssh_string_from_char(s);