All Downloads are FREE. Search and download functionalities are using the official Maven repository.

native.intel.jni.native_features.c Maven / Gradle / Ivy

Go to download

The Long Term Stable (LTS) Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains the JCA/JCE provider and low-level API for the BC LTS version 2.73.7 for Java 8 and later.

There is a newer version: 2.73.7
Show newest version

#include 
#include "org_bouncycastle_crypto_NativeFeatures.h"


typedef struct cpuid_struct {
    unsigned int eax;
    unsigned int ebx;
    unsigned int ecx;
    unsigned int edx;
} cpuid_t;

void cpuid(cpuid_t *info, unsigned int leaf, unsigned int subleaf) {
    __asm__ volatile("cpuid"
            : "=a" (info->eax), "=b" (info->ebx), "=c" (info->ecx), "=d" (info->edx)
            : "a" (leaf), "c" (subleaf)
            );
}


/*
 * Class:     org_bouncycastle_crypto_NativeFeatures
 * Method:    nativeCBC
 * Signature: ()Z
 */
__attribute__((unused)) JNIEXPORT jboolean JNICALL Java_org_bouncycastle_crypto_NativeFeatures_nativeCBC
        (JNIEnv *env, jclass cl) {
    cpuid_t info;
    cpuid(&info, 1, 0);

    return (info.ecx & (1 << 25)) != 0 ? JNI_TRUE : JNI_FALSE;
}


/*
 * Class:     org_bouncycastle_crypto_NativeFeatures
 * Method:    nativeCFB
 * Signature: ()Z
 */
__attribute__((unused)) JNIEXPORT jboolean JNICALL Java_org_bouncycastle_crypto_NativeFeatures_nativeCFB
        (JNIEnv *env, jclass cl) {
    cpuid_t info;
    cpuid(&info, 1, 0);

    return (info.ecx & (1 << 25)) != 0 ? JNI_TRUE : JNI_FALSE;
}


/*
 * Class:     org_bouncycastle_crypto_NativeFeatures
 * Method:    nativeCFB
 * Signature: ()Z
 */
__attribute__((unused)) JNIEXPORT jboolean JNICALL Java_org_bouncycastle_crypto_NativeFeatures_nativeCTR
        (JNIEnv *env, jclass cl) {
    cpuid_t info;
    cpuid(&info, 1, 0);

    return (info.ecx & (1 << 25)) != 0 ? JNI_TRUE : JNI_FALSE;
}


/*
 * Class:     org_bouncycastle_crypto_NativeFeatures
 * Method:    nativeAES
 * Signature: ()Z
 */
__attribute__((unused)) JNIEXPORT jboolean JNICALL Java_org_bouncycastle_crypto_NativeFeatures_nativeAES
        (JNIEnv *env, jclass cl) {

    cpuid_t info;
    cpuid(&info, 1, 0);

    return (info.ecx & (1 << 25)) != 0 ? JNI_TRUE : JNI_FALSE;

}

/*
 * Class:     org_bouncycastle_crypto_NativeFeatures
 * Method:    nativeGCM
 * Signature: ()Z
 */
__attribute__((unused)) JNIEXPORT jboolean JNICALL Java_org_bouncycastle_crypto_NativeFeatures_nativeGCM
        (JNIEnv *env, jclass cl) {

    cpuid_t info;
    cpuid(&info, 1, 0);

    bool aes = (info.ecx & (1 << 25)) != 0;
    bool pclmulqdq = (info.ecx & (1 << 1)) != 0;

    return (aes && pclmulqdq) ? JNI_TRUE : JNI_FALSE;

}


/*
 * Class:     org_bouncycastle_util_NativeFeatures
 * Method:    nativeRand
 * Signature: ()Z
 */
__attribute__((unused)) JNIEXPORT jboolean JNICALL Java_org_bouncycastle_crypto_NativeFeatures_nativeRand
        (JNIEnv *env, jclass cl) {

    cpuid_t info;
    cpuid(&info, 1, 0);

    return (info.ecx & (1 << 30)) != 0 ? JNI_TRUE : JNI_FALSE;

}

/*
 * Class:     org_bouncycastle_util_NativeFeatures
 * Method:    nativeSeed
 * Signature: ()Z
 */
__attribute__((unused)) JNIEXPORT jboolean JNICALL Java_org_bouncycastle_crypto_NativeFeatures_nativeSeed
        (JNIEnv *env, jclass cl) {
    cpuid_t info;
    cpuid(&info, 7, 0);

    return (info.ebx & (1 << 18)) != 0 ? JNI_TRUE : JNI_FALSE;
}

/*
 * Class:     org_bouncycastle_crypto_NativeFeatures
 * Method:    nativeSHA2
 * Signature: ()Z
 */
__attribute__((unused)) JNIEXPORT jboolean JNICALL Java_org_bouncycastle_crypto_NativeFeatures_nativeSHA2
        (JNIEnv *env, jclass cl) {
    cpuid_t info;
    cpuid(&info, 7, 0);

    return (info.ebx & (1 << 29)) != 0 ? JNI_TRUE : JNI_FALSE;

}

/*
 * Class:     org_bouncycastle_crypto_NativeFeatures
 * Method:    nativeMulAcc
 * Signature: ()Z
 */
JNIEXPORT jboolean JNICALL Java_org_bouncycastle_crypto_NativeFeatures_nativeMulAcc
        (JNIEnv *env, jclass cl) {

    cpuid_t info;
    cpuid(&info, 1, 0);

    bool pclmulqdq = (info.ecx & (1 << 1)) != 0;

    return (pclmulqdq) ? JNI_TRUE : JNI_FALSE;

}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy