Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mclub/minivtun into mclub…
Browse files Browse the repository at this point in the history
…-master
  • Loading branch information
rssnsj committed Jan 25, 2018
2 parents e8b9620 + ea99cc3 commit 652a824
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void datagram_encrypt(const void *key, const void *cptype, void *in,
void *out, size_t *dlen)
{
size_t iv_len = EVP_CIPHER_iv_length((const EVP_CIPHER *)cptype);
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
unsigned char iv[CRYPTO_MAX_KEY_SIZE];
int outl = 0, outl2 = 0;

Expand All @@ -80,12 +80,13 @@ void datagram_encrypt(const void *key, const void *cptype, void *in,

memcpy(iv, crypto_ivec_initdata, iv_len);
CRYPTO_DATA_PADDING(in, dlen, iv_len);
EVP_CIPHER_CTX_init(&ctx);
assert(EVP_EncryptInit_ex(&ctx, cptype, NULL, key, iv));
EVP_CIPHER_CTX_set_padding(&ctx, 0);
assert(EVP_EncryptUpdate(&ctx, out, &outl, in, *dlen));
assert(EVP_EncryptFinal_ex(&ctx, (unsigned char *)out + outl, &outl2));
EVP_CIPHER_CTX_cleanup(&ctx);
EVP_CIPHER_CTX_init(ctx);
assert(EVP_EncryptInit_ex(ctx, cptype, NULL, key, iv));
EVP_CIPHER_CTX_set_padding(ctx, 0);
assert(EVP_EncryptUpdate(ctx, out, &outl, in, *dlen));
assert(EVP_EncryptFinal_ex(ctx, (unsigned char *)out + outl, &outl2));
EVP_CIPHER_CTX_cleanup(ctx);
EVP_CIPHER_CTX_free(ctx);

*dlen = (size_t)(outl + outl2);
}
Expand All @@ -94,7 +95,7 @@ void datagram_decrypt(const void *key, const void *cptype, void *in,
void *out, size_t *dlen)
{
size_t iv_len = EVP_CIPHER_iv_length((const EVP_CIPHER *)cptype);
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
unsigned char iv[CRYPTO_MAX_KEY_SIZE];
int outl = 0, outl2 = 0;

Expand All @@ -103,12 +104,13 @@ void datagram_decrypt(const void *key, const void *cptype, void *in,

memcpy(iv, crypto_ivec_initdata, iv_len);
CRYPTO_DATA_PADDING(in, dlen, iv_len);
EVP_CIPHER_CTX_init(&ctx);
assert(EVP_DecryptInit_ex(&ctx, cptype, NULL, key, iv));
EVP_CIPHER_CTX_set_padding(&ctx, 0);
assert(EVP_DecryptUpdate(&ctx, out, &outl, in, *dlen));
assert(EVP_DecryptFinal_ex(&ctx, (unsigned char *)out + outl, &outl2));
EVP_CIPHER_CTX_cleanup(&ctx);
EVP_CIPHER_CTX_init(ctx);
assert(EVP_DecryptInit_ex(ctx, cptype, NULL, key, iv));
EVP_CIPHER_CTX_set_padding(ctx, 0);
assert(EVP_DecryptUpdate(ctx, out, &outl, in, *dlen));
assert(EVP_DecryptFinal_ex(ctx, (unsigned char *)out + outl, &outl2));
EVP_CIPHER_CTX_cleanup(ctx);
EVP_CIPHER_CTX_free(ctx);

*dlen = (size_t)(outl + outl2);
}
Expand Down

0 comments on commit 652a824

Please sign in to comment.