projects
/
silc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'topic/mm-fixes' of git://208.110.73.182/silc into silc.1.1.branch
[silc.git]
/
lib
/
silccrypt
/
silchmac.c
diff --git
a/lib/silccrypt/silchmac.c
b/lib/silccrypt/silchmac.c
index 2ec0160a08cec5f2d161aa7552ee3dac1a8da035..1e9380dbfd1e9a57c1bd26ccca21fcbaab823972 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
6
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,10
+31,10
@@
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[] =
/* Default hmacs for silc_hmac_register_default(). */
const SilcHmacObject silc_default_hmacs[] =
@@
-54,7
+54,7
@@
static void silc_hmac_init_internal(SilcHmac hmac, unsigned char *key,
{
SilcHash hash = hmac->hash;
SilcUInt32 block_len;
{
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));
int i;
memset(hmac->inner_pad, 0, sizeof(hmac->inner_pad));
@@
-84,9
+84,9
@@
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 into the SILC. This function is used at the
initialization of the SILC. */
-
b
ool silc_hmac_register(const SilcHmacObject *hmac)
+
SilcB
ool 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
+102,8
@@
bool 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
+112,15
@@
bool 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;
}
/* Unregister a HMAC from the SILC. */
return TRUE;
}
/* Unregister a HMAC from the SILC. */
-
b
ool silc_hmac_unregister(SilcHmacObject *hmac)
+
SilcB
ool 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,7
+144,7
@@
bool silc_hmac_unregister(SilcHmacObject *hmac)
}
}
}
}
-#endif /* SILC_
EPOC
*/
+#endif /* SILC_
SYMBIAN
*/
return FALSE;
}
return FALSE;
}
@@
-150,21
+152,21
@@
bool silc_hmac_unregister(SilcHmacObject *hmac)
The application may use this to register the default hmacs if
specific hmacs in any specific order is not wanted. */
The application may use this to register the default hmacs if
specific hmacs in any specific order is not wanted. */
-
b
ool silc_hmac_register_default(void)
+
SilcB
ool 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]));
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;
}
return TRUE;
}
-
b
ool silc_hmac_unregister_all(void)
+
SilcB
ool 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
+178,7
@@
bool 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;
}
@@
-185,12
+187,14
@@
bool silc_hmac_unregister_all(void)
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'. */
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'. */
-
b
ool silc_hmac_alloc(const char *name, SilcHash hash, SilcHmac *new_hmac)
+
SilcB
ool 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));
{
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,7
+218,7
@@
bool 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
if (silc_hmac_list) {
SilcHmacObject *entry;
silc_dlist_start(silc_hmac_list);
if (silc_hmac_list) {
SilcHmacObject *entry;
silc_dlist_start(silc_hmac_list);
@@
-236,7
+240,7
@@
bool silc_hmac_alloc(const char *name, SilcHash hash, SilcHmac *new_hmac)
}
}
}
}
}
}
-#endif /* SILC_
EPOC
*/
+#endif /* SILC_
SYMBIAN
*/
silc_free(*new_hmac);
*new_hmac = NULL;
silc_free(*new_hmac);
*new_hmac = NULL;
@@
-283,9
+287,9
@@
const char *silc_hmac_get_name(SilcHmac hmac)
/* Returns TRUE if HMAC `name' is supported. */
/* Returns TRUE if HMAC `name' is supported. */
-
b
ool silc_hmac_is_supported(const char *name)
+
SilcB
ool silc_hmac_is_supported(const char *name)
{
{
-#ifndef SILC_
EPOC
+#ifndef SILC_
SYMBIAN
SilcHmacObject *entry;
if (!name)
SilcHmacObject *entry;
if (!name)
@@
-305,7
+309,7
@@
bool silc_hmac_is_supported(const char *name)
if (!strcmp(silc_default_hmacs[i].name, name))
return TRUE;
}
if (!strcmp(silc_default_hmacs[i].name, name))
return TRUE;
}
-#endif /* SILC_
EPOC
*/
+#endif /* SILC_
SYMBIAN
*/
return FALSE;
}
return FALSE;
}
@@
-317,7
+321,7
@@
char *silc_hmac_get_supported()
char *list = NULL;
int len = 0;
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) {
if (silc_hmac_list) {
silc_dlist_start(silc_hmac_list);
while ((entry = silc_dlist_get(silc_hmac_list)) != SILC_LIST_END) {
@@
-344,7
+348,7
@@
char *silc_hmac_get_supported()
len++;
}
}
len++;
}
}
-#endif /* SILC_
EPOC
*/
+#endif /* SILC_
SYMBIAN
*/
list[len - 1] = 0;
list[len - 1] = 0;
@@
-360,11
+364,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. */
@@
-405,7
+420,7
@@
void silc_hmac_make_truncated(SilcHmac hmac, unsigned char *data,
SilcUInt32 truncated_len,
unsigned char *return_hash)
{
SilcUInt32 truncated_len,
unsigned char *return_hash)
{
- unsigned char hvalue[
20
];
+ unsigned char hvalue[
SILC_HASH_MAXLEN
];
SILC_LOG_DEBUG(("Making HMAC for message"));
SILC_LOG_DEBUG(("Making HMAC for message"));
@@
-449,7
+464,7
@@
void silc_hmac_final(SilcHmac hmac, unsigned char *return_hash,
SilcUInt32 *return_len)
{
SilcHash hash = hmac->hash;
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);
silc_hash_final(hash, mac);
silc_hash_init(hash);