mobile/android/base/background/nativecode/NativeCrypto.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 package org.mozilla.gecko.background.nativecode;
michael@0 6
michael@0 7 import java.security.GeneralSecurityException;
michael@0 8
michael@0 9 import org.mozilla.gecko.AppConstants;
michael@0 10 import org.mozilla.gecko.mozglue.RobocopTarget;
michael@0 11
michael@0 12 import android.util.Log;
michael@0 13
michael@0 14 @RobocopTarget
michael@0 15 public class NativeCrypto {
michael@0 16 static {
michael@0 17 try {
michael@0 18 System.loadLibrary("mozglue");
michael@0 19 } catch (UnsatisfiedLinkError e) {
michael@0 20 Log.wtf("NativeCrypto", "Couldn't load mozglue. Trying /data/app-lib path.");
michael@0 21 try {
michael@0 22 System.load("/data/app-lib/" + AppConstants.ANDROID_PACKAGE_NAME + "/libmozglue.so");
michael@0 23 } catch (Throwable ee) {
michael@0 24 try {
michael@0 25 Log.wtf("NativeCrypto", "Couldn't load mozglue: " + ee + ". Trying /data/data path.");
michael@0 26 System.load("/data/data/" + AppConstants.ANDROID_PACKAGE_NAME + "/lib/libmozglue.so");
michael@0 27 } catch (UnsatisfiedLinkError eee) {
michael@0 28 Log.wtf("NativeCrypto", "Failed every attempt to load mozglue. Giving up.");
michael@0 29 throw new RuntimeException("Unable to load mozglue", eee);
michael@0 30 }
michael@0 31 }
michael@0 32 }
michael@0 33 }
michael@0 34
michael@0 35 /**
michael@0 36 * Wrapper to perform PBKDF2-HMAC-SHA-256 in native code.
michael@0 37 */
michael@0 38 public native static byte[] pbkdf2SHA256(byte[] password, byte[] salt, int c, int dkLen)
michael@0 39 throws GeneralSecurityException;
michael@0 40
michael@0 41 /**
michael@0 42 * Wrapper to perform SHA-1 in native code.
michael@0 43 */
michael@0 44 public native static byte[] sha1(byte[] str);
michael@0 45 }

mercurial