Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  2. * All rights reserved.
  3. *
  4. * This package is an SSL implementation written
  5. * by Eric Young (eay@cryptsoft.com).
  6. * The implementation was written so as to conform with Netscapes SSL.
  7. *
  8. * This library is free for commercial and non-commercial use as long as
  9. * the following conditions are aheared to. The following conditions
  10. * apply to all code found in this distribution, be it the RC4, RSA,
  11. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  12. * included with this distribution is covered by the same copyright terms
  13. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  14. *
  15. * Copyright remains Eric Young's, and as such any Copyright notices in
  16. * the code are not to be removed.
  17. * If this package is used in a product, Eric Young should be given attribution
  18. * as the author of the parts of the library used.
  19. * This can be in the form of a textual message at program startup or
  20. * in documentation (online or textual) provided with the package.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright
  28. * notice, this list of conditions and the following disclaimer in the
  29. * documentation and/or other materials provided with the distribution.
  30. * 3. All advertising materials mentioning features or use of this software
  31. * must display the following acknowledgement:
  32. * "This product includes cryptographic software written by
  33. * Eric Young (eay@cryptsoft.com)"
  34. * The word 'cryptographic' can be left out if the rouines from the library
  35. * being used are not cryptographic related :-).
  36. * 4. If you include any Windows specific code (or a derivative thereof) from
  37. * the apps directory (application code) you must include an acknowledgement:
  38. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  41. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. *
  52. * The licence and distribution terms for any publically available version or
  53. * derivative of this code cannot be changed. i.e. this code cannot simply be
  54. * copied and put under another distribution licence
  55. * [including the GNU Public Licence.] */
  56. #ifndef OPENSSL_HEADER_DIGEST_H
  57. #define OPENSSL_HEADER_DIGEST_H
  58. #include <openssl/base.h>
  59. #if defined(__cplusplus)
  60. extern "C" {
  61. #endif
  62. /* Digest functions.
  63. *
  64. * An EVP_MD abstracts the details of a specific hash function allowing code to
  65. * deal with the concept of a "hash function" without needing to know exactly
  66. * which hash function it is. */
  67. /* Hash algorithms.
  68. *
  69. * The following functions return |EVP_MD| objects that implement the named hash
  70. * function. */
  71. const EVP_MD *EVP_md5(void);
  72. const EVP_MD *EVP_sha1(void);
  73. const EVP_MD *EVP_sha224(void);
  74. const EVP_MD *EVP_sha256(void);
  75. const EVP_MD *EVP_sha384(void);
  76. const EVP_MD *EVP_sha512(void);
  77. /* EVP_get_digestbynid returns an |EVP_MD| for the given NID, or NULL if no
  78. * such digest is known. */
  79. const EVP_MD *EVP_get_digestbynid(int nid);
  80. /* EVP_get_digestbyobj returns an |EVP_MD| for the given |ASN1_OBJECT|, or NULL
  81. * if no such digest is known. */
  82. const EVP_MD *EVP_get_digestbyobj(const ASN1_OBJECT *obj);
  83. /* Digest contexts.
  84. *
  85. * An EVP_MD_CTX represents the state of a specific digest operation in
  86. * progress. */
  87. /* EVP_MD_CTX_init initialises an, already allocated, |EVP_MD_CTX|. */
  88. void EVP_MD_CTX_init(EVP_MD_CTX *ctx);
  89. /* EVP_MD_CTX_create allocates and initialises a fresh |EVP_MD_CTX| and returns
  90. * it, or NULL on allocation failure. */
  91. EVP_MD_CTX *EVP_MD_CTX_create(void);
  92. /* EVP_MD_CTX_cleanup frees any resources owned by |ctx| and resets it to a
  93. * freshly initialised state. It does not free |ctx| itself. It returns one. */
  94. int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
  95. /* EVP_MD_CTX_destroy calls |EVP_MD_CTX_cleanup| and then frees |ctx| itself. */
  96. void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
  97. /* EVP_MD_CTX_copy_ex sets |out|, which must already be initialised, to be a
  98. * copy of |in|. It returns one on success and zero on error. */
  99. int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in);
  100. /* Digest operations. */
  101. /* EVP_DigestInit_ex configures |ctx|, which must already have been
  102. * initialised, for a fresh hashing operation using |type|. It returns one on
  103. * success and zero otherwise. */
  104. int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *engine);
  105. /* EVP_DigestInit acts like |EVP_DigestInit_ex| except that |ctx| is
  106. * initialised before use. */
  107. int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
  108. /* EVP_DigestUpdate hashes |len| bytes from |data| into the hashing operation
  109. * in |ctx|. It returns one on success and zero otherwise. */
  110. int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t len);
  111. /* EVP_MAX_MD_SIZE is the largest digest size supported. Functions that output
  112. * a digest generally require the buffer have at least this much space. */
  113. #define EVP_MAX_MD_SIZE 64 /* SHA-512 is the longest so far. */
  114. /* EVP_DigestFinal_ex finishes the digest in |ctx| and writes the output to
  115. * |md_out|. At most |EVP_MAX_MD_SIZE| bytes are written. If |out_size| is not
  116. * NULL then |*out_size| is set to the number of bytes written. It returns one
  117. * on success and zero otherwise. After this call, the hash cannot be updated
  118. * or finished again until |EVP_DigestFinal_ex| is called to start another
  119. * hashing operation. */
  120. int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, uint8_t *md_out,
  121. unsigned int *out_size);
  122. /* EVP_DigestFinal acts like |EVP_DigestFinal_ex| except that
  123. * |EVP_MD_CTX_cleanup| is called on |ctx| before returning. */
  124. int EVP_DigestFinal(EVP_MD_CTX *ctx, uint8_t *md_out, unsigned int *out_size);
  125. /* EVP_Digest performs a complete hashing operation in one call. It hashes
  126. * |len| bytes from |data| and writes the digest to |md_out|. At most
  127. * |EVP_MAX_MD_SIZE| bytes are written. If |out_size| is not NULL then
  128. * |*out_size| is set to the number of bytes written. It returns one on success
  129. * and zero otherwise. */
  130. int EVP_Digest(const void *data, size_t len, uint8_t *md_out,
  131. unsigned int *md_out_size, const EVP_MD *type, ENGINE *impl);
  132. /* Digest function accessors.
  133. *
  134. * These functions allow code to learn details about an abstract hash
  135. * function. */
  136. /* EVP_MD_type returns a NID identifing |md|. (For example, |NID_md5|.) */
  137. int EVP_MD_type(const EVP_MD *md);
  138. /* EVP_MD_name returns the short name for |md| or NULL if no name is known. */
  139. const char *EVP_MD_name(const EVP_MD *md);
  140. /* EVP_MD_flags returns the flags for |md|, which is a set of |EVP_MD_FLAG_*|
  141. * values, ORed together. */
  142. uint32_t EVP_MD_flags(const EVP_MD *md);
  143. /* EVP_MD_size returns the digest size of |md|, in bytes. */
  144. size_t EVP_MD_size(const EVP_MD *md);
  145. /* EVP_MD_block_size returns the native block-size of |md|. */
  146. size_t EVP_MD_block_size(const EVP_MD *md);
  147. /* EVP_MD_FLAG_PKEY_DIGEST indicates the the digest function is used with a
  148. * specific public key in order to verify signatures. (For example,
  149. * EVP_dss1.) */
  150. #define EVP_MD_FLAG_PKEY_DIGEST 1
  151. /* EVP_MD_FLAG_DIGALGID_ABSENT indicates that the parameter type in an X.509
  152. * DigestAlgorithmIdentifier representing this digest function should be
  153. * undefined rather than NULL. */
  154. #define EVP_MD_FLAG_DIGALGID_ABSENT 2
  155. /* Deprecated functions. */
  156. /* EVP_MD_CTX_copy sets |out|, which must /not/ be initialised, to be a copy of
  157. * |in|. It returns one on success and zero on error. */
  158. int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in);
  159. /* Digest operation accessors. */
  160. /* EVP_MD_CTX_md returns the underlying digest function, or NULL if one has not
  161. * been set. */
  162. const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx);
  163. /* EVP_MD_CTX_size returns the digest size of |ctx|. It will crash if a digest
  164. * hasn't been set on |ctx|. */
  165. unsigned EVP_MD_CTX_size(const EVP_MD_CTX *ctx);
  166. /* EVP_MD_CTX_block_size returns the block size of the digest function used by
  167. * |ctx|. It will crash if a digest hasn't been set on |ctx|. */
  168. unsigned EVP_MD_CTX_block_size(const EVP_MD_CTX *ctx);
  169. /* EVP_MD_CTX_type returns a NID describing the digest function used by |ctx|.
  170. * (For example, |NID_md5|.) It will crash if a digest hasn't been set on
  171. * |ctx|. */
  172. int EVP_MD_CTX_type(const EVP_MD_CTX *ctx);
  173. /* EVP_MD_CTX_set_flags ORs |flags| into the flags member of |ctx|. */
  174. void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, uint32_t flags);
  175. /* EVP_MD_CTX_clear_flags clears any bits from the flags member of |ctx| that
  176. * are set in |flags|. */
  177. void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, uint32_t flags);
  178. /* EVP_MD_CTX_test_flags returns the AND of |flags| and the flags member of
  179. * |ctx|. */
  180. uint32_t EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, uint32_t flags);
  181. struct evp_md_pctx_ops;
  182. struct env_md_ctx_st {
  183. /* digest is the underlying digest function, or NULL if not set. */
  184. const EVP_MD *digest;
  185. /* flags is the OR of a number of |EVP_MD_CTX_FLAG_*| values. */
  186. uint32_t flags;
  187. /* md_data points to a block of memory that contains the hash-specific
  188. * context. */
  189. void *md_data;
  190. /* update is usually copied from |digest->update| but can differ in some
  191. * cases, i.e. HMAC. */
  192. int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);
  193. /* pctx is an opaque (at this layer) pointer to additional context that
  194. * EVP_PKEY functions may store in this object. */
  195. EVP_PKEY_CTX *pctx;
  196. /* pctx_ops, if not NULL, points to a vtable that contains functions to
  197. * manipulate |pctx|. */
  198. const struct evp_md_pctx_ops *pctx_ops;
  199. } /* EVP_MD_CTX */;
  200. /* EVP_MD_CTX_FLAG_NO_INIT causes the |EVP_MD|'s |init| function not to be
  201. * called, the |update| member not to be copied from the |EVP_MD| in
  202. * |EVP_DigestInit_ex| and for |md_data| not to be initialised. */
  203. #define EVP_MD_CTX_FLAG_NO_INIT 1
  204. #if defined(__cplusplus)
  205. } /* extern C */
  206. #endif
  207. #define DIGEST_F_EVP_DigestInit_ex 100
  208. #define DIGEST_F_EVP_MD_CTX_copy_ex 101
  209. #define DIGEST_R_INPUT_NOT_INITIALIZED 100
  210. #endif /* OPENSSL_HEADER_DIGEST_H */