crypto-backend

crypto-backend

Functions

Types and Values

Description

Functions

FIX_SIGN_PARAMS()

#define             FIX_SIGN_PARAMS(params, flags, dig)

gnutls_pk_params_release ()

void
gnutls_pk_params_release (gnutls_pk_params_st *p);

gnutls_pk_params_clear ()

void
gnutls_pk_params_clear (gnutls_pk_params_st *p);

gnutls_pk_params_init ()

void
gnutls_pk_params_init (gnutls_pk_params_st *p);

gnutls_crypto_single_cipher_register ()

int
gnutls_crypto_single_cipher_register (gnutls_cipher_algorithm_t algorithm,
                                      int priority,
                                      const gnutls_crypto_single_cipher_st *s,
                                      int free_s);

gnutls_crypto_single_mac_register ()

int
gnutls_crypto_single_mac_register (gnutls_mac_algorithm_t algorithm,
                                   int priority,
                                   const gnutls_crypto_single_mac_st *s,
                                   int free_s);

gnutls_crypto_single_digest_register ()

int
gnutls_crypto_single_digest_register (gnutls_digest_algorithm_t algorithm,
                                      int priority,
                                      const gnutls_crypto_single_digest_st *s,
                                      int free_s);

gnutls_crypto_rnd_register ()

int
gnutls_crypto_rnd_register (int priority,
                            const gnutls_crypto_rnd_st *s);

gnutls_crypto_pk_register ()

int
gnutls_crypto_pk_register (int priority,
                           const gnutls_crypto_pk_st *s);

gnutls_crypto_bigint_register ()

int
gnutls_crypto_bigint_register (int priority,
                               const gnutls_crypto_bigint_st *s);

Types and Values

gnutls_crypto_single_cipher_st

#define gnutls_crypto_single_cipher_st gnutls_crypto_cipher_st

gnutls_crypto_single_mac_st

#define gnutls_crypto_single_mac_st gnutls_crypto_mac_st

gnutls_crypto_single_digest_st

#define gnutls_crypto_single_digest_st gnutls_crypto_digest_st

gnutls_crypto_cipher_st

typedef struct {
	gnutls_cipher_init_func init;
	gnutls_cipher_setkey_func setkey;
	gnutls_cipher_setiv_func setiv;
	gnutls_cipher_getiv_func getiv;
	gnutls_cipher_encrypt_func encrypt;
	gnutls_cipher_decrypt_func decrypt;
	gnutls_cipher_aead_encrypt_func aead_encrypt;
	gnutls_cipher_aead_decrypt_func aead_decrypt;
	gnutls_cipher_deinit_func deinit;
	gnutls_cipher_auth_func auth;
	gnutls_cipher_tag_func tag;

	/* Not needed for registered on run-time. Only included
	 * should define it. */
	int (*exists) (gnutls_cipher_algorithm_t); /* true/false */
} gnutls_crypto_cipher_st;

gnutls_crypto_mac_st

typedef struct {
	gnutls_mac_init_func init;
	gnutls_mac_setkey_func setkey;
	gnutls_mac_setnonce_func setnonce;
	gnutls_mac_hash_func hash;
	gnutls_mac_output_func output;
	gnutls_mac_deinit_func deinit;
	gnutls_mac_fast_func fast;
	gnutls_mac_copy_func copy;

	/* Not needed for registered on run-time. Only included
	 * should define it. */
	int (*exists) (gnutls_mac_algorithm_t);
} gnutls_crypto_mac_st;

gnutls_crypto_digest_st

typedef struct {
	gnutls_digest_init_func init;
	gnutls_digest_hash_func hash;
	gnutls_digest_output_func output;
	gnutls_digest_deinit_func deinit;
	gnutls_digest_fast_func fast;
	gnutls_digest_copy_func copy;

	/* Not needed for registered on run-time. Only included
	 * should define it. */
	int (*exists) (gnutls_digest_algorithm_t);
} gnutls_crypto_digest_st;

gnutls_crypto_kdf_st

