projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Replace pointers to cipher_t/digest_t in connection_t with structs.
[tinc]
/
src
/
gcrypt
/
digest.c
diff --git
a/src/gcrypt/digest.c
b/src/gcrypt/digest.c
index
a845afa
..
ad1f31d
100644
(file)
--- a/
src/gcrypt/digest.c
+++ b/
src/gcrypt/digest.c
@@
-1,6
+1,6
@@
/*
digest.c -- Digest handling
/*
digest.c -- Digest handling
- Copyright (C) 2007 Guus Sliepen <guus@tinc-vpn.org>
+ Copyright (C) 2007
-2012
Guus Sliepen <guus@tinc-vpn.org>
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
@@
-24,7
+24,7
@@
static struct {
const char *name;
static struct {
const char *name;
-
int
algo;
+
enum gcry_md_algos
algo;
int nid;
} digesttable[] = {
{"none", GCRY_MD_NONE, 0},
int nid;
} digesttable[] = {
{"none", GCRY_MD_NONE, 0},
@@
-34,10
+34,10
@@
static struct {
{"sha512", GCRY_MD_SHA512, 674},
};
{"sha512", GCRY_MD_SHA512, 674},
};
-static bool nametodigest(const char *name,
int
*algo) {
+static bool nametodigest(const char *name,
enum gcry_md_algos
*algo) {
int i;
int i;
- for(i = 0; i < sizeof
digesttable / sizeof *digesttable
; i++) {
+ for(i = 0; i < sizeof
(digesttable) / sizeof(*digesttable)
; i++) {
if(digesttable[i].name && !strcasecmp(name, digesttable[i].name)) {
*algo = digesttable[i].algo;
return true;
if(digesttable[i].name && !strcasecmp(name, digesttable[i].name)) {
*algo = digesttable[i].algo;
return true;
@@
-47,10
+47,8
@@
static bool nametodigest(const char *name, int *algo) {
return false;
}
return false;
}
-static bool nidtodigest(int nid, int *algo) {
- int i;
-
- for(i = 0; i < sizeof digesttable / sizeof *digesttable; i++) {
+static bool nidtodigest(int nid, enum gcry_md_algos *algo) {
+ for(int i = 0; i < sizeof(digesttable) / sizeof(*digesttable); i++) {
if(nid == digesttable[i].nid) {
*algo = digesttable[i].algo;
return true;
if(nid == digesttable[i].nid) {
*algo = digesttable[i].algo;
return true;
@@
-60,10
+58,8
@@
static bool nidtodigest(int nid, int *algo) {
return false;
}
return false;
}
-static bool digesttonid(int algo, int *nid) {
- int i;
-
- for(i = 0; i < sizeof digesttable / sizeof *digesttable; i++) {
+static bool digesttonid(enum gcry_md_algos algo, int *nid) {
+ for(int i = 0; i < sizeof(digesttable) / sizeof(*digesttable); i++) {
if(algo == digesttable[i].algo) {
*nid = digesttable[i].nid;
return true;
if(algo == digesttable[i].algo) {
*nid = digesttable[i].nid;
return true;
@@
-73,7
+69,7
@@
static bool digesttonid(int algo, int *nid) {
return false;
}
return false;
}
-static bool digest_open(digest_t *digest,
int algo, in
t maclength) {
+static bool digest_open(digest_t *digest,
enum gcry_md_algos algo, size_
t maclength) {
if(!digesttonid(algo, &digest->nid)) {
logger(DEBUG_ALWAYS, LOG_DEBUG, "Digest %d has no corresponding nid!", algo);
return false;
if(!digesttonid(algo, &digest->nid)) {
logger(DEBUG_ALWAYS, LOG_DEBUG, "Digest %d has no corresponding nid!", algo);
return false;
@@
-81,19
+77,20
@@
static bool digest_open(digest_t *digest, int algo, int maclength) {
unsigned int len = gcry_md_get_algo_dlen(algo);
unsigned int len = gcry_md_get_algo_dlen(algo);
- if(maclength > len || maclength < 0)
+ if(maclength > len || maclength < 0)
{
digest->maclength = len;
digest->maclength = len;
- else
+ } else {
digest->maclength = maclength;
digest->maclength = maclength;
-
+ }
+
digest->algo = algo;
digest->hmac = NULL;
return true;
}
digest->algo = algo;
digest->hmac = NULL;
return true;
}
-bool digest_open_by_name(digest_t *digest, const char *name,
in
t maclength) {
-
int
algo;
+bool digest_open_by_name(digest_t *digest, const char *name,
size_
t maclength) {
+
enum gcry_md_algos
algo;
if(!nametodigest(name, &algo)) {
logger(DEBUG_ALWAYS, LOG_DEBUG, "Unknown digest name '%s'!", name);
if(!nametodigest(name, &algo)) {
logger(DEBUG_ALWAYS, LOG_DEBUG, "Unknown digest name '%s'!", name);
@@
-103,8
+100,8
@@
bool digest_open_by_name(digest_t *digest, const char *name, int maclength) {
return digest_open(digest, algo, maclength);
}
return digest_open(digest, algo, maclength);
}
-bool digest_open_by_nid(digest_t *digest, int nid,
in
t maclength) {
-
int
algo;
+bool digest_open_by_nid(digest_t *digest, int nid,
size_
t maclength) {
+
enum gcry_md_algos
algo;
if(!nidtodigest(nid, &algo)) {
logger(DEBUG_ALWAYS, LOG_DEBUG, "Unknown digest ID %d!", nid);
if(!nidtodigest(nid, &algo)) {
logger(DEBUG_ALWAYS, LOG_DEBUG, "Unknown digest ID %d!", nid);
@@
-114,21
+111,26
@@
bool digest_open_by_nid(digest_t *digest, int nid, int maclength) {
return digest_open(digest, algo, maclength);
}
return digest_open(digest, algo, maclength);
}
-bool digest_open_sha1(digest_t *digest,
in
t maclength) {
+bool digest_open_sha1(digest_t *digest,
size_
t maclength) {
return digest_open(digest, GCRY_MD_SHA1, maclength);
}
void digest_close(digest_t *digest) {
return digest_open(digest, GCRY_MD_SHA1, maclength);
}
void digest_close(digest_t *digest) {
- if(digest->hmac)
+ if(digest->hmac)
{
gcry_md_close(digest->hmac);
gcry_md_close(digest->hmac);
- digest->hmac = NULL;
+ }
+
+ memset(digest, 0, sizeof(*digest));
}
bool digest_set_key(digest_t *digest, const void *key, size_t len) {
}
bool digest_set_key(digest_t *digest, const void *key, size_t len) {
- if(!digest->hmac)
+ if(!digest->hmac)
{
gcry_md_open(&digest->hmac, digest->algo, GCRY_MD_FLAG_HMAC);
gcry_md_open(&digest->hmac, digest->algo, GCRY_MD_FLAG_HMAC);
- if(!digest->hmac)
+ }
+
+ if(!digest->hmac) {
return false;
return false;
+ }
return !gcry_md_setkey(digest->hmac, key, len);
}
return !gcry_md_setkey(digest->hmac, key, len);
}
@@
-137,12
+139,15
@@
bool digest_create(digest_t *digest, const void *indata, size_t inlen, void *out
unsigned int len = gcry_md_get_algo_dlen(digest->algo);
if(digest->hmac) {
unsigned int len = gcry_md_get_algo_dlen(digest->algo);
if(digest->hmac) {
-
char
*tmpdata;
+
uint8_t
*tmpdata;
gcry_md_reset(digest->hmac);
gcry_md_write(digest->hmac, indata, inlen);
tmpdata = gcry_md_read(digest->hmac, digest->algo);
gcry_md_reset(digest->hmac);
gcry_md_write(digest->hmac, indata, inlen);
tmpdata = gcry_md_read(digest->hmac, digest->algo);
- if(!tmpdata)
+
+ if(!tmpdata) {
return false;
return false;
+ }
+
memcpy(outdata, tmpdata, digest->maclength);
} else {
char tmpdata[len];
memcpy(outdata, tmpdata, digest->maclength);
} else {
char tmpdata[len];
@@
-154,8
+159,8
@@
bool digest_create(digest_t *digest, const void *indata, size_t inlen, void *out
}
bool digest_verify(digest_t *digest, const void *indata, size_t inlen, const void *cmpdata) {
}
bool digest_verify(digest_t *digest, const void *indata, size_t inlen, const void *cmpdata) {
-
unsigned in
t len = digest->maclength;
-
char
outdata[len];
+
size_
t len = digest->maclength;
+
uint8_t
outdata[len];
return digest_create(digest, indata, inlen, outdata) && !memcmp(cmpdata, outdata, len);
}
return digest_create(digest, indata, inlen, outdata) && !memcmp(cmpdata, outdata, len);
}