[INCLUDE]

- import GNUTLS headers
 - define wine's SONAME_LIBGNUTLS to a relevant value

svn path=/trunk/; revision=63995
This commit is contained in:
Jérôme Gardou 2014-08-30 21:32:52 +00:00
parent 6c31293a0b
commit cccf98d172
70 changed files with 16684 additions and 1 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,454 @@
/*
* Copyright (C) 2010-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef __GNUTLS_ABSTRACT_H
#define __GNUTLS_ABSTRACT_H
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#include <gnutls/pkcs11.h>
#include <gnutls/openpgp.h>
#include <gnutls/tpm.h>
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Public key operations */
#define GNUTLS_PUBKEY_VERIFY_FLAG_TLS_RSA GNUTLS_PUBKEY_VERIFY_FLAG_TLS1_RSA
/**
* gnutls_pubkey_flags:
* @GNUTLS_PUBKEY_VERIFY_FLAG_TLS1_RSA: This indicates that a (raw) RSA signature is provided
* as in the TLS 1.0 protocol.
* @GNUTLS_PUBKEY_DISABLE_CALLBACKS: The following flag disables call to PIN callbacks. Only
* relevant to TPM keys.
* @GNUTLS_PUBKEY_GET_OPENPGP_FINGERPRINT: request an OPENPGP fingerprint instead of the default.
*
* Enumeration of different certificate import flags.
*/
typedef enum gnutls_pubkey_flags {
GNUTLS_PUBKEY_VERIFY_FLAG_TLS1_RSA = 1,
GNUTLS_PUBKEY_DISABLE_CALLBACKS = 1 << 2,
GNUTLS_PUBKEY_GET_OPENPGP_FINGERPRINT = 1 << 3,
} gnutls_pubkey_flags_t;
typedef int (*gnutls_privkey_sign_func) (gnutls_privkey_t key,
void *userdata,
const gnutls_datum_t *
raw_data,
gnutls_datum_t * signature);
typedef int (*gnutls_privkey_decrypt_func) (gnutls_privkey_t key,
void *userdata,
const gnutls_datum_t *
ciphertext,
gnutls_datum_t * plaintext);
typedef void (*gnutls_privkey_deinit_func) (gnutls_privkey_t key,
void *userdata);
int gnutls_pubkey_init(gnutls_pubkey_t * key);
void gnutls_pubkey_deinit(gnutls_pubkey_t key);
void gnutls_pubkey_set_pin_function(gnutls_pubkey_t key,
gnutls_pin_callback_t fn,
void *userdata);
int gnutls_pubkey_get_pk_algorithm(gnutls_pubkey_t key,
unsigned int *bits);
int gnutls_pubkey_import_x509(gnutls_pubkey_t key,
gnutls_x509_crt_t crt, unsigned int flags);
int gnutls_pubkey_import_x509_crq(gnutls_pubkey_t key,
gnutls_x509_crq_t crq,
unsigned int flags);
int gnutls_pubkey_import_pkcs11(gnutls_pubkey_t key,
gnutls_pkcs11_obj_t obj,
unsigned int flags);
int gnutls_pubkey_import_openpgp(gnutls_pubkey_t key,
gnutls_openpgp_crt_t crt,
unsigned int flags);
int gnutls_pubkey_import_openpgp_raw(gnutls_pubkey_t pkey,
const gnutls_datum_t * data,
gnutls_openpgp_crt_fmt_t
format,
const gnutls_openpgp_keyid_t
keyid, unsigned int flags);
int gnutls_pubkey_import_x509_raw(gnutls_pubkey_t pkey,
const gnutls_datum_t * data,
gnutls_x509_crt_fmt_t format,
unsigned int flags);
int
gnutls_pubkey_import_privkey(gnutls_pubkey_t key,
gnutls_privkey_t pkey,
unsigned int usage, unsigned int flags);
int
gnutls_pubkey_import_tpm_url(gnutls_pubkey_t pkey,
const char *url,
const char *srk_password, unsigned int flags);
int
gnutls_pubkey_import_url(gnutls_pubkey_t key, const char *url,
unsigned int flags);
int
gnutls_pubkey_import_tpm_raw(gnutls_pubkey_t pkey,
const gnutls_datum_t * fdata,
gnutls_tpmkey_fmt_t format,
const char *srk_password, unsigned int flags);
int gnutls_pubkey_get_preferred_hash_algorithm(gnutls_pubkey_t key,
gnutls_digest_algorithm_t
* hash, unsigned int *mand);
int gnutls_pubkey_get_pk_rsa_raw(gnutls_pubkey_t key,
gnutls_datum_t * m, gnutls_datum_t * e);
int gnutls_pubkey_get_pk_dsa_raw(gnutls_pubkey_t key,
gnutls_datum_t * p,
gnutls_datum_t * q,
gnutls_datum_t * g, gnutls_datum_t * y);
int gnutls_pubkey_get_pk_ecc_raw(gnutls_pubkey_t key,
gnutls_ecc_curve_t * curve,
gnutls_datum_t * x, gnutls_datum_t * y);
int gnutls_pubkey_get_pk_ecc_x962(gnutls_pubkey_t key,
gnutls_datum_t * parameters,
gnutls_datum_t * ecpoint);
int gnutls_pubkey_export(gnutls_pubkey_t key,
gnutls_x509_crt_fmt_t format,
void *output_data, size_t * output_data_size);
int gnutls_pubkey_export2(gnutls_pubkey_t key,
gnutls_x509_crt_fmt_t format,
gnutls_datum_t * out);
int gnutls_pubkey_get_key_id(gnutls_pubkey_t key,
unsigned int flags,
unsigned char *output_data,
size_t * output_data_size);
int
gnutls_pubkey_get_openpgp_key_id(gnutls_pubkey_t key,
unsigned int flags,
unsigned char *output_data,
size_t * output_data_size,
unsigned int *subkey);
int gnutls_pubkey_get_key_usage(gnutls_pubkey_t key, unsigned int *usage);
int gnutls_pubkey_set_key_usage(gnutls_pubkey_t key, unsigned int usage);
int gnutls_pubkey_import(gnutls_pubkey_t key,
const gnutls_datum_t * data,
gnutls_x509_crt_fmt_t format);
int gnutls_pubkey_import_pkcs11_url(gnutls_pubkey_t key,
const char *url, unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */
);
int gnutls_pubkey_import_dsa_raw(gnutls_pubkey_t key,
const gnutls_datum_t * p,
const gnutls_datum_t * q,
const gnutls_datum_t * g,
const gnutls_datum_t * y);
int gnutls_pubkey_import_rsa_raw(gnutls_pubkey_t key,
const gnutls_datum_t * m,
const gnutls_datum_t * e);
int
gnutls_pubkey_import_ecc_x962(gnutls_pubkey_t key,
const gnutls_datum_t * parameters,
const gnutls_datum_t * ecpoint);
int
gnutls_pubkey_import_ecc_raw(gnutls_pubkey_t key,
gnutls_ecc_curve_t curve,
const gnutls_datum_t * x,
const gnutls_datum_t * y);
int
gnutls_pubkey_encrypt_data(gnutls_pubkey_t key,
unsigned int flags,
const gnutls_datum_t * plaintext,
gnutls_datum_t * ciphertext);
int gnutls_x509_crt_set_pubkey(gnutls_x509_crt_t crt, gnutls_pubkey_t key);
int gnutls_x509_crq_set_pubkey(gnutls_x509_crq_t crq, gnutls_pubkey_t key);
int
gnutls_pubkey_verify_hash2(gnutls_pubkey_t key,
gnutls_sign_algorithm_t algo,
unsigned int flags,
const gnutls_datum_t * hash,
const gnutls_datum_t * signature);
int
gnutls_pubkey_get_verify_algorithm(gnutls_pubkey_t key,
const gnutls_datum_t *
signature,
gnutls_digest_algorithm_t * hash);
int
gnutls_pubkey_verify_data2(gnutls_pubkey_t pubkey,
gnutls_sign_algorithm_t algo,
unsigned int flags,
const gnutls_datum_t * data,
const gnutls_datum_t * signature);
/* Private key operations */
int gnutls_privkey_init(gnutls_privkey_t * key);
void gnutls_privkey_deinit(gnutls_privkey_t key);
void gnutls_privkey_set_pin_function(gnutls_privkey_t key,
gnutls_pin_callback_t fn,
void *userdata);
int gnutls_privkey_get_pk_algorithm(gnutls_privkey_t key,
unsigned int *bits);
gnutls_privkey_type_t gnutls_privkey_get_type(gnutls_privkey_t key);
int gnutls_privkey_status(gnutls_privkey_t key);
/**
* gnutls_privkey_flags:
* @GNUTLS_PRIVKEY_SIGN_FLAG_TLS1_RSA: Make an RSA signature on the hashed data as in the TLS protocol.
* @GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE: When importing a private key, automatically
* release it when the structure it was imported is released.
* @GNUTLS_PRIVKEY_IMPORT_COPY: Copy required values during import.
* @GNUTLS_PRIVKEY_DISABLE_CALLBACKS: The following flag disables call to PIN callbacks etc.
* Only relevant to TPM keys.
*
* Enumeration of different certificate import flags.
*/
typedef enum gnutls_privkey_flags {
GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE = 1,
GNUTLS_PRIVKEY_IMPORT_COPY = 1 << 1,
GNUTLS_PRIVKEY_DISABLE_CALLBACKS = 1 << 2,
GNUTLS_PRIVKEY_SIGN_FLAG_TLS1_RSA = 1 << 4,
} gnutls_privkey_flags_t;
int gnutls_privkey_import_pkcs11(gnutls_privkey_t pkey,
gnutls_pkcs11_privkey_t key,
unsigned int flags);
int gnutls_privkey_import_x509(gnutls_privkey_t pkey,
gnutls_x509_privkey_t key,
unsigned int flags);
int gnutls_privkey_import_openpgp(gnutls_privkey_t pkey,
gnutls_openpgp_privkey_t key,
unsigned int flags);
int gnutls_privkey_import_openpgp_raw(gnutls_privkey_t pkey,
const gnutls_datum_t * data,
gnutls_openpgp_crt_fmt_t
format,
const gnutls_openpgp_keyid_t
keyid, const char *password);
int gnutls_privkey_import_x509_raw(gnutls_privkey_t pkey,
const gnutls_datum_t * data,
gnutls_x509_crt_fmt_t format,
const char *password,
unsigned int flags);
int
gnutls_privkey_import_tpm_raw(gnutls_privkey_t pkey,
const gnutls_datum_t * fdata,
gnutls_tpmkey_fmt_t format,
const char *srk_password,
const char *key_password,
unsigned int flags);
int
gnutls_privkey_import_tpm_url(gnutls_privkey_t pkey,
const char *url,
const char *srk_password,
const char *key_password,
unsigned int flags);
int gnutls_privkey_import_url(gnutls_privkey_t key,
const char *url, unsigned int flags);
int gnutls_privkey_import_pkcs11_url(gnutls_privkey_t key,
const char *url);
int
gnutls_privkey_import_ext(gnutls_privkey_t pkey,
gnutls_pk_algorithm_t pk,
void *userdata,
gnutls_privkey_sign_func sign_func,
gnutls_privkey_decrypt_func
decrypt_func, unsigned int flags);
int
gnutls_privkey_import_ext2(gnutls_privkey_t pkey,
gnutls_pk_algorithm_t pk,
void *userdata,
gnutls_privkey_sign_func sign_func,
gnutls_privkey_decrypt_func
decrypt_func,
gnutls_privkey_deinit_func deinit_func,
unsigned int flags);
int gnutls_privkey_sign_data(gnutls_privkey_t signer,
gnutls_digest_algorithm_t hash,
unsigned int flags,
const gnutls_datum_t * data,
gnutls_datum_t * signature);
int gnutls_privkey_sign_hash(gnutls_privkey_t signer,
gnutls_digest_algorithm_t hash_algo,
unsigned int flags,
const gnutls_datum_t * hash_data,
gnutls_datum_t * signature);
int gnutls_privkey_decrypt_data(gnutls_privkey_t key,
unsigned int flags,
const gnutls_datum_t * ciphertext,
gnutls_datum_t * plaintext);
int gnutls_x509_crt_privkey_sign(gnutls_x509_crt_t crt,
gnutls_x509_crt_t issuer,
gnutls_privkey_t issuer_key,
gnutls_digest_algorithm_t dig,
unsigned int flags);
int gnutls_x509_crl_privkey_sign(gnutls_x509_crl_t crl,
gnutls_x509_crt_t issuer,
gnutls_privkey_t issuer_key,
gnutls_digest_algorithm_t dig,
unsigned int flags);
int gnutls_x509_crq_privkey_sign(gnutls_x509_crq_t crq,
gnutls_privkey_t key,
gnutls_digest_algorithm_t dig,
unsigned int flags);
/**
* gnutls_pcert_st:
* @pubkey: public key of parsed certificate.
* @cert: certificate itself of parsed certificate
* @type: type of certificate, a #gnutls_certificate_type_t type.
*
* A parsed certificate.
*/
typedef struct gnutls_pcert_st {
gnutls_pubkey_t pubkey;
gnutls_datum_t cert;
gnutls_certificate_type_t type;
} gnutls_pcert_st;
/* Do not initialize the "cert" element of
* the certificate */
#define GNUTLS_PCERT_NO_CERT 1
int gnutls_pcert_import_x509(gnutls_pcert_st * pcert,
gnutls_x509_crt_t crt, unsigned int flags);
int
gnutls_pcert_list_import_x509_raw(gnutls_pcert_st * pcerts,
unsigned int *pcert_max,
const gnutls_datum_t * data,
gnutls_x509_crt_fmt_t format,
unsigned int flags);
int gnutls_pcert_import_x509_raw(gnutls_pcert_st * pcert,
const gnutls_datum_t * cert,
gnutls_x509_crt_fmt_t format,
unsigned int flags);
int gnutls_pcert_import_openpgp_raw(gnutls_pcert_st * pcert,
const gnutls_datum_t * cert,
gnutls_openpgp_crt_fmt_t
format,
gnutls_openpgp_keyid_t keyid,
unsigned int flags);
int gnutls_pcert_import_openpgp(gnutls_pcert_st * pcert,
gnutls_openpgp_crt_t crt,
unsigned int flags);
void gnutls_pcert_deinit(gnutls_pcert_st * pcert);
/* For certificate credentials */
/* This is the same as gnutls_certificate_retrieve_function()
* but retrieves a gnutls_pcert_st which requires much less processing
* within the library.
*/
typedef int gnutls_certificate_retrieve_function2(gnutls_session_t,
const
gnutls_datum_t *
req_ca_rdn,
int nreqs, const
gnutls_pk_algorithm_t
* pk_algos,
int
pk_algos_length,
gnutls_pcert_st
**, unsigned int
*pcert_length,
gnutls_privkey_t
* privkey);
void gnutls_certificate_set_retrieve_function2
(gnutls_certificate_credentials_t cred,
gnutls_certificate_retrieve_function2 * func);
int
gnutls_certificate_set_key(gnutls_certificate_credentials_t res,
const char **names,
int names_size,
gnutls_pcert_st * pcert_list,
int pcert_list_size, gnutls_privkey_t key);
#include <gnutls/compat.h>
int gnutls_pubkey_verify_data(gnutls_pubkey_t pubkey,
unsigned int flags,
const gnutls_datum_t * data,
const gnutls_datum_t *
signature) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_pubkey_verify_hash(gnutls_pubkey_t key,
unsigned int flags,
const gnutls_datum_t * hash,
const gnutls_datum_t *
signature) _GNUTLS_GCC_ATTR_DEPRECATED;
int
gnutls_pubkey_print(gnutls_pubkey_t pubkey,
gnutls_certificate_print_formats_t format,
gnutls_datum_t * out);
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif

View file

@ -0,0 +1,401 @@
/*
* Copyright (C) 2008-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
/* Typedefs for more compatibility with older GnuTLS. */
#ifndef _GNUTLS_COMPAT_H
#define _GNUTLS_COMPAT_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#ifdef __GNUC__
#define _GNUTLS_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#if !defined GNUTLS_INTERNAL_BUILD
#if _GNUTLS_GCC_VERSION >= 30100
#define _GNUTLS_GCC_ATTR_DEPRECATED __attribute__ ((__deprecated__))
#endif
#endif
#endif /* __GNUC__ */
#ifndef _GNUTLS_GCC_ATTR_DEPRECATED
#define _GNUTLS_GCC_ATTR_DEPRECATED
#endif
/* gnutls_connection_end_t was made redundant in 2.99.0 */
typedef unsigned int gnutls_connection_end_t _GNUTLS_GCC_ATTR_DEPRECATED;
/* Stuff deprected in 2.x */
typedef gnutls_cipher_algorithm_t gnutls_cipher_algorithm
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_kx_algorithm_t gnutls_kx_algorithm
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_mac_algorithm_t gnutls_mac_algorithm
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_digest_algorithm_t gnutls_digest_algorithm
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_compression_method_t gnutls_compression_method
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_connection_end_t gnutls_connection_end
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_x509_crt_fmt_t gnutls_x509_crt_fmt
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_pk_algorithm_t gnutls_pk_algorithm
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_sign_algorithm_t gnutls_sign_algorithm
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_close_request_t gnutls_close_request
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_certificate_request_t gnutls_certificate_request
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_certificate_status_t gnutls_certificate_status
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_session_t gnutls_session _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_alert_level_t gnutls_alert_level
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_alert_description_t gnutls_alert_description
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_x509_subject_alt_name_t gnutls_x509_subject_alt_name
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_openpgp_privkey_t gnutls_openpgp_privkey
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_openpgp_keyring_t gnutls_openpgp_keyring
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_x509_crt_t gnutls_x509_crt _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_x509_privkey_t gnutls_x509_privkey
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_x509_crl_t gnutls_x509_crl _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_x509_crq_t gnutls_x509_crq _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_certificate_credentials_t
gnutls_certificate_credentials _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_anon_server_credentials_t
gnutls_anon_server_credentials _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_anon_client_credentials_t
gnutls_anon_client_credentials _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_srp_client_credentials_t
gnutls_srp_client_credentials _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_srp_server_credentials_t
gnutls_srp_server_credentials _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_dh_params_t gnutls_dh_params _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_rsa_params_t gnutls_rsa_params _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_params_type_t gnutls_params_type
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_credentials_type_t gnutls_credentials_type
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_certificate_type_t gnutls_certificate_type
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_datum_t gnutls_datum _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_transport_ptr_t gnutls_transport_ptr
_GNUTLS_GCC_ATTR_DEPRECATED;
/* Old SRP alerts removed in 2.1.x because the TLS-SRP RFC was
modified to use the PSK alert. */
#define GNUTLS_A_MISSING_SRP_USERNAME GNUTLS_A_UNKNOWN_PSK_IDENTITY
#define GNUTLS_A_UNKNOWN_SRP_USERNAME GNUTLS_A_UNKNOWN_PSK_IDENTITY
/* OpenPGP stuff renamed in 2.1.x. */
#define GNUTLS_OPENPGP_KEY GNUTLS_OPENPGP_CERT
#define GNUTLS_OPENPGP_KEY_FINGERPRINT GNUTLS_OPENPGP_CERT_FINGERPRINT
#define gnutls_openpgp_send_key gnutls_openpgp_send_cert
typedef gnutls_openpgp_crt_status_t gnutls_openpgp_key_status_t
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_openpgp_crt_t gnutls_openpgp_key_t
_GNUTLS_GCC_ATTR_DEPRECATED;
#define gnutls_openpgp_key_init gnutls_openpgp_crt_init
#define gnutls_openpgp_key_deinit gnutls_openpgp_crt_deinit
#define gnutls_openpgp_key_import gnutls_openpgp_crt_import
#define gnutls_openpgp_key_export gnutls_openpgp_crt_export
#define gnutls_openpgp_key_get_key_usage gnutls_openpgp_crt_get_key_usage
#define gnutls_openpgp_key_get_fingerprint gnutls_openpgp_crt_get_fingerprint
#define gnutls_openpgp_key_get_pk_algorithm gnutls_openpgp_crt_get_pk_algorithm
#define gnutls_openpgp_key_get_name gnutls_openpgp_crt_get_name
#define gnutls_openpgp_key_get_version gnutls_openpgp_crt_get_version
#define gnutls_openpgp_key_get_creation_time gnutls_openpgp_crt_get_creation_time
#define gnutls_openpgp_key_get_expiration_time gnutls_openpgp_crt_get_expiration_time
#define gnutls_openpgp_key_get_id gnutls_openpgp_crt_get_id
#define gnutls_openpgp_key_check_hostname gnutls_openpgp_crt_check_hostname
/* OpenPGP stuff renamed in 2.3.x. */
#define gnutls_openpgp_crt_get_id gnutls_openpgp_crt_get_key_id
/* New better names renamed in 2.3.x, add these for backwards
compatibility with old poor names.*/
#define GNUTLS_X509_CRT_FULL GNUTLS_CRT_PRINT_FULL
#define GNUTLS_X509_CRT_ONELINE GNUTLS_CRT_PRINT_ONELINE
#define GNUTLS_X509_CRT_UNSIGNED_FULL GNUTLS_CRT_PRINT_UNSIGNED_FULL
/* Namespace problems. */
#define LIBGNUTLS_VERSION GNUTLS_VERSION
#define LIBGNUTLS_VERSION_MAJOR GNUTLS_VERSION_MAJOR
#define LIBGNUTLS_VERSION_MINOR GNUTLS_VERSION_MINOR
#define LIBGNUTLS_VERSION_PATCH GNUTLS_VERSION_PATCH
#define LIBGNUTLS_VERSION_NUMBER GNUTLS_VERSION_NUMBER
#define LIBGNUTLS_EXTRA_VERSION GNUTLS_VERSION
/* The gnutls_retr_st was deprecated by gnutls_certificate_retrieve_function()
* and gnutls_retr2_st.
*/
typedef struct gnutls_retr_st {
gnutls_certificate_type_t type;
union {
gnutls_x509_crt_t *x509;
gnutls_openpgp_crt_t pgp;
} cert;
unsigned int ncerts; /* one for pgp keys */
union {
gnutls_x509_privkey_t x509;
gnutls_openpgp_privkey_t pgp;
} key;
unsigned int deinit_all; /* if non zero all keys will be deinited */
} gnutls_retr_st;
typedef int
gnutls_certificate_client_retrieve_function(gnutls_session_t,
const
gnutls_datum_t *
req_ca_rdn,
int nreqs, const
gnutls_pk_algorithm_t
* pk_algos, int
pk_algos_length,
gnutls_retr_st *);
typedef int
gnutls_certificate_server_retrieve_function(gnutls_session_t,
gnutls_retr_st *);
void gnutls_certificate_client_set_retrieve_function
(gnutls_certificate_credentials_t cred,
gnutls_certificate_client_retrieve_function *
func) _GNUTLS_GCC_ATTR_DEPRECATED;
void
gnutls_certificate_server_set_retrieve_function
(gnutls_certificate_credentials_t cred,
gnutls_certificate_server_retrieve_function *
func) _GNUTLS_GCC_ATTR_DEPRECATED;
/* External signing callback. No longer supported because it
* was deprecated by the PKCS #11 API or gnutls_privkey_import_ext. */
typedef int (*gnutls_sign_func) (gnutls_session_t session,
void *userdata,
gnutls_certificate_type_t
cert_type,
const gnutls_datum_t * cert,
const gnutls_datum_t * hash,
gnutls_datum_t * signature);
void
gnutls_sign_callback_set(gnutls_session_t session,
gnutls_sign_func sign_func,
void *userdata) _GNUTLS_GCC_ATTR_DEPRECATED;
gnutls_sign_func
gnutls_sign_callback_get(gnutls_session_t session,
void **userdata) _GNUTLS_GCC_ATTR_DEPRECATED;
/* This is a very dangerous and error-prone function.
* Use gnutls_privkey_sign_hash() instead.
*/
int gnutls_x509_privkey_sign_hash(gnutls_x509_privkey_t key,
const gnutls_datum_t * hash,
gnutls_datum_t * signature)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_sign_hash(gnutls_openpgp_privkey_t key,
const gnutls_datum_t * hash,
gnutls_datum_t * signature)
_GNUTLS_GCC_ATTR_DEPRECATED;
/* we support the gnutls_privkey_sign_data() instead.
*/
int gnutls_x509_privkey_sign_data(gnutls_x509_privkey_t key,
gnutls_digest_algorithm_t digest,
unsigned int flags,
const gnutls_datum_t * data,
void *signature,
size_t * signature_size)
_GNUTLS_GCC_ATTR_DEPRECATED;
/* gnutls_pubkey_verify_data() */
int gnutls_x509_crt_verify_data(gnutls_x509_crt_t crt,
unsigned int flags,
const gnutls_datum_t * data,
const gnutls_datum_t * signature)
_GNUTLS_GCC_ATTR_DEPRECATED;
/* gnutls_pubkey_verify_hash() */
int gnutls_x509_crt_verify_hash(gnutls_x509_crt_t crt,
unsigned int flags,
const gnutls_datum_t * hash,
const gnutls_datum_t * signature)
_GNUTLS_GCC_ATTR_DEPRECATED;
/* gnutls_pubkey_get_verify_algorithm() */
int gnutls_x509_crt_get_verify_algorithm(gnutls_x509_crt_t crt,
const gnutls_datum_t *
signature,
gnutls_digest_algorithm_t
* hash)
_GNUTLS_GCC_ATTR_DEPRECATED;
/* gnutls_pubkey_get_preferred_hash_algorithm() */
int gnutls_x509_crt_get_preferred_hash_algorithm(gnutls_x509_crt_t
crt,
gnutls_digest_algorithm_t
* hash, unsigned int
*mand)
_GNUTLS_GCC_ATTR_DEPRECATED;
/* gnutls_x509_crq_privkey_sign() */
int gnutls_x509_crq_sign(gnutls_x509_crq_t crq,
gnutls_x509_privkey_t key)
_GNUTLS_GCC_ATTR_DEPRECATED;
/* gnutls_x509_crl_privkey_sign */
int gnutls_x509_crl_sign(gnutls_x509_crl_t crl,
gnutls_x509_crt_t issuer,
gnutls_x509_privkey_t issuer_key)
_GNUTLS_GCC_ATTR_DEPRECATED;
/* functions to set priority of cipher suites
*/
int gnutls_cipher_set_priority(gnutls_session_t session,
const int *list)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_mac_set_priority(gnutls_session_t session,
const int *list) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_compression_set_priority(gnutls_session_t session,
const int *list)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_kx_set_priority(gnutls_session_t session,
const int *list) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_protocol_set_priority(gnutls_session_t session,
const int *list)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_certificate_type_set_priority(gnutls_session_t session,
const int *list)
_GNUTLS_GCC_ATTR_DEPRECATED;
/* RSA params
*/
int gnutls_rsa_params_init(gnutls_rsa_params_t *
rsa_params) _GNUTLS_GCC_ATTR_DEPRECATED;
void gnutls_rsa_params_deinit(gnutls_rsa_params_t rsa_params)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_rsa_params_cpy(gnutls_rsa_params_t dst,
gnutls_rsa_params_t src)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_rsa_params_import_raw(gnutls_rsa_params_t rsa_params,
const gnutls_datum_t * m,
const gnutls_datum_t * e,
const gnutls_datum_t * d,
const gnutls_datum_t * p,
const gnutls_datum_t * q,
const gnutls_datum_t * u);
int gnutls_rsa_params_generate2(gnutls_rsa_params_t params,
unsigned int bits)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_rsa_params_export_raw(gnutls_rsa_params_t rsa,
gnutls_datum_t * m,
gnutls_datum_t * e,
gnutls_datum_t * d,
gnutls_datum_t * p,
gnutls_datum_t * q,
gnutls_datum_t * u,
unsigned int *bits)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_rsa_params_export_pkcs1(gnutls_rsa_params_t params,
gnutls_x509_crt_fmt_t format,
unsigned char *params_data,
size_t *
params_data_size)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_rsa_params_import_pkcs1(gnutls_rsa_params_t params,
const gnutls_datum_t *
pkcs1_params,
gnutls_x509_crt_fmt_t format)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_rsa_export_get_pubkey(gnutls_session_t session,
gnutls_datum_t * exponent,
gnutls_datum_t *
modulus) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_rsa_export_get_modulus_bits(gnutls_session_t session)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_set_default_export_priority(gnutls_session_t session)
_GNUTLS_GCC_ATTR_DEPRECATED;
void gnutls_certificate_set_rsa_export_params
(gnutls_certificate_credentials_t res,
gnutls_rsa_params_t rsa_params) _GNUTLS_GCC_ATTR_DEPRECATED;
/* use gnutls_privkey_sign_hash() with the GNUTLS_PRIVKEY_SIGN_FLAG_TLS1_RSA flag */
int gnutls_privkey_sign_raw_data(gnutls_privkey_t key,
unsigned flags,
const gnutls_datum_t * data,
gnutls_datum_t *
signature) _GNUTLS_GCC_ATTR_DEPRECATED;
#ifdef _ISOC99_SOURCE
/* we provide older functions for compatibility as inline functions that
* depend on gnutls_session_get_random. */
static inline const void
*gnutls_session_get_server_random(gnutls_session_t session)
_GNUTLS_GCC_ATTR_DEPRECATED;
static inline const void
*gnutls_session_get_server_random(gnutls_session_t session)
{
gnutls_datum_t rnd;
gnutls_session_get_random(session, NULL, &rnd); /*doc-skip */
return rnd.data;
}
static inline const void
*gnutls_session_get_client_random(gnutls_session_t session)
_GNUTLS_GCC_ATTR_DEPRECATED;
static inline const void
*gnutls_session_get_client_random(gnutls_session_t session)
{
gnutls_datum_t rnd;
gnutls_session_get_random(session, &rnd, NULL); /*doc-skip */
return rnd.data;
}
#endif
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* _GNUTLS_COMPAT_H */

View file

@ -0,0 +1,117 @@
/*
* Copyright (C) 2008-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef GNUTLS_CRYPTO_H
#define GNUTLS_CRYPTO_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
typedef struct api_cipher_hd_st *gnutls_cipher_hd_t;
int gnutls_cipher_init(gnutls_cipher_hd_t * handle,
gnutls_cipher_algorithm_t cipher,
const gnutls_datum_t * key,
const gnutls_datum_t * iv);
int gnutls_cipher_encrypt(const gnutls_cipher_hd_t handle,
void *text, size_t textlen);
int gnutls_cipher_decrypt(const gnutls_cipher_hd_t handle,
void *ciphertext, size_t ciphertextlen);
int gnutls_cipher_decrypt2(gnutls_cipher_hd_t handle,
const void *ciphertext,
size_t ciphertextlen, void *text,
size_t textlen);
int gnutls_cipher_encrypt2(gnutls_cipher_hd_t handle,
const void *text, size_t textlen,
void *ciphertext, size_t ciphertextlen);
void gnutls_cipher_set_iv(gnutls_cipher_hd_t handle, void *iv,
size_t ivlen);
int gnutls_cipher_tag(gnutls_cipher_hd_t handle, void *tag,
size_t tag_size);
int gnutls_cipher_add_auth(gnutls_cipher_hd_t handle,
const void *text, size_t text_size);
void gnutls_cipher_deinit(gnutls_cipher_hd_t handle);
int gnutls_cipher_get_block_size(gnutls_cipher_algorithm_t algorithm);
int gnutls_cipher_get_iv_size(gnutls_cipher_algorithm_t algorithm);
int gnutls_cipher_get_tag_size(gnutls_cipher_algorithm_t algorithm);
typedef struct hash_hd_st *gnutls_hash_hd_t;
typedef struct hmac_hd_st *gnutls_hmac_hd_t;
size_t gnutls_mac_get_nonce_size(gnutls_mac_algorithm_t algorithm);
int gnutls_hmac_init(gnutls_hmac_hd_t * dig,
gnutls_mac_algorithm_t algorithm,
const void *key, size_t keylen);
void gnutls_hmac_set_nonce(gnutls_hmac_hd_t handle,
const void *nonce, size_t nonce_len);
int gnutls_hmac(gnutls_hmac_hd_t handle, const void *text, size_t textlen);
void gnutls_hmac_output(gnutls_hmac_hd_t handle, void *digest);
void gnutls_hmac_deinit(gnutls_hmac_hd_t handle, void *digest);
int gnutls_hmac_get_len(gnutls_mac_algorithm_t algorithm);
int gnutls_hmac_fast(gnutls_mac_algorithm_t algorithm,
const void *key, size_t keylen,
const void *text, size_t textlen, void *digest);
int gnutls_hash_init(gnutls_hash_hd_t * dig,
gnutls_digest_algorithm_t algorithm);
int gnutls_hash(gnutls_hash_hd_t handle, const void *text, size_t textlen);
void gnutls_hash_output(gnutls_hash_hd_t handle, void *digest);
void gnutls_hash_deinit(gnutls_hash_hd_t handle, void *digest);
int gnutls_hash_get_len(gnutls_digest_algorithm_t algorithm);
int gnutls_hash_fast(gnutls_digest_algorithm_t algorithm,
const void *text, size_t textlen, void *digest);
/* register ciphers */
/**
* gnutls_rnd_level_t:
* @GNUTLS_RND_NONCE: Non-predictable random number. Fatal in parts
* of session if broken, i.e., vulnerable to statistical analysis.
* @GNUTLS_RND_RANDOM: Pseudo-random cryptographic random number.
* Fatal in session if broken.
* @GNUTLS_RND_KEY: Fatal in many sessions if broken.
*
* Enumeration of random quality levels.
*/
typedef enum gnutls_rnd_level {
GNUTLS_RND_NONCE = 0,
GNUTLS_RND_RANDOM = 1,
GNUTLS_RND_KEY = 2
} gnutls_rnd_level_t;
int gnutls_rnd(gnutls_rnd_level_t level, void *data, size_t len);
void gnutls_rnd_refresh(void);
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif

View file

@ -0,0 +1,92 @@
/*
* Copyright (C) 2011-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
/* This file contains the types and prototypes for the X.509
* certificate and CRL handling functions.
*/
#ifndef GNUTLS_DTLS_H
#define GNUTLS_DTLS_H
#include <gnutls/gnutls.h>
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#define GNUTLS_COOKIE_KEY_SIZE 16
void gnutls_dtls_set_timeouts(gnutls_session_t session,
unsigned int retrans_timeout,
unsigned int total_timeout);
unsigned int gnutls_dtls_get_mtu(gnutls_session_t session);
unsigned int gnutls_dtls_get_data_mtu(gnutls_session_t session);
void gnutls_dtls_set_mtu(gnutls_session_t session, unsigned int mtu);
int gnutls_dtls_set_data_mtu(gnutls_session_t session, unsigned int mtu);
unsigned int gnutls_dtls_get_timeout(gnutls_session_t session);
/**
* gnutls_dtls_prestate_st:
* @record_seq: record sequence number
* @hsk_read_seq: handshake read sequence number
* @hsk_write_seq: handshake write sequence number
*
* DTLS cookie prestate struct. This is usually never modified by
* the application, it is used to carry the cookie data between
* gnutls_dtls_cookie_send(), gnutls_dtls_cookie_verify() and
* gnutls_dtls_prestate_set().
*/
typedef struct {
unsigned int record_seq;
unsigned int hsk_read_seq;
unsigned int hsk_write_seq;
} gnutls_dtls_prestate_st;
int gnutls_dtls_cookie_send(gnutls_datum_t * key,
void *client_data,
size_t client_data_size,
gnutls_dtls_prestate_st * prestate,
gnutls_transport_ptr_t ptr,
gnutls_push_func push_func);
int gnutls_dtls_cookie_verify(gnutls_datum_t * key,
void *client_data,
size_t client_data_size, void *_msg,
size_t msg_size,
gnutls_dtls_prestate_st * prestate);
void gnutls_dtls_prestate_set(gnutls_session_t session,
gnutls_dtls_prestate_st * prestate);
unsigned int gnutls_record_get_discarded(gnutls_session_t session);
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* GNUTLS_DTLS_H */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,426 @@
/*
* Copyright (C) 2006-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef GNUTLSXX_H
#define GNUTLSXX_H
#include <exception>
#include <vector>
#include <gnutls/gnutls.h>
namespace gnutls {
class noncopyable {
protected:
noncopyable() {
} ~noncopyable() {
} private:
// These are non-implemented.
noncopyable(const noncopyable &);
noncopyable & operator=(const noncopyable &);
};
class exception:public std::exception {
public:
exception(int x);
const char *what() const throw();
int get_code();
protected:
int retcode;
};
class dh_params:private noncopyable {
public:
dh_params();
~dh_params();
void import_raw(const gnutls_datum_t & prime,
const gnutls_datum_t & generator);
void import_pkcs3(const gnutls_datum_t & pkcs3_params,
gnutls_x509_crt_fmt_t format);
void generate(unsigned int bits);
void export_pkcs3(gnutls_x509_crt_fmt_t format,
unsigned char *params_data,
size_t * params_data_size);
void export_raw(gnutls_datum_t & prime,
gnutls_datum_t & generator);
gnutls_dh_params_t get_params_t() const;
dh_params & operator=(const dh_params & src);
protected:
gnutls_dh_params_t params;
};
class rsa_params:private noncopyable {
public:
rsa_params();
~rsa_params();
void import_raw(const gnutls_datum_t & m,
const gnutls_datum_t & e,
const gnutls_datum_t & d,
const gnutls_datum_t & p,
const gnutls_datum_t & q,
const gnutls_datum_t & u);
void import_pkcs1(const gnutls_datum_t & pkcs1_params,
gnutls_x509_crt_fmt_t format);
void generate(unsigned int bits);
void export_pkcs1(gnutls_x509_crt_fmt_t format,
unsigned char *params_data,
size_t * params_data_size);
void export_raw(gnutls_datum_t & m, gnutls_datum_t & e,
gnutls_datum_t & d, gnutls_datum_t & p,
gnutls_datum_t & q, gnutls_datum_t & u);
gnutls_rsa_params_t get_params_t() const;
rsa_params & operator=(const rsa_params & src);
protected:
gnutls_rsa_params_t params;
};
class session:private noncopyable {
protected:
gnutls_session_t s;
public:
session(unsigned int);
virtual ~ session();
int bye(gnutls_close_request_t how);
int handshake();
gnutls_alert_description_t get_alert() const;
int send_alert(gnutls_alert_level_t level,
gnutls_alert_description_t desc);
int send_appropriate_alert(int err);
gnutls_cipher_algorithm_t get_cipher() const;
gnutls_kx_algorithm_t get_kx() const;
gnutls_mac_algorithm_t get_mac() const;
gnutls_compression_method_t get_compression() const;
gnutls_certificate_type_t get_certificate_type() const;
// for the handshake
void set_private_extensions(bool allow);
gnutls_handshake_description_t get_handshake_last_out()
const;
gnutls_handshake_description_t get_handshake_last_in()
const;
ssize_t send(const void *data, size_t sizeofdata);
ssize_t recv(void *data, size_t sizeofdata);
bool get_record_direction() const;
// maximum packet size
size_t get_max_size() const;
void set_max_size(size_t size);
size_t check_pending() const;
void prf(size_t label_size, const char *label,
int server_random_first,
size_t extra_size, const char *extra,
size_t outsize, char *out);
void prf_raw(size_t label_size, const char *label,
size_t seed_size, const char *seed,
size_t outsize, char *out);
/* if you just want some defaults, use the following.
*/
void set_priority(const char *prio, const char **err_pos);
void set_priority(gnutls_priority_t p);
gnutls_protocol_t get_protocol_version() const;
// for resuming sessions
void set_data(const void *session_data,
size_t session_data_size);
void get_data(void *session_data,
size_t * session_data_size) const;
void get_data(gnutls_session_t session,
gnutls_datum_t & data) const;
void get_id(void *session_id,
size_t * session_id_size) const;
bool is_resumed() const;
void set_max_handshake_packet_length(size_t max);
void clear_credentials();
void set_credentials(class credentials & cred);
void set_transport_ptr(gnutls_transport_ptr_t ptr);
void set_transport_ptr(gnutls_transport_ptr_t recv_ptr,
gnutls_transport_ptr_t send_ptr);
gnutls_transport_ptr_t get_transport_ptr() const;
void get_transport_ptr(gnutls_transport_ptr_t & recv_ptr,
gnutls_transport_ptr_t & send_ptr)
const;
void set_transport_lowat(size_t num);
void set_transport_push_function(gnutls_push_func
push_func);
void set_transport_vec_push_function(gnutls_vec_push_func
vec_push_func);
void set_transport_pull_function(gnutls_pull_func
pull_func);
void set_user_ptr(void *ptr);
void *get_user_ptr() const;
void send_openpgp_cert(gnutls_openpgp_crt_status_t status);
gnutls_credentials_type_t get_auth_type() const;
gnutls_credentials_type_t get_server_auth_type() const;
gnutls_credentials_type_t get_client_auth_type() const;
// informational stuff
void set_dh_prime_bits(unsigned int bits);
unsigned int get_dh_secret_bits() const;
unsigned int get_dh_peers_public_bits() const;
unsigned int get_dh_prime_bits() const;
void get_dh_group(gnutls_datum_t & gen,
gnutls_datum_t & prime) const;
void get_dh_pubkey(gnutls_datum_t & raw_key) const;
void get_rsa_export_pubkey(gnutls_datum_t & exponent,
gnutls_datum_t & modulus) const;
unsigned int get_rsa_export_modulus_bits() const;
void get_our_certificate(gnutls_datum_t & cert) const;
bool get_peers_certificate(std::vector < gnutls_datum_t >
&out_certs) const;
bool get_peers_certificate(const gnutls_datum_t ** certs,
unsigned int *certs_size) const;
time_t get_peers_certificate_activation_time() const;
time_t get_peers_certificate_expiration_time() const;
void verify_peers_certificate(unsigned int &status) const;
};
// interface for databases
class DB:private noncopyable {
public:
virtual ~ DB() = 0;
virtual bool store(const gnutls_datum_t & key,
const gnutls_datum_t & data) = 0;
virtual bool retrieve(const gnutls_datum_t & key,
gnutls_datum_t & data) = 0;
virtual bool remove(const gnutls_datum_t & key) = 0;
};
class server_session:public session {
public:
server_session();
~server_session();
void db_remove() const;
void set_db_cache_expiration(unsigned int seconds);
void set_db(const DB & db);
// returns true if session is expired
bool db_check_entry(gnutls_datum_t & session_data) const;
// server side only
const char *get_srp_username() const;
const char *get_psk_username() const;
void get_server_name(void *data, size_t * data_length,
unsigned int *type,
unsigned int indx) const;
int rehandshake();
void set_certificate_request(gnutls_certificate_request_t);
};
class client_session:public session {
public:
client_session();
~client_session();
void set_server_name(gnutls_server_name_type_t type,
const void *name, size_t name_length);
bool get_request_status();
};
class credentials:private noncopyable {
public:
virtual ~ credentials() {
} gnutls_credentials_type_t get_type() const;
protected:
friend class session;
credentials(gnutls_credentials_type_t t);
void *ptr() const;
void set_ptr(void *ptr);
gnutls_credentials_type_t type;
private:
void *cred;
};
class certificate_credentials:public credentials {
public:
~certificate_credentials();
certificate_credentials();
void free_keys();
void free_cas();
void free_ca_names();
void free_crls();
void set_dh_params(const dh_params & params);
void set_rsa_export_params(const rsa_params & params);
void set_verify_flags(unsigned int flags);
void set_verify_limits(unsigned int max_bits,
unsigned int max_depth);
void set_x509_trust_file(const char *cafile,
gnutls_x509_crt_fmt_t type);
void set_x509_trust(const gnutls_datum_t & CA,
gnutls_x509_crt_fmt_t type);
// FIXME: use classes instead of gnutls_x509_crt_t
void set_x509_trust(gnutls_x509_crt_t * ca_list,
int ca_list_size);
void set_x509_crl_file(const char *crlfile,
gnutls_x509_crt_fmt_t type);
void set_x509_crl(const gnutls_datum_t & CRL,
gnutls_x509_crt_fmt_t type);
void set_x509_crl(gnutls_x509_crl_t * crl_list,
int crl_list_size);
void set_x509_key_file(const char *certfile,
const char *KEYFILE,
gnutls_x509_crt_fmt_t type);
void set_x509_key(const gnutls_datum_t & CERT,
const gnutls_datum_t & KEY,
gnutls_x509_crt_fmt_t type);
// FIXME: use classes
void set_x509_key(gnutls_x509_crt_t * cert_list,
int cert_list_size,
gnutls_x509_privkey_t key);
void set_simple_pkcs12_file(const char *pkcs12file,
gnutls_x509_crt_fmt_t type,
const char *password);
void set_retrieve_function
(gnutls_certificate_retrieve_function * func);
protected:
gnutls_certificate_credentials_t cred;
};
class certificate_server_credentials:public certificate_credentials {
public:
void set_params_function(gnutls_params_function * func);
};
class certificate_client_credentials:public certificate_credentials {
public:
};
class anon_server_credentials:public credentials {
public:
anon_server_credentials();
~anon_server_credentials();
void set_dh_params(const dh_params & params);
void set_params_function(gnutls_params_function * func);
protected:
gnutls_anon_server_credentials_t cred;
};
class anon_client_credentials:public credentials {
public:
anon_client_credentials();
~anon_client_credentials();
protected:
gnutls_anon_client_credentials_t cred;
};
class srp_server_credentials:public credentials {
public:
srp_server_credentials();
~srp_server_credentials();
void set_credentials_file(const char *password_file,
const char *password_conf_file);
void set_credentials_function
(gnutls_srp_server_credentials_function * func);
protected:
gnutls_srp_server_credentials_t cred;
};
class srp_client_credentials:public credentials {
public:
srp_client_credentials();
~srp_client_credentials();
void set_credentials(const char *username,
const char *password);
void set_credentials_function
(gnutls_srp_client_credentials_function * func);
protected:
gnutls_srp_client_credentials_t cred;
};
class psk_server_credentials:public credentials {
public:
psk_server_credentials();
~psk_server_credentials();
void set_credentials_file(const char *password_file);
void set_credentials_function
(gnutls_psk_server_credentials_function * func);
void set_dh_params(const dh_params & params);
void set_params_function(gnutls_params_function * func);
protected:
gnutls_psk_server_credentials_t cred;
};
class psk_client_credentials:public credentials {
public:
psk_client_credentials();
~psk_client_credentials();
void set_credentials(const char *username,
const gnutls_datum_t & key,
gnutls_psk_key_flags flags);
void set_credentials_function
(gnutls_psk_client_credentials_function * func);
protected:
gnutls_psk_client_credentials_t cred;
};
} /* namespace */
#endif /* GNUTLSXX_H */

View file

@ -0,0 +1,257 @@
/*
* Copyright (C) 2011-2012 Free Software Foundation, Inc.
*
* Author: Simon Josefsson
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
/* Online Certificate Status Protocol - RFC 2560
*/
#ifndef GNUTLS_OCSP_H
#define GNUTLS_OCSP_H
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#define GNUTLS_OCSP_NONCE "1.3.6.1.5.5.7.48.1.2"
/**
* gnutls_ocsp_print_formats_t:
* @GNUTLS_OCSP_PRINT_FULL: Full information about OCSP request/response.
* @GNUTLS_OCSP_PRINT_COMPACT: More compact information about OCSP request/response.
*
* Enumeration of different OCSP printing variants.
*/
typedef enum gnutls_ocsp_print_formats_t {
GNUTLS_OCSP_PRINT_FULL = 0,
GNUTLS_OCSP_PRINT_COMPACT = 1,
} gnutls_ocsp_print_formats_t;
/**
* gnutls_ocsp_resp_status_t:
* @GNUTLS_OCSP_RESP_SUCCESSFUL: Response has valid confirmations.
* @GNUTLS_OCSP_RESP_MALFORMEDREQUEST: Illegal confirmation request
* @GNUTLS_OCSP_RESP_INTERNALERROR: Internal error in issuer
* @GNUTLS_OCSP_RESP_TRYLATER: Try again later
* @GNUTLS_OCSP_RESP_SIGREQUIRED: Must sign the request
* @GNUTLS_OCSP_RESP_UNAUTHORIZED: Request unauthorized
*
* Enumeration of different OCSP response status codes.
*/
typedef enum gnutls_ocsp_resp_status_t {
GNUTLS_OCSP_RESP_SUCCESSFUL = 0,
GNUTLS_OCSP_RESP_MALFORMEDREQUEST = 1,
GNUTLS_OCSP_RESP_INTERNALERROR = 2,
GNUTLS_OCSP_RESP_TRYLATER = 3,
GNUTLS_OCSP_RESP_SIGREQUIRED = 5,
GNUTLS_OCSP_RESP_UNAUTHORIZED = 6
} gnutls_ocsp_resp_status_t;
/**
* gnutls_ocsp_cert_status_t:
* @GNUTLS_OCSP_CERT_GOOD: Positive response to status inquiry.
* @GNUTLS_OCSP_CERT_REVOKED: Certificate has been revoked.
* @GNUTLS_OCSP_CERT_UNKNOWN: The responder doesn't know about the
* certificate.
*
* Enumeration of different OCSP response certificate status codes.
*/
typedef enum gnutls_ocsp_cert_status_t {
GNUTLS_OCSP_CERT_GOOD = 0,
GNUTLS_OCSP_CERT_REVOKED = 1,
GNUTLS_OCSP_CERT_UNKNOWN = 2
} gnutls_ocsp_cert_status_t;
/**
* gnutls_x509_crl_reason_t:
* @GNUTLS_X509_CRLREASON_UNSPECIFIED: Unspecified reason.
* @GNUTLS_X509_CRLREASON_KEYCOMPROMISE: Private key compromised.
* @GNUTLS_X509_CRLREASON_CACOMPROMISE: CA compromised.
* @GNUTLS_X509_CRLREASON_AFFILIATIONCHANGED: Affiliation has changed.
* @GNUTLS_X509_CRLREASON_SUPERSEDED: Certificate superseded.
* @GNUTLS_X509_CRLREASON_CESSATIONOFOPERATION: Operation has ceased.
* @GNUTLS_X509_CRLREASON_CERTIFICATEHOLD: Certificate is on hold.
* @GNUTLS_X509_CRLREASON_REMOVEFROMCRL: Will be removed from delta CRL.
* @GNUTLS_X509_CRLREASON_PRIVILEGEWITHDRAWN: Privilege withdrawn.
* @GNUTLS_X509_CRLREASON_AACOMPROMISE: AA compromised.
*
* Enumeration of different reason codes. Note that this
* corresponds to the CRLReason ASN.1 enumeration type, and not the
* ReasonFlags ASN.1 bit string.
*/
typedef enum gnutls_x509_crl_reason_t {
GNUTLS_X509_CRLREASON_UNSPECIFIED = 0,
GNUTLS_X509_CRLREASON_KEYCOMPROMISE = 1,
GNUTLS_X509_CRLREASON_CACOMPROMISE = 2,
GNUTLS_X509_CRLREASON_AFFILIATIONCHANGED = 3,
GNUTLS_X509_CRLREASON_SUPERSEDED = 4,
GNUTLS_X509_CRLREASON_CESSATIONOFOPERATION = 5,
GNUTLS_X509_CRLREASON_CERTIFICATEHOLD = 6,
GNUTLS_X509_CRLREASON_REMOVEFROMCRL = 8,
GNUTLS_X509_CRLREASON_PRIVILEGEWITHDRAWN = 9,
GNUTLS_X509_CRLREASON_AACOMPROMISE = 10
} gnutls_x509_crl_reason_t;
/**
* gnutls_ocsp_verify_reason_t:
* @GNUTLS_OCSP_VERIFY_SIGNER_NOT_FOUND: Signer cert not found.
* @GNUTLS_OCSP_VERIFY_SIGNER_KEYUSAGE_ERROR: Signer keyusage bits incorrect.
* @GNUTLS_OCSP_VERIFY_UNTRUSTED_SIGNER: Signer is not trusted.
* @GNUTLS_OCSP_VERIFY_INSECURE_ALGORITHM: Signature using insecure algorithm.
* @GNUTLS_OCSP_VERIFY_SIGNATURE_FAILURE: Signature mismatch.
* @GNUTLS_OCSP_VERIFY_CERT_NOT_ACTIVATED: Signer cert is not yet activated.
* @GNUTLS_OCSP_VERIFY_CERT_EXPIRED: Signer cert has expired.
*
* Enumeration of OCSP verify status codes, used by
* gnutls_ocsp_resp_verify() and gnutls_ocsp_resp_verify_direct().
*/
typedef enum gnutls_ocsp_verify_reason_t {
GNUTLS_OCSP_VERIFY_SIGNER_NOT_FOUND = 1,
GNUTLS_OCSP_VERIFY_SIGNER_KEYUSAGE_ERROR = 2,
GNUTLS_OCSP_VERIFY_UNTRUSTED_SIGNER = 4,
GNUTLS_OCSP_VERIFY_INSECURE_ALGORITHM = 8,
GNUTLS_OCSP_VERIFY_SIGNATURE_FAILURE = 16,
GNUTLS_OCSP_VERIFY_CERT_NOT_ACTIVATED = 32,
GNUTLS_OCSP_VERIFY_CERT_EXPIRED = 64
} gnutls_ocsp_verify_reason_t;
struct gnutls_ocsp_req_int;
typedef struct gnutls_ocsp_req_int *gnutls_ocsp_req_t;
int gnutls_ocsp_req_init(gnutls_ocsp_req_t * req);
void gnutls_ocsp_req_deinit(gnutls_ocsp_req_t req);
int gnutls_ocsp_req_import(gnutls_ocsp_req_t req,
const gnutls_datum_t * data);
int gnutls_ocsp_req_export(gnutls_ocsp_req_t req, gnutls_datum_t * data);
int gnutls_ocsp_req_print(gnutls_ocsp_req_t req,
gnutls_ocsp_print_formats_t format,
gnutls_datum_t * out);
int gnutls_ocsp_req_get_version(gnutls_ocsp_req_t req);
int gnutls_ocsp_req_get_cert_id(gnutls_ocsp_req_t req,
unsigned indx,
gnutls_digest_algorithm_t * digest,
gnutls_datum_t * issuer_name_hash,
gnutls_datum_t * issuer_key_hash,
gnutls_datum_t * serial_number);
int gnutls_ocsp_req_add_cert_id(gnutls_ocsp_req_t req,
gnutls_digest_algorithm_t digest,
const gnutls_datum_t *
issuer_name_hash,
const gnutls_datum_t *
issuer_key_hash,
const gnutls_datum_t * serial_number);
int gnutls_ocsp_req_add_cert(gnutls_ocsp_req_t req,
gnutls_digest_algorithm_t digest,
gnutls_x509_crt_t issuer,
gnutls_x509_crt_t cert);
int gnutls_ocsp_req_get_extension(gnutls_ocsp_req_t req,
unsigned indx,
gnutls_datum_t * oid,
unsigned int *critical,
gnutls_datum_t * data);
int gnutls_ocsp_req_set_extension(gnutls_ocsp_req_t req,
const char *oid,
unsigned int critical,
const gnutls_datum_t * data);
int gnutls_ocsp_req_get_nonce(gnutls_ocsp_req_t req,
unsigned int *critical,
gnutls_datum_t * nonce);
int gnutls_ocsp_req_set_nonce(gnutls_ocsp_req_t req,
unsigned int critical,
const gnutls_datum_t * nonce);
int gnutls_ocsp_req_randomize_nonce(gnutls_ocsp_req_t req);
struct gnutls_ocsp_resp_int;
typedef struct gnutls_ocsp_resp_int *gnutls_ocsp_resp_t;
int gnutls_ocsp_resp_init(gnutls_ocsp_resp_t * resp);
void gnutls_ocsp_resp_deinit(gnutls_ocsp_resp_t resp);
int gnutls_ocsp_resp_import(gnutls_ocsp_resp_t resp,
const gnutls_datum_t * data);
int gnutls_ocsp_resp_export(gnutls_ocsp_resp_t resp,
gnutls_datum_t * data);
int gnutls_ocsp_resp_print(gnutls_ocsp_resp_t resp,
gnutls_ocsp_print_formats_t format,
gnutls_datum_t * out);
int gnutls_ocsp_resp_get_status(gnutls_ocsp_resp_t resp);
int gnutls_ocsp_resp_get_response(gnutls_ocsp_resp_t resp,
gnutls_datum_t *
response_type_oid,
gnutls_datum_t * response);
int gnutls_ocsp_resp_get_version(gnutls_ocsp_resp_t resp);
int gnutls_ocsp_resp_get_responder(gnutls_ocsp_resp_t resp,
gnutls_datum_t * dn);
time_t gnutls_ocsp_resp_get_produced(gnutls_ocsp_resp_t resp);
int gnutls_ocsp_resp_get_single(gnutls_ocsp_resp_t resp,
unsigned indx,
gnutls_digest_algorithm_t * digest,
gnutls_datum_t * issuer_name_hash,
gnutls_datum_t * issuer_key_hash,
gnutls_datum_t * serial_number,
unsigned int *cert_status,
time_t * this_update,
time_t * next_update,
time_t * revocation_time,
unsigned int *revocation_reason);
int gnutls_ocsp_resp_get_extension(gnutls_ocsp_resp_t resp,
unsigned indx,
gnutls_datum_t * oid,
unsigned int *critical,
gnutls_datum_t * data);
int gnutls_ocsp_resp_get_nonce(gnutls_ocsp_resp_t resp,
unsigned int *critical,
gnutls_datum_t * nonce);
int gnutls_ocsp_resp_get_signature_algorithm(gnutls_ocsp_resp_t resp);
int gnutls_ocsp_resp_get_signature(gnutls_ocsp_resp_t resp,
gnutls_datum_t * sig);
int gnutls_ocsp_resp_get_certs(gnutls_ocsp_resp_t resp,
gnutls_x509_crt_t ** certs,
size_t * ncerts);
int gnutls_ocsp_resp_verify_direct(gnutls_ocsp_resp_t resp,
gnutls_x509_crt_t issuer,
unsigned int *verify,
unsigned int flags);
int gnutls_ocsp_resp_verify(gnutls_ocsp_resp_t resp,
gnutls_x509_trust_list_t trustlist,
unsigned int *verify, unsigned int flags);
int gnutls_ocsp_resp_check_crt(gnutls_ocsp_resp_t resp,
unsigned int indx, gnutls_x509_crt_t crt);
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* GNUTLS_OCSP_H */

View file

@ -0,0 +1,366 @@
/*
* Copyright (C) 2003-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
/* This file contains the types and prototypes for the OpenPGP
* key and private key parsing functions.
*/
#ifndef GNUTLS_OPENPGP_H
#define GNUTLS_OPENPGP_H
#include <gnutls/gnutls.h>
#include <limits.h>
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Openpgp certificate stuff
*/
/**
* gnutls_openpgp_crt_fmt_t:
* @GNUTLS_OPENPGP_FMT_RAW: OpenPGP certificate in raw format.
* @GNUTLS_OPENPGP_FMT_BASE64: OpenPGP certificate in base64 format.
*
* Enumeration of different OpenPGP key formats.
*/
typedef enum gnutls_openpgp_crt_fmt {
GNUTLS_OPENPGP_FMT_RAW,
GNUTLS_OPENPGP_FMT_BASE64
} gnutls_openpgp_crt_fmt_t;
#define GNUTLS_OPENPGP_KEYID_SIZE 8
#define GNUTLS_OPENPGP_V4_FINGERPRINT_SIZE 20
typedef unsigned char
gnutls_openpgp_keyid_t[GNUTLS_OPENPGP_KEYID_SIZE];
/* gnutls_openpgp_cert_t should be defined in gnutls.h
*/
/* initializes the memory for gnutls_openpgp_crt_t struct */
int gnutls_openpgp_crt_init(gnutls_openpgp_crt_t * key);
/* frees all memory */
void gnutls_openpgp_crt_deinit(gnutls_openpgp_crt_t key);
int gnutls_openpgp_crt_import(gnutls_openpgp_crt_t key,
const gnutls_datum_t * data,
gnutls_openpgp_crt_fmt_t format);
int gnutls_openpgp_crt_export(gnutls_openpgp_crt_t key,
gnutls_openpgp_crt_fmt_t format,
void *output_data,
size_t * output_data_size);
int gnutls_openpgp_crt_export2(gnutls_openpgp_crt_t key,
gnutls_openpgp_crt_fmt_t format,
gnutls_datum_t * out);
int gnutls_openpgp_crt_print(gnutls_openpgp_crt_t cert,
gnutls_certificate_print_formats_t
format, gnutls_datum_t * out);
/* The key_usage flags are defined in gnutls.h. They are
* the GNUTLS_KEY_* definitions.
*/
#define GNUTLS_OPENPGP_MASTER_KEYID_IDX INT_MAX
int gnutls_openpgp_crt_get_key_usage(gnutls_openpgp_crt_t key,
unsigned int *key_usage);
int gnutls_openpgp_crt_get_fingerprint(gnutls_openpgp_crt_t key,
void *fpr, size_t * fprlen);
int gnutls_openpgp_crt_get_subkey_fingerprint(gnutls_openpgp_crt_t
key,
unsigned int idx,
void *fpr, size_t * fprlen);
int gnutls_openpgp_crt_get_name(gnutls_openpgp_crt_t key,
int idx, char *buf, size_t * sizeof_buf);
gnutls_pk_algorithm_t
gnutls_openpgp_crt_get_pk_algorithm(gnutls_openpgp_crt_t key,
unsigned int *bits);
int gnutls_openpgp_crt_get_version(gnutls_openpgp_crt_t key);
time_t gnutls_openpgp_crt_get_creation_time(gnutls_openpgp_crt_t key);
time_t gnutls_openpgp_crt_get_expiration_time(gnutls_openpgp_crt_t key);
int gnutls_openpgp_crt_get_key_id(gnutls_openpgp_crt_t key,
gnutls_openpgp_keyid_t keyid);
int gnutls_openpgp_crt_check_hostname(gnutls_openpgp_crt_t key,
const char *hostname);
int gnutls_openpgp_crt_get_revoked_status(gnutls_openpgp_crt_t key);
int gnutls_openpgp_crt_get_subkey_count(gnutls_openpgp_crt_t key);
int gnutls_openpgp_crt_get_subkey_idx(gnutls_openpgp_crt_t key,
const gnutls_openpgp_keyid_t keyid);
int gnutls_openpgp_crt_get_subkey_revoked_status
(gnutls_openpgp_crt_t key, unsigned int idx);
gnutls_pk_algorithm_t
gnutls_openpgp_crt_get_subkey_pk_algorithm(gnutls_openpgp_crt_t
key,
unsigned int idx,
unsigned int *bits);
time_t
gnutls_openpgp_crt_get_subkey_creation_time
(gnutls_openpgp_crt_t key, unsigned int idx);
time_t
gnutls_openpgp_crt_get_subkey_expiration_time
(gnutls_openpgp_crt_t key, unsigned int idx);
int gnutls_openpgp_crt_get_subkey_id(gnutls_openpgp_crt_t key,
unsigned int idx,
gnutls_openpgp_keyid_t keyid);
int gnutls_openpgp_crt_get_subkey_usage(gnutls_openpgp_crt_t key,
unsigned int idx,
unsigned int *key_usage);
int gnutls_openpgp_crt_get_subkey_pk_dsa_raw(gnutls_openpgp_crt_t
crt, unsigned int idx,
gnutls_datum_t * p,
gnutls_datum_t * q,
gnutls_datum_t * g,
gnutls_datum_t * y);
int gnutls_openpgp_crt_get_subkey_pk_rsa_raw(gnutls_openpgp_crt_t
crt, unsigned int idx,
gnutls_datum_t * m,
gnutls_datum_t * e);
int gnutls_openpgp_crt_get_pk_dsa_raw(gnutls_openpgp_crt_t crt,
gnutls_datum_t * p,
gnutls_datum_t * q,
gnutls_datum_t * g,
gnutls_datum_t * y);
int gnutls_openpgp_crt_get_pk_rsa_raw(gnutls_openpgp_crt_t crt,
gnutls_datum_t * m,
gnutls_datum_t * e);
int gnutls_openpgp_crt_get_preferred_key_id(gnutls_openpgp_crt_t
key,
gnutls_openpgp_keyid_t keyid);
int
gnutls_openpgp_crt_set_preferred_key_id(gnutls_openpgp_crt_t key,
const
gnutls_openpgp_keyid_t keyid);
/* privkey stuff.
*/
int gnutls_openpgp_privkey_init(gnutls_openpgp_privkey_t * key);
void gnutls_openpgp_privkey_deinit(gnutls_openpgp_privkey_t key);
gnutls_pk_algorithm_t
gnutls_openpgp_privkey_get_pk_algorithm
(gnutls_openpgp_privkey_t key, unsigned int *bits);
gnutls_sec_param_t
gnutls_openpgp_privkey_sec_param(gnutls_openpgp_privkey_t key);
int gnutls_openpgp_privkey_import(gnutls_openpgp_privkey_t key,
const gnutls_datum_t * data,
gnutls_openpgp_crt_fmt_t format,
const char *password,
unsigned int flags);
int gnutls_openpgp_privkey_get_fingerprint(gnutls_openpgp_privkey_t
key, void *fpr,
size_t * fprlen);
int gnutls_openpgp_privkey_get_subkey_fingerprint
(gnutls_openpgp_privkey_t key, unsigned int idx, void *fpr,
size_t * fprlen);
int gnutls_openpgp_privkey_get_key_id(gnutls_openpgp_privkey_t key,
gnutls_openpgp_keyid_t keyid);
int gnutls_openpgp_privkey_get_subkey_count(gnutls_openpgp_privkey_t key);
int gnutls_openpgp_privkey_get_subkey_idx(gnutls_openpgp_privkey_t
key,
const
gnutls_openpgp_keyid_t keyid);
int gnutls_openpgp_privkey_get_subkey_revoked_status
(gnutls_openpgp_privkey_t key, unsigned int idx);
int gnutls_openpgp_privkey_get_revoked_status
(gnutls_openpgp_privkey_t key);
gnutls_pk_algorithm_t
gnutls_openpgp_privkey_get_subkey_pk_algorithm
(gnutls_openpgp_privkey_t key, unsigned int idx, unsigned int *bits);
time_t
gnutls_openpgp_privkey_get_subkey_expiration_time
(gnutls_openpgp_privkey_t key, unsigned int idx);
int gnutls_openpgp_privkey_get_subkey_id(gnutls_openpgp_privkey_t
key, unsigned int idx,
gnutls_openpgp_keyid_t keyid);
time_t
gnutls_openpgp_privkey_get_subkey_creation_time
(gnutls_openpgp_privkey_t key, unsigned int idx);
int gnutls_openpgp_privkey_export_subkey_dsa_raw
(gnutls_openpgp_privkey_t pkey, unsigned int idx,
gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * g,
gnutls_datum_t * y, gnutls_datum_t * x);
int gnutls_openpgp_privkey_export_subkey_rsa_raw
(gnutls_openpgp_privkey_t pkey, unsigned int idx,
gnutls_datum_t * m, gnutls_datum_t * e, gnutls_datum_t * d,
gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * u);
int gnutls_openpgp_privkey_export_dsa_raw(gnutls_openpgp_privkey_t
pkey, gnutls_datum_t * p,
gnutls_datum_t * q,
gnutls_datum_t * g,
gnutls_datum_t * y,
gnutls_datum_t * x);
int gnutls_openpgp_privkey_export_rsa_raw(gnutls_openpgp_privkey_t
pkey, gnutls_datum_t * m,
gnutls_datum_t * e,
gnutls_datum_t * d,
gnutls_datum_t * p,
gnutls_datum_t * q,
gnutls_datum_t * u);
int gnutls_openpgp_privkey_export(gnutls_openpgp_privkey_t key,
gnutls_openpgp_crt_fmt_t format,
const char *password,
unsigned int flags,
void *output_data,
size_t * output_data_size);
int gnutls_openpgp_privkey_export2(gnutls_openpgp_privkey_t key,
gnutls_openpgp_crt_fmt_t format,
const char *password,
unsigned int flags,
gnutls_datum_t * out);
int gnutls_openpgp_privkey_set_preferred_key_id
(gnutls_openpgp_privkey_t key, const gnutls_openpgp_keyid_t keyid);
int gnutls_openpgp_privkey_get_preferred_key_id
(gnutls_openpgp_privkey_t key, gnutls_openpgp_keyid_t keyid);
int gnutls_openpgp_crt_get_auth_subkey(gnutls_openpgp_crt_t crt,
gnutls_openpgp_keyid_t
keyid, unsigned int flag);
/* Keyring stuff.
*/
int gnutls_openpgp_keyring_init(gnutls_openpgp_keyring_t * keyring);
void gnutls_openpgp_keyring_deinit(gnutls_openpgp_keyring_t keyring);
int gnutls_openpgp_keyring_import(gnutls_openpgp_keyring_t keyring,
const gnutls_datum_t * data,
gnutls_openpgp_crt_fmt_t format);
int gnutls_openpgp_keyring_check_id(gnutls_openpgp_keyring_t ring,
const gnutls_openpgp_keyid_t
keyid, unsigned int flags);
int gnutls_openpgp_crt_verify_ring(gnutls_openpgp_crt_t key,
gnutls_openpgp_keyring_t
keyring, unsigned int flags,
unsigned int *verify
/* the output of the verification */
);
int gnutls_openpgp_crt_verify_self(gnutls_openpgp_crt_t key,
unsigned int flags,
unsigned int *verify);
int gnutls_openpgp_keyring_get_crt(gnutls_openpgp_keyring_t ring,
unsigned int idx,
gnutls_openpgp_crt_t * cert);
int gnutls_openpgp_keyring_get_crt_count(gnutls_openpgp_keyring_t ring);
/**
* gnutls_openpgp_recv_key_func:
* @session: a TLS session
* @keyfpr: key fingerprint
* @keyfpr_length: length of key fingerprint
* @key: output key.
*
* A callback of this type is used to retrieve OpenPGP keys. Only
* useful on the server, and will only be used if the peer send a key
* fingerprint instead of a full key. See also
* gnutls_openpgp_set_recv_key_function().
*
* The variable @key must be allocated using gnutls_malloc().
*
* Returns: On success, %GNUTLS_E_SUCCESS (zero) is returned,
* otherwise an error code is returned.
*/
typedef int (*gnutls_openpgp_recv_key_func) (gnutls_session_t
session,
const unsigned char
*keyfpr,
unsigned int
keyfpr_length,
gnutls_datum_t * key);
void
gnutls_openpgp_set_recv_key_function(gnutls_session_t session,
gnutls_openpgp_recv_key_func func);
/* certificate authentication stuff.
*/
int gnutls_certificate_set_openpgp_key
(gnutls_certificate_credentials_t res,
gnutls_openpgp_crt_t crt, gnutls_openpgp_privkey_t pkey);
int
gnutls_certificate_set_openpgp_key_file
(gnutls_certificate_credentials_t res, const char *certfile,
const char *keyfile, gnutls_openpgp_crt_fmt_t format);
int gnutls_certificate_set_openpgp_key_mem
(gnutls_certificate_credentials_t res,
const gnutls_datum_t * cert, const gnutls_datum_t * key,
gnutls_openpgp_crt_fmt_t format);
int
gnutls_certificate_set_openpgp_key_file2
(gnutls_certificate_credentials_t res, const char *certfile,
const char *keyfile, const char *subkey_id,
gnutls_openpgp_crt_fmt_t format);
int
gnutls_certificate_set_openpgp_key_mem2
(gnutls_certificate_credentials_t res,
const gnutls_datum_t * cert, const gnutls_datum_t * key,
const char *subkey_id, gnutls_openpgp_crt_fmt_t format);
int gnutls_certificate_set_openpgp_keyring_mem
(gnutls_certificate_credentials_t c, const unsigned char *data,
size_t dlen, gnutls_openpgp_crt_fmt_t format);
int gnutls_certificate_set_openpgp_keyring_file
(gnutls_certificate_credentials_t c, const char *file,
gnutls_openpgp_crt_fmt_t format);
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* GNUTLS_OPENPGP_H */

