src/jdk.crypto.ucrypto/solaris/native/libj2ucrypto/nativeCryptoMD.c
author herrick
Wed, 14 Aug 2019 08:08:39 -0400
branchJDK-8200758-branch
changeset 57743 8d6f0aff03fc
parent 50471 f0aeede1b855
permissions -rw-r--r--
8226534: combination of windows options cause exception in MsiBundler Submitted-by: almatvee Reviewed-by: herrick, asemenyuk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
     1
/*
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
     4
 *
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    10
 *
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    15
 * accompanied this code).
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    16
 *
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    20
 *
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    23
 * questions.
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    24
 */
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    25
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    26
#include <stdlib.h>
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    27
#include <string.h>
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    28
#include <strings.h>
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    29
#include <jni.h>
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    30
#include "jni_util.h"
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    31
#include "nativeCrypto.h"
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    32
#include "nativeFunc.h"
50471
f0aeede1b855 8204572: SetupJdkLibrary should setup SRC and -I flags automatically
ihse
parents: 49440
diff changeset
    33
#include "com_oracle_security_ucrypto_NativeDigestMD.h"
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    34
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    35
extern void throwOutOfMemoryError(JNIEnv *env, const char *msg);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    36
extern jbyte* getBytes(JNIEnv *env, jbyteArray bytes, int offset, int len);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    37
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    38
///////////////////////////////////////////////////////
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    39
// SPECIAL ENTRIES FOR JVM JNI-BYPASSING OPTIMIZATION
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    40
////////////////////////////////////////////////////////
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
    41
JNIEXPORT jlong JNICALL
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
    42
JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeInit(jint mech) {
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    43
  void *pContext = NULL;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    44
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    45
  switch (mech) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    46
  case com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1:
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    47
    pContext = malloc(sizeof(SHA1_CTX));
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    48
    if (pContext != NULL) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    49
      (*ftab->sha1Init)((SHA1_CTX *)pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    50
    }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    51
    break;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    52
  case com_oracle_security_ucrypto_NativeDigestMD_MECH_MD5:
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    53
    pContext = malloc(sizeof(MD5_CTX));
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    54
    if (pContext != NULL) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    55
      (*ftab->md5Init)((MD5_CTX *)pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    56
    }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    57
    break;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    58
  case com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA256:
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    59
    pContext = malloc(sizeof(SHA2_CTX));
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    60
    if (pContext != NULL) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    61
      (*ftab->sha2Init)(SHA256, (SHA2_CTX *)pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    62
    }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    63
    break;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    64
  case com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA384:
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    65
    pContext = malloc(sizeof(SHA2_CTX));
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    66
    if (pContext != NULL) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    67
      (*ftab->sha2Init)(SHA384, (SHA2_CTX *)pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    68
    }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    69
    break;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    70
  case com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA512:
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    71
    pContext = malloc(sizeof(SHA2_CTX));
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    72
    if (pContext != NULL) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    73
      (*ftab->sha2Init)(SHA512, (SHA2_CTX *)pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    74
    }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    75
    break;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    76
  default:
42457
cd246ab491f9 8079898: Resolve disabled warnings for libj2ucrypto
valeriep
parents: 38878
diff changeset
    77
    if (J2UC_DEBUG) printf("ERROR: Unsupported mech %i\n", mech);
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    78
  }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    79
  return (jlong) pContext;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    80
}
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    81
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
    82
JNIEXPORT jint JNICALL
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
    83
JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeUpdate
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    84
  (jint mech, jlong pContext, int notUsed, unsigned char* in, jint ofs, jint len) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    85
  if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    86
    (*ftab->sha1Update)((SHA1_CTX*)pContext, (unsigned char*)(in+ofs), len);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    87
  } else if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_MD5) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    88
    (*ftab->md5Update)((MD5_CTX*)pContext, (unsigned char*)(in+ofs), len);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    89
  } else { // SHA-2 family
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    90
    (*ftab->sha2Update)((SHA2_CTX*)pContext, (unsigned char*)(in+ofs), len);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    91
  }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    92
  return 0;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    93
}
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    94
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    95
// Do digest and free the context immediately
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
    96
JNIEXPORT jint JNICALL
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
    97
JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeDigest
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    98
  (jint mech, jlong pContext, int notUsed, unsigned char* out, jint ofs, jint digestLen) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
    99
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   100
  if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   101
    (*ftab->sha1Final)((unsigned char*)(out + ofs), (SHA1_CTX *)pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   102
    free((SHA1_CTX *)pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   103
  } else if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_MD5) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   104
    (*ftab->md5Final)((unsigned char*)(out + ofs), (MD5_CTX *)pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   105
    free((MD5_CTX *)pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   106
  } else { // SHA-2 family
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   107
    (*ftab->sha2Final)((unsigned char*)(out + ofs), (SHA2_CTX *)pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   108
    free((SHA2_CTX *)pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   109
  }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   110
  return 0;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   111
}
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   112
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
   113
JNIEXPORT jlong JNICALL
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
   114
JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeClone
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   115
  (jint mech, jlong pContext) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   116
  void *copy = NULL;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   117
  size_t len = 0;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   118
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   119
  if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   120
    len = sizeof(SHA1_CTX);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   121
  } else if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_MD5) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   122
    len = sizeof(MD5_CTX);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   123
  } else { // SHA-2 family
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   124
    len = sizeof(SHA2_CTX);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   125
  }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   126
  copy = malloc(len);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   127
  if (copy != NULL) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   128
    bcopy((void *)pContext, copy, len);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   129
  }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   130
  return (jlong) copy;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   131
}
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   132
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
   133
JNIEXPORT void JNICALL
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
   134
JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeFree
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   135
  (jint mech, jlong pContext) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   136
  if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_SHA1) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   137
    free((SHA1_CTX*) pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   138
  } else if (mech == com_oracle_security_ucrypto_NativeDigestMD_MECH_MD5) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   139
    free((MD5_CTX*) pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   140
  } else { // SHA-2 family
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   141
    free((SHA2_CTX*) pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   142
  }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   143
}
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   144
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   145
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   146
/*
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   147
 * Class:     com_oracle_security_ucrypto_NativeDigestMD
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   148
 * Method:    nativeInit
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   149
 * Signature: (I)J
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   150
 */
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   151
JNIEXPORT jlong JNICALL Java_com_oracle_security_ucrypto_NativeDigestMD_nativeInit
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   152
  (JNIEnv *env, jclass jcls, jint mech) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   153
  jlong result = JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeInit(mech);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   154
  if (result == NULL) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   155
     throwOutOfMemoryError(env, NULL);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   156
  }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   157
  return result;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   158
}
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   159
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   160
/*
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   161
 * Class:     com_oracle_security_ucrypto_NativeDigestMD
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   162
 * Method:    nativeUpdate
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   163
 * Signature: (IJ[BII)I
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   164
 */
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   165
JNIEXPORT jint JNICALL Java_com_oracle_security_ucrypto_NativeDigestMD_nativeUpdate
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   166
  (JNIEnv *env, jclass jcls, jint mech, jlong pContext, jbyteArray jIn, jint jOfs, jint jLen) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   167
  unsigned char *bufIn;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   168
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   169
  bufIn = (unsigned char *) getBytes(env, jIn, jOfs, jLen);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   170
  if (!(*env)->ExceptionCheck(env)) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   171
    JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeUpdate(mech, pContext, jLen, bufIn, 0, jLen);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   172
    free(bufIn);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   173
  }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   174
  return 0;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   175
}
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   176
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   177
/*
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   178
 * Class:     com_oracle_security_ucrypto_NativeDigestMD
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   179
 * Method:    nativeDigest
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   180
 * Signature: (IJ[BII)I
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   181
 */
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   182
JNIEXPORT jint JNICALL Java_com_oracle_security_ucrypto_NativeDigestMD_nativeDigest
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   183
  (JNIEnv *env, jclass jcls, jint mech, jlong pContext, jbyteArray jOut, jint jOutOfs, jint digestLen) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   184
  unsigned char *bufOut;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   185
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   186
  bufOut = (unsigned char *) malloc(digestLen);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   187
  if (bufOut == NULL) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   188
    throwOutOfMemoryError(env, NULL);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   189
    return 0;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   190
  }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   191
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   192
  JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeDigest(mech, pContext, digestLen, bufOut, 0, digestLen);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   193
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   194
  (*env)->SetByteArrayRegion(env, jOut, jOutOfs, digestLen, (jbyte *) bufOut);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   195
  free(bufOut);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   196
  return 0;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   197
}
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   198
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   199
/*
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   200
 * Class:     com_oracle_security_ucrypto_NativeDigestMD
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   201
 * Method:    nativeClone
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   202
 * Signature: (IJ)J
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   203
 */
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   204
JNIEXPORT jlong JNICALL Java_com_oracle_security_ucrypto_NativeDigestMD_nativeClone
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   205
  (JNIEnv *env, jclass jcls, jint mech, jlong pContext) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   206
  return JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeClone(mech, pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   207
}
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   208
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   209
/*
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   210
 * Class:     com_oracle_security_ucrypto_NativeDigestMD
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   211
 * Method:    nativeFree
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   212
 * Signature: (IJ)V
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   213
 */
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   214
JNIEXPORT void JNICALL Java_com_oracle_security_ucrypto_NativeDigestMD_nativeFree
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   215
  (JNIEnv *env, jclass jcls, jint mech, jlong pContext) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   216
  JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeFree(mech, pContext);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   217
}
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents:
diff changeset
   218