Bitcoin Core  27.99.0
P2P Digital Currency
clmul_1byte.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * Copyright (c) 2018 Pieter Wuille, Greg Maxwell, Gleb Naumenko *
3  * Distributed under the MIT software license, see the accompanying *
4  * file LICENSE or http://www.opensource.org/licenses/mit-license.php.*
5  **********************************************************************/
6 
7 /* This file was substantially auto-generated by doc/gen_params.sage. */
8 #include "../fielddefines.h"
9 
10 #if defined(ENABLE_FIELD_BYTES_INT_1)
11 
12 #include "clmul_common_impl.h"
13 
14 #include "../int_utils.h"
15 #include "../lintrans.h"
16 #include "../sketch_impl.h"
17 
18 #endif
19 
20 #include "../sketch.h"
21 
22 namespace {
23 #ifdef ENABLE_FIELD_INT_2
24 // 2 bit field
25 typedef RecLinTrans<uint8_t, 2> StatTableTRI2;
26 constexpr StatTableTRI2 SQR_TABLE_TRI2({0x1, 0x3});
27 constexpr StatTableTRI2 QRT_TABLE_TRI2({0x2, 0});
28 typedef FieldTri<uint8_t, 2, 1, StatTableTRI2, &SQR_TABLE_TRI2, &QRT_TABLE_TRI2, &QRT_TABLE_TRI2, &QRT_TABLE_TRI2, &QRT_TABLE_TRI2, &QRT_TABLE_TRI2, IdTrans, &ID_TRANS, &ID_TRANS> FieldTri2;
29 #endif
30 
31 #ifdef ENABLE_FIELD_INT_3
32 // 3 bit field
33 typedef RecLinTrans<uint8_t, 3> StatTableTRI3;
34 constexpr StatTableTRI3 SQR_TABLE_TRI3({0x1, 0x4, 0x6});
35 constexpr StatTableTRI3 QRT_TABLE_TRI3({0, 0x4, 0x6});
36 typedef FieldTri<uint8_t, 3, 1, StatTableTRI3, &SQR_TABLE_TRI3, &QRT_TABLE_TRI3, &QRT_TABLE_TRI3, &QRT_TABLE_TRI3, &QRT_TABLE_TRI3, &QRT_TABLE_TRI3, IdTrans, &ID_TRANS, &ID_TRANS> FieldTri3;
37 #endif
38 
39 #ifdef ENABLE_FIELD_INT_4
40 // 4 bit field
41 typedef RecLinTrans<uint8_t, 4> StatTableTRI4;
42 constexpr StatTableTRI4 SQR_TABLE_TRI4({0x1, 0x4, 0x3, 0xc});
43 constexpr StatTableTRI4 QRT_TABLE_TRI4({0x6, 0xa, 0x8, 0});
44 typedef FieldTri<uint8_t, 4, 1, StatTableTRI4, &SQR_TABLE_TRI4, &QRT_TABLE_TRI4, &QRT_TABLE_TRI4, &QRT_TABLE_TRI4, &QRT_TABLE_TRI4, &QRT_TABLE_TRI4, IdTrans, &ID_TRANS, &ID_TRANS> FieldTri4;
45 #endif
46 
47 #ifdef ENABLE_FIELD_INT_5
48 // 5 bit field
49 typedef RecLinTrans<uint8_t, 5> StatTable5;
50 constexpr StatTable5 SQR_TABLE_5({0x1, 0x4, 0x10, 0xa, 0xd});
51 constexpr StatTable5 SQR2_TABLE_5({0x1, 0x10, 0xd, 0xe, 0x1b});
52 constexpr StatTable5 QRT_TABLE_5({0x14, 0x8, 0xa, 0, 0xe});
53 typedef Field<uint8_t, 5, 5, StatTable5, &SQR_TABLE_5, &SQR2_TABLE_5, &QRT_TABLE_5, &QRT_TABLE_5, &QRT_TABLE_5, &QRT_TABLE_5, IdTrans, &ID_TRANS, &ID_TRANS> Field5;
54 typedef FieldTri<uint8_t, 5, 2, RecLinTrans<uint8_t, 5>, &SQR_TABLE_5, &SQR2_TABLE_5, &QRT_TABLE_5, &QRT_TABLE_5, &QRT_TABLE_5, &QRT_TABLE_5, IdTrans, &ID_TRANS, &ID_TRANS> FieldTri5;
55 #endif
56 
57 #ifdef ENABLE_FIELD_INT_6
58 // 6 bit field
59 typedef RecLinTrans<uint8_t, 6> StatTableTRI6;
60 constexpr StatTableTRI6 SQR_TABLE_TRI6({0x1, 0x4, 0x10, 0x3, 0xc, 0x30});
61 constexpr StatTableTRI6 SQR2_TABLE_TRI6({0x1, 0x10, 0xc, 0x5, 0x13, 0x3c});
62 constexpr StatTableTRI6 QRT_TABLE_TRI6({0x3a, 0x26, 0x24, 0x14, 0x20, 0});
63 typedef FieldTri<uint8_t, 6, 1, StatTableTRI6, &SQR_TABLE_TRI6, &SQR2_TABLE_TRI6, &QRT_TABLE_TRI6, &QRT_TABLE_TRI6, &QRT_TABLE_TRI6, &QRT_TABLE_TRI6, IdTrans, &ID_TRANS, &ID_TRANS> FieldTri6;
64 #endif
65 
66 #ifdef ENABLE_FIELD_INT_7
67 // 7 bit field
68 typedef RecLinTrans<uint8_t, 4, 3> StatTableTRI7;
69 constexpr StatTableTRI7 SQR_TABLE_TRI7({0x1, 0x4, 0x10, 0x40, 0x6, 0x18, 0x60});
70 constexpr StatTableTRI7 SQR2_TABLE_TRI7({0x1, 0x10, 0x6, 0x60, 0x14, 0x46, 0x78});
71 constexpr StatTableTRI7 QRT_TABLE_TRI7({0, 0x14, 0x16, 0x72, 0x12, 0x40, 0x7a});
72 typedef FieldTri<uint8_t, 7, 1, StatTableTRI7, &SQR_TABLE_TRI7, &SQR2_TABLE_TRI7, &QRT_TABLE_TRI7, &QRT_TABLE_TRI7, &QRT_TABLE_TRI7, &QRT_TABLE_TRI7, IdTrans, &ID_TRANS, &ID_TRANS> FieldTri7;
73 #endif
74 
75 #ifdef ENABLE_FIELD_INT_8
76 // 8 bit field
77 typedef RecLinTrans<uint8_t, 4, 4> StatTable8;
78 constexpr StatTable8 SQR_TABLE_8({0x1, 0x4, 0x10, 0x40, 0x1b, 0x6c, 0xab, 0x9a});
79 constexpr StatTable8 SQR2_TABLE_8({0x1, 0x10, 0x1b, 0xab, 0x5e, 0x97, 0xb3, 0xc5});
80 constexpr StatTable8 QRT_TABLE_8({0xbc, 0x2a, 0x28, 0x86, 0x2c, 0xde, 0x8e, 0});
81 typedef Field<uint8_t, 8, 27, StatTable8, &SQR_TABLE_8, &SQR2_TABLE_8, &QRT_TABLE_8, &QRT_TABLE_8, &QRT_TABLE_8, &QRT_TABLE_8, IdTrans, &ID_TRANS, &ID_TRANS> Field8;
82 #endif
83 }
84 
85 Sketch* ConstructClMul1Byte(int bits, int implementation) {
86  switch (bits) {
87 #ifdef ENABLE_FIELD_INT_5
88  case 5: return new SketchImpl<Field5>(implementation, 5);
89 #endif
90 #ifdef ENABLE_FIELD_INT_8
91  case 8: return new SketchImpl<Field8>(implementation, 8);
92 #endif
93  }
94  return nullptr;
95 }
96 
97 Sketch* ConstructClMulTri1Byte(int bits, int implementation) {
98  switch (bits) {
99 #ifdef ENABLE_FIELD_INT_2
100  case 2: return new SketchImpl<FieldTri2>(implementation, 2);
101 #endif
102 #ifdef ENABLE_FIELD_INT_3
103  case 3: return new SketchImpl<FieldTri3>(implementation, 3);
104 #endif
105 #ifdef ENABLE_FIELD_INT_4
106  case 4: return new SketchImpl<FieldTri4>(implementation, 4);
107 #endif
108 #ifdef ENABLE_FIELD_INT_5
109  case 5: return new SketchImpl<FieldTri5>(implementation, 5);
110 #endif
111 #ifdef ENABLE_FIELD_INT_6
112  case 6: return new SketchImpl<FieldTri6>(implementation, 6);
113 #endif
114 #ifdef ENABLE_FIELD_INT_7
115  case 7: return new SketchImpl<FieldTri7>(implementation, 7);
116 #endif
117  }
118  return nullptr;
119 }
The identity transformation.
Definition: lintrans.h:141
A linear transformation constructed using LinTrans tables for sections of bits.
Definition: lintrans.h:107
Abstract class for internal representation of a minisketch object.
Definition: sketch.h:15
Sketch * ConstructClMul1Byte(int bits, int implementation)
Definition: clmul_1byte.cpp:85
Sketch * ConstructClMulTri1Byte(int bits, int implementation)
Definition: clmul_1byte.cpp:97
constexpr IdTrans ID_TRANS
A singleton for the identity transformation.
Definition: lintrans.h:148