2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2016-05-18 02:51:26 +08:00
|
|
|
* Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2000-12-09 03:09:35 +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
|
2000-12-09 03:09:35 +08:00
|
|
|
*/
|
1999-04-10 00:24:32 +08:00
|
|
|
|
2020-01-30 05:23:39 +08:00
|
|
|
/*
|
|
|
|
* DSA low level APIs are deprecated for public use, but still ok for
|
|
|
|
* internal use.
|
|
|
|
*/
|
|
|
|
#include "internal/deprecated.h"
|
|
|
|
|
1999-04-10 00:24:32 +08:00
|
|
|
#include <stdio.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "dsa_local.h"
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/asn1.h>
|
2000-12-09 03:09:35 +08:00
|
|
|
#include <openssl/asn1t.h>
|
2011-01-26 00:55:15 +08:00
|
|
|
#include <openssl/rand.h>
|
2019-09-28 06:45:33 +08:00
|
|
|
#include "crypto/asn1_dsa.h"
|
2016-07-20 01:57:15 +08:00
|
|
|
|
2000-12-09 03:09:35 +08:00
|
|
|
/* Override the default free and new methods */
|
2005-09-02 04:42:52 +08:00
|
|
|
static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
2015-01-22 11:40:55 +08:00
|
|
|
void *exarg)
|
1999-04-10 00:24:32 +08:00
|
|
|
{
|
2015-01-22 11:40:55 +08:00
|
|
|
if (operation == ASN1_OP_NEW_PRE) {
|
|
|
|
*pval = (ASN1_VALUE *)DSA_new();
|
2015-10-30 19:12:26 +08:00
|
|
|
if (*pval != NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return 2;
|
|
|
|
return 0;
|
|
|
|
} else if (operation == ASN1_OP_FREE_PRE) {
|
|
|
|
DSA_free((DSA *)*pval);
|
|
|
|
*pval = NULL;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return 1;
|
1999-04-10 00:24:32 +08:00
|
|
|
}
|
|
|
|
|
2000-12-09 03:09:35 +08:00
|
|
|
ASN1_SEQUENCE_cb(DSAPrivateKey, dsa_cb) = {
|
2017-04-12 17:52:52 +08:00
|
|
|
ASN1_EMBED(DSA, version, INT32),
|
2020-01-24 12:09:33 +08:00
|
|
|
ASN1_SIMPLE(DSA, params.p, BIGNUM),
|
|
|
|
ASN1_SIMPLE(DSA, params.q, BIGNUM),
|
|
|
|
ASN1_SIMPLE(DSA, params.g, BIGNUM),
|
2015-01-22 11:40:55 +08:00
|
|
|
ASN1_SIMPLE(DSA, pub_key, BIGNUM),
|
2015-04-25 04:39:40 +08:00
|
|
|
ASN1_SIMPLE(DSA, priv_key, CBIGNUM)
|
2015-09-05 20:32:58 +08:00
|
|
|
} static_ASN1_SEQUENCE_END_cb(DSA, DSAPrivateKey)
|
1999-04-10 00:24:32 +08:00
|
|
|
|
2019-01-16 04:51:25 +08:00
|
|
|
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAPrivateKey, DSAPrivateKey)
|
1999-04-10 00:24:32 +08:00
|
|
|
|
2000-12-09 03:09:35 +08:00
|
|
|
ASN1_SEQUENCE_cb(DSAparams, dsa_cb) = {
|
2020-01-24 12:09:33 +08:00
|
|
|
ASN1_SIMPLE(DSA, params.p, BIGNUM),
|
|
|
|
ASN1_SIMPLE(DSA, params.q, BIGNUM),
|
|
|
|
ASN1_SIMPLE(DSA, params.g, BIGNUM),
|
2015-09-05 20:32:58 +08:00
|
|
|
} static_ASN1_SEQUENCE_END_cb(DSA, DSAparams)
|
1999-04-10 00:24:32 +08:00
|
|
|
|
2019-01-16 04:51:25 +08:00
|
|
|
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAparams, DSAparams)
|
1999-04-10 00:24:32 +08:00
|
|
|
|
2016-01-29 03:34:51 +08:00
|
|
|
ASN1_SEQUENCE_cb(DSAPublicKey, dsa_cb) = {
|
2015-01-22 11:40:55 +08:00
|
|
|
ASN1_SIMPLE(DSA, pub_key, BIGNUM),
|
2020-01-24 12:09:33 +08:00
|
|
|
ASN1_SIMPLE(DSA, params.p, BIGNUM),
|
|
|
|
ASN1_SIMPLE(DSA, params.q, BIGNUM),
|
|
|
|
ASN1_SIMPLE(DSA, params.g, BIGNUM)
|
2016-01-29 03:34:51 +08:00
|
|
|
} static_ASN1_SEQUENCE_END_cb(DSA, DSAPublicKey)
|
2000-12-09 03:09:35 +08:00
|
|
|
|
2019-01-16 04:51:25 +08:00
|
|
|
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAPublicKey, DSAPublicKey)
|
2009-09-06 23:49:46 +08:00
|
|
|
|
2019-01-16 04:51:25 +08:00
|
|
|
DSA *DSAparams_dup(const DSA *dsa)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa);
|
|
|
|
}
|