forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: add tool for generating random hexadecimal values
This tool generates a random hexadecimal value of a given maximum size. This is useful for generating random canary values during compile-time for the ssp module which currently uses a constant value.
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
randhex.py | ||
---------- | ||
|
||
Usage: `randhex.py <MAXBITS>` | ||
|
||
This script generates a random hexadecimal value of the given maximum | ||
size in bits. If `MAXBITS` is not specified it defaults to 64. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2020 Sören Tempel <tempel@uni-bremen.de> | ||
# | ||
# This file is subject to the terms and conditions of the GNU Lesser | ||
# General Public License v2.1. See the file LICENSE in the top level | ||
# directory for more details. | ||
# | ||
|
||
import sys | ||
import secrets | ||
|
||
if len(sys.argv) >= 2: | ||
maxbits = int(sys.argv[1]) | ||
else: | ||
maxbits = 64 | ||
|
||
maxval = 2 ** maxbits | ||
print(hex(secrets.randbelow(maxval))) |