stun

simple point to point tunnel
git clone git://git.2f30.org/stun
Log | Files | Refs | README

commit 965324af5e5e7826cf87d5c760e8298f5e47161e
parent f9957dadc2dd34dfa20bedade95ff944934afca7
Author: sin <sin@2f30.org>
Date:   Tue, 12 Apr 2016 16:25:53 +0100

crypto cleanup

Diffstat:
Mcrypto.c | 25+++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/crypto.c b/crypto.c @@ -10,7 +10,7 @@ static const EVP_AEAD *aead; static unsigned char key[EVP_MAX_KEY_LENGTH]; static void -findcipher(char *name) +setcipher(char *name) { struct { const char *name; @@ -32,21 +32,22 @@ findcipher(char *name) logerr("unknown cipher: %s", name); } -void -cryptoinit(char *pw) +static void +derivekey(char *pw) { - size_t keylen; - - findcipher(cipher); - keylen = EVP_AEAD_key_length(aead); if (!PKCS5_PBKDF2_HMAC_SHA1(pw, strlen(pw), NULL, 0, NROUNDS, - keylen, key)) + EVP_AEAD_key_length(aead), key)) logerr("PKCS5_PBKDF2_HMAC_SHA1 failed"); +} - if (!EVP_AEAD_CTX_init(&ectx, aead, key, keylen, - EVP_AEAD_DEFAULT_TAG_LENGTH, NULL)) - logerr("EVP_AEAD_CTX_init failed"); - if (!EVP_AEAD_CTX_init(&dctx, aead, key, keylen, +void +cryptoinit(char *pw) +{ + setcipher(cipher); + derivekey(pw); + if (!EVP_AEAD_CTX_init(&ectx, aead, key, EVP_AEAD_key_length(aead), + EVP_AEAD_DEFAULT_TAG_LENGTH, NULL) || + !EVP_AEAD_CTX_init(&dctx, aead, key, EVP_AEAD_key_length(aead), EVP_AEAD_DEFAULT_TAG_LENGTH, NULL)) logerr("EVP_AEAD_CTX_init failed"); }