mirror of
git://f0xx.org/android_cast
synced 2026-07-29 07:20:00 +03:00
31 lines
999 B
C
31 lines
999 B
C
#ifndef OBFUSCATE_H
|
|
#define OBFUSCATE_H
|
|
|
|
#include <stdint.h>
|
|
|
|
/* Payload uses lower 40 bits; upper 24 bits hold verification tag. */
|
|
#define OBF_PAYLOAD_BITS 40u
|
|
#define OBF_PAYLOAD_MASK ((1ULL << OBF_PAYLOAD_BITS) - 1ULL)
|
|
|
|
/* Return codes */
|
|
#define OBF_OK 0
|
|
#define OBF_ERR_NULL -1 /* out pointer is NULL */
|
|
#define OBF_ERR_RANGE -2 /* val exceeds encodable payload width */
|
|
#define OBF_ERR_VERIFY -3 /* tag mismatch (wrong seed or corrupted data) */
|
|
|
|
/*
|
|
* Encode uint64_t payload (e.g. flag bits) using seed-derived keystream.
|
|
* seed is typically unix time in whole seconds shared by encoder and decoder.
|
|
*
|
|
* On success writes single uint64_t to *out and returns OBF_OK.
|
|
*/
|
|
int32_t encode(uint64_t val, uint64_t seed, uint64_t *out);
|
|
|
|
/*
|
|
* Decode and verify. seed must match the value used at encode time.
|
|
* On success writes recovered payload to *out and returns OBF_OK.
|
|
*/
|
|
int32_t decode(uint64_t encoded_val, uint64_t seed, uint64_t *out);
|
|
|
|
#endif /* OBFUSCATE_H */
|