You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2016/07/06 23:36:13 UTC

commons-crypto git commit: Stupid Git

Repository: commons-crypto
Updated Branches:
  refs/heads/master f9ad9cf3d -> a7159569f


Stupid Git

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/a7159569
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/a7159569
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/a7159569

Branch: refs/heads/master
Commit: a7159569f7ad9eda8871da0b0395a7663de53d9c
Parents: f9ad9cf
Author: Sebb <se...@apache.org>
Authored: Thu Jul 7 00:36:10 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Thu Jul 7 00:36:10 2016 +0100

----------------------------------------------------------------------
 .../commons/crypto/jna/OpenSslNativeJna.java    | 99 ++++++++++++++++++++
 1 file changed, 99 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/a7159569/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java b/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
new file mode 100644
index 0000000..6adddb2
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.crypto.jna;
+
+import java.nio.ByteBuffer;
+
+import com.sun.jna.Native;
+import com.sun.jna.NativeLong;
+import com.sun.jna.ptr.PointerByReference;
+
+class OpenSslNativeJna {
+
+    static final int OPENSSL_INIT_ENGINE_RDRAND = 0x00000200;
+
+    static final int OOSL_JNA_ENCRYPT_MODE = 1;
+    static final int OOSL_JNA_DECRYPT_MODE = 0;
+
+    static {
+        Native.register("crypto");
+        ERR_load_crypto_strings();
+    }
+
+    //misc
+    public static native NativeLong SSLeay();
+    public static native String SSLeay_version(int type);
+    public static native void ERR_load_crypto_strings();
+    public static native NativeLong ERR_peek_error();
+    public static native String ERR_error_string(NativeLong err, char[] null_);
+    //String ERR_lib_error_string(NativeLong err);
+    //String ERR_func_error_string(NativeLong err);
+    //String ERR_reason_error_string(NativeLong err);
+    
+    //en-/decryption
+    public static native PointerByReference EVP_CIPHER_CTX_new();
+    public static native void EVP_CIPHER_CTX_init(PointerByReference p);
+    public static native int EVP_CIPHER_CTX_set_padding(PointerByReference c, int pad);
+    public static native PointerByReference EVP_aes_128_cbc();
+    public static native PointerByReference EVP_aes_128_ctr();
+    public static native PointerByReference EVP_aes_192_cbc();
+    public static native PointerByReference EVP_aes_192_ctr();
+    public static native PointerByReference EVP_aes_256_cbc();
+    public static native PointerByReference EVP_aes_256_ctr();
+    public static native int EVP_CipherInit_ex(PointerByReference ctx, PointerByReference cipher, PointerByReference impl, byte key[], byte iv[], int enc);
+    public static native int EVP_CipherUpdate(PointerByReference ctx, ByteBuffer bout, int[] outl, ByteBuffer in, int inl);
+    public static native int EVP_CipherFinal_ex(PointerByReference ctx, ByteBuffer bout, int[] outl);   
+    public static native void EVP_CIPHER_CTX_free(PointerByReference c);
+    public static native void EVP_CIPHER_CTX_cleanup(PointerByReference c);
+    
+    //Random generator
+    public static native PointerByReference RAND_get_rand_method();
+    public static native PointerByReference RAND_SSLeay();
+    public static native int RAND_bytes(ByteBuffer buf, int num);
+    public static native int ENGINE_finish(PointerByReference e);
+    public static native int ENGINE_free(PointerByReference e);
+    public static native int ENGINE_cleanup();
+    public static native int ENGINE_init(PointerByReference e);
+    public static native int ENGINE_set_default(PointerByReference e, int flags);
+    public static native PointerByReference ENGINE_by_id(String id);
+    public static native void ENGINE_load_rdrand();
+    
+    //TODO callback multithreading
+    /*public interface Id_function_cb extends Callback {
+        long invoke ();
+    }
+   
+    public interface Locking_function_cb extends Callback {
+        void invoke(int mode, int n, String file, int line);
+    }
+    
+    public static final Id_function_cb default_id_function = new Id_function_cb() {
+        
+        @Override
+        public long invoke() {
+            //id always positive
+            long id = Thread.currentThread().getId();
+            return id;
+        }
+    };
+    
+    int CRYPTO_num_locks();
+    void CRYPTO_set_id_callback(Id_function_cb id_function);
+    void CRYPTO_set_locking_callback(Locking_function_cb locking_function);*/
+}
\ No newline at end of file