Search in sources :

Example 1 with NativeRSAEngine

use of com.icodici.crypto.rsaoaep.scrsa.NativeRSAEngine in project universa by UniversaBlockchain.

the class RSAEngineFactory method whetherShouldUseNative.

/**
 * Perform a test to check whether we should use an optimized native implementation or default Java one.
 */
static boolean whetherShouldUseNative() {
    // Sometimes NativeRSAEngine does not work; e.g. when GMP native binary is not available.
    // Test once if it will work; if it doesn't, fallback to use default RSAEngine.
    final RSAOAEPTestVectors oaepSpec = new RSAOAEPTestVectors();
    final ParametersWithRandom param = new ParametersWithRandom(oaepSpec.pubParameters, oaepSpec.getRandSeed());
    boolean errorOccured;
    try {
        final NativeRSAEngine nativeRSAEngine = new NativeRSAEngine();
        nativeRSAEngine.init(true, param);
        errorOccured = false;
    } catch (Throwable e) {
        errorOccured = true;
    }
    return !errorOccured;
}
Also used : ParametersWithRandom(org.spongycastle.crypto.params.ParametersWithRandom) NativeRSAEngine(com.icodici.crypto.rsaoaep.scrsa.NativeRSAEngine)

Aggregations

NativeRSAEngine (com.icodici.crypto.rsaoaep.scrsa.NativeRSAEngine)1 ParametersWithRandom (org.spongycastle.crypto.params.ParametersWithRandom)1