michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.background.nativecode; michael@0: michael@0: import java.security.GeneralSecurityException; michael@0: michael@0: import org.mozilla.gecko.AppConstants; michael@0: import org.mozilla.gecko.mozglue.RobocopTarget; michael@0: michael@0: import android.util.Log; michael@0: michael@0: @RobocopTarget michael@0: public class NativeCrypto { michael@0: static { michael@0: try { michael@0: System.loadLibrary("mozglue"); michael@0: } catch (UnsatisfiedLinkError e) { michael@0: Log.wtf("NativeCrypto", "Couldn't load mozglue. Trying /data/app-lib path."); michael@0: try { michael@0: System.load("/data/app-lib/" + AppConstants.ANDROID_PACKAGE_NAME + "/libmozglue.so"); michael@0: } catch (Throwable ee) { michael@0: try { michael@0: Log.wtf("NativeCrypto", "Couldn't load mozglue: " + ee + ". Trying /data/data path."); michael@0: System.load("/data/data/" + AppConstants.ANDROID_PACKAGE_NAME + "/lib/libmozglue.so"); michael@0: } catch (UnsatisfiedLinkError eee) { michael@0: Log.wtf("NativeCrypto", "Failed every attempt to load mozglue. Giving up."); michael@0: throw new RuntimeException("Unable to load mozglue", eee); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Wrapper to perform PBKDF2-HMAC-SHA-256 in native code. michael@0: */ michael@0: public native static byte[] pbkdf2SHA256(byte[] password, byte[] salt, int c, int dkLen) michael@0: throws GeneralSecurityException; michael@0: michael@0: /** michael@0: * Wrapper to perform SHA-1 in native code. michael@0: */ michael@0: public native static byte[] sha1(byte[] str); michael@0: }