2016-05-18 02:51:26 +08:00
|
|
|
/*
|
2020-04-23 20:55:52 +08:00
|
|
|
* Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2016-05-18 02:51:26 +08:00
|
|
|
*
|
2018-12-06 20:36:26 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:51:26 +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
|
|
|
|
*/
|
|
|
|
|
2016-04-03 02:41:41 +08:00
|
|
|
/*
|
2020-10-20 11:32:57 +08:00
|
|
|
* DSA low level APIs are deprecated for public use, but still ok for
|
|
|
|
* internal use.
|
2016-03-31 00:18:55 +08:00
|
|
|
*/
|
2020-10-20 11:32:57 +08:00
|
|
|
#include "internal/deprecated.h"
|
2016-03-31 00:18:55 +08:00
|
|
|
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "dsa_local.h"
|
2016-03-31 00:18:55 +08:00
|
|
|
#include <string.h>
|
2016-05-17 22:08:43 +08:00
|
|
|
#include <openssl/err.h>
|
2016-03-31 00:18:55 +08:00
|
|
|
|
2020-01-30 05:23:39 +08:00
|
|
|
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
2016-03-31 00:18:55 +08:00
|
|
|
DSA_METHOD *DSA_meth_new(const char *name, int flags)
|
|
|
|
{
|
2016-11-10 07:54:03 +08:00
|
|
|
DSA_METHOD *dsam = OPENSSL_zalloc(sizeof(*dsam));
|
2016-03-31 00:18:55 +08:00
|
|
|
|
|
|
|
if (dsam != NULL) {
|
|
|
|
dsam->flags = flags;
|
2016-11-10 07:54:03 +08:00
|
|
|
|
|
|
|
dsam->name = OPENSSL_strdup(name);
|
|
|
|
if (dsam->name != NULL)
|
|
|
|
return dsam;
|
|
|
|
|
|
|
|
OPENSSL_free(dsam);
|
2016-03-31 00:18:55 +08:00
|
|
|
}
|
|
|
|
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE);
|
2016-11-10 07:54:03 +08:00
|
|
|
return NULL;
|
2016-03-31 00:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSA_meth_free(DSA_METHOD *dsam)
|
|
|
|
{
|
|
|
|
if (dsam != NULL) {
|
2016-05-08 00:54:01 +08:00
|
|
|
OPENSSL_free(dsam->name);
|
2016-03-31 00:18:55 +08:00
|
|
|
OPENSSL_free(dsam);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-03 02:41:41 +08:00
|
|
|
DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam)
|
2016-03-31 00:18:55 +08:00
|
|
|
{
|
2016-11-10 07:54:03 +08:00
|
|
|
DSA_METHOD *ret = OPENSSL_malloc(sizeof(*ret));
|
2016-03-31 00:18:55 +08:00
|
|
|
|
|
|
|
if (ret != NULL) {
|
2016-04-03 02:41:41 +08:00
|
|
|
memcpy(ret, dsam, sizeof(*dsam));
|
2016-11-10 07:54:03 +08:00
|
|
|
|
2016-04-03 02:41:41 +08:00
|
|
|
ret->name = OPENSSL_strdup(dsam->name);
|
2016-11-10 07:54:03 +08:00
|
|
|
if (ret->name != NULL)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
OPENSSL_free(ret);
|
2016-03-31 00:18:55 +08:00
|
|
|
}
|
|
|
|
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE);
|
2016-11-10 07:54:03 +08:00
|
|
|
return NULL;
|
2016-03-31 00:18:55 +08:00
|
|
|
}
|
|
|
|
|
2016-04-03 02:41:41 +08:00
|
|
|
const char *DSA_meth_get0_name(const DSA_METHOD *dsam)
|
2016-03-31 00:18:55 +08:00
|
|
|
{
|
|
|
|
return dsam->name;
|
|
|
|
}
|
|
|
|
|
2016-04-03 02:41:41 +08:00
|
|
|
int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name)
|
2016-03-31 00:18:55 +08:00
|
|
|
{
|
2016-11-10 07:54:03 +08:00
|
|
|
char *tmpname = OPENSSL_strdup(name);
|
2016-05-04 18:28:38 +08:00
|
|
|
|
2016-05-17 22:08:43 +08:00
|
|
|
if (tmpname == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE);
|
2016-05-04 18:28:38 +08:00
|
|
|
return 0;
|
2016-05-17 22:08:43 +08:00
|
|
|
}
|
2016-05-04 18:28:38 +08:00
|
|
|
|
2016-03-31 00:18:55 +08:00
|
|
|
OPENSSL_free(dsam->name);
|
2016-05-04 18:28:38 +08:00
|
|
|
dsam->name = tmpname;
|
2016-03-31 00:18:55 +08:00
|
|
|
|
2016-05-04 18:28:38 +08:00
|
|
|
return 1;
|
2016-03-31 00:18:55 +08:00
|
|
|
}
|
|
|
|
|
2017-01-06 00:58:18 +08:00
|
|
|
int DSA_meth_get_flags(const DSA_METHOD *dsam)
|
2016-03-31 00:18:55 +08:00
|
|
|
{
|
|
|
|
return dsam->flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DSA_meth_set_flags(DSA_METHOD *dsam, int flags)
|
|
|
|
{
|
|
|
|
dsam->flags = flags;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-04-03 06:08:14 +08:00
|
|
|
void *DSA_meth_get0_app_data(const DSA_METHOD *dsam)
|
2016-03-31 00:18:55 +08:00
|
|
|
{
|
|
|
|
return dsam->app_data;
|
|
|
|
}
|
|
|
|
|
2016-04-03 06:08:14 +08:00
|
|
|
int DSA_meth_set0_app_data(DSA_METHOD *dsam, void *app_data)
|
2016-03-31 00:18:55 +08:00
|
|
|
{
|
|
|
|
dsam->app_data = app_data;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DSA_SIG *(*DSA_meth_get_sign(const DSA_METHOD *dsam))
|
|
|
|
(const unsigned char *, int, DSA *)
|
|
|
|
{
|
|
|
|
return dsam->dsa_do_sign;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DSA_meth_set_sign(DSA_METHOD *dsam,
|
|
|
|
DSA_SIG *(*sign) (const unsigned char *, int, DSA *))
|
|
|
|
{
|
|
|
|
dsam->dsa_do_sign = sign;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int (*DSA_meth_get_sign_setup(const DSA_METHOD *dsam))
|
|
|
|
(DSA *, BN_CTX *, BIGNUM **, BIGNUM **)
|
|
|
|
{
|
|
|
|
return dsam->dsa_sign_setup;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DSA_meth_set_sign_setup(DSA_METHOD *dsam,
|
|
|
|
int (*sign_setup) (DSA *, BN_CTX *, BIGNUM **, BIGNUM **))
|
|
|
|
{
|
|
|
|
dsam->dsa_sign_setup = sign_setup;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int (*DSA_meth_get_verify(const DSA_METHOD *dsam))
|
2016-08-24 06:17:31 +08:00
|
|
|
(const unsigned char *, int, DSA_SIG *, DSA *)
|
2016-03-31 00:18:55 +08:00
|
|
|
{
|
|
|
|
return dsam->dsa_do_verify;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DSA_meth_set_verify(DSA_METHOD *dsam,
|
|
|
|
int (*verify) (const unsigned char *, int, DSA_SIG *, DSA *))
|
|
|
|
{
|
|
|
|
dsam->dsa_do_verify = verify;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int (*DSA_meth_get_mod_exp(const DSA_METHOD *dsam))
|
2016-06-24 20:34:51 +08:00
|
|
|
(DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
|
|
|
|
const BIGNUM *, const BIGNUM *, BN_CTX *, BN_MONT_CTX *)
|
2016-03-31 00:18:55 +08:00
|
|
|
{
|
|
|
|
return dsam->dsa_mod_exp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DSA_meth_set_mod_exp(DSA_METHOD *dsam,
|
2016-06-24 20:34:51 +08:00
|
|
|
int (*mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
|
|
|
|
const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
|
|
|
|
BN_MONT_CTX *))
|
2016-03-31 00:18:55 +08:00
|
|
|
{
|
|
|
|
dsam->dsa_mod_exp = mod_exp;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int (*DSA_meth_get_bn_mod_exp(const DSA_METHOD *dsam))
|
2016-06-24 20:34:51 +08:00
|
|
|
(DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
|
2016-03-31 00:18:55 +08:00
|
|
|
BN_MONT_CTX *)
|
|
|
|
{
|
|
|
|
return dsam->bn_mod_exp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DSA_meth_set_bn_mod_exp(DSA_METHOD *dsam,
|
2016-06-24 20:34:51 +08:00
|
|
|
int (*bn_mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
|
2016-03-31 00:18:55 +08:00
|
|
|
const BIGNUM *, BN_CTX *, BN_MONT_CTX *))
|
|
|
|
{
|
|
|
|
dsam->bn_mod_exp = bn_mod_exp;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int (*DSA_meth_get_init(const DSA_METHOD *dsam))(DSA *)
|
|
|
|
{
|
|
|
|
return dsam->init;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DSA_meth_set_init(DSA_METHOD *dsam, int (*init)(DSA *))
|
|
|
|
{
|
|
|
|
dsam->init = init;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int (*DSA_meth_get_finish(const DSA_METHOD *dsam)) (DSA *)
|
|
|
|
{
|
|
|
|
return dsam->finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DSA_meth_set_finish(DSA_METHOD *dsam, int (*finish) (DSA *))
|
|
|
|
{
|
|
|
|
dsam->finish = finish;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int (*DSA_meth_get_paramgen(const DSA_METHOD *dsam))
|
|
|
|
(DSA *, int, const unsigned char *, int, int *, unsigned long *,
|
|
|
|
BN_GENCB *)
|
|
|
|
{
|
|
|
|
return dsam->dsa_paramgen;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DSA_meth_set_paramgen(DSA_METHOD *dsam,
|
|
|
|
int (*paramgen) (DSA *, int, const unsigned char *, int, int *,
|
|
|
|
unsigned long *, BN_GENCB *))
|
|
|
|
{
|
|
|
|
dsam->dsa_paramgen = paramgen;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int (*DSA_meth_get_keygen(const DSA_METHOD *dsam)) (DSA *)
|
|
|
|
{
|
|
|
|
return dsam->dsa_keygen;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DSA_meth_set_keygen(DSA_METHOD *dsam, int (*keygen) (DSA *))
|
|
|
|
{
|
|
|
|
dsam->dsa_keygen = keygen;
|
|
|
|
return 1;
|
|
|
|
}
|
2020-01-30 05:23:39 +08:00
|
|
|
#endif
|