xor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Benjamin Valentin <benjamin.valentin@ml-pa.com>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
27 #ifndef CODING_XOR_H
28 #define CODING_XOR_H
29 
30 #include <stddef.h>
31 #include <stdint.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
40 #ifndef CONFIG_CODING_XOR_CHECK_BYTES
41 #define CONFIG_CODING_XOR_CHECK_BYTES 3U
42 #endif
43 
49 #define CODING_XOR_PARITY_LEN(in) (((in) + CONFIG_CODING_XOR_CHECK_BYTES - 1) \
50  / CONFIG_CODING_XOR_CHECK_BYTES)
51 
65 void coding_xor_generate(void *data, size_t len, uint8_t *parity);
66 
86 bool coding_xor_recover(void *data, size_t len, uint8_t *parity,
87  uint8_t *blocks, size_t block_size, bool recover_parity);
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif /* CODING_XOR_H */
void coding_xor_generate(void *data, size_t len, uint8_t *parity)
Generate parity and mix data buffer.
bool coding_xor_recover(void *data, size_t len, uint8_t *parity, uint8_t *blocks, size_t block_size, bool recover_parity)
Restore and unmix buffer.