⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 digest.c

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 C
📖 第 1 页 / 共 2 页
字号:
	}	/* Get data byte array data */	if (off < 0 || off + digestLen > (*env)->GetArrayLength(env, buf)) {		(*env)->ThrowNew(env, aiobClass, "out of range");		return;	}	bufBytes = (*env)->GetByteArrayElements(env, buf, NULL);      	if ((*env)->ExceptionOccurred(env)) {		return;	}	/* Finalize and release byte arrays */	MD4Final(bufBytes + off, (MD4_CTX *) ctxBytes);	(*env)->ReleaseByteArrayElements(env, ctxArray, ctxBytes, 0);	(*env)->ReleaseByteArrayElements(env, buf, bufBytes, JNI_ABORT);}#elsevoid JNICALLJava_org_kaffe_security_provider_MD4_Init(JNIEnv *env, jobject this UNUSED){	supportDisabled(env);}void JNICALLJava_org_kaffe_security_provider_MD4_Update(JNIEnv *env, jobject this UNUSED,	jbyteArray buf UNUSED, jint off UNUSED, jint len UNUSED){	supportDisabled(env);}void JNICALLJava_org_kaffe_security_provider_MD4_Final(JNIEnv *env, jobject this UNUSED,	jbyteArray buf UNUSED, jint off UNUSED){	supportDisabled(env);}#endif	/* defined(HAVE_MD4INIT) || defined(HAVE_LIBMD) *//**************************** MD5 ***********************************/#if defined(HAVE_MD5INIT) || defined(HAVE_LIBMD)#include <md5.h>#else/* * If we don't have an external MD5 library, we use an internal version * instead. */#include "kaffe_md5.h"#define	MD5_CTX			struct md5_ctx#define	MD5Init(C)		md5_init_ctx(C)#define	MD5Update(C,B,L)	md5_process_bytes(B,L,C)#define	MD5Final(B,C)		md5_finish_ctx(C,B)#endif	/* defined(HAVE_MD5INIT) || defined(HAVE_LIBMD) */void JNICALLJava_org_kaffe_security_provider_MD5_Init(JNIEnv *env, jobject this){	const jclass	class = (*env)->GetObjectClass(env, this);	const jfieldID	contextField = (*env)->GetFieldID(env,					  class, "context", "[B");	jbyteArray	ary;	MD5_CTX		ctx;	/* Initialize MD5 context */	MD5Init(&ctx);	/* Copy initialized context into byte array */	ary = (*env)->NewByteArray(env, sizeof(ctx));	(*env)->SetByteArrayRegion(env, ary, 0, sizeof(ctx), (jbyte *) &ctx);      	if ((*env)->ExceptionOccurred(env)) {		return;	}	/* Assign byte array to instance variable */	(*env)->SetObjectField(env, this, contextField, (jobject) ary);}void JNICALLJava_org_kaffe_security_provider_MD5_Update(JNIEnv *env, jobject this,	jbyteArray buf, jint off, jint len){	const jclass	class = (*env)->GetObjectClass(env, this);	const jclass	aiobClass = (*env)->FindClass(env,				"java/lang/ArrayIndexOutOfBoundsException");	const jfieldID	contextField = (*env)->GetFieldID(env,				class, "context", "[B");	jbyte		*ctxBytes, *bufBytes;	jbyteArray	ctxArray;	/* Get context byte array data */	ctxArray = (*env)->GetObjectField(env, this, contextField);	ctxBytes = (*env)->GetByteArrayElements(env, ctxArray, NULL);      	if ((*env)->ExceptionOccurred(env)) {		return;	}	/* Get data byte array data */	if (off < 0 || len < 0 || off + len > (*env)->GetArrayLength(env, buf)) {		(*env)->ThrowNew(env, aiobClass, "out of range");		return;	}	bufBytes = (*env)->GetByteArrayElements(env, buf, NULL);      	if ((*env)->ExceptionOccurred(env)) {		return;	}	/* Update with new data and release array data */	MD5Update((MD5_CTX *) ctxBytes, bufBytes + off, (unsigned)len);	(*env)->ReleaseByteArrayElements(env, ctxArray, ctxBytes, 0);	(*env)->ReleaseByteArrayElements(env, buf, bufBytes, JNI_ABORT);}void JNICALLJava_org_kaffe_security_provider_MD5_Final(JNIEnv *env, jobject this,	jbyteArray buf, jint off){	const jclass	class = (*env)->GetObjectClass(env, this);	const jclass	aiobClass = (*env)->FindClass(env,				"java/lang/ArrayIndexOutOfBoundsException");	const jfieldID	contextField = (*env)->GetFieldID(env,				class, "context", "[B");	const jfieldID	diglenField = (*env)->GetStaticFieldID(env,				class, "DIGEST_LENGTH", "I");	jint		digestLen = (*env)->GetStaticIntField(env,				this, diglenField);	jbyte		*ctxBytes, *bufBytes;	jbyteArray	ctxArray;	/* Get context byte array data */	ctxArray = (*env)->GetObjectField(env, this, contextField);	ctxBytes = (*env)->GetByteArrayElements(env, ctxArray, NULL);      	if ((*env)->ExceptionOccurred(env)) {		return;	}	/* Get data byte array data */	if (off < 0 || off + digestLen > (*env)->GetArrayLength(env, buf)) {		(*env)->ThrowNew(env, aiobClass, "out of range");		return;	}	bufBytes = (*env)->GetByteArrayElements(env, buf, NULL);      	if ((*env)->ExceptionOccurred(env)) {		return;	}	/* Finalize and release byte arrays */	MD5Final(bufBytes + off, (MD5_CTX *) ctxBytes);	(*env)->ReleaseByteArrayElements(env, ctxArray, ctxBytes, 0);	(*env)->ReleaseByteArrayElements(env, buf, bufBytes, JNI_ABORT);}/**************************** SHA ***********************************/void JNICALLJava_org_kaffe_security_provider_SHA_Init(JNIEnv *env, jobject this){	const jclass	class = (*env)->GetObjectClass(env, this);	const jfieldID	contextField = (*env)->GetFieldID(env,					  class, "context", "[B");	jbyteArray	ary;	SHA1_CTX	ctx;	/* Initialize SHA context */	SHA1Init(&ctx);	/* Copy initialized context into byte array */	ary = (*env)->NewByteArray(env, sizeof(ctx));	(*env)->SetByteArrayRegion(env, ary, 0, sizeof(ctx), (jbyte *) &ctx);      	if ((*env)->ExceptionOccurred(env)) {		return;	}	/* Assign byte array to instance variable */	(*env)->SetObjectField(env, this, contextField, (jobject) ary);}void JNICALLJava_org_kaffe_security_provider_SHA_Update(JNIEnv *env, jobject this,	jbyteArray buf, jint off, jint len){	const jclass	class = (*env)->GetObjectClass(env, this);	const jclass	aiobClass = (*env)->FindClass(env,				"java/lang/ArrayIndexOutOfBoundsException");	const jfieldID	contextField = (*env)->GetFieldID(env,				class, "context", "[B");	jbyte		*ctxBytes, *bufBytes;	jbyteArray	ctxArray;	/* Get context byte array data */	ctxArray = (*env)->GetObjectField(env, this, contextField);	ctxBytes = (*env)->GetByteArrayElements(env, ctxArray, NULL);      	if ((*env)->ExceptionOccurred(env)) {		return;	}	/* Get data byte array data */	if (off < 0 || len < 0 || off + len > (*env)->GetArrayLength(env, buf)) {		(*env)->ThrowNew(env, aiobClass, "out of range");		return;	}	bufBytes = (*env)->GetByteArrayElements(env, buf, NULL);      	if ((*env)->ExceptionOccurred(env)) {		return;	}	/* Update with new data and release array data */	SHA1Update((SHA1_CTX *) ctxBytes, (unsigned char *)(bufBytes + off), (unsigned)len);	(*env)->ReleaseByteArrayElements(env, ctxArray, ctxBytes, 0);	(*env)->ReleaseByteArrayElements(env, buf, bufBytes, JNI_ABORT);}void JNICALLJava_org_kaffe_security_provider_SHA_Final(JNIEnv *env, jobject this,	jbyteArray buf, jint off){	const jclass	class = (*env)->GetObjectClass(env, this);	const jclass	aiobClass = (*env)->FindClass(env,				"java/lang/ArrayIndexOutOfBoundsException");	const jfieldID	contextField = (*env)->GetFieldID(env,				class, "context", "[B");	const jfieldID	diglenField = (*env)->GetStaticFieldID(env,				class, "DIGEST_LENGTH", "I");	jint		digestLen = (*env)->GetStaticIntField(env,				this, diglenField);	jbyte		*ctxBytes, *bufBytes;	jbyteArray	ctxArray;	/* Get context byte array data */	ctxArray = (*env)->GetObjectField(env, this, contextField);	ctxBytes = (*env)->GetByteArrayElements(env, ctxArray, NULL);      	if ((*env)->ExceptionOccurred(env)) {		return;	}	/* Get data byte array data */	if (off < 0 || off + digestLen > (*env)->GetArrayLength(env, buf)) {		(*env)->ThrowNew(env, aiobClass, "out of range");		return;	}	bufBytes = (*env)->GetByteArrayElements(env, buf, NULL);      	if ((*env)->ExceptionOccurred(env)) {		return;	}	/* Finalize and release byte arrays */	SHA1Final((unsigned char*)(bufBytes + off), (SHA1_CTX *) ctxBytes);	(*env)->ReleaseByteArrayElements(env, ctxArray, ctxBytes, 0);	(*env)->ReleaseByteArrayElements(env, buf, bufBytes, JNI_ABORT);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -