---
name: "libressl-d2i_DSAPublicKey"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-d2i_DSAPublicKey"
---

# libressl-d2i\_DSAPublicKey(3)

decode and encode DSA keys

## NAME

**d2i\_DSAPublicKey**, **i2d\_DSAPublicKey**, **d2i\_DSA\_PUBKEY**, **i2d\_DSA\_PUBKEY**, **d2i\_DSA\_PUBKEY\_bio**, **d2i\_DSA\_PUBKEY\_fp**, **i2d\_DSA\_PUBKEY\_bio**, **i2d\_DSA\_PUBKEY\_fp**, **d2i\_DSAPrivateKey**, **i2d\_DSAPrivateKey**, **d2i\_DSAPrivateKey\_bio**, **d2i\_DSAPrivateKey\_fp**, **i2d\_DSAPrivateKey\_bio**, **i2d\_DSAPrivateKey\_fp**, **d2i\_DSAparams**, **i2d\_DSAparams**, **d2i\_DSAparams\_bio**, **i2d\_DSAparams\_bio**, **d2i\_DSAparams\_fp**, **i2d\_DSAparams\_fp**, **DSAparams\_dup**, **d2i\_DSA\_SIG**, **i2d\_DSA\_SIG** – decode and encode DSA keys

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/dsa.h\>**

*DSA* *\**\

