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 Intel(R) EPID 1.1 group public key implementation.
20 */
21 #include "epid/common/1.1/src/grouppubkey.h"
22 #include "epid/common/src/memory.h"
23
24 /// Handle SDK Error with Break
25 #define BREAK_ON_EPID_ERROR(ret) \
26 \
27 if (kEpidNoErr != (ret)) { \
28 break; \
29 }
30
CreateEpid11GroupPubKey(Epid11GroupPubKey const * pub_key_str,EcGroup * G1,EcGroup * G2,Epid11GroupPubKey_ ** pub_key)31 EpidStatus CreateEpid11GroupPubKey(Epid11GroupPubKey const* pub_key_str,
32 EcGroup* G1, EcGroup* G2,
33 Epid11GroupPubKey_** pub_key) {
34 EpidStatus result = kEpidErr;
35 Epid11GroupPubKey_* pubkey = NULL;
36 if (!pub_key_str || !G1 || !G2 || !pub_key) {
37 return kEpidBadArgErr;
38 }
39 do {
40 pubkey = SAFE_ALLOC(sizeof(Epid11GroupPubKey_));
41 if (!pubkey) {
42 result = kEpidMemAllocErr;
43 break;
44 }
45 result = NewEcPoint(G1, &pubkey->h1);
46 BREAK_ON_EPID_ERROR(result);
47 result =
48 ReadEcPoint(G1, &pub_key_str->h1, sizeof(pub_key_str->h1), pubkey->h1);
49 BREAK_ON_EPID_ERROR(result);
50 result = NewEcPoint(G1, &pubkey->h2);
51 BREAK_ON_EPID_ERROR(result);
52 result =
53 ReadEcPoint(G1, &pub_key_str->h2, sizeof(pub_key_str->h2), pubkey->h2);
54 BREAK_ON_EPID_ERROR(result);
55 result = NewEcPoint(G2, &pubkey->w);
56 BREAK_ON_EPID_ERROR(result);
57 result =
58 ReadEcPoint(G2, &pub_key_str->w, sizeof(pub_key_str->w), pubkey->w);
59 BREAK_ON_EPID_ERROR(result);
60 pubkey->gid = pub_key_str->gid;
61 *pub_key = pubkey;
62 result = kEpidNoErr;
63 } while (0);
64
65 if (kEpidNoErr != result && pubkey) {
66 DeleteEcPoint(&pubkey->w);
67 DeleteEcPoint(&pubkey->h2);
68 DeleteEcPoint(&pubkey->h1);
69 SAFE_FREE(pubkey);
70 }
71 return result;
72 }
73
DeleteEpid11GroupPubKey(Epid11GroupPubKey_ ** pub_key)74 void DeleteEpid11GroupPubKey(Epid11GroupPubKey_** pub_key) {
75 if (pub_key && *pub_key) {
76 DeleteEcPoint(&(*pub_key)->w);
77 DeleteEcPoint(&(*pub_key)->h2);
78 DeleteEcPoint(&(*pub_key)->h1);
79
80 SAFE_FREE(*pub_key);
81 }
82 }
83