slog2_obfuscate()

Updated: April 19, 2023

Obfuscate file and directory names by replacing some characters

Synopsis:

#include <sys/slog2.h>

int slog2_obfuscate( slog2_obf_t obf_type,
                     char obf_char,
                     uint32_t flags,
                     const char *input,
                     size_t size,
                     char *output );

Arguments:

obf_type
The type of input that needs to be obfuscated:
  • SLOG2_OBF_FILEPATH ̵ the input is a file path, which could include directory name(s), a file name, and an extension.
obf_char
The character to use for obfuscation. If you set this to the null character (i.e., '\0'), then slog2_obfuscate() uses slog2_hash() to fill in the obfuscated characters. Typical values used are “x” or a period.
flags
Reserved for future use. Set this to 0.
input
A null-terminated input string (UTF-8) to be obfuscated (e.g., personally identifiable information, such as a file name).
size
The size of the output buffer.
output
A buffer where the function can store the resulting obfuscated string buffer. The string is null-terminated.

Library:

libslog2-extra

Use the -l slog2-extra option to qcc to link against this library.

Description:

The slog2_obfuscate() function creates an obfuscated version of a string by replacing portions of it with a given character.

The obfuscated output string length is truncated to size - 1 characters if the output buffer is smaller than the size required to store input.

When obf_char isn't the null character, the resulting obfuscated output string always produces the same output for a given string. When obf_char is the null character, the obfuscated output string value will be identical within a similar timeframe across all processes.

For file and directory names:

For example (using “.” as the replacement character):

Before After
dir/file.txt d.r/f..e.txt
my_fav_dir/my_file.txt my......ir/my...le.txt

Because this function depends on the random number generator, make sure that /dev/random is running before you start slogger2.

Returns:

0 on success, or -1 if an error occurred.

Classification:

QNX Neutrino

Safety:  
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes