prand is a minimal user space program written in ARMv7 (32-bit ARM) assembly for Linux. It generates a secure 32 character pseudo random string sampled from a custom set of alphanumeric and symbol characters. This is done purely by invoking Linux system calls, without any C runtime or libraries, making the program extremely small and self contained.
- Directly uses the Linux
getrandomsystem call (syscall number 384 on ARMv7) to gather 32 bytes of cryptographically secure random data. - Transforms each raw random byte into a readable character by taking its remainder modulo the size of a predefined character set and using that as an index into the set.
- Prints the generated string followed by a newline to standard output.
- Implements its own program entry (
_start) with no reliance onlibcor startup files. - Statically linked and designed to run on bare ARMv7 Linux systems or emulators.
The random string is composed from this character set of length 78:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789():;!+-$#@/*={}
This set includes uppercase, lowercase, digits, and a selection of common symbols ensuring a broad range of output characters.
The program directly interfaces with Linux syscalls following the ARM 32-bit EABI convention:
r7holds the syscall number.- Arguments are passed in
r0,r1,r2, etc. svc #0triggers the syscall.
For the key operations, syscalls used:
-
getrandom (384):
Reads 32 random bytes into a buffer.r0: pointer to bufferr1: number of bytes to readr2: flags (0)
-
write (4):
Writes the generated string to stdout.r0: file descriptor (1 for stdout)r1: pointer to output bufferr2: buffer length (33 bytes including null terminator)
-
exit (1):
Cleanly exits the program with status code inr0.
.datasection stores the constant character set..bsssection reserves uninitialized memory:randbuf: 32 bytes (random bytes buffer)outbuf: 33 bytes (output string buffer, including null terminator)
- Call
getrandomsyscall to fillrandbufwith 32 random bytes. - Verify if the syscall returned exactly 32 bytes, else exit with error.
- For each byte in
randbuf:- Calculate the modulo against the character set size (78) by repeated subtraction.
- Use the remainder as index to lookup a character in the character set.
- Store the selected character sequentially in
outbuf.
- Append a null terminator byte to
outbuf. - Use the
writesyscall to output the full string to stdout. - Exit cleanly with success status.
_start: program entry point.- Simple loops written with explicit labels (
convert_loop,mod_loop) to process each byte. - Error handling jumps to
error_exitlabel, which exits with status 1. - Uses ARM instructions like
ldr,mov,cmp,b,blt,sub,ldrb,strb.
You can build the project using the provided Makefile:
git clone https://github.com/gaidardzhiev/getprand
cd getprand
make
Ensure you use a assembler and linker for ARMv7 (32-bit ARM).
Run the resulting executable on an ARMv7 Linux system or emulator. The program will print a single 32 character pseudo random string to stdout.
./getprand
- The modulo operation on random bytes uses repeated subtraction, which is simple but not the most efficient; this is acceptable given the small buffer size.
- There is no error output (no stderr) beyond process exit codes.
- This program assumes the ARM 32 bit Linux syscall convention and wont run on other Linux architectures without modification.
This project is provided under the GPL3 License.