10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #include <stdlib.h>
27 #include <string.h>
28 #include <strings.h>
29 #include <jni.h>
30 #include <libsoftcrypto.h>
31 #include "nativeCrypto.h"
32 #include "nativeFunc.h"
33
34 /*
35 * Dumps out byte array in hex with and name and length info
36 */
37 void printBytes(char* header, unsigned char* bytes, int len) {
38 int i;
39
40 printf("%s", header);
41 printf("len=%d {", len);
42 for (i = 0; i < len; i++) {
43 if (i > 0) printf(":");
44 printf("%02X", bytes[i]);
45 }
46 printf("}\n");
47 }
48
49 /*
50 * Throws java.lang.OutOfMemoryError
51 */
52 void throwOutOfMemoryError(JNIEnv *env, const char *msg)
53 {
54 jclass jExClass = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
55 if (jExClass != 0) /* Otherwise an exception has already been thrown */ {
56 (*env)->ThrowNew(env, jExClass, msg);
57 }
58 /* free the local ref */
59 (*env)->DeleteLocalRef(env, jExClass);
60 }
61
62 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
63 return JNI_VERSION_1_4;
64 }
65
66 /*
67 * Class: com_oracle_security_ucrypto_UcryptoProvider
68 * Method: loadLibraries
69 * Signature: ()[Z
70 */
71 JNIEXPORT jbooleanArray JNICALL Java_com_oracle_security_ucrypto_UcryptoProvider_loadLibraries
72 (JNIEnv *env, jclass jcls) {
73 jbooleanArray jResult;
74 jboolean *result;
75 jResult = (*env)->NewBooleanArray(env, 2);
76
77 if (jResult != NULL) {
78 result = loadNative();
79 (*env)->SetBooleanArrayRegion(env, jResult, 0, 2, result);
80 free(result);
81 }
82 return jResult;
|
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #include <stdlib.h>
27 #include <string.h>
28 #include <strings.h>
29 #include <jni.h>
30 #include "jni_util.h"
31 #include <libsoftcrypto.h>
32 #include "nativeCrypto.h"
33 #include "nativeFunc.h"
34
35 /*
36 * Dumps out byte array in hex with and name and length info
37 */
38 void printBytes(char* header, unsigned char* bytes, int len) {
39 int i;
40
41 printf("%s", header);
42 printf("len=%d {", len);
43 for (i = 0; i < len; i++) {
44 if (i > 0) printf(":");
45 printf("%02X", bytes[i]);
46 }
47 printf("}\n");
48 }
49
50 /*
51 * Throws java.lang.OutOfMemoryError
52 */
53 void throwOutOfMemoryError(JNIEnv *env, const char *msg)
54 {
55 jclass jExClass = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
56 if (jExClass != 0) /* Otherwise an exception has already been thrown */ {
57 (*env)->ThrowNew(env, jExClass, msg);
58 }
59 /* free the local ref */
60 (*env)->DeleteLocalRef(env, jExClass);
61 }
62
63 JNIEXPORT jint JNICALL DEF_JNI_OnLoad(JavaVM *vm, void *reserved) {
64 return JNI_VERSION_1_4;
65 }
66
67 /*
68 * Class: com_oracle_security_ucrypto_UcryptoProvider
69 * Method: loadLibraries
70 * Signature: ()[Z
71 */
72 JNIEXPORT jbooleanArray JNICALL Java_com_oracle_security_ucrypto_UcryptoProvider_loadLibraries
73 (JNIEnv *env, jclass jcls) {
74 jbooleanArray jResult;
75 jboolean *result;
76 jResult = (*env)->NewBooleanArray(env, 2);
77
78 if (jResult != NULL) {
79 result = loadNative();
80 (*env)->SetBooleanArrayRegion(env, jResult, 0, 2, result);
81 free(result);
82 }
83 return jResult;
|