types.h 9.3 KB

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