/src/openssl31/crypto/dsa/dsa_asn1.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
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 |
8 | | */ |
9 | | |
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 | | |
16 | | #include <stdio.h> |
17 | | #include "internal/cryptlib.h" |
18 | | #include "dsa_local.h" |
19 | | #include <openssl/asn1.h> |
20 | | #include <openssl/asn1t.h> |
21 | | #include <openssl/rand.h> |
22 | | #include "crypto/asn1_dsa.h" |
23 | | |
24 | | /* Override the default free and new methods */ |
25 | | static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
26 | | void *exarg) |
27 | 994k | { |
28 | 994k | if (operation == ASN1_OP_NEW_PRE) { |
29 | 329k | *pval = (ASN1_VALUE *)DSA_new(); |
30 | 329k | if (*pval != NULL) |
31 | 329k | return 2; |
32 | 0 | return 0; |
33 | 665k | } else if (operation == ASN1_OP_FREE_PRE) { |
34 | 263k | DSA_free((DSA *)*pval); |
35 | 263k | *pval = NULL; |
36 | 263k | return 2; |
37 | 263k | } |
38 | 402k | return 1; |
39 | 994k | } |
40 | | |
41 | | ASN1_SEQUENCE_cb(DSAPrivateKey, dsa_cb) = { |
42 | | ASN1_EMBED(DSA, version, INT32), |
43 | | ASN1_SIMPLE(DSA, params.p, BIGNUM), |
44 | | ASN1_SIMPLE(DSA, params.q, BIGNUM), |
45 | | ASN1_SIMPLE(DSA, params.g, BIGNUM), |
46 | | ASN1_SIMPLE(DSA, pub_key, BIGNUM), |
47 | | ASN1_SIMPLE(DSA, priv_key, CBIGNUM) |
48 | | } static_ASN1_SEQUENCE_END_cb(DSA, DSAPrivateKey) |
49 | | |
50 | | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAPrivateKey, DSAPrivateKey) |
51 | | |
52 | | ASN1_SEQUENCE_cb(DSAparams, dsa_cb) = { |
53 | | ASN1_SIMPLE(DSA, params.p, BIGNUM), |
54 | | ASN1_SIMPLE(DSA, params.q, BIGNUM), |
55 | | ASN1_SIMPLE(DSA, params.g, BIGNUM), |
56 | | } static_ASN1_SEQUENCE_END_cb(DSA, DSAparams) |
57 | | |
58 | | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAparams, DSAparams) |
59 | | |
60 | | ASN1_SEQUENCE_cb(DSAPublicKey, dsa_cb) = { |
61 | | ASN1_SIMPLE(DSA, pub_key, BIGNUM), |
62 | | ASN1_SIMPLE(DSA, params.p, BIGNUM), |
63 | | ASN1_SIMPLE(DSA, params.q, BIGNUM), |
64 | | ASN1_SIMPLE(DSA, params.g, BIGNUM) |
65 | | } static_ASN1_SEQUENCE_END_cb(DSA, DSAPublicKey) |
66 | | |
67 | | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAPublicKey, DSAPublicKey) |
68 | | |
69 | | DSA *DSAparams_dup(const DSA *dsa) |
70 | 0 | { |
71 | 0 | return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa); |
72 | 0 | } |