api.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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_VERIFIER_API_H_
  17. #define EPID_VERIFIER_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. /*!
  23. * \file
  24. * \brief Intel(R) EPID SDK verifier API.
  25. */
  26. /// Verifier functionality
  27. /*!
  28. \defgroup EpidVerifierModule verifier
  29. Defines the APIs needed by Intel(R) EPID verifiers. Each verifier
  30. context (::VerifierCtx) represents a verifier for a single group.
  31. \ingroup EpidModule
  32. @{
  33. */
  34. /// Internal context of verifier.
  35. typedef struct VerifierCtx VerifierCtx;
  36. /// Pre-computed verifier settings.
  37. /*!
  38. Serialized form of the information about a verifier that remains stable for
  39. a given set of keys.
  40. \note e12 = 0 implies that this data is not valid
  41. */
  42. #pragma pack(1)
  43. typedef struct VerifierPrecomp {
  44. GroupId gid; ///< group ID
  45. GtElemStr e12; ///< an element in GT
  46. GtElemStr e22; ///< an element in GT
  47. GtElemStr e2w; ///< an element in GT
  48. GtElemStr eg12; ///< an element in GT
  49. } VerifierPrecomp;
  50. #pragma pack()
  51. /// Creates a new verifier context.
  52. /*!
  53. Must be called to create the verifier context that is used by
  54. other "Verifier" APIs.
  55. Allocates memory for the context, then initializes it.
  56. EpidVerifierDelete() must be called to safely release the member context.
  57. \param[in] pub_key
  58. The group certificate.
  59. \param[in] precomp
  60. Optional pre-computed data. If NULL the value is computed internally and is
  61. readable using EpidVerifierWritePrecomp().
  62. \param[out] ctx
  63. Newly constructed verifier context.
  64. \returns ::EpidStatus
  65. \note
  66. If the result is not ::kEpidNoErr the content of ctx is undefined.
  67. \see EpidVerifierDelete
  68. \see EpidVerifierWritePrecomp
  69. */
  70. EpidStatus EpidVerifierCreate(GroupPubKey const* pub_key,
  71. VerifierPrecomp const* precomp,
  72. VerifierCtx** ctx);
  73. /// Deletes an existing verifier context.
  74. /*!
  75. Must be called to safely release a verifier context created using
  76. EpidVerifierCreate().
  77. De-initializes the context, frees memory used by the context, and sets the
  78. context pointer to NULL.
  79. \param[in,out] ctx
  80. The verifier context. Can be NULL.
  81. \see EpidVerifierCreate
  82. */
  83. void EpidVerifierDelete(VerifierCtx** ctx);
  84. /// Serializes the pre-computed verifier settings.
  85. /*!
  86. \param[in] ctx
  87. The verifier context.
  88. \param[out] precomp
  89. The Serialized pre-computed verifier settings.
  90. \returns ::EpidStatus
  91. \note
  92. If the result is not ::kEpidNoErr the content of precomp is undefined.
  93. */
  94. EpidStatus EpidVerifierWritePrecomp(VerifierCtx const* ctx,
  95. VerifierPrecomp* precomp);
  96. /// Sets the private key based revocation list.
  97. /*!
  98. The caller is responsible for ensuring the revocation list is authorized,
  99. e.g signed by the issuer. The caller is also responsible checking the version
  100. of the revocation list. The call fails if trying to set an older version
  101. of the revocation list than was last set.
  102. \attention
  103. The memory pointed to by priv_rl is accessed directly by the verifier
  104. until a new list is set or the verifier is destroyed. Do not modify the
  105. contents of this memory. The behavior of subsequent operations that rely on
  106. the revocation list is undefined if the memory is modified.
  107. \attention
  108. It is the responsibility of the caller to free the memory pointed to by priv_rl
  109. after the verifier is no longer using it.
  110. \param[in,out] ctx
  111. The verifier context.
  112. \param[in] priv_rl
  113. The private key based revocation list.
  114. \param[in] priv_rl_size
  115. The size of the private key based revocation list in bytes.
  116. \returns ::EpidStatus
  117. \note
  118. If the result is not ::kEpidNoErr the private key based revocation list
  119. pointed to by the verifier is undefined.
  120. \see EpidVerifierCreate
  121. */
  122. EpidStatus EpidVerifierSetPrivRl(VerifierCtx* ctx, PrivRl const* priv_rl,
  123. size_t priv_rl_size);
  124. /// Sets the signature based revocation list.
  125. /*!
  126. The caller is responsible for ensuring the revocation list is authorized,
  127. e.g signed by the issuer. The caller is also responsible checking the version
  128. of the revocation list. The call fails if trying to set an older version
  129. of the revocation list than was last set.
  130. \attention
  131. The memory pointed to by sig_rl is accessed directly by the verifier
  132. until a new list is set or the verifier is destroyed. Do not modify the
  133. contents of this memory. The behavior of subsequent operations that rely on
  134. the revocation list is undefined if the memory is modified.
  135. \attention
  136. It is the responsibility of the caller to free the memory pointed to by sig_rl
  137. after the verifier is no longer using it.
  138. \param[in,out] ctx
  139. The verifier context.
  140. \param[in] sig_rl
  141. The signature based revocation list.
  142. \param[in] sig_rl_size
  143. The size of the signature based revocation list in bytes.
  144. \returns ::EpidStatus
  145. \note
  146. If the result is not ::kEpidNoErr the signature based revocation list pointed
  147. to by the verifier is undefined.
  148. \see EpidVerifierCreate
  149. */
  150. EpidStatus EpidVerifierSetSigRl(VerifierCtx* ctx, SigRl const* sig_rl,
  151. size_t sig_rl_size);
  152. /// Sets the group based revocation list.
  153. /*!
  154. The caller is responsible for ensuring the revocation list is authorized,
  155. e.g signed by the issuer. The caller is also responsible checking the version
  156. of the revocation list. The call fails if trying to set an older version
  157. of the revocation list than was last set.
  158. \attention
  159. The memory pointed to by grp_rl is accessed directly by the verifier
  160. until a new list is set or the verifier is destroyed. Do not modify the
  161. contents of this memory. The behavior of subsequent operations that rely on
  162. the revocation list is undefined if the memory is modified.
  163. \attention
  164. It is the responsibility of the caller to free the memory pointed to by grp_rl
  165. after the verifier is no longer using it.
  166. \param[in,out] ctx
  167. The verifier context.
  168. \param[in] grp_rl
  169. The group based revocation list.
  170. \param[in] grp_rl_size
  171. The size of the group based revocation list in bytes.
  172. \returns ::EpidStatus
  173. \note
  174. If the result is not ::kEpidNoErr the group based revocation list pointed
  175. to by the verifier is undefined.
  176. \see EpidVerifierCreate
  177. */
  178. EpidStatus EpidVerifierSetGroupRl(VerifierCtx* ctx, GroupRl const* grp_rl,
  179. size_t grp_rl_size);
  180. /// Sets the verifier revocation list.
  181. /*!
  182. The caller is responsible for ensuring the revocation list is
  183. authorized. The caller is also responsible for checking the version
  184. of the revocation list. The call fails if trying to set an older
  185. version of the same revocation list than was last set.
  186. Once ::EpidVerifierSetVerifierRl returns, callers are free to release
  187. the memory pointed to by ver_rl.
  188. \param[in,out] ctx
  189. The verifier context.
  190. \param[in] ver_rl
  191. The verifier revocation list.
  192. \param[in] ver_rl_size
  193. The size of the verifier revocation list in bytes.
  194. \returns ::EpidStatus
  195. \note
  196. If the result is not ::kEpidNoErr the verifier revocation list pointed
  197. to by the verifier is undefined.
  198. \see EpidVerifierCreate
  199. \see EpidBlacklistSig
  200. \see EpidWriteVerifierRl
  201. */
  202. EpidStatus EpidVerifierSetVerifierRl(VerifierCtx* ctx, VerifierRl const* ver_rl,
  203. size_t ver_rl_size);
  204. /// Sets the hash algorithm to be used by a verifier.
  205. /*!
  206. \param[in] ctx
  207. The verifier context.
  208. \param[in] hash_alg
  209. The hash algorithm to use.
  210. \returns ::EpidStatus
  211. \note
  212. If the result is not ::kEpidNoErr, the hash algorithm used by the
  213. verifier is undefined.
  214. \see EpidVerifierCreate
  215. \see ::HashAlg
  216. */
  217. EpidStatus EpidVerifierSetHashAlg(VerifierCtx* ctx, HashAlg hash_alg);
  218. /// Sets the basename to be used by a verifier.
  219. /*!
  220. \note
  221. A successful call to this function will clear the current verifier
  222. blacklist.
  223. \param[in, out] ctx
  224. The verifier context.
  225. \param[in] basename
  226. The basename. Pass NULL for random base.
  227. \param[in] basename_len
  228. Number of bytes in basename buffer. Must be 0 if basename is NULL.
  229. \returns ::EpidStatus
  230. \see EpidVerifierCreate
  231. */
  232. EpidStatus EpidVerifierSetBasename(VerifierCtx* ctx, void const* basename,
  233. size_t basename_len);
  234. /// Verifies a signature and checks revocation status.
  235. /*!
  236. \param[in] ctx
  237. The verifier context.
  238. \param[in] sig
  239. The signature.
  240. \param[in] sig_len
  241. The size of sig in bytes.
  242. \param[in] msg
  243. The message that was signed.
  244. \param[in] msg_len
  245. The size of msg in bytes.
  246. \returns ::EpidStatus
  247. \retval ::kEpidSigValid
  248. Signature validated successfully
  249. \retval ::kEpidSigInvalid
  250. Signature is invalid
  251. \retval ::kEpidSigRevokedInGroupRl
  252. Signature revoked in GroupRl
  253. \retval ::kEpidSigRevokedInPrivRl
  254. Signature revoked in PrivRl
  255. \retval ::kEpidSigRevokedInSigRl
  256. Signature revoked in SigRl
  257. \retval ::kEpidSigRevokedInVerifierRl
  258. Signature revoked in VerifierRl
  259. \note
  260. If the result is not ::kEpidNoErr or one of the values listed above the
  261. verify should be considered to have failed.
  262. \see EpidVerifierCreate
  263. \see EpidSignBasic
  264. \see EpidSign
  265. */
  266. EpidStatus EpidVerify(VerifierCtx const* ctx, EpidSignature const* sig,
  267. size_t sig_len, void const* msg, size_t msg_len);
  268. /// Determines if two signatures are linked.
  269. /*!
  270. The Intel(R) EPID scheme allows signatures to be linked. If basename
  271. option is specified when signing, signatures with the same basename
  272. are linkable. This linking capability allows the verifier, or
  273. anyone, to know whether two Intel(R) EPID signatures are generated
  274. by the same member.
  275. \param[in] sig1
  276. A basic signature.
  277. \param[in] sig2
  278. A basic signature.
  279. \result bool
  280. \retval true
  281. if the signatures were generated by the same member
  282. \retval false
  283. if it couldn't be determined if the signatures were generated by
  284. the same member
  285. \note
  286. The input signatures should be verified using EpidVerifyBasicSig() before
  287. invocation. Behavior is undefined if either of the signatures cannot be
  288. verified.
  289. \see EpidVerifyBasicSig
  290. \see EpidSignBasic
  291. \see EpidSign
  292. */
  293. bool EpidAreSigsLinked(BasicSignature const* sig1, BasicSignature const* sig2);
  294. /// Verifies a member signature without revocation checks.
  295. /*!
  296. Used in constrained environments where, due to limited memory, it may not
  297. be possible to process through a large and potentially unbounded revocation
  298. list.
  299. \param[in] ctx
  300. The verifier context.
  301. \param[in] sig
  302. The basic signature.
  303. \param[in] msg
  304. The message that was signed.
  305. \param[in] msg_len
  306. The size of msg in bytes.
  307. \returns ::EpidStatus
  308. \note
  309. This function should be used in conjunction with EpidNrVerify() and
  310. EpidCheckPrivRlEntry().
  311. \note
  312. If the result is not ::kEpidNoErr the verify should be considered to have
  313. failed.
  314. \see EpidVerifierCreate
  315. \see EpidSignBasic
  316. \see EpidSign
  317. */
  318. EpidStatus EpidVerifyBasicSig(VerifierCtx const* ctx, BasicSignature const* sig,
  319. void const* msg, size_t msg_len);
  320. /// Verifies the non-revoked proof for a single signature based revocation list
  321. /// entry.
  322. /*!
  323. Used in constrained environments where, due to limited memory, it may not
  324. be possible to process through a large and potentially unbounded revocation
  325. list.
  326. \param[in] ctx
  327. The verifier context.
  328. \param[in] sig
  329. The basic signature.
  330. \param[in] msg
  331. The message that was signed.
  332. \param[in] msg_len
  333. The size of msg in bytes.
  334. \param[in] sigrl_entry
  335. The signature based revocation list entry.
  336. \param[in] proof
  337. The non-revoked proof.
  338. \returns ::EpidStatus
  339. \note
  340. Sig should be verified using EpidVerifyBasicSig() before invocation. Behavior
  341. is undefined if sig cannot be verified.
  342. \note
  343. This function should be used in conjunction with EpidVerifyBasicSig() and
  344. EpidCheckPrivRlEntry().
  345. \note
  346. If the result is not ::kEpidNoErr, the verification should be
  347. considered to have failed.
  348. \see EpidVerifierCreate
  349. \see EpidVerifyBasicSig
  350. \see EpidCheckPrivRlEntry
  351. */
  352. EpidStatus EpidNrVerify(VerifierCtx const* ctx, BasicSignature const* sig,
  353. void const* msg, size_t msg_len,
  354. SigRlEntry const* sigrl_entry, NrProof const* proof);
  355. /// Verifies a signature has not been revoked in the private key based
  356. /// revocation list.
  357. /*!
  358. Used in constrained environments where, due to limited memory, it may not
  359. be possible to process through a large and potentially unbounded revocation
  360. list.
  361. \param[in] ctx
  362. The verifier context.
  363. \param[in] sig
  364. The basic signature.
  365. \param[in] f
  366. The private key based revocation list entry.
  367. \note
  368. Sig should be verified using EpidVerifyBasicSig() before invocation. Behavior
  369. is undefined if sig cannot be verified.
  370. \note
  371. This function should be used in conjunction with EpidNrVerify() and
  372. EpidVerifyBasicSig().
  373. \note
  374. If the result is not ::kEpidNoErr the verify should be considered to have
  375. failed.
  376. \returns ::EpidStatus
  377. \see EpidVerifierCreate
  378. \see EpidNrVerify
  379. \see EpidVerifyBasicSig
  380. */
  381. EpidStatus EpidCheckPrivRlEntry(VerifierCtx const* ctx,
  382. BasicSignature const* sig, FpElemStr const* f);
  383. /// Returns the number of bytes required to serialize the verifier blacklist
  384. /*!
  385. Use this function to determine the buffer size required by
  386. ::EpidWriteVerifierRl.
  387. \param[in] ctx
  388. The verifier context.
  389. \returns
  390. Size in bytes required to serialize the verifier blacklist
  391. \see EpidVerifierCreate
  392. \see EpidVerifierSetVerifierRl
  393. \see EpidBlacklistSig
  394. \see EpidWriteVerifierRl
  395. */
  396. size_t EpidGetVerifierRlSize(VerifierCtx const* ctx);
  397. /// Serializes the verifier blacklist to a buffer.
  398. /*!
  399. If the current blacklist is empty or not set a valid empty verifier
  400. blacklist will be serialized.
  401. Use ::EpidGetVerifierRlSize to determine the buffer size required to
  402. serialize the verifier blacklist.
  403. \param[in] ctx
  404. The verifier context.
  405. \param[out] ver_rl
  406. An existing buffer in which to write the verifier revocation list.
  407. \param[in] ver_rl_size
  408. The size of the caller allocated output buffer in bytes.
  409. \returns ::EpidStatus
  410. \see EpidVerifierCreate
  411. \see EpidVerifierSetVerifierRl
  412. \see EpidBlacklistSig
  413. \see EpidGetVerifierRlSize
  414. */
  415. EpidStatus EpidWriteVerifierRl(VerifierCtx const* ctx, VerifierRl* ver_rl,
  416. size_t ver_rl_size);
  417. /// Adds a valid name-based signature to the verifier blacklist.
  418. /*!
  419. If the signature is not valid it will not be added to the blacklist.
  420. \param[in] ctx
  421. The verifier context.
  422. \param[in] sig
  423. The name-based signature to revoke.
  424. \param[in] sig_len
  425. The size of sig in bytes.
  426. \param[in] msg
  427. The message that was signed.
  428. \param[in] msg_len
  429. The size of msg in bytes.
  430. \returns ::EpidStatus
  431. \see EpidVerifierCreate
  432. \see EpidVerifierSetVerifierRl
  433. \see EpidWriteVerifierRl
  434. */
  435. EpidStatus EpidBlacklistSig(VerifierCtx* ctx, EpidSignature const* sig,
  436. size_t sig_len, void const* msg, size_t msg_len);
  437. /*! @} */
  438. #endif // EPID_VERIFIER_API_H_