typedef struct {
	int (*hkdf_extract) (gnutls_mac_algorithm_t,
			     const void *key, size_t keysize,
			     const void *salt, size_t saltsize,
			     void *output);
	int (*hkdf_expand) (gnutls_mac_algorithm_t,
			    const void *key, size_t keysize,
			    const void *info, size_t infosize,
			    void *output, size_t length);
	int (*pbkdf2) (gnutls_mac_algorithm_t,
		       const void *key, size_t keysize,
		       const void *salt, size_t saltsize,
		       unsigned iter_count,
		       void *output, size_t length);
} gnutls_crypto_kdf_st;

gnutls_crypto_rnd_st

typedef struct {
	int (*init) (void **ctx); /* called prior to first usage of randomness */
	int (*rnd) (void *ctx, int level, void *data, size_t datasize);
	void (*rnd_refresh) (void *ctx);
	void (*deinit) (void *ctx);
	int (*self_test) (void); /* this should not require rng initialization */
} gnutls_crypto_rnd_st;

bigint_t

typedef void *bigint_t;

enum gnutls_bigint_format_t

Enumeration of different bignum integer encoding formats.

Members

GNUTLS_MPI_FORMAT_USG

Raw unsigned integer format.

 

GNUTLS_MPI_FORMAT_STD

Raw signed integer format, always a leading zero when positive.

 

GNUTLS_MPI_FORMAT_ULE

   

gnutls_crypto_bigint_st

typedef struct {
	int (*bigint_init) (bigint_t*);
	int (*bigint_init_multi) (bigint_t*, ...);
	void (*bigint_release) (bigint_t n);
	void (*bigint_clear) (bigint_t n); /* zeros the int */
	/* 0 for equality, > 0 for m1>m2, < 0 for m1<m2 */
	int (*bigint_cmp) (const bigint_t m1, const bigint_t m2);
	/* as bigint_cmp */
	int (*bigint_cmp_ui) (const bigint_t m1, unsigned long m2);
	/* r = a % b */
	int (*bigint_modm) (bigint_t r, const bigint_t a, const bigint_t b);
	/* a = b -> ret == a */
	int (*bigint_set) (bigint_t a, const bigint_t b);
	bigint_t (*bigint_copy) (const bigint_t a);
	/* a = b -> ret == a */
	int (*bigint_set_ui) (bigint_t a, unsigned long b);
	unsigned int (*bigint_get_nbits) (const bigint_t a);
	/* w = b ^ e mod m */
	int (*bigint_powm) (bigint_t w, const bigint_t b,
				 const bigint_t e, const bigint_t m);
	/* w = a + b mod m */
	int (*bigint_addm) (bigint_t w, const bigint_t a,
				 const bigint_t b, const bigint_t m);
	/* w = a - b mod m */
	int (*bigint_subm) (bigint_t w, const bigint_t a,
				 const bigint_t b, const bigint_t m);
	/* w = a * b mod m */
	int (*bigint_mulm) (bigint_t w, const bigint_t a,
				 const bigint_t b, const bigint_t m);
	/* w = a + b */ int (*bigint_add) (bigint_t w,
					       const bigint_t a,
					       const bigint_t b);
	/* w = a - b */ int (*bigint_sub) (bigint_t w,
					       const bigint_t a,
					       const bigint_t b);
	/* w = a * b */
	int (*bigint_mul) (bigint_t w, const bigint_t a,
				const bigint_t b);
	/* w = a + b */
	int (*bigint_add_ui) (bigint_t w, const bigint_t a,
				   unsigned long b);
	/* w = a - b */
	int (*bigint_sub_ui) (bigint_t w, const bigint_t a,
				   unsigned long b);
	/* w = a * b */
	int (*bigint_mul_ui) (bigint_t w, const bigint_t a,
				   unsigned long b);
	/* q = a / b */
	int (*bigint_div) (bigint_t q, const bigint_t a,
				const bigint_t b);
	/* 0 if prime */
	int (*bigint_prime_check) (const bigint_t pp);

	/* reads a bigint from a buffer */
	/* stores a bigint into the buffer.  returns
	 * GNUTLS_E_SHORT_MEMORY_BUFFER if buf_size is not sufficient to
	 * store this integer, and updates the buf_size;
	 */
	int (*bigint_scan) (bigint_t m, const void *buf, size_t buf_size,
				 gnutls_bigint_format_t format);
	int (*bigint_print) (const bigint_t a, void *buf,
			     size_t * buf_size,
			     gnutls_bigint_format_t format);
} gnutls_crypto_bigint_st;

