1 /*############################################################################
2   # Copyright 2016-2017 Intel Corporation
3   #
4   # Licensed under the Apache License, Version 2.0 (the "License");
5   # you may not use this file except in compliance with the License.
6   # You may obtain a copy of the License at
7   #
8   #     http://www.apache.org/licenses/LICENSE-2.0
9   #
10   # Unless required by applicable law or agreed to in writing, software
11   # distributed under the License is distributed on an "AS IS" BASIS,
12   # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   # See the License for the specific language governing permissions and
14   # limitations under the License.
15   ############################################################################*/
16 
17 /*!
18  * \file
19  * \brief FfElement C++ wrapper interface.
20  */
21 #ifndef EPID_COMMON_TESTHELPER_FFELEMENT_WRAPPER_TESTHELPER_H_
22 #define EPID_COMMON_TESTHELPER_FFELEMENT_WRAPPER_TESTHELPER_H_
23 
24 #include <memory>
25 #include <vector>
26 
27 extern "C" {
28 #include "epid/common/1.1/types.h"
29 #include "epid/common/math/bignum.h"
30 #include "epid/common/math/finitefield.h"
31 }
32 
33 class FiniteFieldObj;
34 
35 /*!
36 Wrapper class to provide Resource Allocation is Initialization handling
37 for FfElement
38 */
39 class FfElementObj {
40  public:
41   /// constructor
42   FfElementObj();
43   /// copy constructor
44   FfElementObj(FfElementObj const& other);
45   /// assignment operator
46   FfElementObj& operator=(FfElementObj const& other);
47   /// Create a FfElement
48   explicit FfElementObj(FiniteFieldObj* ff);
49   /// Create a FfElement
50   FfElementObj(FiniteFieldObj* ff, FpElemStr const& bytes);
51   /// Create a FfElement
52   FfElementObj(FiniteFieldObj* ff, FqElemStr const& bytes);
53   /// Create a FfElement
54   FfElementObj(FiniteFieldObj* ff, Fq2ElemStr const& bytes);
55   /// Create a FfElement
56   FfElementObj(FiniteFieldObj* ff, Fq3ElemStr const& bytes);
57   /// Create a FfElement
58   FfElementObj(FiniteFieldObj* ff, Fq6ElemStr const& bytes);
59   /// Create a FfElement
60   FfElementObj(FiniteFieldObj* ff, Fq12ElemStr const& bytes);
61   /// Create a FfElement
62   FfElementObj(FiniteFieldObj* ff, std::vector<unsigned char> const& bytes);
63   /// Create a FfElement
64   FfElementObj(FiniteFieldObj* ff, void const* bytes, size_t size);
65   /// Destroy the FfElement
66   ~FfElementObj();
67   /// cast operator to get the pointer to the stored FfElement
68   operator FfElement*();
69   /// const cast operator to get the pointer to the stored FfElement
70   operator const FfElement*() const;
71   /// Get the underlying pointer
72   FfElement* get();
73   /// Get the underlying pointer
74   FfElement const* getc() const;
75   /// Get element bytes
76   std::vector<unsigned char> data() const;
77 
78  private:
79   void init(FiniteFieldObj* ff, unsigned char const* bytes, size_t size);
80   struct State;
81   std::unique_ptr<State> state_;
82 };
83 
84 #endif  // EPID_COMMON_TESTHELPER_FFELEMENT_WRAPPER_TESTHELPER_H_
85