#ifndef _SYS_CPROTECT_H_
#define _SYS_CPROTECT_H_
#ifdef __cplusplus
extern "C" {
#endif
#if KERNEL_PRIVATE
#include <sys/cdefs.h>
#include <sys/kernel_types.h>
#define PROTECTION_CLASS_A 1
#define PROTECTION_CLASS_B 2
#define PROTECTION_CLASS_C 3
#define PROTECTION_CLASS_D 4
#define PROTECTION_CLASS_E 5
#define KEYSIZE 8
#define INTEGRITYSIZE 2
#define LOCKED_STATE 0
#define UNLOCKED_STATE 1
#define LOCKED_KEYCHAIN 0
#define UNLOCKED_KEYCHAIN 1
#define CONTENT_PROTECTION_XATTR_NAME "com.apple.system.cprotect"
#define kEMBCKeyHandleSpecial ~1
typedef struct cprotect *cprotect_t;
typedef struct cp_wrap_func *cp_wrap_func_t;
typedef struct cp_global_state *cp_global_state_t;
typedef struct cp_xattr *cp_xattr_t;
typedef int wrapper_t(uint32_t properties, void *key_bytes, size_t key_length, void **wrapped_data, uint32_t *wrapped_length);
typedef int unwrapper_t(uint32_t properties, void *wrapped_data, size_t wrapped_data_length, void **key_bytes, uint32_t *key_length);
struct cprotect {
uint32_t cache_key[KEYSIZE];
uint32_t special_data;
uint32_t pclass;
uint8_t cache_key_flushed;
uint8_t lock_state;
};
struct cp_entry {
SLIST_ENTRY(cp_entry) cp_list;
struct cprotect *protected_entry;
};
struct cp_wrap_func {
wrapper_t *wrapper;
unwrapper_t *unwrapper;
};
struct cp_global_state {
uint8_t lock_state;
uint8_t wrap_functions_set;
};
struct cp_xattr {
uint32_t persistent_class;
uint8_t persistent_key[32];
uint8_t persistent_integrity[8];
uint8_t xattr_version;
};
int cp_create_init(vnode_t, vfs_context_t);
int cp_key_store_action(int);
int cp_register_wraps(cp_wrap_func_t);
struct cprotect *cp_vnode_entry_alloc(void);
void cp_vnode_entry_init(vnode_t);
int cp_vnode_entry_init_needed(vnode_t);
struct cp_xattr * cp_vn_getxattr(vnode_t, vfs_context_t);
int cp_vn_setxattr(vnode_t, uint32_t, vfs_context_t);
#endif
#ifdef __cplusplus
};
#endif
#endif