gnutls_x509_spki_st

typedef struct {
	/* We can have a key which is of type RSA, but a certificate
	 * of type RSA-PSS; the value here will be the expected value
	 * for signatures (i.e., RSA-PSS) */
	gnutls_pk_algorithm_t pk;

	/* the digest used by RSA-PSS */
	gnutls_digest_algorithm_t rsa_pss_dig;

	/* the size of salt used by RSA-PSS */
	unsigned int salt_size;

	/* if non-zero, the legacy value for PKCS#7 signatures will be
	 * written for RSA signatures. */
	unsigned int legacy;

	/* the digest used by ECDSA/DSA */
	gnutls_digest_algorithm_t dsa_dig;

	/* flags may include GNUTLS_PK_FLAG_REPRODUCIBLE for
	 * deterministic ECDSA/DSA */
	unsigned int flags;
} gnutls_x509_spki_st;

GNUTLS_MAX_PK_PARAMS

#define GNUTLS_MAX_PK_PARAMS 16

gnutls_pk_params_st

typedef struct {
	bigint_t params[GNUTLS_MAX_PK_PARAMS];
	unsigned int params_nr; /* the number of parameters */
	unsigned int pkflags; /* gnutls_pk_flag_t */
	unsigned int qbits; /* GNUTLS_PK_DH */
	gnutls_ecc_curve_t curve; /* GNUTLS_PK_EC, GNUTLS_PK_ED25519, GNUTLS_PK_GOST* */
	gnutls_group_t dh_group; /* GNUTLS_PK_DH - used by ext/key_share */
	gnutls_gost_paramset_t gost_params; /* GNUTLS_PK_GOST_* */
	gnutls_datum_t raw_pub; /* used by x25519 */
	gnutls_datum_t raw_priv;

	unsigned int seed_size;
	uint8_t seed[MAX_PVP_SEED_SIZE];
	gnutls_digest_algorithm_t palgo;
	/* public key information */
	gnutls_x509_spki_st spki;

	gnutls_pk_algorithm_t algo;
} gnutls_pk_params_st;

enum gnutls_pk_flag_t

Enumeration of public-key flag.

Members

GNUTLS_PK_FLAG_NONE

No flag.

 

GNUTLS_PK_FLAG_PROVABLE

   

GNUTLS_PK_FLAG_REPRODUCIBLE

   

GNUTLS_PK_FLAG_RSA_PSS_FIXED_SALT_LENGTH

   

MAX_PUBLIC_PARAMS_SIZE

#define MAX_PUBLIC_PARAMS_SIZE 4 /* ok for RSA and DSA */

DSA_PUBLIC_PARAMS

#define DSA_PUBLIC_PARAMS 4

DH_PUBLIC_PARAMS

#define DH_PUBLIC_PARAMS 4

RSA_PUBLIC_PARAMS

#define RSA_PUBLIC_PARAMS 2

ECC_PUBLIC_PARAMS

#define ECC_PUBLIC_PARAMS 2

GOST_PUBLIC_PARAMS

#define GOST_PUBLIC_PARAMS 2

MAX_PRIV_PARAMS_SIZE

#define MAX_PRIV_PARAMS_SIZE GNUTLS_MAX_PK_PARAMS /* ok for RSA and DSA */

DSA_PRIVATE_PARAMS

#define DSA_PRIVATE_PARAMS 5

DH_PRIVATE_PARAMS

#define DH_PRIVATE_PARAMS 5

RSA_PRIVATE_PARAMS

#define RSA_PRIVATE_PARAMS 8

