sigrlvalid.c 1.6 KB

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