Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
6bf31543
Commit
6bf31543
authored
9 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
Make the crypto_rand_int_range return value right-exclusive.
parent
3f413184
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/common/crypto.c
+7
-7
7 additions, 7 deletions
src/common/crypto.c
with
7 additions
and
7 deletions
src/common/crypto.c
+
7
−
7
View file @
6bf31543
...
...
@@ -2317,23 +2317,23 @@ crypto_rand_int(unsigned int max)
}
}
/** Return a pseudorandom integer, chosen uniformly from the values
between
* <b>min</b>
and
<b>max</b>
inclusive
.
/** Return a pseudorandom integer, chosen uniformly from the values
<i>i</i>
*
such that
<b>min</b>
<= <i>i</i> <
<b>max</b>.
*
* <b>min</b> MUST be
between 0 and
<b>max</b>
- 1
.
* <b>max</b> MUST be
bigger than <b>min</b> and <= to
INT_MAX.
* <b>min</b> MUST be
in range [0,
<b>max</b>
)
.
* <b>max</b> MUST be
in range (min,
INT_MAX
]
.
*/
int
crypto_rand_int_range
(
unsigned
int
min
,
unsigned
int
max
)
{
tor_assert
(
min
<
=
max
);
tor_assert
(
min
<
max
);
tor_assert
(
max
<=
INT_MAX
);
/* The overflow is avoided here because crypto_rand_int() returns a value
* between 0 and (max - min - 1) with max being <= INT_MAX and min <= max.
* This is why we add 1 to the maximum value so we can actually get max as
* a return value. */
return
min
+
crypto_rand_int
(
max
-
min
+
1
);
return
min
+
crypto_rand_int
(
max
-
min
);
}
/** Return a pseudorandom 64-bit integer, chosen uniformly from the values
...
...
@@ -2398,7 +2398,7 @@ crypto_random_hostname(int min_rand_len, int max_rand_len, const char *prefix,
if
(
min_rand_len
>
max_rand_len
)
min_rand_len
=
max_rand_len
;
randlen
=
crypto_rand_int_range
(
min_rand_len
,
max_rand_len
);
randlen
=
crypto_rand_int_range
(
min_rand_len
,
max_rand_len
+
1
);
prefixlen
=
strlen
(
prefix
);
resultlen
=
prefixlen
+
strlen
(
suffix
)
+
randlen
+
16
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment