api.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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_MEMBER_API_H_
  17. #define EPID_MEMBER_API_H_
  18. #include <stddef.h>
  19. #include "epid/common/stdtypes.h"
  20. #include "epid/common/types.h"
  21. #include "epid/common/errors.h"
  22. #include "epid/common/bitsupplier.h"
  23. /*!
  24. * \file
  25. * \brief Intel(R) EPID SDK member API.
  26. */
  27. /// Member functionality
  28. /*!
  29. \defgroup EpidMemberModule member
  30. Defines the APIs needed by Intel(R) EPID members. Each member
  31. context (::MemberCtx) represents membership in a single group.
  32. \ingroup EpidModule
  33. @{
  34. */
  35. /// Internal context of member.
  36. typedef struct MemberCtx MemberCtx;
  37. /// Pre-computed member settings.
  38. /*!
  39. Serialized form of the information about a member that remains stable for
  40. a given set of keys.
  41. \note e12 = 0 implies that this data is not valid
  42. */
  43. #pragma pack(1)
  44. typedef struct MemberPrecomp {
  45. GtElemStr e12; ///< an element in GT
  46. GtElemStr e22; ///< an element in GT
  47. GtElemStr e2w; ///< an element in GT
  48. GtElemStr ea2; ///< an element in GT
  49. } MemberPrecomp;
  50. /// Pre-computed signature.
  51. /*!
  52. Serialized form of an intermediate signature that does not depend on
  53. basename or message. This can be used to time-shift compute time needed to
  54. sign a message.
  55. */
  56. typedef struct PreComputedSignature {
  57. G1ElemStr B; ///< an element in G1
  58. G1ElemStr K; ///< an element in G1
  59. G1ElemStr T; ///< an element in G1
  60. G1ElemStr R1; ///< an element in G1
  61. GtElemStr R2; ///< an element in G1
  62. FpElemStr a; ///< an integer between [0, p-1]
  63. FpElemStr b; ///< an integer between [0, p-1]
  64. FpElemStr rx; ///< an integer between [0, p-1]
  65. FpElemStr rf; ///< an integer between [0, p-1]
  66. FpElemStr ra; ///< an integer between [0, p-1]
  67. FpElemStr rb; ///< an integer between [0, p-1]
  68. } PreComputedSignature;
  69. #pragma pack()
  70. /// Creates a new member context.
  71. /*!
  72. Must be called to create the member context that is used by
  73. other "Member" APIs.
  74. Allocates memory for the context, then initializes it.
  75. EpidMemberDelete() must be called to safely release the member context.
  76. \param[in] pub_key
  77. The group certificate.
  78. \param[in] priv_key
  79. The member private key.
  80. \param[in] precomp
  81. Optional pre-computed data. If NULL the value is computed internally and is
  82. readable using EpidMemberWritePrecomp().
  83. \param[in] rnd_func
  84. Random number generator.
  85. \param[in] rnd_param
  86. Pass through context data for rnd_func.
  87. \param[out] ctx
  88. Newly constructed member context.
  89. \returns ::EpidStatus
  90. \warning
  91. For security rnd_func should be a cryptographically secure random
  92. number generator.
  93. \note
  94. If the result is not ::kEpidNoErr the content of ctx is undefined.
  95. \see EpidMemberDelete
  96. \see EpidMemberWritePrecomp
  97. */
  98. EpidStatus EpidMemberCreate(GroupPubKey const* pub_key, PrivKey const* priv_key,
  99. MemberPrecomp const* precomp, BitSupplier rnd_func,
  100. void* rnd_param, MemberCtx** ctx);
  101. /// Deletes an existing member context.
  102. /*!
  103. Must be called to safely release a member context created using
  104. EpidMemberCreate().
  105. De-initializes the context, frees memory used by the context, and sets the
  106. context pointer to NULL.
  107. \param[in,out] ctx
  108. The member context. Can be NULL.
  109. \see EpidMemberCreate
  110. */
  111. void EpidMemberDelete(MemberCtx** ctx);
  112. /// Serializes the pre-computed member settings.
  113. /*!
  114. \param[in] ctx
  115. The member context.
  116. \param[out] precomp
  117. The Serialized pre-computed member settings.
  118. \returns ::EpidStatus
  119. \note
  120. If the result is not ::kEpidNoErr, the content of precomp is undefined.
  121. */
  122. EpidStatus EpidMemberWritePrecomp(MemberCtx const* ctx, MemberPrecomp* precomp);
  123. /// Sets the hash algorithm to be used by a member.
  124. /*!
  125. \param[in] ctx
  126. The member context.
  127. \param[in] hash_alg
  128. The hash algorithm to use.
  129. \returns ::EpidStatus
  130. \note
  131. If the result is not ::kEpidNoErr, the hash algorithm used by the member is
  132. undefined.
  133. \see EpidMemberCreate
  134. \see ::HashAlg
  135. */
  136. EpidStatus EpidMemberSetHashAlg(MemberCtx* ctx, HashAlg hash_alg);
  137. /// Computes the size in bytes required for an Intel(R) EPID signature.
  138. /*!
  139. \param[in] sig_rl
  140. The signature based revocation list that is used. NULL is treated as
  141. a zero length list.
  142. \returns
  143. Size in bytes of an Intel(R) EPID signature including proofs for each entry
  144. in the signature based revocation list.
  145. \see ::SigRl
  146. */
  147. size_t EpidGetSigSize(SigRl const* sig_rl);
  148. /// Writes an Intel(R) EPID signature.
  149. /*!
  150. \param[in] ctx
  151. The member context.
  152. \param[in] msg
  153. The message to sign.
  154. \param[in] msg_len
  155. The length in bytes of message.
  156. \param[in] basename
  157. Optional basename. If basename is NULL a random basename is used.
  158. Signatures generated using random basenames are anonymous. Signatures
  159. generated using the same basename are linkable by the verifier. If a
  160. basename is provided, it must already be registered, or
  161. ::kEpidBadArgErr is returned.
  162. \param[in] basename_len
  163. The size of basename in bytes. Must be 0 basename is NULL.
  164. \param[in] sig_rl
  165. The signature based revocation list.
  166. \param[in] sig_rl_size
  167. The size in bytes of the signature based revocation list.
  168. \param[out] sig
  169. The generated signature
  170. \param[in] sig_len
  171. The size of signature in bytes. Must be equal to value returned by
  172. EpidGetSigSize().
  173. \returns ::EpidStatus
  174. \note
  175. If the result is not ::kEpidNoErr the content of sig is undefined.
  176. \see
  177. EpidMemberCreate
  178. \see
  179. EpidMemberSetHashAlg
  180. \see
  181. EpidGetSigSize
  182. */
  183. EpidStatus EpidSign(MemberCtx const* ctx, void const* msg, size_t msg_len,
  184. void const* basename, size_t basename_len,
  185. SigRl const* sig_rl, size_t sig_rl_size, EpidSignature* sig,
  186. size_t sig_len);
  187. /// Registers a basename with a member.
  188. /*!
  189. To prevent loss of privacy, the member keeps a list of basenames
  190. (corresponding to authorized verifiers). The member signs a message
  191. with a basename only if the basename is in the member's basename
  192. list.
  193. \warning
  194. The use of a name-based signature creates a platform unique
  195. pseudonymous identifier. Because it reduces the member's privacy, the
  196. user should be notified when it is used and should have control over
  197. its use.
  198. \param[in] ctx
  199. The member context.
  200. \param[in] basename
  201. The basename.
  202. \param[in] basename_len
  203. Length of the basename.
  204. \returns ::EpidStatus
  205. \retval ::kEpidDuplicateErr
  206. The basename was already registered.
  207. \note
  208. If the result is not ::kEpidNoErr or ::kEpidDuplicateErr it is undefined if the
  209. basename is registered.
  210. */
  211. EpidStatus EpidRegisterBaseName(MemberCtx* ctx, void const* basename,
  212. size_t basename_len);
  213. /// Extends the member's pool of pre-computed signatures.
  214. /*!
  215. Can either generate new pre-computed signatures or import existing ones.
  216. ::EpidWritePreSigs can be used to export pre-computed signatures.
  217. \param[in] ctx
  218. The member context.
  219. \param[in] number_presigs
  220. The number of pre-computed signatures to add to the internal pool.
  221. \param[in,out] presigs
  222. Optional array of valid pre-computed signatures to import. If presigs is not
  223. NULL it most contain at least number_presigs pre-computed signatures.
  224. \returns ::EpidStatus
  225. \note
  226. presigs buffer is zeroed out before return to prevent pre-computed
  227. signatures from being reused.
  228. \note
  229. If the result is not ::kEpidNoErr the state of the pre-computed signature
  230. pool, and of presigs, is undefined.
  231. \see ::EpidMemberCreate
  232. \see ::EpidWritePreSigs
  233. */
  234. EpidStatus EpidAddPreSigs(MemberCtx* ctx, size_t number_presigs,
  235. PreComputedSignature* presigs);
  236. /// Gets the number of pre-computed signatures in the member's pool.
  237. /*!
  238. \param[in] ctx
  239. The member context.
  240. \returns
  241. Number of remaining pre-computed signatures. Returns 0 if ctx is NULL.
  242. \see ::EpidMemberCreate
  243. \see ::EpidWritePreSigs
  244. */
  245. size_t EpidGetNumPreSigs(MemberCtx const* ctx);
  246. /// Serializes pre-computed signatures from the member's pool.
  247. /*!
  248. Removes requested number of pre-computed signatures from member's pool and
  249. stores them in presigs array. Use ::EpidAddPreSigs to add pre-computed
  250. signatures to the pool.
  251. \param[in] ctx
  252. The member context.
  253. \param[out] presigs
  254. An existing buffer of pre-computed signatures.
  255. \param[in] number_presigs
  256. Number of pre-computed signatures to read. Number_presigs must not be greater
  257. than the value returned by ::EpidGetNumPreSigs.
  258. \returns ::EpidStatus
  259. \note
  260. If the result is not ::kEpidNoErr the state of the pre-computed signature
  261. pool, and of presigs, is undefined.
  262. \see ::EpidMemberCreate
  263. \see ::EpidGetNumPreSigs
  264. \see ::EpidAddPreSigs
  265. */
  266. EpidStatus EpidWritePreSigs(MemberCtx* ctx, PreComputedSignature* presigs,
  267. size_t number_presigs);
  268. /// Creates a request to join a group.
  269. /*!
  270. The created request is part of the interaction with an issuer needed to join
  271. a group. This interaction with the issuer is outside the scope of this API.
  272. \param[in] pub_key
  273. The group certificate of group to join.
  274. \param[in] ni
  275. The nonce chosen by issuer as part of join protocol.
  276. \param[in] f
  277. A randomly selected integer in [1, p-1].
  278. \param[in] rnd_func
  279. Random number generator.
  280. \param[in] rnd_param
  281. Pass through context data for rnd_func.
  282. \param[in] hash_alg
  283. The hash algorithm to be used.
  284. \param[out] join_request
  285. The join request.
  286. \returns ::EpidStatus
  287. \warning
  288. For security rnd_func should be a cryptographically secure random
  289. number generator.
  290. \note
  291. The default hash algorithm in Member is SHA-512. This is the
  292. recommended option if you do not override the hash algorithm
  293. elsewhere.
  294. \note
  295. If the result is not ::kEpidNoErr, the content of join_request is undefined.
  296. \see ::HashAlg
  297. */
  298. EpidStatus EpidRequestJoin(GroupPubKey const* pub_key, IssuerNonce const* ni,
  299. FpElemStr const* f, BitSupplier rnd_func,
  300. void* rnd_param, HashAlg hash_alg,
  301. JoinRequest* join_request);
  302. /// Creates a basic signature for use in constrained environment.
  303. /*!
  304. Used in constrained environments where, due to limited memory, it may not
  305. be possible to process through a large and potentially unbounded revocation
  306. list.
  307. \param[in] ctx
  308. The member context.
  309. \param[in] msg
  310. The message.
  311. \param[in] msg_len
  312. The length of message in bytes.
  313. \param[in] basename
  314. Optional basename. If basename is NULL a random basename is used.
  315. Signatures generated using random basenames are anonymous. Signatures
  316. generated using the same basename are linkable by the verifier. If a
  317. basename is provided it must already be registered or
  318. ::kEpidBadArgErr is returned.
  319. \param[in] basename_len
  320. The size of basename in bytes. Must be 0 basename is NULL.
  321. \param[out] sig
  322. The generated basic signature
  323. \returns ::EpidStatus
  324. \note
  325. This function should be used in conjunction with EpidNrProve()
  326. \note
  327. If the result is not ::kEpidNoErr the content of sig, is undefined.
  328. \see EpidMemberCreate
  329. \see EpidNrProve
  330. */
  331. EpidStatus EpidSignBasic(MemberCtx const* ctx, void const* msg, size_t msg_len,
  332. void const* basename, size_t basename_len,
  333. BasicSignature* sig);
  334. /// Calculates a non-revoked proof for a single signature based revocation
  335. /// list entry.
  336. /*!
  337. Used in constrained environments where, due to limited memory, it may not
  338. be possible to process through a large and potentially unbounded revocation
  339. list.
  340. \param[in] ctx
  341. The member context.
  342. \param[in] msg
  343. The message.
  344. \param[in] msg_len
  345. The length of message in bytes.
  346. \param[in] sig
  347. The basic signature.
  348. \param[in] sigrl_entry
  349. The signature based revocation list entry.
  350. \param[out] proof
  351. The generated non-revoked proof.
  352. \returns ::EpidStatus
  353. \note
  354. This function should be used in conjunction with EpidSignBasic().
  355. \note
  356. If the result is not ::kEpidNoErr, the content of proof is undefined.
  357. \see EpidMemberCreate
  358. \see EpidSignBasic
  359. */
  360. EpidStatus EpidNrProve(MemberCtx const* ctx, void const* msg, size_t msg_len,
  361. BasicSignature const* sig, SigRlEntry const* sigrl_entry,
  362. NrProof* proof);
  363. /// Tests if a member private key is valid without checking revocation.
  364. /*!
  365. Used to check that a member private key is a valid key for a group. This
  366. is useful as a cross check when creating a new member private key as part of
  367. the join process
  368. \param[in] pub_key
  369. The public key of the group.
  370. \param[in] priv_key
  371. The private key to check.
  372. \result bool
  373. \retval true
  374. if the private key is valid for the group of the public key
  375. \retval false
  376. if the private key is not valid for the group of the public key
  377. \see EpidRequestJoin
  378. */
  379. bool EpidIsPrivKeyInGroup(GroupPubKey const* pub_key, PrivKey const* priv_key);
  380. /// Decompresses compressed member private key.
  381. /*!
  382. Converts a compressed member private key into a member
  383. private key for use by other member APIs.
  384. \param[in] pub_key
  385. The public key of the group.
  386. \param[in] compressed_privkey
  387. The compressed member private key to be decompressed.
  388. \param[out] priv_key
  389. The member private key.
  390. \returns ::EpidStatus
  391. */
  392. EpidStatus EpidDecompressPrivKey(GroupPubKey const* pub_key,
  393. CompressedPrivKey const* compressed_privkey,
  394. PrivKey* priv_key);
  395. /*! @} */
  396. #endif // EPID_MEMBER_API_H_