gnutls_privkey_generate2(3)
π gnutls_privkey_generate2 π
okay bestie, welcome to the gnutls manual, we're doing the whole ~abstract key~ thing today and honestly? iconic. this one's about making brand new private keys from scratch, no cap. ποΈβ¨
β¨ NAME β¨
gnutls_privkey_generate2 β it's literally an API function, that's the whole vibe
πΈ SYNOPSIS πΈ
#include <gnutls/abstract.h>
int gnutls_privkey_generate2(gnutls_privkey_t pkey,
gnutls_pk_algorithm_t algo, unsigned int bits, unsigned int flags, const
gnutls_keygen_data_st * data, unsigned data_size);
like yes, six args, she's a lot, but we'll get through it together π«Ά
π ARGUMENTS π
gnutls_privkey_t pkeyβ the private key itself. your main character. πgnutls_pk_algorithm_t algoβ pick your fighter, it's one of the algorithms fromgnutls_pk_algorithm_t.unsigned int bitsβ the size of the modulus, aka how beefy we're going. πͺunsigned int flagsβ has to be zero, or flags fromgnutls_privkey_flags_t. no random numbers here bestie.const gnutls_keygen_data_st * dataβ lets you specifygnutls_keygen_data_sttypes, like the seed you wanna use. πunsigned data_sizeβ how manydatayou actually have. the count, fr fr.
π¦ DESCRIPTION π¦
so this function generates a random private key. π« and heads up: you must call it on an initialized private key. don't come in with an uninitialized key, she will simply not cooperate. π
the flag GNUTLS_PRIVKEY_FLAG_PROVABLE tells the key generation process to use algorithms like Shawe-Taylor (from FIPS PUB186-4) which generate provable parameters out of a seed for RSA and DSA keys. lowkey obsessed with how that works. on DSA keys the PQG parameters get generated using the seed, while on RSA it's the two primes. and if you wanna specify an explicit seed (by default a random seed is used, the classic), you use the data with a GNUTLS_KEYGEN_SEED type. π―
also, when you're generating an elliptic curve key, the curve can be substituted in the place of thebitsparameter using theGNUTLS_CURVE_TO_BITS()macro. yes the macro. it's giving "we don't have a curve argument so we're being clever." π
to export the generated keys in memory or in files it is recommended to use the PKCS8 form, because it can handle all key types, and can store additional parameters such as the seed, in case of provable RSA or DSA keys. slay, flexible format. β¨ generated keys can be exported in memory using gnutls_privkey_export_x509(), and then with gnutls_x509_privkey_export2_pkcs8().
and here's the tip that will save you: if key generation is part of your application, avoid setting the number of bits directly, and instead use gnutls_sec_param_to_pk_bits(). that way the generated keys will adapt to the security levels of the underlying GnuTLS library. future-proofing?? we love to see it. π
π RETURNS π
on success, GNUTLS_E_SUCCESS (0) comes back to you, otherwise you get a negative error value. simple as that, bestie. π
β SINCE β
3.5.0 β she's been around, she's got history.
π REPORTING BUGS π
found a bug? don't suffer in silence, report it 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. no notes, that's actually so generous of them. π«Ά
πΈ 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/
okay that's the whole page!! this was gnutls version 3.8.13, page gnutls_privkey_generate2(3), and you absolutely ate that reading bestie. go generate some keys, stay provable, and drink water. πβ¨ππ¦
π¦ 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