gnutls_x509_privkey_generate2(3)
β¨ gnutls_x509_privkey_generate2 β¨
okay bestie, this one lives in the gnutls manual (yes, that gnutls, the TLS library of the people) π and it's literally the glow-up machine for private keys. say hi to gnutls_x509_privkey_generate2 β she makes keys, and she's picky about how.
πΈ SYNOPSIS πΈ
#include <gnutls/x509.h>
int gnutls_x509_privkey_generate2(gnutls_x509_privkey_t key,
gnutls_pk_algorithm_t algo, unsigned int bits, unsigned int flags, const
gnutls_keygen_data_st * data, unsigned data_size);
π ARGUMENTS π
gnutls_x509_privkey_t keyβ a key. like, the key. the main character πgnutls_pk_algorithm_t algoβ one of the algorithms fromgnutls_pk_algorithm_t. pick your fighter β¨unsigned int bitsβ the size of the modulus. that's the bigness, bestie πunsigned int flagsβ must be zero, or flags fromgnutls_privkey_flags_t. no rogue bits allowed πconst gnutls_keygen_data_st * dataβ lets you specifygnutls_keygen_data_sttypes, like the seed to be used. yes, you can hand-pick your seed π±unsigned data_sizeβ the number ofdataavailable (count 'em) π’
π DESCRIPTION π
so this function generates a random private key. periodt. but note β she must be called on an initialized private key, so init first, queen. no shortcuts π«Ά
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. On DSA keys the PQG parameters are generated using the seed, while on RSA it's the two primes. to specify an explicit seed (by default a random seed is used, no cap), use the data with a GNUTLS_KEYGEN_SEED type. the way that works is genuinely iconic π₯
also! when you're generating an elliptic curve key, the curve can be substituted in the place of the bits parameter using the GNUTLS_CURVE_TO_BITS() macro. curve swap realness π¦
to export the generated keys in memory or in files, it's 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. generated keys can be exported in memory using gnutls_privkey_export_x509(), and then with gnutls_x509_privkey_export2_pkcs8(). chain them, it's giving pipeline π
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 your app? we love to see it π
also see gnutls_privkey_generate2(). sibling behavior, iykyk π«
β RETURNS β
on success, GNUTLS_E_SUCCESS (0) is returned. otherwise you get a negative error value π (a little sad, but at least it's honest)
π REPORTING BUGS π
found a bug? not me gatekeeping β 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. slay, and also legally binding π
π§ 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, bestie β no cap, every flag intact π
gnutls 3.8.13 β gnutls_x509_privkey_generate2(3), signing off π«Άβ¨
π¦ 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