Skip to content

Commit

Permalink
tools: add tool for generating random hexadecimal values
Browse files Browse the repository at this point in the history
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
nmeum authored and aabadie committed Jan 23, 2020
1 parent 166c145 commit 4bcb2d1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dist/tools/randhex/README.md
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.
20 changes: 20 additions & 0 deletions dist/tools/randhex/randhex.py
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)))

0 comments on commit 4bcb2d1

Please sign in to comment.