156
156
* Do not add any algorithms in other modes (avoid modified algorithms).
157
157
* View first: "The order of encryption and authentication for
158
158
* protecting communications" by Hugo Krawczyk - CRYPTO 2001
160
* Make sure to updated MAX_CIPHER_BLOCK_SIZE and MAX_CIPHER_KEY_SIZE as well.
160
162
static const gnutls_cipher_entry algorithms[] = {
161
163
{"AES-256-CBC", GNUTLS_CIPHER_AES_256_CBC, 16, 32, CIPHER_BLOCK, 16, 0},
171
173
{"CAMELLIA-128-CBC", GNUTLS_CIPHER_CAMELLIA_128_CBC, 16, 16, CIPHER_BLOCK,
177
#ifdef ENABLE_OPENPGP
178
{"IDEA-PGP-CFB", GNUTLS_CIPHER_IDEA_PGP_CFB, 8, 16, CIPHER_BLOCK, 8, 0},
179
{"3DES-PGP-CFB", GNUTLS_CIPHER_3DES_PGP_CFB, 8, 24, CIPHER_BLOCK, 8, 0},
180
{"CAST5-PGP-CFB", GNUTLS_CIPHER_CAST5_PGP_CFB, 8, 16, CIPHER_BLOCK, 8, 0},
181
{"BLOWFISH-PGP-CFB", GNUTLS_CIPHER_BLOWFISH_PGP_CFB, 8,
182
16 /*actually unlimited */ , CIPHER_BLOCK, 8, 0},
183
{"SAFER-SK128-PGP-CFB", GNUTLS_CIPHER_SAFER_SK128_PGP_CFB, 8, 16,
185
{"AES-128-PGP-CFB", GNUTLS_CIPHER_AES128_PGP_CFB, 16, 16, CIPHER_BLOCK, 16,
187
{"AES-192-PGP-CFB", GNUTLS_CIPHER_AES192_PGP_CFB, 16, 24, CIPHER_BLOCK, 16,
189
{"AES-256-PGP-CFB", GNUTLS_CIPHER_AES256_PGP_CFB, 16, 32, CIPHER_BLOCK, 16,
191
{"TWOFISH-PGP-CFB", GNUTLS_CIPHER_TWOFISH_PGP_CFB, 16, 16, CIPHER_BLOCK, 16,
174
194
{"NULL", GNUTLS_CIPHER_NULL, 1, 0, CIPHER_STREAM, 0, 0},
175
195
{0, 0, 0, 0, 0, 0, 0}
215
235
{"SHA256", HASH_OID_SHA256, GNUTLS_MAC_SHA256, 32},
216
236
{"SHA384", HASH_OID_SHA384, GNUTLS_MAC_SHA384, 48},
217
237
{"SHA512", HASH_OID_SHA512, GNUTLS_MAC_SHA512, 64},
218
{"MD2", HASH_OID_MD2, GNUTLS_MAC_MD2, 0}, /* not used as MAC */
238
{"MD2", HASH_OID_MD2, GNUTLS_MAC_MD2, 0}, /* not used as MAC */
219
239
{"RIPEMD160", HASH_OID_RMD160, GNUTLS_MAC_RMD160, 20},
220
240
{"NULL", NULL, GNUTLS_MAC_NULL, 0},
241
261
#define GNUTLS_HASH_ALG_LOOP(a) \
242
262
GNUTLS_HASH_LOOP( if(p->id == algorithm) { a; break; } )
245
/* Compression Section */
246
#define GNUTLS_COMPRESSION_ENTRY(name, id, wb, ml, cl) \
247
{ #name, name, id, wb, ml, cl}
250
#define MAX_COMP_METHODS 5
251
const int _gnutls_comp_algorithms_size = MAX_COMP_METHODS;
253
/* the compression entry is defined in gnutls_algorithms.h */
255
gnutls_compression_entry _gnutls_compression_algorithms[MAX_COMP_METHODS] = {
256
GNUTLS_COMPRESSION_ENTRY (GNUTLS_COMP_NULL, 0x00, 0, 0, 0),
258
/* draft-ietf-tls-compression-02 */
259
GNUTLS_COMPRESSION_ENTRY (GNUTLS_COMP_DEFLATE, 0x01, 15, 8, 3),
264
static const gnutls_compression_method_t supported_compressions[] = {
275
#define GNUTLS_COMPRESSION_LOOP(b) \
276
const gnutls_compression_entry *p; \
277
for(p = _gnutls_compression_algorithms; p->name != NULL; p++) { b ; }
278
#define GNUTLS_COMPRESSION_ALG_LOOP(a) \
279
GNUTLS_COMPRESSION_LOOP( if(p->id == algorithm) { a; break; } )
280
#define GNUTLS_COMPRESSION_ALG_LOOP_NUM(a) \
281
GNUTLS_COMPRESSION_LOOP( if(p->num == num) { a; break; } )
284
264
/* Key Exchange Section */
697
677
* MAC algorithm, or %GNUTLS_MAC_UNKNOWN on failures.
699
679
gnutls_mac_algorithm_t
700
gnutls_mac_get_id (const char* name)
680
gnutls_mac_get_id (const char *name)
702
682
gnutls_mac_algorithm_t ret = GNUTLS_MAC_UNKNOWN;
704
GNUTLS_HASH_LOOP( if (strcasecmp( p->name, name)==0) ret = p->id);
684
GNUTLS_HASH_LOOP (if (strcasecmp (p->name, name) == 0) ret = p->id);
785
/* Compression Functions */
787
_gnutls_compression_priority (gnutls_session_t session,
788
gnutls_compression_method_t algorithm)
789
{ /* actually returns the priority */
792
i < session->internals.priorities.compression.algorithms; i++)
794
if (session->internals.priorities.
795
compression.priority[i] == algorithm)
802
* gnutls_compression_get_name - Returns a string with the name of the specified compression algorithm
803
* @algorithm: is a Compression algorithm
805
* Convert a #gnutls_compression_method_t value to a string.
807
* Returns: a pointer to a string that contains the name of the
808
* specified compression algorithm, or %NULL.
811
gnutls_compression_get_name (gnutls_compression_method_t algorithm)
813
const char *ret = NULL;
816
GNUTLS_COMPRESSION_ALG_LOOP (ret = p->name + sizeof ("GNUTLS_COMP_") - 1);
822
* gnutls_compression_get_id - Returns the gnutls id of the specified in string algorithm
823
* @algorithm: is a compression method name
825
* The names are compared in a case insensitive way.
827
* Returns: an id of the specified in a string compression method, or
828
* %GNUTLS_COMP_UNKNOWN on error.
830
gnutls_compression_method_t
831
gnutls_compression_get_id (const char* name)
833
gnutls_compression_method_t ret = GNUTLS_COMP_UNKNOWN;
835
GNUTLS_COMPRESSION_LOOP( if (strcasecmp( p->name+sizeof("GNUTLS_COMP_")-1, name)==0) ret = p->id);
841
* gnutls_compression_list - Get a list of supported compression methods
843
* Get a list of compression methods. Note that to be able to use LZO
844
* compression, you must link to libgnutls-extra and call
845
* gnutls_global_init_extra().
847
* Returns: a zero-terminated list of #gnutls_compression_method_t
848
* integers indicating the available compression methods.
850
const gnutls_compression_method_t *
851
gnutls_compression_list (void)
853
return supported_compressions;
856
/* return the tls number of the specified algorithm */
858
_gnutls_compression_get_num (gnutls_compression_method_t algorithm)
863
GNUTLS_COMPRESSION_ALG_LOOP (ret = p->num);
869
_gnutls_compression_get_wbits (gnutls_compression_method_t algorithm)
873
GNUTLS_COMPRESSION_ALG_LOOP (ret = p->window_bits);
878
_gnutls_compression_get_mem_level (gnutls_compression_method_t algorithm)
882
GNUTLS_COMPRESSION_ALG_LOOP (ret = p->mem_level);
887
_gnutls_compression_get_comp_level (gnutls_compression_method_t algorithm)
891
GNUTLS_COMPRESSION_ALG_LOOP (ret = p->comp_level);
895
/* returns the gnutls internal ID of the TLS compression
898
gnutls_compression_method_t
899
_gnutls_compression_get_id (int num)
901
gnutls_compression_method_t ret = -1;
904
GNUTLS_COMPRESSION_ALG_LOOP_NUM (ret = p->id);
910
_gnutls_compression_is_ok (gnutls_compression_method_t algorithm)
913
GNUTLS_COMPRESSION_ALG_LOOP (ret = p->id);
923
765
/* CIPHER functions */
925
767
_gnutls_cipher_get_block_size (gnutls_cipher_algorithm_t algorithm)
1023
863
* the specified cipher, or %GNUTLS_CIPHER_UNKNOWN on error.
1025
865
gnutls_cipher_algorithm_t
1026
gnutls_cipher_get_id (const char* name)
866
gnutls_cipher_get_id (const char *name)
1028
868
gnutls_cipher_algorithm_t ret = GNUTLS_CIPHER_UNKNOWN;
1030
GNUTLS_LOOP( if (strcasecmp( p->name, name)==0) ret = p->id);
870
GNUTLS_LOOP (if (strcasecmp (p->name, name) == 0) ret = p->id);
1257
* gnutls_protocol_get_id - Returns the gnutls id of the specified in string protocol
1258
* @algorithm: is a protocol name
1260
* The names are compared in a case insensitive way.
1262
* Returns: an id of the specified protocol, or
1263
* %GNUTLS_VERSION_UNKNOWN on error.
1097
* gnutls_protocol_get_id - Returns the gnutls id of the specified in string protocol
1098
* @name: is a protocol name
1100
* The names are compared in a case insensitive way.
1102
* Returns: an id of the specified protocol, or
1103
* %GNUTLS_VERSION_UNKNOWN on error.
1265
1105
gnutls_protocol_t
1266
gnutls_protocol_get_id (const char* name)
1106
gnutls_protocol_get_id (const char *name)
1268
1108
gnutls_protocol_t ret = GNUTLS_VERSION_UNKNOWN;
1270
GNUTLS_VERSION_LOOP( if (strcasecmp( p->name, name)==0) ret = p->id);
1110
GNUTLS_VERSION_LOOP (if (strcasecmp (p->name, name) == 0) ret = p->id);
1782
1622
return ret_count;
1786
/* For compression */
1788
#define MIN_PRIVATE_COMP_ALGO 0xEF
1790
/* returns the TLS numbers of the compression methods we support
1792
#define SUPPORTED_COMPRESSION_METHODS session->internals.priorities.compression.algorithms
1794
_gnutls_supported_compression_methods (gnutls_session_t session,
1799
*comp = gnutls_malloc (sizeof (uint8_t) * SUPPORTED_COMPRESSION_METHODS);
1801
return GNUTLS_E_MEMORY_ERROR;
1803
for (i = j = 0; i < SUPPORTED_COMPRESSION_METHODS; i++)
1805
int tmp = _gnutls_compression_get_num (session->internals.priorities.
1806
compression.priority[i]);
1808
/* remove private compression algorithms, if requested.
1810
if (tmp == -1 || (tmp >= MIN_PRIVATE_COMP_ALGO &&
1811
session->internals.enable_private == 0))
1817
(*comp)[j] = (uint8_t) tmp;
1824
gnutls_free (*comp);
1826
return GNUTLS_E_NO_COMPRESSION_ALGORITHMS;
1832
1626
* gnutls_certificate_type_get_name - Returns a string with the name of the specified certificate type
1833
1627
* @type: is a certificate type
1854
* gnutls_certificate_type_get_id - Returns the gnutls id of the specified in string type
1855
* @name: is a certificate type name
1857
* The names are compared in a case insensitive way.
1859
* Returns: an id of the specified in a string certificate type, or
1860
* %GNUTLS_CRT_UNKNOWN on error.
1648
* gnutls_certificate_type_get_id - Returns the gnutls id of the specified in string type
1649
* @name: is a certificate type name
1651
* The names are compared in a case insensitive way.
1653
* Returns: an #gnutls_certificate_type_t for the specified in a
1654
* string certificate type, or %GNUTLS_CRT_UNKNOWN on error.
1862
1656
gnutls_certificate_type_t
1863
gnutls_certificate_type_get_id (const char* name)
1657
gnutls_certificate_type_get_id (const char *name)
1865
1659
gnutls_certificate_type_t ret = GNUTLS_CRT_UNKNOWN;
1867
if (strcasecmp( name, "X.509")==0 || strcasecmp( name, "X509")==0)
1661
if (strcasecmp (name, "X.509") == 0 || strcasecmp (name, "X509") == 0)
1868
1662
return GNUTLS_CRT_X509;
1869
if (strcasecmp( name, "OPENPGP")==0)
1663
if (strcasecmp (name, "OPENPGP") == 0)
1870
1664
return GNUTLS_CRT_OPENPGP;
1792
* gnutls_sign_list - Get a list of supported public key signature algorithms
1794
* Get a list of supported public key signature algorithms.
1796
* Returns: a zero-terminated list of #gnutls_sign_algorithm_t
1797
* integers indicating the available ciphers.
1800
const gnutls_sign_algorithm_t *
1801
gnutls_sign_list (void)
1803
return supported_sign;
1807
* gnutls_sign_get_id - Returns the gnutls id of the specified in signature algorithm
1808
* @name: is a MAC algorithm name
1810
* The names are compared in a case insensitive way.
1812
* Returns: return a #gnutls_sign_algorithm_t value corresponding to
1813
* the specified cipher, or %GNUTLS_SIGN_UNKNOWN on error.
1815
gnutls_sign_algorithm_t
1816
gnutls_sign_get_id (const char *name)
1818
gnutls_sign_algorithm_t ret = GNUTLS_SIGN_UNKNOWN;
1820
GNUTLS_SIGN_LOOP (if (strcasecmp (p->name, name) == 0) ret = p->id);
1827
* gnutls_sign_get_name - Get name string for a #gnutls_sign_algorithm_t
1828
* @algorithm: is a public key signature algorithm
1830
* Convert a #gnutls_sign_algorithm_t value to a string.
1832
* Returns: a pointer to a string that contains the name of the
1833
* specified public key signature algorithm, or %NULL.
1838
gnutls_sign_get_name (gnutls_sign_algorithm_t algorithm)
1840
const char *ret = "SIGN_UNKNOWN";
1842
GNUTLS_SIGN_LOOP (if (p->id == algorithm) ret = p->name);
1984
1847
gnutls_sign_algorithm_t
1985
1848
_gnutls_x509_oid2sign_algorithm (const char *oid)
2052
* gnutls_pk_algorithm_get_name - Returns a string with the name of the specified public key algorithm
2053
* @algorithm: is a pk algorithm
2055
* Convert a #gnutls_pk_algorithm_t value to a string.
2057
* Returns: a string that contains the name of the specified public
2058
* key algorithm, or %NULL.
1915
* gnutls_pk_algorithm_get_name - Get string with name of public key algorithm
1916
* @algorithm: is a pk algorithm
1918
* Convert a #gnutls_pk_algorithm_t value to a string.
1920
* Returns: a string that contains the name of the specified public
1921
* key algorithm, or %NULL.
2061
1924
gnutls_pk_algorithm_get_name (gnutls_pk_algorithm_t algorithm)
1940
* gnutls_pk_list - Get a list of supported public key algorithms
1942
* Get a list of supported public key algorithms.
1944
* Returns: a zero-terminated list of #gnutls_pk_algorithm_t integers
1945
* indicating the available ciphers.
1949
const gnutls_pk_algorithm_t *
1950
gnutls_pk_list (void)
1952
static const gnutls_pk_algorithm_t supported_pks[] = {
1958
return supported_pks;
1962
* gnutls_pk_get_id - Get #gnutls_pk_algorithm_t from a string
1963
* @name: is a string containing a public key algorithm name.
1965
* Convert a string to a #gnutls_pk_algorithm_t value. The names are
1966
* compared in a case insensitive way. For example,
1967
* gnutls_pk_get_id("RSA") will return %GNUTLS_PK_RSA.
1969
* Returns: an #gnutls_pk_algorithm_tid of the specified in a string
1970
* public key algorithm, or %GNUTLS_PK_UNKNOWN on failures.
1974
gnutls_pk_algorithm_t
1975
gnutls_pk_get_id (const char *name)
1977
if (strcasecmp (name, "RSA") == 0)
1978
return GNUTLS_PK_RSA;
1979
else if (strcasecmp (name, "DSA") == 0)
1980
return GNUTLS_PK_DSA;
1982
return GNUTLS_PK_UNKNOWN;
1986
* gnutls_pk_get_name - Get name string with #gnutls_pk_algorithm_t algorithm
1987
* @algorithm: is a public key algorithm
1989
* Convert a #gnutls_pk_algorithm_t value to a string.
1991
* Returns: a pointer to a string that contains the name of the
1992
* specified public key algorithm, or %NULL.
1997
gnutls_pk_get_name (gnutls_pk_algorithm_t algorithm)
2012
case GNUTLS_PK_UNKNOWN:
2076
2020
gnutls_pk_algorithm_t
2077
2021
_gnutls_x509_oid2pk_algorithm (const char *oid)