]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/dsa/dsa_asn1.c
threads_pthread.c: change inline to ossl_inline
[thirdparty/openssl.git] / crypto / dsa / dsa_asn1.c
CommitLineData
0f113f3e 1/*
33388b44 2 * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved.
9d6b1ce6 3 *
3cdbea65 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
d2e9e320
RS
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
9d6b1ce6 8 */
a8da8918 9
f41ac0ee
P
10/*
11 * DSA low level APIs are deprecated for public use, but still ok for
12 * internal use.
13 */
14#include "internal/deprecated.h"
15
a8da8918 16#include <stdio.h>
b39fc560 17#include "internal/cryptlib.h"
706457b7 18#include "dsa_local.h"
ec577822 19#include <openssl/asn1.h>
9d6b1ce6 20#include <openssl/asn1t.h>
f7a2afa6 21#include <openssl/rand.h>
25f2138b 22#include "crypto/asn1_dsa.h"
8cc44d97 23
9d6b1ce6 24/* Override the default free and new methods */
24484759 25static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
0f113f3e 26 void *exarg)
a8da8918 27{
0f113f3e
MC
28 if (operation == ASN1_OP_NEW_PRE) {
29 *pval = (ASN1_VALUE *)DSA_new();
90945fa3 30 if (*pval != NULL)
0f113f3e
MC
31 return 2;
32 return 0;
33 } else if (operation == ASN1_OP_FREE_PRE) {
34 DSA_free((DSA *)*pval);
35 *pval = NULL;
36 return 2;
37 }
38 return 1;
a8da8918
UM
39}
40
9d6b1ce6 41ASN1_SEQUENCE_cb(DSAPrivateKey, dsa_cb) = {
9612e157 42 ASN1_EMBED(DSA, version, INT32),
dc8de3e6
SL
43 ASN1_SIMPLE(DSA, params.p, BIGNUM),
44 ASN1_SIMPLE(DSA, params.q, BIGNUM),
45 ASN1_SIMPLE(DSA, params.g, BIGNUM),
0f113f3e 46 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
74924dcb 47 ASN1_SIMPLE(DSA, priv_key, CBIGNUM)
df2ee0e2 48} static_ASN1_SEQUENCE_END_cb(DSA, DSAPrivateKey)
a8da8918 49
9fdcc21f 50IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAPrivateKey, DSAPrivateKey)
a8da8918 51
9d6b1ce6 52ASN1_SEQUENCE_cb(DSAparams, dsa_cb) = {
dc8de3e6
SL
53 ASN1_SIMPLE(DSA, params.p, BIGNUM),
54 ASN1_SIMPLE(DSA, params.q, BIGNUM),
55 ASN1_SIMPLE(DSA, params.g, BIGNUM),
df2ee0e2 56} static_ASN1_SEQUENCE_END_cb(DSA, DSAparams)
a8da8918 57
9fdcc21f 58IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAparams, DSAparams)
a8da8918 59
987157f6 60ASN1_SEQUENCE_cb(DSAPublicKey, dsa_cb) = {
0f113f3e 61 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
dc8de3e6
SL
62 ASN1_SIMPLE(DSA, params.p, BIGNUM),
63 ASN1_SIMPLE(DSA, params.q, BIGNUM),
64 ASN1_SIMPLE(DSA, params.g, BIGNUM)
987157f6 65} static_ASN1_SEQUENCE_END_cb(DSA, DSAPublicKey)
9d6b1ce6 66
9fdcc21f 67IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAPublicKey, DSAPublicKey)
f4274da1 68
9fdcc21f 69DSA *DSAparams_dup(const DSA *dsa)
0f113f3e
MC
70{
71 return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa);
72}