projects
/
silc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added SILC Thread Queue API
[silc.git]
/
lib
/
silccrypt
/
silchmac.c
diff --git
a/lib/silccrypt/silchmac.c
b/lib/silccrypt/silchmac.c
index 56e3bc80bd212ece6d7910af3457fd6dfb7fb948..86754f230c977682c5ce2547ec94c94f25586d39 100644
(file)
--- a/
lib/silccrypt/silchmac.c
+++ b/
lib/silccrypt/silchmac.c
@@
-4,7
+4,7
@@
Author: Pekka Riikonen <priikone@silcnet.org>
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1999 - 200
5
Pekka Riikonen
+ Copyright (C) 1999 - 200
7
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
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
@@
-18,7
+18,7
@@
*/
/* $Id$ */
*/
/* $Id$ */
-#include "silc
includes
.h"
+#include "silc.h"
/* HMAC context */
struct SilcHmacStruct {
/* HMAC context */
struct SilcHmacStruct {
@@
-31,18
+31,20
@@
struct SilcHmacStruct {
unsigned int allocated_hash : 1; /* TRUE if the hash was allocated */
};
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;
/* 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-sha256-96", 12 },
/* Default hmacs for silc_hmac_register_default(). */
const SilcHmacObject silc_default_hmacs[] =
{
{ "hmac-sha256-96", 12 },
+ { "hmac-sha512-96", 12 },
{ "hmac-sha1-96", 12 },
{ "hmac-md5-96", 12 },
{ "hmac-sha256", 32 },
{ "hmac-sha1-96", 12 },
{ "hmac-md5-96", 12 },
{ "hmac-sha256", 32 },
+ { "hmac-sha512", 64 },
{ "hmac-sha1", 20 },
{ "hmac-md5", 16 },
{ "hmac-sha1", 20 },
{ "hmac-md5", 16 },
@@
-81,12
+83,11
@@
static void silc_hmac_init_internal(SilcHmac hmac, unsigned char *key,
}
}
}
}
-/* Registers a new HMAC into the SILC. This function is used at the
- initialization of the SILC. */
+/* Registers a new HMAC */
SilcBool 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));
SilcHmacObject *new;
SILC_LOG_DEBUG(("Registering new HMAC `%s'", hmac->name));
@@
-102,6
+103,8
@@
SilcBool silc_hmac_register(const SilcHmacObject *hmac)
}
new = silc_calloc(1, sizeof(*new));
}
new = silc_calloc(1, sizeof(*new));
+ if (!new)
+ return FALSE;
new->name = strdup(hmac->name);
new->len = hmac->len;
new->name = strdup(hmac->name);
new->len = hmac->len;
@@
-110,15
+113,15
@@
SilcBool silc_hmac_register(const SilcHmacObject *hmac)
silc_hmac_list = silc_dlist_init();
silc_dlist_add(silc_hmac_list, new);
silc_hmac_list = silc_dlist_init();
silc_dlist_add(silc_hmac_list, new);
-#endif /* SILC_
EPOC
*/
+#endif /* SILC_
SYMBIAN
*/
return TRUE;
}
return TRUE;
}
-/* Unregister a HMAC
from the SILC.
*/
+/* Unregister a HMAC */
SilcBool silc_hmac_unregister(SilcHmacObject *hmac)
{
SilcBool silc_hmac_unregister(SilcHmacObject *hmac)
{
-#ifndef SILC_
EPOC
+#ifndef SILC_
SYMBIAN
SilcHmacObject *entry;
SILC_LOG_DEBUG(("Unregistering HMAC"));
SilcHmacObject *entry;
SILC_LOG_DEBUG(("Unregistering HMAC"));
@@
-142,29
+145,23
@@
SilcBool silc_hmac_unregister(SilcHmacObject *hmac)
}
}
}
}
-#endif /* SILC_
EPOC
*/
+#endif /* SILC_
SYMBIAN
*/
return FALSE;
}
return FALSE;
}
-/* Function that registers all the default hmacs (all builtin ones).
- The application may use this to register the default hmacs if
- specific hmacs in any specific order is not wanted. */
+/* Register default HMACs */
SilcBool silc_hmac_register_default(void)
{
SilcBool silc_hmac_register_default(void)
{
-#ifndef SILC_EPOC
- int i;
-
- for (i = 0; silc_default_hmacs[i].name; i++)
- silc_hmac_register(&(silc_default_hmacs[i]));
-
-#endif /* SILC_EPOC */
+ /* We use builtin HMACs */
return TRUE;
}
return TRUE;
}
+/* Unregister all HMACs */
+
SilcBool silc_hmac_unregister_all(void)
{
SilcBool silc_hmac_unregister_all(void)
{
-#ifndef SILC_
EPOC
+#ifndef SILC_
SYMBIAN
SilcHmacObject *entry;
if (!silc_hmac_list)
SilcHmacObject *entry;
if (!silc_hmac_list)
@@
-176,7
+173,7
@@
SilcBool silc_hmac_unregister_all(void)
if (!silc_hmac_list)
break;
}
if (!silc_hmac_list)
break;
}
-#endif /* SILC_
EPOC
*/
+#endif /* SILC_
SYMBIAN
*/
return TRUE;
}
return TRUE;
}
@@
-187,10
+184,15
@@
SilcBool silc_hmac_unregister_all(void)
SilcBool silc_hmac_alloc(const char *name, SilcHash hash, SilcHmac *new_hmac)
{
SilcBool silc_hmac_alloc(const char *name, SilcHash hash, SilcHmac *new_hmac)
{
+ SilcHmacObject *entry = NULL;
+ int i;
+
SILC_LOG_DEBUG(("Allocating new HMAC"));
/* Allocate the new object */
*new_hmac = silc_calloc(1, sizeof(**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;
if (!hash) {
char *tmp = strdup(name), *hname;
@@
-214,9
+216,9
@@
SilcBool silc_hmac_alloc(const char *name, SilcHash hash, SilcHmac *new_hmac)
(*new_hmac)->hash = hash;
(*new_hmac)->hash = hash;
-#ifndef SILC_EPOC
+#ifndef SILC_SYMBIAN
+ /* Check registered list of HMACs */
if (silc_hmac_list) {
if (silc_hmac_list) {
- SilcHmacObject *entry;
silc_dlist_start(silc_hmac_list);
while ((entry = silc_dlist_get(silc_hmac_list)) != SILC_LIST_END) {
if (!strcmp(entry->name, name)) {
silc_dlist_start(silc_hmac_list);
while ((entry = silc_dlist_get(silc_hmac_list)) != SILC_LIST_END) {
if (!strcmp(entry->name, name)) {
@@
-225,10
+227,10
@@
SilcBool silc_hmac_alloc(const char *name, SilcHash hash, SilcHmac *new_hmac)
}
}
}
}
}
}
-#e
lse
- {
- /* On EPOC which don't have globals we check our constant hash list. */
- int i;
+#e
ndif /* SILC_SYMBIAN */
+
+ if (!entry) {
+ /* Check builtin list of HMACs */
for (i = 0; silc_default_hmacs[i].name; i++) {
if (!strcmp(silc_default_hmacs[i].name, name)) {
(*new_hmac)->hmac = (SilcHmacObject *)&(silc_default_hmacs[i]);
for (i = 0; silc_default_hmacs[i].name; i++) {
if (!strcmp(silc_default_hmacs[i].name, name)) {
(*new_hmac)->hmac = (SilcHmacObject *)&(silc_default_hmacs[i]);
@@
-236,7
+238,6
@@
SilcBool silc_hmac_alloc(const char *name, SilcHash hash, SilcHmac *new_hmac)
}
}
}
}
}
}
-#endif /* SILC_EPOC */
silc_free(*new_hmac);
*new_hmac = NULL;
silc_free(*new_hmac);
*new_hmac = NULL;
@@
-285,12
+286,13
@@
const char *silc_hmac_get_name(SilcHmac hmac)
SilcBool silc_hmac_is_supported(const char *name)
{
SilcBool silc_hmac_is_supported(const char *name)
{
-#ifndef SILC_EPOC
SilcHmacObject *entry;
SilcHmacObject *entry;
+ int i;
if (!name)
return FALSE;
if (!name)
return FALSE;
+#ifndef SILC_SYMBIAN
if (silc_hmac_list) {
silc_dlist_start(silc_hmac_list);
while ((entry = silc_dlist_get(silc_hmac_list)) != SILC_LIST_END) {
if (silc_hmac_list) {
silc_dlist_start(silc_hmac_list);
while ((entry = silc_dlist_get(silc_hmac_list)) != SILC_LIST_END) {
@@
-298,14
+300,12
@@
SilcBool silc_hmac_is_supported(const char *name)
return TRUE;
}
}
return TRUE;
}
}
-#else
- {
- int i;
- for (i = 0; silc_default_hmacs[i].name; i++)
- if (!strcmp(silc_default_hmacs[i].name, name))
- return TRUE;
- }
-#endif /* SILC_EPOC */
+#endif /* SILC_SYMBIAN */
+
+ for (i = 0; silc_default_hmacs[i].name; i++)
+ if (!strcmp(silc_default_hmacs[i].name, name))
+ return TRUE;
+
return FALSE;
}
return FALSE;
}
@@
-313,11
+313,11
@@
SilcBool silc_hmac_is_supported(const char *name)
char *silc_hmac_get_supported()
{
char *silc_hmac_get_supported()
{
- SilcHmacObject *entry;
+ SilcHmacObject *entry
, *entry2
;
char *list = NULL;
char *list = NULL;
- int len = 0;
+ int len = 0
, i
;
-#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) {
if (silc_hmac_list) {
silc_dlist_start(silc_hmac_list);
while ((entry = silc_dlist_get(silc_hmac_list)) != SILC_LIST_END) {
@@
-330,21
+330,30
@@
char *silc_hmac_get_supported()
len++;
}
}
len++;
}
}
-#else
- {
- int i;
- for (i = 0; silc_default_hmacs[i].name; i++) {
- entry = (SilcHmacObject *)&(silc_default_hmacs[i]);
- len += strlen(entry->name);
- list = silc_realloc(list, len + 1);
+#endif /* SILC_SYMBIAN */
- memcpy(list + (len - strlen(entry->name)),
- entry->name, strlen(entry->name));
- memcpy(list + len, ",", 1);
- len++;
+
+ for (i = 0; silc_default_hmacs[i].name; i++) {
+ entry = (SilcHmacObject *)&(silc_default_hmacs[i]);
+
+ if (silc_hmac_list) {
+ silc_dlist_start(silc_hmac_list);
+ while ((entry2 = silc_dlist_get(silc_hmac_list)) != SILC_LIST_END) {
+ if (!strcmp(entry2->name, entry->name))
+ break;
+ }
+ if (entry2)
+ continue;
}
}
+
+ len += strlen(entry->name);
+ list = silc_realloc(list, len + 1);
+
+ memcpy(list + (len - strlen(entry->name)),
+ entry->name, strlen(entry->name));
+ memcpy(list + len, ",", 1);
+ len++;
}
}
-#endif /* SILC_EPOC */
list[len - 1] = 0;
list[len - 1] = 0;
@@
-360,11
+369,22
@@
void silc_hmac_set_key(SilcHmac hmac, const unsigned char *key,
memset(hmac->key, 0, hmac->key_len);
silc_free(hmac->key);
}
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);
}
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. */
/* Create the HMAC. This is thee make_hmac function pointer. This
uses the internal key set with silc_hmac_set_key. */