1 /* 2 * Copyright (C) 2010-2012 Free Software Foundation, Inc. 3 * 4 * Author: Nikos Mavrogiannopoulos 5 * 6 * This file is part of GnuTLS. 7 * 8 * The GnuTLS is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public License 10 * as published by the Free Software Foundation; either version 2.1 of 11 * the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with this program. If not, see <https://www.gnu.org/licenses/> 20 * 21 */ 22 23 #ifndef GNUTLS_LIB_ABSTRACT_INT_H 24 #define GNUTLS_LIB_ABSTRACT_INT_H 25 26 #include <gnutls/abstract.h> 27 28 struct gnutls_privkey_st { 29 gnutls_privkey_type_t type; 30 gnutls_pk_algorithm_t pk_algorithm; 31 32 union { 33 gnutls_x509_privkey_t x509; 34 #ifdef ENABLE_PKCS11 35 gnutls_pkcs11_privkey_t pkcs11; 36 #endif 37 struct { 38 gnutls_privkey_sign_func sign_func; /* raw like TLS 1.x */ 39 gnutls_privkey_sign_data_func sign_data_func; 40 gnutls_privkey_sign_hash_func sign_hash_func; 41 gnutls_privkey_decrypt_func decrypt_func; 42 gnutls_privkey_decrypt_func2 decrypt_func2; 43 gnutls_privkey_deinit_func deinit_func; 44 gnutls_privkey_info_func info_func; 45 void *userdata; 46 unsigned bits; 47 } ext; 48 } key; 49 50 unsigned int flags; 51 struct pin_info_st pin; 52 }; 53 54 struct gnutls_pubkey_st { 55 unsigned int bits; /* an indication of the security parameter */ 56 57 /* the size of params depends on the public 58 * key algorithm 59 * RSA: [0] is modulus 60 * [1] is public exponent 61 * DSA: [0] is p 62 * [1] is q 63 * [2] is g 64 * [3] is public key 65 */ 66 gnutls_pk_params_st params; 67 68 unsigned int key_usage; /* bits from GNUTLS_KEY_* */ 69 70 struct pin_info_st pin; 71 }; 72 73 int _gnutls_privkey_get_public_mpis(gnutls_privkey_t key, 74 gnutls_pk_params_st *); 75 76 int _gnutls_privkey_get_spki_params(gnutls_privkey_t key, 77 gnutls_x509_spki_st * params); 78 int _gnutls_privkey_update_spki_params(gnutls_privkey_t key, 79 gnutls_pk_algorithm_t pk, 80 gnutls_digest_algorithm_t dig, 81 unsigned flags, 82 gnutls_x509_spki_st *params); 83 84 unsigned _gnutls_privkey_compatible_with_sig(gnutls_privkey_t key, gnutls_sign_algorithm_t sig); 85 86 void _gnutls_privkey_cleanup(gnutls_privkey_t key); 87 88 int privkey_sign_and_hash_data(gnutls_privkey_t signer, 89 const gnutls_sign_entry_st *se, 90 const gnutls_datum_t * data, 91 gnutls_datum_t * signature, 92 gnutls_x509_spki_st *params); 93 int 94 privkey_sign_raw_data(gnutls_privkey_t key, 95 const gnutls_sign_entry_st *se, 96 const gnutls_datum_t * data, 97 gnutls_datum_t * signature, 98 gnutls_x509_spki_st * params); 99 100 unsigned pubkey_to_bits(const gnutls_pk_params_st * params); 101 int _gnutls_pubkey_compatible_with_sig(gnutls_session_t, 102 gnutls_pubkey_t pubkey, 103 const version_entry_st * ver, 104 gnutls_sign_algorithm_t sign); 105 int 106 _gnutls_pubkey_get_mpis(gnutls_pubkey_t key, gnutls_pk_params_st * params); 107 108 int pubkey_verify_data(const gnutls_sign_entry_st *se, 109 const mac_entry_st *me, 110 const gnutls_datum_t * data, 111 const gnutls_datum_t * signature, 112 gnutls_pk_params_st * params, 113 gnutls_x509_spki_st * sign_params, 114 unsigned vflags); 115 116 117 118 const mac_entry_st *_gnutls_dsa_q_to_hash(const gnutls_pk_params_st * 119 params, unsigned int *hash_len); 120 121 int 122 _gnutls_privkey_get_mpis(gnutls_privkey_t key, gnutls_pk_params_st * params); 123 124 #endif /* GNUTLS_LIB_ABSTRACT_INT_H */ 125