• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*############################################################################
2   # Copyright 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 /// Tiny portable implementations of standard library functions
17 /*! \file */
18 
19 #include "epid/member/tiny/src/serialize.h"
20 #include <stddef.h>
21 
22 #include "epid/common/types.h"
23 #include "epid/member/tiny/math/serialize.h"
24 #include "epid/member/tiny/src/native_types.h"
25 #include "epid/member/tiny/src/signbasic.h"
26 
BasicSignatureSerialize(BasicSignature * dest,NativeBasicSignature const * src)27 void* BasicSignatureSerialize(BasicSignature* dest,
28                               NativeBasicSignature const* src) {
29 #if defined(UNOPTIMIZED_SERIALIZATION)
30   EFqSerialize(&dest->B, &src->B);
31   EFqSerialize(&dest->K, &src->K);
32   EFqSerialize(&dest->T, &src->T);
33   FpSerialize(&dest->c, &src->c);
34   FpSerialize(&dest->sx, &src->sx);
35   FpSerialize(&dest->sf, &src->sf);
36   FpSerialize(&dest->sa, &src->sa);
37   FpSerialize(&dest->sb, &src->sb);
38   return dest + 1;
39 #else   // defined(UNOPTIMIZED_SERIALIZATION)
40   SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src));
41   return dest + 1;
42 #endif  // defined(UNOPTIMIZED_SERIALIZATION)
43 }
44 
BasicSignatureDeserialize(NativeBasicSignature * dest,BasicSignature const * src)45 void const* BasicSignatureDeserialize(NativeBasicSignature* dest,
46                                       BasicSignature const* src) {
47 #if defined(UNOPTIMIZED_SERIALIZATION)
48   EFqDeserialize(&dest->B, &src->B);
49   EFqDeserialize(&dest->K, &src->K);
50   EFqDeserialize(&dest->T, &src->T);
51   FpDeserialize(&dest->c, &src->c);
52   FpDeserialize(&dest->sx, &src->sx);
53   FpDeserialize(&dest->sf, &src->sf);
54   FpDeserialize(&dest->sa, &src->sa);
55   FpDeserialize(&dest->sb, &src->sb);
56   return src + 1;
57 #else   // defined(UNOPTIMIZED_SERIALIZATION)
58   SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src));
59   return src + 1;
60 #endif  // defined(UNOPTIMIZED_SERIALIZATION)
61 }
62 
GroupPubKeySerialize(GroupPubKey * dest,NativeGroupPubKey const * src)63 void* GroupPubKeySerialize(GroupPubKey* dest, NativeGroupPubKey const* src) {
64 #if defined(UNOPTIMIZED_SERIALIZATION)
65   EFqSerialize(&dest->h1, &src->h1);
66   EFqSerialize(&dest->h2, &src->h2);
67   EFq2Serialize(&dest->w, &src->w);
68   dest->gid = src->gid;
69   return dest + 1;
70 #else   // defined(UNOPTIMIZED_SERIALIZATION)
71   dest->gid = src->gid;
72   SwapNativeAndPortableLayout(
73       (uint8_t*)dest + sizeof(dest->gid), sizeof(*dest) - sizeof(dest->gid),
74       (uint8_t*)src + sizeof(src->gid), sizeof(*src) - sizeof(src->gid));
75   return dest + 1;
76 #endif  // defined(UNOPTIMIZED_SERIALIZATION)
77 }
78 
GroupPubKeyDeserialize(NativeGroupPubKey * dest,GroupPubKey const * src)79 void const* GroupPubKeyDeserialize(NativeGroupPubKey* dest,
80                                    GroupPubKey const* src) {
81 #if defined(UNOPTIMIZED_SERIALIZATION)
82   EFqDeserialize(&dest->h1, &src->h1);
83   EFqDeserialize(&dest->h2, &src->h2);
84   EFq2Deserialize(&dest->w, &src->w);
85   dest->gid = src->gid;
86   return src + 1;
87 #else   // defined(UNOPTIMIZED_SERIALIZATION)
88   dest->gid = src->gid;
89   SwapNativeAndPortableLayout(
90       (uint8_t*)dest + sizeof(dest->gid), sizeof(*dest) - sizeof(dest->gid),
91       (uint8_t*)src + sizeof(src->gid), sizeof(*src) - sizeof(src->gid));
92   return src + 1;
93 #endif  // defined(UNOPTIMIZED_SERIALIZATION)
94 }
95 
PrivKeyDeserialize(NativePrivKey * dest,PrivKey const * src)96 void const* PrivKeyDeserialize(NativePrivKey* dest, PrivKey const* src) {
97 #if defined(UNOPTIMIZED_SERIALIZATION)
98   EFqDeserialize(&dest->cred.A, &src->A);
99   FpDeserialize(&dest->cred.x, &src->x);
100   FpDeserialize(&dest->f, &src->f);
101   dest->cred.gid = src->gid;
102   return src + 1;
103 #else   // defined(UNOPTIMIZED_SERIALIZATION)
104   dest->cred.gid = src->gid;
105   SwapNativeAndPortableLayout((uint8_t*)dest + sizeof(dest->cred.gid),
106                               sizeof(*dest) - sizeof(dest->cred.gid),
107                               (uint8_t*)src + sizeof(src->gid),
108                               sizeof(*src) - sizeof(src->gid));
109   return src + 1;
110 #endif  // defined(UNOPTIMIZED_SERIALIZATION)
111 }
112 
PreCompDeserialize(NativeMemberPrecomp * dest,MemberPrecomp const * src)113 void const* PreCompDeserialize(NativeMemberPrecomp* dest,
114                                MemberPrecomp const* src) {
115 #if defined(UNOPTIMIZED_SERIALIZATION)
116   Fq12Deserialize(&dest->ea2, (Fq12ElemStr*)&src->ea2);
117   Fq12Deserialize(&dest->e12, (Fq12ElemStr*)&src->e12);
118   Fq12Deserialize(&dest->e22, (Fq12ElemStr*)&src->e22);
119   Fq12Deserialize(&dest->e2w, (Fq12ElemStr*)&src->e2w);
120   return src + 1;
121 #else   // defined(UNOPTIMIZED_SERIALIZATION)
122   SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src));
123   return src + 1;
124 #endif  // defined(UNOPTIMIZED_SERIALIZATION)
125 }
126 
MembershipCredentialDeserialize(NativeMembershipCredential * dest,MembershipCredential const * src)127 void const* MembershipCredentialDeserialize(NativeMembershipCredential* dest,
128                                             MembershipCredential const* src) {
129 #if defined(UNOPTIMIZED_SERIALIZATION)
130   EFqDeserialize(&dest->A, &src->A);
131   FpDeserialize(&dest->x, &src->x);
132   dest->gid = src->gid;
133   return src + 1;
134 #else   // defined(UNOPTIMIZED_SERIALIZATION)
135   dest->gid = src->gid;
136   SwapNativeAndPortableLayout(
137       (uint8_t*)dest + sizeof(dest->gid), sizeof(*dest) - sizeof(dest->gid),
138       (uint8_t*)src + sizeof(src->gid), sizeof(*src) - sizeof(src->gid));
139   return src + 1;
140 #endif  // defined(UNOPTIMIZED_SERIALIZATION)
141 }
142