early-access version 2698

This commit is contained in:
pineappleEA
2022-04-24 22:29:35 +02:00
parent c96f949832
commit caa0c2911b
486 changed files with 37806 additions and 14362 deletions

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: bio_b64.c,v 1.22 2018/08/24 19:47:25 tb Exp $ */
/* $OpenBSD: bio_b64.c,v 1.25 2022/01/14 08:40:57 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -63,6 +63,9 @@
#include <openssl/buffer.h>
#include <openssl/evp.h>
#include "bio_local.h"
#include "evp_locl.h"
static int b64_write(BIO *h, const char *buf, int num);
static int b64_read(BIO *h, char *buf, int size);
static int b64_puts(BIO *h, const char *str);
@@ -70,7 +73,7 @@ static int b64_puts(BIO *h, const char *str);
static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int b64_new(BIO *h);
static int b64_free(BIO *data);
static long b64_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
static long b64_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
#define B64_BLOCK_SIZE 1024
#define B64_BLOCK_SIZE2 768
#define B64_NONE 0
@@ -547,7 +550,7 @@ again:
}
static long
b64_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
b64_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
{
long ret = 1;

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: bio_enc.c,v 1.22 2018/08/24 19:30:24 tb Exp $ */
/* $OpenBSD: bio_enc.c,v 1.26 2022/01/14 08:40:57 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -63,6 +63,9 @@
#include <openssl/buffer.h>
#include <openssl/evp.h>
#include "bio_local.h"
#include "evp_locl.h"
static int enc_write(BIO *h, const char *buf, int num);
static int enc_read(BIO *h, char *buf, int size);
/*static int enc_puts(BIO *h, const char *str); */
@@ -70,7 +73,7 @@ static int enc_read(BIO *h, char *buf, int size);
static long enc_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int enc_new(BIO *h);
static int enc_free(BIO *data);
static long enc_callback_ctrl(BIO *h, int cmd, bio_info_cb *fps);
static long enc_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fps);
#define ENC_BLOCK_SIZE (1024*4)
#define BUF_OFFSET (EVP_MAX_BLOCK_LENGTH*2)
@@ -370,7 +373,7 @@ again:
}
static long
enc_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
enc_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
{
long ret = 1;
@@ -384,26 +387,6 @@ enc_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
return (ret);
}
/*
void BIO_set_cipher_ctx(b,c)
BIO *b;
EVP_CIPHER_ctx *c;
{
if (b == NULL) return;
if ((b->callback != NULL) &&
(b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
return;
b->init=1;
ctx=(BIO_ENC_CTX *)b->ptr;
memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
if (b->callback != NULL)
b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
}
*/
int
BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *k,
const unsigned char *i, int e)

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: bio_md.c,v 1.15 2018/05/02 15:51:41 tb Exp $ */
/* $OpenBSD: bio_md.c,v 1.18 2022/01/14 08:40:57 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -62,6 +62,9 @@
#include <openssl/buffer.h>
#include <openssl/evp.h>
#include "bio_local.h"
#include "evp_locl.h"
/* BIO_put and BIO_get both add to the digest,
* BIO_gets returns the digest */
@@ -72,7 +75,7 @@ static int md_gets(BIO *h, char *str, int size);
static long md_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int md_new(BIO *h);
static int md_free(BIO *data);
static long md_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
static long md_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
static const BIO_METHOD methods_md = {
.type = BIO_TYPE_MD,
@@ -238,7 +241,7 @@ md_ctrl(BIO *b, int cmd, long num, void *ptr)
}
static long
md_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
md_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
{
long ret = 1;

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: c_all.c,v 1.26 2019/03/17 18:07:41 tb Exp $ */
/* $OpenBSD: c_all.c,v 1.27 2022/01/14 08:38:05 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -263,24 +263,10 @@ OpenSSL_add_all_digests_internal(void)
EVP_add_digest_alias(SN_md5, "ssl3-md5");
#endif
#if !defined(OPENSSL_NO_SHA)
#ifndef OPENSSL_NO_DSA
EVP_add_digest(EVP_dss());
#endif
#endif
#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1)
EVP_add_digest(EVP_sha1());
EVP_add_digest_alias(SN_sha1, "ssl3-sha1");
EVP_add_digest_alias(SN_sha1WithRSAEncryption, SN_sha1WithRSA);
#ifndef OPENSSL_NO_DSA
EVP_add_digest(EVP_dss1());
EVP_add_digest_alias(SN_dsaWithSHA1, SN_dsaWithSHA1_2);
EVP_add_digest_alias(SN_dsaWithSHA1, "DSS1");
EVP_add_digest_alias(SN_dsaWithSHA1, "dss1");
#endif
#ifndef OPENSSL_NO_ECDSA
EVP_add_digest(EVP_ecdsa());
#endif
#endif
#ifndef OPENSSL_NO_GOST

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: digest.c,v 1.31 2019/04/19 17:04:45 jsing Exp $ */
/* $OpenBSD: digest.c,v 1.34 2022/01/10 10:51:31 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -122,6 +122,8 @@
#include <openssl/engine.h>
#endif
#include "evp_locl.h"
int
EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
{
@@ -279,6 +281,14 @@ EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
tmp_buf = NULL;
EVP_MD_CTX_cleanup(out);
memcpy(out, in, sizeof *out);
out->md_data = NULL;
out->pctx = NULL;
/*
* Because of the EVP_PKEY_CTX_dup() below, EVP_MD_CTX_cleanup() needs
* to free out->pctx in all cases (even if this flag is set on in).
*/
EVP_MD_CTX_clear_flags(out, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
if (in->md_data && out->digest->ctx_size) {
if (tmp_buf) {
@@ -381,7 +391,12 @@ EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
if (ctx->digest && ctx->digest->ctx_size && ctx->md_data &&
!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE))
freezero(ctx->md_data, ctx->digest->ctx_size);
EVP_PKEY_CTX_free(ctx->pctx);
/*
* If EVP_MD_CTX_FLAG_KEEP_PKEY_CTX is set, EVP_MD_CTX_set_pkey() was
* called and its strange API contract implies we don't own ctx->pctx.
*/
if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX))
EVP_PKEY_CTX_free(ctx->pctx);
#ifndef OPENSSL_NO_ENGINE
ENGINE_finish(ctx->engine);
#endif

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: e_aes_cbc_hmac_sha1.c,v 1.15 2019/04/03 15:33:37 tb Exp $ */
/* $OpenBSD: e_aes_cbc_hmac_sha1.c,v 1.16 2021/12/12 21:30:13 tb Exp $ */
/* ====================================================================
* Copyright (c) 2011-2013 The OpenSSL Project. All rights reserved.
*
@@ -59,8 +59,9 @@
#include <openssl/objects.h>
#include <openssl/aes.h>
#include <openssl/sha.h>
#include "evp_locl.h"
#include "constant_time_locl.h"
#include "evp_locl.h"
#define TLS1_1_VERSION 0x0302

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: e_camellia.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */
/* $OpenBSD: e_camellia.c,v 1.9 2021/12/12 21:30:13 tb Exp $ */
/* ====================================================================
* Copyright (c) 2006 The OpenSSL Project. All rights reserved.
*
@@ -61,6 +61,7 @@
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/camellia.h>
#include "evp_locl.h"
static int camellia_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: e_gost2814789.c,v 1.4 2017/01/29 17:49:23 beck Exp $ */
/* $OpenBSD: e_gost2814789.c,v 1.5 2021/12/12 21:30:13 tb Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -48,6 +48,7 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
#include <string.h>
#include <openssl/opensslconf.h>
@@ -56,6 +57,7 @@
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/gost.h>
#include "evp_locl.h"
typedef struct {

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: e_null.c,v 1.14 2014/07/11 08:44:48 jsing Exp $ */
/* $OpenBSD: e_null.c,v 1.15 2021/12/12 21:30:13 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -62,6 +62,8 @@
#include <openssl/evp.h>
#include <openssl/objects.h>
#include "evp_locl.h"
static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
const unsigned char *iv, int enc);
static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: e_rc2.c,v 1.12 2017/01/29 17:49:23 beck Exp $ */
/* $OpenBSD: e_rc2.c,v 1.14 2022/01/20 11:31:37 inoguchi Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -150,7 +150,8 @@ rc2_meth_to_magic(EVP_CIPHER_CTX *e)
{
int i;
EVP_CIPHER_CTX_ctrl(e, EVP_CTRL_GET_RC2_KEY_BITS, 0, &i);
if (EVP_CIPHER_CTX_ctrl(e, EVP_CTRL_GET_RC2_KEY_BITS, 0, &i) <= 0)
return (0);
if (i == 128)
return (RC2_128_MAGIC);
else if (i == 64)
@@ -199,9 +200,11 @@ rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
return (-1);
if (i > 0 && !EVP_CipherInit_ex(c, NULL, NULL, NULL, iv, -1))
return -1;
EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_RC2_KEY_BITS,
key_bits, NULL);
EVP_CIPHER_CTX_set_key_length(c, key_bits / 8);
if (EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_RC2_KEY_BITS,
key_bits, NULL) <= 0)
return -1;
if (!EVP_CIPHER_CTX_set_key_length(c, key_bits / 8))
return -1;
}
return (i);
}

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: e_rc4_hmac_md5.c,v 1.8 2017/01/31 13:17:21 inoguchi Exp $ */
/* $OpenBSD: e_rc4_hmac_md5.c,v 1.9 2021/12/12 21:30:13 tb Exp $ */
/* ====================================================================
* Copyright (c) 2011 The OpenSSL Project. All rights reserved.
*
@@ -60,6 +60,8 @@
#include <openssl/rc4.h>
#include <openssl/md5.h>
#include "evp_locl.h"
/* FIXME: surely this is available elsewhere? */
#define EVP_RC4_KEY_SIZE 16

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: encode.c,v 1.28 2020/03/04 11:53:21 inoguchi Exp $ */
/* $OpenBSD: encode.c,v 1.29 2021/12/12 21:30:13 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -62,6 +62,8 @@
#include <openssl/evp.h>
#include "evp_locl.h"
static unsigned char conv_ascii2bin(unsigned char a);
#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f])

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: evp_aead.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */
/* $OpenBSD: evp_aead.c,v 1.7 2022/01/07 21:58:17 tb Exp $ */
/*
* Copyright (c) 2014, Google Inc.
*
@@ -68,6 +68,22 @@ EVP_AEAD_CTX_cleanup(EVP_AEAD_CTX *ctx)
ctx->aead = NULL;
}
EVP_AEAD_CTX *
EVP_AEAD_CTX_new(void)
{
return calloc(1, sizeof(EVP_AEAD_CTX));
}
void
EVP_AEAD_CTX_free(EVP_AEAD_CTX *ctx)
{
if (ctx == NULL)
return;
EVP_AEAD_CTX_cleanup(ctx);
free(ctx);
}
/* check_alias returns 0 if out points within the buffer determined by in
* and in_len and 1 otherwise.
*

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: evp_enc.c,v 1.43 2019/04/14 17:16:57 jsing Exp $ */
/* $OpenBSD: evp_enc.c,v 1.44 2021/02/18 19:12:29 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -56,6 +56,7 @@
* [including the GNU Public Licence.]
*/
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -337,6 +338,17 @@ EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
return 1;
} else {
j = bl - i;
/*
* Once we've processed the first j bytes from in, the
* amount of data left that is a multiple of the block
* length is (inl - j) & ~(bl - 1). Ensure this plus
* the block processed from ctx-buf doesn't overflow.
*/
if (((inl - j) & ~(bl - 1)) > INT_MAX - bl) {
EVPerror(EVP_R_TOO_LARGE);
return 0;
}
memcpy(&(ctx->buf[i]), in, j);
if (!M_do_cipher(ctx, out, ctx->buf, bl))
return 0;
@@ -451,6 +463,16 @@ EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
}
if (ctx->final_used) {
/*
* final_used is only ever set if buf_len is 0. Therefore the
* maximum length output we will ever see from EVP_EncryptUpdate
* is inl & ~(b - 1). Since final_used is set, the final output
* length is (inl & ~(b - 1)) + b. Ensure it doesn't overflow.
*/
if ((inl & ~(b - 1)) > INT_MAX - b) {
EVPerror(EVP_R_TOO_LARGE);
return 0;
}
memcpy(out, ctx->final, b);
out += b;
fix_len = 1;

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: evp_err.c,v 1.26 2020/04/27 19:31:02 tb Exp $ */
/* $OpenBSD: evp_err.c,v 1.27 2021/03/29 15:57:23 tb Exp $ */
/* ====================================================================
* Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
*
@@ -116,6 +116,7 @@ static ERR_STRING_DATA EVP_str_reasons[] = {
{ERR_REASON(EVP_R_INVALID_OPERATION) , "invalid operation"},
{ERR_REASON(EVP_R_IV_TOO_LARGE) , "iv too large"},
{ERR_REASON(EVP_R_KEYGEN_FAILURE) , "keygen failure"},
{ERR_REASON(EVP_R_KEY_SETUP_FAILED) , "key setup failed"},
{ERR_REASON(EVP_R_MESSAGE_DIGEST_IS_NULL), "message digest is null"},
{ERR_REASON(EVP_R_METHOD_NOT_SUPPORTED) , "method not supported"},
{ERR_REASON(EVP_R_MISSING_PARAMETERS) , "missing parameters"},

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: evp_key.c,v 1.26 2018/08/14 17:59:26 tb Exp $ */
/* $OpenBSD: evp_key.c,v 1.27 2021/12/12 21:30:13 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -65,6 +65,8 @@
#include <openssl/ui.h>
#include <openssl/x509.h>
#include "evp_locl.h"
/* should be init to zeros. */
static char prompt_string[80];

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: evp_lib.c,v 1.17 2018/09/12 06:35:38 djm Exp $ */
/* $OpenBSD: evp_lib.c,v 1.24 2022/01/10 13:42:28 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -63,6 +63,9 @@
#include <openssl/evp.h>
#include <openssl/objects.h>
#include "asn1_locl.h"
#include "evp_locl.h"
int
EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
{
@@ -237,6 +240,23 @@ EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data)
ctx->app_data = data;
}
void *
EVP_CIPHER_CTX_get_cipher_data(const EVP_CIPHER_CTX *ctx)
{
return ctx->cipher_data;
}
void *
EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX *ctx, void *cipher_data)
{
void *old_cipher_data;
old_cipher_data = ctx->cipher_data;
ctx->cipher_data = cipher_data;
return old_cipher_data;
}
int
EVP_CIPHER_iv_length(const EVP_CIPHER *cipher)
{
@@ -249,6 +269,12 @@ EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx)
return ctx->cipher->iv_len;
}
unsigned char *
EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX *ctx)
{
return ctx->buf;
}
int
EVP_CIPHER_key_length(const EVP_CIPHER *cipher)
{
@@ -345,6 +371,114 @@ EVP_MD_flags(const EVP_MD *md)
return md->flags;
}
EVP_MD *
EVP_MD_meth_new(int md_type, int pkey_type)
{
EVP_MD *md;
if ((md = calloc(1, sizeof(*md))) == NULL)
return NULL;
md->type = md_type;
md->pkey_type = pkey_type;
return md;
}
EVP_MD *
EVP_MD_meth_dup(const EVP_MD *md)
{
EVP_MD *to;
if ((to = EVP_MD_meth_new(md->type, md->pkey_type)) == NULL)
return NULL;
memcpy(to, md, sizeof(*to));
return to;
}
void
EVP_MD_meth_free(EVP_MD *md)
{
freezero(md, sizeof(*md));
}
int
EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize)
{
md->block_size = blocksize;
return 1;
}
int
EVP_MD_meth_set_result_size(EVP_MD *md, int result_size)
{
md->md_size = result_size;
return 1;
}
int
EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize)
{
md->ctx_size = datasize;
return 1;
}
int
EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags)
{
md->flags = flags;
return 1;
}
int
EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx))
{
md->init = init;
return 1;
}
int
EVP_MD_meth_set_update(EVP_MD *md,
int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count))
{
md->update = update;
return 1;
}
int
EVP_MD_meth_set_final(EVP_MD *md,
int (*final)(EVP_MD_CTX *ctx, unsigned char *md))
{
md->final = final;
return 1;
}
int
EVP_MD_meth_set_copy(EVP_MD *md,
int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from))
{
md->copy = copy;
return 1;
}
int
EVP_MD_meth_set_cleanup(EVP_MD *md,
int (*cleanup)(EVP_MD_CTX *ctx))
{
md->cleanup = cleanup;
return 1;
}
int
EVP_MD_meth_set_ctrl(EVP_MD *md,
int (*ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2))
{
md->md_ctrl = ctrl;
return 1;
}
const EVP_MD *
EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
{
@@ -353,6 +487,41 @@ EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
return ctx->digest;
}
void *
EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx)
{
return ctx->md_data;
}
EVP_PKEY_CTX *
EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx)
{
return ctx->pctx;
}
void
EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx)
{
if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX)) {
EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
} else {
EVP_PKEY_CTX_free(ctx->pctx);
}
ctx->pctx = pctx;
if (pctx != NULL) {
/*
* For unclear reasons it was decided that the caller keeps
* ownership of pctx. So a flag was invented to make sure we
* don't free it in EVP_MD_CTX_cleanup(). We also need to
* unset it in EVP_MD_CTX_copy_ex(). Fortunately, the flag
* isn't public...
*/
EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
}
}
void
EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)
{

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: evp_locl.h,v 1.16 2019/10/29 07:52:17 jsing Exp $ */
/* $OpenBSD: evp_locl.h,v 1.22 2022/01/14 08:38:05 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@@ -56,8 +56,134 @@
*
*/
#ifndef HEADER_EVP_LOCL_H
#define HEADER_EVP_LOCL_H
__BEGIN_HIDDEN_DECLS
/*
* Don't free md_ctx->pctx in EVP_MD_CTX_cleanup(). Needed for ownership
* handling in EVP_MD_CTX_set_pkey_ctx().
*/
#define EVP_MD_CTX_FLAG_KEEP_PKEY_CTX 0x0400
typedef int evp_sign_method(int type, const unsigned char *m,
unsigned int m_length, unsigned char *sigret, unsigned int *siglen,
void *key);
typedef int evp_verify_method(int type, const unsigned char *m,
unsigned int m_length, const unsigned char *sigbuf, unsigned int siglen,
void *key);
/* Type needs to be a bit field
* Sub-type needs to be for variations on the method, as in, can it do
* arbitrary encryption.... */
struct evp_pkey_st {
int type;
int save_type;
int references;
const EVP_PKEY_ASN1_METHOD *ameth;
ENGINE *engine;
union {
char *ptr;
#ifndef OPENSSL_NO_RSA
struct rsa_st *rsa; /* RSA */
#endif
#ifndef OPENSSL_NO_DSA
struct dsa_st *dsa; /* DSA */
#endif
#ifndef OPENSSL_NO_DH
struct dh_st *dh; /* DH */
#endif
#ifndef OPENSSL_NO_EC
struct ec_key_st *ec; /* ECC */
#endif
#ifndef OPENSSL_NO_GOST
struct gost_key_st *gost; /* GOST */
#endif
} pkey;
int save_parameters;
STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
} /* EVP_PKEY */;
struct env_md_st {
int type;
int pkey_type;
int md_size;
unsigned long flags;
int (*init)(EVP_MD_CTX *ctx);
int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);
int (*final)(EVP_MD_CTX *ctx, unsigned char *md);
int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from);
int (*cleanup)(EVP_MD_CTX *ctx);
int block_size;
int ctx_size; /* how big does the ctx->md_data need to be */
/* control function */
int (*md_ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2);
} /* EVP_MD */;
struct env_md_ctx_st {
const EVP_MD *digest;
ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */
unsigned long flags;
void *md_data;
/* Public key context for sign/verify */
EVP_PKEY_CTX *pctx;
/* Update function: usually copied from EVP_MD */
int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);
} /* EVP_MD_CTX */;
struct evp_cipher_st {
int nid;
int block_size;
int key_len; /* Default value for variable length ciphers */
int iv_len;
unsigned long flags; /* Various flags */
int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key,
const unsigned char *iv, int enc); /* init key */
int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t inl);/* encrypt/decrypt data */
int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */
int ctx_size; /* how big ctx->cipher_data needs to be */
int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */
int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */
int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */
void *app_data; /* Application data */
} /* EVP_CIPHER */;
struct evp_cipher_ctx_st {
const EVP_CIPHER *cipher;
ENGINE *engine; /* functional reference if 'cipher' is ENGINE-provided */
int encrypt; /* encrypt or decrypt */
int buf_len; /* number we have left */
unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */
unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */
unsigned char buf[EVP_MAX_BLOCK_LENGTH];/* saved partial block */
int num; /* used by cfb/ofb/ctr mode */
void *app_data; /* application stuff */
int key_len; /* May change for variable length cipher */
unsigned long flags; /* Various flags */
void *cipher_data; /* per EVP data */
int final_used;
int block_mask;
unsigned char final[EVP_MAX_BLOCK_LENGTH];/* possible final block */
} /* EVP_CIPHER_CTX */;
struct evp_Encode_Ctx_st {
int num; /* number saved in a partial encode/decode */
int length; /* The length is either the output line length
* (in input bytes) or the shortest input line
* length that is ok. Once decoding begins,
* the length is adjusted up each time a longer
* line is decoded */
unsigned char enc_data[80]; /* data to encode */
int line_num; /* number read on current line */
int expect_nl;
} /* EVP_ENCODE_CTX */;
/* Macros to code block cipher wrappers */
/* Wrapper functions for each cipher mode */
@@ -338,6 +464,10 @@ struct evp_pkey_method_st {
int (*ctrl)(EVP_PKEY_CTX *ctx, int type, int p1, void *p2);
int (*ctrl_str)(EVP_PKEY_CTX *ctx, const char *type, const char *value);
int (*check)(EVP_PKEY *pkey);
int (*public_check)(EVP_PKEY *pkey);
int (*param_check)(EVP_PKEY *pkey);
} /* EVP_PKEY_METHOD */;
void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx);
@@ -367,6 +497,16 @@ struct evp_aead_st {
const unsigned char *ad, size_t ad_len);
};
/* An EVP_AEAD_CTX represents an AEAD algorithm configured with a specific key
* and message-independent IV. */
struct evp_aead_ctx_st {
const EVP_AEAD *aead;
/* aead_state is an opaque pointer to the AEAD specific state. */
void *aead_state;
};
int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name);
__END_HIDDEN_DECLS
#endif /* !HEADER_EVP_LOCL_H */

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: evp_pkey.c,v 1.23 2018/08/24 20:26:03 tb Exp $ */
/* $OpenBSD: evp_pkey.c,v 1.24 2021/12/12 21:30:13 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 1999.
*/
@@ -63,6 +63,7 @@
#include <openssl/x509.h>
#include "asn1_locl.h"
#include "evp_locl.h"
/* Extract a private key from a PKCS8 structure */

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: m_gost2814789.c,v 1.2 2014/11/09 23:06:50 miod Exp $ */
/* $OpenBSD: m_gost2814789.c,v 1.3 2021/12/12 21:30:13 tb Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -48,6 +48,7 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
#include <openssl/opensslconf.h>
#ifndef OPENSSL_NO_GOST
@@ -56,6 +57,8 @@
#include <openssl/gost.h>
#include <openssl/objects.h>
#include "evp_locl.h"
static int
gost2814789_init(EVP_MD_CTX *ctx)
{

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: m_gostr341194.c,v 1.2 2014/11/09 23:06:50 miod Exp $ */
/* $OpenBSD: m_gostr341194.c,v 1.4 2022/01/14 08:38:05 tb Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -48,6 +48,7 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
#include <stdio.h>
#include <openssl/opensslconf.h>
@@ -58,6 +59,8 @@
#include <openssl/gost.h>
#include <openssl/objects.h>
#include "evp_locl.h"
static int
gostr341194_init(EVP_MD_CTX *ctx)
{
@@ -81,7 +84,7 @@ static const EVP_MD gostr341194_md = {
.type = NID_id_GostR3411_94,
.pkey_type = NID_undef,
.md_size = GOSTR341194_LENGTH,
.flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE,
.flags = 0,
.init = gostr341194_init,
.update = gostr341194_update,
.final = gostr341194_final,

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: m_md4.c,v 1.16 2015/09/14 01:45:03 doug Exp $ */
/* $OpenBSD: m_md4.c,v 1.18 2022/01/14 08:38:05 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -71,6 +71,8 @@
#include <openssl/rsa.h>
#endif
#include "evp_locl.h"
static int
init(EVP_MD_CTX *ctx)
{
@@ -99,13 +101,6 @@ static const EVP_MD md4_md = {
.final = final,
.copy = NULL,
.cleanup = NULL,
#ifndef OPENSSL_NO_RSA
.sign = (evp_sign_method *)RSA_sign,
.verify = (evp_verify_method *)RSA_verify,
.required_pkey_type = {
EVP_PKEY_RSA, EVP_PKEY_RSA2, 0, 0,
},
#endif
.block_size = MD4_CBLOCK,
.ctx_size = sizeof(EVP_MD *) + sizeof(MD4_CTX),
};

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: m_md5.c,v 1.15 2014/07/13 09:30:02 miod Exp $ */
/* $OpenBSD: m_md5.c,v 1.17 2022/01/14 08:38:06 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -71,6 +71,8 @@
#include <openssl/rsa.h>
#endif
#include "evp_locl.h"
static int
init(EVP_MD_CTX *ctx)
{
@@ -99,13 +101,6 @@ static const EVP_MD md5_md = {
.final = final,
.copy = NULL,
.cleanup = NULL,
#ifndef OPENSSL_NO_RSA
.sign = (evp_sign_method *)RSA_sign,
.verify = (evp_verify_method *)RSA_verify,
.required_pkey_type = {
EVP_PKEY_RSA, EVP_PKEY_RSA2, 0, 0,
},
#endif
.block_size = MD5_CBLOCK,
.ctx_size = sizeof(EVP_MD *) + sizeof(MD5_CTX),
};

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: m_md5_sha1.c,v 1.2 2018/08/10 17:30:29 jsing Exp $ */
/* $OpenBSD: m_md5_sha1.c,v 1.4 2022/01/14 08:38:06 tb Exp $ */
/*
* Copyright (c) 2017 Joel Sing <jsing@openbsd.org>
*
@@ -24,6 +24,8 @@
#include <openssl/rsa.h>
#endif
#include "evp_locl.h"
struct md5_sha1_ctx {
MD5_CTX md5;
SHA_CTX sha1;
@@ -78,13 +80,6 @@ static const EVP_MD md5_sha1_md = {
.final = md5_sha1_final,
.block_size = MD5_CBLOCK, /* MD5_CBLOCK == SHA_CBLOCK */
.ctx_size = sizeof(EVP_MD *) + sizeof(struct md5_sha1_ctx),
#ifndef OPENSSL_NO_RSA
.sign = (evp_sign_method *)RSA_sign,
.verify = (evp_verify_method *)RSA_verify,
.required_pkey_type = {
EVP_PKEY_RSA, EVP_PKEY_RSA2, 0, 0,
},
#endif
};
const EVP_MD *

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: m_null.c,v 1.9 2014/07/11 08:44:48 jsing Exp $ */
/* $OpenBSD: m_null.c,v 1.11 2022/01/14 08:38:06 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -62,6 +62,8 @@
#include <openssl/objects.h>
#include <openssl/x509.h>
#include "evp_locl.h"
static int
init(EVP_MD_CTX *ctx)
{
@@ -90,11 +92,6 @@ static const EVP_MD null_md = {
.final = final,
.copy = NULL,
.cleanup = NULL,
.sign = NULL,
.verify = NULL,
.required_pkey_type = {
0, 0, 0, 0,
},
.block_size = 0,
.ctx_size = sizeof(EVP_MD *),
};

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: m_ripemd.c,v 1.12 2014/07/13 09:30:02 miod Exp $ */
/* $OpenBSD: m_ripemd.c,v 1.14 2022/01/14 08:38:06 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -71,6 +71,8 @@
#include <openssl/rsa.h>
#endif
#include "evp_locl.h"
static int
init(EVP_MD_CTX *ctx)
{
@@ -99,13 +101,6 @@ static const EVP_MD ripemd160_md = {
.final = final,
.copy = NULL,
.cleanup = NULL,
#ifndef OPENSSL_NO_RSA
.sign = (evp_sign_method *)RSA_sign,
.verify = (evp_verify_method *)RSA_verify,
.required_pkey_type = {
EVP_PKEY_RSA, EVP_PKEY_RSA2, 0, 0,
},
#endif
.block_size = RIPEMD160_CBLOCK,
.ctx_size = sizeof(EVP_MD *) + sizeof(RIPEMD160_CTX),
};

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: m_sha1.c,v 1.17 2014/07/11 08:44:48 jsing Exp $ */
/* $OpenBSD: m_sha1.c,v 1.19 2022/01/14 08:38:06 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -70,6 +70,8 @@
#include <openssl/rsa.h>
#endif
#include "evp_locl.h"
static int
init(EVP_MD_CTX *ctx)
{
@@ -92,19 +94,12 @@ static const EVP_MD sha1_md = {
.type = NID_sha1,
.pkey_type = NID_sha1WithRSAEncryption,
.md_size = SHA_DIGEST_LENGTH,
.flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT,
.flags = EVP_MD_FLAG_DIGALGID_ABSENT,
.init = init,
.update = update,
.final = final,
.copy = NULL,
.cleanup = NULL,
#ifndef OPENSSL_NO_RSA
.sign = (evp_sign_method *)RSA_sign,
.verify = (evp_verify_method *)RSA_verify,
.required_pkey_type = {
EVP_PKEY_RSA, EVP_PKEY_RSA2, 0, 0,
},
#endif
.block_size = SHA_CBLOCK,
.ctx_size = sizeof(EVP_MD *) + sizeof(SHA_CTX),
};
@@ -149,19 +144,12 @@ static const EVP_MD sha224_md = {
.type = NID_sha224,
.pkey_type = NID_sha224WithRSAEncryption,
.md_size = SHA224_DIGEST_LENGTH,
.flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT,
.flags = EVP_MD_FLAG_DIGALGID_ABSENT,
.init = init224,
.update = update256,
.final = final256,
.copy = NULL,
.cleanup = NULL,
#ifndef OPENSSL_NO_RSA
.sign = (evp_sign_method *)RSA_sign,
.verify = (evp_verify_method *)RSA_verify,
.required_pkey_type = {
EVP_PKEY_RSA, EVP_PKEY_RSA2, 0, 0,
},
#endif
.block_size = SHA256_CBLOCK,
.ctx_size = sizeof(EVP_MD *) + sizeof(SHA256_CTX),
};
@@ -176,19 +164,12 @@ static const EVP_MD sha256_md = {
.type = NID_sha256,
.pkey_type = NID_sha256WithRSAEncryption,
.md_size = SHA256_DIGEST_LENGTH,
.flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT,
.flags = EVP_MD_FLAG_DIGALGID_ABSENT,
.init = init256,
.update = update256,
.final = final256,
.copy = NULL,
.cleanup = NULL,
#ifndef OPENSSL_NO_RSA
.sign = (evp_sign_method *)RSA_sign,
.verify = (evp_verify_method *)RSA_verify,
.required_pkey_type = {
EVP_PKEY_RSA, EVP_PKEY_RSA2, 0, 0,
},
#endif
.block_size = SHA256_CBLOCK,
.ctx_size = sizeof(EVP_MD *) + sizeof(SHA256_CTX),
};
@@ -229,19 +210,12 @@ static const EVP_MD sha384_md = {
.type = NID_sha384,
.pkey_type = NID_sha384WithRSAEncryption,
.md_size = SHA384_DIGEST_LENGTH,
.flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT,
.flags = EVP_MD_FLAG_DIGALGID_ABSENT,
.init = init384,
.update = update512,
.final = final512,
.copy = NULL,
.cleanup = NULL,
#ifndef OPENSSL_NO_RSA
.sign = (evp_sign_method *)RSA_sign,
.verify = (evp_verify_method *)RSA_verify,
.required_pkey_type = {
EVP_PKEY_RSA, EVP_PKEY_RSA2, 0, 0,
},
#endif
.block_size = SHA512_CBLOCK,
.ctx_size = sizeof(EVP_MD *) + sizeof(SHA512_CTX),
};
@@ -256,19 +230,12 @@ static const EVP_MD sha512_md = {
.type = NID_sha512,
.pkey_type = NID_sha512WithRSAEncryption,
.md_size = SHA512_DIGEST_LENGTH,
.flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT,
.flags = EVP_MD_FLAG_DIGALGID_ABSENT,
.init = init512,
.update = update512,
.final = final512,
.copy = NULL,
.cleanup = NULL,
#ifndef OPENSSL_NO_RSA
.sign = (evp_sign_method *)RSA_sign,
.verify = (evp_verify_method *)RSA_verify,
.required_pkey_type = {
EVP_PKEY_RSA, EVP_PKEY_RSA2, 0, 0,
},
#endif
.block_size = SHA512_CBLOCK,
.ctx_size = sizeof(EVP_MD *) + sizeof(SHA512_CTX),
};

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: m_sigver.c,v 1.7 2018/05/13 06:35:10 tb Exp $ */
/* $OpenBSD: m_sigver.c,v 1.9 2021/05/09 14:25:40 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
@@ -74,15 +74,17 @@ do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type,
if (ctx->pctx == NULL)
return 0;
if (type == NULL) {
int def_nid;
if (EVP_PKEY_get_default_digest_nid(pkey, &def_nid) > 0)
type = EVP_get_digestbynid(def_nid);
}
if (!(ctx->pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM)) {
if (type == NULL) {
int def_nid;
if (EVP_PKEY_get_default_digest_nid(pkey, &def_nid) > 0)
type = EVP_get_digestbynid(def_nid);
}
if (type == NULL) {
EVPerror(EVP_R_NO_DEFAULT_DIGEST);
return 0;
if (type == NULL) {
EVPerror(EVP_R_NO_DEFAULT_DIGEST);
return 0;
}
}
if (ver) {
@@ -105,6 +107,8 @@ do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type,
return 0;
if (pctx)
*pctx = ctx->pctx;
if (ctx->pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM)
return 1;
if (!EVP_DigestInit_ex(ctx, type, e))
return 0;
return 1;
@@ -127,7 +131,24 @@ EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type,
int
EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen)
{
int sctx, r = 0;
EVP_PKEY_CTX *pctx = ctx->pctx;
int sctx;
int r = 0;
if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) {
EVP_PKEY_CTX *dctx;
if (sigret == NULL)
return pctx->pmeth->signctx(pctx, sigret, siglen, ctx);
/* XXX - support EVP_MD_CTX_FLAG_FINALISE? */
if ((dctx = EVP_PKEY_CTX_dup(ctx->pctx)) == NULL)
return 0;
r = dctx->pmeth->signctx(dctx, sigret, siglen, ctx);
EVP_PKEY_CTX_free(dctx);
return r;
}
if (ctx->pctx->pmeth->signctx)
sctx = 1;
@@ -165,6 +186,18 @@ EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen)
return 1;
}
int
EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen,
const unsigned char *tbs, size_t tbslen)
{
if (sigret != NULL) {
if (EVP_DigestSignUpdate(ctx, tbs, tbslen) <= 0)
return 0;
}
return EVP_DigestSignFinal(ctx, sigret, siglen);
}
int
EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen)
{
@@ -191,3 +224,13 @@ EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen)
return r;
return EVP_PKEY_verify(ctx->pctx, sig, siglen, md, mdlen);
}
int
EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret, size_t siglen,
const unsigned char *tbs, size_t tbslen)
{
if (EVP_DigestVerifyUpdate(ctx, tbs, tbslen) <= 0)
return -1;
return EVP_DigestVerifyFinal(ctx, sigret, siglen);
}

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: m_sm3.c,v 1.1 2018/11/11 06:53:31 tb Exp $ */
/* $OpenBSD: m_sm3.c,v 1.3 2022/01/14 08:38:06 tb Exp $ */
/*
* Copyright (c) 2018, Ribose Inc
*
@@ -25,6 +25,8 @@
#include <openssl/rsa.h>
#endif
#include "evp_locl.h"
static int
sm3_init(EVP_MD_CTX *ctx)
{
@@ -47,19 +49,12 @@ static const EVP_MD sm3_md = {
.type = NID_sm3,
.pkey_type = NID_sm3WithRSAEncryption,
.md_size = SM3_DIGEST_LENGTH,
.flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT,
.flags = EVP_MD_FLAG_DIGALGID_ABSENT,
.init = sm3_init,
.update = sm3_update,
.final = sm3_final,
.copy = NULL,
.cleanup = NULL,
#ifndef OPENSSL_NO_RSA
.sign = (evp_sign_method *)RSA_sign,
.verify = (evp_verify_method *)RSA_verify,
.required_pkey_type = {
EVP_PKEY_RSA, EVP_PKEY_RSA2, 0, 0,
},
#endif
.block_size = SM3_CBLOCK,
.ctx_size = sizeof(EVP_MD *) + sizeof(SM3_CTX),
};

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: m_streebog.c,v 1.2 2014/11/09 23:06:50 miod Exp $ */
/* $OpenBSD: m_streebog.c,v 1.4 2022/01/14 08:38:06 tb Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -57,6 +57,8 @@
#include <openssl/gost.h>
#include <openssl/objects.h>
#include "evp_locl.h"
static int
streebog_init256(EVP_MD_CTX *ctx)
{
@@ -97,7 +99,7 @@ static const EVP_MD streebog256_md = {
.type = NID_id_tc26_gost3411_2012_256,
.pkey_type = NID_undef,
.md_size = STREEBOG256_LENGTH,
.flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE,
.flags = 0,
.init = streebog_init256,
.update = streebog_update256,
.final = streebog_final256,
@@ -109,7 +111,7 @@ static const EVP_MD streebog512_md = {
.type = NID_id_tc26_gost3411_2012_512,
.pkey_type = NID_undef,
.md_size = STREEBOG512_LENGTH,
.flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE,
.flags = 0,
.init = streebog_init512,
.update = streebog_update512,
.final = streebog_final512,

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: m_wp.c,v 1.8 2014/07/13 09:30:02 miod Exp $ */
/* $OpenBSD: m_wp.c,v 1.10 2022/01/14 08:38:06 tb Exp $ */
#include <stdio.h>
@@ -11,6 +11,8 @@
#include <openssl/x509.h>
#include <openssl/whrlpool.h>
#include "evp_locl.h"
static int
init(EVP_MD_CTX *ctx)
{
@@ -39,11 +41,6 @@ static const EVP_MD whirlpool_md = {
.final = final,
.copy = NULL,
.cleanup = NULL,
.sign = NULL,
.verify = NULL,
.required_pkey_type = {
0, 0, 0, 0,
},
.block_size = WHIRLPOOL_BBLOCK / 8,
.ctx_size = sizeof(EVP_MD *) + sizeof(WHIRLPOOL_CTX),
};

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: names.c,v 1.14 2018/03/17 16:20:01 beck Exp $ */
/* $OpenBSD: names.c,v 1.15 2021/12/12 21:30:13 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -62,6 +62,8 @@
#include <openssl/objects.h>
#include <openssl/x509.h>
#include "evp_locl.h"
int
EVP_add_cipher(const EVP_CIPHER *c)
{

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: p5_crpt.c,v 1.19 2020/01/12 07:11:13 inoguchi Exp $ */
/* $OpenBSD: p5_crpt.c,v 1.20 2021/12/12 21:30:13 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 1999.
*/
@@ -64,6 +64,8 @@
#include <openssl/evp.h>
#include <openssl/x509.h>
#include "evp_locl.h"
/* Doesn't do anything now: Builtin PBE algorithms in static table.
*/

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: p5_crpt2.c,v 1.23 2017/01/29 17:49:23 beck Exp $ */
/* $OpenBSD: p5_crpt2.c,v 1.24 2021/12/12 21:27:37 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 1999.
*/
@@ -70,6 +70,7 @@
#include <openssl/x509.h>
#include "evp_locl.h"
#include "hmac_local.h"
/* This is an implementation of PKCS#5 v2.0 password based encryption key
* derivation function PBKDF2.

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: p_dec.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
/* $OpenBSD: p_dec.c,v 1.12 2021/12/12 21:30:13 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -69,6 +69,8 @@
#include <openssl/rsa.h>
#endif
#include "evp_locl.h"
int
EVP_PKEY_decrypt_old(unsigned char *key, const unsigned char *ek, int ekl,
EVP_PKEY *priv)

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: p_enc.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
/* $OpenBSD: p_enc.c,v 1.12 2021/12/12 21:30:13 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -69,6 +69,8 @@
#include <openssl/rsa.h>
#endif
#include "evp_locl.h"
int
EVP_PKEY_encrypt_old(unsigned char *ek, const unsigned char *key, int key_len,
EVP_PKEY *pubk)

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: p_lib.c,v 1.25 2019/03/17 18:17:45 tb Exp $ */
/* $OpenBSD: p_lib.c,v 1.28 2022/01/20 11:06:24 inoguchi Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -61,6 +61,7 @@
#include <openssl/opensslconf.h>
#include <openssl/bn.h>
#include <openssl/cmac.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/objects.h>
@@ -81,6 +82,7 @@
#endif
#include "asn1_locl.h"
#include "evp_locl.h"
static void EVP_PKEY_free_it(EVP_PKEY *x);
@@ -216,10 +218,14 @@ EVP_PKEY_up_ref(EVP_PKEY *pkey)
*/
static int
pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len)
pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, int len)
{
const EVP_PKEY_ASN1_METHOD *ameth;
ENGINE *e = NULL;
ENGINE **eptr = NULL;
if (e == NULL)
eptr = &e;
if (pkey) {
if (pkey->pkey.ptr)
EVP_PKEY_free_it(pkey);
@@ -234,11 +240,11 @@ pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len)
#endif
}
if (str)
ameth = EVP_PKEY_asn1_find_str(&e, str, len);
ameth = EVP_PKEY_asn1_find_str(eptr, str, len);
else
ameth = EVP_PKEY_asn1_find(&e, type);
ameth = EVP_PKEY_asn1_find(eptr, type);
#ifndef OPENSSL_NO_ENGINE
if (pkey == NULL)
if (pkey == NULL && eptr != NULL)
ENGINE_finish(e);
#endif
if (!ameth) {
@@ -258,13 +264,43 @@ pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len)
int
EVP_PKEY_set_type(EVP_PKEY *pkey, int type)
{
return pkey_set_type(pkey, type, NULL, -1);
return pkey_set_type(pkey, NULL, type, NULL, -1);
}
EVP_PKEY *
EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv, size_t len,
const EVP_CIPHER *cipher)
{
EVP_PKEY *ret = NULL;
CMAC_CTX *cmctx = NULL;
if ((ret = EVP_PKEY_new()) == NULL)
goto err;
if ((cmctx = CMAC_CTX_new()) == NULL)
goto err;
if (!pkey_set_type(ret, e, EVP_PKEY_CMAC, NULL, -1))
goto err;
if (!CMAC_Init(cmctx, priv, len, cipher, e)) {
EVPerror(EVP_R_KEY_SETUP_FAILED);
goto err;
}
ret->pkey.ptr = (char *)cmctx;
return ret;
err:
EVP_PKEY_free(ret);
CMAC_CTX_free(cmctx);
return NULL;
}
int
EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len)
{
return pkey_set_type(pkey, EVP_PKEY_NONE, str, len);
return pkey_set_type(pkey, NULL, EVP_PKEY_NONE, str, len);
}
int
@@ -490,7 +526,8 @@ EVP_PKEY_free_it(EVP_PKEY *x)
static int
unsup_alg(BIO *out, const EVP_PKEY *pkey, int indent, const char *kstr)
{
BIO_indent(out, indent, 128);
if (!BIO_indent(out, indent, 128))
return 0;
BIO_printf(out, "%s algorithm \"%s\" unsupported\n",
kstr, OBJ_nid2ln(pkey->type));
return 1;

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: p_open.c,v 1.19 2017/05/02 03:59:44 deraadt Exp $ */
/* $OpenBSD: p_open.c,v 1.20 2021/12/12 21:30:13 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -69,6 +69,8 @@
#include <openssl/rsa.h>
#include <openssl/x509.h>
#include "evp_locl.h"
int
EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
const unsigned char *ek, int ekl, const unsigned char *iv, EVP_PKEY *priv)

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: p_sign.c,v 1.14 2017/01/29 17:49:23 beck Exp $ */
/* $OpenBSD: p_sign.c,v 1.16 2022/01/14 08:38:06 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -63,15 +63,18 @@
#include <openssl/objects.h>
#include <openssl/x509.h>
#include "evp_locl.h"
int
EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
EVP_PKEY *pkey)
{
unsigned char m[EVP_MAX_MD_SIZE];
unsigned int m_len;
int i = 0, ok = 0, v;
EVP_MD_CTX tmp_ctx;
EVP_PKEY_CTX *pkctx = NULL;
size_t sltmp;
int ret = 0;
*siglen = 0;
EVP_MD_CTX_init(&tmp_ctx);
@@ -81,43 +84,21 @@ EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
goto err;
EVP_MD_CTX_cleanup(&tmp_ctx);
if (ctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) {
size_t sltmp = (size_t)EVP_PKEY_size(pkey);
i = 0;
pkctx = EVP_PKEY_CTX_new(pkey, NULL);
if (!pkctx)
goto err;
if (EVP_PKEY_sign_init(pkctx) <= 0)
goto err;
if (EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0)
goto err;
if (EVP_PKEY_sign(pkctx, sigret, &sltmp, m, m_len) <= 0)
goto err;
*siglen = sltmp;
i = 1;
err:
EVP_PKEY_CTX_free(pkctx);
return i;
}
sltmp = (size_t)EVP_PKEY_size(pkey);
for (i = 0; i < 4; i++) {
v = ctx->digest->required_pkey_type[i];
if (v == 0)
break;
if (pkey->type == v) {
ok = 1;
break;
}
}
if (!ok) {
EVPerror(EVP_R_WRONG_PUBLIC_KEY_TYPE);
return (0);
}
if ((pkctx = EVP_PKEY_CTX_new(pkey, NULL)) == NULL)
goto err;
if (EVP_PKEY_sign_init(pkctx) <= 0)
goto err;
if (EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0)
goto err;
if (EVP_PKEY_sign(pkctx, sigret, &sltmp, m, m_len) <= 0)
goto err;
*siglen = sltmp;
if (ctx->digest->sign == NULL) {
EVPerror(EVP_R_NO_SIGN_FUNCTION_CONFIGURED);
return (0);
}
return(ctx->digest->sign(ctx->digest->type, m, m_len, sigret, siglen,
pkey->pkey.ptr));
ret = 1;
err:
EVP_PKEY_CTX_free(pkctx);
return ret;
}

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: p_verify.c,v 1.13 2017/01/29 17:49:23 beck Exp $ */
/* $OpenBSD: p_verify.c,v 1.15 2022/01/14 08:38:06 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -63,15 +63,17 @@
#include <openssl/objects.h>
#include <openssl/x509.h>
#include "evp_locl.h"
int
EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf,
unsigned int siglen, EVP_PKEY *pkey)
{
unsigned char m[EVP_MAX_MD_SIZE];
unsigned int m_len;
int i = 0, ok = 0, v;
EVP_MD_CTX tmp_ctx;
EVP_PKEY_CTX *pkctx = NULL;
int ret = 0;
EVP_MD_CTX_init(&tmp_ctx);
if (!EVP_MD_CTX_copy_ex(&tmp_ctx, ctx))
@@ -80,39 +82,16 @@ EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf,
goto err;
EVP_MD_CTX_cleanup(&tmp_ctx);
if (ctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) {
i = -1;
pkctx = EVP_PKEY_CTX_new(pkey, NULL);
if (!pkctx)
goto err;
if (EVP_PKEY_verify_init(pkctx) <= 0)
goto err;
if (EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0)
goto err;
i = EVP_PKEY_verify(pkctx, sigbuf, siglen, m, m_len);
err:
EVP_PKEY_CTX_free(pkctx);
return i;
}
ret = -1;
if ((pkctx = EVP_PKEY_CTX_new(pkey, NULL)) == NULL)
goto err;
if (EVP_PKEY_verify_init(pkctx) <= 0)
goto err;
if (EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0)
goto err;
ret = EVP_PKEY_verify(pkctx, sigbuf, siglen, m, m_len);
for (i = 0; i < 4; i++) {
v = ctx->digest->required_pkey_type[i];
if (v == 0)
break;
if (pkey->type == v) {
ok = 1;
break;
}
}
if (!ok) {
EVPerror(EVP_R_WRONG_PUBLIC_KEY_TYPE);
return (-1);
}
if (ctx->digest->verify == NULL) {
EVPerror(EVP_R_NO_VERIFY_FUNCTION_CONFIGURED);
return (0);
}
return(ctx->digest->verify(ctx->digest->type, m, m_len,
sigbuf, siglen, pkey->pkey.ptr));
err:
EVP_PKEY_CTX_free(pkctx);
return ret;
}

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: pmeth_gn.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */
/* $OpenBSD: pmeth_gn.c,v 1.10 2022/01/10 12:10:26 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
@@ -64,6 +64,8 @@
#include <openssl/evp.h>
#include <openssl/objects.h>
#include "asn1_locl.h"
#include "bn_lcl.h"
#include "evp_locl.h"
int
@@ -187,7 +189,7 @@ trans_cb(int a, int b, BN_GENCB *gcb)
void
evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx)
{
BN_GENCB_set(cb, trans_cb, ctx)
BN_GENCB_set(cb, trans_cb, ctx);
}
int
@@ -221,3 +223,66 @@ merr:
EVP_PKEY_CTX_free(mac_ctx);
return mac_key;
}
int
EVP_PKEY_check(EVP_PKEY_CTX *ctx)
{
EVP_PKEY *pkey;
if ((pkey = ctx->pkey) == NULL) {
EVPerror(EVP_R_NO_KEY_SET);
return 0;
}
if (ctx->pmeth->check != NULL)
return ctx->pmeth->check(pkey);
if (pkey->ameth == NULL || pkey->ameth->pkey_check == NULL) {
EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
return -2;
}
return pkey->ameth->pkey_check(pkey);
}
int
EVP_PKEY_public_check(EVP_PKEY_CTX *ctx)
{
EVP_PKEY *pkey;
if ((pkey = ctx->pkey) == NULL) {
EVPerror(EVP_R_NO_KEY_SET);
return 0;
}
if (ctx->pmeth->public_check != NULL)
return ctx->pmeth->public_check(pkey);
if (pkey->ameth == NULL || pkey->ameth->pkey_public_check == NULL) {
EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
return -2;
}
return pkey->ameth->pkey_public_check(pkey);
}
int
EVP_PKEY_param_check(EVP_PKEY_CTX *ctx)
{
EVP_PKEY *pkey;
if ((pkey = ctx->pkey) == NULL) {
EVPerror(EVP_R_NO_KEY_SET);
return 0;
}
if (ctx->pmeth->param_check != NULL)
return ctx->pmeth->param_check(pkey);
if (pkey->ameth == NULL || pkey->ameth->pkey_param_check == NULL) {
EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
return -2;
}
return pkey->ameth->pkey_param_check(pkey);
}

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: pmeth_lib.c,v 1.16 2019/11/01 15:08:57 jsing Exp $ */
/* $OpenBSD: pmeth_lib.c,v 1.20 2022/01/10 12:10:26 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
@@ -224,39 +224,12 @@ EVP_PKEY_meth_new(int id, int flags)
{
EVP_PKEY_METHOD *pmeth;
pmeth = calloc(1, sizeof(EVP_PKEY_METHOD));
if (!pmeth)
if ((pmeth = calloc(1, sizeof(EVP_PKEY_METHOD))) == NULL)
return NULL;
pmeth->pkey_id = id;
pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC;
pmeth->init = 0;
pmeth->copy = 0;
pmeth->cleanup = 0;
pmeth->paramgen_init = 0;
pmeth->paramgen = 0;
pmeth->keygen_init = 0;
pmeth->keygen = 0;
pmeth->sign_init = 0;
pmeth->sign = 0;
pmeth->verify_init = 0;
pmeth->verify = 0;
pmeth->verify_recover_init = 0;
pmeth->verify_recover = 0;
pmeth->signctx_init = 0;
pmeth->signctx = 0;
pmeth->verifyctx_init = 0;
pmeth->verifyctx = 0;
pmeth->encrypt_init = 0;
pmeth->encrypt = 0;
pmeth->decrypt_init = 0;
pmeth->decrypt = 0;
pmeth->derive_init = 0;
pmeth->derive = 0;
pmeth->ctrl = 0;
pmeth->ctrl_str = 0;
return pmeth;
}
@@ -272,42 +245,15 @@ EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, const EVP_PKEY_METHOD *meth)
void
EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src)
{
dst->init = src->init;
dst->copy = src->copy;
dst->cleanup = src->cleanup;
EVP_PKEY_METHOD preserve;
dst->paramgen_init = src->paramgen_init;
dst->paramgen = src->paramgen;
preserve.pkey_id = dst->pkey_id;
preserve.flags = dst->flags;
dst->keygen_init = src->keygen_init;
dst->keygen = src->keygen;
*dst = *src;
dst->sign_init = src->sign_init;
dst->sign = src->sign;
dst->verify_init = src->verify_init;
dst->verify = src->verify;
dst->verify_recover_init = src->verify_recover_init;
dst->verify_recover = src->verify_recover;
dst->signctx_init = src->signctx_init;
dst->signctx = src->signctx;
dst->verifyctx_init = src->verifyctx_init;
dst->verifyctx = src->verifyctx;
dst->encrypt_init = src->encrypt_init;
dst->encrypt = src->encrypt;
dst->decrypt_init = src->decrypt_init;
dst->decrypt = src->decrypt;
dst->derive_init = src->derive_init;
dst->derive = src->derive;
dst->ctrl = src->ctrl;
dst->ctrl_str = src->ctrl_str;
dst->pkey_id = preserve.pkey_id;
dst->flags = preserve.flags;
}
void
@@ -636,3 +582,23 @@ EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth,
pmeth->ctrl = ctrl;
pmeth->ctrl_str = ctrl_str;
}
void
EVP_PKEY_meth_set_check(EVP_PKEY_METHOD *pmeth, int (*check)(EVP_PKEY *pkey))
{
pmeth->check = check;
}
void
EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD *pmeth,
int (*public_check)(EVP_PKEY *pkey))
{
pmeth->public_check = public_check;
}
void
EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD *pmeth,
int (*param_check)(EVP_PKEY *pkey))
{
pmeth->param_check = param_check;
}