]>
git.zerfleddert.de Git - proxmark3-svn/blob - common/parity.h
1 //-----------------------------------------------------------------------------
2 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
3 // at your option, any later version. See the LICENSE.txt file for the text of
5 //-----------------------------------------------------------------------------
7 //-----------------------------------------------------------------------------
9 // all functions defined in header file by purpose. Allows compiler optimizations.
18 extern const uint8_t OddByteParity
[256];
21 static inline bool oddparity8(const uint8_t x
) {
22 return OddByteParity
[x
];
25 static inline void oddparitybuf(const uint8_t *x
, size_t len
, uint8_t *parity
) {
26 memset(parity
, 0x00, (len
- 1) / 8 + 1);
27 for (int i
= 0; i
< len
; i
++)
28 parity
[i
/ 8] |= oddparity8(x
[i
]) << (7 - (i
% 8));
31 static inline bool evenparity8(const uint8_t x
) {
32 return !OddByteParity
[x
];
36 static inline bool evenparity32(uint32_t x
)
41 return evenparity8(x
);
43 return __builtin_parity(x
);
48 static inline bool oddparity32(uint32_t x
)
55 return !__builtin_parity(x
);
59 #endif /* __PARITY_H */