**d2i\_DSAPublicKey**(*DSA \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_DSAPublicKey**(*const DSA \*val\_in*, *unsigned char \*\*der\_out*);

**#include \<openssl/x509.h\>**

*DSA* *\**\

**d2i\_DSA\_PUBKEY**(*DSA \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_DSA\_PUBKEY**(*const DSA \*val\_in*, *unsigned char \*\*der\_out*);

*DSA* *\**\

**d2i\_DSA\_PUBKEY\_bio**(*BIO \*in\_bio*, *DSA \*\*val\_out*);

*DSA* *\**\

**d2i\_DSA\_PUBKEY\_fp**(*FILE \*in\_fp*, *DSA \*\*val\_out*);

*int*\

**i2d\_DSA\_PUBKEY\_bio**(*BIO \*out\_bio*, *DSA \*val\_in*);

*int*\

**i2d\_DSA\_PUBKEY\_fp**(*FILE \*out\_fp*, *DSA \*val\_in*);

**#include \<openssl/dsa.h\>**

*DSA* *\**\

**d2i\_DSAPrivateKey**(*DSA \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_DSAPrivateKey**(*const DSA \*val\_in*, *unsigned char \*\*der\_out*);

**#include \<openssl/x509.h\>**

*DSA* *\**\

**d2i\_DSAPrivateKey\_bio**(*BIO \*in\_bio*, *DSA \*\*val\_out*);

*DSA* *\**\

**d2i\_DSAPrivateKey\_fp**(*FILE \*in\_fp*, *DSA \*\*val\_out*);

*int*\

**i2d\_DSAPrivateKey\_bio**(*BIO \*out\_bio*, *DSA \*val\_in*);

*int*\

**i2d\_DSAPrivateKey\_fp**(*FILE \*out\_fp*, *DSA \*val\_in*);

**#include \<openssl/dsa.h\>**

*DSA* *\**\

**d2i\_DSAparams**(*DSA \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_DSAparams**(*const DSA \*val\_in*, *unsigned char \*\*der\_out*);

*DSA* *\**\

**d2i\_DSAparams\_bio**(*BIO \*in\_bio*, *DSA \*\*val\_out*);

*int*\

**i2d\_DSAparams\_bio**(*BIO \*out\_bio*, *DSA \*val\_in*);

*DSA* *\**\

**d2i\_DSAparams\_fp**(*FILE \*in\_fp*, *DSA \*\*val\_out*);

*int*\

**i2d\_DSAparams\_fp**(*FILE*, *\*out\_fp*, *DSA \*val\_in*);

*DSA* *\**\

**DSAparams\_dup**(*DSA \*val\_in*);

*DSA\_SIG* *\**\

**d2i\_DSA\_SIG**(*DSA\_SIG \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_DSA\_SIG**(*const DSA\_SIG \*val\_in*, *unsigned char \*\*der\_out*);

## DESCRIPTION

These functions decode and encode DSA keys and parameters. For details about the semantics, examples, caveats, and bugs, see ASN1\_item\_d2i(3).

**d2i\_DSAPublicKey**() and **i2d\_DSAPublicKey**() decode and encode the DSA public key components using a non-standard format, so consider using **d2i\_DSA\_PUBKEY**() and **i2d\_DSA\_PUBKEY**() instead. The actual data encoded depends on the value of *val\_in-\>write\_params*. If *val\_in-\>write\_params* is zero, only the *val\_in-\>pub\_key* field is encoded as an ASN.1 INTEGER. If *val\_in-\>write\_params* is 1, then a SEQUENCE consisting of the *val\_in-\>p*, *val\_in-\>q*, *val\_in-\>g*, and *val\_in-\>pub\_key* fields is encoded.

**d2i\_DSA\_PUBKEY**() and **i2d\_DSA\_PUBKEY**() decode and encode a DSA public key using an ASN.1 *SubjectPublicKeyInfo* structure defined in RFC 5280 section 4.1 and documented in X509\_PUBKEY\_new(3). **d2i\_DSA\_PUBKEY\_bio**(), **d2i\_DSA\_PUBKEY\_fp**(), **i2d\_DSA\_PUBKEY\_bio**(), and **i2d\_DSA\_PUBKEY\_fp**() are similar except that they decode or encode using a *BIO* or *FILE* pointer.

**d2i\_DSAPrivateKey**() and **i2d\_DSAPrivateKey**() decode and encode the DSA private key components. The *DSA* object passed to the private key encoding functions should have all the private key components present. These functions use a non-standard structure consisting of a SEQUENCE containing the *val\_in-\>p*, *val\_in-\>q*, *val\_in-\>g*, *val\_in-\>pub\_key*, and *val\_in-\>priv\_key* fields. This data format is unencrypted. For private key security when writing private keys to files, consider using PEM\_write\_DSAPrivateKey(3) instead. **d2i\_DSAPrivateKey\_bio**(), **d2i\_DSAPrivateKey\_fp**(), **i2d\_DSAPrivateKey\_bio**(), and **i2d\_DSAPrivateKey\_fp**() are similar except that they decode or encode using a *BIO* or *FILE* pointer.

**d2i\_DSAparams**() and **i2d\_DSAparams**() decode and encode the DSA parameters using an ASN.1 *Dss-Parms* structure defined in RFC 3279 section 2.3.2 and used for the parameters field of the ASN.1 *AlgorithmIdentifier* structure defined in RFC 5280 section 4.1.1.2. **d2i\_DSAparams\_bio**(), **i2d\_DSAparams\_bio**(), **d2i\_DSAparams\_fp**(), **i2d\_DSAparams\_fp**() are similar except that they decode or encode using a *BIO* or *FILE* pointer.

**DSAparams\_dup**() allocates and initializes an empty *DSA* object and copies the DSA parameters from *val\_in* to it by calling **i2d\_DSAparams**() and **d2i\_DSAparams**(). If a private or public key are present in *val\_in*, they are not copied.

**d2i\_DSA\_SIG**() and **i2d\_DSA\_SIG**() decode and encode a DSA signature using an ASN.1 *Dss-Sig-Value* structure as defined in RFC 3279 section 2.2.2 and used for the signatureValue field of the ASN.1 *Certificate* structure described in RFC 5280 sections 4.1.1.3 and 5.1.1.3.

## RETURN VALUES

**d2i\_DSAPublicKey**(), **d2i\_DSA\_PUBKEY**(), **d2i\_DSA\_PUBKEY\_bio**(), **d2i\_DSA\_PUBKEY\_fp**(), **d2i\_DSAPrivateKey**(), **d2i\_DSAPrivateKey\_bio**(), **d2i\_DSAPrivateKey\_fp**(), **d2i\_DSAparams**(), **d2i\_DSAparams\_bio**(), **d2i\_DSAparams\_fp**(), and **DSAparams\_dup**() return a valid *DSA* object or NULL if an error occurs.

**d2i\_DSA\_SIG**() returns a valid *DSA\_SIG* object or NULL if an error occurs.

## SEE ALSO

ASN1\_item\_d2i(3), DSA\_new(3), DSA\_SIG\_new(3), EVP\_PKEY\_set1\_DSA(3), PEM\_write\_DSAPrivateKey(3), X509\_PUBKEY\_new(3)

## STANDARDS

RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile, section 4.1: Basic Certificate Fields

RFC 3279: Algorithms and Identifiers for the Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile:

- section 2.2.2: DSA Signature Algorithm

- section 2.3.2: DSA Signature Keys

## HISTORY

**d2i\_DSAPublicKey**(), **i2d\_DSAPublicKey**(), **d2i\_DSAPrivateKey**(), and **i2d\_DSAPrivateKey**() first appeared in SSLeay 0.6.0. **d2i\_DSAPrivateKey\_bio**(), **d2i\_DSAPrivateKey\_fp**(), **i2d\_DSAPrivateKey\_bio**(), **i2d\_DSAPrivateKey\_fp**(), **d2i\_DSAparams**(), **i2d\_DSAparams**(), **d2i\_DSAparams\_bio**(), **i2d\_DSAparams\_bio**(), **d2i\_DSAparams\_fp**(), **i2d\_DSAparams\_fp**(), and **DSAparams\_dup**() first appeared in SSLeay 0.8.0. These functions have been available since OpenBSD 2.4.

**d2i\_DSA\_SIG**() and **i2d\_DSA\_SIG**() first appeared in OpenSSL 0.9.3 and have been available since OpenBSD 2.6.

**d2i\_DSA\_PUBKEY**(), **i2d\_DSA\_PUBKEY**(), **d2i\_DSA\_PUBKEY\_bio**(), **d2i\_DSA\_PUBKEY\_fp**(), **i2d\_DSA\_PUBKEY\_bio**(), and **i2d\_DSA\_PUBKEY\_fp**() first appeared in OpenSSL 0.9.5 and have been available since OpenBSD 2.7.
