api.h 14 KB

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