xor.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2021 Benjamin Valentin <benjamin.valentin@ml-pa.com>
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
26 #include <stddef.h>
27 #include <stdint.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
36 #ifndef CONFIG_CODING_XOR_CHECK_BYTES
37 #define CONFIG_CODING_XOR_CHECK_BYTES 3U
38 #endif
39 
45 #define CODING_XOR_PARITY_LEN(in) (((in) + CONFIG_CODING_XOR_CHECK_BYTES - 1) \
46  / CONFIG_CODING_XOR_CHECK_BYTES)
47 
61 void coding_xor_generate(void *data, size_t len, uint8_t *parity);
62 
82 bool coding_xor_recover(void *data, size_t len, uint8_t *parity,
83  uint8_t *blocks, size_t block_size, bool recover_parity);
84 #ifdef __cplusplus
85 }
86 #endif
87 
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.