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 /// Host signing helper implementation 17 /*! \file */ 18 19 #include "epid/member/src/sign_commitment.h" 20 21 #include "epid/common/math/ecgroup.h" 22 #include "epid/common/src/commitment.h" 23 24 /// Handle SDK Error with Break 25 #define BREAK_ON_EPID_ERROR(ret) \ 26 if (kEpidNoErr != (ret)) { \ 27 break; \ 28 } 29 30 EpidStatus HashSignCommitment(FiniteField* Fp, HashAlg hash_alg, 31 GroupPubKey const* pub_key, 32 SignCommitOutput const* commit_out, 33 void const* msg, size_t msg_len, 34 FpElemStr* c_str) { 35 EpidStatus sts = kEpidErr; 36 FfElement* c = NULL; 37 38 if (!Fp || !commit_out || (0 != msg_len && !msg) || !c_str) { 39 return kEpidBadArgErr; 40 } 41 42 do { 43 CommitValues values = {0}; 44 sts = SetKeySpecificCommitValues(pub_key, &values); 45 BREAK_ON_EPID_ERROR(sts); 46 47 values.B = commit_out->B; 48 values.K = commit_out->K; 49 values.T = commit_out->T; 50 values.R1 = commit_out->R1; 51 values.R2 = commit_out->R2; 52 53 sts = NewFfElement(Fp, &c); 54 BREAK_ON_EPID_ERROR(sts); 55 56 // 5. The member computes t3 = Fp.hash(p || g1 || g2 || h1 || h2 57 // || w || B || K || T || R1 || R2). 58 // 6. The member computes c = Fp.hash(t3 || m). 59 sts = CalculateCommitmentHash(&values, Fp, hash_alg, msg, msg_len, c); 60 BREAK_ON_EPID_ERROR(sts); 61 62 sts = WriteFfElement(Fp, c, c_str, sizeof(*c_str)); 63 BREAK_ON_EPID_ERROR(sts); 64 65 sts = kEpidNoErr; 66 } while (0); 67 68 DeleteFfElement(&c); 69 70 return sts; 71 } 72