1 // @file be4-poly-impl.cpp This file contains template instantiations for all
2 // classes using math be4
3 // @author TPOC: contact@palisade-crypto.org
4 //
5 // @copyright Copyright (c) 2019, New Jersey Institute of Technology (NJIT)
6 // All rights reserved.
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 // 1. Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution. THIS SOFTWARE IS
14 // PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
15 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17 // EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 #include "lattice/backend.h"
26 #include "math/backend.h"
27 #include "math/matrix.cpp"
28 #include "matrix-lattice-impl.cpp"
29 
30 #include "elemparams.cpp"
31 #include "ilparams.cpp"
32 #include "poly.cpp"
33 
34 namespace lbcrypto {
35 
36 template class ElemParams<M4Integer>;
37 template class ILParamsImpl<M4Integer>;
38 template class PolyImpl<M4Vector>;
39 // template class DCRTPolyImpl<M4Vector>;
40 
41 template class Matrix<M4Poly>;
42 ONES_FOR_TYPE(M4Poly)
43 IDENTITY_FOR_TYPE(M4Poly)
44 GADGET_FOR_TYPE(M4Poly)
45 NORM_FOR_TYPE(M4Poly)
46 SPLIT64_FOR_TYPE(M4Poly)
47 SPLIT64ALT_FOR_TYPE(M4Poly)
48 SPLIT32ALT_FOR_TYPE(M4Poly)
49 template Matrix<M4Vector> RotateVecResult(Matrix<M4Poly> const& inMat);
50 template Matrix<M4Integer> Rotate(Matrix<M4Poly> const& inMat);
51 
52 template class Matrix<M4DCRTPoly>;
53 ONES_FOR_TYPE(M4DCRTPoly)
54 IDENTITY_FOR_TYPE(M4DCRTPoly)
55 GADGET_FOR_TYPE_DCRT(M4DCRTPoly)
56 NORM_FOR_TYPE(M4DCRTPoly)
57 SPLIT64_FOR_TYPE(M4DCRTPoly)
58 SPLIT64ALT_FOR_TYPE(M4DCRTPoly)
59 SPLIT32ALT_FOR_TYPE(M4DCRTPoly)
60 template Matrix<M4Vector> RotateVecResult(Matrix<M4DCRTPoly> const& inMat);
61 template Matrix<M4Integer> Rotate(Matrix<M4DCRTPoly> const& inMat);
62 
63 // biginteger version
64 template <>
ToNativePoly() const65 PolyImpl<NativeVector> PolyImpl<M4Vector>::ToNativePoly() const {
66   PolyImpl<NativeVector> interp(
67       std::make_shared<ILParamsImpl<NativeInteger>>(
68           this->GetCyclotomicOrder(), std::numeric_limits<uint64_t>::max(), 1),
69       this->GetFormat(), true);
70 
71   for (usint i = 0; i < this->GetLength(); i++) {
72     interp[i] = (*this)[i].ConvertToInt();
73   }
74 
75   return interp;
76 }
77 
78 }  // namespace lbcrypto
79 
80 CEREAL_CLASS_VERSION(lbcrypto::M4Poly, lbcrypto::M4Poly::SerializedVersion());
81 CEREAL_CLASS_VERSION(lbcrypto::M4DCRTPoly,
82                      lbcrypto::M4DCRTPoly::SerializedVersion());
83