/*
- * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
* 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
static int pkey_dsa_init(EVP_PKEY_CTX *ctx)
{
- DSA_PKEY_CTX *dctx;
- dctx = OPENSSL_malloc(sizeof(*dctx));
+ DSA_PKEY_CTX *dctx = OPENSSL_malloc(sizeof(*dctx));
+
if (dctx == NULL)
return 0;
dctx->nbits = 1024;
static int pkey_dsa_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
{
DSA_PKEY_CTX *dctx, *sctx;
+
if (!pkey_dsa_init(dst))
return 0;
sctx = src->data;
DSA_PKEY_CTX *dctx = ctx->data;
DSA *dsa = ctx->pkey->pkey.dsa;
- if (dctx->md) {
- if (tbslen != (size_t)EVP_MD_size(dctx->md))
- return 0;
- } else {
- if (tbslen != SHA_DIGEST_LENGTH)
- return 0;
- }
+ if (dctx->md != NULL && tbslen != (size_t)EVP_MD_size(dctx->md))
+ return 0;
ret = DSA_sign(0, tbs, tbslen, sig, &sltmp, dsa);
DSA_PKEY_CTX *dctx = ctx->data;
DSA *dsa = ctx->pkey->pkey.dsa;
- if (dctx->md) {
- if (tbslen != (size_t)EVP_MD_size(dctx->md))
- return 0;
- } else {
- if (tbslen != SHA_DIGEST_LENGTH)
- return 0;
- }
+ if (dctx->md != NULL && tbslen != (size_t)EVP_MD_size(dctx->md))
+ return 0;
ret = DSA_verify(0, tbs, tbslen, sig, siglen, dsa);
static int pkey_dsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
{
DSA_PKEY_CTX *dctx = ctx->data;
+
switch (type) {
case EVP_PKEY_CTRL_DSA_PARAMGEN_BITS:
if (p1 < 256)
DSAerr(DSA_F_PKEY_DSA_CTRL, DSA_R_INVALID_DIGEST_TYPE);
return 0;
}
- dctx->md = p2;
+ dctx->pmd = p2;
return 1;
case EVP_PKEY_CTRL_MD:
NULL);
}
if (strcmp(type, "dsa_paramgen_md") == 0) {
+ const EVP_MD *md = EVP_get_digestbyname(value);
+
+ if (md == NULL) {
+ DSAerr(DSA_F_PKEY_DSA_CTRL_STR, DSA_R_INVALID_DIGEST_TYPE);
+ return 0;
+ }
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN,
EVP_PKEY_CTRL_DSA_PARAMGEN_MD, 0,
- (void *)EVP_get_digestbyname(value));
+ (void *)md);
}
return -2;
}
DSA_PKEY_CTX *dctx = ctx->data;
BN_GENCB *pcb;
int ret;
+
if (ctx->pkey_gencb) {
pcb = BN_GENCB_new();
if (pcb == NULL)
static int pkey_dsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
{
DSA *dsa = NULL;
+
if (ctx->pkey == NULL) {
DSAerr(DSA_F_PKEY_DSA_KEYGEN, DSA_R_NO_PARAMETERS_SET);
return 0;