1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*############################################################################
# Copyright 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
############################################################################*/
/*!
* \file
* \brief Group public key implementation.
*/
#include "epid/common/grouppubkey.h"
#include "epid/common/memory.h"
EpidStatus CreateGroupPubKey(GroupPubKey const* pub_key_str, EcGroup* G1,
EcGroup* G2, GroupPubKey_** pub_key) {
EpidStatus result = kEpidErr;
GroupPubKey_* pubkey = NULL;
if (!pub_key_str || !G1 || !G2 || !pub_key) {
return kEpidBadArgErr;
}
do {
pubkey = SAFE_ALLOC(sizeof(GroupPubKey_));
if (!pubkey) {
result = kEpidMemAllocErr;
break;
}
result = NewEcPoint(G1, &pubkey->h1);
if (kEpidNoErr != result) {
break;
}
result =
ReadEcPoint(G1, &pub_key_str->h1, sizeof(pub_key_str->h1), pubkey->h1);
if (kEpidNoErr != result) {
break;
}
result = NewEcPoint(G1, &pubkey->h2);
if (kEpidNoErr != result) {
break;
}
result =
ReadEcPoint(G1, &pub_key_str->h2, sizeof(pub_key_str->h2), pubkey->h2);
if (kEpidNoErr != result) {
break;
}
result = NewEcPoint(G2, &pubkey->w);
if (kEpidNoErr != result) {
break;
}
result =
ReadEcPoint(G2, &pub_key_str->w, sizeof(pub_key_str->w), pubkey->w);
if (kEpidNoErr != result) {
break;
}
pubkey->gid = pub_key_str->gid;
*pub_key = pubkey;
result = kEpidNoErr;
} while (0);
if (kEpidNoErr != result && pubkey) {
DeleteEcPoint(&pubkey->w);
DeleteEcPoint(&pubkey->h2);
DeleteEcPoint(&pubkey->h1);
SAFE_FREE(pubkey);
}
return result;
}
void DeleteGroupPubKey(GroupPubKey_** pub_key) {
if (pub_key && *pub_key) {
DeleteEcPoint(&(*pub_key)->w);
DeleteEcPoint(&(*pub_key)->h2);
DeleteEcPoint(&(*pub_key)->h1);
SAFE_FREE(*pub_key);
}
}
|