View file

@ -0,0 +1,356 @@
/*
* Copyright (C) 2010-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef __GNUTLS_PKCS11_H
#define __GNUTLS_PKCS11_H
#include <stdarg.h>
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#define GNUTLS_PKCS11_MAX_PIN_LEN 32
/**
* gnutls_pkcs11_token_callback_t:
* @userdata: user-controlled data from gnutls_pkcs11_set_token_function().
* @label: token label.
* @retry: retry counter, initially 0.
*
* Token callback function. The callback will be used to ask the user
* to re-insert the token with given (null terminated) label. The
* callback should return zero if token has been inserted by user and
* a negative error code otherwise. It might be called multiple times
* if the token is not detected and the retry counter will be
* increased.
*
* Returns: %GNUTLS_E_SUCCESS (0) on success or a negative error code
* on error.
*
* Since: 2.12.0
**/
typedef int (*gnutls_pkcs11_token_callback_t) (void *const
userdata,
const char *const
label, unsigned retry);
struct gnutls_pkcs11_obj_st;
typedef struct gnutls_pkcs11_obj_st *gnutls_pkcs11_obj_t;
#define GNUTLS_PKCS11_FLAG_MANUAL 0 /* Manual loading of libraries */
#define GNUTLS_PKCS11_FLAG_AUTO 1 /* Automatically load libraries by reading /etc/gnutls/pkcs11.conf */
/* pkcs11.conf format:
* load = /lib/xxx-pkcs11.so
* load = /lib/yyy-pkcs11.so
*/
int gnutls_pkcs11_init(unsigned int flags,
const char *deprecated_config_file);
int gnutls_pkcs11_reinit(void);
void gnutls_pkcs11_deinit(void);
void gnutls_pkcs11_set_token_function
(gnutls_pkcs11_token_callback_t fn, void *userdata);
void gnutls_pkcs11_set_pin_function(gnutls_pin_callback_t fn,
void *userdata);
gnutls_pin_callback_t gnutls_pkcs11_get_pin_function(void
**userdata);
int gnutls_pkcs11_add_provider(const char *name, const char *params);
int gnutls_pkcs11_obj_init(gnutls_pkcs11_obj_t * obj);
void gnutls_pkcs11_obj_set_pin_function(gnutls_pkcs11_obj_t obj,
gnutls_pin_callback_t fn,
void *userdata);
#define GNUTLS_PKCS11_OBJ_FLAG_LOGIN (1<<0) /* force login in the token for the operation */
#define GNUTLS_PKCS11_OBJ_FLAG_MARK_TRUSTED (1<<1) /* object marked as trusted */
#define GNUTLS_PKCS11_OBJ_FLAG_MARK_SENSITIVE (1<<2) /* object marked as sensitive (unexportable) */
#define GNUTLS_PKCS11_OBJ_FLAG_LOGIN_SO (1<<3) /* force login as a security officer in the token for the operation */
#define GNUTLS_PKCS11_OBJ_FLAG_MARK_PRIVATE (1<<4) /* marked as private (requires PIN to access) */
#define GNUTLS_PKCS11_OBJ_FLAG_MARK_NOT_PRIVATE (1<<5) /* marked as not private */
#define GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_ANY (1<<6) /* No need for the object to be a trusted one */
#define GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_TRUSTED (1<<7) /* The object must be marked as trusted
* in gnutls_pkcs11_crt_is_known() it implies GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_COMPARE */
#define GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_DISTRUSTED (1<<8) /* The object must be marked as distrusted */
#define GNUTLS_PKCS11_OBJ_FLAG_COMPARE (1<<9) /* The object must be fully compared */
#define GNUTLS_PKCS11_OBJ_FLAG_PRESENT_IN_TRUSTED_MODULE (1<<10) /* The object must be present in a marked as trusted module */
/**
* gnutls_pkcs11_url_type_t:
* @GNUTLS_PKCS11_URL_GENERIC: A generic-purpose URL.
* @GNUTLS_PKCS11_URL_LIB: A URL that specifies the library used as well.
* @GNUTLS_PKCS11_URL_LIB_VERSION: A URL that specifies the library and its version.
*
* Enumeration of different URL extraction flags.
*/
typedef enum {
GNUTLS_PKCS11_URL_GENERIC, /* URL specifies the object on token level */
GNUTLS_PKCS11_URL_LIB, /* URL specifies the object on module level */
GNUTLS_PKCS11_URL_LIB_VERSION /* URL specifies the object on module and version level */
} gnutls_pkcs11_url_type_t;
int gnutls_pkcs11_obj_import_url(gnutls_pkcs11_obj_t obj,
const char *url, unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */ );
int gnutls_pkcs11_obj_export_url(gnutls_pkcs11_obj_t obj,
gnutls_pkcs11_url_type_t detailed,
char **url);
void gnutls_pkcs11_obj_deinit(gnutls_pkcs11_obj_t obj);
int gnutls_pkcs11_obj_export(gnutls_pkcs11_obj_t obj,
void *output_data, size_t * output_data_size);
int gnutls_pkcs11_obj_export2(gnutls_pkcs11_obj_t obj,
gnutls_datum_t * out);
int gnutls_pkcs11_obj_export3(gnutls_pkcs11_obj_t obj, gnutls_x509_crt_fmt_t fmt,
gnutls_datum_t * out);
int gnutls_pkcs11_get_raw_issuer(const char *url, gnutls_x509_crt_t cert,
gnutls_datum_t * issuer,
gnutls_x509_crt_fmt_t fmt,
unsigned int flags);
int gnutls_pkcs11_copy_x509_crt(const char *token_url,
gnutls_x509_crt_t crt,
const char *label, unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */ );
int gnutls_pkcs11_copy_x509_privkey(const char *token_url,
gnutls_x509_privkey_t key,
const char *label,
unsigned int key_usage
/*GNUTLS_KEY_* */ ,
unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */
);
int gnutls_pkcs11_delete_url(const char *object_url, unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */ );
int gnutls_pkcs11_copy_secret_key(const char *token_url,
gnutls_datum_t * key,
const char *label, unsigned int key_usage
/* GNUTLS_KEY_* */ ,
unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */ );
/**
* gnutls_pkcs11_obj_info_t:
* @GNUTLS_PKCS11_OBJ_ID_HEX: The object ID in hex.
* @GNUTLS_PKCS11_OBJ_LABEL: The object label.
* @GNUTLS_PKCS11_OBJ_TOKEN_LABEL: The token's label.
* @GNUTLS_PKCS11_OBJ_TOKEN_SERIAL: The token's serial number.
* @GNUTLS_PKCS11_OBJ_TOKEN_MANUFACTURER: The token's manufacturer.
* @GNUTLS_PKCS11_OBJ_TOKEN_MODEL: The token's model.
* @GNUTLS_PKCS11_OBJ_ID: The object ID.
* @GNUTLS_PKCS11_OBJ_LIBRARY_VERSION: The library's used to access the object version.
* @GNUTLS_PKCS11_OBJ_LIBRARY_DESCRIPTION: The library's used to access the object description (name).
* @GNUTLS_PKCS11_OBJ_LIBRARY_MANUFACTURER: The library's used to access the object manufacturer name.
*
* Enumeration of several object information types.
*/
typedef enum {
GNUTLS_PKCS11_OBJ_ID_HEX = 1,
GNUTLS_PKCS11_OBJ_LABEL,
GNUTLS_PKCS11_OBJ_TOKEN_LABEL,
GNUTLS_PKCS11_OBJ_TOKEN_SERIAL,
GNUTLS_PKCS11_OBJ_TOKEN_MANUFACTURER,
GNUTLS_PKCS11_OBJ_TOKEN_MODEL,
GNUTLS_PKCS11_OBJ_ID,
/* the pkcs11 provider library info */
GNUTLS_PKCS11_OBJ_LIBRARY_VERSION,
GNUTLS_PKCS11_OBJ_LIBRARY_DESCRIPTION,
GNUTLS_PKCS11_OBJ_LIBRARY_MANUFACTURER
} gnutls_pkcs11_obj_info_t;
int gnutls_pkcs11_obj_get_info(gnutls_pkcs11_obj_t crt,
gnutls_pkcs11_obj_info_t itype,
void *output, size_t * output_size);
/**
* gnutls_pkcs11_obj_attr_t:
* @GNUTLS_PKCS11_OBJ_ATTR_CRT_ALL: Specify all certificates.
* @GNUTLS_PKCS11_OBJ_ATTR_CRT_TRUSTED: Specify all certificates marked as trusted.
* @GNUTLS_PKCS11_OBJ_ATTR_CRT_TRUSTED_CA: Specify all certificates marked as trusted and are CAs.
* @GNUTLS_PKCS11_OBJ_ATTR_CRT_WITH_PRIVKEY: Specify all certificates with a corresponding private key.
* @GNUTLS_PKCS11_OBJ_ATTR_PUBKEY: Specify all public keys.
* @GNUTLS_PKCS11_OBJ_ATTR_PRIVKEY: Specify all private keys.
* @GNUTLS_PKCS11_OBJ_ATTR_ALL: Specify all objects.
*
* Enumeration of several attributes for object enumeration.
*/
typedef enum {
GNUTLS_PKCS11_OBJ_ATTR_CRT_ALL = 1, /* all certificates */
GNUTLS_PKCS11_OBJ_ATTR_CRT_TRUSTED, /* certificates marked as trusted */
GNUTLS_PKCS11_OBJ_ATTR_CRT_WITH_PRIVKEY, /* certificates with corresponding private key */
GNUTLS_PKCS11_OBJ_ATTR_PUBKEY, /* public keys */
GNUTLS_PKCS11_OBJ_ATTR_PRIVKEY, /* private keys */
GNUTLS_PKCS11_OBJ_ATTR_ALL, /* everything! */
GNUTLS_PKCS11_OBJ_ATTR_CRT_TRUSTED_CA, /* CAs */
} gnutls_pkcs11_obj_attr_t;
/**
* gnutls_pkcs11_token_info_t:
* @GNUTLS_PKCS11_TOKEN_LABEL: The token's label (string)
* @GNUTLS_PKCS11_TOKEN_SERIAL: The token's serial number (string)
* @GNUTLS_PKCS11_TOKEN_MANUFACTURER: The token's manufacturer (string)
* @GNUTLS_PKCS11_TOKEN_MODEL: The token's model (string)
* @GNUTLS_PKCS11_TOKEN_TRUSTED: Whether the token is marked as trusted in p11-kit (unsigned int)
*
* Enumeration of types for retrieving token information.
*/
typedef enum {
GNUTLS_PKCS11_TOKEN_LABEL,
GNUTLS_PKCS11_TOKEN_SERIAL,
GNUTLS_PKCS11_TOKEN_MANUFACTURER,
GNUTLS_PKCS11_TOKEN_MODEL,
} gnutls_pkcs11_token_info_t;
/**
* gnutls_pkcs11_obj_type_t:
* @GNUTLS_PKCS11_OBJ_UNKNOWN: Unknown PKCS11 object.
* @GNUTLS_PKCS11_OBJ_X509_CRT: X.509 certificate.
* @GNUTLS_PKCS11_OBJ_PUBKEY: Public key.
* @GNUTLS_PKCS11_OBJ_PRIVKEY: Private key.
* @GNUTLS_PKCS11_OBJ_SECRET_KEY: Secret key.
* @GNUTLS_PKCS11_OBJ_DATA: Data object.
*
* Enumeration of object types.
*/
typedef enum {
GNUTLS_PKCS11_OBJ_UNKNOWN,
GNUTLS_PKCS11_OBJ_X509_CRT,
GNUTLS_PKCS11_OBJ_PUBKEY,
GNUTLS_PKCS11_OBJ_PRIVKEY,
GNUTLS_PKCS11_OBJ_SECRET_KEY,
GNUTLS_PKCS11_OBJ_DATA
} gnutls_pkcs11_obj_type_t;
int
gnutls_pkcs11_token_init(const char *token_url,
const char *so_pin, const char *label);
int
gnutls_pkcs11_token_get_mechanism(const char *url,
unsigned int idx,
unsigned long *mechanism);
int gnutls_pkcs11_token_set_pin(const char *token_url, const char *oldpin, const char *newpin, unsigned int flags /*gnutls_pin_flag_t */);
int gnutls_pkcs11_token_get_url(unsigned int seq,
gnutls_pkcs11_url_type_t detailed,
char **url);
int gnutls_pkcs11_token_get_info(const char *url,
gnutls_pkcs11_token_info_t ttype,
void *output, size_t * output_size);
#define GNUTLS_PKCS11_TOKEN_HW 1
#define GNUTLS_PKCS11_TOKEN_TRUSTED (1<<1) /* p11-kit trusted */
int gnutls_pkcs11_token_get_flags(const char *url, unsigned int *flags);
int gnutls_pkcs11_obj_list_import_url(gnutls_pkcs11_obj_t * p_list,
unsigned int *const n_list,
const char *url,
gnutls_pkcs11_obj_attr_t
attrs, unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */
);
int
gnutls_pkcs11_obj_list_import_url2(gnutls_pkcs11_obj_t ** p_list,
unsigned int *n_list,
const char *url,
gnutls_pkcs11_obj_attr_t attrs,
unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */
);
int gnutls_x509_crt_import_pkcs11(gnutls_x509_crt_t crt,
gnutls_pkcs11_obj_t pkcs11_crt);
int gnutls_x509_crt_import_pkcs11_url(gnutls_x509_crt_t crt,
const char *url, unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */
);
gnutls_pkcs11_obj_type_t
gnutls_pkcs11_obj_get_type(gnutls_pkcs11_obj_t obj);
const char *gnutls_pkcs11_type_get_name(gnutls_pkcs11_obj_type_t type);
int gnutls_x509_crt_list_import_pkcs11(gnutls_x509_crt_t * certs,
unsigned int cert_max,
gnutls_pkcs11_obj_t *
const objs, unsigned int flags
/* must be zero */ );
/* private key functions...*/
int gnutls_pkcs11_privkey_init(gnutls_pkcs11_privkey_t * key);
void gnutls_pkcs11_privkey_set_pin_function(gnutls_pkcs11_privkey_t
key,
gnutls_pin_callback_t
fn, void *userdata);
void gnutls_pkcs11_privkey_deinit(gnutls_pkcs11_privkey_t key);
int gnutls_pkcs11_privkey_get_pk_algorithm(gnutls_pkcs11_privkey_t
key, unsigned int *bits);
int gnutls_pkcs11_privkey_get_info(gnutls_pkcs11_privkey_t pkey,
gnutls_pkcs11_obj_info_t itype,
void *output, size_t * output_size);
int gnutls_pkcs11_privkey_import_url(gnutls_pkcs11_privkey_t pkey,
const char *url, unsigned int flags);
int gnutls_pkcs11_privkey_export_url(gnutls_pkcs11_privkey_t key,
gnutls_pkcs11_url_type_t
detailed, char **url);
int gnutls_pkcs11_privkey_status(gnutls_pkcs11_privkey_t key);
int gnutls_pkcs11_privkey_generate(const char *url,
gnutls_pk_algorithm_t pk,
unsigned int bits,
const char *label, unsigned int flags);
int
gnutls_pkcs11_privkey_generate2(const char *url,
gnutls_pk_algorithm_t pk,
unsigned int bits,
const char *label,
gnutls_x509_crt_fmt_t fmt,
gnutls_datum_t * pubkey,
unsigned int flags);
int
gnutls_pkcs11_token_get_random(const char *token_url,
void *data, size_t len);
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif

View file

@ -0,0 +1,135 @@
/*
* Copyright (C) 2003-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef GNUTLS_PKCS12_H
#define GNUTLS_PKCS12_H
#include <gnutls/x509.h>
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* PKCS12 structures handling
*/
struct gnutls_pkcs12_int;
typedef struct gnutls_pkcs12_int *gnutls_pkcs12_t;
struct gnutls_pkcs12_bag_int;
typedef struct gnutls_pkcs12_bag_int *gnutls_pkcs12_bag_t;
int gnutls_pkcs12_init(gnutls_pkcs12_t * pkcs12);
void gnutls_pkcs12_deinit(gnutls_pkcs12_t pkcs12);
int gnutls_pkcs12_import(gnutls_pkcs12_t pkcs12,
const gnutls_datum_t * data,
gnutls_x509_crt_fmt_t format, unsigned int flags);
int gnutls_pkcs12_export(gnutls_pkcs12_t pkcs12,
gnutls_x509_crt_fmt_t format,
void *output_data, size_t * output_data_size);
int gnutls_pkcs12_export2(gnutls_pkcs12_t pkcs12,
gnutls_x509_crt_fmt_t format,
gnutls_datum_t * out);
int gnutls_pkcs12_get_bag(gnutls_pkcs12_t pkcs12,
int indx, gnutls_pkcs12_bag_t bag);
int gnutls_pkcs12_set_bag(gnutls_pkcs12_t pkcs12, gnutls_pkcs12_bag_t bag);
int gnutls_pkcs12_generate_mac(gnutls_pkcs12_t pkcs12, const char *pass);
int gnutls_pkcs12_verify_mac(gnutls_pkcs12_t pkcs12, const char *pass);
int gnutls_pkcs12_bag_decrypt(gnutls_pkcs12_bag_t bag, const char *pass);
int gnutls_pkcs12_bag_encrypt(gnutls_pkcs12_bag_t bag,
const char *pass, unsigned int flags);
#define GNUTLS_PKCS12_SP_INCLUDE_SELF_SIGNED 1
int gnutls_pkcs12_simple_parse(gnutls_pkcs12_t p12,
const char *password,
gnutls_x509_privkey_t * key,
gnutls_x509_crt_t ** chain,
unsigned int *chain_len,
gnutls_x509_crt_t ** extra_certs,
unsigned int *extra_certs_len,
gnutls_x509_crl_t * crl,
unsigned int flags);
/**
* gnutls_pkcs12_bag_type_t:
* @GNUTLS_BAG_EMPTY: Empty PKCS-12 bag.
* @GNUTLS_BAG_PKCS8_ENCRYPTED_KEY: PKCS-12 bag with PKCS-8 encrypted key.
* @GNUTLS_BAG_PKCS8_KEY: PKCS-12 bag with PKCS-8 key.
* @GNUTLS_BAG_CERTIFICATE: PKCS-12 bag with certificate.
* @GNUTLS_BAG_CRL: PKCS-12 bag with CRL.
* @GNUTLS_BAG_SECRET: PKCS-12 bag with secret PKCS-9 keys.
* @GNUTLS_BAG_ENCRYPTED: Encrypted PKCS-12 bag.
* @GNUTLS_BAG_UNKNOWN: Unknown PKCS-12 bag.
*
* Enumeration of different PKCS 12 bag types.
*/
typedef enum gnutls_pkcs12_bag_type_t {
GNUTLS_BAG_EMPTY = 0,
GNUTLS_BAG_PKCS8_ENCRYPTED_KEY = 1,
GNUTLS_BAG_PKCS8_KEY = 2,
GNUTLS_BAG_CERTIFICATE = 3,
GNUTLS_BAG_CRL = 4,
GNUTLS_BAG_SECRET = 5, /* Secret data. Underspecified in pkcs-12,
* gnutls extension. We use the PKCS-9
* random nonce ID 1.2.840.113549.1.9.25.3
* to store randomly generated keys.
*/
GNUTLS_BAG_ENCRYPTED = 10,
GNUTLS_BAG_UNKNOWN = 20
} gnutls_pkcs12_bag_type_t;
gnutls_pkcs12_bag_type_t
gnutls_pkcs12_bag_get_type(gnutls_pkcs12_bag_t bag, int indx);
int gnutls_pkcs12_bag_get_data(gnutls_pkcs12_bag_t bag, int indx,
gnutls_datum_t * data);
int gnutls_pkcs12_bag_set_data(gnutls_pkcs12_bag_t bag,
gnutls_pkcs12_bag_type_t type,
const gnutls_datum_t * data);
int gnutls_pkcs12_bag_set_crl(gnutls_pkcs12_bag_t bag,
gnutls_x509_crl_t crl);
int gnutls_pkcs12_bag_set_crt(gnutls_pkcs12_bag_t bag,
gnutls_x509_crt_t crt);
int gnutls_pkcs12_bag_init(gnutls_pkcs12_bag_t * bag);
void gnutls_pkcs12_bag_deinit(gnutls_pkcs12_bag_t bag);
int gnutls_pkcs12_bag_get_count(gnutls_pkcs12_bag_t bag);
int gnutls_pkcs12_bag_get_key_id(gnutls_pkcs12_bag_t bag, int indx,
gnutls_datum_t * id);
int gnutls_pkcs12_bag_set_key_id(gnutls_pkcs12_bag_t bag, int indx,
const gnutls_datum_t * id);
int gnutls_pkcs12_bag_get_friendly_name(gnutls_pkcs12_bag_t bag,
int indx, char **name);
int gnutls_pkcs12_bag_set_friendly_name(gnutls_pkcs12_bag_t bag,
int indx, const char *name);
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* GNUTLS_PKCS12_H */

View file

@ -0,0 +1,79 @@
/*
* Copyright (C) 2010-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef __GNUTLS_TPM_H
#define __GNUTLS_TPM_H
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
struct tpm_key_list_st;
typedef struct tpm_key_list_st *gnutls_tpm_key_list_t;
#define GNUTLS_TPM_KEY_SIGNING (1<<1)
#define GNUTLS_TPM_REGISTER_KEY (1<<2)
#define GNUTLS_TPM_KEY_USER (1<<3)
/**
* gnutls_tpmkey_fmt_t:
* @GNUTLS_TPMKEY_FMT_RAW: The portable data format.
* @GNUTLS_TPMKEY_FMT_DER: An alias for the raw format.
* @GNUTLS_TPMKEY_FMT_CTK_PEM: A custom data format used by some TPM tools.
*
* Enumeration of different certificate encoding formats.
*/
typedef enum {
GNUTLS_TPMKEY_FMT_RAW = 0,
GNUTLS_TPMKEY_FMT_DER = GNUTLS_TPMKEY_FMT_RAW,
GNUTLS_TPMKEY_FMT_CTK_PEM = 1
} gnutls_tpmkey_fmt_t;
int
gnutls_tpm_privkey_generate(gnutls_pk_algorithm_t pk,
unsigned int bits,
const char *srk_password,
const char *key_password,
gnutls_tpmkey_fmt_t format,
gnutls_x509_crt_fmt_t pub_format,
gnutls_datum_t * privkey,
gnutls_datum_t * pubkey, unsigned int flags);
void gnutls_tpm_key_list_deinit(gnutls_tpm_key_list_t list);
int gnutls_tpm_key_list_get_url(gnutls_tpm_key_list_t list,
unsigned int idx, char **url,
unsigned int flags);
int gnutls_tpm_get_registered(gnutls_tpm_key_list_t * list);
int gnutls_tpm_privkey_delete(const char *url, const char *srk_password);
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,125 @@
/* -*- c -*-
* Copyright (C) 2013 Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef GNUTLS_SBUF_H
#define GNUTLS_SBUF_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#include <gnutls/gnutls.h>
/* Buffered session I/O */
typedef struct xssl_st *xssl_t;
typedef struct xssl_cred_st *xssl_cred_t;
ssize_t xssl_printf(xssl_t sb, const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format(printf, 2, 3)))
#endif
;
ssize_t xssl_write(xssl_t sb, const void *data, size_t data_size);
ssize_t xssl_flush(xssl_t sb);
ssize_t xssl_read(xssl_t sb, void *data, size_t data_size);
ssize_t
xssl_getdelim(xssl_t sbuf, char **lineptr, size_t * n, int delimiter);
#define xssl_getline(sbuf, ptr, n) xssl_getdelim(sbuf, ptr, n, '\n')
void xssl_deinit(xssl_t sb);
#define GNUTLS_SBUF_WRITE_FLUSHES (1<<0)
int xssl_sinit(xssl_t * isb, gnutls_session_t session, unsigned int flags);
gnutls_session_t xssl_get_session(xssl_t sb);
int xssl_client_init(xssl_t * isb, const char *hostname,
const char *service,
gnutls_transport_ptr fd,
const char *priority, xssl_cred_t cred,
unsigned int *status, unsigned int flags);
int xssl_server_init(xssl_t * isb,
gnutls_transport_ptr fd,
const char *priority, xssl_cred_t cred,
unsigned int *status, unsigned int flags);
/* High level credential structures */
typedef enum {
GNUTLS_VMETHOD_NO_AUTH = 0,
GNUTLS_VMETHOD_TOFU = 1 << 0,
GNUTLS_VMETHOD_GIVEN_CAS = 1 << 1,
GNUTLS_VMETHOD_SYSTEM_CAS = 1 << 2
} gnutls_vmethod_t;
typedef enum {
GNUTLS_CINPUT_TYPE_FILE = 0,
GNUTLS_CINPUT_TYPE_MEM = 1,
GNUTLS_CINPUT_TYPE_PIN_FUNC = 2,
} gnutls_cinput_type_t;
typedef enum {
GNUTLS_CINPUT_CAS = 1, /* i1 contains the CAs */
GNUTLS_CINPUT_CRLS = 2, /* i1 contains the CRLs */
GNUTLS_CINPUT_TOFU_DB = 3, /* i1 contains the DB filename */
GNUTLS_CINPUT_KEYPAIR = 4, /* i1 contains the certificate, i2 the key
* or i1.pin_fn contains the pin function,
* and i2.udata the user pointer */
} gnutls_cinput_contents_t;
typedef struct gnutls_cinput_st {
gnutls_cinput_type_t type;
gnutls_cinput_contents_t contents;
gnutls_x509_crt_fmt_t fmt; /* if applicable */
union {
gnutls_pin_callback_t pin_fn;
const char *file;
gnutls_datum_t mem;
} i1;
union {
void *udata;
const char *file;
gnutls_datum_t mem;
} i2;
unsigned long future_pad[8];
} gnutls_cinput_st;
int xssl_cred_init(xssl_cred_t * c, unsigned vflags,
gnutls_cinput_st * aux, unsigned aux_size);
void xssl_cred_deinit(xssl_cred_t cred);
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* GNUTLS_SBUF_H */

View file

