warp-vpn

point to point VPN implementation
git clone git://git.2f30.org/warp-vpn
Log | Files | Refs | README

commit 6659ab0293db6f8953ef25fc6bdc123c1569a412
parent c57cbb84aa431bd3d376ed70a6b096bd0de97357
Author: sin <sin@2f30.org>
Date:   Fri,  8 Apr 2016 15:48:39 +0100

use a null entry to terminate ciphers table

Diffstat:
Mstun.c | 23++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/stun.c b/stun.c @@ -85,8 +85,6 @@ #define explicit_bzero bzero #endif -#define LEN(x) (sizeof (x) / sizeof *(x)) - #define NOPRIVUSER "nobody" #define RCVTIMEO 250 /* in milliseconds */ #define RECONNECTTIMEO 60 /* in seconds */ @@ -646,27 +644,26 @@ err: } void -aead_from_name(const EVP_AEAD **aead, const char *name) +mapaead(const EVP_AEAD **aead, const char *name) { - size_t i; struct { const char *name; const EVP_AEAD *(*aeadfn)(void); - } ciphers[] = { + } *cp, ciphers[] = { { "aes-128-gcm", EVP_aead_aes_128_gcm }, { "aes-256-gcm", EVP_aead_aes_256_gcm }, { "chacha20-poly1305", EVP_aead_chacha20_poly1305 }, - { "chacha20-poly1305-ietf", EVP_aead_chacha20_poly1305_ietf } + { "chacha20-poly1305-ietf", EVP_aead_chacha20_poly1305_ietf }, + { NULL, NULL } }; - for (i = 0; i < LEN(ciphers); i++) { - if (!strcmp(ciphers[i].name, name)) { - *aead = (*ciphers[i].aeadfn)(); - break; + for (cp = ciphers; cp->name; cp++) { + if (!strcmp(cp->name, name)) { + *aead = (*cp->aeadfn)(); + return; } } - if (i == LEN(ciphers)) - logerr("unknown cipher: %s", name); + logerr("unknown cipher: %s", name); } void @@ -674,7 +671,7 @@ aeadinit(unsigned char *pw) { size_t keylen; - aead_from_name(&aead, cipher); + mapaead(&aead, cipher); keylen = EVP_AEAD_key_length(aead); if (!PKCS5_PBKDF2_HMAC_SHA1(pw, strlen(pw), NULL, 0, NROUNDS, keylen, key))