2016-05-18 02:24:46 +08:00
|
|
|
/*
|
2021-06-17 20:24:59 +08:00
|
|
|
* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2018-12-06 20:48:17 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:24:46 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/objects.h>
|
|
|
|
#include <openssl/x509.h>
|
|
|
|
#include <openssl/pem.h>
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2009-09-24 07:43:49 +08:00
|
|
|
int PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
return EVP_DigestInit_ex(ctx, type, NULL);
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2019-11-15 15:54:17 +08:00
|
|
|
int PEM_SignUpdate(EVP_MD_CTX *ctx,
|
|
|
|
const unsigned char *data, unsigned int count)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
return EVP_DigestUpdate(ctx, data, count);
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
|
|
|
|
unsigned int *siglen, EVP_PKEY *pkey)
|
|
|
|
{
|
|
|
|
unsigned char *m;
|
|
|
|
int i, ret = 0;
|
|
|
|
unsigned int m_len;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
m = OPENSSL_malloc(EVP_PKEY_get_size(pkey));
|
2022-09-29 19:57:34 +08:00
|
|
|
if (m == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (EVP_SignFinal(ctx, m, &m_len, pkey) <= 0)
|
|
|
|
goto err;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
i = EVP_EncodeBlock(sigret, m, m_len);
|
|
|
|
*siglen = i;
|
|
|
|
ret = 1;
|
|
|
|
err:
|
|
|
|
/* ctx has been zeroed by EVP_SignFinal() */
|
2015-05-01 22:02:07 +08:00
|
|
|
OPENSSL_free(m);
|
2017-10-17 22:04:09 +08:00
|
|
|
return ret;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|