src/jdk.crypto.ucrypto/solaris/native/libj2ucrypto/nativeFunc.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47216 71c04702a3d5
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     1
/*
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     4
 *
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    10
 *
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    15
 * accompanied this code).
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    16
 *
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    20
 *
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    23
 * questions.
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    24
 */
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    25
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    26
#include <jni.h>
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    27
#include <stdio.h>
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    28
#include <stdlib.h>
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    29
#include <dlfcn.h>
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    30
#include <link.h>
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    31
#include "nativeFunc.h"
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    32
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    33
/* standard md5/md/softcrypto method names (ordering is from mapfile) */
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    34
static const char MD5_INIT[]                     = "MD5Init";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    35
static const char MD5_UPDATE[]                   = "MD5Update";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    36
static const char MD5_FINAL[]                    = "MD5Final";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    37
static const char SHA1_INIT[]                    = "SHA1Init";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    38
static const char SHA1_UPDATE[]                  = "SHA1Update";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    39
static const char SHA1_FINAL[]                   = "SHA1Final";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    40
static const char SHA2_INIT[]                    = "SHA2Init";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    41
static const char SHA2_UPDATE[]                  = "SHA2Update";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    42
static const char SHA2_FINAL[]                   = "SHA2Final";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    43
static const char UCRYPTO_VERSION[]              = "ucrypto_version";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    44
static const char UCRYPTO_GET_MECHLIST[]         = "ucrypto_get_mechlist";
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
    45
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    46
static const char UCRYPTO_ENCRYPT_INIT[]         = "ucrypto_encrypt_init";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    47
static const char UCRYPTO_ENCRYPT_UPDATE[]       = "ucrypto_encrypt_update";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    48
static const char UCRYPTO_ENCRYPT_FINAL[]        = "ucrypto_encrypt_final";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    49
static const char UCRYPTO_ENCRYPT[]              = "ucrypto_encrypt";
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
    50
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    51
static const char UCRYPTO_DECRYPT_INIT[]         = "ucrypto_decrypt_init";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    52
static const char UCRYPTO_DECRYPT_UPDATE[]       = "ucrypto_decrypt_update";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    53
static const char UCRYPTO_DECRYPT_FINAL[]        = "ucrypto_decrypt_final";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    54
static const char UCRYPTO_DECRYPT[]              = "ucrypto_decrypt";
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
    55
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    56
static const char UCRYPTO_SIGN_INIT[]            = "ucrypto_sign_init";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    57
static const char UCRYPTO_SIGN_UPDATE[]          = "ucrypto_sign_update";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    58
static const char UCRYPTO_SIGN_FINAL[]           = "ucrypto_sign_final";
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
    59
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    60
static const char UCRYPTO_VERIFY_INIT[]          = "ucrypto_verify_init";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    61
static const char UCRYPTO_VERIFY_UPDATE[]        = "ucrypto_verify_update";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    62
static const char UCRYPTO_VERIFY_FINAL[]         = "ucrypto_verify_final";
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    63
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
    64
static const char UCRYPTO_DIGEST_INIT[]          = "ucrypto_digest_init";
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
    65
static const char UCRYPTO_DIGEST_UPDATE[]        = "ucrypto_digest_update";
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
    66
static const char UCRYPTO_DIGEST_FINAL[]         = "ucrypto_digest_final";
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
    67
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
    68
static const char UCRYPTO_FREE_CONTEXT[]         = "ucrypto_free_context";
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
    69
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
    70
static const char UCRYPTO_STRERROR[]             = "ucrypto_strerror";
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
    71
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    72
/**
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    73
 * Initialize native T4 crypto function pointers
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    74
 */
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
    75
