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 SigRl validity checking implementation.
20 */
21
22 #include <string.h>
23
24 #include "epid/common/src/endian_convert.h"
25 #include "epid/common/src/sigrlvalid.h"
26
IsSigRlValid(GroupId const * gid,SigRl const * sig_rl,size_t sig_rl_size)27 bool IsSigRlValid(GroupId const* gid, SigRl const* sig_rl, size_t sig_rl_size) {
28 const size_t kMinSigRlSize = sizeof(SigRl) - sizeof(SigRlEntry);
29 size_t input_sig_rl_size = 0;
30 if (!gid || !sig_rl || kMinSigRlSize > sig_rl_size) {
31 return false;
32 }
33 if (ntohl(sig_rl->n2) > (SIZE_MAX - kMinSigRlSize) / sizeof(sig_rl->bk[0])) {
34 return false;
35 }
36 // sanity check of intput SigRl size
37 input_sig_rl_size = kMinSigRlSize + ntohl(sig_rl->n2) * sizeof(sig_rl->bk[0]);
38 if (input_sig_rl_size != sig_rl_size) {
39 return false;
40 }
41 // verify that gid given and gid in SigRl match
42 if (0 != memcmp(gid, &sig_rl->gid, sizeof(*gid))) {
43 return false;
44 }
45 return true;
46 }
47