2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.apache.harmony.xnet.provider.jsse;
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.
24 public class NativeCrypto {
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();
33 // --- DSA/RSA public/private key handling functions -----------------------
35 public static native int EVP_PKEY_new_DSA(byte[] p, byte[] q, byte[] g, byte[] priv_key, byte[] pub_key);
37 public static native int EVP_PKEY_new_RSA(byte[] n, byte[] e, byte[] d, byte[] p, byte[] q);
39 public static native void EVP_PKEY_free(int pkey);
41 // --- General context handling functions (despite the names) --------------
43 public static native int EVP_new();
45 public static native void EVP_free(int ctx);
47 // --- Digest handling functions -------------------------------------------
49 public static native void EVP_DigestInit(int ctx, String algorithm);
51 public static native void EVP_DigestUpdate(int ctx, byte[] buffer, int offset, int length);
53 public static native int EVP_DigestFinal(int ctx, byte[] hash, int offset);
55 public static native int EVP_DigestSize(int ctx);
57 public static native int EVP_DigestBlockSize(int ctx);
59 // --- Signature handling functions ----------------------------------------
61 public static native void EVP_VerifyInit(int ctx, String algorithm);
63 public static native void EVP_VerifyUpdate(int ctx, byte[] buffer, int offset, int length);
65 public static native int EVP_VerifyFinal(int ctx, byte[] signature, int offset, int length, int key);