Check-in [423575338a]
Overview
Comment:Some platforms do not define LONG_LONG_MAX and we really don't need that many bytes of random data anyway, so use a smaller value
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 423575338a4efde9f3b0fefd8a11ad9095d488e8e38caa2ee5b241e7851fb255
User & Date: rkeene on 2018-07-10 19:20:52
Other Links: manifest | tags
Context
2018-07-10
19:27
Added dependencies check-in: 84a49387e9 user: rkeene tags: trunk
19:20
Some platforms do not define LONG_LONG_MAX and we really don't need that many bytes of random data anyway, so use a smaller value check-in: 423575338a user: rkeene tags: trunk
00:33
Better formatting of Downloads wiki page check-in: 7e81c41b70 user: rkeene tags: trunk
Changes

Modified randombytes.c from [9959d0caf1] to [2ad22d5176].

1
2
3
4
5
6
7
8
9
10








11
12
13
14
15
16
17
18
#include <limits.h>
#include <tcl.h>

#include "randombytes.h"

long long getrandom_impl(void *buf, unsigned int buflen);
void randombytes(unsigned char *buffer, unsigned long long length) {
	long long gr_ret;
	int errorCount = 0;









	if (length > UINT_MAX || length > LONG_LONG_MAX) {
		Tcl_Panic("Buffer length is too large");
	}

	while (length > 0) {
		gr_ret = getrandom_impl(buffer, length);

		if (gr_ret < 0) {





|

|


>
>
>
>
>
>
>
>
|







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
#include <limits.h>
#include <tcl.h>

#include "randombytes.h"

long getrandom_impl(void *buf, unsigned int buflen);
void randombytes(unsigned char *buffer, unsigned long long length) {
	long gr_ret;
	int errorCount = 0;

	/*
	 * Ensure that the number of bytes requested can fit within
	 * the types we pass to other calls.
	 *
	 * The interface required by randombytes() used by TweetNaCl
	 * does not give us any way to handle errors.  However,
	 * no buffer should exceed these amounts.
	 */
	if (length > UINT_MAX || length > LONG_MAX) {
		Tcl_Panic("Buffer length is too large");
	}

	while (length > 0) {
		gr_ret = getrandom_impl(buffer, length);

		if (gr_ret < 0) {
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
}

#if defined(HAVE_GETRANDOM)
#  ifdef HAVE_SYS_RANDOM_H
#    include <sys/random.h>
#  endif

long long getrandom_impl(void *buf, unsigned int buflen) {
	ssize_t gr_ret;

	gr_ret = getrandom(buf, buflen, 0);

	return(gr_ret);
}

#elif defined(HAVE_GETENTROPY)
#include <unistd.h>

long long getrandom_impl(void *buf, unsigned int buflen) {
	int ge_ret;

	if (buflen > 255) {
		buflen = 255;
	}

	ge_ret = getentropy(buf, buflen);
	if (ge_ret != 0) {
		return(-1);
	}

	return(buflen);
}
#elif defined(HAVE_CRYPTGENRANDOM) && 0
#include <tcl.h>
long long getrandom_impl(void *buf, unsigned int buflen) {
	Tcl_Panic("Incomplete CryptGenRandom");
}
#else
#  ifdef HAVE_SYS_TYPES_H
#    include <sys/types.h>
#  endif
#  ifdef HAVE_SYS_STAT_H
#    include <sys/stat.h>
#  endif
#  ifdef HAVE_FCNTL_H
#    include <fcntl.h>
# endif
# ifdef HAVE_UNISTD_H
#    include <unistd.h>
# endif
long long getrandom_impl(void *buf, unsigned int buflen) {
	ssize_t read_ret;
	long long retval;
	int fd = -1;

	fd = open("/dev/urandom", O_RDONLY);
	if (fd < 0) {
		return(-1);
	}








|










|















|















|

|







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
}

#if defined(HAVE_GETRANDOM)
#  ifdef HAVE_SYS_RANDOM_H
#    include <sys/random.h>
#  endif

long getrandom_impl(void *buf, unsigned int buflen) {
	ssize_t gr_ret;

	gr_ret = getrandom(buf, buflen, 0);

	return(gr_ret);
}

#elif defined(HAVE_GETENTROPY)
#include <unistd.h>

long getrandom_impl(void *buf, unsigned int buflen) {
	int ge_ret;

	if (buflen > 255) {
		buflen = 255;
	}

	ge_ret = getentropy(buf, buflen);
	if (ge_ret != 0) {
		return(-1);
	}

	return(buflen);
}
#elif defined(HAVE_CRYPTGENRANDOM) && 0
#include <tcl.h>
long getrandom_impl(void *buf, unsigned int buflen) {
	Tcl_Panic("Incomplete CryptGenRandom");
}
#else
#  ifdef HAVE_SYS_TYPES_H
#    include <sys/types.h>
#  endif
#  ifdef HAVE_SYS_STAT_H
#    include <sys/stat.h>
#  endif
#  ifdef HAVE_FCNTL_H
#    include <fcntl.h>
# endif
# ifdef HAVE_UNISTD_H
#    include <unistd.h>
# endif
long getrandom_impl(void *buf, unsigned int buflen) {
	ssize_t read_ret;
	long retval;
	int fd = -1;

	fd = open("/dev/urandom", O_RDONLY);
	if (fd < 0) {
		return(-1);
	}