• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*############################################################################
2   # Copyright 2016 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 Group public key implementation.
20  */
21 #include "epid/common/src/grouppubkey.h"
22 #include "epid/common/src/memory.h"
23 
CreateGroupPubKey(GroupPubKey const * pub_key_str,EcGroup * G1,EcGroup * G2,GroupPubKey_ ** pub_key)24 EpidStatus CreateGroupPubKey(GroupPubKey const* pub_key_str, EcGroup* G1,
25                              EcGroup* G2, GroupPubKey_** pub_key) {
26   EpidStatus result = kEpidErr;
27   GroupPubKey_* pubkey = NULL;
28   if (!pub_key_str || !G1 || !G2 || !pub_key) {
29     return kEpidBadArgErr;
30   }
31   do {
32     pubkey = SAFE_ALLOC(sizeof(GroupPubKey_));
33     if (!pubkey) {
34       result = kEpidMemAllocErr;
35       break;
36     }
37     result = NewEcPoint(G1, &pubkey->h1);
38     if (kEpidNoErr != result) {
39       break;
40     }
41     result =
42         ReadEcPoint(G1, &pub_key_str->h1, sizeof(pub_key_str->h1), pubkey->h1);
43     if (kEpidNoErr != result) {
44       break;
45     }
46     result = NewEcPoint(G1, &pubkey->h2);
47     if (kEpidNoErr != result) {
48       break;
49     }
50     result =
51         ReadEcPoint(G1, &pub_key_str->h2, sizeof(pub_key_str->h2), pubkey->h2);
52     if (kEpidNoErr != result) {
53       break;
54     }
55     result = NewEcPoint(G2, &pubkey->w);
56     if (kEpidNoErr != result) {
57       break;
58     }
59     result =
60         ReadEcPoint(G2, &pub_key_str->w, sizeof(pub_key_str->w), pubkey->w);
61     if (kEpidNoErr != result) {
62       break;
63     }
64     pubkey->gid = pub_key_str->gid;
65     *pub_key = pubkey;
66     result = kEpidNoErr;
67   } while (0);
68 
69   if (kEpidNoErr != result && pubkey) {
70     DeleteEcPoint(&pubkey->w);
71     DeleteEcPoint(&pubkey->h2);
72     DeleteEcPoint(&pubkey->h1);
73     SAFE_FREE(pubkey);
74   }
75   return result;
76 }
77 
DeleteGroupPubKey(GroupPubKey_ ** pub_key)78 void DeleteGroupPubKey(GroupPubKey_** pub_key) {
79   if (pub_key && *pub_key) {
80     DeleteEcPoint(&(*pub_key)->w);
81     DeleteEcPoint(&(*pub_key)->h2);
82     DeleteEcPoint(&(*pub_key)->h1);
83 
84     SAFE_FREE(*pub_key);
85   }
86 }
87