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:
md_5
2014-07-01 20:13:30 +10:00
parent 21be93a1b1
commit 7318750ed0
7 changed files with 39 additions and 102 deletions

View 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);
}