bkcrack: include/bkcrack/Crc32Tab.hpp Source File

bkcrack 1.8.1 Crack legacy zip encryption with Biham and Kocher's known plaintext attack.

Crc32Tab.hpp
1#ifndef BKCRACK_CRC32TAB_HPP
2#define BKCRACK_CRC32TAB_HPP
3
4#include <bkcrack/types.hpp>
5
7 class Crc32Tab
8{
9public:
11 static auto crc32(std::uint32_t pval, std::uint8_t b) -> std::uint32_t
12 {
13 return pval >> 8 ^ instance.crctab[lsb(pval) ^ b];
14 }
15
17 static auto crc32inv(std::uint32_t crc, std::uint8_t b) -> std::uint32_t
18 {
19 return crc << 8 ^ instance.crcinvtab[msb(crc)] ^ b;
20 }
21
23 static auto getYi_24_32(std::uint32_t zi, std::uint32_t zim1) -> std::uint32_t
24 {
25 return (crc32inv(zi, 0) ^ zim1) << 24;
26 }
27
29 static auto getZim1_10_32(std::uint32_t zi_2_32) -> std::uint32_t
30 {
31 return crc32inv(zi_2_32, 0) & mask<10, 32>; // discard 10 least significant bits
32 }
33
34private:
35 // initialize lookup tables
36 Crc32Tab();
37
38 // lookup tables
39 std::array<std::uint32_t, 256> crctab;
40 std::array<std::uint32_t, 256> crcinvtab;
41
42 static const Crc32Tab instance;
43};
44
45#endif // BKCRACK_CRC32TAB_HPP
Crc32Tab
Lookup tables for CRC32 related computations.
Definition Crc32Tab.hpp:8
Crc32Tab::crc32inv
static auto crc32inv(std::uint32_t crc, std::uint8_t b) -> std::uint32_t
Definition Crc32Tab.hpp:17
Crc32Tab::getYi_24_32
static auto getYi_24_32(std::uint32_t zi, std::uint32_t zim1) -> std::uint32_t
Definition Crc32Tab.hpp:23
Crc32Tab::getZim1_10_32
static auto getZim1_10_32(std::uint32_t zi_2_32) -> std::uint32_t
Definition Crc32Tab.hpp:29
Crc32Tab::crc32
static auto crc32(std::uint32_t pval, std::uint8_t b) -> std::uint32_t
Definition Crc32Tab.hpp:11
types.hpp
Useful types, constants and utility functions.
lsb
constexpr auto lsb(std::uint32_t x) -> std::uint8_t
Definition types.hpp:24
mask
constexpr auto mask
Constant value for bit masking.
Definition types.hpp:39
msb
constexpr auto msb(std::uint32_t x) -> std::uint8_t
Definition types.hpp:30