NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | ERRORS | LINKING | SEE ALSO | COLOPHON

KEYCTL_DH_COMPUTE(3)     Linux Key Management Calls     KEYCTL_DH_COMPUTE(3)

NAME         top

       keyctl_dh_compute  - Compute a Diffie-Hellman shared secret or public
       key

SYNOPSIS         top

       #include <keyutils.h>

       long keyctl_dh_compute(key_serial_t private, key_serial_t prime,
       key_serial_t base, char *buffer, size_t buflen);

       long keyctl_dh_compute_alloc(key_serial_t private,
       key_serial_t prime, key_serial_t base, void **_buffer);

DESCRIPTION         top

       keyctl_dh_compute() computes a Diffie-Hellman public key or shared
       secret.  That computation is:

              base ^ private ( mod prime )

       When base is a key containing the shared generator value, the remote
       public key is computed.  When base is a key containing the remote
       public key, the shared secret is computed.

       base, private, and prime must all refer to user-type keys containing
       the parameters for the computation.  Each of these keys must grant
       the caller read permission in order for them to be used.

       buffer and buflen specify the buffer into which the computed result
       will be placed.  buflen may be zero, in which case the buffer is not
       used and the minimum buffer length is fetched.

       keyctl_dh_compute_alloc() is similar to 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 *_buffer.  The caller must free the buffer.

RETURN VALUE         top

       On success keyctl_dh_compute() returns the amount of data placed into
       the buffer when buflen is non-zero.  When buflen is zero, the minimum
       buffer length to hold the data is returned.

       On success keyctl_dh_compute_alloc() returns the amount of data in
       the buffer.

       On error, both functions set errno to an appropriate code and return
       the value -1.

ERRORS         top

       ENOKEY One of the keys specified is invalid or not readable.

       EINVAL The buffer pointer is invalid or buflen is too small.

       EOPNOTSUPP
              One of the keys was not a valid user key.

LINKING         top

       This is a library function that can be found in libkeyutils.  When
       linking, -lkeyutils should be specified to the linker.

SEE ALSO         top

       keyctl(1),
       keyctl(2),
       keyctl(3),
       keyutils(7)

COLOPHON         top

       This page is part of the keyutils (key management utilities) project.
       Information about the project can be found at [unknown -- if you
       know, please contact man-pages@man7.org] If you have a bug report for
       this manual page, send it to keyrings@linux-nfs.org.  This page was
       obtained from the project's upstream Git repository 
       ⟨http://git.kernel.org/pub/scm/linux/kernel/git/dhowells/keyutils.git⟩
       on 2017-03-13.  If you discover any rendering problems in this HTML
       version of the page, or you believe there is a better or more up-to-
       date source for the page, or you have corrections or improvements to
       the information in this COLOPHON (which is not part of the original
       manual page), send a mail to man-pages@man7.org

Linux                            07 Apr 2016            KEYCTL_DH_COMPUTE(3)