31 lines
791 B
C
31 lines
791 B
C
#ifndef STATIC_CIPHER_H
|
|
#define STATIC_CIPHER_H
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
/**
|
|
* @brief XOR-decrypts a buffer using the static cipher.
|
|
*
|
|
* Each byte is XORed with the mask byte computed from the fixed
|
|
* 256-byte substitution box at position
|
|
* S_BOX[(offset^2 + 27) & 0xFF].
|
|
*
|
|
* @param buf The buffer to decrypt in-place.
|
|
* @param len The length of @p buf.
|
|
* @param offset The starting file offset for mask generation.
|
|
*/
|
|
void static_decrypt(uint8_t *buf, size_t len, int offset);
|
|
|
|
/**
|
|
* @brief Computes the static cipher mask byte for the given offset.
|
|
*
|
|
* Exposed for testing. Offsets above 0x7FFF are reduced modulo 0x7FFF.
|
|
*
|
|
* @param offset The file offset.
|
|
* @return The mask byte.
|
|
*/
|
|
uint8_t static_mask(int offset);
|
|
|
|
#endif /* STATIC_CIPHER_H */
|