1238384Sjkim/* crypto/dsa/dsa_prn.c */
2280304Sjkim/*
3280304Sjkim * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
4280304Sjkim * 2006.
5238384Sjkim */
6238384Sjkim/* ====================================================================
7238384Sjkim * Copyright (c) 2006 The OpenSSL Project.  All rights reserved.
8238384Sjkim *
9238384Sjkim * Redistribution and use in source and binary forms, with or without
10238384Sjkim * modification, are permitted provided that the following conditions
11238384Sjkim * are met:
12238384Sjkim *
13238384Sjkim * 1. Redistributions of source code must retain the above copyright
14280304Sjkim *    notice, this list of conditions and the following disclaimer.
15238384Sjkim *
16238384Sjkim * 2. Redistributions in binary form must reproduce the above copyright
17238384Sjkim *    notice, this list of conditions and the following disclaimer in
18238384Sjkim *    the documentation and/or other materials provided with the
19238384Sjkim *    distribution.
20238384Sjkim *
21238384Sjkim * 3. All advertising materials mentioning features or use of this
22238384Sjkim *    software must display the following acknowledgment:
23238384Sjkim *    "This product includes software developed by the OpenSSL Project
24238384Sjkim *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25238384Sjkim *
26238384Sjkim * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27238384Sjkim *    endorse or promote products derived from this software without
28238384Sjkim *    prior written permission. For written permission, please contact
29238384Sjkim *    licensing@OpenSSL.org.
30238384Sjkim *
31238384Sjkim * 5. Products derived from this software may not be called "OpenSSL"
32238384Sjkim *    nor may "OpenSSL" appear in their names without prior written
33238384Sjkim *    permission of the OpenSSL Project.
34238384Sjkim *
35238384Sjkim * 6. Redistributions of any form whatsoever must retain the following
36238384Sjkim *    acknowledgment:
37238384Sjkim *    "This product includes software developed by the OpenSSL Project
38238384Sjkim *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39238384Sjkim *
40238384Sjkim * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41238384Sjkim * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42238384Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43238384Sjkim * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
44238384Sjkim * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45238384Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46238384Sjkim * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47238384Sjkim * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48238384Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49238384Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50238384Sjkim * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51238384Sjkim * OF THE POSSIBILITY OF SUCH DAMAGE.
52238384Sjkim * ====================================================================
53238384Sjkim *
54238384Sjkim * This product includes cryptographic software written by Eric Young
55238384Sjkim * (eay@cryptsoft.com).  This product includes software written by Tim
56238384Sjkim * Hudson (tjh@cryptsoft.com).
57238384Sjkim *
58238384Sjkim */
59238384Sjkim
60238384Sjkim#include <stdio.h>
61238384Sjkim#include "cryptlib.h"
62238384Sjkim#include <openssl/evp.h>
63238384Sjkim#include <openssl/dsa.h>
64238384Sjkim
65238384Sjkim#ifndef OPENSSL_NO_FP_API
66238384Sjkimint DSA_print_fp(FILE *fp, const DSA *x, int off)
67280304Sjkim{
68280304Sjkim    BIO *b;
69280304Sjkim    int ret;
70238384Sjkim
71280304Sjkim    if ((b = BIO_new(BIO_s_file())) == NULL) {
72280304Sjkim        DSAerr(DSA_F_DSA_PRINT_FP, ERR_R_BUF_LIB);
73280304Sjkim        return (0);
74280304Sjkim    }
75280304Sjkim    BIO_set_fp(b, fp, BIO_NOCLOSE);
76280304Sjkim    ret = DSA_print(b, x, off);
77280304Sjkim    BIO_free(b);
78280304Sjkim    return (ret);
79280304Sjkim}
80238384Sjkim
81238384Sjkimint DSAparams_print_fp(FILE *fp, const DSA *x)
82280304Sjkim{
83280304Sjkim    BIO *b;
84280304Sjkim    int ret;
85238384Sjkim
86280304Sjkim    if ((b = BIO_new(BIO_s_file())) == NULL) {
87280304Sjkim        DSAerr(DSA_F_DSAPARAMS_PRINT_FP, ERR_R_BUF_LIB);
88280304Sjkim        return (0);
89280304Sjkim    }
90280304Sjkim    BIO_set_fp(b, fp, BIO_NOCLOSE);
91280304Sjkim    ret = DSAparams_print(b, x);
92280304Sjkim    BIO_free(b);
93280304Sjkim    return (ret);
94280304Sjkim}
95238384Sjkim#endif
96238384Sjkim
97238384Sjkimint DSA_print(BIO *bp, const DSA *x, int off)
98280304Sjkim{
99280304Sjkim    EVP_PKEY *pk;
100280304Sjkim    int ret;
101280304Sjkim    pk = EVP_PKEY_new();
102280304Sjkim    if (!pk || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
103280304Sjkim        return 0;
104280304Sjkim    ret = EVP_PKEY_print_private(bp, pk, off, NULL);
105280304Sjkim    EVP_PKEY_free(pk);
106280304Sjkim    return ret;
107280304Sjkim}
108238384Sjkim
109238384Sjkimint DSAparams_print(BIO *bp, const DSA *x)
110280304Sjkim{
111280304Sjkim    EVP_PKEY *pk;
112280304Sjkim    int ret;
113280304Sjkim    pk = EVP_PKEY_new();
114280304Sjkim    if (!pk || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
115280304Sjkim        return 0;
116280304Sjkim    ret = EVP_PKEY_print_params(bp, pk, 4, NULL);
117280304Sjkim    EVP_PKEY_free(pk);
118280304Sjkim    return ret;
119280304Sjkim}
120