summaryrefslogtreecommitdiff
path: root/man/keyctl_dh_compute.3
blob: 5b79378d93eb76b5b0160140b38159fe352eb0bf (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
.\"
.\" Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
.\" Copyright (C) 2016 Intel Corporation. All rights reserved.
.\"
.\" This program is free software; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License
.\" as published by the Free Software Foundation; either version
.\" 2 of the License, or (at your option) any later version.
.\"
.TH KEYCTL_DH_COMPUTE 3 "07 Apr 2016" Linux "Linux Key Management Calls"
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.SH NAME
keyctl_dh_compute \- Compute a Diffie-Hellman shared secret or public key
.br
keyctl_dh_compute_kdf \- Derive key from a Diffie-Hellman shared secret
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.SH SYNOPSIS
.nf
.B #include <keyutils.h>
.sp
.BI "long keyctl_dh_compute(key_serial_t " private ", key_serial_t " prime ,
.BI "key_serial_t " base ", char *" buffer ", size_t " buflen ");"
.sp
.BI "long keyctl_dh_compute_alloc(key_serial_t " private,
.BI "key_serial_t " prime ", key_serial_t " base ", void **" _buffer ");"
.sp
.BI "long keyctl_dh_compute_kdf(key_serial_t " private ", key_serial_t " prime ,
.BI "key_serial_t " base ", char *" hashname ", char *" otherinfo ",
.BI "size_t " otherinfolen ", char *" buffer ", size_t " buflen ");"
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.SH DESCRIPTION
.BR keyctl_dh_compute ()
computes a Diffie-Hellman public key or shared secret.  That computation is:
.IP
.I base
^
.I private
( mod
.I prime
)
.P
When
.I base
is a key containing the shared generator value, the remote public key is
computed.  When
.I base
is a key containing the remote public key, the shared secret is computed.
.P
.IR base ", " private ", and " prime
must all refer to
.BR user -type
keys containing the parameters for the computation.  Each of these keys must
grant the caller
.B read
permission in order for them to be used.
.P
.I buffer
and
.I buflen
specify the buffer into which the computed result will be placed.
.I buflen
may be zero, in which case the buffer is not used and the minimum buffer length
is fetched.
.P
.BR keyctl_dh_compute_alloc ()
is similar to
.BR keyctl_dh_compute ()
except that it allocates a buffer big enough to hold the payload data and
places the data in it.  If successful, a pointer to the buffer is placed in
.IR *_buffer .
The caller must free the buffer.
.P
.BR keyctl_dh_compute_kdf ()
derives a key from a Diffie-Hellman shared secret according to the protocol
specified in SP800-56A. The Diffie-Hellman computation is based on the same
primitives as discussed
for
.BR keyctl_dh_compute ().
.P
To implement the protocol of SP800-56A
.I base
is a key containing the remote public key to compute the Diffie-Hellman
shared secret. That shared secret is post-processed with a key derivation
function.
.P
The
.I hashname
specifies the Linux kernel crypto API name for a hash that shall be used
for the key derivation function, such as sha256.
The
.I hashname
must be a NULL terminated string.  See
.I /proc/crypto
for available hashes on the system.
.P
Following the specification of SP800-56A section 5.8.1.2 the
.I otherinfo
parameter may be provided. The format of the OtherInfo field is defined
by the caller. The caller may also specify NULL as a valid argument when
no OtherInfo data shall be processed. The length of the
.I otherinfo
parameter is specified with
.I otherinfolen
and is restricted to a maximum length by the kernel.
.P
The KDF returns the requested number of bytes specified with the
.I genlen
or the
.I buflen
parameter depending on the invoked function.
.P
.I buffer
and
.I buflen
specify the buffer into which the computed result will be placed.
.P
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.SH RETURN VALUE
On success
.BR keyctl_dh_compute ()
returns the amount of data placed into the buffer when
.I buflen
is non-zero.  When
.I buflen
is zero, the minimum buffer length to hold the data is returned.
.P
On success
.BR keyctl_dh_compute_alloc ()
returns the amount of data in the buffer.
.P
On error, both functions set errno to an appropriate code and return the value
.BR -1 .
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.SH ERRORS
.TP
.B ENOKEY
One of the keys specified is invalid or not readable.
.TP
.B EINVAL
The buffer pointer is invalid or buflen is too small.
.TP
.B EOPNOTSUPP
One of the keys was not a valid user key.
.TP
.B EMSGSIZE
When using
.BR keyctl_dh_compute_kdf (),
the size of either
.I otherinfolen
or
.I buflen
is too big.
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.SH LINKING
This is a library function that can be found in
.IR libkeyutils .
When linking,
.B \-lkeyutils
should be specified to the linker.
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.SH SEE ALSO
.BR keyctl (1),
.br
.BR keyctl (2),
.br
.BR keyctl (3),
.br
.BR keyutils (7)