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 be NULL, no pressure babe)
  • gnutls_privkey_sign_hash_func sign_hash_fn β€” also a callback for signature operations (may be NULL)
  • gnutls_privkey_decrypt_func decrypt_fn β€” the callback for decryption operations (may be NULL)
  • 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 be NULL πŸ™ˆ
  • 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 Β© 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