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