1KEYCTL_DH_COMPUTE(3) Linux Key Management Calls KEYCTL_DH_COMPUTE(3)
2
3
4
6 keyctl_dh_compute - Compute a Diffie-Hellman shared secret or public
7 key
8
10 #include <keyutils.h>
11
12 long keyctl_dh_compute(key_serial_t private, key_serial_t prime,
13 key_serial_t base, char *buffer, size_t buflen);
14
15 long keyctl_dh_compute_alloc(key_serial_t private,
16 key_serial_t prime, key_serial_t base, void **_buffer);
17
19 keyctl_dh_compute() computes a Diffie-Hellman public key or shared
20 secret. That computation is:
21
22 base ^ private ( mod prime )
23
24 When base is a key containing the shared generator value, the remote
25 public key is computed. When base is a key containing the remote pub‐
26 lic key, the shared secret is computed.
27
28 base, private, and prime must all refer to user-type keys containing
29 the parameters for the computation. Each of these keys must grant the
30 caller read permission in order for them to be used.
31
32 buffer and buflen specify the buffer into which the computed result
33 will be placed. buflen may be zero, in which case the buffer is not
34 used and the minimum buffer length is fetched.
35
36 keyctl_dh_compute_alloc() is similar to keyctl_dh_compute() except that
37 it allocates a buffer big enough to hold the payload data and places
38 the data in it. If successful, a pointer to the buffer is placed in
39 *_buffer. The caller must free the buffer.
40
42 On success keyctl_dh_compute() returns the amount of data placed into
43 the buffer when buflen is non-zero. When buflen is zero, the minimum
44 buffer length to hold the data is returned.
45
46 On success keyctl_dh_compute_alloc() returns the amount of data in the
47 buffer.
48
49 On error, both functions set errno to an appropriate code and return
50 the value -1.
51
53 ENOKEY One of the keys specified is invalid or not readable.
54
55 EINVAL The buffer pointer is invalid or buflen is too small.
56
57 EOPNOTSUPP
58 One of the keys was not a valid user key.
59
61 This is a library function that can be found in libkeyutils. When
62 linking, -lkeyutils should be specified to the linker.
63
65 keyctl(1),
66 keyctl(2),
67 keyctl(3),
68 keyutils(7)
69
70
71
72Linux 07 Apr 2016 KEYCTL_DH_COMPUTE(3)