~mdw
/
disorder
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Buffered socket IO wrappers
[disorder]
/
lib
/
authhash.c
diff --git
a/lib/authhash.c
b/lib/authhash.c
index
1eaf27f
..
78352da
100644
(file)
--- a/
lib/authhash.c
+++ b/
lib/authhash.c
@@
-1,30
+1,30
@@
/*
* This file is part of DisOrder
/*
* This file is part of DisOrder
- * Copyright (C) 2004, 2006 Richard Kettlewell
+ * Copyright (C) 2004, 2006
, 2007, 2009, 2013
Richard Kettlewell
*
*
- * This program is free software
;
you can redistribute it and/or modify
+ * 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
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation
; either version 2
of the License, or
+ * the Free Software Foundation
, either version 3
of the License, or
* (at your option) any later version.
* (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU
- * General Public License for more details.
- *
+ *
+ * This program is distributed in the hope that it will be useful,
+ *
but
WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * G
NU G
eneral Public License for more details.
+ *
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file lib/authhash.c @brief The authorization hash */
*/
/** @file lib/authhash.c @brief The authorization hash */
-#include <config.h>
-#include "types.h"
+#include "common.h"
#include <stddef.h>
#include <stddef.h>
-#include <gcrypt.h>
-#include <assert.h>
+#if HAVE_GCRYPT_H
+# include <gcrypt.h>
+#else
+# error No crypto API available
+#endif
#include "hex.h"
#include "log.h"
#include "hex.h"
#include "log.h"
@@
-32,8
+32,14
@@
/** @brief Structure of algorithm lookup table */
struct algorithm {
/** @brief Structure of algorithm lookup table */
struct algorithm {
+ /** @brief DisOrder algorithm name */
const char *name;
const char *name;
+
+#if HAVE_GCRYPT_H
+ /** @brief gcrypt algorithm ID */
int id;
int id;
+#endif
+
};
/** @brief Algorithm lookup table
};
/** @brief Algorithm lookup table
@@
-42,6
+48,7
@@
struct algorithm {
* the disorder protocol.
*/
static const struct algorithm algorithms[] = {
* the disorder protocol.
*/
static const struct algorithm algorithms[] = {
+#if HAVE_GCRYPT_H
{ "SHA1", GCRY_MD_SHA1 },
{ "sha1", GCRY_MD_SHA1 },
{ "SHA256", GCRY_MD_SHA256 },
{ "SHA1", GCRY_MD_SHA1 },
{ "sha1", GCRY_MD_SHA1 },
{ "SHA256", GCRY_MD_SHA256 },
@@
-50,6
+57,7
@@
static const struct algorithm algorithms[] = {
{ "sha384", GCRY_MD_SHA384 },
{ "SHA512", GCRY_MD_SHA512 },
{ "sha512", GCRY_MD_SHA512 },
{ "sha384", GCRY_MD_SHA384 },
{ "SHA512", GCRY_MD_SHA512 },
{ "sha512", GCRY_MD_SHA512 },
+#endif
};
/** @brief Number of supported algorithms */
};
/** @brief Number of supported algorithms */
@@
-60,16
+68,19
@@
static const struct algorithm algorithms[] = {
* @param nchallenge Size of challenge
* @param password Password
* @param algo Algorithm to use
* @param nchallenge Size of challenge
* @param password Password
* @param algo Algorithm to use
+ * @return Hex string or NULL on error
*
* Computes H(challenge|password) and returns it as a newly allocated hex
* string, or returns NULL on error.
*/
*
* Computes H(challenge|password) and returns it as a newly allocated hex
* string, or returns NULL on error.
*/
-const char *authhash(const void *challenge, size_t nchallenge,
- const char *password, const char *algo) {
+char *authhash(const void *challenge, size_t nchallenge,
+ const char *password, const char *algo) {
+#if HAVE_GCRYPT_H
gcrypt_hash_handle h;
gcrypt_hash_handle h;
- const char *res;
- size_t n;
int id;
int id;
+#endif
+ char *res;
+ size_t n;
assert(challenge != 0);
assert(password != 0);
assert(challenge != 0);
assert(password != 0);
@@
-79,13
+90,14
@@
const char *authhash(const void *challenge, size_t nchallenge,
break;
if(n >= NALGORITHMS)
return NULL;
break;
if(n >= NALGORITHMS)
return NULL;
+#if HAVE_GCRYPT_H
id = algorithms[n].id;
#if HAVE_GCRY_ERROR_T
{
gcry_error_t e;
if((e = gcry_md_open(&h, id, 0))) {
id = algorithms[n].id;
#if HAVE_GCRY_ERROR_T
{
gcry_error_t e;
if((e = gcry_md_open(&h, id, 0))) {
- error(0, "gcry_md_open: %s", gcry_strerror(e));
+
disorder_
error(0, "gcry_md_open: %s", gcry_strerror(e));
return 0;
}
}
return 0;
}
}
@@
-96,6
+108,7
@@
const char *authhash(const void *challenge, size_t nchallenge,
gcry_md_write(h, challenge, nchallenge);
res = hex(gcry_md_read(h, id), gcry_md_get_algo_dlen(id));
gcry_md_close(h);
gcry_md_write(h, challenge, nchallenge);
res = hex(gcry_md_read(h, id), gcry_md_get_algo_dlen(id));
gcry_md_close(h);
+#endif
return res;
}
return res;
}