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 from gnutls_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 from gnutls_privkey_flags_t. no rogue bits allowed πŸ™ˆ
  • const gnutls_keygen_data_st * data β€” lets you specify gnutls_keygen_data_st types, like the seed to be used. yes, you can hand-pick your seed 🌱
  • unsigned data_size β€” the number of data available (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 Β© 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