summaryrefslogtreecommitdiff
path: root/lib/crypto-backend.h
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2023-04-24 12:39:42 +0900
committerDaiki Ueno <ueno@gnu.org>2023-04-24 12:45:46 +0900
commitaa5950abab56b011331ad4331409b6ff8efb8aeb (patch)
treead363fb38e8b65c942876641cda9c76caa13b498 /lib/crypto-backend.h
parent0fe9cb6842d63761718046cc7dd7eb437e6c5163 (diff)
downloadgnutls-aa5950abab56b011331ad4331409b6ff8efb8aeb.tar.gz
build: re-indent code
Signed-off-by: Daiki Ueno <ueno@gnu.org>
Diffstat (limited to 'lib/crypto-backend.h')
-rw-r--r--lib/crypto-backend.h336
1 files changed, 162 insertions, 174 deletions
diff --git a/lib/crypto-backend.h b/lib/crypto-backend.h
index 03c5ca5433..8f11ce9036 100644
--- a/lib/crypto-backend.h
+++ b/lib/crypto-backend.h
@@ -21,13 +21,13 @@
*/
#ifndef GNUTLS_LIB_CRYPTO_BACKEND_H
-# define GNUTLS_LIB_CRYPTO_BACKEND_H
+#define GNUTLS_LIB_CRYPTO_BACKEND_H
-# include <gnutls/crypto.h>
+#include <gnutls/crypto.h>
-# define gnutls_crypto_single_cipher_st gnutls_crypto_cipher_st
-# define gnutls_crypto_single_mac_st gnutls_crypto_mac_st
-# define gnutls_crypto_single_digest_st gnutls_crypto_digest_st
+#define gnutls_crypto_single_cipher_st gnutls_crypto_cipher_st
+#define gnutls_crypto_single_mac_st gnutls_crypto_mac_st
+#define gnutls_crypto_single_digest_st gnutls_crypto_digest_st
typedef struct {
gnutls_cipher_init_func init;
@@ -44,7 +44,7 @@ typedef struct {
/* Not needed for registered on run-time. Only included
* should define it. */
- int (*exists)(gnutls_cipher_algorithm_t); /* true/false */
+ int (*exists)(gnutls_cipher_algorithm_t); /* true/false */
} gnutls_crypto_cipher_st;
typedef struct {
@@ -76,25 +76,23 @@ typedef struct {
} gnutls_crypto_digest_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,
+ 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);
+ 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;
typedef struct gnutls_crypto_rnd {
- int (*init)(void **ctx); /* called prior to first usage of randomness */
+ 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 */
+ int (*self_test)(void); /* this should not require rng initialization */
} gnutls_crypto_rnd_st;
typedef void *bigint_t;
@@ -121,7 +119,7 @@ typedef struct gnutls_crypto_bigint {
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 */
+ 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 */
@@ -130,26 +128,26 @@ typedef struct gnutls_crypto_bigint {
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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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 */
@@ -170,8 +168,8 @@ typedef struct gnutls_crypto_bigint {
*/
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);
+ int (*bigint_print)(const bigint_t a, void *buf, size_t *buf_size,
+ gnutls_bigint_format_t format);
} gnutls_crypto_bigint_st;
/* Additional information about the public key, filled from
@@ -202,17 +200,18 @@ typedef struct gnutls_x509_spki_st {
unsigned int flags;
} gnutls_x509_spki_st;
-# define GNUTLS_MAX_PK_PARAMS 16
+#define GNUTLS_MAX_PK_PARAMS 16
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 */
+ 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;
@@ -237,52 +236,54 @@ typedef enum {
GNUTLS_PK_FLAG_RSA_PSS_FIXED_SALT_LENGTH = 4
} gnutls_pk_flag_t;
-# define FIX_SIGN_PARAMS(params, flags, dig) do { \
- if ((flags) & GNUTLS_PRIVKEY_FLAG_REPRODUCIBLE) { \
- (params).flags |= GNUTLS_PK_FLAG_REPRODUCIBLE; \
- } \
- if ((params).pk == GNUTLS_PK_DSA || (params).pk == GNUTLS_PK_ECDSA) { \
- (params).dsa_dig = (dig); \
- } \
-} while (0)
+#define FIX_SIGN_PARAMS(params, flags, dig) \
+ do { \
+ if ((flags)&GNUTLS_PRIVKEY_FLAG_REPRODUCIBLE) { \
+ (params).flags |= GNUTLS_PK_FLAG_REPRODUCIBLE; \
+ } \
+ if ((params).pk == GNUTLS_PK_DSA || \
+ (params).pk == GNUTLS_PK_ECDSA) { \
+ (params).dsa_dig = (dig); \
+ } \
+ } while (0)
-void gnutls_pk_params_release(gnutls_pk_params_st * p);
-void gnutls_pk_params_clear(gnutls_pk_params_st * p);
-void gnutls_pk_params_init(gnutls_pk_params_st * p);
+void gnutls_pk_params_release(gnutls_pk_params_st *p);
+void gnutls_pk_params_clear(gnutls_pk_params_st *p);
+void gnutls_pk_params_init(gnutls_pk_params_st *p);
-# define MAX_PUBLIC_PARAMS_SIZE 4 /* ok for RSA and DSA */
+#define MAX_PUBLIC_PARAMS_SIZE 4 /* ok for RSA and DSA */
/* parameters should not be larger than this limit */
-# define DSA_PUBLIC_PARAMS 4
-# define DH_PUBLIC_PARAMS 4
-# define RSA_PUBLIC_PARAMS 2
-# define ECC_PUBLIC_PARAMS 2
-# define GOST_PUBLIC_PARAMS 2
+#define DSA_PUBLIC_PARAMS 4
+#define DH_PUBLIC_PARAMS 4
+#define RSA_PUBLIC_PARAMS 2
+#define ECC_PUBLIC_PARAMS 2
+#define GOST_PUBLIC_PARAMS 2
-# define MAX_PRIV_PARAMS_SIZE GNUTLS_MAX_PK_PARAMS /* ok for RSA and DSA */
+#define MAX_PRIV_PARAMS_SIZE GNUTLS_MAX_PK_PARAMS /* ok for RSA and DSA */
/* parameters should not be larger than this limit */
-# define DSA_PRIVATE_PARAMS 5
-# define DH_PRIVATE_PARAMS 5
-# define RSA_PRIVATE_PARAMS 8
-# define ECC_PRIVATE_PARAMS 3
-# define GOST_PRIVATE_PARAMS 3
+#define DSA_PRIVATE_PARAMS 5
+#define DH_PRIVATE_PARAMS 5
+#define RSA_PRIVATE_PARAMS 8
+#define ECC_PRIVATE_PARAMS 3
+#define GOST_PRIVATE_PARAMS 3
-# if MAX_PRIV_PARAMS_SIZE - RSA_PRIVATE_PARAMS < 0
-# error INCREASE MAX_PRIV_PARAMS
-# endif
+#if MAX_PRIV_PARAMS_SIZE - RSA_PRIVATE_PARAMS < 0
+#error INCREASE MAX_PRIV_PARAMS
+#endif
-# if MAX_PRIV_PARAMS_SIZE - ECC_PRIVATE_PARAMS < 0
-# error INCREASE MAX_PRIV_PARAMS
-# endif
+#if MAX_PRIV_PARAMS_SIZE - ECC_PRIVATE_PARAMS < 0
+#error INCREASE MAX_PRIV_PARAMS
+#endif
-# if MAX_PRIV_PARAMS_SIZE - GOST_PRIVATE_PARAMS < 0
-# error INCREASE MAX_PRIV_PARAMS
-# endif
+#if MAX_PRIV_PARAMS_SIZE - GOST_PRIVATE_PARAMS < 0
+#error INCREASE MAX_PRIV_PARAMS
+#endif
-# if MAX_PRIV_PARAMS_SIZE - DSA_PRIVATE_PARAMS < 0
-# error INCREASE MAX_PRIV_PARAMS
-# endif
+#if MAX_PRIV_PARAMS_SIZE - DSA_PRIVATE_PARAMS < 0
+#error INCREASE MAX_PRIV_PARAMS
+#endif
/* params are:
* RSA:
@@ -319,34 +320,34 @@ void gnutls_pk_params_init(gnutls_pk_params_st * p);
* [8] is k (private key)
*/
-# define ECC_X 0
-# define ECC_Y 1
-# define ECC_K 2
-
-# define GOST_X 0
-# define GOST_Y 1
-# define GOST_K 2
-
-# define DSA_P 0
-# define DSA_Q 1
-# define DSA_G 2
-# define DSA_Y 3
-# define DSA_X 4
-
-# define DH_P 0
-# define DH_Q 1
-# define DH_G 2
-# define DH_Y 3
-# define DH_X 4
-
-# define RSA_MODULUS 0
-# define RSA_PUB 1
-# define RSA_PRIV 2
-# define RSA_PRIME1 3
-# define RSA_PRIME2 4
-# define RSA_COEF 5
-# define RSA_E1 6
-# define RSA_E2 7
+#define ECC_X 0
+#define ECC_Y 1
+#define ECC_K 2
+
+#define GOST_X 0
+#define GOST_Y 1
+#define GOST_K 2
+
+#define DSA_P 0
+#define DSA_Q 1
+#define DSA_G 2
+#define DSA_Y 3
+#define DSA_X 4
+
+#define DH_P 0
+#define DH_Q 1
+#define DH_G 2
+#define DH_Y 3
+#define DH_X 4
+
+#define RSA_MODULUS 0
+#define RSA_PUB 1
+#define RSA_PRIV 2
+#define RSA_PRIME1 3
+#define RSA_PRIME2 4
+#define RSA_COEF 5
+#define RSA_E1 6
+#define RSA_E2 7
/**
* gnutls_direction_t:
@@ -364,30 +365,26 @@ typedef enum {
typedef struct gnutls_crypto_pk {
/* 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);
+ 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);
+ const gnutls_pk_params_st *priv);
int (*verify_pub_params)(gnutls_pk_algorithm_t,
- const gnutls_pk_params_st * pub);
+ 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,
@@ -398,67 +395,58 @@ typedef struct gnutls_crypto_pk {
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 */
+#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;
/* priority: infinity for backend algorithms, 90 for kernel
algorithms, lowest wins
*/
-int gnutls_crypto_single_cipher_register(gnutls_cipher_algorithm_t
- algorithm, int priority,
- const gnutls_crypto_single_cipher_st *
- s, int free_s);
+int gnutls_crypto_single_cipher_register(
+ gnutls_cipher_algorithm_t algorithm, int priority,
+ const gnutls_crypto_single_cipher_st *s, int free_s);
int gnutls_crypto_single_mac_register(gnutls_mac_algorithm_t algorithm,
int priority,
- const gnutls_crypto_single_mac_st * s,
+ const gnutls_crypto_single_mac_st *s,
int free_s);
-int gnutls_crypto_single_digest_register(gnutls_digest_algorithm_t algorithm,
- int priority,
- const gnutls_crypto_single_digest_st *
- s, int free_s);
+int gnutls_crypto_single_digest_register(
+ gnutls_digest_algorithm_t algorithm, int priority,
+ const gnutls_crypto_single_digest_st *s, int free_s);
-int gnutls_crypto_rnd_register(int priority, const gnutls_crypto_rnd_st * s);
-int gnutls_crypto_pk_register(int priority, const gnutls_crypto_pk_st * s);
+int gnutls_crypto_rnd_register(int priority, const gnutls_crypto_rnd_st *s);
+int gnutls_crypto_pk_register(int priority, const gnutls_crypto_pk_st *s);
int gnutls_crypto_bigint_register(int priority,
- const gnutls_crypto_bigint_st * s);
+ const gnutls_crypto_bigint_st *s);
/* Provided by crypto-backend */
-int
-_gnutls_prf_raw(gnutls_mac_algorithm_t mac,
- size_t master_size, const void *master,
- size_t label_size, const char *label,
- size_t seed_size, const uint8_t * seed, size_t outsize,
- char *out);
+int _gnutls_prf_raw(gnutls_mac_algorithm_t mac, size_t master_size,
+ const void *master, size_t label_size, const char *label,
+ size_t seed_size, const uint8_t *seed, size_t outsize,
+ char *out);
int _gnutls_gost_key_wrap(gnutls_gost_paramset_t gost_params,
- const gnutls_datum_t * kek,
- const gnutls_datum_t * ukm,
- const gnutls_datum_t * cek,
- gnutls_datum_t * enc, gnutls_datum_t * imit);
+ const gnutls_datum_t *kek, const gnutls_datum_t *ukm,
+ const gnutls_datum_t *cek, gnutls_datum_t *enc,
+ gnutls_datum_t *imit);
int _gnutls_gost_key_unwrap(gnutls_gost_paramset_t gost_params,
- const gnutls_datum_t * kek,
- const gnutls_datum_t * ukm,
- const gnutls_datum_t * enc,
- const gnutls_datum_t * imit, gnutls_datum_t * cek);
-
-int
-_gnutls_rsa_pkcs1_sign_pad(size_t key_bits,
- const gnutls_datum_t * data,
- unsigned char *buffer, size_t buffer_size);
-
-int
-_gnutls_rsa_pss_sign_pad(gnutls_x509_spki_st * params,
- size_t key_bits,
- const gnutls_datum_t * data,
- unsigned char *buffer, size_t buffer_size);
-
-#endif /* GNUTLS_LIB_CRYPTO_BACKEND_H */
+ const gnutls_datum_t *kek,
+ const gnutls_datum_t *ukm,
+ const gnutls_datum_t *enc,
+ const gnutls_datum_t *imit, gnutls_datum_t *cek);
+
+int _gnutls_rsa_pkcs1_sign_pad(size_t key_bits, const gnutls_datum_t *data,
+ unsigned char *buffer, size_t buffer_size);
+
+int _gnutls_rsa_pss_sign_pad(gnutls_x509_spki_st *params, size_t key_bits,
+ const gnutls_datum_t *data, unsigned char *buffer,
+ size_t buffer_size);
+
+#endif /* GNUTLS_LIB_CRYPTO_BACKEND_H */