grouppubkey.c 2.5 KB

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