api.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /*############################################################################
  2. # Copyright 2016-2017 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. /// Intel(R) EPID SDK member API.
  17. /*! \file */
  18. #ifndef EPID_MEMBER_API_H_
  19. #define EPID_MEMBER_API_H_
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #include <stddef.h>
  24. #include "epid/common/bitsupplier.h"
  25. #include "epid/common/epiddefs.h"
  26. #include "epid/common/errors.h"
  27. #include "epid/common/types.h"
  28. /// Internal context of member.
  29. typedef struct MemberCtx MemberCtx;
  30. /// Implementation specific configuration parameters.
  31. typedef struct MemberParams MemberParams;
  32. /// Member functionality
  33. /*!
  34. \defgroup EpidMemberModule member
  35. Defines the APIs needed by Intel(R) EPID members. Each member
  36. context (::MemberCtx) represents membership in a single group.
  37. To use this module, include the header epid/member/api.h.
  38. \ingroup EpidModule
  39. @{
  40. */
  41. /// Allocates and initializes a new member context.
  42. /*!
  43. \param[in] params
  44. Implementation specific configuration parameters.
  45. \param[out] ctx
  46. Newly constructed member context.
  47. \warning buffers allocated using this function should not be
  48. initialized with ::EpidMemberInit.
  49. \deprecated This API has been superseded by ::EpidMemberGetSize
  50. and ::EpidMemberInit.
  51. \returns ::EpidStatus
  52. */
  53. EpidStatus EPID_API EpidMemberCreate(MemberParams const* params,
  54. MemberCtx** ctx);
  55. /// Computes the size in bytes required for a member context
  56. /*!
  57. \param[in] params
  58. Implementation specific configuration parameters.
  59. \param[out] context_size
  60. Number of bytes required for a ::MemberCtx buffer
  61. \returns ::EpidStatus
  62. \see EpidMemberInit
  63. */
  64. EpidStatus EPID_API EpidMemberGetSize(MemberParams const* params,
  65. size_t* context_size);
  66. /// Initializes a new member context.
  67. /*!
  68. \param[in] params
  69. Implementation specific configuration parameters.
  70. \param[in,out] ctx
  71. An existing buffer that will be used as a ::MemberCtx.
  72. \warning ctx must be a buffer of at least the size reported by
  73. ::EpidMemberGetSize for the same parameters.
  74. \returns ::EpidStatus
  75. \see EpidMemberGetSize
  76. */
  77. EpidStatus EPID_API EpidMemberInit(MemberParams const* params, MemberCtx* ctx);
  78. /// Creates a request to join a group.
  79. /*!
  80. The created request is part of the interaction with an issuer needed to join
  81. a group. This interaction with the issuer is outside the scope of this API.
  82. \param[in,out] ctx
  83. The member context.
  84. \param[in] pub_key
  85. The group certificate of group to join.
  86. \param[in] ni
  87. The nonce chosen by issuer as part of join protocol.
  88. \param[out] join_request
  89. The join request.
  90. \returns ::EpidStatus
  91. */
  92. EpidStatus EPID_API EpidCreateJoinRequest(MemberCtx* ctx,
  93. GroupPubKey const* pub_key,
  94. IssuerNonce const* ni,
  95. JoinRequest* join_request);
  96. /// Provisions a member context from a membership credential
  97. /*!
  98. \param[in,out] ctx
  99. The member context.
  100. \param[in] pub_key
  101. The group certificate of group to provision.
  102. \param[in] credential
  103. membership credential.
  104. \param[in] precomp_str
  105. Precomputed state (implementation specific optional)
  106. \returns ::EpidStatus
  107. */
  108. EpidStatus EPID_API EpidProvisionCredential(
  109. MemberCtx* ctx, GroupPubKey const* pub_key,
  110. MembershipCredential const* credential, MemberPrecomp const* precomp_str);
  111. /// Provisions a member context from a compressed private key
  112. /*!
  113. \param[in,out] ctx
  114. The member context.
  115. \param[in] pub_key
  116. The group certificate of group to provision.
  117. \param[in] compressed_privkey
  118. private key.
  119. \param[in] precomp_str
  120. Precomputed state (implementation specific optional)
  121. \returns ::EpidStatus
  122. */
  123. EpidStatus EPID_API
  124. EpidProvisionCompressed(MemberCtx* ctx, GroupPubKey const* pub_key,
  125. CompressedPrivKey const* compressed_privkey,
  126. MemberPrecomp const* precomp_str);
  127. /// Provisions a member context from a private key
  128. /*!
  129. \param[in,out] ctx
  130. The member context.
  131. \param[in] pub_key
  132. The group certificate of group to provision.
  133. \param[in] priv_key
  134. private key.
  135. \param[in] precomp_str
  136. Precomputed state (implementation specific optional)
  137. \returns ::EpidStatus
  138. */
  139. EpidStatus EPID_API EpidProvisionKey(MemberCtx* ctx, GroupPubKey const* pub_key,
  140. PrivKey const* priv_key,
  141. MemberPrecomp const* precomp_str);
  142. /// Change member from setup state to normal operation
  143. /*!
  144. \param[in,out] ctx
  145. The member context.
  146. \returns ::EpidStatus
  147. */
  148. EpidStatus EPID_API EpidMemberStartup(MemberCtx* ctx);
  149. /// De-initializes an existing member context buffer.
  150. /*!
  151. Must be called to safely release a member context initialized using
  152. ::EpidMemberInit.
  153. De-initializes the context.
  154. \param[in,out] ctx
  155. The member context. Can be NULL.
  156. \warning This function should not be used on buffers allocated with
  157. ::EpidMemberCreate. Those buffers should be released using ::EpidMemberDelete
  158. \see EpidMemberInit
  159. */
  160. void EPID_API EpidMemberDeinit(MemberCtx* ctx);
  161. /// Deletes an existing member context.
  162. /*!
  163. Must be called to safely release a member context created using
  164. ::EpidMemberCreate.
  165. De-initializes the context, frees memory used by the context, and sets the
  166. context pointer to NULL.
  167. \param[in,out] ctx
  168. The member context. Can be NULL.
  169. \deprecated This API has been superseded by ::EpidMemberDeinit.
  170. \see EpidMemberCreate
  171. \b Example
  172. \ref UserManual_GeneratingAnIntelEpidSignature
  173. */
  174. void EPID_API EpidMemberDelete(MemberCtx** ctx);
  175. /// Sets the hash algorithm to be used by a member.
  176. /*!
  177. \param[in] ctx
  178. The member context.
  179. \param[in] hash_alg
  180. The hash algorithm to use.
  181. \returns ::EpidStatus
  182. \note
  183. If the result is not ::kEpidNoErr, the hash algorithm used by the member is
  184. undefined.
  185. \see EpidMemberInit
  186. \see ::HashAlg
  187. \b Example
  188. \ref UserManual_GeneratingAnIntelEpidSignature
  189. */
  190. EpidStatus EPID_API EpidMemberSetHashAlg(MemberCtx* ctx, HashAlg hash_alg);
  191. /// Sets the signature based revocation list to be used by a member.
  192. /*!
  193. The caller is responsible for ensuring the revocation list is authorized,
  194. e.g. signed by the issuer. The caller is also responsible checking the version
  195. of the revocation list. The call fails if trying to set an older version
  196. of the revocation list than was last set.
  197. \attention
  198. The memory pointed to by sig_rl is accessed directly by the member
  199. until a new list is set or the member is destroyed. Do not modify the
  200. contents of this memory. The behavior of subsequent operations that rely on
  201. the revocation list is undefined if the memory is modified.
  202. \attention
  203. It is the responsibility of the caller to free the memory pointed to by sig_rl
  204. after the member is no longer using it.
  205. \param[in] ctx
  206. The member context.
  207. \param[in] sig_rl
  208. The signature based revocation list.
  209. \param[in] sig_rl_size
  210. The size of the signature based revocation list in bytes.
  211. \returns ::EpidStatus
  212. \note
  213. If the result is not ::kEpidNoErr the signature based revocation list pointed
  214. to by the member is not changed.
  215. \see EpidMemberInit
  216. \b Example
  217. \ref UserManual_GeneratingAnIntelEpidSignature
  218. */
  219. EpidStatus EPID_API EpidMemberSetSigRl(MemberCtx* ctx, SigRl const* sig_rl,
  220. size_t sig_rl_size);
  221. /// Computes the size in bytes required for an Intel(R) EPID signature.
  222. /*!
  223. \param[in] sig_rl
  224. The signature based revocation list that is used. NULL is treated as
  225. a zero length list.
  226. \returns
  227. Size in bytes of an Intel(R) EPID signature including proofs for each entry
  228. in the signature based revocation list.
  229. \see ::SigRl
  230. \b Example
  231. \ref UserManual_GeneratingAnIntelEpidSignature
  232. */
  233. size_t EPID_API EpidGetSigSize(SigRl const* sig_rl);
  234. /// Writes an Intel(R) EPID signature.
  235. /*!
  236. \param[in] ctx
  237. The member context.
  238. \param[in] msg
  239. The message to sign.
  240. \param[in] msg_len
  241. The length in bytes of message.
  242. \param[in] basename
  243. Optional basename. If basename is NULL a random basename is used.
  244. Signatures generated using random basenames are anonymous. Signatures
  245. generated using the same basename are linkable by the verifier. If a
  246. basename is provided, it must already be registered, or
  247. ::kEpidBadArgErr is returned.
  248. \param[in] basename_len
  249. The size of basename in bytes. Must be 0 if basename is NULL.
  250. \param[out] sig
  251. The generated signature
  252. \param[in] sig_len
  253. The size of signature in bytes. Must be equal to value returned by
  254. EpidGetSigSize().
  255. \returns ::EpidStatus
  256. \note
  257. If the result is not ::kEpidNoErr the content of sig is undefined.
  258. \see EpidMemberInit
  259. \see EpidMemberSetHashAlg
  260. \see EpidMemberSetSigRl
  261. \see EpidGetSigSize
  262. \b Example
  263. \ref UserManual_GeneratingAnIntelEpidSignature
  264. */
  265. EpidStatus EPID_API EpidSign(MemberCtx const* ctx, void const* msg,
  266. size_t msg_len, void const* basename,
  267. size_t basename_len, EpidSignature* sig,
  268. size_t sig_len);
  269. /// Registers a basename with a member.
  270. /*!
  271. To prevent loss of privacy, the member keeps a list of basenames
  272. (corresponding to authorized verifiers). The member signs a message
  273. with a basename only if the basename is in the member's basename
  274. list.
  275. \warning
  276. The use of a name-based signature creates a platform unique
  277. pseudonymous identifier. Because it reduces the member's privacy, the
  278. user should be notified when it is used and should have control over
  279. its use.
  280. \param[in] ctx
  281. The member context.
  282. \param[in] basename
  283. The basename.
  284. \param[in] basename_len
  285. Length of the basename.
  286. \returns ::EpidStatus
  287. \retval ::kEpidDuplicateErr
  288. The basename was already registered.
  289. \note
  290. If the result is not ::kEpidNoErr or ::kEpidDuplicateErr it is undefined if the
  291. basename is registered.
  292. \b Example
  293. \ref UserManual_GeneratingAnIntelEpidSignature
  294. */
  295. EpidStatus EPID_API EpidRegisterBasename(MemberCtx* ctx, void const* basename,
  296. size_t basename_len);
  297. /// Clears registered basenames.
  298. /*!
  299. Allows clearing registered basenames without recreating member.
  300. \param[in,out] ctx
  301. The member context.
  302. \returns ::EpidStatus
  303. \see ::EpidRegisterBasename
  304. */
  305. EpidStatus EPID_API EpidClearRegisteredBasenames(MemberCtx* ctx);
  306. /// Extends the member's pool of pre-computed signatures.
  307. /*!
  308. Generate new pre-computed signatures and add them to the internal pool.
  309. \param[in] ctx
  310. The member context.
  311. \param[in] number_presigs
  312. The number of pre-computed signatures to add to the internal pool.
  313. \returns ::EpidStatus
  314. \see ::EpidMemberInit
  315. */
  316. EpidStatus EPID_API EpidAddPreSigs(MemberCtx* ctx, size_t number_presigs);
  317. /// Gets the number of pre-computed signatures in the member's pool.
  318. /*!
  319. \param[in] ctx
  320. The member context.
  321. \returns
  322. Number of remaining pre-computed signatures. Returns 0 if ctx is NULL.
  323. \see ::EpidMemberInit
  324. */
  325. size_t EPID_API EpidGetNumPreSigs(MemberCtx const* ctx);
  326. /// Decompresses compressed member private key.
  327. /*!
  328. Converts a compressed member private key into a member
  329. private key for use by other member APIs.
  330. \param[in] pub_key
  331. The public key of the group.
  332. \param[in] compressed_privkey
  333. The compressed member private key to be decompressed.
  334. \param[out] priv_key
  335. The member private key.
  336. \returns ::EpidStatus
  337. \b Example
  338. \ref UserManual_GeneratingAnIntelEpidSignature
  339. */
  340. EpidStatus EPID_API EpidDecompressPrivKey(
  341. GroupPubKey const* pub_key, CompressedPrivKey const* compressed_privkey,
  342. PrivKey* priv_key);
  343. /*! @} */
  344. #ifdef __cplusplus
  345. }
  346. #endif
  347. #endif // EPID_MEMBER_API_H_