gnutls_privkey_import_ext4(3)
π gnutls_privkey_import_ext4 β the glow-up of the external privkey glow-up π
okay bestie, so this one lives in the gnutls manual (section 3, the library-call girlies), and it's literally the fourth edition of "let me hand you my own private key callbacks and you handle the rest". We're in gnutls/abstract.h territory, it's giving "I brought my own crypto, pls just use it", and honestly? iconic.
β¨ SYNOPSIS β¨
#include <gnutls/abstract.h>
int gnutls_privkey_import_ext4(gnutls_privkey_t pkey, void * userdata,
gnutls_privkey_sign_data_func sign_data_fn,
gnutls_privkey_sign_hash_func sign_hash_fn, gnutls_privkey_decrypt_func
decrypt_fn, gnutls_privkey_deinit_func deinit_fn,
gnutls_privkey_info_func info_fn, unsigned int flags);
π ARGUMENTS π
gnutls_privkey_t pkeyβ the private key itself. the main character, fr.void * userdataβ your own lil stash of private data that gets handed over to the callbacks. it's your stuff, gnutls is just the courier π«Άgnutls_privkey_sign_data_func sign_data_fnβ the callback for signature operations (may beNULL, no pressure babe)gnutls_privkey_sign_hash_func sign_hash_fnβ also a callback for signature operations (may beNULL)gnutls_privkey_decrypt_func decrypt_fnβ the callback for decryption operations (may beNULL)gnutls_privkey_deinit_func deinit_fnβ a deinitialization function, aka the cleanup crew π§Ήgnutls_privkey_info_func info_fnβ returns info about the public key algorithm. heads up: this one should not beNULLπunsigned int flagsβ flags for the import. the little switches that change the vibe β
πΈ DESCRIPTION πΈ
So this function will associate the given callbacks with the gnutls_privkey_t type. That's the whole point. At least one of the callbacks must be non-null β you can't just show up empty-handed, bestie π
If a deinitialization function is provided then flags is assumed to contain GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE. like, it just is. assumed. periodt.
Now, the important lore: in contrast with the signing function of gnutls_privkey_import_ext3(), the signing functions provided to this function take explicitly the signature algorithm as a parameter, and different functions are provided to sign the data and hashes. so it's giving "we split the job into two" β no cap, that's the upgrade.
The sign_hash_fn is to be called to sign pre-hashed data. The input to the callback is the output of the hash (such as SHA256) corresponding to the signature algorithm. For RSA PKCS1 signatures, the signature algorithm can be set to GNUTLS_SIGN_RSA_RAW, and in that case the data should be handled as if they were an RSA PKCS1 DigestInfo structure. π
The sign_data_fn is to be called to sign data. The input data will be he data to be signed (and hashed), with the provided signature algorithm. (yes, "he data" β the manpage said it, I'm not fixing it, that's the original text's little moment π). This function is to be used for signature algorithms like Ed25519 which cannot take pre-hashed data as input.
When both sign_data_fn and sign_hash_fn functions are provided they must be able to operate on all the supported signature algorithms, unless prohibited by the type of the algorithm (e.g., as with Ed25519). so like, they gotta be versatile β¨
The info_fn must provide information on the signature algorithms supported by this private key, and should support the flags GNUTLS_PRIVKEY_INFO_PK_ALGO, GNUTLS_PRIVKEY_INFO_HAVE_SIGN_ALGO and GNUTLS_PRIVKEY_INFO_PK_ALGO_BITS. It must return -1 on unknown flags. that's the rule, don't fight it π
π RETURNS π
On success, GNUTLS_E_SUCCESS (0) is returned, otherwise a negative error value. so if you see a negative number, that's not a vibe check you passed, bestie. π
π¦ SINCE π¦
3.6.0 β a classic, been here since forever in crypto years.
π’ REPORTING BUGS π’
Report bugs to <bugs@gnutls.org>.
Home page: https://www.gnutls.org
π COPYRIGHT π
Copyright Β© 2001-2023 Free Software Foundation, Inc., and others.
Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. (tl;dr: share it, just keep the receipts π§Ύ)
π SEE ALSO π
The full documentation for gnutls is maintained as a Texinfo manual. If the /usr/share/doc/gnutls/ directory does not contain the HTML form visit
https://www.gnutls.org/manual/
and that's the whole page, babe π this was gnutls 3.8.13 with gnutls_privkey_import_ext4(3) β mwah, go write some callbacks, you're gonna slay πβ¨
π¦ where this page comes from
- alpine 3.22: gnutls-doc 3.8.13-r0 Β· LGPL-2.1-or-later
- alpine 3.23: gnutls-doc 3.8.13-r0 Β· LGPL-2.1-or-later
- alpine 3.24: gnutls-doc 3.8.13-r0 Β· LGPL-2.1-or-later
- arch rolling: gnutls 3.8.13-3 Β· GPL-3.0-or-later AND LGPL-2.1-or-later
- fedora 43: gnutls-devel 3.8.13-1.fc43 Β· GPL-3.0-or-later AND LGPL-2.1-or-later
- fedora 43: gnutls-devel 3.8.13-1.fc43 Β· GPL-3.0-or-later AND LGPL-2.1-or-later
- fedora 44: gnutls-devel 3.8.13-1.fc44 Β· GPL-3.0-or-later AND LGPL-2.1-or-later
- fedora 44: gnutls-devel 3.8.13-1.fc44 Β· GPL-3.0-or-later AND LGPL-2.1-or-later
- ubuntu stonking: gnutls-doc 3.8.13-1ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms