Update native cipher to make use of the OpenSSL EVP API so that it can actually utilise hardware acceleration and other goodies.
Whereas before OpenSSL would often lose benchmarks now it always wins.
This commit is contained in:
22
native/src/main/c/NativeCipherImpl.cpp
Normal file
22
native/src/main/c/NativeCipherImpl.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <openssl/evp.h>
|
||||
#include "net_md_5_bungee_NativeCipherImpl.h"
|
||||
|
||||
typedef unsigned char byte;
|
||||
|
||||
jlong JNICALL Java_net_md_15_bungee_NativeCipherImpl_init(JNIEnv* env, jobject obj, jboolean forEncryption, jbyteArray key) {
|
||||
jbyte *keyBytes = env->GetByteArrayElements(key, NULL);
|
||||
|
||||
EVP_CIPHER_CTX *cipherCtx = new EVP_CIPHER_CTX();
|
||||
EVP_CipherInit(cipherCtx, EVP_aes_128_cfb8(), (byte*) keyBytes, (byte*) keyBytes, forEncryption);
|
||||
|
||||
env->ReleaseByteArrayElements(key, keyBytes, JNI_ABORT);
|
||||
return (jlong) cipherCtx;
|
||||
}
|
||||
|
||||
void Java_net_md_15_bungee_NativeCipherImpl_free(JNIEnv* env, jobject obj, jlong ctx) {
|
||||
EVP_CIPHER_CTX_free((EVP_CIPHER_CTX*) ctx);
|
||||
}
|
||||
|
||||
void Java_net_md_15_bungee_NativeCipherImpl_cipher(JNIEnv* env, jobject obj, jlong ctx, jlong in, jlong out, jint length) {
|
||||
EVP_CipherUpdate((EVP_CIPHER_CTX*) ctx, (byte*) out, &length, (byte*) in, length);
|
||||
}
|
Reference in New Issue
Block a user