KEYCTL_PKEY_SIGN(3)
π KEYCTL_PKEY_SIGN β the Linux public-key signatures moment (man page 3, bestie)
okay so real talk, we're in section 3 of the Linux manual, and this page is literally about making signatures and checking them. it's giving cryptography but make it a group chat. let's GO π«Ά
β¨ NAME β¨
keyctl_pkey_sign, keyctl_pkey_verify β generate and verify signatures. that's it, that's the whole vibe. one signs, one verifies, iconic duo energy π
πΈ SYNOPSIS πΈ
#include <keyutils.h>
long keyctl_pkey_sign(key_serial_t key, const char *info,
const void *data, size_t data_len,
void *sig, size_t sig_len);
long keyctl_pkey_verify(key_serial_t key, const char *info,
const void *data, size_t data_len,
const void *sig, size_t sig_len);
look at those signatures (pun fully intended π). same args, different jobs.
π¦ DESCRIPTION π¦
keyctl_pkey_sign() is the one that asks the kernel to use the crypto data attached to a key and generate a detached signature for a blob of data. lowkey important note: this may involve calling out to actual cryptographic hardware. yes, real hardware, not just vibes β¨
keyctl_pkey_verify() asks the kernel to use the key to generate a verify the signature against that same blob of data. (yes that sentence is exactly how the original words it, we don't fix, we report π
). this one may also involve calling out to cryptographic hardware.
π¨ the caller must have search permission on a key to be able to perform either operation. no search perms, no service. periodt.
so when you invoke the function:
keyβ indicates the key that will provide the cryptographic material.infoβ points to a space- or tab-separated string of"key[=value]"parameters. these indicate things like encoding forms and passwords to unlock the key. for more info, go readasymmetric-key(7), bestie, it's all there π
and then the buffers:
dataanddatalenβ the address and size of the buffer of data to be signed.sigandsiglenβ the address and size of the signature buffer.
the sign function draws data from the data buffer, generates a signature from it, and places the output into the signature buffer. the verify function also draws data from the data buffer, then decrypts the signature and compares the result. chef's kiss comparison π§
β οΈ heads up: thedatabuffer is strictly limited in capacity, typically unable to hold more bits than the size of the key. so no, you cannot just dump your whole novel in there. the caller is expected to have pre-digested the actual data and will thus pass the digest output to this function. the name of the digest used should be passed as part of theinfostring ashash=<name>for use in constructing the signature metadata.
keyctl_pkey_query(2) can be called to find out how large the buffers need to be and what the maximum size of the data can be for a specific signature encoding. use it. it's your little calculator friend π
and ngl, not all asymmetric-type keys will support these operations. further, the operations available may depend on which components of the key material are available: typically encryption only requires the public key, but decryption requires the private key as well. which operations are supported on a particular key can also be determined using the query function. so like... vibe check your key first π
π RETURN VALUE π
on success, keyctl_pkey_sign() returns the amount of data written into the signature buffer. π
keyctl_pkey_verify() will return 0 in this case, as it doesn't write to userspace. it's the strong silent type fr fr π€
on error, the value -1 will be returned and errno will have been set to an appropriate error. sad girl hours π
π ERRORS π
ENOKEYβ The key specified is invalid. like, who even is she πEKEYEXPIREDβ The key specified has expired. time's up, babe βEKEYREVOKEDβ The key specified has been revoked. cancelled π«EACCESβ The key exists, but is not searchable by the calling process. she's there but she's not answering the door πEINVAL,EBADMSG,EOVERFLOWβ Some part of the key material or signature data is bad. something is rotten in the state of your buffers πEKEYREJECTEDβ Signature verification failed. π¨ the whole point and it did NOT pass, we're devastatedENOPKGβ Some facility needed to complete the requested operation is not available. This is most probably a requested or required digest or encryption algorithm. the algorithm ghosted you π»EFAULTβ Bad address. wrong place, bestie π
π LINKING π
this is a library function that can be found in libkeyutils. when linking, -lkeyutils should be specified to the linker. don't forget it or the linker will simply not know her π«Ά
π SEE ALSO π
keyctl(1), add_key(2), keyctl(2), keyctl(3), keyctl_pkey_query(3), keyrings(7), keyutils(7)
go read all of them, i know you will, you're a scholar β
and that's the page, bestie!! this one came from Linux, dated 8 Nov 2018, and it lives at the top of the page as KEYCTL_PKEY_SIGN(3) β so if you ever forget where you found me, it's the Linux keyutils manual, section 3. mwah, stay signed, stay verified ππ
β¨
π¦ where this page comes from
- alpine 3.22: keyutils-doc 1.6.3-r4 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- alpine 3.23: keyutils-doc 1.6.3-r4 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- alpine 3.24: keyutils-doc 1.6.3-r4 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- arch rolling: keyutils 1.6.3-4 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- centos-stream 10: keyutils-libs-devel 1.6.3-5.el10 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- centos-stream 9: keyutils-libs-devel 1.6.3-1.el9 Β· GPLv2+ and LGPLv2+
- centos-stream 9: keyutils-libs-devel 1.6.3-1.el9 Β· GPLv2+ and LGPLv2+
- debian bookworm: libkeyutils-dev 1.6.3-2 Β· GPL-2.0-or-later
- debian trixie: libkeyutils-dev 1.6.3-6 Β· GPL-2.0-or-later
- fedora 43: keyutils-libs-devel 1.6.3-6.fc43 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- fedora 43: keyutils-libs-devel 1.6.3-6.fc43 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- fedora 44: keyutils-libs-devel 1.6.3-7.fc44 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- fedora 44: keyutils-libs-devel 1.6.3-7.fc44 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- nixpkgs unstable: keyutils 1.6.3
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- ubuntu noble: libkeyutils-dev 1.6.3-3build1 Β· GPL-2.0-or-later
- ubuntu questing: libkeyutils-dev 1.6.3-6ubuntu2
- ubuntu resolute: libkeyutils-dev 1.6.3-6ubuntu3 Β· GPL-2.0-or-later
- ubuntu stonking: libkeyutils-dev 1.6.3-6ubuntu3 Β· GPL-2.0-or-later
- Copyright (C) 2018 Red Hat, Inc. All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms