Skip to content

rhjddjdbc/otp-asm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

One-Time-Pad (Vernam Cipher) - x86-64 Linux Assembly

This project implements a One-Time-Pad (OTP) encryption algorithm in x86-64 Assembly for Linux. It uses the Vernam cipher, where the key is as long as the file to encrypt and is used only once. When used correctly, this provides unbreakable encryption.

Features

  • Key Generation: Generates a secure key using /dev/urandom.
  • Encryption: Encrypts a file using the generated or provided key.
  • Decryption: The same key can be used to decrypt a file.
  • Key Management: Choose between a generated key or an existing key file.
  • File Deletion: Optionally deletes the original file after successful encryption.
  • Configurable Block Size: Allows processing large files in blocks.

Compatibility

  • OS: Linux
  • Architecture: x86-64 (64-bit)
  • Assembler: NASM (Netwide Assembler)
  • Linker: GNU ld

Usage

Compile and Link

nasm -f elf64 otp.asm -o otp.o   # Assemble
ld otp.o -o otp                  # Link

Available Options

Usage: ./otp [OPTIONS] <input_file> <output_file>

Options:
  -g               Generate a new key (size = input file)
  -k <keyfile>     Use an existing key file
  -o <keyfile>     Save generated key to this file (default: otp_key.bin)
  -b <blocksize>   Set block size in KiB (default: 64 KiB)
  -d               Delete original file after encryption
  -h, --help       Show this help message

Examples

  • Generate a new key and encrypt a file:
./otp -g -o mykey.bin -d input.txt encrypted.enc
  • Use an existing key to decrypt a file:
./otp -k mykey.bin encrypted.enc decrypted.txt
  • Use a custom block size (128 KiB):
./otp -g -o otp_key.bin -b 128 -d input.txt encrypted.enc

How It Works

  1. Key Generation: With -g, the program generates a key with random bytes from /dev/urandom. The key size matches the input file size.
  2. Encryption/Decryption: The file is read in blocks (default 64 KiB) and XORed with the key to produce the output.
  3. Optional File Deletion: If -d is used and encryption is performed, the original file is deleted after successful encryption.

Error Handling

  • Invalid arguments produce an error message.
  • File access errors (e.g., missing files or permission issues) produce detailed error messages.
  • Insufficient key length or write errors are also reported.

Error Messages

  • Invalid arguments: Arguments are missing or incorrect.
  • stat() failed: Could not get input file size.
  • Cannot open /dev/urandom: Failed to access the random source.
  • Key file error: Failed to read/write the key file.
  • Key shorter than input: The key is shorter than the input file.
  • Write failed: Writing the output file failed.
  • File I/O error: General file I/O failure.

Important Notes

  • Security: Keep your keys secure. If a key is lost or compromised, the encrypted file is no longer secure.
  • Key Size: The key must be at least as large as the file to encrypt.
  • One-Time Use: Never reuse an OTP key. Generate a new key for each file.

License

This project is licensed under the GNU General Public License v3.0 (GPL-3.0).

You may use, modify, and redistribute the code under the GPL-3.0 terms. See the LICENSE file for details.

About

One-Time-Pad (Vernam Cipher) - x86-64 Linux Assembly

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors