Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

189 wiersze
7.6 KiB

  1. /* ====================================================================
  2. * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in
  13. * the documentation and/or other materials provided with the
  14. * distribution.
  15. *
  16. * 3. All advertising materials mentioning features or use of this
  17. * software must display the following acknowledgment:
  18. * "This product includes software developed by the OpenSSL Project
  19. * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
  20. *
  21. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  22. * endorse or promote products derived from this software without
  23. * prior written permission. For written permission, please contact
  24. * openssl-core@OpenSSL.org.
  25. *
  26. * 5. Products derived from this software may not be called "OpenSSL"
  27. * nor may "OpenSSL" appear in their names without prior written
  28. * permission of the OpenSSL Project.
  29. *
  30. * 6. Redistributions of any form whatsoever must retain the following
  31. * acknowledgment:
  32. * "This product includes software developed by the OpenSSL Project
  33. * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
  34. *
  35. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  36. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  37. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  41. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  44. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  45. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  46. * OF THE POSSIBILITY OF SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This product includes cryptographic software written by Eric Young
  50. * (eay@cryptsoft.com). This product includes software written by Tim
  51. * Hudson (tjh@cryptsoft.com). */
  52. #ifndef OPENSSL_HEADER_ECDSA_H
  53. #define OPENSSL_HEADER_ECDSA_H
  54. #include <openssl/base.h>
  55. #include <openssl/ec_key.h>
  56. #if defined(__cplusplus)
  57. extern "C" {
  58. #endif
  59. /* DSA contains functions for signing and verifing with the Digital Signature
  60. * Algorithm over elliptic curves. */
  61. /* Signing and verifing. */
  62. /* ECDSA_sign signs |digest_len| bytes from |digest| with |key| and writes the
  63. * resulting signature to |sig|, which must have |ECDSA_size(key)| bytes of
  64. * space. On successful exit, |*sig_len| is set to the actual number of bytes
  65. * written. The |type| argument should be zero. It returns one on success and
  66. * zero otherwise. */
  67. int ECDSA_sign(int type, const uint8_t *digest, size_t digest_len, uint8_t *sig,
  68. unsigned int *sig_len, EC_KEY *key);
  69. /* ECDSA_verify verifies that |sig_len| bytes from |sig| constitute a valid
  70. * signature by |key| of |digest|. (The |type| argument should be zero.) It
  71. * returns one on success, zero if the signature is invalid and -1 on error.
  72. *
  73. * DANGER: this function differs from the usual OpenSSL return value
  74. * convention.
  75. *
  76. * TODO(fork): change this to return the usual 0/1. */
  77. int ECDSA_verify(int type, const uint8_t *digest, size_t digest_len,
  78. const uint8_t *sig, size_t sig_len, EC_KEY *key);
  79. /* ECDSA_size returns the maximum size of an ECDSA signature using |key|. It
  80. * returns zero on error. */
  81. size_t ECDSA_size(const EC_KEY *key);
  82. /* Low-level signing and verification.
  83. *
  84. * Low-level functions handle signatures as |ECDSA_SIG| structures which allow
  85. * the two values in an ECDSA signature to be handled separately. */
  86. struct ecdsa_sig_st {
  87. BIGNUM *r;
  88. BIGNUM *s;
  89. };
  90. /* ECDSA_SIG_new returns a fresh |ECDSA_SIG| structure or NULL on error. */
  91. ECDSA_SIG *ECDSA_SIG_new(void);
  92. /* ECDSA_SIG_free frees |sig| its member |BIGNUM|s. */
  93. void ECDSA_SIG_free(ECDSA_SIG *sig);
  94. /* ECDSA_sign signs |digest_len| bytes from |digest| with |key| and returns the
  95. * resulting signature structure, or NULL on error.
  96. *
  97. * TODO(fork): remove this function. */
  98. ECDSA_SIG *ECDSA_do_sign(const uint8_t *digest, size_t digest_len,
  99. EC_KEY *key);
  100. /* ECDSA_verify verifies that |sig| constitutes a valid signature by |key| of
  101. * |digest|. It returns one on success, zero if the signature is invalid and -1
  102. * on error.
  103. *
  104. * DANGER: this function differs from the usual OpenSSL return value
  105. * convention.
  106. *
  107. * TODO(fork): remove this function. */
  108. int ECDSA_do_verify(const uint8_t *digest, size_t digest_len,
  109. const ECDSA_SIG *sig, EC_KEY *key);
  110. /* Signing with precomputation.
  111. *
  112. * Parts of the ECDSA signature can be independent of the message to be signed
  113. * thus it's possible to precompute them and reduce the signing latency.
  114. *
  115. * TODO(fork): remove support for this as it cannot support safe-randomness. */
  116. /* ECDSA_sign_setup precomputes parts of an ECDSA signing operation. It sets
  117. * |*kinv| and |*rp| to the precomputed values and uses the |ctx| argument, if
  118. * not NULL. It returns one on success and zero otherwise. */
  119. int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp);
  120. /* ECDSA_do_sign_ex is the same as |ECDSA_do_sign| but takes precomputed values
  121. * as generated by |ECDSA_sign_setup|. */
  122. ECDSA_SIG *ECDSA_do_sign_ex(const uint8_t *digest, size_t digest_len,
  123. const BIGNUM *kinv, const BIGNUM *rp,
  124. EC_KEY *eckey);
  125. /* ECDSA_sign_ex is the same as |ECDSA_sign| but takes precomputed values as
  126. * generated by |ECDSA_sign_setup|. */
  127. int ECDSA_sign_ex(int type, const uint8_t *digest, size_t digest_len,
  128. uint8_t *sig, unsigned int *sig_len, const BIGNUM *kinv,
  129. const BIGNUM *rp, EC_KEY *eckey);
  130. /* ASN.1 functions. */
  131. /* d2i_ECDSA_SIG parses an ASN.1, DER-encoded, signature from |len| bytes at
  132. * |*inp|. If |out| is not NULL then, on exit, a pointer to the result is in
  133. * |*out|. If |*out| is already non-NULL on entry then the result is written
  134. * directly into |*out|, otherwise a fresh |ECDSA_SIG| is allocated. On
  135. * successful exit, |*inp| is advanced past the DER structure. It returns the
  136. * result or NULL on error. */
  137. ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **out, const uint8_t **inp, long len);
  138. /* i2d_ECDSA_SIG marshals a signature from |sig| to an ASN.1, DER
  139. * structure. If |outp| is not NULL then the result is written to |*outp| and
  140. * |*outp| is advanced just past the output. It returns the number of bytes in
  141. * the result, whether written or not, or a negative value on error. */
  142. int i2d_ECDSA_SIG(const ECDSA_SIG *sig, uint8_t **outp);
  143. #if defined(__cplusplus)
  144. } /* extern C */
  145. #endif
  146. #define ECDSA_F_digest_to_bn 100
  147. #define ECDSA_F_ECDSA_do_verify 101
  148. #define ECDSA_F_ECDSA_sign_setup 102
  149. #define ECDSA_F_ECDSA_do_sign_ex 103
  150. #define ECDSA_F_ECDSA_sign_ex 104
  151. #define ECDSA_F_ecdsa_sign_setup 105
  152. #define ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED 100
  153. #define ECDSA_R_NEED_NEW_SETUP_VALUES 101
  154. #define ECDSA_R_MISSING_PARAMETERS 102
  155. #define ECDSA_R_BAD_SIGNATURE 103
  156. #define ECDSA_R_NOT_IMPLEMENTED 104
  157. #endif /* OPENSSL_HEADER_ECDSA_H */