api.h 16 KB

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