-/* $OpenBSD: ech_lib.c,v 1.18 2023/06/25 18:27:38 tb Exp $ */
+/* $OpenBSD: ech_lib.c,v 1.19 2023/06/25 18:45:56 tb Exp $ */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
static const ECDH_METHOD *default_ECDH_method = NULL;
-static void *ecdh_data_new(void);
-static void *ecdh_data_dup(void *);
-static void ecdh_data_free(void *);
-
void
ECDH_set_default_method(const ECDH_METHOD *meth)
{
return 0;
}
-static ECDH_DATA *
-ECDH_DATA_new_method(ENGINE *engine)
-{
- ECDH_DATA *ret;
-
- ret = malloc(sizeof(ECDH_DATA));
- if (ret == NULL) {
- ECDHerror(ERR_R_MALLOC_FAILURE);
- return (NULL);
- }
-
- ret->init = NULL;
-
- ret->meth = ECDH_get_default_method();
- ret->engine = engine;
-#ifndef OPENSSL_NO_ENGINE
- if (!ret->engine)
- ret->engine = ENGINE_get_default_ECDH();
- if (ret->engine) {
- ret->meth = ENGINE_get_ECDH(ret->engine);
- if (ret->meth == NULL) {
- ECDHerror(ERR_R_ENGINE_LIB);
- ENGINE_finish(ret->engine);
- free(ret);
- return NULL;
- }
- }
-#endif
-
- ret->flags = ret->meth->flags;
- CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ECDH, ret, &ret->ex_data);
- return (ret);
-}
-
-static void *
-ecdh_data_new(void)
-{
- return (void *)ECDH_DATA_new_method(NULL);
-}
-
-static void *
-ecdh_data_dup(void *data)
-{
- ECDH_DATA *r = (ECDH_DATA *)data;
-
- /* XXX: dummy operation */
- if (r == NULL)
- return NULL;
-
- return (void *)ecdh_data_new();
-}
-
-void
-ecdh_data_free(void *data)
-{
- ECDH_DATA *r = (ECDH_DATA *)data;
-
-#ifndef OPENSSL_NO_ENGINE
- ENGINE_finish(r->engine);
-#endif
-
- CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDH, r, &r->ex_data);
-
- freezero(r, sizeof(ECDH_DATA));
-}
-
-ECDH_DATA *
-ecdh_check(EC_KEY *key)
-{
- ECDH_DATA *ecdh_data;
-
- void *data = EC_KEY_get_key_method_data(key, ecdh_data_dup,
- ecdh_data_free, ecdh_data_free);
- if (data == NULL) {
- ecdh_data = (ECDH_DATA *)ecdh_data_new();
- if (ecdh_data == NULL)
- return NULL;
- data = EC_KEY_insert_key_method_data(key, (void *)ecdh_data,
- ecdh_data_dup, ecdh_data_free, ecdh_data_free);
- if (data != NULL) {
- /* Another thread raced us to install the key_method
- * data and won. */
- ecdh_data_free(ecdh_data);
- ecdh_data = (ECDH_DATA *)data;
- }
- } else
- ecdh_data = (ECDH_DATA *)data;
-
- return ecdh_data;
-}
-
int
ECDH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
-/* $OpenBSD: ech_local.h,v 1.3 2023/06/25 08:12:23 tb Exp $ */
+/* $OpenBSD: ech_local.h,v 1.4 2023/06/25 18:45:56 tb Exp $ */
/* ====================================================================
* Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved.
*
char *app_data;
};
-typedef struct ecdh_data_st {
- /* EC_KEY_METH_DATA part */
- int (*init)(EC_KEY *);
- /* method specific part */
- ENGINE *engine;
- int flags;
- const ECDH_METHOD *meth;
- CRYPTO_EX_DATA ex_data;
-} ECDH_DATA;
-
-ECDH_DATA *ecdh_check(EC_KEY *);
-
/*
* ECDH Key Derivation Function as defined in ANSI X9.63.
*/
-/* $OpenBSD: ecs_lib.c,v 1.19 2023/06/25 18:27:38 tb Exp $ */
+/* $OpenBSD: ecs_lib.c,v 1.20 2023/06/25 18:45:56 tb Exp $ */
/* ====================================================================
* Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
*
static const ECDSA_METHOD *default_ECDSA_method = NULL;
-static void *ecdsa_data_new(void);
-static void *ecdsa_data_dup(void *);
-static void ecdsa_data_free(void *);
-
void
ECDSA_set_default_method(const ECDSA_METHOD *meth)
{
return 0;
}
-static ECDSA_DATA *
-ECDSA_DATA_new_method(ENGINE *engine)
-{
- ECDSA_DATA *ret;
-
- ret = malloc(sizeof(ECDSA_DATA));
- if (ret == NULL) {
- ECDSAerror(ERR_R_MALLOC_FAILURE);
- return (NULL);
- }
-
- ret->init = NULL;
-
- ret->meth = ECDSA_get_default_method();
- ret->engine = engine;
-#ifndef OPENSSL_NO_ENGINE
- if (!ret->engine)
- ret->engine = ENGINE_get_default_ECDSA();
- if (ret->engine) {
- ret->meth = ENGINE_get_ECDSA(ret->engine);
- if (ret->meth == NULL) {
- ECDSAerror(ERR_R_ENGINE_LIB);
- ENGINE_finish(ret->engine);
- free(ret);
- return NULL;
- }
- }
-#endif
-
- ret->flags = ret->meth->flags;
- CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ECDSA, ret, &ret->ex_data);
- return (ret);
-}
-
-static void *
-ecdsa_data_new(void)
-{
- return (void *)ECDSA_DATA_new_method(NULL);
-}
-
-static void *
-ecdsa_data_dup(void *data)
-{
- ECDSA_DATA *r = (ECDSA_DATA *)data;
-
- /* XXX: dummy operation */
- if (r == NULL)
- return NULL;
-
- return ecdsa_data_new();
-}
-
-static void
-ecdsa_data_free(void *data)
-{
- ECDSA_DATA *r = (ECDSA_DATA *)data;
-
-#ifndef OPENSSL_NO_ENGINE
- ENGINE_finish(r->engine);
-#endif
- CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDSA, r, &r->ex_data);
-
- freezero(r, sizeof(ECDSA_DATA));
-}
-
-ECDSA_DATA *
-ecdsa_check(EC_KEY *key)
-{
- ECDSA_DATA *ecdsa_data;
-
- void *data = EC_KEY_get_key_method_data(key, ecdsa_data_dup,
- ecdsa_data_free, ecdsa_data_free);
- if (data == NULL) {
- ecdsa_data = (ECDSA_DATA *)ecdsa_data_new();
- if (ecdsa_data == NULL)
- return NULL;
- data = EC_KEY_insert_key_method_data(key, (void *)ecdsa_data,
- ecdsa_data_dup, ecdsa_data_free, ecdsa_data_free);
- if (data != NULL) {
- /* Another thread raced us to install the key_method
- * data and won. */
- ecdsa_data_free(ecdsa_data);
- ecdsa_data = (ECDSA_DATA *)data;
- }
- } else
- ecdsa_data = (ECDSA_DATA *)data;
-
- return ecdsa_data;
-}
-
int
ECDSA_size(const EC_KEY *r)
{
-/* $OpenBSD: ecs_local.h,v 1.2 2022/11/26 17:23:17 tb Exp $ */
+/* $OpenBSD: ecs_local.h,v 1.3 2023/06/25 18:45:56 tb Exp $ */
/*
* Written by Nils Larsch for the OpenSSL project
*/
__BEGIN_HIDDEN_DECLS
-typedef struct ecdsa_data_st {
- /* EC_KEY_METH_DATA part */
- int (*init)(EC_KEY *);
- /* method (ECDSA) specific part */
- ENGINE *engine;
- int flags;
- const ECDSA_METHOD *meth;
- CRYPTO_EX_DATA ex_data;
-} ECDSA_DATA;
-
struct ECDSA_SIG_st {
BIGNUM *r;
BIGNUM *s;
};
-/** ecdsa_check
- * checks whether ECKEY->meth_data is a pointer to a ECDSA_DATA structure
- * and if not it removes the old meth_data and creates a ECDSA_DATA structure.
- * \param eckey pointer to a EC_KEY object
- * \return pointer to a ECDSA_DATA structure
- */
-ECDSA_DATA *ecdsa_check(EC_KEY *eckey);
-
int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
BIGNUM **rp);
int ossl_ecdsa_sign(int type, const unsigned char *dgst, int dlen,