1 /* |
1 /* |
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
36 extern jbyte* getBytes(JNIEnv *env, jbyteArray bytes, int offset, int len); |
36 extern jbyte* getBytes(JNIEnv *env, jbyteArray bytes, int offset, int len); |
37 |
37 |
38 /////////////////////////////////////////////////////// |
38 /////////////////////////////////////////////////////// |
39 // SPECIAL ENTRIES FOR JVM JNI-BYPASSING OPTIMIZATION |
39 // SPECIAL ENTRIES FOR JVM JNI-BYPASSING OPTIMIZATION |
40 //////////////////////////////////////////////////////// |
40 //////////////////////////////////////////////////////// |
41 jlong JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeInit(jint mech) { |
41 JNIEXPORT jlong JNICALL |
|
42 JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeInit(jint mech) { |
42 void *pContext = NULL; |
43 void *pContext = NULL; |
43 |
44 |
44 switch (mech) { |
45 switch (mech) { |
45 case com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1: |
46 case com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1: |
46 pContext = malloc(sizeof(SHA1_CTX)); |
47 pContext = malloc(sizeof(SHA1_CTX)); |
76 if (J2UC_DEBUG) printf("ERROR: Unsupported mech %i\n", mech); |
77 if (J2UC_DEBUG) printf("ERROR: Unsupported mech %i\n", mech); |
77 } |
78 } |
78 return (jlong) pContext; |
79 return (jlong) pContext; |
79 } |
80 } |
80 |
81 |
81 jint JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeUpdate |
82 JNIEXPORT jint JNICALL |
|
83 JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeUpdate |
82 (jint mech, jlong pContext, int notUsed, unsigned char* in, jint ofs, jint len) { |
84 (jint mech, jlong pContext, int notUsed, unsigned char* in, jint ofs, jint len) { |
83 if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1) { |
85 if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1) { |
84 (*ftab->sha1Update)((SHA1_CTX*)pContext, (unsigned char*)(in+ofs), len); |
86 (*ftab->sha1Update)((SHA1_CTX*)pContext, (unsigned char*)(in+ofs), len); |
85 } else if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_MD5) { |
87 } else if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_MD5) { |
86 (*ftab->md5Update)((MD5_CTX*)pContext, (unsigned char*)(in+ofs), len); |
88 (*ftab->md5Update)((MD5_CTX*)pContext, (unsigned char*)(in+ofs), len); |
89 } |
91 } |
90 return 0; |
92 return 0; |
91 } |
93 } |
92 |
94 |
93 // Do digest and free the context immediately |
95 // Do digest and free the context immediately |
94 jint JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeDigest |
96 JNIEXPORT jint JNICALL |
|
97 JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeDigest |
95 (jint mech, jlong pContext, int notUsed, unsigned char* out, jint ofs, jint digestLen) { |
98 (jint mech, jlong pContext, int notUsed, unsigned char* out, jint ofs, jint digestLen) { |
96 |
99 |
97 if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1) { |
100 if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1) { |
98 (*ftab->sha1Final)((unsigned char*)(out + ofs), (SHA1_CTX *)pContext); |
101 (*ftab->sha1Final)((unsigned char*)(out + ofs), (SHA1_CTX *)pContext); |
99 free((SHA1_CTX *)pContext); |
102 free((SHA1_CTX *)pContext); |
105 free((SHA2_CTX *)pContext); |
108 free((SHA2_CTX *)pContext); |
106 } |
109 } |
107 return 0; |
110 return 0; |
108 } |
111 } |
109 |
112 |
110 jlong JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeClone |
113 JNIEXPORT jlong JNICALL |
|
114 JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeClone |
111 (jint mech, jlong pContext) { |
115 (jint mech, jlong pContext) { |
112 void *copy = NULL; |
116 void *copy = NULL; |
113 size_t len = 0; |
117 size_t len = 0; |
114 |
118 |
115 if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1) { |
119 if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1) { |
124 bcopy((void *)pContext, copy, len); |
128 bcopy((void *)pContext, copy, len); |
125 } |
129 } |
126 return (jlong) copy; |
130 return (jlong) copy; |
127 } |
131 } |
128 |
132 |
129 void JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeFree |
133 JNIEXPORT void JNICALL |
|
134 JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeFree |
130 (jint mech, jlong pContext) { |
135 (jint mech, jlong pContext) { |
131 if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1) { |
136 if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1) { |
132 free((SHA1_CTX*) pContext); |
137 free((SHA1_CTX*) pContext); |
133 } else if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_MD5) { |
138 } else if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_MD5) { |
134 free((MD5_CTX*) pContext); |
139 free((MD5_CTX*) pContext); |