52 lines
1.3 KiB
C
52 lines
1.3 KiB
C
#ifndef MAP_CIPHER_H
|
|
#define MAP_CIPHER_H
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
/**
|
|
* @brief State for the map cipher.
|
|
*
|
|
* @var key The key bytes used for mask lookup.
|
|
* @var len The length of @p key.
|
|
*/
|
|
typedef struct {
|
|
uint8_t *key;
|
|
int len;
|
|
} map_cipher_t;
|
|
|
|
/**
|
|
* @brief Initializes a map cipher instance.
|
|
*
|
|
* Takes ownership of @p key; the caller must not free it separately.
|
|
*
|
|
* @param c The cipher instance to initialize.
|
|
* @param key The key bytes (allocated, ownership transferred).
|
|
* @param len The key length.
|
|
*/
|
|
void map_cipher_init(map_cipher_t *c, uint8_t *key, int len);
|
|
|
|
/**
|
|
* @brief XOR-decrypts a buffer using the map cipher.
|
|
*
|
|
* Each byte is XORed with a rotated key byte selected from the
|
|
* key by the formula (offset^2 + 71214) % key_len.
|
|
*
|
|
* @param c The map cipher instance.
|
|
* @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 map_decrypt(map_cipher_t *c, uint8_t *buf, size_t len, int offset);
|
|
|
|
/**
|
|
* @brief Frees resources held by a map cipher instance.
|
|
*
|
|
* The key buffer passed to map_cipher_init is freed.
|
|
*
|
|
* @param c The cipher instance to clean up.
|
|
*/
|
|
void map_cipher_free(map_cipher_t *c);
|
|
|
|
#endif /* MAP_CIPHER_H */
|