summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2002-06-21 08:34:40 +0000
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2002-06-21 08:34:40 +0000
commit97afb82e102142494173f55b35c6ef7d2687b90d (patch)
treee46ddd1be0322e0ca051a0c60b977cb95d637199
parent7c3cf260f7acdeb847a9bacff1142846d019e6c7 (diff)
downloadgnutls-97afb82e102142494173f55b35c6ef7d2687b90d.tar.gz
Exported gnutls_cipher_get_key_size(). Better name printing for MAC algorithms.
-rw-r--r--lib/gnutls.h.in.in10
-rw-r--r--lib/gnutls_algorithms.c18
-rw-r--r--lib/gnutls_algorithms.h2
-rw-r--r--lib/gnutls_constate.c4
-rw-r--r--lib/gnutls_int.h4
5 files changed, 28 insertions, 10 deletions
diff --git a/lib/gnutls.h.in.in b/lib/gnutls.h.in.in
index b1f3510536..247b1e0096 100644
--- a/lib/gnutls.h.in.in
+++ b/lib/gnutls.h.in.in
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000,2001,2002 Nikos Mavroyanopoulos
+ * Copyright (C) 2000,2001,2002 Nikos Mavroyanopoulos
*
* This file is part of GNUTLS.
*
@@ -43,6 +43,12 @@ typedef enum GNUTLS_CredType { GNUTLS_CRD_CERTIFICATE=1, GNUTLS_CRD_ANON, GNUTLS
typedef enum GNUTLS_MACAlgorithm { GNUTLS_MAC_NULL=1, GNUTLS_MAC_MD5, GNUTLS_MAC_SHA } GNUTLS_MACAlgorithm;
typedef enum GNUTLS_DigestAlgorithm { GNUTLS_DIG_NULL=1, GNUTLS_DIG_MD5, GNUTLS_DIG_SHA } GNUTLS_DigestAlgorithm;
+
+/* exported for other gnutls headers. This is the maximum number
+ * of algorithms (ciphers, kx or macs).
+ */
+#define GNUTLS_MAX_ALGORITHM_NUM 8
+
typedef enum GNUTLS_CompressionMethod { GNUTLS_COMP_NULL=1, GNUTLS_COMP_ZLIB } GNUTLS_CompressionMethod;
typedef enum GNUTLS_ConnectionEnd { GNUTLS_SERVER=1, GNUTLS_CLIENT } GNUTLS_ConnectionEnd;
typedef enum GNUTLS_AlertLevel { GNUTLS_AL_WARNING=1, GNUTLS_AL_FATAL } GNUTLS_AlertLevel;
@@ -124,6 +130,8 @@ GNUTLS_MACAlgorithm gnutls_mac_get( GNUTLS_STATE state);
GNUTLS_CompressionMethod gnutls_compression_get( GNUTLS_STATE state);
GNUTLS_CertificateType gnutls_cert_type_get( GNUTLS_STATE state);
+size_t gnutls_cipher_get_key_size(BulkCipherAlgorithm algorithm);
+
/* the name of the specified algorithms */
const char *gnutls_cipher_get_name( GNUTLS_BulkCipherAlgorithm);
const char *gnutls_mac_get_name( GNUTLS_MACAlgorithm);
diff --git a/lib/gnutls_algorithms.c b/lib/gnutls_algorithms.c
index 2ac87427b8..05f4ed69e7 100644
--- a/lib/gnutls_algorithms.c
+++ b/lib/gnutls_algorithms.c
@@ -106,8 +106,8 @@ static const gnutls_cipher_entry algorithms[] = {
GNUTLS_LOOP( if(p->id == algorithm) { a; break; } )
-#define GNUTLS_HASH_ENTRY(name, hashsize) \
- { #name, name, hashsize }
+#define GNUTLS_HASH_ENTRY(strname, name, hashsize) \
+ { strname, name, hashsize }
struct gnutls_hash_entry {
char *name;
@@ -117,9 +117,9 @@ struct gnutls_hash_entry {
typedef struct gnutls_hash_entry gnutls_hash_entry;
static const gnutls_hash_entry hash_algorithms[] = {
- GNUTLS_HASH_ENTRY(GNUTLS_MAC_SHA, 20),
- GNUTLS_HASH_ENTRY(GNUTLS_MAC_MD5, 16),
- GNUTLS_HASH_ENTRY(GNUTLS_MAC_NULL, 0),
+ GNUTLS_HASH_ENTRY("SHA", GNUTLS_MAC_SHA, 20),
+ GNUTLS_HASH_ENTRY("MD5", GNUTLS_MAC_MD5, 16),
+ GNUTLS_HASH_ENTRY("NULL", GNUTLS_MAC_NULL, 0),
{0}
};
@@ -558,7 +558,13 @@ int _gnutls_cipher_is_block(BulkCipherAlgorithm algorithm)
}
-int _gnutls_cipher_get_key_size(BulkCipherAlgorithm algorithm)
+/**
+ * gnutls_cipher_get_key_size - Returns the length of the cipher's key size
+ * @algorithm: is an encryption algorithm
+ *
+ * Returns the length (in bytes) of the given cipher's key size.
+ **/
+size_t gnutls_cipher_get_key_size(BulkCipherAlgorithm algorithm)
{ /* In bytes */
size_t ret = 0;
GNUTLS_ALG_LOOP(ret = p->keysize);
diff --git a/lib/gnutls_algorithms.h b/lib/gnutls_algorithms.h
index 2209a3b263..bc095369a1 100644
--- a/lib/gnutls_algorithms.h
+++ b/lib/gnutls_algorithms.h
@@ -53,7 +53,7 @@ int _gnutls_cipher_priority(GNUTLS_STATE state, BulkCipherAlgorithm algorithm);
int _gnutls_cipher_get_block_size(BulkCipherAlgorithm algorithm);
int _gnutls_cipher_is_block(BulkCipherAlgorithm algorithm);
int _gnutls_cipher_is_ok(BulkCipherAlgorithm algorithm);
-int _gnutls_cipher_get_key_size(BulkCipherAlgorithm algorithm);
+size_t gnutls_cipher_get_key_size(BulkCipherAlgorithm algorithm);
int _gnutls_cipher_get_iv_size(BulkCipherAlgorithm algorithm);
const char *gnutls_cipher_get_name(BulkCipherAlgorithm algorithm);
diff --git a/lib/gnutls_constate.c b/lib/gnutls_constate.c
index eb94db5e77..ae4630c703 100644
--- a/lib/gnutls_constate.c
+++ b/lib/gnutls_constate.c
@@ -140,7 +140,7 @@ int _gnutls_set_read_keys(GNUTLS_STATE state)
hash_size = _gnutls_mac_get_digest_size( mac_algo);
IV_size = _gnutls_cipher_get_iv_size( algo);
- key_size = _gnutls_cipher_get_key_size( algo);
+ key_size = gnutls_cipher_get_key_size( algo);
return _gnutls_set_keys( state, hash_size, IV_size, key_size);
}
@@ -158,7 +158,7 @@ int _gnutls_set_write_keys(GNUTLS_STATE state)
hash_size = _gnutls_mac_get_digest_size( mac_algo);
IV_size = _gnutls_cipher_get_iv_size( algo);
- key_size = _gnutls_cipher_get_key_size( algo);
+ key_size = gnutls_cipher_get_key_size( algo);
return _gnutls_set_keys( state, hash_size, IV_size, key_size);
}
diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h
index f7cfb796eb..75de283072 100644
--- a/lib/gnutls_int.h
+++ b/lib/gnutls_int.h
@@ -141,7 +141,11 @@ typedef struct {
} gnutls_datum;
typedef gnutls_datum gnutls_sdatum;
+/* This is the maximum number of algorithms (ciphers or macs etc).
+ * keep it synced with GNUTLS_MAX_ALGORITHM_NUM in gnutls.h
+ */
#define MAX_ALGOS 8
+
#define MAX_CIPHERSUITES 256
/* STATE */