2 * Copyright (C) 2008-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
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 3 of
11 * the License, or (at your option) any later version.
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.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 #ifndef GNUTLS_CRYPTO_H
24 #define GNUTLS_CRYPTO_H
31 typedef struct api_cipher_hd_st
*gnutls_cipher_hd_t
;
33 int gnutls_cipher_init (gnutls_cipher_hd_t
* handle
,
34 gnutls_cipher_algorithm_t cipher
,
35 const gnutls_datum_t
* key
,
36 const gnutls_datum_t
* iv
);
37 int gnutls_cipher_encrypt (const gnutls_cipher_hd_t handle
,
38 void *text
, size_t textlen
);
39 int gnutls_cipher_decrypt (const gnutls_cipher_hd_t handle
,
40 void *ciphertext
, size_t ciphertextlen
);
41 int gnutls_cipher_decrypt2 (gnutls_cipher_hd_t handle
,
42 const void *ciphertext
, size_t ciphertextlen
,
43 void *text
, size_t textlen
);
44 int gnutls_cipher_encrypt2 (gnutls_cipher_hd_t handle
, const void *text
,
45 size_t textlen
, void *ciphertext
,
46 size_t ciphertextlen
);
48 void gnutls_cipher_set_iv (gnutls_cipher_hd_t handle
, void *iv
, size_t ivlen
);
50 int gnutls_cipher_tag( gnutls_cipher_hd_t handle
, void* tag
, size_t tag_size
);
51 int gnutls_cipher_add_auth( gnutls_cipher_hd_t handle
, const void* text
, size_t text_size
);
53 void gnutls_cipher_deinit (gnutls_cipher_hd_t handle
);
54 int gnutls_cipher_get_block_size (gnutls_cipher_algorithm_t algorithm
);
57 typedef struct hash_hd_st
*gnutls_hash_hd_t
;
58 typedef struct hmac_hd_st
*gnutls_hmac_hd_t
;
60 int gnutls_hmac_init (gnutls_hmac_hd_t
* dig
,
61 gnutls_mac_algorithm_t algorithm
, const void *key
,
63 int gnutls_hmac (gnutls_hmac_hd_t handle
, const void *text
, size_t textlen
);
64 void gnutls_hmac_output (gnutls_hmac_hd_t handle
, void *digest
);
65 void gnutls_hmac_deinit (gnutls_hmac_hd_t handle
, void *digest
);
66 int gnutls_hmac_get_len (gnutls_mac_algorithm_t algorithm
);
67 int gnutls_hmac_fast (gnutls_mac_algorithm_t algorithm
, const void *key
,
68 size_t keylen
, const void *text
, size_t textlen
,
71 int gnutls_hash_init (gnutls_hash_hd_t
* dig
,
72 gnutls_digest_algorithm_t algorithm
);
73 int gnutls_hash (gnutls_hash_hd_t handle
, const void *text
, size_t textlen
);
74 void gnutls_hash_output (gnutls_hash_hd_t handle
, void *digest
);
75 void gnutls_hash_deinit (gnutls_hash_hd_t handle
, void *digest
);
76 int gnutls_hash_get_len (gnutls_digest_algorithm_t algorithm
);
77 int gnutls_hash_fast (gnutls_digest_algorithm_t algorithm
,
78 const void *text
, size_t textlen
, void *digest
);
80 /* register ciphers */
85 * @GNUTLS_RND_NONCE: Non-predictable random number. Fatal in parts
86 * of session if broken, i.e., vulnerable to statistical analysis.
87 * @GNUTLS_RND_RANDOM: Pseudo-random cryptographic random number.
88 * Fatal in session if broken.
89 * @GNUTLS_RND_KEY: Fatal in many sessions if broken.
91 * Enumeration of random quality levels.
93 typedef enum gnutls_rnd_level
96 GNUTLS_RND_RANDOM
= 1,
100 int gnutls_rnd (gnutls_rnd_level_t level
, void *data
, size_t len
);