ECC_PRIVATE_PARAMS

#define ECC_PRIVATE_PARAMS 3

GOST_PRIVATE_PARAMS

#define GOST_PRIVATE_PARAMS 3

ECC_X

#define ECC_X 0

ECC_Y

#define ECC_Y 1

ECC_K

#define ECC_K 2

GOST_X

#define GOST_X 0

GOST_Y

#define GOST_Y 1

GOST_K

#define GOST_K 2

DSA_P

#define DSA_P 0

DSA_Q

#define DSA_Q 1

DSA_G

#define DSA_G 2

DSA_Y

#define DSA_Y 3

DSA_X

#define DSA_X 4

DH_P

#define DH_P 0

DH_Q

#define DH_Q 1

DH_G

#define DH_G 2

DH_Y

#define DH_Y 3

DH_X

#define DH_X 4

RSA_MODULUS

#define RSA_MODULUS 0

RSA_PUB

#define RSA_PUB 1

RSA_PRIV

#define RSA_PRIV 2

RSA_PRIME1

#define RSA_PRIME1 3

RSA_PRIME2

#define RSA_PRIME2 4

RSA_COEF

#define RSA_COEF 5

RSA_E1

#define RSA_E1 6

RSA_E2

#define RSA_E2 7

enum gnutls_direction_t

Enumeration of different directions.

Members

GNUTLS_IMPORT

Import direction.

 

GNUTLS_EXPORT

Export direction.

 

gnutls_crypto_pk_st

typedef struct {
	/* The params structure should contain the private or public key
	 * parameters, depending on the operation */
	int (*encrypt) (gnutls_pk_algorithm_t, gnutls_datum_t * ciphertext,
			const gnutls_datum_t * plaintext,
			const gnutls_pk_params_st * pub);
	int (*decrypt) (gnutls_pk_algorithm_t,
                        gnutls_datum_t * plaintext,
			const gnutls_datum_t * ciphertext,
			const gnutls_pk_params_st * priv);
	int (*decrypt2) (gnutls_pk_algorithm_t,
			 const gnutls_datum_t * ciphertext,
                         unsigned char * plaintext,
                         size_t paintext_size,
			 const gnutls_pk_params_st * priv);
	int (*sign) (gnutls_pk_algorithm_t, gnutls_datum_t * signature,
		     const gnutls_datum_t * data,
		     const gnutls_pk_params_st *priv,
		     const gnutls_x509_spki_st *sign);
	int (*verify) (gnutls_pk_algorithm_t, const gnutls_datum_t * data,
		       const gnutls_datum_t * sig,
		       const gnutls_pk_params_st *pub,
		       const gnutls_x509_spki_st *sign);
	/* sanity checks the public key parameters */
	int (*verify_priv_params) (gnutls_pk_algorithm_t,
			      const gnutls_pk_params_st * priv);
	int (*verify_pub_params) (gnutls_pk_algorithm_t,
			      const gnutls_pk_params_st * pub);
	int (*generate_keys) (gnutls_pk_algorithm_t, unsigned int nbits,
			 gnutls_pk_params_st *, unsigned ephemeral);
	int (*generate_params) (gnutls_pk_algorithm_t, unsigned int nbits,
			 gnutls_pk_params_st *);
	/* this function should convert params to ones suitable
	 * for the above functions
	 */
	int (*pk_fixup_private_params) (gnutls_pk_algorithm_t,
					gnutls_direction_t,
					gnutls_pk_params_st *);
#define PK_DERIVE_TLS13 1
	int (*derive) (gnutls_pk_algorithm_t, gnutls_datum_t * out,
		       const gnutls_pk_params_st * priv,
		       const gnutls_pk_params_st * pub,
		       const gnutls_datum_t *nonce,
		       unsigned int flags);

	int (*curve_exists) (gnutls_ecc_curve_t); /* true/false */
	int (*pk_exists) (gnutls_pk_algorithm_t); /* true/false */
	int (*sign_exists) (gnutls_sign_algorithm_t); /* true/false */
} gnutls_crypto_pk_st;