OSDN Git Service

First pass at reorganizing org.apache.harmony.xnet.provider.jsse native code into...
[android-x86/dalvik.git] / libcore / x-net / src / main / java / org / apache / harmony / xnet / provider / jsse / NativeCrypto.java
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.apache.harmony.xnet.provider.jsse;
18
19 /**
20  * Provides the Java side of our JNI glue for OpenSSL. Currently only hashing
21  * and verifying are covered. Is expected to grow over time. Also needs to move
22  * into libcore/openssl at some point.
23  */
24 public class NativeCrypto {
25
26     static {
27         // Need to ensure that OpenSSL initialization is done exactly once.
28         // This can be cleaned up later, when all OpenSSL glue moves into its
29         // own libcore module. Make it run, make it nice.
30         OpenSSLSocketImpl.class.getClass();
31     }
32
33     // --- DSA/RSA public/private key handling functions -----------------------
34     
35     public static native int EVP_PKEY_new_DSA(byte[] p, byte[] q, byte[] g, byte[] priv_key, byte[] pub_key);
36
37     public static native int EVP_PKEY_new_RSA(byte[] n, byte[] e, byte[] d, byte[] p, byte[] q);
38     
39     public static native void EVP_PKEY_free(int pkey);
40   
41     // --- General context handling functions (despite the names) --------------
42     
43     public static native int EVP_new();
44     
45     public static native void EVP_free(int ctx);
46     
47     // --- Digest handling functions -------------------------------------------
48     
49     public static native void EVP_DigestInit(int ctx, String algorithm);
50     
51     public static native void EVP_DigestUpdate(int ctx, byte[] buffer, int offset, int length);
52
53     public static native int EVP_DigestFinal(int ctx, byte[] hash, int offset);
54
55     public static native int EVP_DigestSize(int ctx);
56
57     public static native int EVP_DigestBlockSize(int ctx);
58     
59     // --- Signature handling functions ----------------------------------------
60     
61     public static native void EVP_VerifyInit(int ctx, String algorithm);
62     
63     public static native void EVP_VerifyUpdate(int ctx, byte[] buffer, int offset, int length);
64     
65     public static native int EVP_VerifyFinal(int ctx, byte[] signature, int offset, int length, int key);
66     
67 }