jboolean* loadNative(void) {
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    76
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    77
  jboolean* buf;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    78
  void *lib;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    79
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    80
  buf = malloc(2 * sizeof(jboolean));
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    81
  buf[0] = buf[1] = JNI_FALSE;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    82
  ftab = (T4CRYPTO_FUNCTION_TABLE_PTR) calloc(1, sizeof(T4CRYPTO_FUNCTION_TABLE));
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    83
  if (ftab == NULL) {
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    84
    free(buf);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    85
    return NULL;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    86
  }
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    87
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    88
  lib = dlopen("libsoftcrypto.so", RTLD_NOW);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    89
  if (lib != NULL) {
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    90
    // These APIs aren't available for v0 lib on Solaris 10
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    91
    ftab->ucryptoVersion = (UCRYPTO_VERSION_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    92
      dlsym(lib, UCRYPTO_VERSION);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    93
    ftab->ucryptoGetMechList = (UCRYPTO_GET_MECHLIST_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    94
      dlsym(lib, UCRYPTO_GET_MECHLIST);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    95
    ftab->ucryptoSignInit = (UCRYPTO_SIGN_INIT_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    96
      dlsym(lib, UCRYPTO_SIGN_INIT);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    97
    ftab->ucryptoSignUpdate = (UCRYPTO_SIGN_UPDATE_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    98
      dlsym(lib, UCRYPTO_SIGN_UPDATE);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
    99
    ftab->ucryptoSignFinal = (UCRYPTO_SIGN_FINAL_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   100
      dlsym(lib, UCRYPTO_SIGN_FINAL);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   101
    ftab->ucryptoVerifyInit = (UCRYPTO_VERIFY_INIT_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   102
      dlsym(lib, UCRYPTO_VERIFY_INIT);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   103
    ftab->ucryptoVerifyUpdate = (UCRYPTO_VERIFY_UPDATE_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   104
      dlsym(lib, UCRYPTO_VERIFY_UPDATE);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   105
    ftab->ucryptoVerifyFinal = (UCRYPTO_VERIFY_FINAL_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   106
      dlsym(lib, UCRYPTO_VERIFY_FINAL);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   107
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   108
    // These APS are added starting S12
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   109
    ftab->ucryptoDigestInit = (UCRYPTO_DIGEST_INIT_FN_PTR)
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   110
      dlsym(lib, UCRYPTO_DIGEST_INIT);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   111
    ftab->ucryptoDigestUpdate = (UCRYPTO_DIGEST_UPDATE_FN_PTR)
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   112
      dlsym(lib, UCRYPTO_DIGEST_UPDATE);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   113
    ftab->ucryptoDigestFinal = (UCRYPTO_DIGEST_FINAL_FN_PTR)
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   114
      dlsym(lib, UCRYPTO_DIGEST_FINAL);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   115
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   116
    ftab->ucryptoFreeContext = (UCRYPTO_FREE_CONTEXT_FN_PTR)
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   117
      dlsym(lib, UCRYPTO_FREE_CONTEXT);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   118
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   119
    ftab->ucryptoStrerror = (UCRYPTO_STRERROR_FN_PTR)
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   120
      dlsym(lib, UCRYPTO_STRERROR);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   121
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   122
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   123
    // These should be avilable for all libsoftcrypto libs
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   124
    ftab->ucryptoEncryptInit = (UCRYPTO_ENCRYPT_INIT_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   125
      dlsym(lib, UCRYPTO_ENCRYPT_INIT);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   126
    ftab->ucryptoEncryptUpdate = (UCRYPTO_ENCRYPT_UPDATE_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   127
      dlsym(lib, UCRYPTO_ENCRYPT_UPDATE);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   128
    ftab->ucryptoEncryptFinal = (UCRYPTO_ENCRYPT_FINAL_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   129
      dlsym(lib, UCRYPTO_ENCRYPT_FINAL);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   130
    ftab->ucryptoEncrypt = (UCRYPTO_ENCRYPT_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   131
      dlsym(lib, UCRYPTO_ENCRYPT);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   132
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   133
    ftab->ucryptoDecryptInit = (UCRYPTO_DECRYPT_INIT_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   134
      dlsym(lib, UCRYPTO_DECRYPT_INIT);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   135
    ftab->ucryptoDecryptUpdate = (UCRYPTO_DECRYPT_UPDATE_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   136
      dlsym(lib, UCRYPTO_DECRYPT_UPDATE);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   137
    ftab->ucryptoDecryptFinal = (UCRYPTO_DECRYPT_FINAL_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   138
      dlsym(lib, UCRYPTO_DECRYPT_FINAL);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   139
    ftab->ucryptoDecrypt = (UCRYPTO_DECRYPT_FN_PTR)
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   140
      dlsym(lib, UCRYPTO_DECRYPT);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   141
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   142
    if (ftab->ucryptoEncryptInit != NULL &&
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   143
        ftab->ucryptoEncryptUpdate != NULL &&
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   144
        ftab->ucryptoEncryptFinal != NULL &&
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   145
        ftab->ucryptoEncrypt != NULL &&
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   146
        ftab->ucryptoDecryptInit != NULL &&
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   147
        ftab->ucryptoDecryptUpdate != NULL &&
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   148
        ftab->ucryptoDecryptFinal != NULL &&
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   149
        ftab->ucryptoDecrypt != NULL) {
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   150
      buf[1] = JNI_TRUE;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   151
    } else {
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   152
      dlclose(lib);
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   153
    }
37909
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   154
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   155
    // proceed with libmd when libucrypto does not support digest operations
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   156
    if (ftab->ucryptoDigestInit == NULL ||
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   157
        ftab->ucryptoDigestUpdate == NULL ||
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   158
        ftab->ucryptoDigestFinal == NULL) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   159
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   160
      lib = dlopen("libmd.so", RTLD_NOW);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   161
      if (lib != NULL) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   162
        ftab->md5Init = (MD5INIT_FN_PTR) dlsym(lib, MD5_INIT);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   163
        ftab->md5Update = (MD5UPDATE_FN_PTR) dlsym(lib, MD5_UPDATE);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   164
        ftab->md5Final = (MD5FINAL_FN_PTR) dlsym(lib, MD5_FINAL);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   165
        ftab->sha1Init = (SHA1INIT_FN_PTR) dlsym(lib, SHA1_INIT);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   166
        ftab->sha1Update = (SHA1UPDATE_FN_PTR) dlsym(lib, SHA1_UPDATE);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   167
        ftab->sha1Final = (SHA1FINAL_FN_PTR) dlsym(lib, SHA1_FINAL);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   168
        ftab->sha2Init = (SHA2INIT_FN_PTR) dlsym(lib, SHA2_INIT);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   169
        ftab->sha2Update = (SHA2UPDATE_FN_PTR) dlsym(lib, SHA2_UPDATE);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   170
        ftab->sha2Final = (SHA2FINAL_FN_PTR) dlsym(lib, SHA2_FINAL);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   171
        if (ftab->md5Init != NULL && ftab->md5Update != NULL &&
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   172
            ftab->md5Final != NULL && ftab->sha1Init != NULL &&
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   173
            ftab->sha1Update != NULL && ftab->sha1Final != NULL &&
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   174
            ftab->sha2Init != NULL && ftab->sha2Update != NULL &&
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   175
            ftab->sha2Final != NULL) {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   176
          buf[0] = JNI_TRUE;
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   177
        } else {
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   178
          dlclose(lib);
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   179
        }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   180
      }
38b1efe33344 8000415: Add support for SHA-3
valeriep
parents: 27182
diff changeset
   181
    }
27182
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   182
  }
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   183
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   184
  return buf;
4525d13b8af1 8046002: Move Ucrypto to the open jdk repo
valeriep
parents:
diff changeset
   185
}