summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/DH_generate_key.3
blob: 6e2edbadb3e12d371976c9f61daf8f95f3ec9275 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
.Dd $Mdocdate: November 2 2016 $
.Dt DH_GENERATE_KEY 3
.Os
.Sh NAME
.Nm DH_generate_key ,
.Nm DH_compute_key
.Nd perform Diffie-Hellman key exchange
.Sh SYNOPSIS
.In openssl/dh.h
.Ft int
.Fo DH_generate_key
.Fa "DH *dh"
.Fc
.Ft int
.Fo DH_compute_key
.Fa "unsigned char *key"
.Fa "BIGNUM *pub_key"
.Fa "DH *dh"
.Fc
.Sh DESCRIPTION
.Fn DH_generate_key
performs the first step of a Diffie-Hellman key exchange by generating
private and public DH values.
By calling
.Fn DH_compute_key ,
these are combined with the other party's public value to compute the
shared key.
.Pp
.Fn DH_generate_key
expects
.Fa dh
to contain the shared parameters
.Sy dh->p
and
.Sy dh->g .
It generates a random private DH value unless
.Sy dh->priv_key
is already set, and computes the corresponding public value
.Sy dh->pub_key ,
which can then be published.
.Pp
.Fn DH_compute_key
computes the shared secret from the private DH value in
.Fa dh
and the other party's public value in
.Fa pub_key
and stores it in
.Fa key .
.Fa key
must point to
.Fn DH_size dh
bytes of memory.
.Sh RETURN VALUES
.Fn DH_generate_key
returns 1 on success, 0 otherwise.
.Pp
.Fn DH_compute_key
returns the size of the shared secret on success, -1 on error.
.Pp
The error codes can be obtained by
.Xr ERR_get_error 3 .
.Sh SEE ALSO
.Xr dh 3 ,
.Xr DH_size 3 ,
.Xr ERR_get_error 3 ,
.Xr rand 3
.Sh HISTORY
.Fn DH_generate_key
and
.Fn DH_compute_key
are available in all versions of SSLeay and OpenSSL.