@ -0,0 +1,80 @@
/* aes.h
*
* The aes/rijndael block cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_AES_H_INCLUDED
#define NETTLE_AES_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define aes_set_encrypt_key nettle_aes_set_encrypt_key
#define aes_set_decrypt_key nettle_aes_set_decrypt_key
#define aes_invert_key nettle_aes_invert_key
#define aes_encrypt nettle_aes_encrypt
#define aes_decrypt nettle_aes_decrypt
#define AES_BLOCK_SIZE 16
/* Variable key size between 128 and 256 bits. But the only valid
* values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */
#define AES_MIN_KEY_SIZE 16
#define AES_MAX_KEY_SIZE 32
#define AES_KEY_SIZE 32
/* FIXME: Change to put nrounds first, to make it possible to use a
truncated ctx struct, with less subkeys, for the shorter key
sizes? */
struct aes_ctx {
uint32_t keys[60]; /* maximum size of key schedule */
unsigned nrounds; /* number of rounds to use for our key size */
};
void
aes_set_encrypt_key(struct aes_ctx *ctx,
unsigned length, const uint8_t * key);
void
aes_set_decrypt_key(struct aes_ctx *ctx,
unsigned length, const uint8_t * key);
void
aes_invert_key(struct aes_ctx *dst, const struct aes_ctx *src);
void
aes_encrypt(const struct aes_ctx *ctx,
unsigned length, uint8_t * dst, const uint8_t * src);
void
aes_decrypt(const struct aes_ctx *ctx,
unsigned length, uint8_t * dst, const uint8_t * src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_AES_H_INCLUDED */

View file

@ -0,0 +1,63 @@
/* arcfour.h
*
* The arcfour/rc4 stream cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_ARCFOUR_H_INCLUDED
#define NETTLE_ARCFOUR_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define arcfour_set_key nettle_arcfour_set_key
#define arcfour_crypt nettle_arcfour_crypt
/* Minimum and maximum keysizes, and a reasonable default. In
* octets.*/
#define ARCFOUR_MIN_KEY_SIZE 1
#define ARCFOUR_MAX_KEY_SIZE 256
#define ARCFOUR_KEY_SIZE 16
struct arcfour_ctx {
uint8_t S[256];
uint8_t i;
uint8_t j;
};
void
arcfour_set_key(struct arcfour_ctx *ctx,
unsigned length, const uint8_t * key);
void
arcfour_crypt(struct arcfour_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ARCFOUR_H_INCLUDED */

View file

@ -0,0 +1,84 @@
/* arctwo.h
*
* The arctwo/rfc2268 block cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2004 Simon Josefsson
* Copyright (C) 2002, 2004 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_ARCTWO_H_INCLUDED
#define NETTLE_ARCTWO_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define arctwo_set_key nettle_arctwo_set_key
#define arctwo_set_key_ekb nettle_arctwo_set_key_ekb
#define arctwo_encrypt nettle_arctwo_encrypt
#define arctwo_decrypt nettle_arctwo_decrypt
#define arctwo_set_key_gutmann nettle_arctwo_set_key_gutmann
#define ARCTWO_BLOCK_SIZE 8
/* Variable key size from 1 byte to 128 bytes. */
#define ARCTWO_MIN_KEY_SIZE 1
#define ARCTWO_MAX_KEY_SIZE 128
#define ARCTWO_KEY_SIZE 8
struct arctwo_ctx {
uint16_t S[64];
};
/* Key expansion function that takes the "effective key bits", 1-1024,
as an explicit argument. 0 means maximum key bits. */
void
arctwo_set_key_ekb(struct arctwo_ctx *ctx,
unsigned length, const uint8_t * key,
unsigned ekb);
/* Equvivalent to arctwo_set_key_ekb, with ekb = 8 * length */
void
arctwo_set_key(struct arctwo_ctx *ctx, unsigned length,
const uint8_t * key);
/* Equvivalent to arctwo_set_key_ekb, with ekb = 1024 */
void
arctwo_set_key_gutmann(struct arctwo_ctx *ctx,
unsigned length, const uint8_t * key);
void
arctwo_encrypt(struct arctwo_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
void
arctwo_decrypt(struct arctwo_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ARCTWO_H_INCLUDED */

View file

@ -0,0 +1,138 @@
/* asn1.h
*
* Some very limited asn.1 support.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2005 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_ASN1_H_INCLUDED
#define NETTLE_ASN1_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define asn1_der_iterator_first nettle_asn1_der_iterator_first
#define asn1_der_iterator_next nettle_asn1_der_iterator_next
#define asn1_der_decode_constructed nettle_asn1_der_decode_constructed
#define asn1_der_decode_constructed_last nettle_asn1_der_decode_constructed_last
#define asn1_der_decode_bitstring nettle_asn1_der_decode_bitstring
#define asn1_der_decode_bitstring_last nettle_asn1_der_decode_bitstring_last
#define asn1_der_get_uint32 nettle_asn1_der_get_uint32
#define asn1_der_get_bignum nettle_asn1_der_get_bignum
/* enum asn1_type keeps the class number and the constructive in bits
13-14, and the constructive flag in bit 12. The remaining 14 bits
are the tag (although currently, only tags in the range 0-30 are
supported). */
enum {
ASN1_TYPE_CONSTRUCTED = 1 << 12,
ASN1_CLASS_UNIVERSAL = 0,
ASN1_CLASS_APPLICATION = 1 << 13,
ASN1_CLASS_CONTEXT_SPECIFIC = 2 << 13,
ASN1_CLASS_PRIVATE = 3 << 13,
ASN1_CLASS_MASK = 3 << 13,
ASN1_CLASS_SHIFT = 13,
};
enum asn1_type {
ASN1_BOOLEAN = 1,
ASN1_INTEGER = 2,
ASN1_BITSTRING = 3,
ASN1_OCTETSTRING = 4,
ASN1_NULL = 5,
ASN1_IDENTIFIER = 6,
ASN1_REAL = 9,
ASN1_ENUMERATED = 10,
ASN1_UTF8STRING = 12,
ASN1_SEQUENCE = 16 | ASN1_TYPE_CONSTRUCTED,
ASN1_SET = 17 | ASN1_TYPE_CONSTRUCTED,
ASN1_PRINTABLESTRING = 19,
ASN1_TELETEXSTRING = 20,
ASN1_IA5STRING = 22,
ASN1_UTC = 23,
ASN1_UNIVERSALSTRING = 28,
ASN1_BMPSTRING = 30,
};
enum asn1_iterator_result {
ASN1_ITERATOR_ERROR,
ASN1_ITERATOR_PRIMITIVE,
ASN1_ITERATOR_CONSTRUCTED,
ASN1_ITERATOR_END,
};
/* Parsing DER objects. */
struct asn1_der_iterator {
unsigned buffer_length;
const uint8_t *buffer;
/* Next object to parse. */
unsigned pos;
enum asn1_type type;
/* Pointer to the current object */
unsigned length;
const uint8_t *data;
};
/* Initializes the iterator. */
enum asn1_iterator_result
asn1_der_iterator_first(struct asn1_der_iterator *iterator,
unsigned length, const uint8_t * input);
enum asn1_iterator_result
asn1_der_iterator_next(struct asn1_der_iterator *iterator);
/* Starts parsing of a constructed object. */
enum asn1_iterator_result
asn1_der_decode_constructed(struct asn1_der_iterator *i,
struct asn1_der_iterator *contents);
/* For the common case that we have a sequence at the end of the
object. Checks that the current object is the final one, and then
reinitializes the iterator to parse its ontents. */
enum asn1_iterator_result
asn1_der_decode_constructed_last(struct asn1_der_iterator *i);
enum asn1_iterator_result
asn1_der_decode_bitstring(struct asn1_der_iterator *i,
struct asn1_der_iterator *contents);
enum asn1_iterator_result
asn1_der_decode_bitstring_last(struct asn1_der_iterator *i);
/* All these functions return 1 on success, 0 on failure */
int
asn1_der_get_uint32(struct asn1_der_iterator *i, uint32_t * x);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ASN1_H_INCLUDED */

View file

@ -0,0 +1,100 @@
/* base16.h
*
* Hex encoding and decoding, following spki conventions (i.e.
* allowing whitespace between digits).
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_BASE16_H_INCLUDED
#define NETTLE_BASE16_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define base16_encode_single nettle_base16_encode_single
#define base16_encode_update nettle_base16_encode_update
#define base16_decode_init nettle_base16_decode_init
#define base16_decode_single nettle_base16_decode_single
#define base16_decode_update nettle_base16_decode_update
#define base16_decode_final nettle_base16_decode_final
/* Base16 encoding */
/* Maximum length of output for base16_encode_update. */
#define BASE16_ENCODE_LENGTH(length) ((length) * 2)
/* Encodes a single byte. Always stores two digits in dst[0] and dst[1]. */
void
base16_encode_single(uint8_t * dst, uint8_t src);
/* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */
void
base16_encode_update(uint8_t * dst,
unsigned length, const uint8_t * src);
/* Base16 decoding */
/* Maximum length of output for base16_decode_update. */
/* We have at most 4 buffered bits, and a total of (length + 1) * 4 bits. */
#define BASE16_DECODE_LENGTH(length) (((length) + 1) / 2)
struct base16_decode_ctx {
unsigned word; /* Leftover bits */
unsigned bits; /* Number buffered bits */
};
void
base16_decode_init(struct base16_decode_ctx *ctx);
/* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
* errors. */
int
base16_decode_single(struct base16_decode_ctx *ctx,
uint8_t * dst, uint8_t src);
/* Returns 1 on success, 0 on error. DST should point to an area of
* size at least BASE16_DECODE_LENGTH(length), and for sanity
* checking, *DST_LENGTH should be initialized to the size of that
* area before the call. *DST_LENGTH is updated to the amount of
* decoded output. */
/* Currently results in an assertion failure if *DST_LENGTH is
* too small. FIXME: Return some error instead? */
int
base16_decode_update(struct base16_decode_ctx *ctx,
unsigned *dst_length,
uint8_t * dst,
unsigned src_length, const uint8_t * src);
/* Returns 1 on success. */
int
base16_decode_final(struct base16_decode_ctx *ctx);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BASE16_H_INCLUDED */

View file

@ -0,0 +1,146 @@
/* base64.h
*
* "ASCII armor" codecs.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller, Dan Egnor
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_BASE64_H_INCLUDED
#define NETTLE_BASE64_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define base64_encode_init nettle_base64_encode_init
#define base64_encode_single nettle_base64_encode_single
#define base64_encode_update nettle_base64_encode_update
#define base64_encode_final nettle_base64_encode_final
#define base64_encode_raw nettle_base64_encode_raw
#define base64_encode_group nettle_base64_encode_group
#define base64_decode_init nettle_base64_decode_init
#define base64_decode_single nettle_base64_decode_single
#define base64_decode_update nettle_base64_decode_update
#define base64_decode_final nettle_base64_decode_final
#define BASE64_BINARY_BLOCK_SIZE 3
#define BASE64_TEXT_BLOCK_SIZE 4
/* Base64 encoding */
/* Maximum length of output for base64_encode_update. NOTE: Doesn't
* include any padding that base64_encode_final may add. */
/* We have at most 4 buffered bits, and a total of (4 + length * 8) bits. */
#define BASE64_ENCODE_LENGTH(length) (((length) * 8 + 4)/6)
/* Maximum length of output generated by base64_encode_final. */
#define BASE64_ENCODE_FINAL_LENGTH 3
/* Exact length of output generated by base64_encode_raw, including
* padding. */
#define BASE64_ENCODE_RAW_LENGTH(length) ((((length) + 2)/3)*4)
struct base64_encode_ctx {
unsigned word; /* Leftover bits */
unsigned bits; /* Number of bits, always 0, 2, or 4. */
};
void
base64_encode_init(struct base64_encode_ctx *ctx);
/* Encodes a single byte. Returns amount of output (always 1 or 2). */
unsigned
base64_encode_single(struct base64_encode_ctx *ctx,
uint8_t * dst, uint8_t src);
/* Returns the number of output characters. DST should point to an
* area of size at least BASE64_ENCODE_LENGTH(length). */
unsigned
base64_encode_update(struct base64_encode_ctx *ctx,
uint8_t * dst,
unsigned length, const uint8_t * src);
/* DST should point to an area of size at least
* BASE64_ENCODE_FINAL_LENGTH */
unsigned
base64_encode_final(struct base64_encode_ctx *ctx, uint8_t * dst);
/* Lower level functions */
/* Encodes a string in one go, including any padding at the end.
* Generates exactly BASE64_ENCODE_RAW_LENGTH(length) bytes of output.
* Supports overlapped operation, if src <= dst. */
void
base64_encode_raw(uint8_t * dst, unsigned length,
const uint8_t * src);
void
base64_encode_group(uint8_t * dst, uint32_t group);
/* Base64 decoding */
/* Maximum length of output for base64_decode_update. */
/* We have at most 6 buffered bits, and a total of (length + 1) * 6 bits. */
#define BASE64_DECODE_LENGTH(length) ((((length) + 1) * 6) / 8)
struct base64_decode_ctx {
unsigned word; /* Leftover bits */
unsigned bits; /* Number buffered bits */
/* Number of padding characters encountered */
unsigned padding;
};
void
base64_decode_init(struct base64_decode_ctx *ctx);
/* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
* errors. */
int
base64_decode_single(struct base64_decode_ctx *ctx,
uint8_t * dst, uint8_t src);
/* Returns 1 on success, 0 on error. DST should point to an area of
* size at least BASE64_DECODE_LENGTH(length), and for sanity
* checking, *DST_LENGTH should be initialized to the size of that
* area before the call. *DST_LENGTH is updated to the amount of
* decoded output. */
/* Currently results in an assertion failure if *DST_LENGTH is
* too small. FIXME: Return some error instead? */
int
base64_decode_update(struct base64_decode_ctx *ctx,
unsigned *dst_length,
uint8_t * dst,
unsigned src_length, const uint8_t * src);
/* Returns 1 on success. */
int
base64_decode_final(struct base64_decode_ctx *ctx);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BASE64_H_INCLUDED */

View file

@ -0,0 +1,124 @@
/* bignum.h
*
* bignum operations that are missing from gmp.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_BIGNUM_H_INCLUDED
#define NETTLE_BIGNUM_H_INCLUDED
#include "nettle-meta.h"
#include <gmp.h>
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Size needed for signed encoding, including extra sign byte if
* necessary. */
unsigned
nettle_mpz_sizeinbase_256_s(const mpz_t x);
/* Size needed for unsigned encoding */
unsigned
nettle_mpz_sizeinbase_256_u(const mpz_t x);
/* Writes an integer as length octets, using big endian byte order,
* and two's complement for negative numbers. */
void
nettle_mpz_get_str_256(unsigned length, uint8_t * s,
const mpz_t x);
/* Reads a big endian, two's complement, integer. */
void
nettle_mpz_set_str_256_s(mpz_t x,
unsigned length, const uint8_t * s);
void
nettle_mpz_init_set_str_256_s(mpz_t x,
unsigned length, const uint8_t * s);
/* Similar, but for unsigned format. These function don't interpret
* the most significant bit as the sign. */
void
nettle_mpz_set_str_256_u(mpz_t x,
unsigned length, const uint8_t * s);
void
nettle_mpz_init_set_str_256_u(mpz_t x,
unsigned length, const uint8_t * s);
/* Returns a uniformly distributed random number 0 <= x < 2^n */
void
nettle_mpz_random_size(mpz_t x,
void *ctx, nettle_random_func * random,
unsigned bits);
/* Returns a number x, almost uniformly random in the range
* 0 <= x < n. */
void
nettle_mpz_random(mpz_t x,
void *ctx, nettle_random_func * random,
const mpz_t n);
void
nettle_next_prime(mpz_t p, mpz_t n, unsigned count,
unsigned prime_limit, void *progress_ctx,
nettle_progress_func * progress);
void
nettle_random_prime(mpz_t p, unsigned bits, int top_bits_set,
void *ctx, nettle_random_func * random,
void *progress_ctx,
nettle_progress_func * progress);
void
_nettle_generate_pocklington_prime(mpz_t p, mpz_t r,
unsigned bits,
int top_bits_set, void *ctx,
nettle_random_func * random,
const mpz_t p0, const mpz_t q,
const mpz_t p0q);
/* sexp parsing */
struct sexp_iterator;
/* If LIMIT is non-zero, the number must be at most LIMIT bits.
* Implies sexp_iterator_next. */
int
nettle_mpz_set_sexp(mpz_t x, unsigned limit,
struct sexp_iterator *i);
/* der parsing */
struct asn1_der_iterator;
int
nettle_asn1_der_get_bignum(struct asn1_der_iterator *iterator,
mpz_t x, unsigned max_bits);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BIGNUM_H_INCLUDED */

View file

@ -0,0 +1,74 @@
/* blowfish.h
*
* Blowfish block cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 1998, 2001 FSF, Ray Dassen, Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_BLOWFISH_H_INCLUDED
#define NETTLE_BLOWFISH_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define blowfish_set_key nettle_blowfish_set_key
#define blowfish_encrypt nettle_blowfish_encrypt
#define blowfish_decrypt nettle_blowfish_decrypt
#define BLOWFISH_BLOCK_SIZE 8
/* Variable key size between 64 and 448 bits. */
#define BLOWFISH_MIN_KEY_SIZE 8
#define BLOWFISH_MAX_KEY_SIZE 56
/* Default to 128 bits */
#define BLOWFISH_KEY_SIZE 16
#define _BLOWFISH_ROUNDS 16
struct blowfish_ctx {
uint32_t s[4][256];
uint32_t p[_BLOWFISH_ROUNDS + 2];
};
/* On success, returns 1 and sets ctx->status to BLOWFISH_OK (zero).
* On error, returns 0 and sets ctx->status to BLOWFISH_WEAK_KEY. */
int
blowfish_set_key(struct blowfish_ctx *ctx,
unsigned length, const uint8_t * key);
void
blowfish_encrypt(const struct blowfish_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
void
blowfish_decrypt(const struct blowfish_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BLOWFISH_H_INCLUDED */

View file

@ -0,0 +1,94 @@
/* buffer.h
*
* A bare-bones string stream.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_BUFFER_H_INCLUDED
#define NETTLE_BUFFER_H_INCLUDED
#include "realloc.h"
#ifdef __cplusplus
extern "C" {
#endif
struct nettle_buffer {
uint8_t *contents;
/* Allocated size */
unsigned alloc;
void *realloc_ctx;
nettle_realloc_func *realloc;
/* Current size */
unsigned size;
};
/* Initializes a buffer that uses plain realloc */
void
nettle_buffer_init(struct nettle_buffer *buffer);
void
nettle_buffer_init_realloc(struct nettle_buffer *buffer,
void *realloc_ctx,
nettle_realloc_func * realloc);
/* Initializes a buffer of fix size */
void
nettle_buffer_init_size(struct nettle_buffer *buffer,
unsigned length, uint8_t * space);
void
nettle_buffer_clear(struct nettle_buffer *buffer);
/* Resets the buffer, without freeing the buffer space. */
void
nettle_buffer_reset(struct nettle_buffer *buffer);
int
nettle_buffer_grow(struct nettle_buffer *buffer, unsigned length);
#define NETTLE_BUFFER_PUTC(buffer, c) \
( (((buffer)->size < (buffer)->alloc) || nettle_buffer_grow((buffer), 1)) \
&& ((buffer)->contents[(buffer)->size++] = (c), 1) )
int
nettle_buffer_write(struct nettle_buffer *buffer,
unsigned length, const uint8_t * data);
/* Like nettle_buffer_write, but instead of copying data to the
* buffer, it returns a pointer to the area where the caller can copy
* the data. The pointer is valid only until the next call that can
* reallocate the buffer. */
uint8_t *nettle_buffer_space(struct nettle_buffer *buffer,
unsigned length);
/* Copy the contents of SRC to the end of DST. */
int
nettle_buffer_copy(struct nettle_buffer *dst,
const struct nettle_buffer *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BUFFER_H_INCLUDED */

View file

@ -0,0 +1,80 @@
/* camellia.h
*
* Copyright (C) 2006,2007
* NTT (Nippon Telegraph and Telephone Corporation).
*
* Copyright (C) 2010 Niels Möller
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef NETTLE_CAMELLIA_H_INCLUDED
#define NETTLE_CAMELLIA_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define camellia_set_encrypt_key nettle_camellia_set_encrypt_key
#define camellia_set_decrypt_key nettle_camellia_set_decrypt_key
#define camellia_invert_key nettle_camellia_invert_key
#define camellia_crypt nettle_camellia_crypt
#define camellia_crypt nettle_camellia_crypt
#define CAMELLIA_BLOCK_SIZE 16
/* Valid key sizes are 128, 192 or 256 bits (16, 24 or 32 bytes) */
#define CAMELLIA_MIN_KEY_SIZE 16
#define CAMELLIA_MAX_KEY_SIZE 32
#define CAMELLIA_KEY_SIZE 32
struct camellia_ctx {
/* Number of subkeys. */
unsigned nkeys;
/* For 128-bit keys, there are 18 regular rounds, pre- and
post-whitening, and two FL and FLINV rounds, using a total of 26
subkeys, each of 64 bit. For 192- and 256-bit keys, there are 6
additional regular rounds and one additional FL and FLINV, using
a total of 34 subkeys. */
/* The clever combination of subkeys imply one of the pre- and
post-whitening keys is folded with the round keys, so that subkey
#1 and the last one (#25 or #33) is not used. The result is that
we have only 24 or 32 subkeys at the end of key setup. */
uint64_t keys[32];
};
void
camellia_set_encrypt_key(struct camellia_ctx *ctx,
unsigned length, const uint8_t * key);
void
camellia_set_decrypt_key(struct camellia_ctx *ctx,
unsigned length, const uint8_t * key);
void
camellia_invert_key(struct camellia_ctx *dst,
const struct camellia_ctx *src);
void
camellia_crypt(const struct camellia_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CAMELLIA_H_INCLUDED */

View file

@ -0,0 +1,75 @@
/* cast128.h
*
* The CAST-128 block cipher.
*/
/* CAST-128 in C
* Written by Steve Reid <sreid@sea-to-sky.net>
* 100% Public Domain - no warranty
* Released 1997.10.11
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_CAST128_H_INCLUDED
#define NETTLE_CAST128_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define cast128_set_key nettle_cast128_set_key
#define cast128_encrypt nettle_cast128_encrypt
#define cast128_decrypt nettle_cast128_decrypt
#define CAST128_BLOCK_SIZE 8
/* Variable key size between 40 and 128. */
#define CAST128_MIN_KEY_SIZE 5
#define CAST128_MAX_KEY_SIZE 16
#define CAST128_KEY_SIZE 16
struct cast128_ctx {
uint32_t keys[32]; /* Key, after expansion */
unsigned rounds; /* Number of rounds to use, 12 or 16 */
};
void
cast128_set_key(struct cast128_ctx *ctx,
unsigned length, const uint8_t * key);
void
cast128_encrypt(const struct cast128_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
void
cast128_decrypt(const struct cast128_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CAST128_H_INCLUDED */

View file

@ -0,0 +1,73 @@
/* cbc.h
*
* Cipher block chaining mode.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_CBC_H_INCLUDED
#define NETTLE_CBC_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define cbc_encrypt nettle_cbc_encrypt
#define cbc_decrypt nettle_cbc_decrypt
void
cbc_encrypt(void *ctx, nettle_crypt_func * f,
unsigned block_size, uint8_t * iv,
unsigned length, uint8_t * dst, const uint8_t * src);
void
cbc_decrypt(void *ctx, nettle_crypt_func * f,
unsigned block_size, uint8_t * iv,
unsigned length, uint8_t * dst, const uint8_t * src);
#define CBC_CTX(type, size) \
{ type ctx; uint8_t iv[size]; }
#define CBC_SET_IV(ctx, data) \
memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
#define CBC_ENCRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, (void *)0, (void *)0)) \
: cbc_encrypt((void *) &(self)->ctx, \
(nettle_crypt_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
#define CBC_DECRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, (void *)0, (void *)0)) \
: cbc_decrypt((void *) &(self)->ctx, \
(nettle_crypt_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CBC_H_INCLUDED */

View file

@ -0,0 +1,60 @@
/* ctr.h
*
* Counter mode, using an network byte order incremented counter,
* matching the testcases of NIST 800-38A.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2005 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_CTR_H_INCLUDED
#define NETTLE_CTR_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define ctr_crypt nettle_ctr_crypt
void
ctr_crypt(void *ctx, nettle_crypt_func * f,
unsigned block_size, uint8_t * ctr,
unsigned length, uint8_t * dst, const uint8_t * src);
#define CTR_CTX(type, size) \
{ type ctx; uint8_t ctr[size]; }
#define CTR_SET_COUNTER(ctx, data) \
memcpy((ctx)->ctr, (data), sizeof((ctx)->ctr))
#define CTR_CRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, NULL, NULL)) \
: ctr_crypt((void *) &(self)->ctx, \
(nettle_crypt_func *) (f), \
sizeof((self)->ctr), (self)->ctr, \
(length), (dst), (src)))
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CTR_H_INCLUDED */

View file

@ -0,0 +1,151 @@
/* des-compat.h
*
* The des block cipher, libdes/openssl-style interface.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_DES_COMPAT_H_INCLUDED
#define NETTLE_DES_COMPAT_H_INCLUDED
/* According to Assar, des_set_key, des_set_key_odd_parity,
* des_is_weak_key, plus the encryption functions (des_*_encrypt and
* des_cbc_cksum) would be a pretty useful subset. */
/* NOTE: This is quite experimental, and not all functions are
* implemented. Contributions, in particular test cases are welcome. */
#include "des.h"
#ifdef __cplusplus
extern "C" {
#endif
/* We use some name mangling, to avoid collisions with either other
* nettle functions or with libcrypto. */
#define des_ecb3_encrypt nettle_openssl_des_ecb3_encrypt
#define des_cbc_cksum nettle_openssl_des_cbc_cksum
#define des_ncbc_encrypt nettle_openssl_des_ncbc_encrypt
#define des_cbc_encrypt nettle_openssl_des_cbc_encrypt
#define des_ecb_encrypt nettle_openssl_des_ecb_encrypt
#define des_ede3_cbc_encrypt nettle_openssl_des_ede3_cbc_encrypt
#define des_set_odd_parity nettle_openssl_des_set_odd_parity
#define des_check_key nettle_openssl_des_check_key
#define des_key_sched nettle_openssl_des_key_sched
#define des_is_weak_key nettle_openssl_des_is_weak_key
/* An extra alias */
#undef des_set_key
#define des_set_key nettle_openssl_des_key_sched
enum { DES_DECRYPT = 0, DES_ENCRYPT = 1 };
/* Types */
typedef uint32_t DES_LONG;
/* Note: Typedef:ed arrays should be avoided, but they're used here
* for compatibility. */
typedef struct des_ctx des_key_schedule[1];
typedef uint8_t des_cblock[DES_BLOCK_SIZE];
/* Note: The proper definition,
typedef const uint8_t const_des_cblock[DES_BLOCK_SIZE];
would have worked, *if* all the prototypes had used arguments like
foo(const_des_cblock src, des_cblock dst), letting argument arrays
"decay" into pointers of type uint8_t * and const uint8_t *.
But since openssl's prototypes use *pointers* const_des_cblock *src,
des_cblock *dst, this ends up in type conflicts, and the workaround
is to not use const at all.
*/
#define const_des_cblock des_cblock
/* Aliases */
#define des_ecb2_encrypt(i,o,k1,k2,e) \
des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
/* Global flag */
extern int des_check_key;
/* Prototypes */
/* Typing is a little confusing. Since both des_cblock and
des_key_schedule are typedef:ed arrays, it automatically decay to
a pointers.
But the functions are declared taking pointers to des_cblock, i.e.
pointers to arrays. And on the other hand, they take plain
des_key_schedule arguments, which is equivalent to pointers to
struct des_ctx. */
void
des_ecb3_encrypt(const_des_cblock * src, des_cblock * dst,
des_key_schedule k1,
des_key_schedule k2,
des_key_schedule k3, int enc);
/* des_cbc_cksum in libdes returns a 32 bit integer, representing the
* latter half of the output block, using little endian byte order. */
uint32_t
des_cbc_cksum(const uint8_t * src, des_cblock * dst,
long length, des_key_schedule ctx,
const_des_cblock * iv);
/* NOTE: Doesn't update iv. */
void
des_cbc_encrypt(const_des_cblock * src, des_cblock * dst,
long length, des_key_schedule ctx,
const_des_cblock * iv, int enc);
/* Similar, but updates iv. */
void
des_ncbc_encrypt(const_des_cblock * src, des_cblock * dst,
long length, des_key_schedule ctx,
des_cblock * iv, int enc);
void
des_ecb_encrypt(const_des_cblock * src, des_cblock * dst,
des_key_schedule ctx, int enc);
void
des_ede3_cbc_encrypt(const_des_cblock * src, des_cblock * dst,
long length, des_key_schedule k1,
des_key_schedule k2, des_key_schedule k3,
des_cblock * iv, int enc);
int
des_set_odd_parity(des_cblock * key);
int
des_key_sched(const_des_cblock * key, des_key_schedule ctx);
int
des_is_weak_key(const_des_cblock * key);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_DES_COMPAT_H_INCLUDED */

View file

@ -0,0 +1,104 @@
/* des.h
*
* The des block cipher. And triple des.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 1992, 2001, Dana L. How, Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/*
* des - fast & portable DES encryption & decryption.
* Copyright (C) 1992 Dana L. How
* Please see the file `../lib/descore.README' for the complete copyright
* notice.
*
* Slightly edited by Niels Möller, 1997
*/
#ifndef NETTLE_DES_H_INCLUDED
#define NETTLE_DES_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Namespace mangling */
#define des_set_key nettle_des_set_key
#define des_encrypt nettle_des_encrypt
#define des_decrypt nettle_des_decrypt
#define des_check_parity nettle_des_check_parity
#define des_fix_parity nettle_des_fix_parity
#define des3_set_key nettle_des3_set_key
#define des3_encrypt nettle_des3_encrypt
#define des3_decrypt nettle_des3_decrypt
#define DES_KEY_SIZE 8
#define DES_BLOCK_SIZE 8
/* Expanded key length */
#define _DES_KEY_LENGTH 32
struct des_ctx {
uint32_t key[_DES_KEY_LENGTH];
};
/* Returns 1 for good keys and 0 for weak keys. */
int
des_set_key(struct des_ctx *ctx, const uint8_t * key);
void
des_encrypt(const struct des_ctx *ctx,
unsigned length, uint8_t * dst, const uint8_t * src);
void
des_decrypt(const struct des_ctx *ctx,
unsigned length, uint8_t * dst, const uint8_t * src);
int
des_check_parity(unsigned length, const uint8_t * key);
void
des_fix_parity(unsigned length, uint8_t * dst,
const uint8_t * src);
#define DES3_KEY_SIZE 24
#define DES3_BLOCK_SIZE DES_BLOCK_SIZE
struct des3_ctx {
struct des_ctx des[3];
};
/* Returns 1 for good keys and 0 for weak keys. */
int
des3_set_key(struct des3_ctx *ctx, const uint8_t * key);
void
des3_encrypt(const struct des3_ctx *ctx,
unsigned length, uint8_t * dst, const uint8_t * src);
void
des3_decrypt(const struct des3_ctx *ctx,
unsigned length, uint8_t * dst, const uint8_t * src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_DES_H_INCLUDED */

View file

@ -0,0 +1,294 @@
/* dsa.h
*
* The DSA publickey algorithm.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_DSA_H_INCLUDED
#define NETTLE_DSA_H_INCLUDED
#include <gmp.h>
#include "nettle-types.h"
#include "sha1.h"
#include "sha2.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define dsa_public_key_init nettle_dsa_public_key_init
#define dsa_public_key_clear nettle_dsa_public_key_clear
#define dsa_private_key_init nettle_dsa_private_key_init
#define dsa_private_key_clear nettle_dsa_private_key_clear
#define dsa_signature_init nettle_dsa_signature_init
#define dsa_signature_clear nettle_dsa_signature_clear
#define dsa_sha1_sign nettle_dsa_sha1_sign
#define dsa_sha1_verify nettle_dsa_sha1_verify
#define dsa_sha256_sign nettle_dsa_sha256_sign
#define dsa_sha256_verify nettle_dsa_sha256_verify
#define dsa_sha1_sign_digest nettle_dsa_sha1_sign_digest
#define dsa_sha1_verify_digest nettle_dsa_sha1_verify_digest
#define dsa_sha256_sign_digest nettle_dsa_sha256_sign_digest
#define dsa_sha256_verify_digest nettle_dsa_sha256_verify_digest
#define dsa_generate_keypair nettle_dsa_generate_keypair
#define dsa_signature_from_sexp nettle_dsa_signature_from_sexp
#define dsa_keypair_to_sexp nettle_dsa_keypair_to_sexp
#define dsa_keypair_from_sexp_alist nettle_dsa_keypair_from_sexp_alist
#define dsa_sha1_keypair_from_sexp nettle_dsa_sha1_keypair_from_sexp
#define dsa_sha256_keypair_from_sexp nettle_dsa_sha256_keypair_from_sexp
#define dsa_params_from_der_iterator nettle_dsa_params_from_der_iterator
#define dsa_public_key_from_der_iterator nettle_dsa_public_key_from_der_iterator
#define dsa_openssl_private_key_from_der_iterator nettle_dsa_openssl_private_key_from_der_iterator
#define dsa_openssl_private_key_from_der nettle_openssl_provate_key_from_der
#define _dsa_sign _nettle_dsa_sign
#define _dsa_verify _nettle_dsa_verify
#define DSA_SHA1_MIN_P_BITS 512
#define DSA_SHA1_Q_OCTETS 20
#define DSA_SHA1_Q_BITS 160
#define DSA_SHA256_MIN_P_BITS 1024
#define DSA_SHA256_Q_OCTETS 32
#define DSA_SHA256_Q_BITS 256
struct dsa_public_key {
/* Modulo */
mpz_t p;
/* Group order */
mpz_t q;
/* Generator */
mpz_t g;
/* Public value */
mpz_t y;
};
struct dsa_private_key {
/* Unlike an rsa public key, private key operations will need both
* the private and the public information. */
mpz_t x;
};
struct dsa_signature {
mpz_t r;
mpz_t s;
};
/* Signing a message works as follows:
*
* Store the private key in a dsa_private_key struct.
*
* Initialize a hashing context, by callling
* sha1_init
*
* Hash the message by calling
* sha1_update
*
* Create the signature by calling
* dsa_sha1_sign
*
* The signature is represented as a struct dsa_signature. This call also
* resets the hashing context.
*
* When done with the key and signature, don't forget to call
* dsa_signature_clear.
*/
/* Calls mpz_init to initialize bignum storage. */
void
dsa_public_key_init(struct dsa_public_key *key);
/* Calls mpz_clear to deallocate bignum storage. */
void
dsa_public_key_clear(struct dsa_public_key *key);
/* Calls mpz_init to initialize bignum storage. */
void
dsa_private_key_init(struct dsa_private_key *key);
/* Calls mpz_clear to deallocate bignum storage. */
void
dsa_private_key_clear(struct dsa_private_key *key);
/* Calls mpz_init to initialize bignum storage. */
void
dsa_signature_init(struct dsa_signature *signature);
/* Calls mpz_clear to deallocate bignum storage. */
void
dsa_signature_clear(struct dsa_signature *signature);
int
dsa_sha1_sign(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx, nettle_random_func * random,
struct sha1_ctx *hash,
struct dsa_signature *signature);
int
dsa_sha256_sign(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx, nettle_random_func * random,
struct sha256_ctx *hash,
struct dsa_signature *signature);
int
dsa_sha1_verify(const struct dsa_public_key *key,
struct sha1_ctx *hash,
const struct dsa_signature *signature);
int
dsa_sha256_verify(const struct dsa_public_key *key,
struct sha256_ctx *hash,
const struct dsa_signature *signature);
int
dsa_sha1_sign_digest(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx,
nettle_random_func * random,
const uint8_t * digest,
struct dsa_signature *signature);
int
dsa_sha256_sign_digest(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx,
nettle_random_func * random,
const uint8_t * digest,
struct dsa_signature *signature);
int
dsa_sha1_verify_digest(const struct dsa_public_key *key,
const uint8_t * digest,
const struct dsa_signature *signature);
int
dsa_sha256_verify_digest(const struct dsa_public_key *key,
const uint8_t * digest,
const struct dsa_signature *signature);
/* Key generation */
int
dsa_generate_keypair(struct dsa_public_key *pub,
struct dsa_private_key *key,
void *random_ctx,
nettle_random_func * random,
void *progress_ctx,
nettle_progress_func * progress,
unsigned p_bits, unsigned q_bits);
/* Keys in sexp form. */
struct nettle_buffer;
/* Generates a public-key expression if PRIV is NULL .*/
int
dsa_keypair_to_sexp(struct nettle_buffer *buffer, const char *algorithm_name, /* NULL means "dsa" */
const struct dsa_public_key *pub,
const struct dsa_private_key *priv);
struct sexp_iterator;
int
dsa_signature_from_sexp(struct dsa_signature *rs,
struct sexp_iterator *i, unsigned q_bits);
int
dsa_keypair_from_sexp_alist(struct dsa_public_key *pub,
struct dsa_private_key *priv,
unsigned p_max_bits,
unsigned q_bits,
struct sexp_iterator *i);
/* If PRIV is NULL, expect a public-key expression. If PUB is NULL,
* expect a private key expression and ignore the parts not needed for
* the public key. */
/* Keys must be initialized before calling this function, as usual. */
int
dsa_sha1_keypair_from_sexp(struct dsa_public_key *pub,
struct dsa_private_key *priv,
unsigned p_max_bits,
unsigned length, const uint8_t * expr);
int
dsa_sha256_keypair_from_sexp(struct dsa_public_key *pub,
struct dsa_private_key *priv,
unsigned p_max_bits,
unsigned length,
const uint8_t * expr);
/* Keys in X.509 andd OpenSSL format. */
struct asn1_der_iterator;
int
dsa_params_from_der_iterator(struct dsa_public_key *pub,
unsigned p_max_bits,
struct asn1_der_iterator *i);
int
dsa_public_key_from_der_iterator(struct dsa_public_key *pub,
unsigned p_max_bits,
struct asn1_der_iterator *i);
int
dsa_openssl_private_key_from_der_iterator(struct dsa_public_key
*pub,
struct dsa_private_key
*priv,
unsigned p_max_bits,
struct asn1_der_iterator
*i);
int
dsa_openssl_private_key_from_der(struct dsa_public_key *pub,
struct dsa_private_key *priv,
unsigned p_max_bits,
unsigned length,
const uint8_t * data);
/* Internal functions. */
int
_dsa_sign(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx, nettle_random_func * random,
unsigned digest_size,
const uint8_t * digest,
struct dsa_signature *signature);
int
_dsa_verify(const struct dsa_public_key *key,
unsigned digest_size,
const uint8_t * digest,
const struct dsa_signature *signature);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_DSA_H_INCLUDED */

View file

@ -0,0 +1,44 @@
/* ecc-curve.h */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2013 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
#ifndef NETTLE_ECC_CURVE_H_INCLUDED
#define NETTLE_ECC_CURVE_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
/* The contets of this struct is internal. */
struct ecc_curve;
extern const struct ecc_curve nettle_secp_192r1;
extern const struct ecc_curve nettle_secp_224r1;
extern const struct ecc_curve nettle_secp_256r1;
extern const struct ecc_curve nettle_secp_384r1;
extern const struct ecc_curve nettle_secp_521r1;
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ECC_CURVE_H_INCLUDED */

View file

@ -0,0 +1,247 @@
/* ecc.h */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2013 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
#ifndef NETTLE_ECC_H_INCLUDED
#define NETTLE_ECC_H_INCLUDED
#include <gmp.h>
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define ecc_point_init nettle_ecc_point_init
#define ecc_point_clear nettle_ecc_point_clear
#define ecc_point_set nettle_ecc_point_set
#define ecc_point_get nettle_ecc_point_get
#define ecc_point_mul nettle_ecc_point_mul
#define ecc_point_mul_g nettle_ecc_point_mul_g
#define ecc_scalar_init nettle_ecc_scalar_init
#define ecc_scalar_clear nettle_ecc_scalar_clear
#define ecc_scalar_set nettle_ecc_scalar_set
#define ecc_scalar_get nettle_ecc_scalar_get
#define ecc_scalar_random nettle_ecc_scalar_random
#define ecc_point_mul nettle_ecc_point_mul
#define ecc_size nettle_ecc_size
#define ecc_size_a nettle_ecc_size_a
#define ecc_size_j nettle_ecc_size_j
#define ecc_a_to_a_itch nettle_ecc_a_to_a_itch
#define ecc_a_to_a nettle_ecc_a_to_a
#define ecc_a_to_j nettle_ecc_a_to_j
#define ecc_j_to_a_itch nettle_ecc_j_to_a_itch
#define ecc_j_to_a nettle_ecc_j_to_a
#define ecc_dup_ja_itch nettle_ecc_dup_ja_itch
#define ecc_dup_ja nettle_ecc_dup_ja
#define ecc_dup_jj_itch nettle_ecc_dup_jj_itch
#define ecc_dup_jj nettle_ecc_dup_jj
#define ecc_add_jja_itch nettle_ecc_add_jja_itch
#define ecc_add_jja nettle_ecc_add_jja
#define ecc_add_jjj_itch nettle_ecc_add_jjj_itch
#define ecc_add_jjj nettle_ecc_add_jjj
#define ecc_mul_g_itch nettle_ecc_mul_g_itch
#define ecc_mul_g nettle_ecc_mul_g
#define ecc_mul_a_itch nettle_ecc_mul_a_itch
#define ecc_mul_a nettle_ecc_mul_a
struct ecc_curve;
/* High level interface, for ECDSA, DH, etc */
/* Represents a point on the ECC curve */
struct ecc_point {
const struct ecc_curve *ecc;
/* Allocated using the same allocation function as GMP. */
mp_limb_t *p;
};
/* Represents a non-zero scalar, an element of Z_q^*, where q is the
group order of the curve. */
struct ecc_scalar {
const struct ecc_curve *ecc;
/* Allocated using the same allocation function as GMP. */
mp_limb_t *p;
};
void
ecc_point_init(struct ecc_point *p, const struct ecc_curve *ecc);
void
ecc_point_clear(struct ecc_point *p);
/* Fails and returns zero if the point is not on the curve. */
int
ecc_point_set(struct ecc_point *p, const mpz_t x, const mpz_t y);
void
ecc_point_get(const struct ecc_point *p, mpz_t x, mpz_t y);
void
ecc_scalar_init(struct ecc_scalar *s,
const struct ecc_curve *ecc);
void
ecc_scalar_clear(struct ecc_scalar *s);
/* Fails and returns zero if the scalar is not in the proper range. */
int
ecc_scalar_set(struct ecc_scalar *s, const mpz_t z);
void
ecc_scalar_get(const struct ecc_scalar *s, mpz_t z);
/* Generates a random scalar, suitable as an ECDSA private key or a
ECDH exponent. */
void
ecc_scalar_random(struct ecc_scalar *s,
void *random_ctx, nettle_random_func * random);
/* Computes r = n p */
void
ecc_point_mul(struct ecc_point *r, const struct ecc_scalar *n,
const struct ecc_point *p);
/* Computes r = n g */
void
ecc_point_mul_g(struct ecc_point *r, const struct ecc_scalar *n);
/* Low-level interface */
/* Points on a curve are represented as arrays of mp_limb_t. For some
curves, point coordinates are represented in montgomery form. We
use either affine coordinates x,y, or Jacobian coordinates X, Y, Z,
where x = X/Z^2 and y = X/Z^2.
Since we use additive notation for the groups, the infinity point
on the curve is denoted 0. The infinity point can be represented
with x = y = 0 in affine coordinates, and Z = 0 in Jacobian
coordinates. However, note that most of the ECC functions do *not*
support infinity as an input or output.
*/
/* FIXME: Also provided some compile time constants? */
/* Returns the size of a single coordinate. */
mp_size_t ecc_size(const struct ecc_curve *ecc);
/* Size of a point, using affine coordinates x, y. */
mp_size_t ecc_size_a(const struct ecc_curve *ecc);
/* Size of a point, using jacobian coordinates X, Y and Z. */
mp_size_t ecc_size_j(const struct ecc_curve *ecc);
/* FIXME: Rename the low-level (and side-channel silent) functions to
_ecc_*, and provide public ecc_* functions which handle the
infinity points properly? */
/* Converts the affine coordinates of a point into montgomery form, if
used for this curve. */
mp_size_t ecc_a_to_a_itch(const struct ecc_curve *ecc);
void
ecc_a_to_a(const struct ecc_curve *ecc,
mp_limb_t * r, const mp_limb_t * p,
mp_limb_t * scratch);
/* Converts a point P in affine coordinates into a point R in jacobian
coordinates. If INITIAL is non-zero, and the curve uses montgomery
coordinates, also convert coordinates to montgomery form. */
void
ecc_a_to_j(const struct ecc_curve *ecc,
int initial, mp_limb_t * r, const mp_limb_t * p);
/* Converts a point P in jacobian coordinates into a point R in affine
coordinates. If FLAGS has bit 0 set, and the curve uses montgomery
coordinates, also undo the montgomery conversion. If flags has bit
1 set, produce x coordinate only. */
mp_size_t ecc_j_to_a_itch(const struct ecc_curve *ecc);
void
ecc_j_to_a(const struct ecc_curve *ecc,
int flags,
mp_limb_t * r, const mp_limb_t * p,
mp_limb_t * scratch);
/* Group operations */
/* Point doubling, with jacobian output and affine input. Corner
cases: Correctly sets R = 0 (r_Z = 0) if p = 0 or 2p = 0. */
mp_size_t ecc_dup_ja_itch(const struct ecc_curve *ecc);
void
ecc_dup_ja(const struct ecc_curve *ecc,
mp_limb_t * r, const mp_limb_t * p,
mp_limb_t * scratch);
/* Point doubling, with jacobian input and output. Corner cases:
Correctly sets R = 0 (r_Z = 0) if p = 0 or 2p = 0. */
mp_size_t ecc_dup_jj_itch(const struct ecc_curve *ecc);
void
ecc_dup_jj(const struct ecc_curve *ecc,
mp_limb_t * r, const mp_limb_t * p,
mp_limb_t * scratch);
/* Point addition, with jacobian output, one jacobian input and one
affine input. Corner cases: Fails for the cases
P = Q != 0 Duplication of non-zero point
P = 0, Q != 0 or P != 0, Q = 0 One input zero
Correctly gives R = 0 if P = Q = 0 or P = -Q. */
mp_size_t ecc_add_jja_itch(const struct ecc_curve *ecc);
void
ecc_add_jja(const struct ecc_curve *ecc,
mp_limb_t * r, const mp_limb_t * p,
const mp_limb_t * q, mp_limb_t * scratch);
/* Point addition with Jacobian input and output. */
mp_size_t ecc_add_jjj_itch(const struct ecc_curve *ecc);
void
ecc_add_jjj(const struct ecc_curve *ecc,
mp_limb_t * r, const mp_limb_t * p,
const mp_limb_t * q, mp_limb_t * scratch);
/* Computes N * the group generator. N is an array of ecc_size()
limbs. It must be in the range 0 < N < group order, then R != 0,
and the algorithm can work without any intermediate values getting
to zero. */
mp_size_t ecc_mul_g_itch(const struct ecc_curve *ecc);
void
ecc_mul_g(const struct ecc_curve *ecc, mp_limb_t * r,
const mp_limb_t * np, mp_limb_t * scratch);
/* Computes N * P. The scalar N is the same as for ecc_mul_g. P is a
non-zero point on the curve, in affine coordinates. Pass a non-zero
INITIAL if the point coordinates have not previously been converted
to Montgomery representation. Output R is a non-zero point, in
Jacobian coordinates. */
mp_size_t ecc_mul_a_itch(const struct ecc_curve *ecc);
void
ecc_mul_a(const struct ecc_curve *ecc,
int initial, mp_limb_t * r,
const mp_limb_t * np, const mp_limb_t * p,
mp_limb_t * scratch);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ECC_H_INCLUDED */

View file

@ -0,0 +1,90 @@
/* ecdsa.h */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2013 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
#ifndef NETTLE_ECDSA_H_INCLUDED
#define NETTLE_ECDSA_H_INCLUDED
#include "ecc.h"
#include "dsa.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define ecdsa_sign nettle_ecdsa_sign
#define ecdsa_verify nettle_ecdsa_verify
#define ecdsa_generate_keypair nettle_ecdsa_generate_keypair
#define ecc_ecdsa_sign nettle_ecc_ecdsa_sign
#define ecc_ecdsa_sign_itch nettle_ecc_ecdsa_sign_itch
#define ecc_ecdsa_verify nettle_ecc_ecdsa_verify
#define ecc_ecdsa_verify_itch nettle_ecc_ecdsa_verify_itch
/* High level ECDSA functions.
*
* A public key is represented as a struct ecc_point, and a private
* key as a struct ecc_scalar. FIXME: Introduce some aliases? */
void
ecdsa_sign(const struct ecc_scalar *key,
void *random_ctx, nettle_random_func * random,
unsigned digest_length,
const uint8_t * digest,
struct dsa_signature *signature);
int
ecdsa_verify(const struct ecc_point *pub,
unsigned length, const uint8_t * digest,
const struct dsa_signature *signature);
void
ecdsa_generate_keypair(struct ecc_point *pub,
struct ecc_scalar *key,
void *random_ctx,
nettle_random_func * random);
/* Low-level ECDSA functions. */
mp_size_t ecc_ecdsa_sign_itch(const struct ecc_curve *ecc);
void
ecc_ecdsa_sign(const struct ecc_curve *ecc, const mp_limb_t * zp,
/* Random nonce, must be invertible mod ecc group
order. */
const mp_limb_t * kp,
unsigned length, const uint8_t * digest,
mp_limb_t * rp, mp_limb_t * sp,
mp_limb_t * scratch);
mp_size_t ecc_ecdsa_verify_itch(const struct ecc_curve *ecc);
int
ecc_ecdsa_verify(const struct ecc_curve *ecc, const mp_limb_t * pp, /* Public key */
unsigned length, const uint8_t * digest,
const mp_limb_t * rp, const mp_limb_t * sp,
mp_limb_t * scratch);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ECDSA_H_INCLUDED */

View file

@ -0,0 +1,186 @@
/* gcm.h
*
* Galois counter mode, specified by NIST,
* http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf
*
*/
/* NOTE: Tentative interface, subject to change. No effort will be
made to avoid incompatible changes. */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2011 Niels Möller
* Copyright (C) 2011 Katholieke Universiteit Leuven
*
* Contributed by Nikos Mavrogiannopoulos
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_GCM_H_INCLUDED
#define NETTLE_GCM_H_INCLUDED
#include "aes.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define gcm_set_key nettle_gcm_set_key
#define gcm_set_iv nettle_gcm_set_iv
#define gcm_update nettle_gcm_update
#define gcm_encrypt nettle_gcm_encrypt
#define gcm_decrypt nettle_gcm_decrypt
#define gcm_digest nettle_gcm_digest
#define gcm_aes_set_key nettle_gcm_aes_set_key
#define gcm_aes_set_iv nettle_gcm_aes_set_iv
#define gcm_aes_update nettle_gcm_aes_update
#define gcm_aes_encrypt nettle_gcm_aes_encrypt
#define gcm_aes_decrypt nettle_gcm_aes_decrypt
#define gcm_aes_digest nettle_gcm_aes_digest
#define GCM_BLOCK_SIZE 16
#define GCM_IV_SIZE (GCM_BLOCK_SIZE - 4)
#define GCM_TABLE_BITS 8
/* To make sure that we have proper alignment. */
union gcm_block {
uint8_t b[GCM_BLOCK_SIZE];
unsigned long w[GCM_BLOCK_SIZE / sizeof(unsigned long)];
};
/* Hashing subkey */
struct gcm_key {
union gcm_block h[1 << GCM_TABLE_BITS];
};
/* Per-message state, depending on the iv */
struct gcm_ctx {
/* Original counter block */
union gcm_block iv;
/* Updated for each block. */
union gcm_block ctr;
/* Hashing state */
union gcm_block x;
uint64_t auth_size;
uint64_t data_size;
};
/* FIXME: Should use const for the cipher context. Then needs const for
nettle_crypt_func, which also rules out using that abstraction for
arcfour. */
void
gcm_set_key(struct gcm_key *key,
void *cipher, nettle_crypt_func * f);
void
gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key,
unsigned length, const uint8_t * iv);
void
gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key,
unsigned length, const uint8_t * data);
void
gcm_encrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
void *cipher, nettle_crypt_func * f,
unsigned length, uint8_t * dst, const uint8_t * src);
void
gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
void *cipher, nettle_crypt_func * f,
unsigned length, uint8_t * dst, const uint8_t * src);
void
gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key,
void *cipher, nettle_crypt_func * f,
unsigned length, uint8_t * digest);
/* Convenience macrology (not sure how useful it is) */
/* All-in-one context, with cipher, hash subkey, and message state. */
#define GCM_CTX(type) \
{ type cipher; struct gcm_key key; struct gcm_ctx gcm; }
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
#define GCM_SET_KEY(ctx, set_key, encrypt, length, data) \
do { \
(set_key)(&(ctx)->cipher, (length), (data)); \
if (0) (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0); \
gcm_set_key(&(ctx)->key, &(ctx)->cipher, \
(nettle_crypt_func *) (encrypt)); \
} while (0)
#define GCM_SET_IV(ctx, length, data) \
gcm_set_iv(&(ctx)->gcm, &(ctx)->key, (length), (data))
#define GCM_UPDATE(ctx, length, data) \
gcm_update(&(ctx)->gcm, &(ctx)->key, (length), (data))
#define GCM_ENCRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0) \
: gcm_encrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
(nettle_crypt_func *) (encrypt), \
(length), (dst), (src)))
#define GCM_DECRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0) \
: gcm_decrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
(nettle_crypt_func *) (encrypt), \
(length), (dst), (src)))
#define GCM_DIGEST(ctx, encrypt, length, digest) \
(0 ? (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0) \
: gcm_digest(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
(nettle_crypt_func *) (encrypt), \
(length), (digest)))
struct gcm_aes_ctx GCM_CTX(struct aes_ctx);
void
gcm_aes_set_key(struct gcm_aes_ctx *ctx,
unsigned length, const uint8_t * key);
void
gcm_aes_set_iv(struct gcm_aes_ctx *ctx,
unsigned length, const uint8_t * iv);
void
gcm_aes_update(struct gcm_aes_ctx *ctx,
unsigned length, const uint8_t * data);
void
gcm_aes_encrypt(struct gcm_aes_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
void
gcm_aes_decrypt(struct gcm_aes_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
void
gcm_aes_digest(struct gcm_aes_ctx *ctx, unsigned length,
uint8_t * digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_GCM_H_INCLUDED */

View file

@ -0,0 +1,86 @@
/* gosthash94.h
*
* The GOST R 34.11-94 hash function, described in RFC 5831.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2012 Nikos Mavrogiannopoulos, Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/* Interface based on rhash gost.h. */
/* Copyright: 2009-2012 Aleksey Kravchenko <rhash.admin@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Ported to nettle by Nikos Mavrogiannopoulos.
*/
#ifndef NETTLE_GOSTHASH94_H_INCLUDED
#define NETTLE_GOSTHASH94_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
#define gosthash94_init nettle_gosthash94_init
#define gosthash94_update nettle_gosthash94_update
#define gosthash94_digest nettle_gosthash94_digest
#define GOSTHASH94_DATA_SIZE 32
#define GOSTHASH94_DIGEST_SIZE 32
struct gosthash94_ctx {
uint32_t hash[8]; /* algorithm 256-bit state */
uint32_t sum[8]; /* sum of processed message blocks */
uint8_t message[GOSTHASH94_DATA_SIZE]; /* 256-bit buffer for leftovers */
uint64_t length; /* number of processed bytes */
};
void gosthash94_init(struct gosthash94_ctx *ctx);
void gosthash94_update(struct gosthash94_ctx *ctx,
unsigned length, const uint8_t * msg);
void gosthash94_digest(struct gosthash94_ctx *ctx,
unsigned length, uint8_t * result);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_GOSTHASH94_H_INCLUDED */

View file

@ -0,0 +1,201 @@
/* hmac.h
*
* HMAC message authentication code (RFC-2104).
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001, 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_HMAC_H_INCLUDED
#define NETTLE_HMAC_H_INCLUDED
#include "nettle-meta.h"
#include "md5.h"
#include "ripemd160.h"
#include "sha1.h"
#include "sha2.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Namespace mangling */
#define hmac_set_key nettle_hmac_set_key
#define hmac_update nettle_hmac_update
#define hmac_digest nettle_hmac_digest
#define hmac_md5_set_key nettle_hmac_md5_set_key
#define hmac_md5_update nettle_hmac_md5_update
#define hmac_md5_digest nettle_hmac_md5_digest
#define hmac_ripemd160_set_key nettle_hmac_ripemd160_set_key
#define hmac_ripemd160_update nettle_hmac_ripemd160_update
#define hmac_ripemd160_digest nettle_hmac_ripemd160_digest
#define hmac_sha1_set_key nettle_hmac_sha1_set_key
#define hmac_sha1_update nettle_hmac_sha1_update
#define hmac_sha1_digest nettle_hmac_sha1_digest
#define hmac_sha224_set_key nettle_hmac_sha224_set_key
#define hmac_sha224_digest nettle_hmac_sha224_digest
#define hmac_sha256_set_key nettle_hmac_sha256_set_key
#define hmac_sha256_update nettle_hmac_sha256_update
#define hmac_sha256_digest nettle_hmac_sha256_digest
#define hmac_sha384_set_key nettle_hmac_sha384_set_key
#define hmac_sha384_digest nettle_hmac_sha384_digest
#define hmac_sha512_set_key nettle_hmac_sha512_set_key
#define hmac_sha512_update nettle_hmac_sha512_update
#define hmac_sha512_digest nettle_hmac_sha512_digest
void
hmac_set_key(void *outer, void *inner, void *state,
const struct nettle_hash *hash,
unsigned length, const uint8_t * key);
/* This function is not strictly needed, it's s just the same as the
* hash update function. */
void
hmac_update(void *state,
const struct nettle_hash *hash,
unsigned length, const uint8_t * data);
void
hmac_digest(const void *outer, const void *inner, void *state,
const struct nettle_hash *hash,
unsigned length, uint8_t * digest);
#define HMAC_CTX(type) \
{ type outer; type inner; type state; }
#define HMAC_SET_KEY(ctx, hash, length, key) \
hmac_set_key( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
(hash), (length), (key) )
#define HMAC_DIGEST(ctx, hash, length, digest) \
hmac_digest( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
(hash), (length), (digest) )
/* HMAC using specific hash functions */
/* hmac-md5 */
struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
void
hmac_md5_set_key(struct hmac_md5_ctx *ctx,
unsigned key_length, const uint8_t * key);
void
hmac_md5_update(struct hmac_md5_ctx *ctx,
unsigned length, const uint8_t * data);
void
hmac_md5_digest(struct hmac_md5_ctx *ctx,
unsigned length, uint8_t * digest);
/* hmac-ripemd160 */
struct hmac_ripemd160_ctx HMAC_CTX(struct ripemd160_ctx);
void
hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx,
unsigned key_length, const uint8_t * key);
void
hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx,
unsigned length, const uint8_t * data);
void
hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx,
unsigned length, uint8_t * digest);
/* hmac-sha1 */
struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
void
hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
unsigned key_length, const uint8_t * key);
void
hmac_sha1_update(struct hmac_sha1_ctx *ctx,
unsigned length, const uint8_t * data);
void
hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
unsigned length, uint8_t * digest);
/* hmac-sha256 */
struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx);
void
hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
unsigned key_length, const uint8_t * key);
void
hmac_sha256_update(struct hmac_sha256_ctx *ctx,
unsigned length, const uint8_t * data);
void
hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
unsigned length, uint8_t * digest);
/* hmac-sha224 */
#define hmac_sha224_ctx hmac_sha256_ctx
void
hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
unsigned key_length, const uint8_t * key);
#define hmac_sha224_update nettle_hmac_sha256_update
void
hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
unsigned length, uint8_t * digest);
/* hmac-sha512 */
struct hmac_sha512_ctx HMAC_CTX(struct sha512_ctx);
void
hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
unsigned key_length, const uint8_t * key);
void
hmac_sha512_update(struct hmac_sha512_ctx *ctx,
unsigned length, const uint8_t * data);
void
hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
unsigned length, uint8_t * digest);
/* hmac-sha384 */
#define hmac_sha384_ctx hmac_sha512_ctx
void
hmac_sha384_set_key(struct hmac_sha512_ctx *ctx,
unsigned key_length, const uint8_t * key);
#define hmac_sha384_update nettle_hmac_sha512_update
void
hmac_sha384_digest(struct hmac_sha512_ctx *ctx,
unsigned length, uint8_t * digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_HMAC_H_INCLUDED */

View file

@ -0,0 +1,72 @@
/* knuth-lfib.h
*
* A "lagged fibonacci" pseudorandomness generator.
*
* Described in Knuth, TAOCP, 3.6
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/* NOTE: This generator is totally inappropriate for cryptographic
* applications. It is useful for generating deterministic but
* random-looking test data, and is used by the Nettle testsuite. */
#ifndef NETTLE_KNUTH_LFIB_H_INCLUDED
#define NETTLE_KNUTH_LFIB_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Namespace mangling */
#define knuth_lfib_init nettle_knuth_lfib_init
#define knuth_lfib_get nettle_knuth_lfib_get
#define knuth_lfib_get_array nettle_knuth_lfib_get_array
#define knuth_lfib_random nettle_knuth_lfib_random
#define _KNUTH_LFIB_KK 100
struct knuth_lfib_ctx {
uint32_t x[_KNUTH_LFIB_KK];
unsigned index;
};
void
knuth_lfib_init(struct knuth_lfib_ctx *ctx, uint32_t seed);
/* Get's a single number in the range 0 ... 2^30-1 */
uint32_t knuth_lfib_get(struct knuth_lfib_ctx *ctx);
/* Get an array of numbers */
void
knuth_lfib_get_array(struct knuth_lfib_ctx *ctx,
unsigned n, uint32_t * a);
/* Get an array of octets. */
void
knuth_lfib_random(struct knuth_lfib_ctx *ctx,
unsigned n, uint8_t * dst);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_KNUTH_LFIB_H_INCLUDED */

View file

@ -0,0 +1,238 @@
/* macros.h
*
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001, 2010 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_MACROS_H_INCLUDED
#define NETTLE_MACROS_H_INCLUDED
/* Reads a 64-bit integer, in network, big-endian, byte order */
#define READ_UINT64(p) \
( (((uint64_t) (p)[0]) << 56) \
| (((uint64_t) (p)[1]) << 48) \
| (((uint64_t) (p)[2]) << 40) \
| (((uint64_t) (p)[3]) << 32) \
| (((uint64_t) (p)[4]) << 24) \
| (((uint64_t) (p)[5]) << 16) \
| (((uint64_t) (p)[6]) << 8) \
| ((uint64_t) (p)[7]))
#define WRITE_UINT64(p, i) \
do { \
(p)[0] = ((i) >> 56) & 0xff; \
(p)[1] = ((i) >> 48) & 0xff; \
(p)[2] = ((i) >> 40) & 0xff; \
(p)[3] = ((i) >> 32) & 0xff; \
(p)[4] = ((i) >> 24) & 0xff; \
(p)[5] = ((i) >> 16) & 0xff; \
(p)[6] = ((i) >> 8) & 0xff; \
(p)[7] = (i) & 0xff; \
} while(0)
/* Reads a 32-bit integer, in network, big-endian, byte order */
#define READ_UINT32(p) \
( (((uint32_t) (p)[0]) << 24) \
| (((uint32_t) (p)[1]) << 16) \
| (((uint32_t) (p)[2]) << 8) \
| ((uint32_t) (p)[3]))
#define WRITE_UINT32(p, i) \
do { \
(p)[0] = ((i) >> 24) & 0xff; \
(p)[1] = ((i) >> 16) & 0xff; \
(p)[2] = ((i) >> 8) & 0xff; \
(p)[3] = (i) & 0xff; \
} while(0)
/* Analogous macros, for 24 and 16 bit numbers */
#define READ_UINT24(p) \
( (((uint32_t) (p)[0]) << 16) \
| (((uint32_t) (p)[1]) << 8) \
| ((uint32_t) (p)[2]))
#define WRITE_UINT24(p, i) \
do { \
(p)[0] = ((i) >> 16) & 0xff; \
(p)[1] = ((i) >> 8) & 0xff; \
(p)[2] = (i) & 0xff; \
} while(0)
#define READ_UINT16(p) \
( (((uint32_t) (p)[0]) << 8) \
| ((uint32_t) (p)[1]))
#define WRITE_UINT16(p, i) \
do { \
(p)[0] = ((i) >> 8) & 0xff; \
(p)[1] = (i) & 0xff; \
} while(0)
/* And the other, little-endian, byteorder */
#define LE_READ_UINT64(p) \
( (((uint64_t) (p)[7]) << 56) \
| (((uint64_t) (p)[6]) << 48) \
| (((uint64_t) (p)[5]) << 40) \
| (((uint64_t) (p)[4]) << 32) \
| (((uint64_t) (p)[3]) << 24) \
| (((uint64_t) (p)[2]) << 16) \
| (((uint64_t) (p)[1]) << 8) \
| ((uint64_t) (p)[0]))
#define LE_WRITE_UINT64(p, i) \
do { \
(p)[7] = ((i) >> 56) & 0xff; \
(p)[6] = ((i) >> 48) & 0xff; \
(p)[5] = ((i) >> 40) & 0xff; \
(p)[4] = ((i) >> 32) & 0xff; \
(p)[3] = ((i) >> 24) & 0xff; \
(p)[2] = ((i) >> 16) & 0xff; \
(p)[1] = ((i) >> 8) & 0xff; \
(p)[0] = (i) & 0xff; \
} while (0)
#define LE_READ_UINT32(p) \
( (((uint32_t) (p)[3]) << 24) \
| (((uint32_t) (p)[2]) << 16) \
| (((uint32_t) (p)[1]) << 8) \
| ((uint32_t) (p)[0]))
#define LE_WRITE_UINT32(p, i) \
do { \
(p)[3] = ((i) >> 24) & 0xff; \
(p)[2] = ((i) >> 16) & 0xff; \
(p)[1] = ((i) >> 8) & 0xff; \
(p)[0] = (i) & 0xff; \
} while(0)
/* Analogous macros, for 16 bit numbers */
#define LE_READ_UINT16(p) \
( (((uint32_t) (p)[1]) << 8) \
| ((uint32_t) (p)[0]))
#define LE_WRITE_UINT16(p, i) \
do { \
(p)[1] = ((i) >> 8) & 0xff; \
(p)[0] = (i) & 0xff; \
} while(0)
/* Macro to make it easier to loop over several blocks. */
#define FOR_BLOCKS(length, dst, src, blocksize) \
assert( !((length) % (blocksize))); \
for (; (length); ((length) -= (blocksize), \
(dst) += (blocksize), \
(src) += (blocksize)) )
#define ROTL32(n,x) (((x)<<(n)) | ((x)>>(32-(n))))
#define ROTL64(n,x) (((x)<<(n)) | ((x)>>(64-(n))))
/* Requires that size > 0 */
#define INCREMENT(size, ctr) \
do { \
unsigned increment_i = (size) - 1; \
if (++(ctr)[increment_i] == 0) \
while (increment_i > 0 \
&& ++(ctr)[--increment_i] == 0 ) \
; \
} while (0)
/* Helper macro for Merkle-Damgård hash functions. Assumes the context
structs includes the following fields:
xxx count_low, count_high; // Two word block count
uint8_t block[...]; // Buffer holding one block
unsigned int index; // Index into block
*/
/* FIXME: Should probably switch to using uint64_t for the count, but
due to alignment and byte order that may be an ABI change. */
#define MD_INCR(ctx) ((ctx)->count_high += !++(ctx)->count_low)
/* Takes the compression function f as argument. NOTE: also clobbers
length and data. */
#define MD_UPDATE(ctx, length, data, f, incr) \
do { \
if ((ctx)->index) \
{ \
/* Try to fill partial block */ \
unsigned __md_left = sizeof((ctx)->block) - (ctx)->index; \
if ((length) < __md_left) \
{ \
memcpy((ctx)->block + (ctx)->index, (data), (length)); \
(ctx)->index += (length); \
goto __md_done; /* Finished */ \
} \
else \
{ \
memcpy((ctx)->block + (ctx)->index, (data), __md_left); \
\
f((ctx), (ctx)->block); \
(incr); \
\
(data) += __md_left; \
(length) -= __md_left; \
} \
} \
while ((length) >= sizeof((ctx)->block)) \
{ \
f((ctx), (data)); \
(incr); \
\
(data) += sizeof((ctx)->block); \
(length) -= sizeof((ctx)->block); \
} \
memcpy ((ctx)->block, (data), (length)); \
(ctx)->index = (length); \
__md_done: \
; \
} while (0)
/* Pads the block to a block boundary with the bit pattern 1 0*,
leaving size octets for the length field at the end. If needed,
compresses the block and starts a new one. */
#define MD_PAD(ctx, size, f) \
do { \
unsigned __md_i; \
__md_i = (ctx)->index; \
\
/* Set the first char of padding to 0x80. This is safe since there \
is always at least one byte free */ \
\
assert(__md_i < sizeof((ctx)->block)); \
(ctx)->block[__md_i++] = 0x80; \
\
if (__md_i > (sizeof((ctx)->block) - 2*sizeof((ctx)->count_low))) \
{ /* No room for length in this block. Process it and \
pad with another one */ \
memset((ctx)->block + __md_i, 0, sizeof((ctx)->block) - __md_i); \
\
f((ctx), (ctx)->block); \
__md_i = 0; \
} \
memset((ctx)->block + __md_i, 0, \
sizeof((ctx)->block) - (size) - __md_i); \
\
} while (0)
#endif /* NETTLE_MACROS_H_INCLUDED */

View file

@ -0,0 +1,65 @@
/* md2.h
*
* The MD2 hash function, described in RFC 1319.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2003 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_MD2_H_INCLUDED
#define NETTLE_MD2_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define md2_init nettle_md2_init
#define md2_update nettle_md2_update
#define md2_digest nettle_md2_digest
#define MD2_DIGEST_SIZE 16
#define MD2_DATA_SIZE 16
struct md2_ctx {
uint8_t C[MD2_DATA_SIZE];
uint8_t X[3 * MD2_DATA_SIZE];
uint8_t block[MD2_DATA_SIZE]; /* Block buffer */
unsigned index; /* Into buffer */
};
void
md2_init(struct md2_ctx *ctx);
void
md2_update(struct md2_ctx *ctx,
unsigned length, const uint8_t * data);
void
md2_digest(struct md2_ctx *ctx,
unsigned length, uint8_t * digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MD2_H_INCLUDED */

View file

@ -0,0 +1,69 @@
/* md4.h
*
* The MD4 hash function, described in RFC 1320.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2003 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_MD4_H_INCLUDED
#define NETTLE_MD4_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define md4_init nettle_md4_init
#define md4_update nettle_md4_update
#define md4_digest nettle_md4_digest
#define MD4_DIGEST_SIZE 16
#define MD4_DATA_SIZE 64
/* Digest is kept internally as 4 32-bit words. */
#define _MD4_DIGEST_LENGTH 4
/* FIXME: Identical to md5_ctx */
struct md4_ctx {
uint32_t state[_MD4_DIGEST_LENGTH];
uint32_t count_low, count_high; /* Block count */
uint8_t block[MD4_DATA_SIZE]; /* Block buffer */
unsigned index; /* Into buffer */
};
void
md4_init(struct md4_ctx *ctx);
void
md4_update(struct md4_ctx *ctx,
unsigned length, const uint8_t * data);
void
md4_digest(struct md4_ctx *ctx,
unsigned length, uint8_t * digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MD4_H_INCLUDED */

View file

@ -0,0 +1,50 @@
/* md5-compat.h
*
* The md5 hash function, RFC 1321-style interface.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_MD5_COMPAT_H_INCLUDED
#define NETTLE_MD5_COMPAT_H_INCLUDED
#include "md5.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define MD5Init nettle_MD5Init
#define MD5Update nettle_MD5Update
#define MD5Final nettle_MD5Final
typedef struct md5_ctx MD5_CTX;
void MD5Init(MD5_CTX * ctx);
void MD5Update(MD5_CTX * ctx, const unsigned char *data,
unsigned int length);
void MD5Final(unsigned char *out, MD5_CTX * ctx);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MD5_COMPAT_H_INCLUDED */

View file

@ -0,0 +1,72 @@
/* md5.h
*
* The MD5 hash function, described in RFC 1321.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_MD5_H_INCLUDED
#define NETTLE_MD5_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define md5_init nettle_md5_init
#define md5_update nettle_md5_update
#define md5_digest nettle_md5_digest
#define MD5_DIGEST_SIZE 16
#define MD5_DATA_SIZE 64
/* Digest is kept internally as 4 32-bit words. */
#define _MD5_DIGEST_LENGTH 4
struct md5_ctx {
uint32_t state[_MD5_DIGEST_LENGTH];
uint32_t count_low, count_high; /* Block count */
uint8_t block[MD5_DATA_SIZE]; /* Block buffer */
unsigned index; /* Into buffer */
};
void
md5_init(struct md5_ctx *ctx);
void
md5_update(struct md5_ctx *ctx,
unsigned length, const uint8_t * data);
void
md5_digest(struct md5_ctx *ctx,
unsigned length, uint8_t * digest);
/* Internal compression function. STATE points to 4 uint32_t words,
and DATA points to 64 bytes of input data, possibly unaligned. */
void
_nettle_md5_compress(uint32_t * state, const uint8_t * data);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MD5_H_INCLUDED */

View file

@ -0,0 +1,22 @@
/* memxor.h
*
*/
#ifndef NETTLE_MEMXOR_H_INCLUDED
#define NETTLE_MEMXOR_H_INCLUDED
#include <stdlib.h>
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
uint8_t *memxor(uint8_t * dst, const uint8_t * src, size_t n);
uint8_t *memxor3(uint8_t * dst, const uint8_t * a,
const uint8_t * b, size_t n);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MEMXOR_H_INCLUDED */

View file

@ -0,0 +1,228 @@
/* nettle-meta.h
*
* Information about algorithms.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_META_H_INCLUDED
#define NETTLE_META_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
struct nettle_cipher {
const char *name;
unsigned context_size;
/* Zero for stream ciphers */
unsigned block_size;
/* Suggested key size; other sizes are sometimes possible. */
unsigned key_size;
nettle_set_key_func *set_encrypt_key;
nettle_set_key_func *set_decrypt_key;
nettle_crypt_func *encrypt;
nettle_crypt_func *decrypt;
};
#define _NETTLE_CIPHER(name, NAME, key_size) { \
#name #key_size, \
sizeof(struct name##_ctx), \
NAME##_BLOCK_SIZE, \
key_size / 8, \
(nettle_set_key_func *) name##_set_key, \
(nettle_set_key_func *) name##_set_key, \
(nettle_crypt_func *) name##_encrypt, \
(nettle_crypt_func *) name##_decrypt, \
}
#define _NETTLE_CIPHER_SEP(name, NAME, key_size) { \
#name #key_size, \
sizeof(struct name##_ctx), \
NAME##_BLOCK_SIZE, \
key_size / 8, \
(nettle_set_key_func *) name##_set_encrypt_key, \
(nettle_set_key_func *) name##_set_decrypt_key, \
(nettle_crypt_func *) name##_encrypt, \
(nettle_crypt_func *) name##_decrypt, \
}
#define _NETTLE_CIPHER_SEP_SET_KEY(name, NAME, key_size) {\
#name #key_size, \
sizeof(struct name##_ctx), \
NAME##_BLOCK_SIZE, \
key_size / 8, \
(nettle_set_key_func *) name##_set_encrypt_key, \
(nettle_set_key_func *) name##_set_decrypt_key, \
(nettle_crypt_func *) name##_crypt, \
(nettle_crypt_func *) name##_crypt, \
}
#define _NETTLE_CIPHER_FIX(name, NAME) { \
#name, \
sizeof(struct name##_ctx), \
NAME##_BLOCK_SIZE, \
NAME##_KEY_SIZE, \
(nettle_set_key_func *) name##_set_key, \
(nettle_set_key_func *) name##_set_key, \
(nettle_crypt_func *) name##_encrypt, \
(nettle_crypt_func *) name##_decrypt, \
}
/* null-terminated list of ciphers implemented by this version of nettle */
extern const struct nettle_cipher *const nettle_ciphers[];
extern const struct nettle_cipher nettle_aes128;
extern const struct nettle_cipher nettle_aes192;
extern const struct nettle_cipher nettle_aes256;
extern const struct nettle_cipher nettle_arcfour128;
extern const struct nettle_cipher nettle_camellia128;
extern const struct nettle_cipher nettle_camellia192;
extern const struct nettle_cipher nettle_camellia256;
extern const struct nettle_cipher nettle_cast128;
extern const struct nettle_cipher nettle_serpent128;
extern const struct nettle_cipher nettle_serpent192;
extern const struct nettle_cipher nettle_serpent256;
extern const struct nettle_cipher nettle_twofish128;
extern const struct nettle_cipher nettle_twofish192;
extern const struct nettle_cipher nettle_twofish256;
extern const struct nettle_cipher nettle_arctwo40;
extern const struct nettle_cipher nettle_arctwo64;
extern const struct nettle_cipher nettle_arctwo128;
extern const struct nettle_cipher nettle_arctwo_gutmann128;
struct nettle_hash {
const char *name;
/* Size of the context struct */
unsigned context_size;
/* Size of digests */
unsigned digest_size;
/* Internal block size */
unsigned block_size;
nettle_hash_init_func *init;
nettle_hash_update_func *update;
nettle_hash_digest_func *digest;
};
#define _NETTLE_HASH(name, NAME) { \
#name, \
sizeof(struct name##_ctx), \
NAME##_DIGEST_SIZE, \
NAME##_DATA_SIZE, \
(nettle_hash_init_func *) name##_init, \
(nettle_hash_update_func *) name##_update, \
(nettle_hash_digest_func *) name##_digest \
}
/* null-terminated list of digests implemented by this version of nettle */
extern const struct nettle_hash *const nettle_hashes[];
extern const struct nettle_hash nettle_md2;
extern const struct nettle_hash nettle_md4;
extern const struct nettle_hash nettle_md5;
extern const struct nettle_hash nettle_gosthash94;
extern const struct nettle_hash nettle_ripemd160;
extern const struct nettle_hash nettle_sha1;
extern const struct nettle_hash nettle_sha224;
extern const struct nettle_hash nettle_sha256;
extern const struct nettle_hash nettle_sha384;
extern const struct nettle_hash nettle_sha512;
extern const struct nettle_hash nettle_sha3_224;
extern const struct nettle_hash nettle_sha3_256;
extern const struct nettle_hash nettle_sha3_384;
extern const struct nettle_hash nettle_sha3_512;
struct nettle_armor {
const char *name;
unsigned encode_context_size;
unsigned decode_context_size;
unsigned encode_final_length;
nettle_armor_init_func *encode_init;
nettle_armor_length_func *encode_length;
nettle_armor_encode_update_func *encode_update;
nettle_armor_encode_final_func *encode_final;
nettle_armor_init_func *decode_init;
nettle_armor_length_func *decode_length;
nettle_armor_decode_update_func *decode_update;
nettle_armor_decode_final_func *decode_final;
};
#define _NETTLE_ARMOR(name, NAME) { \
#name, \
sizeof(struct name##_encode_ctx), \
sizeof(struct name##_decode_ctx), \
NAME##_ENCODE_FINAL_LENGTH, \
(nettle_armor_init_func *) name##_encode_init, \
(nettle_armor_length_func *) name##_encode_length, \
(nettle_armor_encode_update_func *) name##_encode_update, \
(nettle_armor_encode_final_func *) name##_encode_final, \
(nettle_armor_init_func *) name##_decode_init, \
(nettle_armor_length_func *) name##_decode_length, \
(nettle_armor_decode_update_func *) name##_decode_update, \
(nettle_armor_decode_final_func *) name##_decode_final, \
}
#define _NETTLE_ARMOR_0(name, NAME) { \
#name, \
0, \
sizeof(struct name##_decode_ctx), \
NAME##_ENCODE_FINAL_LENGTH, \
(nettle_armor_init_func *) name##_encode_init, \
(nettle_armor_length_func *) name##_encode_length, \
(nettle_armor_encode_update_func *) name##_encode_update, \
(nettle_armor_encode_final_func *) name##_encode_final, \
(nettle_armor_init_func *) name##_decode_init, \
(nettle_armor_length_func *) name##_decode_length, \
(nettle_armor_decode_update_func *) name##_decode_update, \
(nettle_armor_decode_final_func *) name##_decode_final, \
}
/* null-terminated list of armor schemes implemented by this version of nettle */
extern const struct nettle_armor *const nettle_armors[];
extern const struct nettle_armor nettle_base64;
extern const struct nettle_armor nettle_base16;
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_META_H_INCLUDED */

View file

@ -0,0 +1,286 @@
#ifndef __NETTLE_STDINT_H
#define __NETTLE_STDINT_H 1
#ifndef _GENERATED_STDINT_H
#define _GENERATED_STDINT_H " "
/* generated using gnu compiler i686-w64-mingw32-gcc (GCC) 4.9.0 */
#define _STDINT_HAVE_STDINT_H 1
/* ................... shortcircuit part ........................... */
#if defined HAVE_STDINT_H || defined _STDINT_HAVE_STDINT_H
#include <stdint.h>
#else
#include <stddef.h>
/* .................... configured part ............................ */
/* whether we have a C99 compatible stdint header file */
/* #undef _STDINT_HEADER_INTPTR */
/* whether we have a C96 compatible inttypes header file */
/* #undef _STDINT_HEADER_UINT32 */
/* whether we have a BSD compatible inet types header */
/* #undef _STDINT_HEADER_U_INT32 */
/* which 64bit typedef has been found */
/* #undef _STDINT_HAVE_UINT64_T */
/* #undef _STDINT_HAVE_U_INT64_T */
/* which type model has been detected */
/* #undef _STDINT_CHAR_MODEL // skipped */
/* #undef _STDINT_LONG_MODEL // skipped */
/* whether int_least types were detected */
/* #undef _STDINT_HAVE_INT_LEAST32_T */
/* whether int_fast types were detected */
/* #undef _STDINT_HAVE_INT_FAST32_T */
/* whether intmax_t type was detected */
/* #undef _STDINT_HAVE_INTMAX_T */
/* .................... detections part ............................ */
/* whether we need to define bitspecific types from compiler base types */
#ifndef _STDINT_HEADER_INTPTR
#ifndef _STDINT_HEADER_UINT32
#ifndef _STDINT_HEADER_U_INT32
#define _STDINT_NEED_INT_MODEL_T
#else
#define _STDINT_HAVE_U_INT_TYPES
#endif
#endif
#endif
#ifdef _STDINT_HAVE_U_INT_TYPES
#undef _STDINT_NEED_INT_MODEL_T
#endif
#ifdef _STDINT_CHAR_MODEL
#if _STDINT_CHAR_MODEL+0 == 122 || _STDINT_CHAR_MODEL+0 == 124
#ifndef _STDINT_BYTE_MODEL
#define _STDINT_BYTE_MODEL 12
#endif
#endif
#endif
#ifndef _STDINT_HAVE_INT_LEAST32_T
#define _STDINT_NEED_INT_LEAST_T
#endif
#ifndef _STDINT_HAVE_INT_FAST32_T
#define _STDINT_NEED_INT_FAST_T
#endif
#ifndef _STDINT_HEADER_INTPTR
#define _STDINT_NEED_INTPTR_T
#ifndef _STDINT_HAVE_INTMAX_T
#define _STDINT_NEED_INTMAX_T
#endif
#endif
/* .................... definition part ............................ */
/* some system headers have good uint64_t */
#ifndef _HAVE_UINT64_T
#if defined _STDINT_HAVE_UINT64_T || defined HAVE_UINT64_T
#define _HAVE_UINT64_T
#elif defined _STDINT_HAVE_U_INT64_T || defined HAVE_U_INT64_T
#define _HAVE_UINT64_T
typedef u_int64_t uint64_t;
#endif
#endif
#ifndef _HAVE_UINT64_T
/* .. here are some common heuristics using compiler runtime specifics */
#if defined __STDC_VERSION__ && defined __STDC_VERSION__ >= 199901L
#define _HAVE_UINT64_T
typedef long long int64_t;
typedef unsigned long long uint64_t;
#elif !defined __STRICT_ANSI__
#if defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__
#define _HAVE_UINT64_T
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#elif defined __GNUC__ || defined __MWERKS__ || defined __ELF__
/* note: all ELF-systems seem to have loff-support which needs 64-bit */
#if !defined _NO_LONGLONG
#define _HAVE_UINT64_T
typedef long long int64_t;
typedef unsigned long long uint64_t;
#endif
#elif defined __alpha || (defined __mips && defined _ABIN32)
#if !defined _NO_LONGLONG
typedef long int64_t;
typedef unsigned long uint64_t;
#endif
/* compiler/cpu type to define int64_t */
#endif
#endif
#endif
#if defined _STDINT_HAVE_U_INT_TYPES
/* int8_t int16_t int32_t defined by inet code, redeclare the u_intXX types */
typedef u_int8_t uint8_t;
typedef u_int16_t uint16_t;
typedef u_int32_t uint32_t;
/* glibc compatibility */
#ifndef __int8_t_defined
#define __int8_t_defined
#endif
#endif
#ifdef _STDINT_NEED_INT_MODEL_T
/* we must guess all the basic types. Apart from byte-adressable system, */
/* there a few 32-bit-only dsp-systems that we guard with BYTE_MODEL 8-} */
/* (btw, those nibble-addressable systems are way off, or so we assume) */
#if defined _STDINT_BYTE_MODEL
#if _STDINT_LONG_MODEL+0 == 242
/* 2:4:2 = IP16 = a normal 16-bit system */
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
#ifndef __int8_t_defined
#define __int8_t_defined
typedef char int8_t;
typedef short int16_t;
typedef long int32_t;
#endif
#elif _STDINT_LONG_MODEL+0 == 244 || _STDINT_LONG_MODEL == 444
/* 2:4:4 = LP32 = a 32-bit system derived from a 16-bit */
/* 4:4:4 = ILP32 = a normal 32-bit system */
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#ifndef __int8_t_defined
#define __int8_t_defined
typedef char int8_t;
typedef short int16_t;
typedef int int32_t;
#endif
#elif _STDINT_LONG_MODEL+0 == 484 || _STDINT_LONG_MODEL+0 == 488
/* 4:8:4 = IP32 = a 32-bit system prepared for 64-bit */
/* 4:8:8 = LP64 = a normal 64-bit system */
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#ifndef __int8_t_defined
#define __int8_t_defined
typedef char int8_t;
typedef short int16_t;
typedef int int32_t;
#endif
/* this system has a "long" of 64bit */
#ifndef _HAVE_UINT64_T
#define _HAVE_UINT64_T
typedef unsigned long uint64_t;
typedef long int64_t;
#endif
#elif _STDINT_LONG_MODEL+0 == 448
/* LLP64 a 64-bit system derived from a 32-bit system */
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#ifndef __int8_t_defined
#define __int8_t_defined
typedef char int8_t;
typedef short int16_t;
typedef int int32_t;
#endif
/* assuming the system has a "long long" */
#ifndef _HAVE_UINT64_T
#define _HAVE_UINT64_T
typedef unsigned long long uint64_t;
typedef long long int64_t;
#endif
#else
#define _STDINT_NO_INT32_T
#endif
#else
#define _STDINT_NO_INT8_T
#define _STDINT_NO_INT32_T
#endif
#endif
/*
* quote from SunOS-5.8 sys/inttypes.h:
* Use at your own risk. As of February 1996, the committee is squarely
* behind the fixed sized types; the "least" and "fast" types are still being
* discussed. The probability that the "fast" types may be removed before
* the standard is finalized is high enough that they are not currently
* implemented.
*/
#if defined _STDINT_NEED_INT_LEAST_T
typedef int8_t int_least8_t;
typedef int16_t int_least16_t;
typedef int32_t int_least32_t;
#ifdef _HAVE_UINT64_T
typedef int64_t int_least64_t;
#endif
typedef uint8_t uint_least8_t;
typedef uint16_t uint_least16_t;
typedef uint32_t uint_least32_t;
#ifdef _HAVE_UINT64_T
typedef uint64_t uint_least64_t;
#endif
/* least types */
#endif
#if defined _STDINT_NEED_INT_FAST_T
typedef int8_t int_fast8_t;
typedef int int_fast16_t;
typedef int32_t int_fast32_t;
#ifdef _HAVE_UINT64_T
typedef int64_t int_fast64_t;
#endif
typedef uint8_t uint_fast8_t;
typedef unsigned uint_fast16_t;
typedef uint32_t uint_fast32_t;
#ifdef _HAVE_UINT64_T
typedef uint64_t uint_fast64_t;
#endif
/* fast types */
#endif
#ifdef _STDINT_NEED_INTMAX_T
#ifdef _HAVE_UINT64_T
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
#else
typedef long intmax_t;
typedef unsigned long uintmax_t;
#endif
#endif
#ifdef _STDINT_NEED_INTPTR_T
#ifndef __intptr_t_defined
#define __intptr_t_defined
/* we encourage using "long" to store pointer values, never use "int" ! */
#if _STDINT_LONG_MODEL+0 == 242 || _STDINT_LONG_MODEL+0 == 484
typedef unsinged int uintptr_t;
typedef int intptr_t;
#elif _STDINT_LONG_MODEL+0 == 244 || _STDINT_LONG_MODEL+0 == 444
typedef unsigned long uintptr_t;
typedef long intptr_t;
#elif _STDINT_LONG_MODEL+0 == 448 && defined _HAVE_UINT64_T
typedef uint64_t uintptr_t;
typedef int64_t intptr_t;
#else /* matches typical system types ILP32 and LP64 - but not IP16 or LLP64 */
typedef unsigned long uintptr_t;
typedef long intptr_t;
#endif
#endif
#endif
/* shortcircuit*/
#endif
/* once */
#endif
#endif

View file

@ -0,0 +1,96 @@
/* nettle-types.h */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2005 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_TYPES_H
#define NETTLE_TYPES_H
/* Pretend these types always exists. Nettle doesn't use them. */
#define _STDINT_HAVE_INT_FAST32_T 1
#include "nettle-stdint.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Randomness. Used by key generation and dsa signature creation. */
typedef void nettle_random_func(void *ctx,
unsigned length, uint8_t * dst);
/* Progress report function, mainly for key generation. */
typedef void nettle_progress_func(void *ctx, int c);
/* Realloc function, used by struct nettle_buffer. */
typedef void *nettle_realloc_func(void *ctx, void *p,
unsigned length);
/* Ciphers */
typedef void nettle_set_key_func(void *ctx,
unsigned length,
const uint8_t * key);
/* Uses a void * for cipher contexts.
For block ciphers it would make sense with a const void * for the
context, but we use the same typedef for stream ciphers where the
internal state changes during the encryption. */
typedef void nettle_crypt_func(void *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
/* Hash algorithms */
typedef void nettle_hash_init_func(void *ctx);
typedef void nettle_hash_update_func(void *ctx,
unsigned length,
const uint8_t * src);
typedef void nettle_hash_digest_func(void *ctx,
unsigned length,
uint8_t * dst);
/* ASCII armor codecs. NOTE: Experimental and subject to change. */
typedef unsigned nettle_armor_length_func(unsigned length);
typedef void nettle_armor_init_func(void *ctx);
typedef unsigned nettle_armor_encode_update_func(void *ctx,
uint8_t * dst,
unsigned
src_length,
const uint8_t *
src);
typedef unsigned nettle_armor_encode_final_func(void *ctx,
uint8_t * dst);
typedef int nettle_armor_decode_update_func(void *ctx,
unsigned *dst_length,
uint8_t * dst,
unsigned src_length,
const uint8_t * src);
typedef int nettle_armor_decode_final_func(void *ctx);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_TYPES_H */

View file

@ -0,0 +1,75 @@
/* pbkdf2.h
*
* PKCS #5 password-based key derivation function PBKDF2, see RFC 2898.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2012 Simon Josefsson
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_PBKDF2_H_INCLUDED
#define NETTLE_PBKDF2_H_INCLUDED
#include "nettle-meta.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Namespace mangling */
#define pbkdf2 nettle_pbkdf2
#define pbkdf2_hmac_sha1 nettle_pbkdf2_hmac_sha1
#define pbkdf2_hmac_sha256 nettle_pbkdf2_hmac_sha256
void
pbkdf2(void *mac_ctx,
nettle_hash_update_func * update,
nettle_hash_digest_func * digest,
unsigned digest_size, unsigned iterations,
unsigned salt_length, const uint8_t * salt,
unsigned length, uint8_t * dst);
#define PBKDF2(ctx, update, digest, digest_size, \
iterations, salt_length, salt, length, dst) \
(0 ? ((update)((ctx), 0, (uint8_t *) 0), \
(digest)((ctx), 0, (uint8_t *) 0)) \
: pbkdf2 ((ctx), \
(nettle_hash_update_func *)(update), \
(nettle_hash_digest_func *)(digest), \
(digest_size), (iterations), \
(salt_length), (salt), (length), (dst)))
/* PBKDF2 with specific PRFs. */
void
pbkdf2_hmac_sha1(unsigned key_length, const uint8_t * key,
unsigned iterations,
unsigned salt_length, const uint8_t * salt,
unsigned length, uint8_t * dst);
void
pbkdf2_hmac_sha256(unsigned key_length, const uint8_t * key,
unsigned iterations,
unsigned salt_length, const uint8_t * salt,
unsigned length, uint8_t * dst);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_PBKDF2_H_INCLUDED */

View file

@ -0,0 +1,222 @@
/* pgp.h
*
* PGP related functions.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001, 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_PGP_H_INCLUDED
#define NETTLE_PGP_H_INCLUDED
#include <time.h>
#include "nettle-types.h"
#include "bignum.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define pgp_put_uint32 nettle_pgp_put_uint32
#define pgp_put_uint16 nettle_pgp_put_uint16
#define pgp_put_mpi nettle_pgp_put_mpi
#define pgp_put_string nettle_pgp_put_string
#define pgp_put_length nettle_pgp_put_length
#define pgp_put_header nettle_pgp_put_header
#define pgp_put_header_length nettle_pgp_put_header_length
#define pgp_sub_packet_start nettle_pgp_sub_packet_start
#define pgp_put_sub_packet nettle_pgp_put_sub_packet
#define pgp_sub_packet_end nettle_pgp_sub_packet_end
#define pgp_put_public_rsa_key nettle_pgp_put_public_rsa_key
#define pgp_put_rsa_sha1_signature nettle_pgp_put_rsa_sha1_signature
#define pgp_put_userid nettle_pgp_put_userid
#define pgp_crc24 nettle_pgp_crc24
#define pgp_armor nettle_pgp_armor
struct nettle_buffer;
struct rsa_public_key;
struct rsa_private_key;
struct sha1_ctx;
int
pgp_put_uint32(struct nettle_buffer *buffer, uint32_t i);
int
pgp_put_uint16(struct nettle_buffer *buffer, unsigned i);
int
pgp_put_mpi(struct nettle_buffer *buffer, const mpz_t x);
int
pgp_put_string(struct nettle_buffer *buffer,
unsigned length, const uint8_t * s);
int
pgp_put_length(struct nettle_buffer *buffer, unsigned length);
int
pgp_put_header(struct nettle_buffer *buffer,
unsigned tag, unsigned length);
void
pgp_put_header_length(struct nettle_buffer *buffer,
/* start of the header */
unsigned start, unsigned field_size);
unsigned
pgp_sub_packet_start(struct nettle_buffer *buffer);
int
pgp_put_sub_packet(struct nettle_buffer *buffer,
unsigned type,
unsigned length, const uint8_t * data);
void
pgp_sub_packet_end(struct nettle_buffer *buffer, unsigned start);
int
pgp_put_public_rsa_key(struct nettle_buffer *,
const struct rsa_public_key *key,
time_t timestamp);
int
pgp_put_rsa_sha1_signature(struct nettle_buffer *buffer,
const struct rsa_private_key *key,
const uint8_t * keyid,
unsigned type, struct sha1_ctx *hash);
int
pgp_put_userid(struct nettle_buffer *buffer,
unsigned length, const uint8_t * name);
uint32_t pgp_crc24(unsigned length, const uint8_t * data);
int
pgp_armor(struct nettle_buffer *buffer,
const char *tag, unsigned length, const uint8_t * data);
/* Values that can be passed to pgp_put_header when the size of the
* length field, but not the length itself, is known. Also the minimum length
* for the given field size. */
enum pgp_lengths {
PGP_LENGTH_ONE_OCTET = 0,
PGP_LENGTH_TWO_OCTETS = 192,
PGP_LENGTH_FOUR_OCTETS = 8384,
};
enum pgp_public_key_algorithm {
PGP_RSA = 1,
PGP_RSA_ENCRYPT = 2,
PGP_RSA_SIGN = 3,
PGP_EL_GAMAL_ENCRYPT = 16,
PGP_DSA = 17,
PGP_EL_GAMAL = 20,
};
enum pgp_symmetric_algorithm {
PGP_PLAINTEXT = 0,
PGP_IDEA = 1,
PGP_3DES = 2,
PGP_CAST5 = 3,
PGP_BLOWFISH = 4,
PGP_SAFER_SK = 5,
PGP_AES128 = 7,
PGP_AES192 = 8,
PGP_AES256 = 9,
};
enum pgp_compression_algorithm {
PGP_UNCOMPRESSED = 0,
PGP_ZIP = 1,
PGP_ZLIB = 2,
};
enum pgp_hash_algorithm {
PGP_MD5 = 1,
PGP_SHA1 = 2,
PGP_RIPEMD = 3,
PGP_MD2 = 5,
PGP_TIGER192 = 6,
PGP_HAVAL = 7,
};
enum pgp_tag {
PGP_TAG_PUBLIC_SESSION_KEY = 1,
PGP_TAG_SIGNATURE = 2,
PGP_TAG_SYMMETRIC_SESSION_KEY = 3,
PGP_TAG_ONE_PASS_SIGNATURE = 4,
PGP_TAG_SECRET_KEY = 5,
PGP_TAG_PUBLIC_KEY = 6,
PGP_TAG_SECRET_SUBKEY = 7,
PGP_TAG_COMPRESSED = 8,
PGP_TAG_ENCRYPTED = 9,
PGP_TAG_MARKER = 10,
PGP_TAG_LITERAL = 11,
PGP_TAG_TRUST = 12,
PGP_TAG_USERID = 13,
PGP_TAG_PUBLIC_SUBKEY = 14,
};
enum pgp_signature_type {
PGP_SIGN_BINARY = 0,
PGP_SIGN_TEXT = 1,
PGP_SIGN_STANDALONE = 2,
PGP_SIGN_CERTIFICATION = 0x10,
PGP_SIGN_CERTIFICATION_PERSONA = 0x11,
PGP_SIGN_CERTIFICATION_CASUAL = 0x12,
PGP_SIGN_CERTIFICATION_POSITIVE = 0x13,
PGP_SIGN_SUBKEY = 0x18,
PGP_SIGN_KEY = 0x1f,
PGP_SIGN_REVOCATION = 0x20,
PGP_SIGN_REVOCATION_SUBKEY = 0x28,
PGP_SIGN_REVOCATION_CERTIFICATE = 0x30,
PGP_SIGN_TIMESTAMP = 0x40,
};
enum pgp_subpacket_tag {
PGP_SUBPACKET_CREATION_TIME = 2,
PGP_SUBPACKET_SIGNATURE_EXPIRATION_TIME = 3,
PGP_SUBPACKET_EXPORTABLE_CERTIFICATION = 4,
PGP_SUBPACKET_TRUST_SIGNATURE = 5,
PGP_SUBPACKET_REGULAR_EXPRESSION = 6,
PGP_SUBPACKET_REVOCABLE = 7,
PGP_SUBPACKET_KEY_EXPIRATION_TIME = 9,
PGP_SUBPACKET_PLACEHOLDER = 10,
PGP_SUBPACKET_PREFERRED_SYMMETRIC_ALGORITHMS = 11,
PGP_SUBPACKET_REVOCATION_KEY = 12,
PGP_SUBPACKET_ISSUER_KEY_ID = 16,
PGP_SUBPACKET_NOTATION_DATA = 20,
PGP_SUBPACKET_PREFERRED_HASH_ALGORITHMS = 21,
PGP_SUBPACKET_PREFERRED_COMPRESSION_ALGORITHMS = 22,
PGP_SUBPACKET_KEY_SERVER_PREFERENCES = 23,
PGP_SUBPACKET_PREFERRED_KEY_SERVER = 24,
PGP_SUBPACKET_PRIMARY_USER_ID = 25,
PGP_SUBPACKET_POLICY_URL = 26,
PGP_SUBPACKET_KEY_FLAGS = 27,
PGP_SUBPACKET_SIGNERS_USER_ID = 28,
PGP_SUBPACKET_REASON_FOR_REVOCATION = 29,
};
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_PGP_H_INCLUDED */

View file

@ -0,0 +1,111 @@
/* pkcs1.h
*
* PKCS1 embedding.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2003 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_PKCS1_H_INCLUDED
#define NETTLE_PKCS1_H_INCLUDED
#include <gmp.h>
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define _pkcs1_signature_prefix _nettle_pkcs1_signature_prefix
#define pkcs1_rsa_digest_encode nettle_pkcs1_rsa_digest_encode
#define pkcs1_rsa_md5_encode nettle_pkcs1_rsa_md5_encode
#define pkcs1_rsa_md5_encode_digest nettle_pkcs1_rsa_md5_encode_digest
#define pkcs1_rsa_sha1_encode nettle_pkcs1_rsa_sha1_encode
#define pkcs1_rsa_sha1_encode_digest nettle_pkcs1_rsa_sha1_encode_digest
#define pkcs1_rsa_sha256_encode nettle_pkcs1_rsa_sha256_encode
#define pkcs1_rsa_sha256_encode_digest nettle_pkcs1_rsa_sha256_encode_digest
#define pkcs1_rsa_sha512_encode nettle_pkcs1_rsa_sha512_encode
#define pkcs1_rsa_sha512_encode_digest nettle_pkcs1_rsa_sha512_encode_digest
#define pkcs1_encrypt nettle_pkcs1_encrypt
#define pkcs1_decrypt nettle_pkcs1_decrypt
struct md5_ctx;
struct sha1_ctx;
struct sha256_ctx;
struct sha512_ctx;
uint8_t *_pkcs1_signature_prefix(unsigned key_size,
uint8_t * buffer,
unsigned id_size,
const uint8_t * id,
unsigned digest_size);
int
pkcs1_encrypt(unsigned key_size,
/* For padding */
void *random_ctx, nettle_random_func * random,
unsigned length, const uint8_t * message, mpz_t m);
int
pkcs1_decrypt(unsigned key_size,
const mpz_t m, unsigned *length, uint8_t * message);
int
pkcs1_rsa_digest_encode(mpz_t m, unsigned key_size,
unsigned di_length,
const uint8_t * digest_info);
int
pkcs1_rsa_md5_encode(mpz_t m, unsigned length,
struct md5_ctx *hash);
int
pkcs1_rsa_md5_encode_digest(mpz_t m, unsigned length,
const uint8_t * digest);
int
pkcs1_rsa_sha1_encode(mpz_t m, unsigned length,
struct sha1_ctx *hash);
int
pkcs1_rsa_sha1_encode_digest(mpz_t m, unsigned length,
const uint8_t * digest);
int
pkcs1_rsa_sha256_encode(mpz_t m, unsigned length,
struct sha256_ctx *hash);
int
pkcs1_rsa_sha256_encode_digest(mpz_t m, unsigned length,
const uint8_t * digest);
int
pkcs1_rsa_sha512_encode(mpz_t m, unsigned length,
struct sha512_ctx *hash);
int
pkcs1_rsa_sha512_encode_digest(mpz_t m, unsigned length,
const uint8_t * digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_PKCS1_H_INCLUDED */

View file

@ -0,0 +1,40 @@
/* realloc.h
*
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_REALLOC_H_INCLUDED
#define NETTLE_REALLOC_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
nettle_realloc_func nettle_realloc;
nettle_realloc_func nettle_xrealloc;
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_REALLOC_H_INCLUDED */

View file

@ -0,0 +1,75 @@
/* ripemd160.h
*
* RIPEMD-160 hash function.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2011 Andres Mejia
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_RIPEMD160_H_INCLUDED
#define NETTLE_RIPEMD160_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
#include "nettle-types.h"
/* Name mangling */
#define ripemd160_init nettle_ripemd160_init
#define ripemd160_update nettle_ripemd160_update
#define ripemd160_digest nettle_ripemd160_digest
/* RIPEMD160 */
#define RIPEMD160_DIGEST_SIZE 20
#define RIPEMD160_DATA_SIZE 64
/* Digest is kept internally as 5 32-bit words. */
#define _RIPEMD160_DIGEST_LENGTH 5
struct ripemd160_ctx {
uint32_t state[_RIPEMD160_DIGEST_LENGTH];
uint32_t count_low, count_high; /* 64-bit block count */
uint8_t block[RIPEMD160_DATA_SIZE];
unsigned int index;
};
void
ripemd160_init(struct ripemd160_ctx *ctx);
void
ripemd160_update(struct ripemd160_ctx *ctx,
unsigned length, const uint8_t * data);
void
ripemd160_digest(struct ripemd160_ctx *ctx,
unsigned length, uint8_t * digest);
/* Internal compression function. STATE points to 5 uint32_t words,
and DATA points to 64 bytes of input data, possibly unaligned. */
void
_nettle_ripemd160_compress(uint32_t * state,
const uint8_t * data);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_RIPEMD160_H_INCLUDED */

View file

@ -0,0 +1,121 @@
/* rsa-compat.h
*
* The RSA publickey algorithm, RSAREF compatible interface.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_RSA_COMPAT_H_INCLUDED
#define NETTLE_RSA_COMPAT_H_INCLUDED
#include "rsa.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define R_SignInit nettle_R_SignInit
#define R_SignUpdate nettle_R_SignUpdate
#define R_SignFinal nettle_R_SignFinal
#define R_VerifyInit nettle_R_VerifyInit
#define R_VerifyUpdate nettle_R_VerifyUpdate
#define R_VerifyFinal nettle_R_VerifyFinal
/* 256 octets or 2048 bits */
#define MAX_RSA_MODULUS_LEN 256
typedef struct {
unsigned bits;
uint8_t modulus[MAX_RSA_MODULUS_LEN];
uint8_t exponent[MAX_RSA_MODULUS_LEN];
} R_RSA_PUBLIC_KEY;
typedef struct {
unsigned bits;
uint8_t modulus[MAX_RSA_MODULUS_LEN];
uint8_t publicExponent[MAX_RSA_MODULUS_LEN];
uint8_t exponent[MAX_RSA_MODULUS_LEN];
uint8_t prime[2][MAX_RSA_MODULUS_LEN];
uint8_t primeExponent[2][MAX_RSA_MODULUS_LEN];
uint8_t coefficient[MAX_RSA_MODULUS_LEN];
} R_RSA_PRIVATE_KEY;
/* Only MD5 is supported for now */
typedef struct {
struct md5_ctx hash;
} R_SIGNATURE_CTX;
/* Digest algorithms */
/* DA_MD2 not implemented */
enum { DA_MD5 = 1 };
/* Return values */
enum {
RE_SUCCESS = 0,
RE_CONTENT_ENCODING, /* encryptedContent has RFC 1421 encoding error */
RE_DATA, /* other party's private value out of range */
RE_DIGEST_ALGORITHM, /* message-digest algorithm is invalid */
RE_ENCODING, /* encoded block has RFC 1421 encoding error */
RE_ENCRYPTION_ALGORITHM, /* encryption algorithm is invalid */
RE_KEY, /* recovered data encryption key cannot decrypt */
RE_KEY_ENCODING, /* encrypted key has RFC 1421 encoding error */
RE_LEN, /* signatureLen out of range */
RE_MODULUS_LEN, /* modulus length invalid */
RE_NEED_RANDOM, /* random structure is not seeded */
RE_PRIVATE_KEY, /* private key cannot encrypt message digest, */
RE_PUBLIC_KEY, /* publicKey cannot decrypt signature */
RE_SIGNATURE, /* signature is incorrect */
RE_SIGNATURE_ENCODING, /* encodedSignature has RFC 1421 encoding error */
};
int
R_SignInit(R_SIGNATURE_CTX * ctx, int digestAlgorithm);
int
R_SignUpdate(R_SIGNATURE_CTX * ctx, const uint8_t * data,
/* Length is an unsigned char according to rsaref.txt,
* but that must be a typo. */
unsigned length);
int
R_SignFinal(R_SIGNATURE_CTX * ctx,
uint8_t * signature,
unsigned *length, R_RSA_PRIVATE_KEY * key);
int
R_VerifyInit(R_SIGNATURE_CTX * ctx, int digestAlgorithm);
int
R_VerifyUpdate(R_SIGNATURE_CTX * ctx, const uint8_t * data,
/* Length is an unsigned char according to rsaref.txt,
* but that must be a typo. */
unsigned length);
int
R_VerifyFinal(R_SIGNATURE_CTX * ctx,
uint8_t * signature,
unsigned length, R_RSA_PUBLIC_KEY * key);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_RSA_COMPAT_H_INCLUDED */

View file

@ -0,0 +1,403 @@
/* rsa.h
*
* The RSA publickey algorithm.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001, 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_RSA_H_INCLUDED
#define NETTLE_RSA_H_INCLUDED
#include <gmp.h>
#include "nettle-types.h"
#include "md5.h"
#include "sha1.h"
#include "sha2.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define rsa_public_key_init nettle_rsa_public_key_init
#define rsa_public_key_clear nettle_rsa_public_key_clear
#define rsa_public_key_prepare nettle_rsa_public_key_prepare
#define rsa_private_key_init nettle_rsa_private_key_init
#define rsa_private_key_clear nettle_rsa_private_key_clear
#define rsa_private_key_prepare nettle_rsa_private_key_prepare
#define rsa_pkcs1_verify nettle_rsa_pkcs1_verify
#define rsa_pkcs1_sign nettle_rsa_pkcs1_sign
#define rsa_pkcs1_sign_tr nettle_rsa_pkcs1_sign_tr
#define rsa_md5_sign nettle_rsa_md5_sign
#define rsa_md5_verify nettle_rsa_md5_verify
#define rsa_sha1_sign nettle_rsa_sha1_sign
#define rsa_sha1_verify nettle_rsa_sha1_verify
#define rsa_sha256_sign nettle_rsa_sha256_sign
#define rsa_sha256_verify nettle_rsa_sha256_verify
#define rsa_sha512_sign nettle_rsa_sha512_sign
#define rsa_sha512_verify nettle_rsa_sha512_verify
#define rsa_md5_sign_digest nettle_rsa_md5_sign_digest
#define rsa_md5_verify_digest nettle_rsa_md5_verify_digest
#define rsa_sha1_sign_digest nettle_rsa_sha1_sign_digest
#define rsa_sha1_verify_digest nettle_rsa_sha1_verify_digest
#define rsa_sha256_sign_digest nettle_rsa_sha256_sign_digest
#define rsa_sha256_verify_digest nettle_rsa_sha256_verify_digest
#define rsa_sha512_sign_digest nettle_rsa_sha512_sign_digest
#define rsa_sha512_verify_digest nettle_rsa_sha512_verify_digest
#define rsa_encrypt nettle_rsa_encrypt
#define rsa_decrypt nettle_rsa_decrypt
#define rsa_decrypt_tr nettle_rsa_decrypt_tr
#define rsa_compute_root nettle_rsa_compute_root
#define rsa_generate_keypair nettle_rsa_generate_keypair
#define rsa_keypair_to_sexp nettle_rsa_keypair_to_sexp
#define rsa_keypair_from_sexp_alist nettle_rsa_keypair_from_sexp_alist
#define rsa_keypair_from_sexp nettle_rsa_keypair_from_sexp
#define rsa_public_key_from_der_iterator nettle_rsa_public_key_from_der_iterator
#define rsa_private_key_from_der_iterator nettle_rsa_private_key_from_der_iterator
#define rsa_keypair_from_der nettle_rsa_keypair_from_der
#define rsa_keypair_to_openpgp nettle_rsa_keypair_to_openpgp
#define _rsa_verify _nettle_rsa_verify
#define _rsa_check_size _nettle_rsa_check_size
#define _rsa_blind _nettle_rsa_blind
#define _rsa_unblind _nettle_rsa_unblind
/* This limit is somewhat arbitrary. Technically, the smallest modulo
which makes sense at all is 15 = 3*5, phi(15) = 8, size 4 bits. But
for ridiculously small keys, not all odd e are possible (e.g., for
5 bits, the only possible modulo is 3*7 = 21, phi(21) = 12, and e =
3 don't work). The smallest size that makes sense with pkcs#1, and
which allows RSA encryption of one byte messages, is 12 octets, 89
bits. */
#define RSA_MINIMUM_N_OCTETS 12
#define RSA_MINIMUM_N_BITS (8*RSA_MINIMUM_N_OCTETS - 7)
struct rsa_public_key {
/* Size of the modulo, in octets. This is also the size of all
* signatures that are created or verified with this key. */
unsigned size;
/* Modulo */
mpz_t n;
/* Public exponent */
mpz_t e;
};
struct rsa_private_key {
unsigned size;
/* d is filled in by the key generation function; otherwise it's
* completely unused. */
mpz_t d;
/* The two factors */
mpz_t p;
mpz_t q;
/* d % (p-1), i.e. a e = 1 (mod (p-1)) */
mpz_t a;
/* d % (q-1), i.e. b e = 1 (mod (q-1)) */
mpz_t b;
/* modular inverse of q , i.e. c q = 1 (mod p) */
mpz_t c;
};
/* Signing a message works as follows:
*
* Store the private key in a rsa_private_key struct.
*
* Call rsa_private_key_prepare. This initializes the size attribute
* to the length of a signature.
*
* Initialize a hashing context, by callling
* md5_init
*
* Hash the message by calling
* md5_update
*
* Create the signature by calling
* rsa_md5_sign
*
* The signature is represented as a mpz_t bignum. This call also
* resets the hashing context.
*
* When done with the key and signature, don't forget to call
* mpz_clear.
*/
/* Calls mpz_init to initialize bignum storage. */
void
rsa_public_key_init(struct rsa_public_key *key);
/* Calls mpz_clear to deallocate bignum storage. */
void
rsa_public_key_clear(struct rsa_public_key *key);
int
rsa_public_key_prepare(struct rsa_public_key *key);
/* Calls mpz_init to initialize bignum storage. */
void
rsa_private_key_init(struct rsa_private_key *key);
/* Calls mpz_clear to deallocate bignum storage. */
void
rsa_private_key_clear(struct rsa_private_key *key);
int
rsa_private_key_prepare(struct rsa_private_key *key);
/* PKCS#1 style signatures */
int
rsa_pkcs1_sign(const struct rsa_private_key *key,
unsigned length, const uint8_t * digest_info,
mpz_t s);
int
rsa_pkcs1_sign_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func * random,
unsigned length, const uint8_t * digest_info,
mpz_t s);
int
rsa_pkcs1_verify(const struct rsa_public_key *key,
unsigned length, const uint8_t * digest_info,
const mpz_t signature);
int
rsa_md5_sign(const struct rsa_private_key *key,
struct md5_ctx *hash, mpz_t signature);
int
rsa_md5_verify(const struct rsa_public_key *key,
struct md5_ctx *hash, const mpz_t signature);
int
rsa_sha1_sign(const struct rsa_private_key *key,
struct sha1_ctx *hash, mpz_t signature);
int
rsa_sha1_verify(const struct rsa_public_key *key,
struct sha1_ctx *hash, const mpz_t signature);
int
rsa_sha256_sign(const struct rsa_private_key *key,
struct sha256_ctx *hash, mpz_t signature);
int
rsa_sha256_verify(const struct rsa_public_key *key,
struct sha256_ctx *hash, const mpz_t signature);
int
rsa_sha512_sign(const struct rsa_private_key *key,
struct sha512_ctx *hash, mpz_t signature);
int
rsa_sha512_verify(const struct rsa_public_key *key,
struct sha512_ctx *hash, const mpz_t signature);
/* Variants taking the digest as argument. */
int
rsa_md5_sign_digest(const struct rsa_private_key *key,
const uint8_t * digest, mpz_t s);
int
rsa_md5_verify_digest(const struct rsa_public_key *key,
const uint8_t * digest,
const mpz_t signature);
int
rsa_sha1_sign_digest(const struct rsa_private_key *key,
const uint8_t * digest, mpz_t s);
int
rsa_sha1_verify_digest(const struct rsa_public_key *key,
const uint8_t * digest,
const mpz_t signature);
int
rsa_sha256_sign_digest(const struct rsa_private_key *key,
const uint8_t * digest, mpz_t s);
int
rsa_sha256_verify_digest(const struct rsa_public_key *key,
const uint8_t * digest,
const mpz_t signature);
int
rsa_sha512_sign_digest(const struct rsa_private_key *key,
const uint8_t * digest, mpz_t s);
int
rsa_sha512_verify_digest(const struct rsa_public_key *key,
const uint8_t * digest,
const mpz_t signature);
/* RSA encryption, using PKCS#1 */
/* These functions uses the v1.5 padding. What should the v2 (OAEP)
* functions be called? */
/* Returns 1 on success, 0 on failure, which happens if the
* message is too long for the key. */
int
rsa_encrypt(const struct rsa_public_key *key,
/* For padding */
void *random_ctx, nettle_random_func * random,
unsigned length, const uint8_t * cleartext,
mpz_t cipher);
/* Message must point to a buffer of size *LENGTH. KEY->size is enough
* for all valid messages. On success, *LENGTH is updated to reflect
* the actual length of the message. Returns 1 on success, 0 on
* failure, which happens if decryption failed or if the message
* didn't fit. */
int
rsa_decrypt(const struct rsa_private_key *key,
unsigned *length, uint8_t * cleartext,
const mpz_t ciphertext);
/* Timing-resistant version, using randomized RSA blinding. */
int
rsa_decrypt_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func * random,
unsigned *length, uint8_t * message,
const mpz_t gibberish);
/* Compute x, the e:th root of m. Calling it with x == m is allowed. */
void
rsa_compute_root(const struct rsa_private_key *key,
mpz_t x, const mpz_t m);
/* Key generation */
/* Note that the key structs must be initialized first. */
int
rsa_generate_keypair(struct rsa_public_key *pub,
struct rsa_private_key *key,
void *random_ctx,
nettle_random_func * random,
void *progress_ctx,
nettle_progress_func * progress,
/* Desired size of modulo, in bits */
unsigned n_size,
/* Desired size of public exponent, in bits. If
* zero, the passed in value pub->e is used. */
unsigned e_size);
#define RSA_SIGN(key, algorithm, ctx, length, data, signature) ( \
algorithm##_update(ctx, length, data), \
rsa_##algorithm##_sign(key, ctx, signature) \
)
#define RSA_VERIFY(key, algorithm, ctx, length, data, signature) ( \
algorithm##_update(ctx, length, data), \
rsa_##algorithm##_verify(key, ctx, signature) \
)
/* Keys in sexp form. */
struct nettle_buffer;
/* Generates a public-key expression if PRIV is NULL .*/
int
rsa_keypair_to_sexp(struct nettle_buffer *buffer, const char *algorithm_name, /* NULL means "rsa" */
const struct rsa_public_key *pub,
const struct rsa_private_key *priv);
struct sexp_iterator;
int
rsa_keypair_from_sexp_alist(struct rsa_public_key *pub,
struct rsa_private_key *priv,
unsigned limit,
struct sexp_iterator *i);
/* If PRIV is NULL, expect a public-key expression. If PUB is NULL,
* expect a private key expression and ignore the parts not needed for
* the public key. */
/* Keys must be initialized before calling this function, as usual. */
int
rsa_keypair_from_sexp(struct rsa_public_key *pub,
struct rsa_private_key *priv,
unsigned limit,
unsigned length, const uint8_t * expr);
/* Keys in PKCS#1 format. */
struct asn1_der_iterator;
int
rsa_public_key_from_der_iterator(struct rsa_public_key *pub,
unsigned limit,
struct asn1_der_iterator *i);
int
rsa_private_key_from_der_iterator(struct rsa_public_key *pub,
struct rsa_private_key *priv,
unsigned limit,
struct asn1_der_iterator *i);
/* For public keys, use PRIV == NULL */
int
rsa_keypair_from_der(struct rsa_public_key *pub,
struct rsa_private_key *priv,
unsigned limit,
unsigned length, const uint8_t * data);
/* OpenPGP format. Experimental interface, subject to change. */
int
rsa_keypair_to_openpgp(struct nettle_buffer *buffer,
const struct rsa_public_key *pub,
const struct rsa_private_key *priv,
/* A single user id. NUL-terminated utf8. */
const char *userid);
/* Internal functions. */
int
_rsa_verify(const struct rsa_public_key *key,
const mpz_t m, const mpz_t s);
unsigned
_rsa_check_size(mpz_t n);
void
_rsa_blind(const struct rsa_public_key *pub,
void *random_ctx, nettle_random_func * random,
mpz_t c, mpz_t ri);
void
_rsa_unblind(const struct rsa_public_key *pub, mpz_t c,
const mpz_t ri);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_RSA_H_INCLUDED */

