Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1999 - 2005 Pekka Riikonen
+ Copyright (C) 1999 - 2006 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
*/
/* $Id$ */
-#include "silcincludes.h"
+#include "silc.h"
/* HMAC context */
struct SilcHmacStruct {
unsigned int allocated_hash : 1; /* TRUE if the hash was allocated */
};
-#ifndef SILC_EPOC
+#ifndef SILC_SYMBIAN
/* List of dynamically registered HMACs. */
SilcDList silc_hmac_list = NULL;
-#endif /* SILC_EPOC */
+#endif /* SILC_SYMBIAN */
/* Default hmacs for silc_hmac_register_default(). */
const SilcHmacObject silc_default_hmacs[] =
{
- { "hmac-sha1-96", 12 },
{ "hmac-sha256-96", 12 },
+ { "hmac-sha1-96", 12 },
{ "hmac-md5-96", 12 },
- { "hmac-sha1", 20 },
{ "hmac-sha256", 32 },
+ { "hmac-sha1", 20 },
{ "hmac-md5", 16 },
{ NULL, 0 }
{
SilcHash hash = hmac->hash;
SilcUInt32 block_len;
- unsigned char hvalue[20];
+ unsigned char hvalue[SILC_HASH_MAXLEN];
int i;
memset(hmac->inner_pad, 0, sizeof(hmac->inner_pad));
/* Registers a new HMAC into the SILC. This function is used at the
initialization of the SILC. */
-bool silc_hmac_register(const SilcHmacObject *hmac)
+SilcBool silc_hmac_register(const SilcHmacObject *hmac)
{
-#ifndef SILC_EPOC
+#ifndef SILC_SYMBIAN
SilcHmacObject *new;
SILC_LOG_DEBUG(("Registering new HMAC `%s'", hmac->name));
}
new = silc_calloc(1, sizeof(*new));
+ if (!new)
+ return FALSE;
new->name = strdup(hmac->name);
new->len = hmac->len;
silc_hmac_list = silc_dlist_init();
silc_dlist_add(silc_hmac_list, new);
-#endif /* SILC_EPOC */
+#endif /* SILC_SYMBIAN */
return TRUE;
}
/* Unregister a HMAC from the SILC. */
-bool silc_hmac_unregister(SilcHmacObject *hmac)
+SilcBool silc_hmac_unregister(SilcHmacObject *hmac)
{
-#ifndef SILC_EPOC
+#ifndef SILC_SYMBIAN
SilcHmacObject *entry;
SILC_LOG_DEBUG(("Unregistering HMAC"));
}
}
-#endif /* SILC_EPOC */
+#endif /* SILC_SYMBIAN */
return FALSE;
}
The application may use this to register the default hmacs if
specific hmacs in any specific order is not wanted. */
-bool silc_hmac_register_default(void)
+SilcBool silc_hmac_register_default(void)
{
-#ifndef SILC_EPOC
+#ifndef SILC_SYMBIAN
int i;
for (i = 0; silc_default_hmacs[i].name; i++)
silc_hmac_register(&(silc_default_hmacs[i]));
-#endif /* SILC_EPOC */
+#endif /* SILC_SYMBIAN */
return TRUE;
}
-bool silc_hmac_unregister_all(void)
+SilcBool silc_hmac_unregister_all(void)
{
-#ifndef SILC_EPOC
+#ifndef SILC_SYMBIAN
SilcHmacObject *entry;
if (!silc_hmac_list)
if (!silc_hmac_list)
break;
}
-#endif /* SILC_EPOC */
+#endif /* SILC_SYMBIAN */
return TRUE;
}
of the HMAC. If it is NULL then the hash function is allocated and
the name of the hash algorithm is derived from the `name'. */
-bool silc_hmac_alloc(const char *name, SilcHash hash, SilcHmac *new_hmac)
+SilcBool silc_hmac_alloc(const char *name, SilcHash hash, SilcHmac *new_hmac)
{
SILC_LOG_DEBUG(("Allocating new HMAC"));
/* Allocate the new object */
*new_hmac = silc_calloc(1, sizeof(**new_hmac));
+ if (!(*new_hmac))
+ return FALSE;
if (!hash) {
char *tmp = strdup(name), *hname;
(*new_hmac)->hash = hash;
-#ifndef SILC_EPOC
+#ifndef SILC_SYMBIAN
if (silc_hmac_list) {
SilcHmacObject *entry;
silc_dlist_start(silc_hmac_list);
}
}
}
-#endif /* SILC_EPOC */
+#endif /* SILC_SYMBIAN */
silc_free(*new_hmac);
*new_hmac = NULL;
/* Returns TRUE if HMAC `name' is supported. */
-bool silc_hmac_is_supported(const char *name)
+SilcBool silc_hmac_is_supported(const char *name)
{
-#ifndef SILC_EPOC
+#ifndef SILC_SYMBIAN
SilcHmacObject *entry;
if (!name)
if (!strcmp(silc_default_hmacs[i].name, name))
return TRUE;
}
-#endif /* SILC_EPOC */
+#endif /* SILC_SYMBIAN */
return FALSE;
}
char *list = NULL;
int len = 0;
-#ifndef SILC_EPOC
+#ifndef SILC_SYMBIAN
if (silc_hmac_list) {
silc_dlist_start(silc_hmac_list);
while ((entry = silc_dlist_get(silc_hmac_list)) != SILC_LIST_END) {
len++;
}
}
-#endif /* SILC_EPOC */
+#endif /* SILC_SYMBIAN */
list[len - 1] = 0;
memset(hmac->key, 0, hmac->key_len);
silc_free(hmac->key);
}
- hmac->key = silc_calloc(key_len, sizeof(unsigned char));
+ hmac->key = silc_malloc(key_len);
+ if (!hmac->key)
+ return;
hmac->key_len = key_len;
memcpy(hmac->key, key, key_len);
}
+/* Return HMAC key */
+
+const unsigned char *silc_hmac_get_key(SilcHmac hmac, SilcUInt32 *key_len)
+{
+ if (key_len)
+ *key_len = hmac->key_len;
+ return (const unsigned char *)hmac->key;
+}
+
/* Create the HMAC. This is thee make_hmac function pointer. This
uses the internal key set with silc_hmac_set_key. */
SilcUInt32 truncated_len,
unsigned char *return_hash)
{
- unsigned char hvalue[20];
+ unsigned char hvalue[SILC_HASH_MAXLEN];
SILC_LOG_DEBUG(("Making HMAC for message"));
SilcUInt32 *return_len)
{
SilcHash hash = hmac->hash;
- unsigned char mac[20];
+ unsigned char mac[SILC_HASH_MAXLEN];
silc_hash_final(hash, mac);
silc_hash_init(hash);