Add message-based EVP_PKEY APIs.
Right now this is just a wrapper over EVP_Digest and EVP_PKEY_sign. A
later change will introduce a sign_message hook to EVP_PKEY_METHOD which
Ed25519 and other single-shot-only algorithms can implement.
(EVP_PKEY_sign does not quite work for this purpose as all the other key
types believe EVP_PKEY_sign acts on a pre-hashed input.)
BUG=187
Change-Id: Ia4bbf61b25cc4a0d64bcb4364805fe9b5a6e829c
Reviewed-on: https://boringssl-review.googlesource.com/14447
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/include/openssl/evp.h b/include/openssl/evp.h
index 9abce9d..951a143 100644
--- a/include/openssl/evp.h
+++ b/include/openssl/evp.h
@@ -223,6 +223,10 @@
* operation will be written to |*pctx|; this can be used to set alternative
* signing options.
*
+ * This function performs a streaming signing operation and will fail for
+ * signature algorithms which do not support this. Use |EVP_PKEY_sign_message|
+ * for a single-shot operation.
+ *
* It returns one on success, or zero on error. */
OPENSSL_EXPORT int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
const EVP_MD *type, ENGINE *e,
@@ -253,6 +257,10 @@
* operation will be written to |*pctx|; this can be used to set alternative
* signing options.
*
+ * This function performs streaming signature verification and will fail for
+ * signature algorithms which do not support this. Use |EVP_PKEY_verify_message|
+ * for a single-shot verification.
+ *
* It returns one on success, or zero on error. */
OPENSSL_EXPORT int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
const EVP_MD *type, ENGINE *e,
@@ -409,20 +417,39 @@
* It returns one on success or zero on error. */
OPENSSL_EXPORT int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx);
-/* EVP_PKEY_sign signs |data_len| bytes from |data| using |ctx|. If |sig| is
+/* EVP_PKEY_sign signs |digest_len| bytes from |digest| using |ctx|. If |sig| is
* NULL, the maximum size of the signature is written to
* |out_sig_len|. Otherwise, |*sig_len| must contain the number of bytes of
* space available at |sig|. If sufficient, the signature will be written to
* |sig| and |*sig_len| updated with the true length.
*
+ * This function expects a pre-hashed input and will fail for signature
+ * algorithms which do not support this. Use |EVP_PKEY_sign_message| or
+ * |EVP_DigestSignInit| to sign an unhashed input.
+ *
* WARNING: Setting |sig| to NULL only gives the maximum size of the
* signature. The actual signature may be smaller.
*
* It returns one on success or zero on error. (Note: this differs from
* OpenSSL, which can also return negative values to indicate an error. ) */
OPENSSL_EXPORT int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, uint8_t *sig,
- size_t *sig_len, const uint8_t *data,
- size_t data_len);
+ size_t *sig_len, const uint8_t *digest,
+ size_t digest_len);
+
+/* EVP_PKEY_sign_message signs |data_len| bytes from |data| using |ctx|. If
+ * |sig| is NULL, the maximum size of the signature is written to |out_sig_len|.
+ * Otherwise, |*sig_len| must contain the number of bytes of space available at
+ * |sig|. If sufficient, the signature will be written to |sig| and |*sig_len|
+ * updated with the true length.
+ *
+ * WARNING: Setting |sig| to NULL only gives the maximum size of the
+ * signature. The actual signature may be smaller.
+ *
+ * It returns one on success or zero on error. (Note: this differs from
+ * OpenSSL, which can also return negative values to indicate an error. ) */
+OPENSSL_EXPORT int EVP_PKEY_sign_message(EVP_PKEY_CTX *ctx, uint8_t *sig,
+ size_t *sig_len, const uint8_t *data,
+ size_t data_len);
/* EVP_PKEY_verify_init initialises an |EVP_PKEY_CTX| for a signature
* verification operation. It should be called before |EVP_PKEY_verify|.
@@ -431,12 +458,23 @@
OPENSSL_EXPORT int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx);
/* EVP_PKEY_verify verifies that |sig_len| bytes from |sig| are a valid
- * signature for |data|.
+ * signature for |digest|.
+ *
+ * This function expects a pre-hashed input and will fail for signature
+ * algorithms which do not support this. Use |EVP_PKEY_verify_message| or
+ * |EVP_DigestVerifyInit| to verify a signature given the unhashed input.
*
* It returns one on success or zero on error. */
OPENSSL_EXPORT int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, const uint8_t *sig,
- size_t sig_len, const uint8_t *data,
- size_t data_len);
+ size_t sig_len, const uint8_t *digest,
+ size_t digest_len);
+
+/* EVP_PKEY_verify_message verifies that |sig_len| bytes from |sig| are a valid
+ * signature for |data|. It returns one on success or zero on error. */
+OPENSSL_EXPORT int EVP_PKEY_verify_message(EVP_PKEY_CTX *ctx,
+ const uint8_t *sig, size_t sig_len,
+ const uint8_t *data,
+ size_t data_len);
/* EVP_PKEY_encrypt_init initialises an |EVP_PKEY_CTX| for an encryption
* operation. It should be called before |EVP_PKEY_encrypt|.