ioctl(cfd, CIOCFSESSION, &sess.ses);
ret =
- gnutls_crypto_single_mac_register(i, 90, &mac_struct);
+ gnutls_crypto_single_mac_register(i, 90, &mac_struct, 0);
if (ret < 0) {
gnutls_assert();
return ret;
gnutls_mac_get_name(i));
ret =
gnutls_crypto_single_digest_register(i, 90,
- &digest_struct);
+ &digest_struct, 0);
if (ret < 0) {
gnutls_assert();
return ret;
ret =
gnutls_crypto_single_digest_register
(GNUTLS_DIG_SHA384, 80,
- &_gnutls_sha_padlock_nano);
+ &_gnutls_sha_padlock_nano, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_digest_register
(GNUTLS_DIG_SHA512, 80,
- &_gnutls_sha_padlock_nano);
+ &_gnutls_sha_padlock_nano, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_mac_register
(GNUTLS_MAC_SHA384, 80,
- &_gnutls_hmac_sha_padlock_nano);
+ &_gnutls_hmac_sha_padlock_nano, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_mac_register
(GNUTLS_MAC_SHA512, 80,
- &_gnutls_hmac_sha_padlock_nano);
+ &_gnutls_hmac_sha_padlock_nano, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_digest_register(GNUTLS_DIG_SHA1,
80,
- &_gnutls_sha_padlock_nano);
+ &_gnutls_sha_padlock_nano, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_digest_register(GNUTLS_DIG_SHA224,
80,
- &_gnutls_sha_padlock_nano);
+ &_gnutls_sha_padlock_nano, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_digest_register(GNUTLS_DIG_SHA256,
80,
- &_gnutls_sha_padlock_nano);
+ &_gnutls_sha_padlock_nano, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_mac_register(GNUTLS_MAC_SHA1,
80,
- &_gnutls_hmac_sha_padlock_nano);
+ &_gnutls_hmac_sha_padlock_nano, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_mac_register(GNUTLS_MAC_SHA256,
80,
- &_gnutls_hmac_sha_padlock_nano);
+ &_gnutls_hmac_sha_padlock_nano, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_digest_register(GNUTLS_DIG_SHA1,
80,
- &_gnutls_sha_padlock);
+ &_gnutls_sha_padlock, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_digest_register(GNUTLS_DIG_SHA256,
80,
- &_gnutls_sha_padlock);
+ &_gnutls_sha_padlock, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_mac_register(GNUTLS_MAC_SHA1,
80,
- &_gnutls_hmac_sha_padlock);
+ &_gnutls_hmac_sha_padlock, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_mac_register(GNUTLS_MAC_SHA256,
80,
- &_gnutls_hmac_sha_padlock);
+ &_gnutls_hmac_sha_padlock, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_digest_register(GNUTLS_DIG_SHA1,
80,
- &_gnutls_sha_x86_ssse3);
+ &_gnutls_sha_x86_ssse3, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_digest_register(GNUTLS_DIG_SHA224,
80,
- &_gnutls_sha_x86_ssse3);
+ &_gnutls_sha_x86_ssse3, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_digest_register(GNUTLS_DIG_SHA256,
80,
- &_gnutls_sha_x86_ssse3);
+ &_gnutls_sha_x86_ssse3, 0);
if (ret < 0) {
gnutls_assert();
}
ret =
gnutls_crypto_single_mac_register(GNUTLS_MAC_SHA1,
80,
- &_gnutls_hmac_sha_x86_ssse3);
+ &_gnutls_hmac_sha_x86_ssse3, 0);
if (ret < 0)
gnutls_assert();
ret =
gnutls_crypto_single_mac_register(GNUTLS_MAC_SHA224,
80,
- &_gnutls_hmac_sha_x86_ssse3);
+ &_gnutls_hmac_sha_x86_ssse3, 0);
if (ret < 0)
gnutls_assert();
ret =
gnutls_crypto_single_mac_register(GNUTLS_MAC_SHA256,
80,
- &_gnutls_hmac_sha_x86_ssse3);
+ &_gnutls_hmac_sha_x86_ssse3, 0);
if (ret < 0)
gnutls_assert();
ret =
gnutls_crypto_single_digest_register(GNUTLS_DIG_SHA384,
80,
- &_gnutls_sha_x86_ssse3);
+ &_gnutls_sha_x86_ssse3, 0);
if (ret < 0)
gnutls_assert();
ret =
gnutls_crypto_single_digest_register(GNUTLS_DIG_SHA512,
80,
- &_gnutls_sha_x86_ssse3);
+ &_gnutls_sha_x86_ssse3, 0);
if (ret < 0)
gnutls_assert();
ret =
gnutls_crypto_single_mac_register(GNUTLS_MAC_SHA384,
80,
- &_gnutls_hmac_sha_x86_ssse3);
+ &_gnutls_hmac_sha_x86_ssse3, 0);
if (ret < 0)
gnutls_assert();
ret =
gnutls_crypto_single_mac_register(GNUTLS_MAC_SHA512,
80,
- &_gnutls_hmac_sha_x86_ssse3);
+ &_gnutls_hmac_sha_x86_ssse3, 0);
if (ret < 0)
gnutls_assert();
#endif
return NULL;
}
-static cipher_list glob_cl = { GNUTLS_CIPHER_NULL, 0, NULL, NULL };
-static mac_list glob_ml = { GNUTLS_MAC_NULL, 0, NULL, NULL };
-static digest_list glob_dl = { GNUTLS_MAC_NULL, 0, NULL, NULL };
+static cipher_list glob_cl = { GNUTLS_CIPHER_NULL, 0, NULL, 0, NULL };
+static mac_list glob_ml = { GNUTLS_MAC_NULL, 0, NULL, 0, NULL };
+static digest_list glob_dl = { GNUTLS_MAC_NULL, 0, NULL, 0, NULL };
static void _deregister(algo_list * cl)
{
int
gnutls_crypto_single_mac_register(gnutls_mac_algorithm_t algorithm,
int priority,
- const gnutls_crypto_mac_st * s)
+ const gnutls_crypto_mac_st * s,
+ int free_s)
{
- return _algo_register(&glob_ml, algorithm, priority, s, 0);
+ return _algo_register(&glob_ml, algorithm, priority, (void*)s, free_s);
}
const gnutls_crypto_mac_st *_gnutls_get_crypto_mac(gnutls_mac_algorithm_t
int
gnutls_crypto_single_digest_register(gnutls_digest_algorithm_t algorithm,
int priority,
- const gnutls_crypto_digest_st * s)
+ const gnutls_crypto_digest_st * s,
+ int free_s)
{
- return _algo_register(&glob_dl, algorithm, priority, s, 0);
+ return _algo_register(&glob_dl, algorithm, priority, (void*)s, free_s);
}
const gnutls_crypto_digest_st
return GNUTLS_E_CRYPTO_ALREADY_REGISTERED;
}
+/**
+ * gnutls_crypto_register_mac:
+ * @algorithm: is the gnutls MAC identifier
+ * @priority: is the priority of the algorithm
+ * @init: A function which initializes the MAC
+ * @setkey: A function which sets the key of the MAC
+ * @setnonce: A function which sets the nonce for the mac (may be %NULL for common MAC algorithms)
+ * @hash: Perform the hash operation
+ * @output: Provide the output of the MAC
+ * @deinit: A function which deinitializes the MAC
+ * @hash_fast: Perform the MAC operation in one go
+ *
+ * This function will register a MAC algorithm to be used by gnutls.
+ * Any algorithm registered will override the included algorithms and
+ * by convention kernel implemented algorithms have priority of 90
+ * and CPU-assisted of 80.
+ * The algorithm with the lowest priority will be used by gnutls.
+ *
+ * Returns: %GNUTLS_E_SUCCESS on success, otherwise a negative error code.
+ *
+ * Since: 3.4.0
+ **/
+int
+gnutls_crypto_register_mac(gnutls_mac_algorithm_t algorithm,
+ int priority,
+ 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 hash_fast)
+{
+ gnutls_crypto_mac_st *s = gnutls_calloc(1, sizeof(gnutls_crypto_mac_st));
+ if (s == NULL)
+ return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
+
+ s->init = init;
+ s->setkey = setkey;
+ s->setnonce = setnonce;
+ s->hash = hash;
+ s->output = output;
+ s->fast = hash_fast;
+ s->deinit = deinit;
+
+ return gnutls_crypto_single_mac_register(algorithm, priority, s, 1);
+}
+
+/**
+ * gnutls_crypto_register_digest:
+ * @algorithm: is the gnutls digest identifier
+ * @priority: is the priority of the algorithm
+ * @init: A function which initializes the digest
+ * @hash: Perform the hash operation
+ * @output: Provide the output of the digest
+ * @deinit: A function which deinitializes the digest
+ * @hash_fast: Perform the digest operation in one go
+ *
+ * This function will register a digest algorithm to be used by gnutls.
+ * Any algorithm registered will override the included algorithms and
+ * by convention kernel implemented algorithms have priority of 90
+ * and CPU-assisted of 80.
+ * The algorithm with the lowest priority will be used by gnutls.
+ *
+ * Returns: %GNUTLS_E_SUCCESS on success, otherwise a negative error code.
+ *
+ * Since: 3.4.0
+ **/
+int
+gnutls_crypto_register_digest(gnutls_digest_algorithm_t algorithm,
+ int priority,
+ gnutls_digest_init_func init,
+ gnutls_digest_hash_func hash,
+ gnutls_digest_output_func output,
+ gnutls_digest_deinit_func deinit,
+ gnutls_digest_fast_func hash_fast)
+{
+ gnutls_crypto_digest_st *s = gnutls_calloc(1, sizeof(gnutls_crypto_digest_st));
+ if (s == NULL)
+ return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
+
+ s->init = init;
+ s->hash = hash;
+ s->output = output;
+ s->fast = hash_fast;
+ s->deinit = deinit;
+
+ return gnutls_crypto_single_digest_register(algorithm, priority, s, 1);
+}
} gnutls_crypto_cipher_st;
typedef struct {
- int (*init) (gnutls_mac_algorithm_t, void **ctx);
- int (*setkey) (void *ctx, const void *key, size_t keysize);
- int (*setnonce) (void *ctx, const void *nonce, size_t noncesize);
- int (*hash) (void *ctx, const void *text, size_t textsize);
- int (*output) (void *src_ctx, void *digest, size_t digestsize);
- void (*deinit) (void *ctx);
- int (*fast) (gnutls_mac_algorithm_t, const void *nonce,
- size_t nonce_size, const void *key, size_t keysize,
- const void *text, size_t textsize, void *digest);
+ 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;
/* Not needed for registered on run-time. Only included
* should define it. */
} gnutls_crypto_mac_st;
typedef struct {
- int (*init) (gnutls_digest_algorithm_t, void **ctx);
- int (*hash) (void *ctx, const void *src, size_t srcsize);
- int (*output) (void *src_ctx, void *digest, size_t digestsize);
- void (*deinit) (void *ctx);
- int (*fast) (gnutls_digest_algorithm_t, const void *src,
- size_t srcsize, void *digest);
+ 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;
/* Not needed for registered on run-time. Only included
* should define it. */
int gnutls_crypto_single_mac_register(gnutls_mac_algorithm_t algorithm,
int priority,
const gnutls_crypto_single_mac_st *
- s);
+ s, int free_s);
int gnutls_crypto_single_digest_register(gnutls_digest_algorithm_t
algorithm, int priority,
const
gnutls_crypto_single_digest_st *
- s);
+ s, int free_s);
int gnutls_crypto_rnd_register(int priority,
const gnutls_crypto_rnd_st * s);
void gnutls_rnd_refresh(void);
+
+/* API to override ciphers and MAC algorithms
+ */
+
typedef int (*gnutls_cipher_init_func) (gnutls_cipher_algorithm_t, void **ctx, int enc);
typedef int (*gnutls_cipher_setkey_func) (void *ctx, const void *key, size_t keysize);
/* old style ciphers */
gnutls_cipher_aead_decrypt_func aead_decrypt,
gnutls_cipher_deinit_func deinit);
+typedef int (*gnutls_mac_init_func) (gnutls_mac_algorithm_t, void **ctx);
+typedef int (*gnutls_mac_setkey_func) (void *ctx, const void *key, size_t keysize);
+typedef int (*gnutls_mac_setnonce_func) (void *ctx, const void *nonce, size_t noncesize);
+typedef int (*gnutls_mac_hash_func) (void *ctx, const void *text, size_t textsize);
+typedef int (*gnutls_mac_output_func) (void *src_ctx, void *digest, size_t digestsize);
+typedef void (*gnutls_mac_deinit_func) (void *ctx);
+typedef int (*gnutls_mac_fast_func) (gnutls_mac_algorithm_t, const void *nonce,
+ size_t nonce_size, const void *key, size_t keysize,
+ const void *text, size_t textsize, void *digest);
+
+int
+gnutls_crypto_register_mac(gnutls_mac_algorithm_t mac,
+ int priority,
+ 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 hash_fast);
+
+typedef int (*gnutls_digest_init_func) (gnutls_digest_algorithm_t, void **ctx);
+typedef int (*gnutls_digest_hash_func) (void *ctx, const void *text, size_t textsize);
+typedef int (*gnutls_digest_output_func) (void *src_ctx, void *digest, size_t digestsize);
+typedef void (*gnutls_digest_deinit_func) (void *ctx);
+typedef int (*gnutls_digest_fast_func) (gnutls_digest_algorithm_t,
+ const void *text, size_t textsize, void *digest);
+
+int
+gnutls_crypto_register_digest(gnutls_digest_algorithm_t digest,
+ int priority,
+ gnutls_digest_init_func init,
+ gnutls_digest_hash_func hash,
+ gnutls_digest_output_func output,
+ gnutls_digest_deinit_func deinit,
+ gnutls_digest_fast_func hash_fast);
+
/* *INDENT-OFF* */
#ifdef __cplusplus
}
gnutls_pkcs11_obj_set_info;
gnutls_crypto_register_cipher;
gnutls_crypto_register_aead_cipher;
+ gnutls_crypto_register_mac;
+ gnutls_crypto_register_digest;
local:
*;
};