View file

@ -0,0 +1,92 @@
/* salsa20.h
*
* The Salsa20 stream cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2012 Simon Josefsson
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_SALSA20_H_INCLUDED
#define NETTLE_SALSA20_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define salsa20_set_key nettle_salsa20_set_key
#define salsa20_set_iv nettle_salsa20_set_iv
#define salsa20_crypt nettle_salsa20_crypt
#define _salsa20_core _nettle_salsa20_core
#define salsa20r12_crypt nettle_salsa20r12_crypt
/* Minimum and maximum keysizes, and a reasonable default. In
* octets.*/
#define SALSA20_MIN_KEY_SIZE 16
#define SALSA20_MAX_KEY_SIZE 32
#define SALSA20_KEY_SIZE 32
#define SALSA20_BLOCK_SIZE 64
#define SALSA20_IV_SIZE 8
#define _SALSA20_INPUT_LENGTH 16
struct salsa20_ctx {
/* Indices 1-4 and 11-14 holds the key (two identical copies for the
shorter key size), indices 0, 5, 10, 15 are constant, indices 6, 7
are the IV, and indices 8, 9 are the block counter:
C K K K
K C I I
B B C K
K K K C
*/
uint32_t input[_SALSA20_INPUT_LENGTH];
};
void
salsa20_set_key(struct salsa20_ctx *ctx,
unsigned length, const uint8_t * key);
void
salsa20_set_iv(struct salsa20_ctx *ctx, const uint8_t * iv);
void
salsa20_crypt(struct salsa20_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
void
salsa20r12_crypt(struct salsa20_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
void
_salsa20_core(uint32_t * dst, const uint32_t * src,
unsigned rounds);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SALSA20_H_INCLUDED */

View file

@ -0,0 +1,79 @@
/* serpent.h
*
* The serpent block cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/* Serpent is a 128-bit block cipher that accepts a key size of 256
* bits, designed by Ross Anderson, Eli Biham, and Lars Knudsen. See
* http://www.cl.cam.ac.uk/~rja14/serpent.html for details.
*/
#ifndef NETTLE_SERPENT_H_INCLUDED
#define NETTLE_SERPENT_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define serpent_set_key nettle_serpent_set_key
#define serpent_encrypt nettle_serpent_encrypt
#define serpent_decrypt nettle_serpent_decrypt
#define SERPENT_BLOCK_SIZE 16
/* Other key lengths are possible, but the design of Serpent makes
* smaller key lengths quite pointless; they cheated with the AES
* requirements, using a 256-bit key length exclusively and just
* padding it out if the desired key length was less, so there really
* is no advantage to using key lengths less than 256 bits. */
#define SERPENT_KEY_SIZE 32
/* Allow keys of size 128 <= bits <= 256 */
#define SERPENT_MIN_KEY_SIZE 16
#define SERPENT_MAX_KEY_SIZE 32
struct serpent_ctx {
uint32_t keys[33][4]; /* key schedule */
};
void
serpent_set_key(struct serpent_ctx *ctx,
unsigned length, const uint8_t * key);
void
serpent_encrypt(const struct serpent_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
void
serpent_decrypt(const struct serpent_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SERPENT_H_INCLUDED */

View file

@ -0,0 +1,209 @@
/* sexp.h
*
* Parsing s-expressions.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_SEXP_H_INCLUDED
#define NETTLE_SEXP_H_INCLUDED
#include <stdarg.h>
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define sexp_iterator_first nettle_sexp_iterator_first
#define sexp_transport_iterator_first nettle_sexp_transport_iterator_first
#define sexp_iterator_next nettle_sexp_iterator_next
#define sexp_iterator_enter_list nettle_sexp_iterator_enter_list
#define sexp_iterator_exit_list nettle_sexp_iterator_exit_list
#define sexp_iterator_subexpr nettle_sexp_iterator_subexpr
#define sexp_iterator_get_uint32 nettle_sexp_iterator_get_uint32
#define sexp_iterator_check_type nettle_sexp_iterator_check_type
#define sexp_iterator_check_types nettle_sexp_iterator_check_types
#define sexp_iterator_assoc nettle_sexp_iterator_assoc
#define sexp_format nettle_sexp_format
#define sexp_vformat nettle_sexp_vformat
#define sexp_transport_format nettle_sexp_transport_format
#define sexp_transport_vformat nettle_sexp_transport_vformat
#define sexp_token_chars nettle_sexp_token_chars
enum sexp_type { SEXP_ATOM, SEXP_LIST, SEXP_END };
struct sexp_iterator {
unsigned length;
const uint8_t *buffer;
/* Points at the start of the current sub expression. */
unsigned start;
/* If type is SEXP_LIST, pos points at the start of the current
* element. Otherwise, it points at the end. */
unsigned pos;
unsigned level;
enum sexp_type type;
unsigned display_length;
const uint8_t *display;
unsigned atom_length;
const uint8_t *atom;
};
/* All these functions return 1 on success, 0 on failure */
/* Initializes the iterator. */
int
sexp_iterator_first(struct sexp_iterator *iterator,
unsigned length, const uint8_t * input);
/* NOTE: Decodes the input string in place */
int
sexp_transport_iterator_first(struct sexp_iterator *iterator,
unsigned length, uint8_t * input);
int
sexp_iterator_next(struct sexp_iterator *iterator);
/* Current element must be a list. */
int
sexp_iterator_enter_list(struct sexp_iterator *iterator);
/* Skips the rest of the current list */
int
sexp_iterator_exit_list(struct sexp_iterator *iterator);
#if 0
/* Skips out of as many lists as necessary to get back to the given
* level. */
int
sexp_iterator_exit_lists(struct sexp_iterator *iterator,
unsigned level);
#endif
/* Gets start and length of the current subexpression. Implies
* sexp_iterator_next. */
const uint8_t *sexp_iterator_subexpr(struct sexp_iterator
*iterator, unsigned *length);
int
sexp_iterator_get_uint32(struct sexp_iterator *iterator,
uint32_t * x);
/* Checks the type of the current expression, which should be a list
*
* (<type> ...)
*/
int
sexp_iterator_check_type(struct sexp_iterator *iterator,
const uint8_t * type);
const uint8_t *sexp_iterator_check_types(struct sexp_iterator
*iterator,
unsigned ntypes,
const uint8_t *
const *types);
/* Current element must be a list. Looks up element of type
*
* (key rest...)
*
* For a matching key, the corresponding iterator is initialized
* pointing at the start of REST.
*
* On success, exits the current list.
*/
int
sexp_iterator_assoc(struct sexp_iterator *iterator,
unsigned nkeys,
const uint8_t * const *keys,
struct sexp_iterator *values);
/* Output functions. What is a reasonable API for this? It seems
* ugly to have to reimplement string streams. */
/* Declared for real in buffer.h */
struct nettle_buffer;
/* Returns the number of output characters, or 0 on out of memory. If
* buffer == NULL, just compute length.
*
* Format strings can contained matched parentheses, tokens ("foo" in
* the format string is formatted as "3:foo"), whitespace (which
* separates tokens but is otherwise ignored) and the following
* formatting specifiers:
*
* %s String represented as unsigned length, const uint8_t *data.
*
* %t Optional display type, represented as
* unsigned display_length, const uint8_t *display,
* display == NULL means no display type.
*
* %i Non-negative small integer, uint32_t.
*
* %b Non-negative bignum, mpz_t.
*
* %l Literal string (no length added), typically a balanced
* subexpression. Represented as unsigned length, const uint8_t
* *data.
*
* %(, %) Allows insertion of unbalanced parenthesis.
*
* Modifiers:
*
* %0 For %s, %t and %l, says that there's no length argument,
* instead the string is NUL-terminated, and there's only one
* const uint8_t * argument.
*/
unsigned
sexp_format(struct nettle_buffer *buffer,
const char *format, ...);
unsigned
sexp_vformat(struct nettle_buffer *buffer,
const char *format, va_list args);
unsigned
sexp_transport_format(struct nettle_buffer *buffer,
const char *format, ...);
unsigned
sexp_transport_vformat(struct nettle_buffer *buffer,
const char *format, va_list args);
/* Classification for advanced syntax. */
extern const char
sexp_token_chars[0x80];
#define TOKEN_CHAR(c) ((c) < 0x80 && sexp_token_chars[(c)])
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SEXP_H_INCLUDED */

View file

@ -0,0 +1,34 @@
/* sha.h
*
* This file is deprecated, and provided only for backwards
* compatibility with earlier versions of Nettle. Please use sha1.h
* and/or sha2.h instead.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_SHA_H_INCLUDED
#define NETTLE_SHA_H_INCLUDED
#include "sha1.h"
#include "sha2.h"
#endif /* NETTLE_SHA_H_INCLUDED */

View file

@ -0,0 +1,74 @@
/* sha1.h
*
* The sha1 hash function.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001, 2012 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_SHA1_H_INCLUDED
#define NETTLE_SHA1_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define sha1_init nettle_sha1_init
#define sha1_update nettle_sha1_update
#define sha1_digest nettle_sha1_digest
/* SHA1 */
#define SHA1_DIGEST_SIZE 20
#define SHA1_DATA_SIZE 64
/* Digest is kept internally as 5 32-bit words. */
#define _SHA1_DIGEST_LENGTH 5
struct sha1_ctx {
uint32_t state[_SHA1_DIGEST_LENGTH]; /* State variables */
uint32_t count_low, count_high; /* 64-bit block count */
uint8_t block[SHA1_DATA_SIZE]; /* SHA1 data buffer */
unsigned int index; /* index into buffer */
};
void
sha1_init(struct sha1_ctx *ctx);
void
sha1_update(struct sha1_ctx *ctx,
unsigned length, const uint8_t * data);
void
sha1_digest(struct sha1_ctx *ctx,
unsigned length, uint8_t * digest);
/* Internal compression function. STATE points to 5 uint32_t words,
and DATA points to 64 bytes of input data, possibly unaligned. */
void
_nettle_sha1_compress(uint32_t * state, const uint8_t * data);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SHA1_H_INCLUDED */

View file

@ -0,0 +1,149 @@
/* sha2.h
*
* The sha2 family of hash functions.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001, 2012 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_SHA2_H_INCLUDED
#define NETTLE_SHA2_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define sha224_init nettle_sha224_init
#define sha224_digest nettle_sha224_digest
#define sha256_init nettle_sha256_init
#define sha256_update nettle_sha256_update
#define sha256_digest nettle_sha256_digest
#define sha384_init nettle_sha384_init
#define sha384_digest nettle_sha384_digest
#define sha512_init nettle_sha512_init
#define sha512_update nettle_sha512_update
#define sha512_digest nettle_sha512_digest
/* SHA256 */
#define SHA256_DIGEST_SIZE 32
#define SHA256_DATA_SIZE 64
/* Digest is kept internally as 8 32-bit words. */
#define _SHA256_DIGEST_LENGTH 8
struct sha256_ctx {
uint32_t state[_SHA256_DIGEST_LENGTH]; /* State variables */
uint32_t count_low, count_high; /* 64-bit block count */
uint8_t block[SHA256_DATA_SIZE]; /* SHA256 data buffer */
unsigned int index; /* index into buffer */
};
void
sha256_init(struct sha256_ctx *ctx);
void
sha256_update(struct sha256_ctx *ctx,
unsigned length, const uint8_t * data);
void
sha256_digest(struct sha256_ctx *ctx,
unsigned length, uint8_t * digest);
/* Internal compression function. STATE points to 8 uint32_t words,
DATA points to 64 bytes of input data, possibly unaligned, and K
points to the table of constants. */
void
_nettle_sha256_compress(uint32_t * state, const uint8_t * data,
const uint32_t * k);
/* SHA224, a truncated SHA256 with different initial state. */
#define SHA224_DIGEST_SIZE 28
#define SHA224_DATA_SIZE SHA256_DATA_SIZE
#define sha224_ctx sha256_ctx
void
sha224_init(struct sha256_ctx *ctx);
#define sha224_update nettle_sha256_update
void
sha224_digest(struct sha256_ctx *ctx,
unsigned length, uint8_t * digest);
/* SHA512 */
#define SHA512_DIGEST_SIZE 64
#define SHA512_DATA_SIZE 128
/* Digest is kept internally as 8 64-bit words. */
#define _SHA512_DIGEST_LENGTH 8
struct sha512_ctx {
uint64_t state[_SHA512_DIGEST_LENGTH]; /* State variables */
uint64_t count_low, count_high; /* 128-bit block count */
uint8_t block[SHA512_DATA_SIZE]; /* SHA512 data buffer */
unsigned int index; /* index into buffer */
};
void
sha512_init(struct sha512_ctx *ctx);
void
sha512_update(struct sha512_ctx *ctx,
unsigned length, const uint8_t * data);
void
sha512_digest(struct sha512_ctx *ctx,
unsigned length, uint8_t * digest);
/* Internal compression function. STATE points to 8 uint64_t words,
DATA points to 128 bytes of input data, possibly unaligned, and K
points to the table of constants. */
void
_nettle_sha512_compress(uint64_t * state, const uint8_t * data,
const uint64_t * k);
/* SHA384, a truncated SHA512 with different initial state. */
#define SHA384_DIGEST_SIZE 48
#define SHA384_DATA_SIZE SHA512_DATA_SIZE
#define sha384_ctx sha512_ctx
void
sha384_init(struct sha512_ctx *ctx);
#define sha384_update nettle_sha512_update
void
sha384_digest(struct sha512_ctx *ctx,
unsigned length, uint8_t * digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SHA2_H_INCLUDED */

View file

@ -0,0 +1,161 @@
/* sha3.h
*
* The sha3 hash function (aka Keccak).
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2012 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_SHA3_H_INCLUDED
#define NETTLE_SHA3_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
#define sha3_permute nettle_sha3_permute
#define _sha3_update _nettle_sha3_update
#define _sha3_pad _nettle_sha3_pad
#define sha3_224_init nettle_sha3_224_init
#define sha3_224_update nettle_sha3_224_update
#define sha3_224_digest nettle_sha3_224_digest
#define sha3_256_init nettle_sha3_256_init
#define sha3_256_update nettle_sha3_256_update
#define sha3_256_digest nettle_sha3_256_digest
#define sha3_384_init nettle_sha3_384_init
#define sha3_384_update nettle_sha3_384_update
#define sha3_384_digest nettle_sha3_384_digest
#define sha3_512_init nettle_sha3_512_init
#define sha3_512_update nettle_sha3_512_update
#define sha3_512_digest nettle_sha3_512_digest
/* The sha3 state is a 5x5 matrix of 64-bit words. In the notation of
Keccak description, S[x,y] is element x + 5*y, so if x is
interpreted as the row index and y the column index, it is stored
in column-major order. */
#define SHA3_STATE_LENGTH 25
/* The "width" is 1600 bits or 200 octets */
struct sha3_state {
uint64_t a[SHA3_STATE_LENGTH];
};
void
sha3_permute(struct sha3_state *state);
unsigned
_sha3_update(struct sha3_state *state,
unsigned block_size, uint8_t * block,
unsigned pos, unsigned length, const uint8_t * data);
void
_sha3_pad(struct sha3_state *state,
unsigned block_size, uint8_t * block, unsigned pos);
/* The "capacity" is set to 2*(digest size), 512 bits or 64 octets.
The "rate" is the width - capacity, or width - 2 * (digest
size). */
#define SHA3_224_DIGEST_SIZE 28
#define SHA3_224_DATA_SIZE 144
#define SHA3_256_DIGEST_SIZE 32
#define SHA3_256_DATA_SIZE 136
#define SHA3_384_DIGEST_SIZE 48
#define SHA3_384_DATA_SIZE 104
#define SHA3_512_DIGEST_SIZE 64
#define SHA3_512_DATA_SIZE 72
struct sha3_224_ctx {
struct sha3_state state;
unsigned index;
uint8_t block[SHA3_224_DATA_SIZE];
};
void
sha3_224_init(struct sha3_224_ctx *ctx);
void
sha3_224_update(struct sha3_224_ctx *ctx,
unsigned length, const uint8_t * data);
void
sha3_224_digest(struct sha3_224_ctx *ctx,
unsigned length, uint8_t * digest);
struct sha3_256_ctx {
struct sha3_state state;
unsigned index;
uint8_t block[SHA3_256_DATA_SIZE];
};
void
sha3_256_init(struct sha3_256_ctx *ctx);
void
sha3_256_update(struct sha3_256_ctx *ctx,
unsigned length, const uint8_t * data);
void
sha3_256_digest(struct sha3_256_ctx *ctx,
unsigned length, uint8_t * digest);
struct sha3_384_ctx {
struct sha3_state state;
unsigned index;
uint8_t block[SHA3_384_DATA_SIZE];
};
void
sha3_384_init(struct sha3_384_ctx *ctx);
void
sha3_384_update(struct sha3_384_ctx *ctx,
unsigned length, const uint8_t * data);
void
sha3_384_digest(struct sha3_384_ctx *ctx,
unsigned length, uint8_t * digest);
struct sha3_512_ctx {
struct sha3_state state;
unsigned index;
uint8_t block[SHA3_512_DATA_SIZE];
};
void
sha3_512_init(struct sha3_512_ctx *ctx);
void
sha3_512_update(struct sha3_512_ctx *ctx,
unsigned length, const uint8_t * data);
void
sha3_512_digest(struct sha3_512_ctx *ctx,
unsigned length, uint8_t * digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SHA3_H_INCLUDED */

View file

@ -0,0 +1,76 @@
/* twofish.h
*
* The twofish block cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/*
* Twofish is a 128-bit block cipher that accepts a variable-length
* key up to 256 bits, designed by Bruce Schneier and others. See
* http://www.counterpane.com/twofish.html for details.
*/
#ifndef NETTLE_TWOFISH_H_INCLUDED
#define NETTLE_TWOFISH_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define twofish_set_key nettle_twofish_set_key
#define twofish_encrypt nettle_twofish_encrypt
#define twofish_decrypt nettle_twofish_decrypt
#define TWOFISH_BLOCK_SIZE 16
/* Variable key size between 128 and 256 bits. But the only valid
* values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */
#define TWOFISH_MIN_KEY_SIZE 16
#define TWOFISH_MAX_KEY_SIZE 32
#define TWOFISH_KEY_SIZE 32
struct twofish_ctx {
uint32_t keys[40];
uint32_t s_box[4][256];
};
void
twofish_set_key(struct twofish_ctx *ctx,
unsigned length, const uint8_t * key);
void
twofish_encrypt(const struct twofish_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
void
twofish_decrypt(const struct twofish_ctx *ctx,
unsigned length, uint8_t * dst,
const uint8_t * src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_TWOFISH_H_INCLUDED */

View file

@ -0,0 +1,238 @@
/* umac.h
*
* UMAC message authentication code (RFC-4418).
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2013 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_UMAC_H_INCLUDED
#define NETTLE_UMAC_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
/* Namespace mangling */
#define umac32_set_key nettle_umac32_set_key
#define umac64_set_key nettle_umac64_set_key
#define umac96_set_key nettle_umac96_set_key
#define umac128_set_key nettle_umac128_set_key
#define umac32_set_nonce nettle_umac32_set_nonce
#define umac64_set_nonce nettle_umac64_set_nonce
#define umac96_set_nonce nettle_umac96_set_nonce
#define umac128_set_nonce nettle_umac128_set_nonce
#define umac32_update nettle_umac32_update
#define umac64_update nettle_umac64_update
#define umac96_update nettle_umac96_update
#define umac128_update nettle_umac128_update
#define umac32_digest nettle_umac32_digest
#define umac64_digest nettle_umac64_digest
#define umac96_digest nettle_umac96_digest
#define umac128_digest nettle_umac128_digest
#define _umac_set_key _nettle_umac_set_key
#define _umac_nh _nettle_umac_nh
#define _umac_nh_n _nettle_umac_nh_n
#define _umac_poly64 _nettle_umac_poly64
#define _umac_poly128 _nettle_umac_poly128
#define _umac_l2_init _nettle_umac_l2_init
#define _umac_l2 _nettle_umac_l2
#define _umac_l2_final _nettle_umac_l2_final
#define _umac_l3_init _nettle_umac_l3_init
#define _umac_l3 _nettle_umac_l3
#include "nettle-types.h"
#include "aes.h"
#define UMAC_KEY_SIZE 16
#define UMAC32_DIGEST_SIZE 4
#define UMAC64_DIGEST_SIZE 8
#define UMAC96_DIGEST_SIZE 12
#define UMAC128_DIGEST_SIZE 16
#define UMAC_DATA_SIZE 1024
/* Subkeys and state for UMAC with tag size 32*n bits. */
#define _UMAC_STATE(n) \
uint32_t l1_key[UMAC_DATA_SIZE/4 + 4*((n)-1)]; \
/* Keys in 32-bit pieces, high first */ \
uint32_t l2_key[6*(n)]; \
uint64_t l3_key1[8*(n)]; \
uint32_t l3_key2[(n)]; \
/* AES cipher for encrypting the nonce */ \
struct aes_ctx pdf_key; \
/* The l2_state consists of 2*n uint64_t, for poly64 \
and poly128 hashing, followed by n additional \
uint64_t used as an input buffer. */ \
uint64_t l2_state[3*(n)]; \
/* Input to the pdf_key, zero-padded and low bits \
cleared if appropriate. */ \
uint8_t nonce[AES_BLOCK_SIZE]; \
unsigned short nonce_length /* For incrementing */
/* Buffering */
#define _UMAC_BUFFER \
unsigned index; \
/* Complete blocks processed */ \
uint64_t count; \
uint8_t block[UMAC_DATA_SIZE]
#define _UMAC_NONCE_CACHED 0x80
struct umac32_ctx {
_UMAC_STATE(1);
/* Low bits and cache flag. */
unsigned short nonce_low;
/* Previous padding block */
uint32_t pad_cache[AES_BLOCK_SIZE / 4];
_UMAC_BUFFER;
};
struct umac64_ctx {
_UMAC_STATE(2);
/* Low bit and cache flag. */
unsigned short nonce_low;
/* Previous padding block */
uint32_t pad_cache[AES_BLOCK_SIZE / 4];
_UMAC_BUFFER;
};
struct umac96_ctx {
_UMAC_STATE(3);
_UMAC_BUFFER;
};
struct umac128_ctx {
_UMAC_STATE(4);
_UMAC_BUFFER;
};
/* The _set_key function initialize the nonce to zero. */
void
umac32_set_key(struct umac32_ctx *ctx, const uint8_t * key);
void
umac64_set_key(struct umac64_ctx *ctx, const uint8_t * key);
void
umac96_set_key(struct umac96_ctx *ctx, const uint8_t * key);
void
umac128_set_key(struct umac128_ctx *ctx, const uint8_t * key);
/* Optional, if not used, messages get incrementing nonces starting from zero. */
void
umac32_set_nonce(struct umac32_ctx *ctx,
unsigned nonce_length, const uint8_t * nonce);
void
umac64_set_nonce(struct umac64_ctx *ctx,
unsigned nonce_length, const uint8_t * nonce);
void
umac96_set_nonce(struct umac96_ctx *ctx,
unsigned nonce_length, const uint8_t * nonce);
void
umac128_set_nonce(struct umac128_ctx *ctx,
unsigned nonce_length, const uint8_t * nonce);
void
umac32_update(struct umac32_ctx *ctx,
unsigned length, const uint8_t * data);
void
umac64_update(struct umac64_ctx *ctx,
unsigned length, const uint8_t * data);
void
umac96_update(struct umac96_ctx *ctx,
unsigned length, const uint8_t * data);
void
umac128_update(struct umac128_ctx *ctx,
unsigned length, const uint8_t * data);
/* The _digest functions increment the nonce */
void
umac32_digest(struct umac32_ctx *ctx,
unsigned length, uint8_t * digest);
void
umac64_digest(struct umac64_ctx *ctx,
unsigned length, uint8_t * digest);
void
umac96_digest(struct umac96_ctx *ctx,
unsigned length, uint8_t * digest);
void
umac128_digest(struct umac128_ctx *ctx,
unsigned length, uint8_t * digest);
/* Internal functions */
#define UMAC_POLY64_BLOCKS 16384
#define UMAC_P64_OFFSET 59
#define UMAC_P64 (- (uint64_t) UMAC_P64_OFFSET)
#define UMAC_P128_OFFSET 159
#define UMAC_P128_HI (~(uint64_t) 0)
#define UMAC_P128_LO (-(uint64_t) UMAC_P128_OFFSET)
void
_umac_set_key(uint32_t * l1_key, uint32_t * l2_key,
uint64_t * l3_key1, uint32_t * l3_key2,
struct aes_ctx *pad, const uint8_t * key,
unsigned n);
uint64_t
_umac_nh(const uint32_t * key, unsigned length,
const uint8_t * msg);
/* Equivalent to
for (i = 0; i < n; i++)
out[i] = _umac_nh (key + 4*i, length, msg);
but processing input only once.
*/
void
_umac_nh_n(uint64_t * out, unsigned n, const uint32_t * key,
unsigned length, const uint8_t * msg);
/* Returns y*k + m (mod p), including "marker" processing. Return
value is *not* in canonical representation, and must be normalized
before the output is used. */
uint64_t
_umac_poly64(uint32_t kh, uint32_t kl, uint64_t y, uint64_t m);
void
_umac_poly128(const uint32_t * k, uint64_t * y, uint64_t mh,
uint64_t ml);
void
_umac_l2_init(unsigned size, uint32_t * k);
void
_umac_l2(const uint32_t * key, uint64_t * state, unsigned n,
uint64_t count, const uint64_t * m);
void
_umac_l2_final(const uint32_t * key, uint64_t * state, unsigned n,
uint64_t count);
void
_umac_l3_init(unsigned size, uint64_t * k);
uint32_t _umac_l3(const uint64_t * key, const uint64_t * m);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_UMAC_H_INCLUDED */

View file

@ -0,0 +1,132 @@
/* yarrow.h
*
* The yarrow pseudo-randomness generator.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_YARROW_H_INCLUDED
#define NETTLE_YARROW_H_INCLUDED
#include "aes.h"
#include "sha2.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define yarrow256_init nettle_yarrow256_init
#define yarrow256_seed nettle_yarrow256_seed
#define yarrow256_update nettle_yarrow256_update
#define yarrow256_random nettle_yarrow256_random
#define yarrow256_is_seeded nettle_yarrow256_is_seeded
#define yarrow256_needed_sources nettle_yarrow256_needed_sources
#define yarrow256_fast_reseed nettle_yarrow256_fast_reseed
#define yarrow256_slow_reseed nettle_yarrow256_slow_reseed
#define yarrow_key_event_init nettle_yarrow_key_event_init
#define yarrow_key_event_estimate nettle_yarrow_key_event_estimate
/* Obsolete alias for backwards compatibility. Will be deleted in some
later version. */
#define yarrow256_force_reseed yarrow256_slow_reseed
enum yarrow_pool_id { YARROW_FAST = 0, YARROW_SLOW = 1 };
struct yarrow_source {
/* Indexed by yarrow_pool_id */
uint32_t estimate[2];
/* The pool next sample should go to. */
enum yarrow_pool_id next;
};
#define YARROW256_SEED_FILE_SIZE (2 * AES_BLOCK_SIZE)
/* Yarrow-256, based on SHA-256 and AES-256 */
struct yarrow256_ctx {
/* Indexed by yarrow_pool_id */
struct sha256_ctx pools[2];
int seeded;
/* The current key and counter block */
struct aes_ctx key;
uint8_t counter[AES_BLOCK_SIZE];
/* The entropy sources */
unsigned nsources;
struct yarrow_source *sources;
};
void
yarrow256_init(struct yarrow256_ctx *ctx,
unsigned nsources, struct yarrow_source *sources);
void
yarrow256_seed(struct yarrow256_ctx *ctx,
unsigned length, const uint8_t * seed_file);
/* Returns 1 on reseed */
int
yarrow256_update(struct yarrow256_ctx *ctx,
unsigned source, unsigned entropy,
unsigned length, const uint8_t * data);
void
yarrow256_random(struct yarrow256_ctx *ctx, unsigned length,
uint8_t * dst);
int
yarrow256_is_seeded(struct yarrow256_ctx *ctx);
unsigned
yarrow256_needed_sources(struct yarrow256_ctx *ctx);
void
yarrow256_fast_reseed(struct yarrow256_ctx *ctx);
void
yarrow256_slow_reseed(struct yarrow256_ctx *ctx);
/* Key event estimator */
#define YARROW_KEY_EVENT_BUFFER 16
struct yarrow_key_event_ctx {
/* Counter for initial priming of the state */
unsigned index;
unsigned chars[YARROW_KEY_EVENT_BUFFER];
unsigned previous;
};
void
yarrow_key_event_init(struct yarrow_key_event_ctx *ctx);
unsigned
yarrow_key_event_estimate(struct yarrow_key_event_ctx *ctx,
unsigned key, unsigned time);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_YARROW_H_INCLUDED */

View file

@ -0,0 +1,97 @@
/*
* Copyright (c) 2013 Red Hat Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * The names of contributors to this software may not be
* used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* Author: Stef Walter <stefw@redhat.com>
*/
#ifndef __P11_KIT_DEPRECATED_H__
#define __P11_KIT_DEPRECATED_H__
#ifndef __P11_KIT_H__
#error "Please include <p11-kit/p11-kit.h> instead of this file."
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifndef P11_KIT_NO_DEPRECATIONS
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define P11_KIT_DEPRECATED_FOR(f) __attribute__((deprecated("Use " #f " instead")))
#elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
#define P11_KIT_DEPRECATED_FOR(f) __attribute__((__deprecated__))
#endif
#endif
#ifndef P11_KIT_DEPRECATED_FOR
#define P11_KIT_DEPRECATED_FOR(f)
#endif
#ifndef P11_KIT_DISABLE_DEPRECATED
P11_KIT_DEPRECATED_FOR (p11_kit_modules_load)
CK_RV p11_kit_initialize_registered (void);
P11_KIT_DEPRECATED_FOR (p11_kit_modules_release)
CK_RV p11_kit_finalize_registered (void);
P11_KIT_DEPRECATED_FOR (p11_kit_modules_release)
CK_FUNCTION_LIST_PTR * p11_kit_registered_modules (void);
P11_KIT_DEPRECATED_FOR (p11_kit_module_for_name)
CK_FUNCTION_LIST_PTR p11_kit_registered_name_to_module (const char *name);
P11_KIT_DEPRECATED_FOR (p11_kit_module_get_name)
char * p11_kit_registered_module_to_name (CK_FUNCTION_LIST_PTR module);
P11_KIT_DEPRECATED_FOR (p11_kit_config_option)
char * p11_kit_registered_option (CK_FUNCTION_LIST_PTR module,
const char *field);
P11_KIT_DEPRECATED_FOR (module->C_Initialize)
CK_RV p11_kit_initialize_module (CK_FUNCTION_LIST_PTR module);
P11_KIT_DEPRECATED_FOR (module->C_Finalize)
CK_RV p11_kit_finalize_module (CK_FUNCTION_LIST_PTR module);
P11_KIT_DEPRECATED_FOR (p11_kit_module_load)
CK_RV p11_kit_load_initialize_module (const char *module_path,
CK_FUNCTION_LIST_PTR *module);
#endif /* P11_KIT_DISABLE_DEPRECATED */
#undef P11_KIT_DEPRECATED_FOR
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __P11_KIT_DEPRECATED_H__ */

View file

@ -0,0 +1,115 @@
/*
* Copyright (c) 2013 Red Hat, Inc
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * The names of contributors to this software may not be
* used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* Author: Stef Walter <stefw@redhat.com>
*/
#ifndef P11_KIT_ITER_H
#define P11_KIT_ITER_H
#include "p11-kit/p11-kit.h"
#include "p11-kit/pkcs11.h"
#include "p11-kit/uri.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef P11_KIT_FUTURE_UNSTABLE_API
typedef struct p11_kit_iter P11KitIter;
typedef P11KitIter p11_kit_iter;
typedef enum {
P11_KIT_ITER_BUSY_SESSIONS = 1 << 1,
P11_KIT_ITER_WANT_WRITABLE = 1 << 2,
} P11KitIterBehavior;
typedef CK_RV (* p11_kit_iter_callback) (P11KitIter *iter,
CK_BBOOL *matches,
void *data);
P11KitIter * p11_kit_iter_new (P11KitUri *uri,
P11KitIterBehavior behavior);
void p11_kit_iter_free (P11KitIter *iter);
void p11_kit_iter_add_callback (P11KitIter *iter,
p11_kit_iter_callback callback,
void *callback_data,
p11_kit_destroyer callback_destroy);
void p11_kit_iter_add_filter (P11KitIter *iter,
CK_ATTRIBUTE *matching,
CK_ULONG count);
void p11_kit_iter_set_uri (P11KitIter *iter,
P11KitUri *uri);
void p11_kit_iter_begin (P11KitIter *iter,
CK_FUNCTION_LIST_PTR *modules);
void p11_kit_iter_begin_with (P11KitIter *iter,
CK_FUNCTION_LIST_PTR module,
CK_SLOT_ID slot,
CK_SESSION_HANDLE session);
CK_RV p11_kit_iter_next (P11KitIter *iter);
CK_FUNCTION_LIST_PTR p11_kit_iter_get_module (P11KitIter *iter);
CK_SLOT_ID p11_kit_iter_get_slot (P11KitIter *iter);
CK_TOKEN_INFO * p11_kit_iter_get_token (P11KitIter *iter);
CK_SESSION_HANDLE p11_kit_iter_get_session (P11KitIter *iter);
CK_OBJECT_HANDLE p11_kit_iter_get_object (P11KitIter *iter);
CK_RV p11_kit_iter_get_attributes (P11KitIter *iter,
CK_ATTRIBUTE *template,
CK_ULONG count);
CK_RV p11_kit_iter_load_attributes (P11KitIter *iter,
CK_ATTRIBUTE *template,
CK_ULONG count);
CK_SESSION_HANDLE p11_kit_iter_keep_session (P11KitIter *iter);
CK_RV p11_kit_iter_destroy_object (P11KitIter *iter);
#endif /* P11_KIT_FUTURE_UNSTABLE_API */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* P11_KIT_ITER_H */

View file

@ -0,0 +1,121 @@
/*
* Copyright (c) 2011 Collabora Ltd.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * The names of contributors to this software may not be
* used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* Author: Stef Walter <stefw@collabora.co.uk>
*/
#ifndef __P11_KIT_H__
#define __P11_KIT_H__
#include "p11-kit/pkcs11.h"
/*
* If the caller is using the PKCS#11 GNU calling convention, then we cater
* to that here.
*/
#ifdef CRYPTOKI_GNU
typedef ck_rv_t CK_RV;
typedef struct ck_function_list* CK_FUNCTION_LIST_PTR;
typedef struct ck_function_list CK_FUNCTION_LIST;
#endif
#include "p11-kit/deprecated.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
P11_KIT_MODULE_UNMANAGED = 1 << 0,
P11_KIT_MODULE_CRITICAL = 1 << 1,
P11_KIT_MODULE_TRUSTED = 1 << 2,
};
typedef void (* p11_kit_destroyer) (void *data);
CK_FUNCTION_LIST ** p11_kit_modules_load (const char *reserved,
int flags);
CK_RV p11_kit_modules_initialize (CK_FUNCTION_LIST **modules,
p11_kit_destroyer failure_callback);
CK_FUNCTION_LIST ** p11_kit_modules_load_and_initialize (int flags);
CK_RV p11_kit_modules_finalize (CK_FUNCTION_LIST **modules);
void p11_kit_modules_release (CK_FUNCTION_LIST **modules);
void p11_kit_modules_finalize_and_release (CK_FUNCTION_LIST **modules);
CK_FUNCTION_LIST * p11_kit_module_for_name (CK_FUNCTION_LIST **modules,
const char *name);
char * p11_kit_module_get_name (CK_FUNCTION_LIST *module);
int p11_kit_module_get_flags (CK_FUNCTION_LIST *module);
CK_FUNCTION_LIST * p11_kit_module_load (const char *module_path,
int flags);
CK_RV p11_kit_module_initialize (CK_FUNCTION_LIST *module);
CK_RV p11_kit_module_finalize (CK_FUNCTION_LIST *module);
void p11_kit_module_release (CK_FUNCTION_LIST *module);
char * p11_kit_config_option (CK_FUNCTION_LIST *module,
const char *option);
const char* p11_kit_strerror (CK_RV rv);
size_t p11_kit_space_strlen (const unsigned char *string,
size_t max_length);
char* p11_kit_space_strdup (const unsigned char *string,
size_t max_length);
#ifdef P11_KIT_FUTURE_UNSTABLE_API
void p11_kit_set_progname (const char *progname);
void p11_kit_be_quiet (void);
void p11_kit_be_loud (void);
#endif
const char * p11_kit_message (void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __P11_KIT_H__ */

View file

@ -0,0 +1,107 @@
/*
* Copyright (c) 2011 Collabora Ltd.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * The names of contributors to this software may not be
* used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* Author: Stef Walter <stefw@collabora.co.uk>
*/
#ifndef P11_KIT_PIN_H
#define P11_KIT_PIN_H
#include <p11-kit/uri.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct p11_kit_pin P11KitPin;
typedef enum {
P11_KIT_PIN_FLAGS_USER_LOGIN = 1<<0,
P11_KIT_PIN_FLAGS_SO_LOGIN = 1<<1,
P11_KIT_PIN_FLAGS_CONTEXT_LOGIN = 1<<2,
P11_KIT_PIN_FLAGS_RETRY = 1<<3,
P11_KIT_PIN_FLAGS_MANY_TRIES = 1<<4,
P11_KIT_PIN_FLAGS_FINAL_TRY = 1<<5
} P11KitPinFlags;
#define P11_KIT_PIN_FALLBACK ""
typedef void (*p11_kit_pin_destroy_func) (void *data);
P11KitPin* p11_kit_pin_new (const unsigned char *value,
size_t length);
P11KitPin* p11_kit_pin_new_for_string (const char *value);
P11KitPin* p11_kit_pin_new_for_buffer (unsigned char *buffer,
size_t length,
p11_kit_pin_destroy_func destroy);
P11KitPin* p11_kit_pin_ref (P11KitPin *pin);
void p11_kit_pin_unref (P11KitPin *pin);
const unsigned char * p11_kit_pin_get_value (P11KitPin *pin,
size_t *length);
size_t p11_kit_pin_get_length (P11KitPin *pin);
typedef P11KitPin* (*p11_kit_pin_callback) (const char *pin_source,
P11KitUri *pin_uri,
const char *pin_description,
P11KitPinFlags pin_flags,
void *callback_data);
int p11_kit_pin_register_callback (const char *pin_source,
p11_kit_pin_callback callback,
void *callback_data,
p11_kit_pin_destroy_func callback_destroy);
void p11_kit_pin_unregister_callback (const char *pin_source,
p11_kit_pin_callback callback,
void *callback_data);
P11KitPin* p11_kit_pin_request (const char *pin_source,
P11KitUri *pin_uri,
const char *pin_description,
P11KitPinFlags pin_flags);
P11KitPin* p11_kit_pin_file_callback (const char *pin_source,
P11KitUri *pin_uri,
const char *pin_description,
P11KitPinFlags pin_flags,
void *callback_data);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* P11_KIT_URI_H */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,162 @@
/*
* Copyright (c) 2011 Collabora Ltd.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * The names of contributors to this software may not be
* used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* Author: Stef Walter <stefw@collabora.co.uk>
*/
#ifndef P11_KIT_URI_H
#define P11_KIT_URI_H
#include "p11-kit/pkcs11.h"
#ifdef __cplusplus
extern "C" {
#endif
#define P11_KIT_URI_SCHEME "pkcs11"
#define P11_KIT_URI_SCHEME_LEN 6
typedef enum {
P11_KIT_URI_OK = 0,
P11_KIT_URI_UNEXPECTED = -1,
P11_KIT_URI_BAD_SCHEME = -2,
P11_KIT_URI_BAD_ENCODING = -3,
P11_KIT_URI_BAD_SYNTAX = -4,
P11_KIT_URI_BAD_VERSION = -5,
P11_KIT_URI_NOT_FOUND = -6,
} P11KitUriResult;
#define P11_KIT_URI_NO_MEMORY P11_KIT_URI_UNEXPECTED
typedef enum {
P11_KIT_URI_FOR_OBJECT = (1 << 1),
P11_KIT_URI_FOR_TOKEN = (1 << 2),
P11_KIT_URI_FOR_MODULE = (1 << 3),
P11_KIT_URI_FOR_MODULE_WITH_VERSION =
(1 << 4) | P11_KIT_URI_FOR_MODULE,
P11_KIT_URI_FOR_OBJECT_ON_TOKEN =
P11_KIT_URI_FOR_OBJECT | P11_KIT_URI_FOR_TOKEN,
P11_KIT_URI_FOR_OBJECT_ON_TOKEN_AND_MODULE =
P11_KIT_URI_FOR_OBJECT_ON_TOKEN | P11_KIT_URI_FOR_MODULE,
P11_KIT_URI_FOR_ANY = 0x0000FFFF,
} P11KitUriType;
/*
* If the caller is using the PKCS#11 GNU calling convention, then we cater
* to that here.
*/
#ifdef CRYPTOKI_GNU
typedef struct ck_info *CK_INFO_PTR;
typedef struct ck_token_info *CK_TOKEN_INFO_PTR;
typedef ck_attribute_type_t CK_ATTRIBUTE_TYPE;
typedef struct ck_attribute *CK_ATTRIBUTE_PTR;
typedef unsigned long int CK_ULONG;
typedef P11KitUriType p11_kit_uri_type_t;
typedef P11KitUriResult p11_kit_uri_result_t;
#endif
typedef struct p11_kit_uri P11KitUri;
typedef struct p11_kit_uri p11_kit_uri;
CK_INFO_PTR p11_kit_uri_get_module_info (P11KitUri *uri);
int p11_kit_uri_match_module_info (P11KitUri *uri,
CK_INFO_PTR info);
CK_TOKEN_INFO_PTR p11_kit_uri_get_token_info (P11KitUri *uri);
int p11_kit_uri_match_token_info (P11KitUri *uri,
CK_TOKEN_INFO_PTR token_info);
CK_ATTRIBUTE_PTR p11_kit_uri_get_attribute (P11KitUri *uri,
CK_ATTRIBUTE_TYPE attr_type);
int p11_kit_uri_set_attribute (P11KitUri *uri,
CK_ATTRIBUTE_PTR attr);
int p11_kit_uri_clear_attribute (P11KitUri *uri,
CK_ATTRIBUTE_TYPE attr_type);
CK_ATTRIBUTE_PTR p11_kit_uri_get_attributes (P11KitUri *uri,
CK_ULONG *n_attrs);
int p11_kit_uri_set_attributes (P11KitUri *uri,
CK_ATTRIBUTE_PTR attrs,
CK_ULONG n_attrs);
void p11_kit_uri_clear_attributes (P11KitUri *uri);
int p11_kit_uri_match_attributes (P11KitUri *uri,
CK_ATTRIBUTE_PTR attrs,
CK_ULONG n_attrs);
const char* p11_kit_uri_get_pin_source (P11KitUri *uri);
void p11_kit_uri_set_pin_source (P11KitUri *uri,
const char *pin_source);
#ifndef P11_KIT_DISABLE_DEPRECATED
const char* p11_kit_uri_get_pinfile (P11KitUri *uri);
void p11_kit_uri_set_pinfile (P11KitUri *uri,
const char *pinfile);
#endif /* P11_KIT_DISABLE_DEPRECATED */
void p11_kit_uri_set_unrecognized (P11KitUri *uri,
int unrecognized);
int p11_kit_uri_any_unrecognized (P11KitUri *uri);
P11KitUri* p11_kit_uri_new (void);
int p11_kit_uri_format (P11KitUri *uri,
P11KitUriType uri_type,
char **string);
int p11_kit_uri_parse (const char *string,
P11KitUriType uri_type,
P11KitUri *uri);
void p11_kit_uri_free (P11KitUri *uri);
const char* p11_kit_uri_message (int code);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* P11_KIT_URI_H */

View file

@ -1226,7 +1226,7 @@
/* #undef SONAME_LIBGLU */
/* Define to the soname of the libgnutls library. */
/* #unef SONAME_LIBGNUTLS */
#define SONAME_LIBGNUTLS L"libgnutls-28.dll"
/* Define to the soname of the libgsm library. */
/* #undef SONAME_LIBGSM */