aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/impl/openssl.c
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-05-26 11:47:17 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-05-26 11:47:17 -0400
commitaeaac8d328b75911541be64d6f09d58fca294a08 (patch)
tree86f48cd3cef91dd5320215aebd44ea56c2571c74 /src/crypto/impl/openssl.c
parent86b02540cce6015cfe4a2a56499a9a2f45d4e368 (diff)
refactor: Dep update, openssl chacha20 added
Diffstat (limited to 'src/crypto/impl/openssl.c')
-rw-r--r--src/crypto/impl/openssl.c57
1 files changed, 55 insertions, 2 deletions
diff --git a/src/crypto/impl/openssl.c b/src/crypto/impl/openssl.c
index fd3b4e6..132c643 100644
--- a/src/crypto/impl/openssl.c
+++ b/src/crypto/impl/openssl.c
@@ -150,6 +150,8 @@
EVP_MD_CTX* ctx;
cstatus_t result;
struct nc_hkdf_fn_cb_struct handler;
+
+ result = CSTATUS_FAIL;
/*
* NOTE! Hmac reusable flag must be set to allow for multiple
@@ -161,15 +163,23 @@
return CSTATUS_FAIL;
}
- _OSSL_FAIL(EVP_DigestInit_ex2(ctx, EVP_sha256(), NULL))
+ if (!EVP_DigestInit_ex2(ctx, EVP_sha256(), NULL))
+ {
+ goto Cleanup;
+ }
- _OSSL_FAIL(EVP_DigestUpdate(ctx, prk->data, prk->size));
+ if (!EVP_DigestUpdate(ctx, prk->data, prk->size))
+ {
+ goto Cleanup;
+ }
handler.update = _ossl_hkdf_update;
handler.finish = _ossl_hkdf_finish;
result = hkdfExpandProcess(&handler, ctx, info, okm);
+ Cleanup:
+
EVP_MD_CTX_destroy(ctx);
return result;
@@ -177,4 +187,47 @@
#endif /* !_IMPL_CRYPTO_SHA256_HKDF_EXPAND */
+#ifndef _IMPL_CHACHA20_CRYPT
+
+ #define _IMPL_CHACHA20_CRYPT _ossl_chacha20_crypt
+
+ _IMPLSTB cstatus_t _ossl_chacha20_crypt(
+ const uint8_t* key,
+ const uint8_t* nonce,
+ const uint8_t* input,
+ uint8_t* output,
+ uint32_t dataLen
+ )
+ {
+ cstatus_t result;
+ EVP_CIPHER_CTX* ctx;
+
+ result = CSTATUS_FAIL;
+
+ if ((ctx = EVP_CIPHER_CTX_new()) == NULL)
+ {
+ return CSTATUS_FAIL;
+ }
+
+ if (!EVP_EncryptInit_ex(ctx, EVP_chacha20(), NULL, key, nonce))
+ {
+ goto Cleanup;
+ }
+
+ if (!EVP_EncryptUpdate(ctx, output, (int*)&dataLen, input, dataLen))
+ {
+ goto Cleanup;
+ }
+
+ result = CSTATUS_OK;
+
+ Cleanup:
+
+ EVP_CIPHER_CTX_free(ctx);
+
+ return result;
+ }
+
+#endif
+
#endif /*!OPENSSL_CRYPTO_LIB */ \ No newline at end of file