epid_types.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. #ifndef EPID_COMMON_TYPES_H_
  17. #define EPID_COMMON_TYPES_H_
  18. #include <limits.h> // for CHAR_BIT
  19. /*!
  20. * \file
  21. * \brief SDK data types.
  22. * \defgroup EpidTypes types
  23. * \ingroup EpidCommon
  24. * @{
  25. */
  26. /// Recognized hash algorithms
  27. typedef enum {
  28. /// SHA-256
  29. kSha256 = 0,
  30. /// SHA-384
  31. kSha384 = 1,
  32. /// SHA-512
  33. kSha512 = 2,
  34. /// SHA-512/256
  35. kSha512_256 = 3,
  36. /// Reserved for SHA3/256
  37. kSha3_256 = 4,
  38. /// Reserved for SHA3/384
  39. kSha3_384 = 5,
  40. /// Reserved for SHA3/512
  41. kSha3_512 = 6,
  42. } HashAlg;
  43. #pragma pack(1)
  44. /// 8 bit octet string
  45. typedef struct OctStr8 {
  46. unsigned char data[8 / CHAR_BIT]; ///< 8 bit data
  47. } OctStr8;
  48. /// 32 bit octet string
  49. typedef struct OctStr32 {
  50. unsigned char data[32 / CHAR_BIT]; ///< 32 bit data
  51. } OctStr32;
  52. /// 64 bit octet string
  53. typedef struct OctStr64 {
  54. unsigned char data[64 / CHAR_BIT]; ///< 64 bit data
  55. } OctStr64;
  56. /// 128 bit octet string
  57. typedef struct OctStr128 {
  58. unsigned char data[128 / CHAR_BIT]; ///< 128 bit data
  59. } OctStr128;
  60. /// 256 bit octet string
  61. typedef struct OctStr256 {
  62. unsigned char data[256 / CHAR_BIT]; ///< 256 bit data
  63. } OctStr256;
  64. /// Serialized BigNum
  65. typedef struct BigNumStr {
  66. OctStr256 data; ///< 256 bit octet string
  67. } BigNumStr;
  68. /// a number in [0, p-1]
  69. typedef struct FpElemStr {
  70. OctStr256 data; ///< 256 bit octet string
  71. } FpElemStr;
  72. /// a number in [0, q-1]
  73. typedef struct FqElemStr {
  74. OctStr256 data; ///< 256 bit octet string
  75. } FqElemStr;
  76. /// Serialized G1 element
  77. typedef struct G1ElemStr {
  78. FqElemStr x; ///< an integer between [0, q-1]
  79. FqElemStr y; ///< an integer between [0, q-1]
  80. } G1ElemStr;
  81. /// Serialized G2 element
  82. typedef struct G2ElemStr {
  83. FqElemStr x[2]; ///< an integer between [0, q-1]
  84. FqElemStr y[2]; ///< an integer between [0, q-1]
  85. } G2ElemStr;
  86. /// Serialized GT element
  87. typedef struct GTElemStr {
  88. FqElemStr x[12]; ///< an integer between [0, q-1]
  89. } GTElemStr;
  90. typedef FpElemStr PElemStr;
  91. typedef OctStr32 RLver_t;
  92. typedef OctStr32 RLCount;
  93. /// Intel(R) EPID 2.0 Parameters.
  94. /*!
  95. * INTEL(R) EPID 2.0 parameters: (p, q, b, t, neg, beta, xi0, xi1,
  96. * g1, g2)
  97. */
  98. typedef struct Epid2Params {
  99. BigNumStr p; ///< a prime
  100. BigNumStr q; ///< a prime
  101. FqElemStr b; ///< an integer between [0, q-1]
  102. OctStr64 t; ///< an integer
  103. OctStr8 neg; ///< a boolean
  104. FqElemStr beta; ///< an integer between [0, q-1]
  105. FqElemStr xi[2]; ///< array of integers between [0, q-1]
  106. G1ElemStr g1; ///< a generator (an element) of G1
  107. G2ElemStr g2; ///< a generator (an element) of G2
  108. } EPID2Params;
  109. /// group ID
  110. typedef OctStr32 GroupID;
  111. /// Intel(R) EPID 2.0 group public key
  112. /*!
  113. * Group public key: (gid, h1, h2, w)
  114. */
  115. typedef struct GroupPubKey {
  116. GroupID gid; ///< group ID
  117. G1ElemStr h1; ///< an element in G1
  118. G1ElemStr h2; ///< an element in G1
  119. G2ElemStr w; ///< an element in G2
  120. } GroupPubKey;
  121. /// Intel(R) EPID 2.0 issuing private key
  122. /*!
  123. * Issuing private key: (gid, gamma)
  124. */
  125. typedef struct IPrivKey {
  126. GroupID gid; ///< group ID
  127. FpElemStr gamma; ///< an integer between [0, p-1]
  128. } IPrivKey;
  129. /// Intel(R) EPID 2.0 private key
  130. /*!
  131. * Private key: (gid, A, x, f)
  132. */
  133. typedef struct PrivKey {
  134. GroupID gid; ///< group ID
  135. G1ElemStr A; ///< an element in G1
  136. FpElemStr x; ///< an integer between [0, p-1]
  137. FpElemStr f; ///< an integer between [0, p-1]
  138. } PrivKey;
  139. /// 256 bit seed derived from fuse key
  140. typedef OctStr256 Seed;
  141. /// Compressed private key
  142. /*!
  143. * Compressed Private key: (gid, A.x, seed)
  144. */
  145. typedef struct CompressedPrivKey {
  146. GroupID gid; ///< group ID
  147. FqElemStr ax; ///< an integer between [0, p-1]
  148. Seed seed; ///< 256 bit rekey seed
  149. } CompressedPrivKey;
  150. /// Membership credential
  151. /*!
  152. * Membership credential: (gid, A, x)
  153. */
  154. typedef struct MembershipCredential {
  155. GroupID gid; ///< group ID
  156. G1ElemStr A; ///< an element in G1
  157. FpElemStr x; ///< an integer between [0, p-1]
  158. } MembershipCredential;
  159. /// 256 bit nonce chosen by issuer
  160. typedef OctStr256 IssuerNonce;
  161. /// Join request
  162. /*!
  163. * Join request: (F, c, s)
  164. */
  165. typedef struct JoinRequest {
  166. G1ElemStr F; ///< an element in G1
  167. FpElemStr c; ///< an integer between [0, p-1]
  168. FpElemStr s; ///< an integer between [0, p-1]
  169. } JoinRequest;
  170. ////////////////////////
  171. /// Intel(R) EPID 2.0 basic signature.
  172. /*!
  173. * Basic signature: (B, K, T, c, sx, sf, sa, sb)
  174. */
  175. typedef struct BasicSignature {
  176. G1ElemStr B; ///< an element in G1
  177. G1ElemStr K; ///< an element in G1
  178. G1ElemStr T; ///< an element in G1
  179. FpElemStr c; ///< an integer between [0, p-1]
  180. FpElemStr sx; ///< an integer between [0, p-1]
  181. FpElemStr sf; ///< an integer between [0, p-1]
  182. FpElemStr sa; ///< an integer between [0, p-1]
  183. FpElemStr sb; ///< an integer between [0, p-1]
  184. } BasicSignature;
  185. ///
  186. /*!
  187. * \brief
  188. * non-revoked Proof.
  189. *
  190. * Non-revoked Proof: (T, c, smu, snu)
  191. */
  192. typedef struct NrProof {
  193. G1ElemStr T; ///< an element in G1
  194. FpElemStr c; ///< an integer between [0, p-1]
  195. FpElemStr smu; ///< an integer between [0, p-1]
  196. FpElemStr snu; ///< an integer between [0, p-1]
  197. } NRProof;
  198. /// Intel(R) EPID 2.0 Signature
  199. /*!
  200. * Signature: (sigma0, RLver, n2, sigma[0], ..., sigma[n2-1])
  201. */
  202. typedef struct EpidSignature {
  203. BasicSignature sigma0; ///< basic signature
  204. OctStr32 rl_ver; ///< revocation list version number
  205. OctStr32 n2; ///< number of entries in SigRL
  206. NRProof sigma[1]; ///< array of non-revoked proofs (flexible array)
  207. } EPIDSignature;
  208. /// private-key based revocation list.
  209. /*!
  210. * Private-key based revocation list PrivRL: (gid, RLver, n1, f[0],
  211. * ..., f[n1-1])
  212. */
  213. typedef struct PrivRl {
  214. GroupID gid; ///< group ID
  215. OctStr32 version; ///< revocation list version number
  216. OctStr32 n1; ///< number of entries in PrivRL
  217. FpElemStr f[1]; ///< integers between [1, p-1] (flexible array)
  218. } PrivRl;
  219. /// entry in SigRL (B,K)
  220. typedef struct SigRlEntry {
  221. G1ElemStr b; ///< an element of G1
  222. G1ElemStr k; ///< an element of G1
  223. } SigRLEntry;
  224. /// signature based revocation list
  225. /*!
  226. * Signature based revocation list SigRL: (gid, RLver, n2, B[0],
  227. * K[0], ..., B[n2-1], K[n2-1])
  228. */
  229. typedef struct SigRl {
  230. GroupID gid; ///< group ID
  231. OctStr32 RLver; ///< revocation list version number
  232. OctStr32 n2; ///< number of entries in SigRL
  233. SigRLEntry BK[1]; ///< revoked Bs and Ks (flexible array)
  234. } SigRL;
  235. /// group revocation list
  236. /*!
  237. * Group revocation list GroupRL: (RLver, n3, gid[0], ...,
  238. * gid[n3-1])
  239. */
  240. typedef struct GroupRl {
  241. OctStr32 version; ///< revocation list version number
  242. OctStr32 n3; ///< number of entries in GroupRL
  243. GroupID gid[1]; ///< revoked group IDs (flexible array)
  244. } GroupRl;
  245. /*! verifier revocation list
  246. * Verifier revocation list VerifierRL: (gid, B, RLver, n4, K[0],
  247. * ..., K[n4-1])
  248. */
  249. typedef struct VerifierRl {
  250. GroupID gid; ///< group ID
  251. G1ElemStr B; ///< an element in G1
  252. OctStr32 version; ///< revocation list version number
  253. OctStr32 n4; ///< number of entries in VerifierRL
  254. G1ElemStr K[1]; ///< elements in G1 (flexible array)
  255. } VerifierRl;
  256. /*!
  257. * \brief
  258. * member pre-computation blob
  259. *
  260. * \note e12 = 0 implies that this blob is not valid
  261. */
  262. typedef struct _MemberPrecomp {
  263. GTElemStr e12; ///< an element in GT
  264. GTElemStr e22; ///< an element in GT
  265. GTElemStr e2w; ///< an element in GT
  266. GTElemStr ea2; ///< an element in GT
  267. } MemberPrecomp;
  268. /*!
  269. * \brief
  270. * verifier pre-computation blob
  271. *
  272. * \note e12 = 0 implies that this blob is not valid
  273. */
  274. typedef struct _VerifierPrecomp {
  275. GTElemStr e12; ///< an element in GT
  276. GTElemStr e22; ///< an element in GT
  277. GTElemStr e2w; ///< an element in GT
  278. GTElemStr eg12; ///< an element in GT
  279. } VerifierPrecomp;
  280. /// element to store seed values for later rekey
  281. typedef G1ElemStr ReKeySeed;
  282. /// Serialized Fq2 element
  283. typedef struct Fq2ElemStr {
  284. FqElemStr a[2]; ///< polynomial coefficient
  285. } Fq2ElemStr;
  286. /// Serialized Fq2^3 element
  287. typedef struct Fq6ElemStr {
  288. Fq2ElemStr a[3]; ///< polynomial coefficient
  289. } Fq6ElemStr;
  290. /// Serialized Fq2^3^2 element
  291. typedef struct Fq12ElemStr {
  292. Fq6ElemStr a[2]; ///< polynomial coefficient
  293. } Fq12ElemStr;
  294. #pragma pack()
  295. /*! @} */
  296. #endif // EPID_COMMON_TYPES_H_