1DH_set_method(3)                    OpenSSL                   DH_set_method(3)
2
3
4

NAME

6       DH_set_default_method, DH_get_default_method, DH_set_method,
7       DH_new_method, DH_OpenSSL - select DH method
8

SYNOPSIS

10        #include <openssl/dh.h>
11        #include <openssl/engine.h>
12
13        void DH_set_default_method(const DH_METHOD *meth);
14
15        const DH_METHOD *DH_get_default_method(void);
16
17        int DH_set_method(DH *dh, const DH_METHOD *meth);
18
19        DH *DH_new_method(ENGINE *engine);
20
21        const DH_METHOD *DH_OpenSSL(void);
22

DESCRIPTION

24       A DH_METHOD specifies the functions that OpenSSL uses for Diffie-Hell‐
25       man operations. By modifying the method, alternative implementations
26       such as hardware accelerators may be used. IMPORTANT: See the NOTES
27       section for important information about how these DH API functions are
28       affected by the use of ENGINE API calls.
29
30       Initially, the default DH_METHOD is the OpenSSL internal implementa‐
31       tion, as returned by DH_OpenSSL().
32
33       DH_set_default_method() makes meth the default method for all DH struc‐
34       tures created later. NB: This is true only whilst no ENGINE has been
35       set as a default for DH, so this function is no longer recommended.
36
37       DH_get_default_method() returns a pointer to the current default
38       DH_METHOD.  However, the meaningfulness of this result is dependant on
39       whether the ENGINE API is being used, so this function is no longer
40       recommended.
41
42       DH_set_method() selects meth to perform all operations using the key
43       dh.  This will replace the DH_METHOD used by the DH key and if the pre‐
44       vious method was supplied by an ENGINE, the handle to that ENGINE will
45       be released during the change. It is possible to have DH keys that only
46       work with certain DH_METHOD implementations (eg. from an ENGINE module
47       that supports embedded hardware-protected keys), and in such cases
48       attempting to change the DH_METHOD for the key can have unexpected
49       results.
50
51       DH_new_method() allocates and initializes a DH structure so that engine
52       will be used for the DH operations. If engine is NULL, the default
53       ENGINE for DH operations is used, and if no default ENGINE is set, the
54       DH_METHOD controlled by DH_set_default_method() is used.
55

THE DH_METHOD STRUCTURE

57        typedef struct dh_meth_st
58        {
59            /* name of the implementation */
60               const char *name;
61
62            /* generate private and public DH values for key agreement */
63               int (*generate_key)(DH *dh);
64
65            /* compute shared secret */
66               int (*compute_key)(unsigned char *key, BIGNUM *pub_key, DH *dh);
67
68            /* compute r = a ^ p mod m (May be NULL for some implementations) */
69               int (*bn_mod_exp)(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
70                                       const BIGNUM *m, BN_CTX *ctx,
71                                       BN_MONT_CTX *m_ctx);
72
73            /* called at DH_new */
74               int (*init)(DH *dh);
75
76            /* called at DH_free */
77               int (*finish)(DH *dh);
78
79               int flags;
80
81               char *app_data; /* ?? */
82
83        } DH_METHOD;
84

RETURN VALUES

86       DH_OpenSSL() and DH_get_default_method() return pointers to the respec‐
87       tive DH_METHODs.
88
89       DH_set_default_method() returns no value.
90
91       DH_set_method() returns non-zero if the provided meth was successfully
92       set as the method for dh (including unloading the ENGINE handle if the
93       previous method was supplied by an ENGINE).
94
95       DH_new_method() returns NULL and sets an error code that can be
96       obtained by ERR_get_error(3) if the allocation fails. Otherwise it
97       returns a pointer to the newly allocated structure.
98

NOTES

100       As of version 0.9.7, DH_METHOD implementations are grouped together
101       with other algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in ENGINE
102       modules. If a default ENGINE is specified for DH functionality using an
103       ENGINE API function, that will override any DH defaults set using the
104       DH API (ie.  DH_set_default_method()). For this reason, the ENGINE API
105       is the recommended way to control default implementations for use in DH
106       and other cryptographic algorithms.
107

SEE ALSO

109       dh(3), DH_new(3)
110

HISTORY

112       DH_set_default_method(), DH_get_default_method(), DH_set_method(),
113       DH_new_method() and DH_OpenSSL() were added in OpenSSL 0.9.4.
114
115       DH_set_default_openssl_method() and DH_get_default_openssl_method()
116       replaced DH_set_default_method() and DH_get_default_method() respec‐
117       tively, and DH_set_method() and DH_new_method() were altered to use
118       ENGINEs rather than DH_METHODs during development of the engine version
119       of OpenSSL 0.9.6. For 0.9.7, the handling of defaults in the ENGINE API
120       was restructured so that this change was reversed, and behaviour of the
121       other functions resembled more closely the previous behaviour. The be‐
122       haviour of defaults in the ENGINE API now transparently overrides the
123       behaviour of defaults in the DH API without requiring changing these
124       function prototypes.
125
126
127
1280.9.8b                            2002-10-28                  DH_set_method(3)
Impressum