diff --git a/native/compile-native.sh b/native/compile-native.sh index f6e6a35a..98baf0e2 100755 --- a/native/compile-native.sh +++ b/native/compile-native.sh @@ -1,6 +1,6 @@ #!/bin/sh -CXX="g++ -std=c++11 -shared -fPIC -O3 -Wall -Werror -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/" +CXX="g++ -shared -fPIC -O3 -Wall -Werror -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/" $CXX src/main/c/NativeCipherImpl.cpp -o src/main/resources/native-cipher.so -lcrypto $CXX src/main/c/NativeCompressImpl.cpp -o src/main/resources/native-compress.so -lz diff --git a/native/src/main/java/net/md_5/bungee/jni/cipher/NativeCipher.java b/native/src/main/java/net/md_5/bungee/jni/cipher/NativeCipher.java index dea5e846..7b0ecb09 100644 --- a/native/src/main/java/net/md_5/bungee/jni/cipher/NativeCipher.java +++ b/native/src/main/java/net/md_5/bungee/jni/cipher/NativeCipher.java @@ -44,6 +44,12 @@ public class NativeCipher implements BungeeCipher // Store how many bytes we can cipher int length = in.readableBytes(); + // Older OpenSSL versions will flip if length <= 0 + if ( length <= 0 ) + { + return; + } + // It is important to note that in AES CFB-8 mode, the number of read bytes, is the number of outputted bytes out.ensureWritable( length ); diff --git a/native/src/test/java/net/md_5/bungee/NativeCipherTest.java b/native/src/test/java/net/md_5/bungee/NativeCipherTest.java index d6af2d95..13ac6f7b 100644 --- a/native/src/test/java/net/md_5/bungee/NativeCipherTest.java +++ b/native/src/test/java/net/md_5/bungee/NativeCipherTest.java @@ -124,6 +124,7 @@ public class NativeCipherTest for ( int i = 0; i < BENCHMARK_COUNT; i++ ) { cipher.cipher( nativePlain, out ); + nativePlain.readerIndex( 0 ); out.clear(); } System.out.println( String.format( "Encryption Iteration: %d, Elapsed: %d ms", BENCHMARK_COUNT, System.currentTimeMillis() - start ) ); @@ -134,6 +135,7 @@ public class NativeCipherTest for ( int i = 0; i < BENCHMARK_COUNT; i++ ) { cipher.cipher( nativeCiphered, out ); + nativeCiphered.readerIndex( 0 ); out.clear(); } System.out.println( String.format( "Decryption Iteration: %d, Elapsed: %d ms", BENCHMARK_COUNT, System.currentTimeMillis() - start ) );