diff --git a/.github/workflows/maven-ci-macos.yml b/.github/workflows/maven-ci-macos.yml
new file mode 100644
index 0000000..bab7ddb
--- /dev/null
+++ b/.github/workflows/maven-ci-macos.yml
@@ -0,0 +1,46 @@
+# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
+# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
+
+# This workflow uses actions that are not certified by GitHub.
+# They are provided by a third-party and are governed by
+# separate terms of service, privacy policy, and support
+# documentation.
+
+name: Maven CI-macos
+on:
+ push:
+ branches: [ "main" ]
+ pull_request:
+ branches: [ "main" ]
+env:
+ BUILD_TYPE: Debug
+
+jobs:
+ build:
+ runs-on: macos-latest
+
+ steps:
+ - uses: actions/checkout@v3
+
+ - name: Set up JDK 18
+ uses: actions/setup-java@v2
+ with:
+ java-version: '18'
+ distribution: 'temurin'
+ cache: maven
+
+ - name: Build GmSSL
+ run : |
+ git clone https://github.com/guanzhi/GmSSL.git
+ cd GmSSL
+ mkdir build
+ cd build
+ cmake .. -DCMAKE_OSX_ARCHITECTURES=x86_64
+ make
+ sudo make install
+
+ - name: Set DYLD_LIBRARY_PATH
+ run: echo "DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH" >> $GITHUB_ENV
+
+ - name: Build with Maven
+ run: sudo mvn -B -X package --file pom.xml
diff --git a/.github/workflows/maven-ci-release-macos.yml b/.github/workflows/maven-ci-release-macos.yml
new file mode 100644
index 0000000..6e1e689
--- /dev/null
+++ b/.github/workflows/maven-ci-release-macos.yml
@@ -0,0 +1,51 @@
+name: maven-ci-release-macos
+
+on:
+ push:
+ branches: [ "main" ]
+ pull_request:
+ branches: [ "main" ]
+env:
+ BUILD_TYPE: Release
+
+jobs:
+ build:
+ runs-on: macos-latest
+
+ steps:
+ - uses: actions/checkout@v3
+
+ - name: Set up JDK 18
+ uses: actions/setup-java@v2
+ with:
+ java-version: '18'
+ distribution: 'temurin'
+ cache: maven
+
+ - name: Download GmSSL release
+ run: curl -L "https://github.com/guanzhi/GmSSL/archive/refs/tags/v3.1.1.zip" -o "GmSSL.zip"
+
+ - name: Extract GmSSL
+ run: unzip GmSSL.zip
+
+ - name: Build GmSSL
+ run: |
+ cd GmSSL-3.1.1
+ mkdir build
+ cd build
+ cmake .. -DCMAKE_OSX_ARCHITECTURES=x86_64
+ make
+ sudo make install
+
+ - name: Set DYLD_LIBRARY_PATH
+ run: echo "DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH" >> $GITHUB_ENV
+
+ - name: Verify Installation and Environment
+ run: gmssl version
+
+ - name: Build with Maven
+ run: mvn clean install
+
+ - name: Clean up
+ if: always()
+ run: rm GmSSL.zip
diff --git a/.github/workflows/maven-ci-release-ubuntu.yml b/.github/workflows/maven-ci-release-ubuntu.yml
new file mode 100644
index 0000000..f4696b7
--- /dev/null
+++ b/.github/workflows/maven-ci-release-ubuntu.yml
@@ -0,0 +1,52 @@
+name: maven-ci-release-ubuntu
+
+on:
+ push:
+ branches: [ "main" ]
+ pull_request:
+ branches: [ "main" ]
+env:
+ BUILD_TYPE: Release
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+
+ - name: Set up JDK 18
+ uses: actions/setup-java@v2
+ with:
+ java-version: '18'
+ distribution: 'temurin'
+ cache: maven
+
+ - name: Install dependencies
+ run: sudo apt-get update && sudo apt-get install -y cmake build-essential
+
+ - name: Download GmSSL release
+ run: wget "https://github.com/guanzhi/GmSSL/archive/refs/tags/v3.1.1.zip" -O "GmSSL.zip"
+
+ - name: Extract GmSSL
+ run: unzip GmSSL.zip
+
+ - name: Build GmSSL
+ run: |
+ cd GmSSL-3.1.1
+ mkdir build
+ cd build
+ cmake ..
+ make
+ sudo make install
+ sudo ldconfig
+
+ - name: Verify Installation and Environment
+ run: gmssl version
+
+ - name: Build with Maven
+ run: mvn clean install
+
+ - name: Clean up
+ if: always()
+ run: rm GmSSL.zip
diff --git a/.github/workflows/maven-ci-release-windows.yml b/.github/workflows/maven-ci-release-windows.yml
new file mode 100644
index 0000000..3463cb8
--- /dev/null
+++ b/.github/workflows/maven-ci-release-windows.yml
@@ -0,0 +1,71 @@
+# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
+# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
+
+# This workflow uses actions that are not certified by GitHub.
+# They are provided by a third-party and are governed by
+# separate terms of service, privacy policy, and support
+# documentation.
+
+name: maven-ci-release-windows
+
+on:
+ push:
+ branches: [ "main" ]
+ pull_request:
+ branches: [ "main" ]
+env:
+ BUILD_TYPE: Release
+
+jobs:
+ build:
+ runs-on: windows-latest
+
+ steps:
+ - uses: actions/checkout@v3
+
+ - name: Configure build for x86
+ uses: ilammy/msvc-dev-cmd@v1
+ with:
+ arch: amd64
+
+ - name: Set up JDK 18
+ uses: actions/setup-java@v2
+ with:
+ java-version: '18'
+ distribution: 'temurin'
+ cache: maven
+
+ - name: Set up environment variable in windows
+ uses: myci-actions/append-to-path-windows@2
+ with:
+ path: C:\Program Files\GmSSL\bin
+ env-var: PATH
+
+ - name: Download GmSSL release
+ run: |
+ Invoke-WebRequest -Uri "https://github.com/guanzhi/GmSSL/archive/refs/tags/v3.1.1.zip" -OutFile "GmSSL.zip"
+
+ - name: Extract GmSSL
+ run: |
+ Expand-Archive -Path "GmSSL.zip" -DestinationPath "."
+
+ - name: Build GmSSL
+ run: |
+ cd GmSSL-3.1.1;
+ mkdir build;
+ cd build;
+ cmake .. -G "NMake Makefiles" -DWIN32=ON;
+ nmake ;
+ nmake install;
+
+ - name: Verify Installation and Environment
+ run: |
+ gmssl version
+
+ - name: Build with Maven
+ run: mvn clean install
+
+ - name: Clean up
+ if: always()
+ run: |
+ Remove-Item GmSSL.zip
diff --git a/.github/workflows/maven-ci-ubuntu.yml b/.github/workflows/maven-ci-ubuntu.yml
new file mode 100644
index 0000000..923889e
--- /dev/null
+++ b/.github/workflows/maven-ci-ubuntu.yml
@@ -0,0 +1,37 @@
+# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
+# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
+
+# This workflow uses actions that are not certified by GitHub.
+# They are provided by a third-party and are governed by
+# separate terms of service, privacy policy, and support
+# documentation.
+
+name: Maven CI-ubuntu
+on:
+ push:
+ branches: [ "main" ]
+ pull_request:
+ branches: [ "main" ]
+env:
+ # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
+ BUILD_TYPE: Debug
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+
+ - name: Set up JDK 17
+ uses: actions/setup-java@v3
+ with:
+ java-version: '17'
+ distribution: 'temurin'
+ cache: maven
+
+ - name: Build GmSSL
+ run : git clone https://github.com/guanzhi/GmSSL.git; cd GmSSL; mkdir build; cd build; cmake ..; make;sudo make install;sudo ldconfig
+
+ - name: Build with Maven
+ run: sudo mvn -B package --file pom.xml
diff --git a/.github/workflows/maven-ci-windows.yml b/.github/workflows/maven-ci-windows.yml
new file mode 100644
index 0000000..dba7e61
--- /dev/null
+++ b/.github/workflows/maven-ci-windows.yml
@@ -0,0 +1,56 @@
+
+# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
+# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
+
+# This workflow uses actions that are not certified by GitHub.
+# They are provided by a third-party and are governed by
+# separate terms of service, privacy policy, and support
+# documentation.
+
+name: Maven CI-windows
+on:
+ push:
+ branches: [ "main" ]
+ pull_request:
+ branches: [ "main" ]
+env:
+ BUILD_TYPE: Debug
+
+jobs:
+ build:
+ runs-on: windows-latest
+
+ steps:
+ - uses: actions/checkout@v3
+
+ - name: Configure build for x86
+ uses: ilammy/msvc-dev-cmd@v1
+ with:
+ arch: amd64
+
+ - name: Set up JDK 18
+ uses: actions/setup-java@v2
+ with:
+ java-version: '18'
+ distribution: 'temurin'
+ cache: maven
+
+ - name: Set up environment variable in windows
+ uses: myci-actions/append-to-path-windows@2
+ with:
+ path: C:\Program Files\GmSSL\bin
+ env-var: PATH
+
+ - name: Build GmSSL
+ run : |
+ git clone https://github.com/guanzhi/GmSSL.git;
+ cd GmSSL;
+ mkdir build;
+ cd build;
+ cmake .. -G "NMake Makefiles" -DWIN32=ON;
+ nmake ;
+ nmake install;
+
+ - name: Build with Maven
+ run: mvn clean install
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
deleted file mode 100644
index c13e3e3..0000000
--- a/CMakeLists.txt
+++ /dev/null
@@ -1,64 +0,0 @@
-cmake_minimum_required(VERSION 3.11)
-project(gmssljni)
-
-add_library(gmssljni-native SHARED gmssljni.c)
-target_include_directories(gmssljni-native PUBLIC ${CMAKE_SOURCE_DIR}/src/include)
-target_link_libraries(gmssljni-native -L/usr/local/lib)
-target_link_libraries(gmssljni-native gmssl)
-set_target_properties(gmssljni-native PROPERTIES OUTPUT_NAME gmssljni)
-
-
-find_package(Java REQUIRED)
-include(UseJava)
-include_directories(jni)
-include_directories(/usr/local/include)
-
-# javac src/main/java/org/gmssl/GmSSLJNI.java -d .
-# jar cf GmSSLJNI.jar GmSSLJNI.class
-add_jar(GmSSLJNI
- VERSION 2.1.0-dev
- ENTRY_POINT org.gmssl.GmSSLJNI
- GENERATE_NATIVE_HEADERS
- OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}
- SOURCES src/main/java/org/gmssl/GmSSLJNI.java
- src/main/java/org/gmssl/GmSSLException.java
- src/main/java/org/gmssl/Random.java
- src/main/java/org/gmssl/Sm3.java
- src/main/java/org/gmssl/Sm3Hmac.java
- src/main/java/org/gmssl/Sm3Pbkdf2.java
- src/main/java/org/gmssl/Sm4.java
- src/main/java/org/gmssl/Sm4Cbc.java
- src/main/java/org/gmssl/Sm4Ctr.java
- src/main/java/org/gmssl/Sm4Gcm.java
- src/main/java/org/gmssl/Zuc.java
- src/main/java/org/gmssl/Sm2Key.java
- src/main/java/org/gmssl/Sm2Signature.java
- src/main/java/org/gmssl/Sm2Certificate.java
- src/main/java/org/gmssl/Sm9EncMasterKey.java
- src/main/java/org/gmssl/Sm9EncKey.java
- src/main/java/org/gmssl/Sm9SignMasterKey.java
- src/main/java/org/gmssl/Sm9SignKey.java
- src/main/java/org/gmssl/Sm9Signature.java
- src/main/java/org/gmssl/NativeLoader.java
- )
-
-enable_testing()
-
-set(certfile
-"-----BEGIN CERTIFICATE-----\n"
-"MIIBszCCAVegAwIBAgIIaeL+wBcKxnswDAYIKoEcz1UBg3UFADAuMQswCQYDVQQG\n"
-"EwJDTjEOMAwGA1UECgwFTlJDQUMxDzANBgNVBAMMBlJPT1RDQTAeFw0xMjA3MTQw\n"
-"MzExNTlaFw00MjA3MDcwMzExNTlaMC4xCzAJBgNVBAYTAkNOMQ4wDAYDVQQKDAVO\n"
-"UkNBQzEPMA0GA1UEAwwGUk9PVENBMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE\n"
-"MPCca6pmgcchsTf2UnBeL9rtp4nw+itk1Kzrmbnqo05lUwkwlWK+4OIrtFdAqnRT\n"
-"V7Q9v1htkv42TsIutzd126NdMFswHwYDVR0jBBgwFoAUTDKxl9kzG8SmBcHG5Yti\n"
-"W/CXdlgwDAYDVR0TBAUwAwEB/zALBgNVHQ8EBAMCAQYwHQYDVR0OBBYEFEwysZfZ\n"
-"MxvEpgXBxuWLYlvwl3ZYMAwGCCqBHM9VAYN1BQADSAAwRQIgG1bSLeOXp3oB8H7b\n"
-"53W+CKOPl2PknmWEq/lMhtn25HkCIQDaHDgWxWFtnCrBjH16/W3Ezn7/U/Vjo5xI\n"
-"pDoiVhsLwg==\n"
-"-----END CERTIFICATE-----\n")
-file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/ROOTCA.pem ${certfile})
-
-# java -cp GmSSLJNI.jar org.gmssl.GmSSLJNI
-add_test(NAME main COMMAND java -cp GmSSLJNI.jar -Djava.library.path=./ org.gmssl.GmSSLJNI)
-
diff --git a/README.md b/README.md
index f7d6ab9..9df6b1c 100644
--- a/README.md
+++ b/README.md
@@ -8,12 +8,6 @@ GmSSL-Java是采用JNI (Java Native Interface)方式实现的,也就是说所
因为GmSSL-Java以JNI方式实现,GmSSL-Java不仅包含Java语言实现的Java类库(Jar包),还包括C语言实现的本地库(libgmssljni动态库),其中libgmssljni这个本地库是Java接口类库和GmSSL库(libgmssl)之间的胶水层,应用部署时还需要保证系统中已经安全了GmSSL库。虽然看起来这种实现方式比纯Java实现的类似更麻烦,而且因为包含C编译的本地代码,这个类库也失去了Java代码一次编译到处运行的跨平台能力,但是这是密码库的主流实现方式。相对于纯Java实现来说,GmSSL-Java可以充分利用成熟和功能丰富的GmSSL库,在性能、标准兼容性上都更有优势,并且可以随着GmSSL主项目的升级获得功能和性能上的升级。
-## 下载
-
-* GmSSL-Java主分支源代码 [GmSSL-Java-main.zip](https://github.com/GmSSL/GmSSL-Java/archive/refs/heads/main.zip) (版本号:2.1.0 dev)
-* 依赖的GmSSL库主分支源代码 [GmSSL-master.zip](https://github.com/guanzhi/GmSSL/archive/refs/heads/master.zip) (版本号:3.1.1 Dev)]
-* GitHub主页:https://github.com/GmSSL/GmSSL-Java
-
## 项目构成
GmSSL的项目组成主要包括C语言的本地代码、`src`目录下的Java类库代码、`examples`目录下面的例子代码。其中只有本地代码和`src`下面的Java类库代码会参与默认的编译,生成动态库和Jar包,而`examples`下的例子默认不编译也不进入Jar包。
@@ -47,46 +41,57 @@ GmSSL-Java提供一个包`org.gmssl`,其中包含如下密码算法类
+## 下载
-## 编译和安装
+### 主页
+* GmSSL-Java主页 [GmSSL-Java](https://github.com/GmSSL/GmSSL-Java)
+* 依赖的GmSSL库主页 [GmSSL](https://github.com/guanzhi/GmSSL)
-GmSSL-Java依赖GmSSL项目,在编译前需要先在系统上编译、安装并测试通过GmSSL库及工具。请在https://github.com/guanzhi/GmSSL 项目上下载最新的GmSSL代码,并完成编译、测试和安装。
+### 最新发布
+* GmSSL-Java发布页,支持windows、Linux、MacOS多平台 [GmSSL-Java](https://github.com/GmSSL/GmSSL-Java/releases)
+* 依赖的GmSSL发布页,包含windows、Linux、MacOS多平台 [GmSSL](https://github.com/guanzhi/GmSSL/releases)
+* 当前最新发布版本 3.1.1
+ [GmSSL-Java](https://github.com/GmSSL/GmSSL-Java/archive/refs/heads/main.zip)
+ [GmSSL](https://github.com/guanzhi/GmSSL/archive/refs/tags/v3.1.1.zip)
-首先下载最新的GmSSL-Java代码,然后安装编译工具链。
+## 编译和安装
-GmSSL-Java的当前版本采用CMake编译工具链,需要在系统上安装基础的GCC编译工具链、CMake和Java环境,在Ubuntu/Debian系统上可以执行如下命令安装依赖的工具。
+### 编译安装GmSSL
+GmSSL-Java依赖GmSSL项目,在编译前需要先在系统上编译、安装并测试通过GmSSL库及工具。请在https://github.com/guanzhi/GmSSL 项目上下载最新发布的GmSSL代码,并完成编译、测试和安装。
-```bash
-sudo apt update
-sudo apt install build-essential cmake default-jdk
-```
+### 通过Maven编译安装GmSSL-java
-安装完成后可以通过CMake编译
+安装Java开发环境和Maven,检查JAVA、Maven、GmSSL的C库环境变量是否配置正确
-```bash
-mkdir build
-cd build
-cmake ..
-make
-make test
+```shell
+$ java -version
+$ echo $JAVA_HOME
+$ mvn -v
+$ gmssl version
```
-编译并测试成功后可以显示
-
-```bash
-$ make test
-Running tests...
-Test project /path/to/GmSSL-Java/build
- Start 1: main
-1/1 Test #1: main ............................. Passed 2.27 sec
-
-100% tests passed, 0 tests failed out of 1
-
-Total Test time (real) = 2.27 sec
+MacOS环境下在resources目录config.properties设置了生成库的引用库macReferencedLib,为方便项目运行进行配置,本项目生成库引用关系可通过otool -L命令查看,也可以通过下面命令修正本项目生成库的实际引用关系,
+install_name_tool -change /path/xxx/libgmssl.3.dylib @rpath/libgmssl.3.dylib /project/xxx/libgmssljni.dylib
+,此时macReferencedLib参数可不必配置。
+```
+macReferencedLib 设置MacOS系统下依赖的GmSSL相关的引用库信息路径地址
```
-此时查看`build`目录下可以看到生成的本地动态库`libgmssljni`和GmSSLJNI的Jar包`GmSSLJNI.jar`、`GmSSLJNI-2.1.0-dev.jar`。
+执行Maven编译打包命令
+```shell
+mvn clean install
+```
+最终会执行单元测试并在target目录下生成相应版本jar包。
+## 使用
+在其他项目中使用GmSSL-java,只需在pom.xml中添加如下依赖:
+```xml
+
+ com.gmssl
+ GmSSLJNI
+ 3.1.1
+
+```
## 开发手册
diff --git a/gmssljni.c b/gmssljni.c
deleted file mode 100644
index fe1cc72..0000000
--- a/gmssljni.c
+++ /dev/null
@@ -1,3882 +0,0 @@
-/*
- * Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the License); you may
- * not use this file except in compliance with the License.
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include "gmssljni.h"
-
-
-static int check_buf(const jbyte *buf, jint bufsiz, jint offset, jint outlen)
-{
- if (offset < 0 || outlen < 0) {
- error_print();
- return -1;
- }
- if (!(buf + offset >= buf)
- || !(buf + offset + outlen >= buf + offset)
- || !(offset + outlen >= offset)) {
- error_print();
- return -1;
- }
- if (offset + outlen > bufsiz) {
- error_print();
- return -1;
- }
- return 1;
-}
-
-
-JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
-{
- return JNI_VERSION_1_2;
-}
-
-JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
-{
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: version_num
- * Signature: ()I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_version_1num(
- JNIEnv *env, jclass this)
-{
- return (jint)gmssl_version_num();
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: version_str
- * Signature: ()Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL Java_org_gmssl_GmSSLJNI_version_1str(
- JNIEnv *env, jclass this)
-{
- return (*env)->NewStringUTF(env, gmssl_version_str());
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: rand_bytes
- * Signature: ([BIJ)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_rand_1bytes(
- JNIEnv *env, jclass this,
- jbyteArray out, jint offset, jlong length)
-{
- jint ret = -1;
- jbyte *buf = NULL;
- jint mode = JNI_ABORT;
-
- if (!(buf = (*env)->GetByteArrayElements(env, out, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(buf, (*env)->GetArrayLength(env, out), offset, length) != 1) {
- error_print();
- goto end;
- }
- if (rand_bytes((uint8_t *)buf + offset, length) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, out, buf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm3_1ctx_1new(
- JNIEnv *env, jclass this)
-{
- jlong sm3_ctx;
-
- if (!(sm3_ctx = (jlong)malloc(sizeof(SM3_CTX)))) {
- error_print();
- return 0;
- }
- memset((SM3_CTX *)sm3_ctx, 0, sizeof(SM3_CTX));
- return sm3_ctx;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm3_1ctx_1free(
- JNIEnv *env, jclass this,
- jlong sm3_ctx)
-{
- if (sm3_ctx) {
- gmssl_secure_clear((SM3_CTX *)sm3_ctx, sizeof(SM3_CTX));
- free((SM3_CTX *)sm3_ctx);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_init
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1init(
- JNIEnv *env, jclass this,
- jlong sm3_ctx)
-{
- if (!sm3_ctx) {
- error_print();
- return -1;
- }
- sm3_init((SM3_CTX *)sm3_ctx);
- return 1;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_update
- * Signature: (J[BII)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1update(
- JNIEnv *env, jclass this,
- jlong sm3_ctx, jbyteArray data, jint offset, jint length)
-{
- jint ret = -1;
- jbyte *buf = NULL;
- jsize buflen;
-
- if (!sm3_ctx) {
- error_print();
- return -1;
- }
- if (!(buf = (*env)->GetByteArrayElements(env, data, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(buf, (*env)->GetArrayLength(env, data), offset, length) != 1) {
- error_print();
- goto end;
- }
- sm3_update((SM3_CTX *)sm3_ctx, (uint8_t *)buf + offset, (size_t)length);
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, data, buf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_finish
- * Signature: (J[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1finish(
- JNIEnv *env, jclass this,
- jlong sm3_ctx, jbyteArray dgst)
-{
- jint ret = -1;
- jbyte *buf = NULL;
- jint mode = JNI_ABORT;
-
- if (!sm3_ctx) {
- error_print();
- return -1;
- }
- if (!(buf = (*env)->GetByteArrayElements(env, dgst, NULL))) {
- error_print();
- return -1;
- }
- if ((*env)->GetArrayLength(env, dgst) < SM3_DIGEST_SIZE) {
- error_print();
- goto end;
- }
- sm3_finish((SM3_CTX *)sm3_ctx, (uint8_t *)buf);
- mode = 0;
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, dgst, buf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_hmac_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm3_1hmac_1ctx_1new(
- JNIEnv *env, jclass this)
-{
- jlong sm3_hmac_ctx;
- if (!(sm3_hmac_ctx = (jlong)malloc(sizeof(SM3_HMAC_CTX)))) {
- error_print();
- return 0;
- }
- return sm3_hmac_ctx;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_hmac_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm3_1hmac_1ctx_1free(
- JNIEnv *env, jclass this,
- jlong sm3_hmac_ctx)
-{
- if (sm3_hmac_ctx) {
- gmssl_secure_clear((SM3_HMAC_CTX *)sm3_hmac_ctx, sizeof(SM3_HMAC_CTX));
- free((SM3_HMAC_CTX *)sm3_hmac_ctx);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_hmac_init
- * Signature: (J[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1hmac_1init(
- JNIEnv *env, jclass this,
- jlong sm3_hmac_ctx, jbyteArray key)
-{
- jint ret = -1;
- jbyte *buf = NULL;
- jlong buflen;
-
- if (!sm3_hmac_ctx) {
- error_print();
- return -1;
- }
- if (!(buf = (*env)->GetByteArrayElements(env, key, NULL))) {
- error_print();
- return -1;
- }
- buflen = (*env)->GetArrayLength(env, key);
- if (buflen < 1 || buflen > 64) {
- error_print();
- goto end;
- }
- sm3_hmac_init((SM3_HMAC_CTX *)sm3_hmac_ctx, (uint8_t *)buf, (size_t)buflen);
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, key, buf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_hmac_update
- * Signature: (J[BII)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1hmac_1update(
- JNIEnv *env, jclass this,
- jlong sm3_hmac_ctx, jbyteArray data, jint offset, jint length)
-{
- jint ret = -1;
- jbyte *buf = NULL;
- jsize buflen;
-
- if (!sm3_hmac_ctx) {
- error_print();
- return -1;
- }
- if (!(buf = (*env)->GetByteArrayElements(env, data, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(buf, (*env)->GetArrayLength(env, data), offset, length) != 1) {
- error_print();
- goto end;
- }
- sm3_hmac_update((SM3_HMAC_CTX *)sm3_hmac_ctx, (uint8_t *)buf + offset, (size_t)length);
- ret = 1;
-end:
- if (buf) (*env)->ReleaseByteArrayElements(env, data, buf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_hmac_finish
- * Signature: (J[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1hmac_1finish(
- JNIEnv *env, jclass this,
- jlong sm3_hmac_ctx, jbyteArray hmac)
-{
- jint ret = -1;
- jbyte *buf = NULL;
- jint mode = JNI_ABORT;
-
- if (!sm3_hmac_ctx) {
- error_print();
- return -1;
- }
- if (!(buf = (*env)->GetByteArrayElements(env, hmac, NULL))) {
- error_print();
- return -1;
- }
- if ((*env)->GetArrayLength(env, hmac) < SM3_HMAC_SIZE) {
- error_print();
- goto end;
- }
- sm3_hmac_finish((SM3_HMAC_CTX *)sm3_hmac_ctx, (uint8_t *)buf);
- mode = 0;
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, hmac, buf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_pbkdf2
- * Signature: (Ljava/lang/String;[BII)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm3_1pbkdf2(
- JNIEnv *env, jclass this,
- jstring pass, jbyteArray salt, jint iter, jint keylen)
-{
- jbyteArray ret = NULL;
- uint8_t keybuf[256];
- const char *pass_str = NULL;
- jbyte *saltbuf = NULL;
- jlong saltlen;
-
- if (!(pass_str = (*env)->GetStringUTFChars(env, pass, 0))) {
- error_print();
- goto end;
- }
- if (iter < PBKDF2_MIN_ITER || iter > PBKDF2_MAX_ITER) {
- error_print();
- goto end;
- }
- if (!(saltbuf = (*env)->GetByteArrayElements(env, salt, NULL))) {
- error_print();
- goto end;
- }
- saltlen = (*env)->GetArrayLength(env, salt);
- if (saltlen < 1 || saltlen > PBKDF2_MAX_SALT_SIZE) {
- error_print();
- goto end;
- }
- if (keylen < 1 || keylen > sizeof(keybuf)) {
- error_print();
- goto end;
- }
-
- if (pbkdf2_hmac_sm3_genkey(pass_str, strlen(pass_str),
- (const uint8_t *)saltbuf, saltlen, iter, keylen, keybuf) != 1) {
- error_print();
- goto end;
- }
-
- if (!(ret = (*env)->NewByteArray(env, keylen))) {
- error_print();
- goto end;
- }
- (*env)->SetByteArrayRegion(env, ret, 0, keylen, (jbyte *)keybuf);
-
-end:
- if (pass_str) (*env)->ReleaseStringUTFChars(env, pass, pass_str);
- if (saltbuf) (*env)->ReleaseByteArrayElements(env, salt, saltbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_key_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm4_1key_1new(
- JNIEnv *env, jclass this)
-{
- jlong sm4_key;
-
- if (!(sm4_key = (jlong)malloc(sizeof(SM4_KEY)))) {
- error_print();
- return 0;
- }
- memset((SM4_KEY *)sm4_key, 0, sizeof(SM4_KEY));
- return sm4_key;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_key_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm4_1key_1free(
- JNIEnv *env, jclass this,
- jlong sm4_key)
-{
- if (sm4_key) {
- gmssl_secure_clear((SM4_KEY *)sm4_key, sizeof(SM4_KEY));
- free((SM4_KEY *)sm4_key);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_set_encrypt_key
- * Signature: (J[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1set_1encrypt_1key(
- JNIEnv *env, jclass this,
- jlong sm4_key, jbyteArray key)
-{
- jint ret = -1;
- jbyte *buf = NULL;
-
- if (!sm4_key) {
- error_print();
- return -1;
- }
- if (!(buf = (*env)->GetByteArrayElements(env, key, NULL))) {
- error_print();
- return -1;
- }
- if ((*env)->GetArrayLength(env, key) < SM4_KEY_SIZE) {
- error_print();
- goto end;
- }
- sm4_set_encrypt_key((SM4_KEY *)sm4_key, (uint8_t *)buf);
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, key, buf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_set_decrypt_key
- * Signature: (J[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1set_1decrypt_1key(
- JNIEnv *env, jclass this,
- jlong sm4_key, jbyteArray key)
-{
- jint ret = -1;
- jbyte *buf = NULL;
-
- if (!sm4_key) {
- error_print();
- return -1;
- }
- if (!(buf = (*env)->GetByteArrayElements(env, key, NULL))) {
- error_print();
- return -1;
- }
- if ((*env)->GetArrayLength(env, key) < SM4_KEY_SIZE) {
- error_print();
- goto end;
- }
- sm4_set_decrypt_key((SM4_KEY *)sm4_key, (uint8_t *)buf);
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, key, buf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_encrypt
- * Signature: (J[BI[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1encrypt(
- JNIEnv *env, jclass this,
- jlong sm4_key,
- jbyteArray in, jint in_offset,
- jbyteArray out, jint out_offset)
-{
- jint ret = -1;
- jbyte *inbuf = NULL;
- jbyte *outbuf = NULL;
- jsize inbuflen, outbuflen;
- jint mode = JNI_ABORT;
-
- if (!sm4_key) {
- error_print();
- return -1;
- }
- if (!(inbuf = (*env)->GetByteArrayElements(env, in, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(inbuf, (*env)->GetArrayLength(env, in), in_offset, SM4_BLOCK_SIZE) != 1) {
- error_print();
- goto end;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, NULL))) {
- error_print();
- goto end;
- }
- if (check_buf(outbuf, (*env)->GetArrayLength(env, out), out_offset, SM4_BLOCK_SIZE) != 1) {
- error_print();
- goto end;
- }
- sm4_encrypt((SM4_KEY *)sm4_key, (uint8_t *)inbuf + in_offset, (uint8_t *)outbuf + out_offset);
- mode = 0;
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, in, inbuf, JNI_ABORT);
- if (outbuf) (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1ctx_1new(
- JNIEnv *env, jclass this)
-{
- jlong sm4_cbc_ctx;
-
- if (!(sm4_cbc_ctx = (jlong)malloc(sizeof(SM4_CBC_CTX)))) {
- error_print();
- return 0;
- }
- memset((SM4_CBC_CTX *)sm4_cbc_ctx, 0, sizeof(SM4_CBC_CTX));
- return sm4_cbc_ctx;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1ctx_1free(
- JNIEnv *env, jclass this,
- jlong sm4_cbc_ctx)
-{
- if (sm4_cbc_ctx) {
- gmssl_secure_clear((SM4_CBC_CTX *)sm4_cbc_ctx, sizeof(SM4_CBC_CTX));
- free((SM4_CBC_CTX *)sm4_cbc_ctx);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_encrypt_init
- * Signature: (J[B[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1encrypt_1init(
- JNIEnv *env, jclass this,
- jlong sm4_cbc_ctx, jbyteArray key, jbyteArray iv)
-{
- jint ret = -1;
- jbyte *keybuf = NULL;
- jbyte *ivbuf = NULL;
-
- if (!sm4_cbc_ctx) {
- error_print();
- return -1;
- }
- if (!(keybuf = (*env)->GetByteArrayElements(env, key, NULL))) {
- error_print();
- return -1;
- }
- if ((*env)->GetArrayLength(env, key) < SM4_KEY_SIZE) {
- error_print();
- goto end;
- }
- if (!(ivbuf = (*env)->GetByteArrayElements(env, iv, 0))) {
- error_print();
- goto end;
- }
- if ((*env)->GetArrayLength(env, iv) < SM4_BLOCK_SIZE) {
- error_print();
- goto end;
- }
- if (sm4_cbc_encrypt_init((SM4_CBC_CTX *)sm4_cbc_ctx, (uint8_t *)keybuf, (uint8_t *)ivbuf) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, key, keybuf, JNI_ABORT);
- if (ivbuf) (*env)->ReleaseByteArrayElements(env, iv, ivbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_encrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1encrypt_1update(
- JNIEnv *env, jclass this,
- jlong sm4_cbc_ctx,
- jbyteArray in, jint in_offset, jint inlen,
- jbyteArray out, jint out_offset)
-{
- jint ret = -1;
- jbyte *inbuf = NULL;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!sm4_cbc_ctx) {
- error_print();
- return -1;
- }
- if (!(inbuf = (*env)->GetByteArrayElements(env, in, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(inbuf, (*env)->GetArrayLength(env, in), in_offset, inlen) != 1) {
- error_print();
- goto end;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, NULL))) {
- error_print();
- goto end;
- }
- outlen = inlen + SM4_BLOCK_SIZE;
- if (check_buf(outbuf, (*env)->GetArrayLength(env, out), out_offset, outlen) != 1
- || outlen < inlen) {
- error_print();
- goto end;
- }
- if (sm4_cbc_encrypt_update((SM4_CBC_CTX *)sm4_cbc_ctx, (uint8_t *)inbuf + in_offset, (size_t)inlen,
- (uint8_t *)outbuf + out_offset, &outlen) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = (jint)outlen;
-end:
- (*env)->ReleaseByteArrayElements(env, in, inbuf, JNI_ABORT);
- if (outbuf) (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_encrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1encrypt_1finish(
- JNIEnv *env, jclass this,
- jlong sm4_cbc_ctx,
- jbyteArray out, jint out_offset)
-{
- jint ret = -1;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!sm4_cbc_ctx) {
- error_print();
- return -1;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(outbuf, (*env)->GetArrayLength(env, out), out_offset, SM4_BLOCK_SIZE) != 1) {
- error_print();
- goto end;
- }
- if (sm4_cbc_encrypt_finish((SM4_CBC_CTX *)sm4_cbc_ctx,
- (uint8_t *)outbuf + out_offset, &outlen) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = (jint)outlen;
-end:
- (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_decrypt_init
- * Signature: (J[B[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1decrypt_1init(
- JNIEnv *env, jclass this,
- jlong sm4_cbc_ctx, jbyteArray key, jbyteArray iv)
-{
- jint ret = -1;
- jbyte *keybuf = NULL;
- jbyte *ivbuf = NULL;
-
- if (!sm4_cbc_ctx) {
- error_print();
- return -1;
- }
- if (!(keybuf = (*env)->GetByteArrayElements(env, key, NULL))) {
- error_print();
- return -1;
- }
- if ((*env)->GetArrayLength(env, key) < SM4_KEY_SIZE) {
- error_print();
- goto end;
- }
- if (!(ivbuf = (*env)->GetByteArrayElements(env, iv, NULL))) {
- error_print();
- goto end;
- }
- if ((*env)->GetArrayLength(env, iv) < SM4_BLOCK_SIZE) {
- error_print();
- goto end;
- }
- if (sm4_cbc_decrypt_init((SM4_CBC_CTX *)sm4_cbc_ctx, (uint8_t *)keybuf, (uint8_t *)ivbuf) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, key, keybuf, JNI_ABORT);
- if (ivbuf) (*env)->ReleaseByteArrayElements(env, iv, ivbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_decrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1decrypt_1update(
- JNIEnv *env, jclass this,
- jlong sm4_cbc_ctx,
- jbyteArray in, jint in_offset, jint inlen, jbyteArray out, jint out_offset)
-{
- jint ret = -1;
- jbyte *inbuf = NULL;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!sm4_cbc_ctx) {
- error_print();
- return -1;
- }
- if (!(inbuf = (*env)->GetByteArrayElements(env, in, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(inbuf, (*env)->GetArrayLength(env, in), in_offset, inlen) != 1) {
- error_print();
- goto end;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, 0))) {
- error_print();
- goto end;
- }
- outlen = inlen + SM4_BLOCK_SIZE;
- if (check_buf(outbuf, (*env)->GetArrayLength(env, out), out_offset, outlen) != 1
- || outlen < inlen) {
- error_print();
- goto end;
- }
- if (sm4_cbc_decrypt_update((SM4_CBC_CTX *)sm4_cbc_ctx, (uint8_t *)inbuf + in_offset, (size_t)inlen,
- (uint8_t *)outbuf + out_offset, &outlen) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = (jint)outlen;
-end:
- (*env)->ReleaseByteArrayElements(env, in, inbuf, JNI_ABORT);
- if (outbuf) (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_decrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1decrypt_1finish(
- JNIEnv *env, jclass this,
- jlong sm4_cbc_ctx, jbyteArray out, jint offset)
-{
- jint ret = -1;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!sm4_cbc_ctx) {
- error_print();
- return -1;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(outbuf, (*env)->GetArrayLength(env, out), offset, SM4_BLOCK_SIZE) != 1) {
- error_print();
- goto end;
- }
- if (sm4_cbc_decrypt_finish((SM4_CBC_CTX *)sm4_cbc_ctx, (uint8_t *)outbuf + offset, &outlen) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = (jint)outlen;
-end:
- (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1ctx_1new(
- JNIEnv *env, jclass this)
-{
- jlong sm4_ctr_ctx;
-
- if (!(sm4_ctr_ctx = (jlong)malloc(sizeof(SM4_CTR_CTX)))) {
- error_print();
- return 0;
- }
- memset((SM4_CTR_CTX *)sm4_ctr_ctx, 0, sizeof(SM4_CTR_CTX));
- return sm4_ctr_ctx;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1ctx_1free(
- JNIEnv *env, jclass this,
- jlong sm4_ctr_ctx)
-{
- if (sm4_ctr_ctx) {
- gmssl_secure_clear((SM4_CTR_CTX *)sm4_ctr_ctx, sizeof(SM4_CTR_CTX));
- free((SM4_CTR_CTX *)sm4_ctr_ctx);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_encrypt_init
- * Signature: (J[B[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1encrypt_1init(
- JNIEnv *env, jclass this,
- jlong sm4_ctr_ctx, jbyteArray key, jbyteArray iv)
-{
- jint ret = -1;
- jbyte *keybuf = NULL;
- jbyte *ivbuf = NULL;
-
- if (!sm4_ctr_ctx) {
- error_print();
- return -1;
- }
- if (!(keybuf = (*env)->GetByteArrayElements(env, key, NULL))) {
- error_print();
- return -1;
- }
- if ((*env)->GetArrayLength(env, key) < SM4_KEY_SIZE) {
- error_print();
- goto end;
- }
- if (!(ivbuf = (*env)->GetByteArrayElements(env, iv, NULL))) {
- error_print();
- goto end;
- }
- if ((*env)->GetArrayLength(env, iv) < SM4_BLOCK_SIZE) {
- error_print();
- goto end;
- }
- if (sm4_ctr_encrypt_init((SM4_CTR_CTX *)sm4_ctr_ctx, (uint8_t *)keybuf, (uint8_t *)ivbuf) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, key, keybuf, JNI_ABORT);
- if (ivbuf) (*env)->ReleaseByteArrayElements(env, iv, ivbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_encrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1encrypt_1update(
- JNIEnv *env, jclass this,
- jlong sm4_ctr_ctx,
- jbyteArray in, jint in_offset, jint inlen,
- jbyteArray out, jint out_offset)
-{
- jint ret = -1;
- jbyte *inbuf = NULL;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!sm4_ctr_ctx) {
- error_print();
- return -1;
- }
- if (!(inbuf = (*env)->GetByteArrayElements(env, in, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(inbuf, (*env)->GetArrayLength(env, in), in_offset, inlen) != 1) {
- error_print();
- goto end;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, NULL))) {
- error_print();
- goto end;
- }
- outlen = inlen + SM4_BLOCK_SIZE;
- if (check_buf(outbuf, (*env)->GetArrayLength(env, out), out_offset, outlen) != 1
- || outlen < inlen) {
- error_print();
- goto end;
- }
- if (sm4_ctr_encrypt_update((SM4_CTR_CTX *)sm4_ctr_ctx, (uint8_t *)inbuf + in_offset, (size_t)inlen,
- (uint8_t *)outbuf + out_offset, &outlen) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = (jint)outlen;
-end:
- (*env)->ReleaseByteArrayElements(env, in, inbuf, JNI_ABORT);
- if (outbuf) (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_encrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1encrypt_1finish(
- JNIEnv *env, jclass this,
- jlong sm4_ctr_ctx, jbyteArray out, jint offset)
-{
- jint ret = -1;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!sm4_ctr_ctx) {
- error_print();
- return -1;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, 0))) {
- error_print();
- goto end;
- }
- if ((*env)->GetArrayLength(env, out) < offset + SM4_BLOCK_SIZE) {
- error_print();
- goto end;
- }
- if (sm4_ctr_encrypt_finish((SM4_CTR_CTX *)sm4_ctr_ctx,
- (uint8_t *)outbuf + offset, &outlen) != 1) {
- error_print();
- goto end;
- }
-
- mode = 0;
- ret = (jint)outlen;
-end:
- if (outbuf) (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_decrypt_init
- * Signature: (J[B[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1decrypt_1init(
- JNIEnv *env, jclass this,
- jlong sm4_ctr_ctx, jbyteArray key, jbyteArray iv)
-{
- jint ret = -1;
- jbyte *keybuf = NULL;
- jbyte *ivbuf = NULL;
-
- if (!sm4_ctr_ctx) {
- error_print();
- return -1;
- }
- if (!(keybuf = (*env)->GetByteArrayElements(env, key, NULL))) {
- error_print();
- return -1;
- }
- if ((*env)->GetArrayLength(env, key) < SM4_KEY_SIZE) {
- error_print();
- goto end;
- }
- if (!(ivbuf = (*env)->GetByteArrayElements(env, iv, NULL))) {
- error_print();
- goto end;
- }
- if ((*env)->GetArrayLength(env, iv) < SM4_BLOCK_SIZE) {
- error_print();
- goto end;
- }
- if (sm4_ctr_decrypt_init((SM4_CTR_CTX *)sm4_ctr_ctx, (uint8_t *)keybuf, (uint8_t *)ivbuf) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, key, keybuf, JNI_ABORT);
- if (ivbuf) (*env)->ReleaseByteArrayElements(env, iv, ivbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_decrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1decrypt_1update(
- JNIEnv *env, jclass this,
- jlong sm4_ctr_ctx,
- jbyteArray in, jint in_offset, jint inlen,
- jbyteArray out, jint out_offset)
-{
- jint ret = -1;
- jbyte *inbuf = NULL;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!sm4_ctr_ctx) {
- error_print();
- return -1;
- }
- if (!(inbuf = (*env)->GetByteArrayElements(env, in, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(inbuf, (*env)->GetArrayLength(env, in), in_offset, inlen) != 1) {
- error_print();
- goto end;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, NULL))) {
- error_print();
- goto end;
- }
- outlen = inlen + SM4_BLOCK_SIZE;
- if (check_buf(outbuf, (*env)->GetArrayLength(env, out), out_offset, outlen) != 1
- || outlen < inlen) {
- error_print();
- goto end;
- }
- if (sm4_ctr_decrypt_update((SM4_CTR_CTX *)sm4_ctr_ctx, (uint8_t *)inbuf + in_offset, (size_t)inlen,
- (uint8_t *)outbuf + out_offset, &outlen) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = (jint)outlen;
-end:
- (*env)->ReleaseByteArrayElements(env, in, inbuf, JNI_ABORT);
- if (outbuf) (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_decrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1decrypt_1finish(
- JNIEnv *env, jclass this,
- jlong sm4_ctr_ctx, jbyteArray out, jint offset)
-{
- jint ret = -1;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!sm4_ctr_ctx) {
- error_print();
- return -1;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(outbuf, (*env)->GetArrayLength(env, out), offset, SM4_BLOCK_SIZE) != 1) {
- error_print();
- goto end;
- }
- if (sm4_ctr_decrypt_finish((SM4_CTR_CTX *)sm4_ctr_ctx,
- (uint8_t *)outbuf + offset, &outlen) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = (jint)outlen;
-end:
- (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1ctx_1new(
- JNIEnv *env, jclass this)
-{
- jlong sm4_gcm_ctx;
-
- if (!(sm4_gcm_ctx = (jlong)malloc(sizeof(SM4_GCM_CTX)))) {
- error_print();
- return 0;
- }
- memset((SM4_GCM_CTX *)sm4_gcm_ctx, 0, sizeof(SM4_GCM_CTX));
- return sm4_gcm_ctx;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1ctx_1free(
- JNIEnv *env, jclass this,
- jlong sm4_gcm_ctx)
-{
- if (sm4_gcm_ctx) {
- gmssl_secure_clear((SM4_GCM_CTX *)sm4_gcm_ctx, sizeof(SM4_GCM_CTX));
- free((SM4_GCM_CTX *)sm4_gcm_ctx);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_encrypt_init
- * Signature: (J[B[B[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1encrypt_1init(
- JNIEnv *env, jclass this,
- jlong sm4_gcm_ctx, jbyteArray key, jbyteArray iv, jbyteArray aad, jint taglen)
-{
- jint ret = -1;
- jbyte *keybuf = NULL;
- jbyte *ivbuf = NULL;
- jbyte *aadbuf = NULL;
- jsize ivlen, aadlen;
-
- if (!sm4_gcm_ctx) {
- error_print();
- return -1;
- }
- if (!(keybuf = (*env)->GetByteArrayElements(env, key, NULL))) {
- error_print();
- return -1;
- }
- if ((*env)->GetArrayLength(env, key) < SM4_KEY_SIZE) {
- error_print();
- goto end;
- }
- if (!(ivbuf = (*env)->GetByteArrayElements(env, iv, NULL))) {
- error_print();
- goto end;
- }
- ivlen = (*env)->GetArrayLength(env, iv);
- if (!(aadbuf = (*env)->GetByteArrayElements(env, aad, NULL))) {
- error_print();
- goto end;
- }
- aadlen = (*env)->GetArrayLength(env, aad);
- if (sm4_gcm_encrypt_init((SM4_GCM_CTX *)sm4_gcm_ctx, (uint8_t *)keybuf, SM4_KEY_SIZE,
- (uint8_t *)ivbuf, (size_t)ivlen, (uint8_t *)aadbuf, (size_t)aadlen, (size_t)taglen) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, key, keybuf, JNI_ABORT);
- if (ivbuf) (*env)->ReleaseByteArrayElements(env, iv, ivbuf, JNI_ABORT);
- if (aadbuf) (*env)->ReleaseByteArrayElements(env, aad, aadbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_encrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1encrypt_1update(
- JNIEnv *env, jclass this,
- jlong sm4_gcm_ctx,
- jbyteArray in, jint in_offset, jint inlen,
- jbyteArray out, jint out_offset)
-{
- jint ret = -1;
- jbyte *inbuf = NULL;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!sm4_gcm_ctx) {
- error_print();
- return -1;
- }
- if (!(inbuf = (*env)->GetByteArrayElements(env, in, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(inbuf, (*env)->GetArrayLength(env, in), in_offset, inlen) != 1) {
- error_print();
- goto end;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, NULL))) {
- error_print();
- goto end;
- }
- outlen = inlen + SM4_BLOCK_SIZE;
- if (check_buf(outbuf, (*env)->GetArrayLength(env, out), out_offset, outlen) != 1
- || outlen < inlen) {
- error_print();
- goto end;
- }
- if (sm4_gcm_encrypt_update((SM4_GCM_CTX *)sm4_gcm_ctx, (uint8_t *)inbuf + in_offset, (size_t)inlen,
- (uint8_t *)outbuf + out_offset, &outlen) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = (jint)outlen;
-end:
- (*env)->ReleaseByteArrayElements(env, in, inbuf, JNI_ABORT);
- if (outbuf) (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_encrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1encrypt_1finish(
- JNIEnv *env, jclass this,
- jlong sm4_gcm_ctx, jbyteArray out, jint offset)
-{
- jint ret = -1;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!sm4_gcm_ctx) {
- error_print();
- return -1;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(outbuf, (*env)->GetArrayLength(env, out),
- offset, SM4_BLOCK_SIZE + SM4_GCM_MAX_TAG_SIZE) != 1) {
- error_print();
- goto end;
- }
- if (sm4_gcm_encrypt_finish((SM4_GCM_CTX *)sm4_gcm_ctx,
- (uint8_t *)outbuf + offset, &outlen) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = (jint)outlen;
-end:
- (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_decrypt_init
- * Signature: (J[B[B[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1decrypt_1init(
- JNIEnv *env, jclass this,
- jlong sm4_gcm_ctx, jbyteArray key, jbyteArray iv, jbyteArray aad, jint taglen)
-{
- jint ret = -1;
- jbyte *keybuf = NULL;
- jbyte *ivbuf = NULL;
- jbyte *aadbuf = NULL;
- jsize ivlen, aadlen;
-
- if (!sm4_gcm_ctx) {
- error_print();
- return -1;
- }
- if (!(keybuf = (*env)->GetByteArrayElements(env, key, NULL))) {
- error_print();
- return -1;
- }
- if ((*env)->GetArrayLength(env, key) < SM4_KEY_SIZE) {
- error_print();
- goto end;
- }
- if (!(ivbuf = (*env)->GetByteArrayElements(env, iv, NULL))) {
- error_print();
- goto end;
- }
- ivlen = (*env)->GetArrayLength(env, iv);
- if (!(aadbuf = (*env)->GetByteArrayElements(env, aad, NULL))) {
- error_print();
- goto end;
- }
- aadlen = (*env)->GetArrayLength(env, aad);
- if (sm4_gcm_decrypt_init((SM4_GCM_CTX *)sm4_gcm_ctx,
- (uint8_t *)keybuf, SM4_KEY_SIZE, (uint8_t *)ivbuf, (size_t)ivlen,
- (uint8_t *)aadbuf, (size_t)aadlen, (size_t)taglen) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, key, keybuf, JNI_ABORT);
- if (ivbuf) (*env)->ReleaseByteArrayElements(env, iv, ivbuf, JNI_ABORT);
- if (aadbuf) (*env)->ReleaseByteArrayElements(env, aad, aadbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_decrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1decrypt_1update(
- JNIEnv *env, jclass this,
- jlong sm4_gcm_ctx, jbyteArray in, jint in_offset, jint inlen,
- jbyteArray out, jint out_offset)
-{
- jint ret = -1;
- jbyte *inbuf = NULL;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!sm4_gcm_ctx) {
- error_print();
- return -1;
- }
- if (!(inbuf = (*env)->GetByteArrayElements(env, in, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(inbuf, (*env)->GetArrayLength(env, in), in_offset, inlen) != 1) {
- error_print();
- goto end;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, 0))) {
- error_print();
- goto end;
- }
- outlen = inlen + SM4_BLOCK_SIZE;
- if (check_buf(outbuf, (*env)->GetArrayLength(env, out), out_offset, outlen) != 1) {
- error_print();
- goto end;
- }
- if (sm4_gcm_decrypt_update((SM4_GCM_CTX *)sm4_gcm_ctx, (uint8_t *)inbuf + in_offset, (size_t)inlen,
- (uint8_t *)outbuf + out_offset, &outlen) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = (jint)outlen;
-end:
- (*env)->ReleaseByteArrayElements(env, in, inbuf, JNI_ABORT);
- if (outbuf) (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_decrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1decrypt_1finish(
- JNIEnv *env, jclass this,
- jlong sm4_gcm_ctx, jbyteArray out, jint offset)
-{
- jint ret = -1;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!sm4_gcm_ctx) {
- error_print();
- return -1;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(outbuf, (*env)->GetArrayLength(env, out),
- offset, SM4_BLOCK_SIZE + SM4_GCM_MAX_TAG_SIZE) != 1) {
- error_print();
- goto end;
- }
- if (sm4_gcm_decrypt_finish((SM4_GCM_CTX *)sm4_gcm_ctx,
- (uint8_t *)outbuf + offset, &outlen) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = (jint)outlen;
-end:
- (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_key_generate
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm2_1key_1generate(
- JNIEnv *env, jclass this)
-{
- jlong sm2_key;
-
- if (!(sm2_key = (jlong)malloc(sizeof(SM2_KEY)))) {
- error_print();
- return 0;
- }
- if (sm2_key_generate((SM2_KEY *)sm2_key) != 1) {
- gmssl_secure_clear((SM2_KEY *)sm2_key, sizeof(SM2_KEY));
- error_print();
- return 0;
- }
- return sm2_key;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: zuc_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_zuc_1ctx_1new(
- JNIEnv *env, jclass this)
-{
- jlong zuc_ctx;
-
- if (!(zuc_ctx = (jlong)malloc(sizeof(ZUC_CTX)))) {
- error_print();
- return 0;
- }
- memset((ZUC_CTX *)zuc_ctx, 0, sizeof(ZUC_CTX));
- return zuc_ctx;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: zuc_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_zuc_1ctx_1free(
- JNIEnv *env, jclass this,
- jlong zuc_ctx)
-{
- if (zuc_ctx) {
- gmssl_secure_clear((ZUC_CTX *)zuc_ctx, sizeof(ZUC_CTX));
- free((ZUC_CTX *)zuc_ctx);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: zuc_encrypt_init
- * Signature: (J[B[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_zuc_1encrypt_1init(
- JNIEnv *env, jclass this,
- jlong zuc_ctx, jbyteArray key, jbyteArray iv)
-{
- jint ret = -1;
- jbyte *keybuf = NULL;
- jbyte *ivbuf = NULL;
-
- if (!zuc_ctx) {
- error_print();
- return -1;
- }
- if (!(keybuf = (*env)->GetByteArrayElements(env, key, NULL))) {
- error_print();
- return -1;
- }
- if ((*env)->GetArrayLength(env, key) < ZUC_KEY_SIZE) {
- error_print();
- goto end;
- }
- if (!(ivbuf = (*env)->GetByteArrayElements(env, iv, NULL))) {
- error_print();
- goto end;
- }
- if ((*env)->GetArrayLength(env, iv) < ZUC_IV_SIZE) {
- error_print();
- goto end;
- }
- if (zuc_encrypt_init((ZUC_CTX *)zuc_ctx, (uint8_t *)keybuf, (uint8_t *)ivbuf) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, key, keybuf, JNI_ABORT);
- if (ivbuf) (*env)->ReleaseByteArrayElements(env, iv, ivbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: zuc_encrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_zuc_1encrypt_1update(
- JNIEnv *env, jclass this,
- jlong zuc_ctx,
- jbyteArray in, jint in_offset, jint inlen,
- jbyteArray out, jint out_offset)
-{
- jint ret = -1;
- jbyte *inbuf = NULL;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!zuc_ctx) {
- error_print();
- return -1;
- }
- if (!(inbuf = (*env)->GetByteArrayElements(env, in, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(inbuf, (*env)->GetArrayLength(env, in), in_offset, inlen) != 1) {
- error_print();
- goto end;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, NULL))) {
- error_print();
- goto end;
- }
- outlen = inlen + 4; // ZUC block size is sizeof(uint32_t)
- if (check_buf(outbuf, (*env)->GetArrayLength(env, out), out_offset, outlen) != 1
- || outlen < inlen) {
- error_print();
- goto end;
- }
- if (zuc_encrypt_update((ZUC_CTX *)zuc_ctx, (uint8_t *)inbuf + in_offset, (size_t)inlen,
- (uint8_t *)outbuf + out_offset, &outlen) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = (jint)outlen;
-end:
- (*env)->ReleaseByteArrayElements(env, in, inbuf, JNI_ABORT);
- if (outbuf) (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: zuc_encrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_zuc_1encrypt_1finish(
- JNIEnv *env, jclass this,
- jlong zuc_ctx, jbyteArray out, jint offset)
-{
- jint ret = -1;
- jbyte *outbuf = NULL;
- size_t outlen;
- jint mode = JNI_ABORT;
-
- if (!zuc_ctx) {
- error_print();
- return -1;
- }
- if (!(outbuf = (*env)->GetByteArrayElements(env, out, 0))) {
- error_print();
- goto end;
- }
- if ((*env)->GetArrayLength(env, out) < offset + 4) { // ZUC block size is sizeof(uint32) == 4
- error_print();
- goto end;
- }
- if (zuc_encrypt_finish((ZUC_CTX *)zuc_ctx,
- (uint8_t *)outbuf + offset, &outlen) != 1) {
- error_print();
- goto end;
- }
- mode = 0;
- ret = (jint)outlen;
-end:
- if (outbuf) (*env)->ReleaseByteArrayElements(env, out, outbuf, mode);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_key_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm2_1key_1free(
- JNIEnv *env, jclass this,
- jlong sm2_key)
-{
- if (sm2_key) {
- gmssl_secure_clear((SM2_KEY *)sm2_key, sizeof(SM2_KEY));
- free((SM2_KEY *)sm2_key);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_private_key_info_to_der
- * Signature: (J)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm2_1private_1key_1info_1to_1der(
- JNIEnv *env, jclass this,
- jlong sm2_key)
-{
- jbyteArray ret = NULL;
- uint8_t outbuf[1024];
- uint8_t *p = outbuf;
- size_t outlen = 0;
-
- if (sm2_private_key_info_to_der((SM2_KEY *)sm2_key, &p, &outlen) != 1) {
- error_print();
- return NULL;
- }
- if (!(ret = (*env)->NewByteArray(env, outlen))) {
- error_print();
- gmssl_secure_clear(outbuf, sizeof(outbuf));
- return NULL;
- }
- (*env)->SetByteArrayRegion(env, ret, 0, outlen, (jbyte *)outbuf);
- gmssl_secure_clear(outbuf, sizeof(outbuf));
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_private_key_info_from_der
- * Signature: ([B)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm2_1private_1key_1info_1from_1der(
- JNIEnv *env, jclass this,
- jbyteArray der)
-{
- jlong ret = 0;
- SM2_KEY *sm2_key = NULL;
- jbyte *derbuf = NULL;
- size_t derlen;
- const uint8_t *attrs;
- size_t attrslen;
- const uint8_t *cp;
-
- if (!(derbuf = (*env)->GetByteArrayElements(env, der, NULL))) {
- error_print();
- return 0;
- }
- derlen = (*env)->GetArrayLength(env, der);
-
- if (!(sm2_key = (SM2_KEY *)malloc(sizeof(SM2_KEY)))) {
- error_print();
- goto end;
- }
- cp = (const uint8_t *)derbuf;
- if (sm2_private_key_info_from_der(sm2_key, &attrs, &attrslen, &cp, &derlen) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)sm2_key;
- sm2_key = NULL;
-end:
- (*env)->ReleaseByteArrayElements(env, der, derbuf, JNI_ABORT);
- if (sm2_key) {
- gmssl_secure_clear(sm2_key, sizeof(SM2_KEY));
- free(sm2_key);
- }
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_public_key_info_to_der
- * Signature: (J)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm2_1public_1key_1info_1to_1der(
- JNIEnv *env, jclass this,
- jlong sm2_key)
-{
- jbyteArray ret = NULL;
- uint8_t outbuf[1024];
- uint8_t *p = outbuf;
- size_t outlen = 0;
-
- if (sm2_public_key_info_to_der((SM2_KEY *)sm2_key, &p, &outlen) != 1) {
- error_print();
- return NULL;
- }
- if (!(ret = (*env)->NewByteArray(env, outlen))) {
- error_print();
- gmssl_secure_clear(outbuf, sizeof(outbuf));
- return NULL;
- }
- (*env)->SetByteArrayRegion(env, ret, 0, outlen, (jbyte *)outbuf);
- gmssl_secure_clear(outbuf, sizeof(outbuf));
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_public_key_info_from_der
- * Signature: ([B)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm2_1public_1key_1info_1from_1der(
- JNIEnv *env, jclass this,
- jbyteArray der)
-{
- jlong ret = 0;
- SM2_KEY *sm2_key = NULL;
- jbyte *derbuf = NULL;
- size_t derlen;
- const uint8_t *cp;
-
- if (!(derbuf = (*env)->GetByteArrayElements(env, der, NULL))) {
- error_print();
- return 0;
- }
- derlen = (*env)->GetArrayLength(env, der); // return jsize which is int!
-
- if (!(sm2_key = (SM2_KEY *)malloc(sizeof(SM2_KEY)))) {
- error_print();
- goto end;
- }
- cp = (const uint8_t *)derbuf;
- if (sm2_public_key_info_from_der(sm2_key, &cp, &derlen) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)sm2_key;
- sm2_key = NULL;
-end:
- (*env)->ReleaseByteArrayElements(env, der, derbuf, JNI_ABORT);
- if (sm2_key) {
- gmssl_secure_clear(sm2_key, sizeof(SM2_KEY));
- free(sm2_key);
- }
- return ret;
-}
-
-// FIXME: ReleaseStringUTFChars ?? no mode?
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_private_key_info_encrypt_to_pem
- * Signature: (JLjava/lang/String;Ljava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1private_1key_1info_1encrypt_1to_1pem(
- JNIEnv *env, jclass this,
- jlong sm2_key, jstring pass, jstring file)
-{
- jint ret = -1;
- FILE *fp = NULL;
- const char *pass_str = NULL;
- const char *file_str = NULL;
-
- if (!sm2_key) {
- error_print();
- return -1;
- }
- if (!(pass_str = (*env)->GetStringUTFChars(env, pass, NULL))) {
- error_print();
- goto end;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, NULL))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "wb"))) {
- error_print();
- goto end;
- }
- if (sm2_private_key_info_encrypt_to_pem((SM2_KEY *)sm2_key, pass_str, fp) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- if (fp) fclose(fp);
- if (pass_str) (*env)->ReleaseStringUTFChars(env, pass, pass_str);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_private_key_info_decrypt_from_pem
- * Signature: (Ljava/lang/String;Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm2_1private_1key_1info_1decrypt_1from_1pem(
- JNIEnv *env, jclass this,
- jstring pass, jstring file)
-{
- jlong ret = 0;
- SM2_KEY *sm2_key = NULL;
- FILE *fp = NULL;
- const char *pass_str = NULL;
- const char *file_str = NULL;
-
- if (!(sm2_key = (SM2_KEY *)malloc(sizeof(SM2_KEY)))) {
- error_print();
- return 0;
- }
- if (!(pass_str = (*env)->GetStringUTFChars(env, pass, NULL))) {
- error_print();
- goto end;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, NULL))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "rb"))) {
- error_print();
- goto end;
- }
- if (sm2_private_key_info_decrypt_from_pem(sm2_key, pass_str, fp) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)sm2_key;
- sm2_key = NULL;
-end:
- if (fp) fclose(fp);
- if (sm2_key) {
- gmssl_secure_clear(sm2_key, sizeof(SM2_KEY));
- free(sm2_key);
- }
- if (pass_str) (*env)->ReleaseStringUTFChars(env, pass, pass_str);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_public_key_info_to_pem
- * Signature: (JLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1public_1key_1info_1to_1pem(
- JNIEnv *env, jclass this,
- jlong sm2_pub, jstring file)
-{
- jint ret = -1;
- FILE *fp = NULL;
- const char *file_str = NULL;
-
- if (!sm2_pub) {
- error_print();
- return -1;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, NULL))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "wb"))) {
- error_print();
- goto end;
- }
- if (sm2_public_key_info_to_pem((SM2_KEY *)sm2_pub, fp) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- if (fp) fclose(fp);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_public_key_info_from_pem
- * Signature: (Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm2_1public_1key_1info_1from_1pem(
- JNIEnv *env, jclass this,
- jstring file)
-{
- jlong ret = 0;
- SM2_KEY *sm2_pub = NULL;
- FILE *fp = NULL;
- const char *file_str = NULL;
-
- if (!(sm2_pub = (SM2_KEY *)malloc(sizeof(SM2_KEY)))) {
- error_print();
- goto end;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, NULL))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "rb"))) {
- error_print();
- goto end;
- }
- if (sm2_public_key_info_from_pem(sm2_pub, fp) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)sm2_pub;
- sm2_pub = NULL;
-end:
- if (fp) fclose(fp);
- if (sm2_pub) {
- gmssl_secure_clear(sm2_pub, sizeof(SM2_KEY));
- free(sm2_pub);
- }
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_compute_z
- * Signature: (JLjava/lang/String;[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1compute_1z(
- JNIEnv *env, jclass this,
- jlong sm2_pub, jstring id, jbyteArray z)
-{
- jint ret = -1;
- const char *id_str = NULL;
- jbyte *zbuf = NULL;
- jint mode = JNI_ABORT;
-
- if (!sm2_pub) {
- error_print();
- return -1;
- }
- if (!(id_str = (*env)->GetStringUTFChars(env, id, NULL))) {
- error_print();
- goto end;
- }
- if (!(zbuf = (*env)->GetByteArrayElements(env, z, NULL))) {
- error_print();
- goto end;
- }
- if ((*env)->GetArrayLength(env, z) < SM3_DIGEST_SIZE) {
- error_print();
- goto end;
- }
- sm2_compute_z((uint8_t *)zbuf, &((SM2_KEY *)sm2_pub)->public_key, id_str, strlen(id_str));
- mode = 0;
- ret = 1;
-end:
- if (id_str) (*env)->ReleaseStringUTFChars(env, id, id_str);
- if (zbuf) (*env)->ReleaseByteArrayElements(env, z, zbuf, mode);
- return ret;
-}
-
-// FIXME: change the function name to sign_digest
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_sign
- * Signature: (J[B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm2_1sign(
- JNIEnv *env, jclass this,
- jlong sm2_key, jbyteArray dgst)
-{
- jbyteArray ret = NULL;
- jbyte *buf = NULL;
- uint8_t sig[SM2_MAX_SIGNATURE_SIZE];
- size_t siglen;
-
- if (!sm2_key) {
- error_print();
- return NULL;
- }
- if (!(buf = (*env)->GetByteArrayElements(env, dgst, NULL))) {
- error_print();
- return NULL;
- }
- if ((*env)->GetArrayLength(env, dgst) != SM3_DIGEST_SIZE) {
- error_print();
- goto end;
- }
- if (sm2_sign((SM2_KEY *)sm2_key, (uint8_t *)buf, sig, &siglen) != 1) {
- error_print();
- goto end;
- }
- if (!(ret = (*env)->NewByteArray(env, siglen))) {
- error_print();
- goto end;
- }
- (*env)->SetByteArrayRegion(env, ret, 0, siglen, (jbyte *)sig);
-end:
- (*env)->ReleaseByteArrayElements(env, dgst, buf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_verify
- * Signature: (J[B[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1verify(
- JNIEnv *env, jclass this,
- jlong sm2_pub, jbyteArray dgst, jbyteArray sig)
-{
- jint ret = -1;
- jbyte *dgstbuf = NULL;
- jbyte *sigbuf = NULL;
- jsize siglen;
-
- if (!sm2_pub) {
- error_print();
- return -1;
- }
- if (!(dgstbuf = (*env)->GetByteArrayElements(env, dgst, NULL))) {
- error_print();
- return -1;
- }
- if ((*env)->GetArrayLength(env, dgst) != SM3_DIGEST_SIZE) {
- error_print();
- goto end;
- }
- if (!(sigbuf = (*env)->GetByteArrayElements(env, sig, NULL))) {
- error_print();
- goto end;
- }
- siglen = (*env)->GetArrayLength(env, sig);
- if ((ret = sm2_verify((SM2_KEY *)sm2_pub, (uint8_t *)dgstbuf, (uint8_t *)sigbuf, (size_t)siglen)) < 0) {
- error_print();
- goto end;
- }
-end:
- (*env)->ReleaseByteArrayElements(env, dgst, dgstbuf, JNI_ABORT);
- if (sigbuf) (*env)->ReleaseByteArrayElements(env, sig, sigbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_encrypt
- * Signature: (J[B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm2_1encrypt(
- JNIEnv *env, jclass this,
- jlong sm2_pub, jbyteArray in)
-{
- jbyteArray ret = NULL;
- jbyte *inbuf = NULL;
- jsize inlen;
- uint8_t outbuf[SM2_MAX_CIPHERTEXT_SIZE];
- size_t outlen;
-
- if (!sm2_pub) {
- error_print();
- return NULL;
- }
- if (!(inbuf = (*env)->GetByteArrayElements(env, in, NULL))) {
- error_print();
- return NULL;
- }
- inlen = (*env)->GetArrayLength(env, in);
- if (sm2_encrypt((SM2_KEY *)sm2_pub, (uint8_t *)inbuf, (size_t)inlen, outbuf, &outlen) != 1) {
- error_print();
- goto end;
- }
- if (!(ret = (*env)->NewByteArray(env, outlen))) {
- error_print();
- goto end;
- }
- (*env)->SetByteArrayRegion(env, ret, 0, outlen, (jbyte *)outbuf);
-end:
- (*env)->ReleaseByteArrayElements(env, in, inbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_decrypt
- * Signature: (J[B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm2_1decrypt(
- JNIEnv *env, jclass this,
- jlong sm2_key, jbyteArray in)
-{
- jbyteArray ret = NULL;
- jbyte *inbuf = NULL;
- jsize inlen;
- uint8_t outbuf[SM2_MAX_PLAINTEXT_SIZE];
- size_t outlen;
-
- if (!sm2_key) {
- error_print();
- return NULL;
- }
- if (!(inbuf = (*env)->GetByteArrayElements(env, in, NULL))) {
- error_print();
- return NULL;
- }
- inlen = (*env)->GetArrayLength(env, in);
- if (sm2_decrypt((SM2_KEY *)sm2_key, (uint8_t *)inbuf, (size_t)inlen, outbuf, &outlen) != 1) {
- error_print();
- goto end;
- }
- if (!(ret = (*env)->NewByteArray(env, outlen))) {
- error_print();
- goto end;
- }
- (*env)->SetByteArrayRegion(env, ret, 0, outlen, (jbyte *)outbuf);
-end:
- (*env)->ReleaseByteArrayElements(env, in, inbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_sign_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm2_1sign_1ctx_1new(
- JNIEnv *env, jclass this)
-{
- jlong sm2_sign_ctx;
-
- if (!(sm2_sign_ctx = (jlong)malloc(sizeof(SM2_SIGN_CTX)))) {
- error_print();
- return 0;
- }
- memset((SM2_SIGN_CTX *)sm2_sign_ctx, 0, sizeof(SM2_SIGN_CTX));
- return sm2_sign_ctx;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_sign_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm2_1sign_1ctx_1free(
- JNIEnv *env, jclass this,
- jlong sm2_sign_ctx)
-{
- if (sm2_sign_ctx) {
- gmssl_secure_clear((SM2_SIGN_CTX *)sm2_sign_ctx, sizeof(SM2_SIGN_CTX));
- free((SM2_SIGN_CTX *)sm2_sign_ctx);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_sign_init
- * Signature: (JJLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1sign_1init(
- JNIEnv *env, jclass this,
- jlong sm2_sign_ctx, jlong sm2_key, jstring id)
-{
- int ret = -1;
- const char *id_str = NULL;
-
- if (!sm2_sign_ctx) {
- error_print();
- return -1;
- }
- if (!sm2_key) {
- error_print();
- return -1;
- }
- if (!(id_str = (*env)->GetStringUTFChars(env, id, NULL))) {
- error_print();
- return -1;
- }
- if (sm2_sign_init((SM2_SIGN_CTX *)sm2_sign_ctx, (SM2_KEY *)sm2_key, id_str, strlen(id_str)) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseStringUTFChars(env, id, id_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_sign_update
- * Signature: (J[BII)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1sign_1update(
- JNIEnv *env, jclass this,
- jlong sm2_sign_ctx, jbyteArray data, jint offset, jint length)
-{
- jint ret = -1;
- jbyte *buf = NULL;
- jsize buflen;
-
- if (!sm2_sign_ctx) {
- error_print();
- return -1;
- }
- if (!(buf = (*env)->GetByteArrayElements(env, data, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(buf, (*env)->GetArrayLength(env, data), offset, length) != 1) {
- error_print();
- goto end;
- }
- if (sm2_sign_update((SM2_SIGN_CTX *)sm2_sign_ctx, (uint8_t *)buf + offset, (size_t)length) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, data, buf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_sign_finish
- * Signature: (J)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm2_1sign_1finish(
- JNIEnv *env, jclass this,
- jlong sm2_sign_ctx)
-{
- jbyteArray ret = NULL;
- uint8_t sig[SM2_MAX_SIGNATURE_SIZE];
- size_t siglen;
-
- if (!sm2_sign_ctx) {
- error_print();
- return NULL;
- }
- if (sm2_sign_finish((SM2_SIGN_CTX *)sm2_sign_ctx, sig, &siglen) != 1) {
- error_print();
- return NULL;
- }
- if (!(ret = (*env)->NewByteArray(env, siglen))) {
- error_print();
- return NULL;
- }
- (*env)->SetByteArrayRegion(env, ret, 0, siglen, (jbyte *)sig);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_verify_init
- * Signature: (JJLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1verify_1init(
- JNIEnv *env, jclass this,
- jlong sm2_sign_ctx, jlong sm2_pub, jstring id)
-{
- int ret = -1;
- const char *id_str = NULL;
-
- if (!sm2_sign_ctx) {
- error_print();
- return -1;
- }
- if (!sm2_pub) {
- error_print();
- return -1;
- }
- if (!(id_str = (*env)->GetStringUTFChars(env, id, NULL))) {
- error_print();
- return -1;
- }
- if (sm2_verify_init((SM2_SIGN_CTX *)sm2_sign_ctx, (SM2_KEY *)sm2_pub, id_str, strlen(id_str)) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseStringUTFChars(env, id, id_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_verify_update
- * Signature: (J[BII)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1verify_1update(
- JNIEnv *env, jclass this,
- jlong sm2_sign_ctx, jbyteArray data, jint offset, jint length)
-{
- jint ret = -1;
- jbyte *buf = NULL;
- jsize buflen;
-
- if (!sm2_sign_ctx) {
- error_print();
- return -1;
- }
- if (!(buf = (*env)->GetByteArrayElements(env, data, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(buf, (*env)->GetArrayLength(env, data), offset, length) != 1) {
- error_print();
- goto end;
- }
- if (sm2_verify_update((SM2_SIGN_CTX *)sm2_sign_ctx, (uint8_t *)buf + offset, (size_t)length) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, data, buf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_verify_finish
- * Signature: (J[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1verify_1finish(
- JNIEnv *env, jclass this,
- jlong sm2_sign_ctx, jbyteArray sig)
-{
- jint ret = -1;
- jbyte *sigbuf = NULL;
- jsize siglen;
-
- if (!sm2_sign_ctx) {
- error_print();
- return -1;
- }
- if (!(sigbuf = (*env)->GetByteArrayElements(env, sig, NULL))) {
- error_print();
- return -1;
- }
- siglen = (*env)->GetArrayLength(env, sig);
- if ((ret = sm2_verify_finish((SM2_SIGN_CTX *)sm2_sign_ctx, (uint8_t *)sigbuf, (size_t)siglen)) < 0) {
- error_print();
- goto end;
- }
-end:
- (*env)->ReleaseByteArrayElements(env, sig, sigbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_key_generate
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1key_1generate(
- JNIEnv *env, jclass this)
-{
- jlong sm9_sign_master_key;
-
- if (!(sm9_sign_master_key = (jlong)malloc(sizeof(SM9_SIGN_MASTER_KEY)))) {
- error_print();
- return 0;
- }
- if (sm9_sign_master_key_generate((SM9_SIGN_MASTER_KEY *)sm9_sign_master_key) != 1) {
- gmssl_secure_clear((SM9_SIGN_MASTER_KEY *)sm9_sign_master_key, sizeof(SM9_SIGN_MASTER_KEY));
- error_print();
- return 0;
- }
- return sm9_sign_master_key;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_key_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1key_1free(
- JNIEnv *env, jclass this,
- jlong sm9_sign_master_key)
-{
- if (sm9_sign_master_key) {
- gmssl_secure_clear((SM9_SIGN_MASTER_KEY *)sm9_sign_master_key, sizeof(SM9_SIGN_MASTER_KEY));
- free((SM9_SIGN_MASTER_KEY *)sm9_sign_master_key);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_key_info_encrypt_to_pem
- * Signature: (JLjava/lang/String;Ljava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1key_1info_1encrypt_1to_1pem(
- JNIEnv *env, jclass this,
- jlong sm9_sign_master_key, jstring pass, jstring file)
-{
- jint ret = -1;
- FILE *fp = NULL;
- const char *pass_str = NULL;
- const char *file_str = NULL;
-
- if (!sm9_sign_master_key) {
- error_print();
- return -1;
- }
- if (!(pass_str = (*env)->GetStringUTFChars(env, pass, 0))) {
- error_print();
- goto end;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, 0))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "wb"))) {
- error_print();
- goto end;
- }
- if (sm9_sign_master_key_info_encrypt_to_pem((SM9_SIGN_MASTER_KEY *)sm9_sign_master_key, pass_str, fp) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- if (fp) fclose(fp);
- if (pass_str) (*env)->ReleaseStringUTFChars(env, pass, pass_str);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_key_info_decrypt_from_pem
- * Signature: (Ljava/lang/String;Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1key_1info_1decrypt_1from_1pem(
- JNIEnv *env, jclass this,
- jstring pass, jstring file)
-{
- jlong ret = 0;
- SM9_SIGN_MASTER_KEY *sm9_sign_master_key = NULL;
- FILE *fp = NULL;
- const char *pass_str = NULL;
- const char *file_str = NULL;
-
- if (!(sm9_sign_master_key = (SM9_SIGN_MASTER_KEY *)malloc(sizeof(SM9_SIGN_MASTER_KEY)))) {
- error_print();
- return 0;
- }
- if (!(pass_str = (*env)->GetStringUTFChars(env, pass, 0))) {
- error_print();
- goto end;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, 0))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "rb"))) {
- error_print();
- goto end;
- }
- if (sm9_sign_master_key_info_decrypt_from_pem(sm9_sign_master_key, pass_str, fp) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)sm9_sign_master_key;
- sm9_sign_master_key = NULL;
-end:
- if (fp) fclose(fp);
- if (sm9_sign_master_key) {
- gmssl_secure_clear(sm9_sign_master_key, sizeof(SM9_SIGN_MASTER_KEY));
- free(sm9_sign_master_key);
- }
- if (pass_str) (*env)->ReleaseStringUTFChars(env, pass, pass_str);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_public_key_to_pem
- * Signature: (JLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1public_1key_1to_1pem(
- JNIEnv *env, jclass this,
- jlong sm9_sign_master_pub, jstring file)
-{
- jint ret = -1;
- FILE *fp = NULL;
- const char *file_str = NULL;
-
- if (!sm9_sign_master_pub) {
- error_print();
- return -1;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, 0))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "wb"))) {
- error_print();
- goto end;
- }
- if (sm9_sign_master_public_key_to_pem((SM9_SIGN_MASTER_KEY *)sm9_sign_master_pub, fp) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- if (fp) fclose(fp);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_public_key_from_pem
- * Signature: (Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1public_1key_1from_1pem(
- JNIEnv *env, jclass this,
- jstring file)
-{
- jlong ret = 0;
- SM9_SIGN_MASTER_KEY *sm9_sign_master_pub = NULL;
- FILE *fp = NULL;
- const char *file_str = NULL;
-
- if (!(sm9_sign_master_pub = (SM9_SIGN_MASTER_KEY *)malloc(sizeof(SM9_SIGN_MASTER_KEY)))) {
- error_print();
- goto end;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, 0))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "rb"))) {
- error_print();
- goto end;
- }
- if (sm9_sign_master_public_key_from_pem(sm9_sign_master_pub, fp) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)sm9_sign_master_pub;
- sm9_sign_master_pub = NULL;
-end:
- if (fp) fclose(fp);
- if (sm9_sign_master_pub) {
- gmssl_secure_clear(sm9_sign_master_pub, sizeof(SM9_SIGN_MASTER_KEY));
- free(sm9_sign_master_pub);
- }
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_key_extract_key
- * Signature: (JLjava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1key_1extract_1key(
- JNIEnv *env, jclass this,
- jlong sm9_sign_master_key, jstring id)
-{
- jlong ret = 0;
- SM9_SIGN_KEY *sm9_sign_key = NULL;
- const char *id_str = NULL;
-
- if (!sm9_sign_master_key) {
- error_print();
- return 0;
- }
- if (!(id_str = (*env)->GetStringUTFChars(env, id, 0))) {
- error_print();
- goto end;
- }
- if (!(sm9_sign_key = (SM9_SIGN_KEY *)malloc(sizeof(SM9_SIGN_KEY)))) {
- error_print();
- goto end;
- }
- if (sm9_sign_master_key_extract_key((SM9_SIGN_MASTER_KEY *)sm9_sign_master_key,
- id_str, strlen(id_str), sm9_sign_key) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)sm9_sign_key;
- sm9_sign_key = NULL;
-end:
- if (id_str) (*env)->ReleaseStringUTFChars(env, id, id_str);
- if (sm9_sign_key) {
- gmssl_secure_clear(sm9_sign_key, sizeof(SM9_SIGN_KEY));
- free(sm9_sign_key);
- }
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_key_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1key_1free(
- JNIEnv *env, jclass this,
- jlong sm9_sign_key)
-{
- if (sm9_sign_key) {
- gmssl_secure_clear((SM9_SIGN_KEY *)sm9_sign_key, sizeof(SM9_SIGN_KEY));
- free((SM9_SIGN_KEY *)sm9_sign_key);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_key_info_encrypt_to_pem
- * Signature: (JLjava/lang/String;Ljava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1key_1info_1encrypt_1to_1pem(
- JNIEnv *env, jclass this,
- jlong sm9_sign_key, jstring pass, jstring file)
-{
- jint ret = -1;
- FILE *fp = NULL;
- const char *pass_str = NULL;
- const char *file_str = NULL;
-
- if (!sm9_sign_key) {
- error_print();
- return -1;
- }
- if (!(pass_str = (*env)->GetStringUTFChars(env, pass, 0))) {
- error_print();
- goto end;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, 0))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "wb"))) {
- error_print();
- goto end;
- }
- if (sm9_sign_key_info_encrypt_to_pem((SM9_SIGN_KEY *)sm9_sign_key, pass_str, fp) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- if (fp) fclose(fp);
- if (pass_str) (*env)->ReleaseStringUTFChars(env, pass, pass_str);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_key_info_decrypt_from_pem
- * Signature: (Ljava/lang/String;Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1key_1info_1decrypt_1from_1pem(
- JNIEnv *env, jclass this,
- jstring pass, jstring file)
-{
- jlong ret = 0;
- SM9_SIGN_KEY *sm9_sign_key = NULL;
- FILE *fp = NULL;
- const char *pass_str = NULL;
- const char *file_str = NULL;
-
- if (!(sm9_sign_key = (SM9_SIGN_KEY *)malloc(sizeof(SM9_SIGN_KEY)))) {
- error_print();
- return 0;
- }
- if (!(pass_str = (*env)->GetStringUTFChars(env, pass, 0))) {
- error_print();
- goto end;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, 0))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "rb"))) {
- error_print();
- goto end;
- }
- if (sm9_sign_key_info_decrypt_from_pem(sm9_sign_key, pass_str, fp) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)sm9_sign_key;
- sm9_sign_key = NULL;
-end:
- if (fp) fclose(fp);
- if (sm9_sign_key) {
- gmssl_secure_clear(sm9_sign_key, sizeof(SM9_SIGN_KEY));
- free(sm9_sign_key);
- }
- if (pass_str) (*env)->ReleaseStringUTFChars(env, pass, pass_str);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1ctx_1new(
- JNIEnv *env, jclass this)
-{
- jlong sm9_sign_ctx;
-
- if (!(sm9_sign_ctx = (jlong)malloc(sizeof(SM9_SIGN_CTX)))) {
- error_print();
- return 0;
- }
- memset((SM9_SIGN_CTX *)sm9_sign_ctx, 0, sizeof(SM9_SIGN_CTX));
- return sm9_sign_ctx;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1ctx_1free(
- JNIEnv *env, jclass this,
- jlong sm9_sign_ctx)
-{
- if (sm9_sign_ctx) {
- gmssl_secure_clear((SM9_SIGN_CTX *)sm9_sign_ctx, sizeof(SM9_SIGN_CTX));
- free((SM9_SIGN_CTX *)sm9_sign_ctx);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_init
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1init(
- JNIEnv *env, jclass this,
- jlong sm9_sign_ctx)
-{
- if (!sm9_sign_ctx) {
- error_print();
- return -1;
- }
- if (sm9_sign_init((SM9_SIGN_CTX *)sm9_sign_ctx) != 1) {
- error_print();
- return -1;
- }
- return 1;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_update
- * Signature: (J[BII)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1update(
- JNIEnv *env, jclass this,
- jlong sm9_sign_ctx, jbyteArray data, jint offset, jint length)
-{
- jint ret = -1;
- jbyte *buf = NULL;
- jsize buflen;
-
- if (!sm9_sign_ctx) {
- error_print();
- return -1;
- }
- if (!(buf = (*env)->GetByteArrayElements(env, data, NULL))) {
- error_print();
- goto end;
- }
- if (check_buf(buf, (*env)->GetArrayLength(env, data), offset, length) != 1) {
- error_print();
- goto end;
- }
- if (sm9_sign_update((SM9_SIGN_CTX *)sm9_sign_ctx, (uint8_t *)buf + offset, (size_t)length) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, data, buf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_finish
- * Signature: (JJ)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1finish(
- JNIEnv *env, jclass this,
- jlong sm9_sign_ctx, jlong sm9_sign_key)
-{
- jbyteArray ret = NULL;
- uint8_t sig[SM9_SIGNATURE_SIZE];
- size_t siglen;
-
- if (!sm9_sign_ctx) {
- error_print();
- return NULL;
- }
- if (!sm9_sign_key) {
- error_print();
- return NULL;
- }
- if (sm9_sign_finish((SM9_SIGN_CTX *)sm9_sign_ctx, (SM9_SIGN_KEY *)sm9_sign_key, sig, &siglen) != 1) {
- error_print();
- return NULL;
- }
- if (!(ret = (*env)->NewByteArray(env, siglen))) {
- error_print();
- return NULL;
- }
- (*env)->SetByteArrayRegion(env, ret, 0, siglen, (jbyte *)sig);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_verify_init
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1verify_1init(
- JNIEnv *env, jclass this,
- jlong sm9_sign_ctx)
-{
- if (!sm9_sign_ctx) {
- error_print();
- return -1;
- }
- if (sm9_verify_init((SM9_SIGN_CTX *)sm9_sign_ctx) != 1) {
- error_print();
- return -1;
- }
- return 1;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_verify_update
- * Signature: (J[BII)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1verify_1update(
- JNIEnv *env, jclass this,
- jlong sm9_sign_ctx, jbyteArray data, jint offset, jint length)
-{
- jint ret = -1;
- jbyte *buf = NULL;
- jsize buflen;
-
- if (!sm9_sign_ctx) {
- error_print();
- return -1;
- }
- if (!(buf = (*env)->GetByteArrayElements(env, data, NULL))) {
- error_print();
- return -1;
- }
- if (check_buf(buf, (*env)->GetArrayLength(env, data), offset, length) != 1) {
- error_print();
- goto end;
- }
- if (sm9_verify_update((SM9_SIGN_CTX *)sm9_sign_ctx, (uint8_t *)buf + offset, (size_t)length) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, data, buf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_verify_finish
- * Signature: (J[BJLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1verify_1finish(
- JNIEnv *env, jclass this,
- jlong sm9_sign_ctx, jbyteArray sig, jlong sm9_sign_master_pub, jstring id)
-{
- jint ret = -1;
- jbyte *sigbuf = NULL;
- jsize siglen;
- const char *id_str = NULL;
-
- if (!sm9_sign_ctx) {
- error_print();
- return -1;
- }
- if (!sm9_sign_master_pub) {
- error_print();
- return -1;
- }
- if (!(sigbuf = (*env)->GetByteArrayElements(env, sig, NULL))) {
- error_print();
- return -1;
- }
- siglen = (*env)->GetArrayLength(env, sig);
- if (!(id_str = (*env)->GetStringUTFChars(env, id, 0))) {
- error_print();
- goto end;
- }
- if ((ret = sm9_verify_finish((SM9_SIGN_CTX *)sm9_sign_ctx, (uint8_t *)sigbuf, (size_t)siglen,
- (SM9_SIGN_MASTER_KEY *)sm9_sign_master_pub, id_str, strlen(id_str))) < 0) {
- error_print();
- goto end;
- }
-end:
- (*env)->ReleaseByteArrayElements(env, sig, sigbuf, JNI_ABORT);
- if (id_str) (*env)->ReleaseStringUTFChars(env, id, id_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_key_generate
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1key_1generate(
- JNIEnv * env, jclass this)
-{
- jlong sm9_enc_master_key;
-
- if (!(sm9_enc_master_key = (jlong)malloc(sizeof(SM9_ENC_MASTER_KEY)))) {
- error_print();
- return 0;
- }
- if (sm9_enc_master_key_generate((SM9_ENC_MASTER_KEY *)sm9_enc_master_key) != 1) {
- gmssl_secure_clear((SM9_ENC_MASTER_KEY *)sm9_enc_master_key, sizeof(SM9_ENC_MASTER_KEY));
- error_print();
- return 0;
- }
- return sm9_enc_master_key;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_key_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1key_1free(
- JNIEnv *env, jclass this,
- jlong sm9_enc_master_key)
-{
- if (sm9_enc_master_key) {
- gmssl_secure_clear((SM9_ENC_MASTER_KEY *)sm9_enc_master_key, sizeof(SM9_ENC_MASTER_KEY));
- free((SM9_ENC_MASTER_KEY *)sm9_enc_master_key);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_key_info_encrypt_to_pem
- * Signature: (JLjava/lang/String;Ljava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1key_1info_1encrypt_1to_1pem(
- JNIEnv *env, jclass this,
- jlong sm9_enc_master_key, jstring pass, jstring file)
-{
- jint ret = -1;
- FILE *fp = NULL;
- const char *pass_str = NULL;
- const char *file_str = NULL;
-
- if (!sm9_enc_master_key) {
- error_print();
- return -1;
- }
- if (!(pass_str = (*env)->GetStringUTFChars(env, pass, 0))) {
- error_print();
- goto end;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, 0))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "wb"))) {
- error_print();
- goto end;
- }
- if (sm9_enc_master_key_info_encrypt_to_pem((SM9_ENC_MASTER_KEY *)sm9_enc_master_key, pass_str, fp) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- if (fp) fclose(fp);
- if (pass_str) (*env)->ReleaseStringUTFChars(env, pass, pass_str);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_key_info_decrypt_from_pem
- * Signature: (Ljava/lang/String;Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1key_1info_1decrypt_1from_1pem(
- JNIEnv *env, jclass this,
- jstring pass, jstring file)
-{
- jlong ret = 0;
- SM9_ENC_MASTER_KEY *sm9_enc_master_key = NULL;
- FILE *fp = NULL;
- const char *pass_str = NULL;
- const char *file_str = NULL;
-
- if (!(sm9_enc_master_key = (SM9_ENC_MASTER_KEY *)malloc(sizeof(SM9_ENC_MASTER_KEY)))) {
- error_print();
- return 0;
- }
- if (!(pass_str = (*env)->GetStringUTFChars(env, pass, 0))) {
- error_print();
- goto end;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, 0))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "rb"))) {
- error_print();
- goto end;
- }
- if (sm9_enc_master_key_info_decrypt_from_pem(sm9_enc_master_key, pass_str, fp) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)sm9_enc_master_key;
- sm9_enc_master_key = NULL;
-end:
- if (fp) fclose(fp);
- if (sm9_enc_master_key) {
- gmssl_secure_clear(sm9_enc_master_key, sizeof(SM9_ENC_MASTER_KEY));
- free(sm9_enc_master_key);
- }
- if (pass_str) (*env)->ReleaseStringUTFChars(env, pass, pass_str);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
- return 0;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_public_key_to_pem
- * Signature: (JLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1public_1key_1to_1pem(
- JNIEnv *env, jclass this,
- jlong sm9_enc_master_pub, jstring file)
-{
- jint ret = -1;
- FILE *fp = NULL;
- const char *file_str = NULL;
-
- if (!sm9_enc_master_pub) {
- error_print();
- return -1;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, 0))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "wb"))) {
- error_print();
- goto end;
- }
- if (sm9_enc_master_public_key_to_pem((SM9_ENC_MASTER_KEY *)sm9_enc_master_pub, fp) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- if (fp) fclose(fp);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_public_key_from_pem
- * Signature: (Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1public_1key_1from_1pem(
- JNIEnv *env, jclass this,
- jstring file)
-{
- jlong ret = 0;
- SM9_ENC_MASTER_KEY *sm9_enc_master_pub = NULL;
- FILE *fp = NULL;
- const char *file_str = NULL;
-
- if (!(sm9_enc_master_pub = (SM9_ENC_MASTER_KEY *)malloc(sizeof(SM9_ENC_MASTER_KEY)))) {
- error_print();
- goto end;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, 0))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "rb"))) {
- error_print();
- goto end;
- }
- if (sm9_enc_master_public_key_from_pem(sm9_enc_master_pub, fp) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)sm9_enc_master_pub;
- sm9_enc_master_pub = NULL;
-end:
- if (fp) fclose(fp);
- if (sm9_enc_master_pub) {
- gmssl_secure_clear(sm9_enc_master_pub, sizeof(SM9_ENC_MASTER_KEY));
- free(sm9_enc_master_pub);
- }
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_key_extract_key
- * Signature: (JLjava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1key_1extract_1key(
- JNIEnv *env, jclass this,
- jlong sm9_enc_master_key, jstring id)
-{
- jlong ret = 0;
- SM9_ENC_KEY *sm9_enc_key = NULL;
- const char *id_str = NULL;
-
- if (!sm9_enc_master_key) {
- error_print();
- return 0;
- }
- if (!(id_str = (*env)->GetStringUTFChars(env, id, 0))) {
- error_print();
- goto end;
- }
- if (!(sm9_enc_key = (SM9_ENC_KEY *)malloc(sizeof(SM9_ENC_KEY)))) {
- error_print();
- goto end;
- }
- if (sm9_enc_master_key_extract_key((SM9_ENC_MASTER_KEY *)sm9_enc_master_key,
- id_str, strlen(id_str), sm9_enc_key) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)sm9_enc_key;
- sm9_enc_key = NULL;
-end:
- if (id_str) (*env)->ReleaseStringUTFChars(env, id, id_str);
- if (sm9_enc_key) {
- gmssl_secure_clear(sm9_enc_key, sizeof(SM9_ENC_KEY));
- free(sm9_enc_key);
- }
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_key_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1key_1free(
- JNIEnv *env, jclass this,
- jlong sm9_enc_key)
-{
- if (sm9_enc_key) {
- gmssl_secure_clear((SM9_ENC_KEY *)sm9_enc_key, sizeof(SM9_ENC_KEY));
- free((SM9_ENC_KEY *)sm9_enc_key);
- }
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_key_info_encrypt_to_pem
- * Signature: (JLjava/lang/String;Ljava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1key_1info_1encrypt_1to_1pem(
- JNIEnv *env, jclass this,
- jlong sm9_enc_key, jstring pass, jstring file)
-{
- jint ret = -1;
- FILE *fp = NULL;
- const char *pass_str = NULL;
- const char *file_str = NULL;
-
- if (!sm9_enc_key) {
- error_print();
- return -1;
- }
- if (!(pass_str = (*env)->GetStringUTFChars(env, pass, 0))) {
- error_print();
- goto end;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, 0))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "wb"))) {
- error_print();
- goto end;
- }
- if (sm9_enc_key_info_encrypt_to_pem((SM9_ENC_KEY *)sm9_enc_key, pass_str, fp) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- if (fp) fclose(fp);
- if (pass_str) (*env)->ReleaseStringUTFChars(env, pass, pass_str);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_key_info_decrypt_from_pem
- * Signature: (Ljava/lang/String;Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1key_1info_1decrypt_1from_1pem(
- JNIEnv *env, jclass this,
- jstring pass, jstring file)
-{
- jlong ret = 0;
- SM9_ENC_KEY *sm9_enc_key = NULL;
- FILE *fp = NULL;
- const char *pass_str = NULL;
- const char *file_str = NULL;
-
- if (!(sm9_enc_key = (SM9_ENC_KEY *)malloc(sizeof(SM9_ENC_KEY)))) {
- error_print();
- return 0;
- }
- if (!(pass_str = (*env)->GetStringUTFChars(env, pass, 0))) {
- error_print();
- goto end;
- }
- if (!(file_str = (*env)->GetStringUTFChars(env, file, 0))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "rb"))) {
- error_print();
- goto end;
- }
- if (sm9_enc_key_info_decrypt_from_pem(sm9_enc_key, pass_str, fp) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)sm9_enc_key;
- sm9_enc_key = NULL;
-end:
- if (fp) fclose(fp);
- if (sm9_enc_key) {
- gmssl_secure_clear(sm9_enc_key, sizeof(SM9_ENC_KEY));
- free(sm9_enc_key);
- }
- if (pass_str) (*env)->ReleaseStringUTFChars(env, pass, pass_str);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_encrypt
- * Signature: (JLjava/lang/String;[B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm9_1encrypt(
- JNIEnv *env, jclass this,
- jlong sm9_enc_master_pub, jstring id, jbyteArray in)
-{
- jbyteArray ret = NULL;
- const char *id_str = NULL;
- jbyte *inbuf = NULL;
- jsize inlen;
- uint8_t outbuf[SM9_MAX_CIPHERTEXT_SIZE];
- size_t outlen;
-
- if (!sm9_enc_master_pub) {
- error_print();
- return NULL;
- }
- if (!(id_str = (*env)->GetStringUTFChars(env, id, NULL))) {
- error_print();
- return NULL;
- }
- if (!(inbuf = (*env)->GetByteArrayElements(env, in, 0))) {
- error_print();
- goto end;
- }
- inlen = (*env)->GetArrayLength(env, in);
- if (sm9_encrypt((SM9_ENC_MASTER_KEY *)sm9_enc_master_pub, id_str, strlen(id_str),
- (uint8_t *)inbuf, (size_t)inlen, outbuf, &outlen) != 1) {
- error_print();
- goto end;
- }
- if (!(ret = (*env)->NewByteArray(env, outlen))) {
- error_print();
- goto end;
- }
- (*env)->SetByteArrayRegion(env, ret, 0, outlen, (jbyte *)outbuf);
-end:
- (*env)->ReleaseStringUTFChars(env, id, id_str);
- if (inbuf) (*env)->ReleaseByteArrayElements(env, in, inbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_decrypt
- * Signature: (JLjava/lang/String;[B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm9_1decrypt(
- JNIEnv *env, jclass this,
- jlong sm9_enc_key, jstring id, jbyteArray in)
-{
- jbyteArray ret = NULL;
- const char *id_str = NULL;
- jbyte *inbuf = NULL;
- jsize inlen;
- uint8_t outbuf[SM9_MAX_CIPHERTEXT_SIZE];
- size_t outlen;
-
- if (!sm9_enc_key) {
- error_print();
- return NULL;
- }
- if (!(id_str = (*env)->GetStringUTFChars(env, id, NULL))) {
- error_print();
- return NULL;
- }
- if (!(inbuf = (*env)->GetByteArrayElements(env, in, NULL))) {
- error_print();
- goto end;
- }
- inlen = (*env)->GetArrayLength(env, in);
- if (sm9_decrypt((SM9_ENC_KEY *)sm9_enc_key, id_str, strlen(id_str),
- (uint8_t *)inbuf, (size_t)inlen, outbuf, &outlen) != 1) {
- error_print();
- goto end;
- }
- if (!(ret = (*env)->NewByteArray(env, outlen))) {
- error_print();
- goto end;
- }
- (*env)->SetByteArrayRegion(env, ret, 0, outlen, (jbyte *)outbuf);
-end:
- (*env)->ReleaseStringUTFChars(env, id, id_str);
- if (inbuf) (*env)->ReleaseByteArrayElements(env, in, inbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_from_pem
- * Signature: (Ljava/lang/String;)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_cert_1from_1pem(
- JNIEnv *env, jclass this, jstring file)
-{
- jbyteArray ret = NULL;
- const char *file_str = NULL;
- uint8_t *cert = NULL;
- size_t certlen;
-
- if (!(file_str = (*env)->GetStringUTFChars(env, file, NULL))) {
- error_print();
- return 0;
- }
- if (x509_cert_new_from_file(&cert, &certlen, file_str) != 1) {
- error_print();
- goto end;
- }
- if (!(ret = (*env)->NewByteArray(env, certlen))) {
- error_print();
- goto end;
- }
- (*env)->SetByteArrayRegion(env, ret, 0, certlen, (jbyte *)cert);
-end:
- (*env)->ReleaseStringUTFChars(env, file, file_str);
- if (cert) free(cert);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_to_pem
- * Signature: ([BLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_cert_1to_1pem(
- JNIEnv *env, jclass this, jbyteArray cert, jstring file)
-{
- jint ret = -1;
- jbyte *certbuf;
- jsize certlen;
- const char *file_str = NULL;
- FILE *fp = NULL;
-
- if (!(certbuf = (*env)->GetByteArrayElements(env, cert, NULL))) {
- error_print();
- return -1;
- }
- certlen = (*env)->GetArrayLength(env, cert);
- if (!(file_str = (*env)->GetStringUTFChars(env, file, NULL))) {
- error_print();
- goto end;
- }
- if (!(fp = fopen(file_str, "wb"))) {
- error_print();
- goto end;
- }
- if (x509_cert_to_pem((uint8_t *)certbuf, (size_t)certlen, fp) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, cert, certbuf, JNI_ABORT);
- if (file_str) (*env)->ReleaseStringUTFChars(env, file, file_str);
- if (fp) fclose(fp);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_get_serial_number
- * Signature: ([B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_cert_1get_1serial_1number(
- JNIEnv *env, jclass this, jbyteArray cert)
-{
- jbyteArray ret = NULL;
- jbyte *certbuf;
- jsize certlen;
- const uint8_t *serial;
- size_t serial_len;
-
- if (!(certbuf = (*env)->GetByteArrayElements(env, cert, NULL))) {
- error_print();
- return NULL;
- }
- certlen = (*env)->GetArrayLength(env, cert);
- if (x509_cert_get_issuer_and_serial_number((uint8_t *)certbuf, certlen,
- NULL, NULL, &serial, &serial_len) != 1) {
- error_print();
- goto end;
- }
- if (!(ret = (*env)->NewByteArray(env, serial_len))) {
- error_print();
- goto end;
- }
- (*env)->SetByteArrayRegion(env, ret, 0, serial_len, (jbyte *)serial);
-end:
- (*env)->ReleaseByteArrayElements(env, cert, certbuf, JNI_ABORT);
- return ret;
-}
-
-static int gmssl_name_cnt(const uint8_t *d, size_t dlen, int *count)
-{
- int cnt = 0;
-
- while (dlen) {
- const uint8_t *rdn;
- size_t rdnlen;
-
- if (asn1_set_from_der(&rdn, &rdnlen, &d, &dlen) != 1) {
- error_print();
- return -1;
- }
- while (rdnlen) {
- const uint8_t *p;
- size_t len;
-
- if (asn1_sequence_from_der(&p, &len, &rdn, &rdnlen) != 1) {
- error_print();
- return -1;
- }
- cnt++;
- }
- }
- *count = cnt;
- return 1;
-}
-
-static int gmssl_parse_attr_type_and_value(JNIEnv *env, jobjectArray arr, int *index, const uint8_t *d, size_t dlen)
-{
- int oid, tag;
- const uint8_t *val;
- size_t vlen;
- char *c_str = NULL;
- size_t c_str_len;
- jstring str = NULL;
-
-
- if (x509_name_type_from_der(&oid, &d, &dlen) != 1) {
- error_print();
- return -1;
- }
- c_str_len = strlen(x509_name_type_name(oid)) + 1;
-
- if (oid == OID_email_address) {
- if (asn1_ia5_string_from_der((const char **)&val, &vlen, &d, &dlen) != 1) {
- error_print();
- return -1;
- }
- } else {
- if (x509_directory_name_from_der(&tag, &val, &vlen, &d, &dlen) != 1) {
- error_print();
- return -1;
- }
- }
- c_str_len += vlen + 1;
-
- if (asn1_length_is_zero(dlen) != 1) {
- error_print();
- return -1;
- }
-
- if (!(c_str = malloc(c_str_len))) {
- error_print();
- return -1;
- }
- strcpy(c_str, x509_name_type_name(oid));
- c_str[strlen(x509_name_type_name(oid))] = ':';
- memcpy(c_str + strlen(x509_name_type_name(oid)) + 1, val, vlen);
- c_str[c_str_len-1] = 0;
-
- if (!(str = (*env)->NewStringUTF(env, c_str))) {
- error_print();
- return -1;
- }
- free(c_str);
- (*env)->SetObjectArrayElement(env, arr, *index, str);
- (*index)++;
- return 1;
-}
-
-static int gmssl_parse_rdn(JNIEnv *env, jobjectArray arr, int *index, const uint8_t *d, size_t dlen)
-{
- const uint8_t *p;
- size_t len;
-
- while (dlen) {
- if (asn1_sequence_from_der(&p, &len, &d, &dlen) != 1) {
- error_print();
- return -1;
- }
- if (gmssl_parse_attr_type_and_value(env, arr, index, p, len) != 1) {
- error_print();
- return -1;
- }
- }
- return 1;
-}
-
-static int gmssl_parse_name(JNIEnv *env, jobjectArray arr, const uint8_t *d, size_t dlen)
-{
- const uint8_t *p;
- size_t len;
- int index = 0;
-
- while (dlen) {
- if (asn1_set_from_der(&p, &len, &d, &dlen) != 1) {
- error_print();
- return -1;
- }
- if (gmssl_parse_rdn(env, arr, &index, p, len) != 1) {
- error_print();
- return -1;
- }
- }
- return 1;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_get_issuer
- * Signature: ([B)[Ljava/lang/String;
- */
-JNIEXPORT jobjectArray JNICALL Java_org_gmssl_GmSSLJNI_cert_1get_1issuer(
- JNIEnv *env, jclass this, jbyteArray cert)
-{
- jobjectArray ret = NULL;
- jobjectArray arr = NULL;
- jbyte *certbuf;
- jsize certlen;
- const uint8_t *name;
- size_t namelen;
- int cnt;
-
- if (!(certbuf = (*env)->GetByteArrayElements(env, cert, NULL))) {
- error_print();
- return NULL;
- }
- certlen = (*env)->GetArrayLength(env, cert);
- if (x509_cert_get_issuer((uint8_t *)certbuf, certlen, &name, &namelen) != 1) {
- error_print();
- goto end;
- }
- if (gmssl_name_cnt(name, namelen, &cnt) != 1) {
- error_print();
- goto end;
- }
- if (!(arr = (*env)->NewObjectArray(env, cnt, (*env)->FindClass(env, "java/lang/String"), 0))) {
- error_print();
- goto end;
- }
- if (gmssl_parse_name(env, arr, name, namelen) != 1) {
- error_print();
- //goto end;
- // FIXME: how to release arr ???
- }
- ret = arr;
- arr = NULL;
-end:
- (*env)->ReleaseByteArrayElements(env, cert, certbuf, JNI_ABORT);
- return ret;
-}
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_get_subject
- * Signature: ([B)[Ljava/lang/String;
- */
-JNIEXPORT jobjectArray JNICALL Java_org_gmssl_GmSSLJNI_cert_1get_1subject(
- JNIEnv *env, jclass this, jbyteArray cert)
-{
- jobjectArray ret = NULL;
- jobjectArray arr = NULL;
- jbyte *certbuf;
- jsize certlen;
- const uint8_t *name;
- size_t namelen;
- int cnt;
-
- if (!(certbuf = (*env)->GetByteArrayElements(env, cert, NULL))) {
- error_print();
- return NULL;
- }
- certlen = (*env)->GetArrayLength(env, cert);
- if (x509_cert_get_subject((uint8_t *)certbuf, certlen, &name, &namelen) != 1) {
- error_print();
- goto end;
- }
- if (gmssl_name_cnt(name, namelen, &cnt) != 1) {
- error_print();
- goto end;
- }
- if (!(arr = (*env)->NewObjectArray(env, cnt, (*env)->FindClass(env, "java/lang/String"), 0))) {
- error_print();
- goto end;
- }
- if (gmssl_parse_name(env, arr, name, namelen) != 1) {
- error_print();
- //goto end;
- // FIXME: how to release arr ???
- }
- ret = arr;
- arr = NULL;
-end:
- (*env)->ReleaseByteArrayElements(env, cert, certbuf, JNI_ABORT);
- return ret;
-}
-
-
-#define x509_cert_get_validity(cert,certlen,not_before,not_after) \
- x509_cert_get_details(cert,certlen,\
- NULL,\
- NULL,NULL,\
- NULL,\
- NULL,NULL,\
- not_before,not_after,\
- NULL,NULL,\
- NULL,\
- NULL,NULL,\
- NULL,NULL,\
- NULL,NULL,\
- NULL,\
- NULL,NULL)
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_get_not_before
- * Signature: ([B)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_cert_1get_1not_1before(
- JNIEnv *env, jclass this, jbyteArray cert)
-{
- jlong ret = -1;
- jbyte *certbuf;
- jsize certlen;
- time_t not_before, not_after;
-
- if (!(certbuf = (*env)->GetByteArrayElements(env, cert, NULL))) {
- error_print();
- return -1;
- }
- certlen = (*env)->GetArrayLength(env, cert);
- if (x509_cert_get_validity((uint8_t *)certbuf, certlen, ¬_before, ¬_after) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)not_before;
-end:
- (*env)->ReleaseByteArrayElements(env, cert, certbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_get_not_after
- * Signature: ([B)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_cert_1get_1not_1after(
- JNIEnv *env, jclass this, jbyteArray cert)
-{
- jlong ret = -1;
- jbyte *certbuf;
- jsize certlen;
- time_t not_before, not_after;
-
- if (!(certbuf = (*env)->GetByteArrayElements(env, cert, NULL))) {
- error_print();
- return -1;
- }
- certlen = (*env)->GetArrayLength(env, cert);
- if (x509_cert_get_validity((uint8_t *)certbuf, certlen, ¬_before, ¬_after) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)not_after;
-end:
- (*env)->ReleaseByteArrayElements(env, cert, certbuf, JNI_ABORT);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_get_subject_public_key
- * Signature: ([B)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_cert_1get_1subject_1public_1key(
- JNIEnv *env, jclass this, jbyteArray cert)
-{
- jlong ret = 0;
- jbyte *certbuf;
- jsize certlen;
- SM2_KEY *sm2_pub = NULL;
-
- if (!(certbuf = (*env)->GetByteArrayElements(env, cert, NULL))) {
- error_print();
- return -1;
- }
- certlen = (*env)->GetArrayLength(env, cert);
- if (!(sm2_pub = (SM2_KEY *)malloc(sizeof(SM2_KEY)))) {
- error_print();
- goto end;
- }
- memset(sm2_pub, 0, sizeof(SM2_KEY));
- if (x509_cert_get_subject_public_key((uint8_t *)certbuf, certlen, sm2_pub) != 1) {
- error_print();
- goto end;
- }
- ret = (jlong)sm2_pub;
- sm2_pub = NULL;
-end:
- (*env)->ReleaseByteArrayElements(env, cert, certbuf, JNI_ABORT);
- if (sm2_pub) free(sm2_pub);
- return ret;
-}
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_verify_by_ca_cert
- * Signature: ([B[BLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_cert_1verify_1by_1ca_1cert(
- JNIEnv *env, jclass this, jbyteArray cert, jbyteArray cacert, jstring ca_sm2_id)
-{
- jint ret = -1;
- jbyte *certbuf = NULL;
- jsize certlen;
- jbyte *cacertbuf = NULL;
- jsize cacertlen;
- const char *id_str = NULL;
-
- if (!(certbuf = (*env)->GetByteArrayElements(env, cert, NULL))) {
- error_print();
- return -1;
- }
- certlen = (*env)->GetArrayLength(env, cert);
- if (!(cacertbuf = (*env)->GetByteArrayElements(env, cacert, NULL))) {
- error_print();
- goto end;
- }
- cacertlen = (*env)->GetArrayLength(env, cacert);
- if (!(id_str = (*env)->GetStringUTFChars(env, ca_sm2_id, NULL))) {
- error_print();
- goto end;
- }
- if (x509_cert_verify_by_ca_cert((uint8_t *)certbuf, certlen, (uint8_t *)cacertbuf, cacertlen,
- id_str, strlen(id_str)) != 1) {
- error_print();
- goto end;
- }
- ret = 1;
-end:
- (*env)->ReleaseByteArrayElements(env, cert, certbuf, JNI_ABORT);
- if (cacertbuf) (*env)->ReleaseByteArrayElements(env, cacert, cacertbuf, JNI_ABORT);
- if (id_str) (*env)->ReleaseStringUTFChars(env, ca_sm2_id, id_str);
- return ret;
-}
-
diff --git a/gmssljni.h b/gmssljni.h
deleted file mode 100644
index 9dd0b4c..0000000
--- a/gmssljni.h
+++ /dev/null
@@ -1,919 +0,0 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include
-/* Header for class org_gmssl_GmSSLJNI */
-
-#ifndef _Included_org_gmssl_GmSSLJNI
-#define _Included_org_gmssl_GmSSLJNI
-#ifdef __cplusplus
-extern "C" {
-#endif
-#undef org_gmssl_GmSSLJNI_SM3_DIGEST_SIZE
-#define org_gmssl_GmSSLJNI_SM3_DIGEST_SIZE 32L
-#undef org_gmssl_GmSSLJNI_SM3_HMAC_SIZE
-#define org_gmssl_GmSSLJNI_SM3_HMAC_SIZE 32L
-#undef org_gmssl_GmSSLJNI_SM3_HMAC_MIN_KEY_SIZE
-#define org_gmssl_GmSSLJNI_SM3_HMAC_MIN_KEY_SIZE 16L
-#undef org_gmssl_GmSSLJNI_SM4_KEY_SIZE
-#define org_gmssl_GmSSLJNI_SM4_KEY_SIZE 16L
-#undef org_gmssl_GmSSLJNI_SM4_BLOCK_SIZE
-#define org_gmssl_GmSSLJNI_SM4_BLOCK_SIZE 16L
-#undef org_gmssl_GmSSLJNI_SM4_GCM_MIN_IV_SIZE
-#define org_gmssl_GmSSLJNI_SM4_GCM_MIN_IV_SIZE 1L
-#undef org_gmssl_GmSSLJNI_SM4_GCM_MAX_IV_SIZE
-#define org_gmssl_GmSSLJNI_SM4_GCM_MAX_IV_SIZE 64L
-#undef org_gmssl_GmSSLJNI_SM4_GCM_DEFAULT_IV_SIZE
-#define org_gmssl_GmSSLJNI_SM4_GCM_DEFAULT_IV_SIZE 12L
-#undef org_gmssl_GmSSLJNI_SM4_GCM_MAX_TAG_SIZE
-#define org_gmssl_GmSSLJNI_SM4_GCM_MAX_TAG_SIZE 16L
-#undef org_gmssl_GmSSLJNI_SM2_MAX_PLAINTEXT_SIZE
-#define org_gmssl_GmSSLJNI_SM2_MAX_PLAINTEXT_SIZE 255L
-#undef org_gmssl_GmSSLJNI_SM9_MAX_PLAINTEXT_SIZE
-#define org_gmssl_GmSSLJNI_SM9_MAX_PLAINTEXT_SIZE 255L
-#undef org_gmssl_GmSSLJNI_ZUC_KEY_SIZE
-#define org_gmssl_GmSSLJNI_ZUC_KEY_SIZE 16L
-#undef org_gmssl_GmSSLJNI_ZUC_IV_SIZE
-#define org_gmssl_GmSSLJNI_ZUC_IV_SIZE 16L
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: version_num
- * Signature: ()I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_version_1num
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: version_str
- * Signature: ()Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL Java_org_gmssl_GmSSLJNI_version_1str
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: rand_bytes
- * Signature: ([BIJ)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_rand_1bytes
- (JNIEnv *, jclass, jbyteArray, jint, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm3_1ctx_1new
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm3_1ctx_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_init
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1init
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_update
- * Signature: (J[BII)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1update
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_finish
- * Signature: (J[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1finish
- (JNIEnv *, jclass, jlong, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_hmac_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm3_1hmac_1ctx_1new
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_hmac_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm3_1hmac_1ctx_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_hmac_init
- * Signature: (J[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1hmac_1init
- (JNIEnv *, jclass, jlong, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_hmac_update
- * Signature: (J[BII)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1hmac_1update
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_hmac_finish
- * Signature: (J[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1hmac_1finish
- (JNIEnv *, jclass, jlong, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm3_pbkdf2
- * Signature: (Ljava/lang/String;[BII)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm3_1pbkdf2
- (JNIEnv *, jclass, jstring, jbyteArray, jint, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_key_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm4_1key_1new
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_key_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm4_1key_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_set_encrypt_key
- * Signature: (J[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1set_1encrypt_1key
- (JNIEnv *, jclass, jlong, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_set_decrypt_key
- * Signature: (J[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1set_1decrypt_1key
- (JNIEnv *, jclass, jlong, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_encrypt
- * Signature: (J[BI[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1encrypt
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1ctx_1new
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1ctx_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_encrypt_init
- * Signature: (J[B[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1encrypt_1init
- (JNIEnv *, jclass, jlong, jbyteArray, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_encrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1encrypt_1update
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jint, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_encrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1encrypt_1finish
- (JNIEnv *, jclass, jlong, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_decrypt_init
- * Signature: (J[B[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1decrypt_1init
- (JNIEnv *, jclass, jlong, jbyteArray, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_decrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1decrypt_1update
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jint, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_cbc_decrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1cbc_1decrypt_1finish
- (JNIEnv *, jclass, jlong, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1ctx_1new
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1ctx_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_encrypt_init
- * Signature: (J[B[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1encrypt_1init
- (JNIEnv *, jclass, jlong, jbyteArray, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_encrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1encrypt_1update
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jint, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_encrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1encrypt_1finish
- (JNIEnv *, jclass, jlong, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_decrypt_init
- * Signature: (J[B[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1decrypt_1init
- (JNIEnv *, jclass, jlong, jbyteArray, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_decrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1decrypt_1update
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jint, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_ctr_decrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1ctr_1decrypt_1finish
- (JNIEnv *, jclass, jlong, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1ctx_1new
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1ctx_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_encrypt_init
- * Signature: (J[B[B[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1encrypt_1init
- (JNIEnv *, jclass, jlong, jbyteArray, jbyteArray, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_encrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1encrypt_1update
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jint, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_encrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1encrypt_1finish
- (JNIEnv *, jclass, jlong, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_decrypt_init
- * Signature: (J[B[B[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1decrypt_1init
- (JNIEnv *, jclass, jlong, jbyteArray, jbyteArray, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_decrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1decrypt_1update
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jint, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm4_gcm_decrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm4_1gcm_1decrypt_1finish
- (JNIEnv *, jclass, jlong, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: zuc_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_zuc_1ctx_1new
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: zuc_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_zuc_1ctx_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: zuc_encrypt_init
- * Signature: (J[B[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_zuc_1encrypt_1init
- (JNIEnv *, jclass, jlong, jbyteArray, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: zuc_encrypt_update
- * Signature: (J[BII[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_zuc_1encrypt_1update
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jint, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: zuc_encrypt_finish
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_zuc_1encrypt_1finish
- (JNIEnv *, jclass, jlong, jbyteArray, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_key_generate
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm2_1key_1generate
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_key_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm2_1key_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_private_key_info_to_der
- * Signature: (J)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm2_1private_1key_1info_1to_1der
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_private_key_info_from_der
- * Signature: ([B)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm2_1private_1key_1info_1from_1der
- (JNIEnv *, jclass, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_public_key_info_to_der
- * Signature: (J)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm2_1public_1key_1info_1to_1der
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_public_key_info_from_der
- * Signature: ([B)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm2_1public_1key_1info_1from_1der
- (JNIEnv *, jclass, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_private_key_info_encrypt_to_pem
- * Signature: (JLjava/lang/String;Ljava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1private_1key_1info_1encrypt_1to_1pem
- (JNIEnv *, jclass, jlong, jstring, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_private_key_info_decrypt_from_pem
- * Signature: (Ljava/lang/String;Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm2_1private_1key_1info_1decrypt_1from_1pem
- (JNIEnv *, jclass, jstring, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_public_key_info_to_pem
- * Signature: (JLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1public_1key_1info_1to_1pem
- (JNIEnv *, jclass, jlong, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_public_key_info_from_pem
- * Signature: (Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm2_1public_1key_1info_1from_1pem
- (JNIEnv *, jclass, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_compute_z
- * Signature: (JLjava/lang/String;[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1compute_1z
- (JNIEnv *, jclass, jlong, jstring, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_sign
- * Signature: (J[B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm2_1sign
- (JNIEnv *, jclass, jlong, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_verify
- * Signature: (J[B[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1verify
- (JNIEnv *, jclass, jlong, jbyteArray, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_encrypt
- * Signature: (J[B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm2_1encrypt
- (JNIEnv *, jclass, jlong, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_decrypt
- * Signature: (J[B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm2_1decrypt
- (JNIEnv *, jclass, jlong, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_sign_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm2_1sign_1ctx_1new
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_sign_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm2_1sign_1ctx_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_sign_init
- * Signature: (JJLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1sign_1init
- (JNIEnv *, jclass, jlong, jlong, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_sign_update
- * Signature: (J[BII)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1sign_1update
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_sign_finish
- * Signature: (J)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm2_1sign_1finish
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_verify_init
- * Signature: (JJLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1verify_1init
- (JNIEnv *, jclass, jlong, jlong, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_verify_update
- * Signature: (J[BII)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1verify_1update
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm2_verify_finish
- * Signature: (J[B)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm2_1verify_1finish
- (JNIEnv *, jclass, jlong, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_key_generate
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1key_1generate
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_key_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1key_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_key_info_encrypt_to_pem
- * Signature: (JLjava/lang/String;Ljava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1key_1info_1encrypt_1to_1pem
- (JNIEnv *, jclass, jlong, jstring, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_key_info_decrypt_from_pem
- * Signature: (Ljava/lang/String;Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1key_1info_1decrypt_1from_1pem
- (JNIEnv *, jclass, jstring, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_public_key_to_pem
- * Signature: (JLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1public_1key_1to_1pem
- (JNIEnv *, jclass, jlong, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_public_key_from_pem
- * Signature: (Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1public_1key_1from_1pem
- (JNIEnv *, jclass, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_master_key_extract_key
- * Signature: (JLjava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1master_1key_1extract_1key
- (JNIEnv *, jclass, jlong, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_key_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1key_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_key_info_encrypt_to_pem
- * Signature: (JLjava/lang/String;Ljava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1key_1info_1encrypt_1to_1pem
- (JNIEnv *, jclass, jlong, jstring, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_key_info_decrypt_from_pem
- * Signature: (Ljava/lang/String;Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1key_1info_1decrypt_1from_1pem
- (JNIEnv *, jclass, jstring, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_ctx_new
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1ctx_1new
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_ctx_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1ctx_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_init
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1init
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_update
- * Signature: (J[BII)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1update
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_sign_finish
- * Signature: (JJ)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm9_1sign_1finish
- (JNIEnv *, jclass, jlong, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_verify_init
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1verify_1init
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_verify_update
- * Signature: (J[BII)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1verify_1update
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jint);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_verify_finish
- * Signature: (J[BJLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1verify_1finish
- (JNIEnv *, jclass, jlong, jbyteArray, jlong, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_key_generate
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1key_1generate
- (JNIEnv *, jclass);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_key_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1key_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_key_info_encrypt_to_pem
- * Signature: (JLjava/lang/String;Ljava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1key_1info_1encrypt_1to_1pem
- (JNIEnv *, jclass, jlong, jstring, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_key_info_decrypt_from_pem
- * Signature: (Ljava/lang/String;Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1key_1info_1decrypt_1from_1pem
- (JNIEnv *, jclass, jstring, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_public_key_to_pem
- * Signature: (JLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1public_1key_1to_1pem
- (JNIEnv *, jclass, jlong, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_public_key_from_pem
- * Signature: (Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1public_1key_1from_1pem
- (JNIEnv *, jclass, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_master_key_extract_key
- * Signature: (JLjava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1master_1key_1extract_1key
- (JNIEnv *, jclass, jlong, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_key_free
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1key_1free
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_key_info_encrypt_to_pem
- * Signature: (JLjava/lang/String;Ljava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1key_1info_1encrypt_1to_1pem
- (JNIEnv *, jclass, jlong, jstring, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_enc_key_info_decrypt_from_pem
- * Signature: (Ljava/lang/String;Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_sm9_1enc_1key_1info_1decrypt_1from_1pem
- (JNIEnv *, jclass, jstring, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_encrypt
- * Signature: (JLjava/lang/String;[B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm9_1encrypt
- (JNIEnv *, jclass, jlong, jstring, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: sm9_decrypt
- * Signature: (JLjava/lang/String;[B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm9_1decrypt
- (JNIEnv *, jclass, jlong, jstring, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_from_pem
- * Signature: (Ljava/lang/String;)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_cert_1from_1pem
- (JNIEnv *, jclass, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_to_pem
- * Signature: ([BLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_cert_1to_1pem
- (JNIEnv *, jclass, jbyteArray, jstring);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_get_serial_number
- * Signature: ([B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_cert_1get_1serial_1number
- (JNIEnv *, jclass, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_get_issuer
- * Signature: ([B)[Ljava/lang/String;
- */
-JNIEXPORT jobjectArray JNICALL Java_org_gmssl_GmSSLJNI_cert_1get_1issuer
- (JNIEnv *, jclass, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_get_subject
- * Signature: ([B)[Ljava/lang/String;
- */
-JNIEXPORT jobjectArray JNICALL Java_org_gmssl_GmSSLJNI_cert_1get_1subject
- (JNIEnv *, jclass, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_get_not_before
- * Signature: ([B)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_cert_1get_1not_1before
- (JNIEnv *, jclass, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_get_not_after
- * Signature: ([B)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_cert_1get_1not_1after
- (JNIEnv *, jclass, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_get_subject_public_key
- * Signature: ([B)J
- */
-JNIEXPORT jlong JNICALL Java_org_gmssl_GmSSLJNI_cert_1get_1subject_1public_1key
- (JNIEnv *, jclass, jbyteArray);
-
-/*
- * Class: org_gmssl_GmSSLJNI
- * Method: cert_verify_by_ca_cert
- * Signature: ([B[BLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_cert_1verify_1by_1ca_1cert
- (JNIEnv *, jclass, jbyteArray, jbyteArray, jstring);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/jni/jni.h b/jni/jni.h
deleted file mode 100755
index b56fb7f..0000000
--- a/jni/jni.h
+++ /dev/null
@@ -1,1961 +0,0 @@
-/*
- * @(#)jni.h 1.62 06/02/02
- *
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
- */
-
-/*
- * We used part of Netscape's Java Runtime Interface (JRI) as the starting
- * point of our design and implementation.
- */
-
-/******************************************************************************
- * Java Runtime Interface
- * Copyright (c) 1996 Netscape Communications Corporation. All rights reserved.
- *****************************************************************************/
-
-#ifndef _JAVASOFT_JNI_H_
-#define _JAVASOFT_JNI_H_
-
-#include
-#include
-
-/* jni_md.h contains the machine-dependent typedefs for jbyte, jint
- and jlong */
-
-#include "jni_md.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * JNI Types
- */
-
-#ifndef JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H
-
-typedef unsigned char jboolean;
-typedef unsigned short jchar;
-typedef short jshort;
-typedef float jfloat;
-typedef double jdouble;
-
-typedef jint jsize;
-
-#ifdef __cplusplus
-
-class _jobject {};
-class _jclass : public _jobject {};
-class _jthrowable : public _jobject {};
-class _jstring : public _jobject {};
-class _jarray : public _jobject {};
-class _jbooleanArray : public _jarray {};
-class _jbyteArray : public _jarray {};
-class _jcharArray : public _jarray {};
-class _jshortArray : public _jarray {};
-class _jintArray : public _jarray {};
-class _jlongArray : public _jarray {};
-class _jfloatArray : public _jarray {};
-class _jdoubleArray : public _jarray {};
-class _jobjectArray : public _jarray {};
-
-typedef _jobject *jobject;
-typedef _jclass *jclass;
-typedef _jthrowable *jthrowable;
-typedef _jstring *jstring;
-typedef _jarray *jarray;
-typedef _jbooleanArray *jbooleanArray;
-typedef _jbyteArray *jbyteArray;
-typedef _jcharArray *jcharArray;
-typedef _jshortArray *jshortArray;
-typedef _jintArray *jintArray;
-typedef _jlongArray *jlongArray;
-typedef _jfloatArray *jfloatArray;
-typedef _jdoubleArray *jdoubleArray;
-typedef _jobjectArray *jobjectArray;
-
-#else
-
-struct _jobject;
-
-typedef struct _jobject *jobject;
-typedef jobject jclass;
-typedef jobject jthrowable;
-typedef jobject jstring;
-typedef jobject jarray;
-typedef jarray jbooleanArray;
-typedef jarray jbyteArray;
-typedef jarray jcharArray;
-typedef jarray jshortArray;
-typedef jarray jintArray;
-typedef jarray jlongArray;
-typedef jarray jfloatArray;
-typedef jarray jdoubleArray;
-typedef jarray jobjectArray;
-
-#endif
-
-typedef jobject jweak;
-
-typedef union jvalue {
- jboolean z;
- jbyte b;
- jchar c;
- jshort s;
- jint i;
- jlong j;
- jfloat f;
- jdouble d;
- jobject l;
-} jvalue;
-
-struct _jfieldID;
-typedef struct _jfieldID *jfieldID;
-
-struct _jmethodID;
-typedef struct _jmethodID *jmethodID;
-
-/* Return values from jobjectRefType */
-typedef enum _jobjectType {
- JNIInvalidRefType = 0,
- JNILocalRefType = 1,
- JNIGlobalRefType = 2,
- JNIWeakGlobalRefType = 3
-} jobjectRefType;
-
-
-#endif /* JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H */
-
-/*
- * jboolean constants
- */
-
-#define JNI_FALSE 0
-#define JNI_TRUE 1
-
-/*
- * possible return values for JNI functions.
- */
-
-#define JNI_OK 0 /* success */
-#define JNI_ERR (-1) /* unknown error */
-#define JNI_EDETACHED (-2) /* thread detached from the VM */
-#define JNI_EVERSION (-3) /* JNI version error */
-#define JNI_ENOMEM (-4) /* not enough memory */
-#define JNI_EEXIST (-5) /* VM already created */
-#define JNI_EINVAL (-6) /* invalid arguments */
-
-/*
- * used in ReleaseScalarArrayElements
- */
-
-#define JNI_COMMIT 1
-#define JNI_ABORT 2
-
-/*
- * used in RegisterNatives to describe native method name, signature,
- * and function pointer.
- */
-
-typedef struct {
- char *name;
- char *signature;
- void *fnPtr;
-} JNINativeMethod;
-
-/*
- * JNI Native Method Interface.
- */
-
-struct JNINativeInterface_;
-
-struct JNIEnv_;
-
-#ifdef __cplusplus
-typedef JNIEnv_ JNIEnv;
-#else
-typedef const struct JNINativeInterface_ *JNIEnv;
-#endif
-
-/*
- * JNI Invocation Interface.
- */
-
-struct JNIInvokeInterface_;
-
-struct JavaVM_;
-
-#ifdef __cplusplus
-typedef JavaVM_ JavaVM;
-#else
-typedef const struct JNIInvokeInterface_ *JavaVM;
-#endif
-
-struct JNINativeInterface_ {
- void *reserved0;
- void *reserved1;
- void *reserved2;
-
- void *reserved3;
-
-#if !TARGET_RT_MAC_CFM && defined(__ppc__)
- void* cfm_vectors[225];
-#endif /* !TARGET_RT_MAC_CFM && defined(__ppc__) */
-
- jint (JNICALL *GetVersion)(JNIEnv *env);
-
- jclass (JNICALL *DefineClass)
- (JNIEnv *env, const char *name, jobject loader, const jbyte *buf,
- jsize len);
- jclass (JNICALL *FindClass)
- (JNIEnv *env, const char *name);
-
- jmethodID (JNICALL *FromReflectedMethod)
- (JNIEnv *env, jobject method);
- jfieldID (JNICALL *FromReflectedField)
- (JNIEnv *env, jobject field);
-
- jobject (JNICALL *ToReflectedMethod)
- (JNIEnv *env, jclass cls, jmethodID methodID, jboolean isStatic);
-
- jclass (JNICALL *GetSuperclass)
- (JNIEnv *env, jclass sub);
- jboolean (JNICALL *IsAssignableFrom)
- (JNIEnv *env, jclass sub, jclass sup);
-
- jobject (JNICALL *ToReflectedField)
- (JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic);
-
- jint (JNICALL *Throw)
- (JNIEnv *env, jthrowable obj);
- jint (JNICALL *ThrowNew)
- (JNIEnv *env, jclass clazz, const char *msg);
- jthrowable (JNICALL *ExceptionOccurred)
- (JNIEnv *env);
- void (JNICALL *ExceptionDescribe)
- (JNIEnv *env);
- void (JNICALL *ExceptionClear)
- (JNIEnv *env);
- void (JNICALL *FatalError)
- (JNIEnv *env, const char *msg);
-
- jint (JNICALL *PushLocalFrame)
- (JNIEnv *env, jint capacity);
- jobject (JNICALL *PopLocalFrame)
- (JNIEnv *env, jobject result);
-
- jobject (JNICALL *NewGlobalRef)
- (JNIEnv *env, jobject lobj);
- void (JNICALL *DeleteGlobalRef)
- (JNIEnv *env, jobject gref);
- void (JNICALL *DeleteLocalRef)
- (JNIEnv *env, jobject obj);
- jboolean (JNICALL *IsSameObject)
- (JNIEnv *env, jobject obj1, jobject obj2);
- jobject (JNICALL *NewLocalRef)
- (JNIEnv *env, jobject ref);
- jint (JNICALL *EnsureLocalCapacity)
- (JNIEnv *env, jint capacity);
-
- jobject (JNICALL *AllocObject)
- (JNIEnv *env, jclass clazz);
- jobject (JNICALL *NewObject)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jobject (JNICALL *NewObjectV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jobject (JNICALL *NewObjectA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jclass (JNICALL *GetObjectClass)
- (JNIEnv *env, jobject obj);
- jboolean (JNICALL *IsInstanceOf)
- (JNIEnv *env, jobject obj, jclass clazz);
-
- jmethodID (JNICALL *GetMethodID)
- (JNIEnv *env, jclass clazz, const char *name, const char *sig);
-
- jobject (JNICALL *CallObjectMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jobject (JNICALL *CallObjectMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jobject (JNICALL *CallObjectMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue * args);
-
- jboolean (JNICALL *CallBooleanMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jboolean (JNICALL *CallBooleanMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jboolean (JNICALL *CallBooleanMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue * args);
-
- jbyte (JNICALL *CallByteMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jbyte (JNICALL *CallByteMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jbyte (JNICALL *CallByteMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- jchar (JNICALL *CallCharMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jchar (JNICALL *CallCharMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jchar (JNICALL *CallCharMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- jshort (JNICALL *CallShortMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jshort (JNICALL *CallShortMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jshort (JNICALL *CallShortMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- jint (JNICALL *CallIntMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jint (JNICALL *CallIntMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jint (JNICALL *CallIntMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- jlong (JNICALL *CallLongMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jlong (JNICALL *CallLongMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jlong (JNICALL *CallLongMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- jfloat (JNICALL *CallFloatMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jfloat (JNICALL *CallFloatMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jfloat (JNICALL *CallFloatMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- jdouble (JNICALL *CallDoubleMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jdouble (JNICALL *CallDoubleMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jdouble (JNICALL *CallDoubleMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- void (JNICALL *CallVoidMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- void (JNICALL *CallVoidMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- void (JNICALL *CallVoidMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue * args);
-
- jobject (JNICALL *CallNonvirtualObjectMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jobject (JNICALL *CallNonvirtualObjectMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jobject (JNICALL *CallNonvirtualObjectMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue * args);
-
- jboolean (JNICALL *CallNonvirtualBooleanMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jboolean (JNICALL *CallNonvirtualBooleanMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jboolean (JNICALL *CallNonvirtualBooleanMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue * args);
-
- jbyte (JNICALL *CallNonvirtualByteMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jbyte (JNICALL *CallNonvirtualByteMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jbyte (JNICALL *CallNonvirtualByteMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- jchar (JNICALL *CallNonvirtualCharMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jchar (JNICALL *CallNonvirtualCharMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jchar (JNICALL *CallNonvirtualCharMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- jshort (JNICALL *CallNonvirtualShortMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jshort (JNICALL *CallNonvirtualShortMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jshort (JNICALL *CallNonvirtualShortMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- jint (JNICALL *CallNonvirtualIntMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jint (JNICALL *CallNonvirtualIntMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jint (JNICALL *CallNonvirtualIntMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- jlong (JNICALL *CallNonvirtualLongMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jlong (JNICALL *CallNonvirtualLongMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jlong (JNICALL *CallNonvirtualLongMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- jfloat (JNICALL *CallNonvirtualFloatMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jfloat (JNICALL *CallNonvirtualFloatMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jfloat (JNICALL *CallNonvirtualFloatMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- jdouble (JNICALL *CallNonvirtualDoubleMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jdouble (JNICALL *CallNonvirtualDoubleMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jdouble (JNICALL *CallNonvirtualDoubleMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- void (JNICALL *CallNonvirtualVoidMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- void (JNICALL *CallNonvirtualVoidMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- void (JNICALL *CallNonvirtualVoidMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue * args);
-
- jfieldID (JNICALL *GetFieldID)
- (JNIEnv *env, jclass clazz, const char *name, const char *sig);
-
- jobject (JNICALL *GetObjectField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jboolean (JNICALL *GetBooleanField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jbyte (JNICALL *GetByteField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jchar (JNICALL *GetCharField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jshort (JNICALL *GetShortField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jint (JNICALL *GetIntField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jlong (JNICALL *GetLongField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jfloat (JNICALL *GetFloatField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jdouble (JNICALL *GetDoubleField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
-
- void (JNICALL *SetObjectField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jobject val);
- void (JNICALL *SetBooleanField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jboolean val);
- void (JNICALL *SetByteField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jbyte val);
- void (JNICALL *SetCharField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jchar val);
- void (JNICALL *SetShortField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jshort val);
- void (JNICALL *SetIntField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jint val);
- void (JNICALL *SetLongField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jlong val);
- void (JNICALL *SetFloatField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jfloat val);
- void (JNICALL *SetDoubleField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jdouble val);
-
- jmethodID (JNICALL *GetStaticMethodID)
- (JNIEnv *env, jclass clazz, const char *name, const char *sig);
-
- jobject (JNICALL *CallStaticObjectMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jobject (JNICALL *CallStaticObjectMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jobject (JNICALL *CallStaticObjectMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jboolean (JNICALL *CallStaticBooleanMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jboolean (JNICALL *CallStaticBooleanMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jboolean (JNICALL *CallStaticBooleanMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jbyte (JNICALL *CallStaticByteMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jbyte (JNICALL *CallStaticByteMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jbyte (JNICALL *CallStaticByteMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jchar (JNICALL *CallStaticCharMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jchar (JNICALL *CallStaticCharMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jchar (JNICALL *CallStaticCharMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jshort (JNICALL *CallStaticShortMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jshort (JNICALL *CallStaticShortMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jshort (JNICALL *CallStaticShortMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jint (JNICALL *CallStaticIntMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jint (JNICALL *CallStaticIntMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jint (JNICALL *CallStaticIntMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jlong (JNICALL *CallStaticLongMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jlong (JNICALL *CallStaticLongMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jlong (JNICALL *CallStaticLongMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jfloat (JNICALL *CallStaticFloatMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jfloat (JNICALL *CallStaticFloatMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jfloat (JNICALL *CallStaticFloatMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jdouble (JNICALL *CallStaticDoubleMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jdouble (JNICALL *CallStaticDoubleMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jdouble (JNICALL *CallStaticDoubleMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- void (JNICALL *CallStaticVoidMethod)
- (JNIEnv *env, jclass cls, jmethodID methodID, ...);
- void (JNICALL *CallStaticVoidMethodV)
- (JNIEnv *env, jclass cls, jmethodID methodID, va_list args);
- void (JNICALL *CallStaticVoidMethodA)
- (JNIEnv *env, jclass cls, jmethodID methodID, const jvalue * args);
-
- jfieldID (JNICALL *GetStaticFieldID)
- (JNIEnv *env, jclass clazz, const char *name, const char *sig);
- jobject (JNICALL *GetStaticObjectField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jboolean (JNICALL *GetStaticBooleanField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jbyte (JNICALL *GetStaticByteField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jchar (JNICALL *GetStaticCharField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jshort (JNICALL *GetStaticShortField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jint (JNICALL *GetStaticIntField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jlong (JNICALL *GetStaticLongField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jfloat (JNICALL *GetStaticFloatField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jdouble (JNICALL *GetStaticDoubleField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
-
- void (JNICALL *SetStaticObjectField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value);
- void (JNICALL *SetStaticBooleanField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value);
- void (JNICALL *SetStaticByteField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value);
- void (JNICALL *SetStaticCharField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value);
- void (JNICALL *SetStaticShortField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value);
- void (JNICALL *SetStaticIntField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jint value);
- void (JNICALL *SetStaticLongField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value);
- void (JNICALL *SetStaticFloatField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value);
- void (JNICALL *SetStaticDoubleField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value);
-
- jstring (JNICALL *NewString)
- (JNIEnv *env, const jchar *unicode, jsize len);
- jsize (JNICALL *GetStringLength)
- (JNIEnv *env, jstring str);
- const jchar *(JNICALL *GetStringChars)
- (JNIEnv *env, jstring str, jboolean *isCopy);
- void (JNICALL *ReleaseStringChars)
- (JNIEnv *env, jstring str, const jchar *chars);
-
- jstring (JNICALL *NewStringUTF)
- (JNIEnv *env, const char *utf);
- jsize (JNICALL *GetStringUTFLength)
- (JNIEnv *env, jstring str);
- const char* (JNICALL *GetStringUTFChars)
- (JNIEnv *env, jstring str, jboolean *isCopy);
- void (JNICALL *ReleaseStringUTFChars)
- (JNIEnv *env, jstring str, const char* chars);
-
-
- jsize (JNICALL *GetArrayLength)
- (JNIEnv *env, jarray array);
-
- jobjectArray (JNICALL *NewObjectArray)
- (JNIEnv *env, jsize len, jclass clazz, jobject init);
- jobject (JNICALL *GetObjectArrayElement)
- (JNIEnv *env, jobjectArray array, jsize index);
- void (JNICALL *SetObjectArrayElement)
- (JNIEnv *env, jobjectArray array, jsize index, jobject val);
-
- jbooleanArray (JNICALL *NewBooleanArray)
- (JNIEnv *env, jsize len);
- jbyteArray (JNICALL *NewByteArray)
- (JNIEnv *env, jsize len);
- jcharArray (JNICALL *NewCharArray)
- (JNIEnv *env, jsize len);
- jshortArray (JNICALL *NewShortArray)
- (JNIEnv *env, jsize len);
- jintArray (JNICALL *NewIntArray)
- (JNIEnv *env, jsize len);
- jlongArray (JNICALL *NewLongArray)
- (JNIEnv *env, jsize len);
- jfloatArray (JNICALL *NewFloatArray)
- (JNIEnv *env, jsize len);
- jdoubleArray (JNICALL *NewDoubleArray)
- (JNIEnv *env, jsize len);
-
- jboolean * (JNICALL *GetBooleanArrayElements)
- (JNIEnv *env, jbooleanArray array, jboolean *isCopy);
- jbyte * (JNICALL *GetByteArrayElements)
- (JNIEnv *env, jbyteArray array, jboolean *isCopy);
- jchar * (JNICALL *GetCharArrayElements)
- (JNIEnv *env, jcharArray array, jboolean *isCopy);
- jshort * (JNICALL *GetShortArrayElements)
- (JNIEnv *env, jshortArray array, jboolean *isCopy);
- jint * (JNICALL *GetIntArrayElements)
- (JNIEnv *env, jintArray array, jboolean *isCopy);
- jlong * (JNICALL *GetLongArrayElements)
- (JNIEnv *env, jlongArray array, jboolean *isCopy);
- jfloat * (JNICALL *GetFloatArrayElements)
- (JNIEnv *env, jfloatArray array, jboolean *isCopy);
- jdouble * (JNICALL *GetDoubleArrayElements)
- (JNIEnv *env, jdoubleArray array, jboolean *isCopy);
-
- void (JNICALL *ReleaseBooleanArrayElements)
- (JNIEnv *env, jbooleanArray array, jboolean *elems, jint mode);
- void (JNICALL *ReleaseByteArrayElements)
- (JNIEnv *env, jbyteArray array, jbyte *elems, jint mode);
- void (JNICALL *ReleaseCharArrayElements)
- (JNIEnv *env, jcharArray array, jchar *elems, jint mode);
- void (JNICALL *ReleaseShortArrayElements)
- (JNIEnv *env, jshortArray array, jshort *elems, jint mode);
- void (JNICALL *ReleaseIntArrayElements)
- (JNIEnv *env, jintArray array, jint *elems, jint mode);
- void (JNICALL *ReleaseLongArrayElements)
- (JNIEnv *env, jlongArray array, jlong *elems, jint mode);
- void (JNICALL *ReleaseFloatArrayElements)
- (JNIEnv *env, jfloatArray array, jfloat *elems, jint mode);
- void (JNICALL *ReleaseDoubleArrayElements)
- (JNIEnv *env, jdoubleArray array, jdouble *elems, jint mode);
-
- void (JNICALL *GetBooleanArrayRegion)
- (JNIEnv *env, jbooleanArray array, jsize start, jsize l, jboolean *buf);
- void (JNICALL *GetByteArrayRegion)
- (JNIEnv *env, jbyteArray array, jsize start, jsize len, jbyte *buf);
- void (JNICALL *GetCharArrayRegion)
- (JNIEnv *env, jcharArray array, jsize start, jsize len, jchar *buf);
- void (JNICALL *GetShortArrayRegion)
- (JNIEnv *env, jshortArray array, jsize start, jsize len, jshort *buf);
- void (JNICALL *GetIntArrayRegion)
- (JNIEnv *env, jintArray array, jsize start, jsize len, jint *buf);
- void (JNICALL *GetLongArrayRegion)
- (JNIEnv *env, jlongArray array, jsize start, jsize len, jlong *buf);
- void (JNICALL *GetFloatArrayRegion)
- (JNIEnv *env, jfloatArray array, jsize start, jsize len, jfloat *buf);
- void (JNICALL *GetDoubleArrayRegion)
- (JNIEnv *env, jdoubleArray array, jsize start, jsize len, jdouble *buf);
-
- void (JNICALL *SetBooleanArrayRegion)
- (JNIEnv *env, jbooleanArray array, jsize start, jsize l, const jboolean *buf);
- void (JNICALL *SetByteArrayRegion)
- (JNIEnv *env, jbyteArray array, jsize start, jsize len, const jbyte *buf);
- void (JNICALL *SetCharArrayRegion)
- (JNIEnv *env, jcharArray array, jsize start, jsize len, const jchar *buf);
- void (JNICALL *SetShortArrayRegion)
- (JNIEnv *env, jshortArray array, jsize start, jsize len, const jshort *buf);
- void (JNICALL *SetIntArrayRegion)
- (JNIEnv *env, jintArray array, jsize start, jsize len, const jint *buf);
- void (JNICALL *SetLongArrayRegion)
- (JNIEnv *env, jlongArray array, jsize start, jsize len, const jlong *buf);
- void (JNICALL *SetFloatArrayRegion)
- (JNIEnv *env, jfloatArray array, jsize start, jsize len, const jfloat *buf);
- void (JNICALL *SetDoubleArrayRegion)
- (JNIEnv *env, jdoubleArray array, jsize start, jsize len, const jdouble *buf);
-
- jint (JNICALL *RegisterNatives)
- (JNIEnv *env, jclass clazz, const JNINativeMethod *methods,
- jint nMethods);
- jint (JNICALL *UnregisterNatives)
- (JNIEnv *env, jclass clazz);
-
- jint (JNICALL *MonitorEnter)
- (JNIEnv *env, jobject obj);
- jint (JNICALL *MonitorExit)
- (JNIEnv *env, jobject obj);
-
- jint (JNICALL *GetJavaVM)
- (JNIEnv *env, JavaVM **vm);
-
- void (JNICALL *GetStringRegion)
- (JNIEnv *env, jstring str, jsize start, jsize len, jchar *buf);
- void (JNICALL *GetStringUTFRegion)
- (JNIEnv *env, jstring str, jsize start, jsize len, char *buf);
-
- void * (JNICALL *GetPrimitiveArrayCritical)
- (JNIEnv *env, jarray array, jboolean *isCopy);
- void (JNICALL *ReleasePrimitiveArrayCritical)
- (JNIEnv *env, jarray array, void *carray, jint mode);
-
- const jchar * (JNICALL *GetStringCritical)
- (JNIEnv *env, jstring string, jboolean *isCopy);
- void (JNICALL *ReleaseStringCritical)
- (JNIEnv *env, jstring string, const jchar *cstring);
-
- jweak (JNICALL *NewWeakGlobalRef)
- (JNIEnv *env, jobject obj);
- void (JNICALL *DeleteWeakGlobalRef)
- (JNIEnv *env, jweak ref);
-
- jboolean (JNICALL *ExceptionCheck)
- (JNIEnv *env);
-
- jobject (JNICALL *NewDirectByteBuffer)
- (JNIEnv* env, void* address, jlong capacity);
- void* (JNICALL *GetDirectBufferAddress)
- (JNIEnv* env, jobject buf);
- jlong (JNICALL *GetDirectBufferCapacity)
- (JNIEnv* env, jobject buf);
-
- /* New JNI 1.6 Features */
-
- jobjectRefType (JNICALL *GetObjectRefType)
- (JNIEnv* env, jobject obj);
-
- #if TARGET_RT_MAC_CFM && defined(__ppc__)
- void* real_functions[228];
- #endif /* TARGET_RT_MAC_CFM && defined(__ppc__) */
-};
-
-/*
- * We use inlined functions for C++ so that programmers can write:
- *
- * env->FindClass("java/lang/String")
- *
- * in C++ rather than:
- *
- * (*env)->FindClass(env, "java/lang/String")
- *
- * in C.
- */
-
-struct JNIEnv_ {
- const struct JNINativeInterface_ *functions;
-#ifdef __cplusplus
-
- jint GetVersion() {
- return functions->GetVersion(this);
- }
- jclass DefineClass(const char *name, jobject loader, const jbyte *buf,
- jsize len) {
- return functions->DefineClass(this, name, loader, buf, len);
- }
- jclass FindClass(const char *name) {
- return functions->FindClass(this, name);
- }
- jmethodID FromReflectedMethod(jobject method) {
- return functions->FromReflectedMethod(this,method);
- }
- jfieldID FromReflectedField(jobject field) {
- return functions->FromReflectedField(this,field);
- }
-
- jobject ToReflectedMethod(jclass cls, jmethodID methodID, jboolean isStatic) {
- return functions->ToReflectedMethod(this, cls, methodID, isStatic);
- }
-
- jclass GetSuperclass(jclass sub) {
- return functions->GetSuperclass(this, sub);
- }
- jboolean IsAssignableFrom(jclass sub, jclass sup) {
- return functions->IsAssignableFrom(this, sub, sup);
- }
-
- jobject ToReflectedField(jclass cls, jfieldID fieldID, jboolean isStatic) {
- return functions->ToReflectedField(this,cls,fieldID,isStatic);
- }
-
- jint Throw(jthrowable obj) {
- return functions->Throw(this, obj);
- }
- jint ThrowNew(jclass clazz, const char *msg) {
- return functions->ThrowNew(this, clazz, msg);
- }
- jthrowable ExceptionOccurred() {
- return functions->ExceptionOccurred(this);
- }
- void ExceptionDescribe() {
- functions->ExceptionDescribe(this);
- }
- void ExceptionClear() {
- functions->ExceptionClear(this);
- }
- void FatalError(const char *msg) {
- functions->FatalError(this, msg);
- }
-
- jint PushLocalFrame(jint capacity) {
- return functions->PushLocalFrame(this,capacity);
- }
- jobject PopLocalFrame(jobject result) {
- return functions->PopLocalFrame(this,result);
- }
-
- jobject NewGlobalRef(jobject lobj) {
- return functions->NewGlobalRef(this,lobj);
- }
- void DeleteGlobalRef(jobject gref) {
- functions->DeleteGlobalRef(this,gref);
- }
- void DeleteLocalRef(jobject obj) {
- functions->DeleteLocalRef(this, obj);
- }
-
- jboolean IsSameObject(jobject obj1, jobject obj2) {
- return functions->IsSameObject(this,obj1,obj2);
- }
-
- jobject NewLocalRef(jobject ref) {
- return functions->NewLocalRef(this,ref);
- }
- jint EnsureLocalCapacity(jint capacity) {
- return functions->EnsureLocalCapacity(this,capacity);
- }
-
- jobject AllocObject(jclass clazz) {
- return functions->AllocObject(this,clazz);
- }
- jobject NewObject(jclass clazz, jmethodID methodID, ...) {
- va_list args;
- jobject result;
- va_start(args, methodID);
- result = functions->NewObjectV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jobject NewObjectV(jclass clazz, jmethodID methodID,
- va_list args) {
- return functions->NewObjectV(this,clazz,methodID,args);
- }
- jobject NewObjectA(jclass clazz, jmethodID methodID,
- const jvalue *args) {
- return functions->NewObjectA(this,clazz,methodID,args);
- }
-
- jclass GetObjectClass(jobject obj) {
- return functions->GetObjectClass(this,obj);
- }
- jboolean IsInstanceOf(jobject obj, jclass clazz) {
- return functions->IsInstanceOf(this,obj,clazz);
- }
-
- jmethodID GetMethodID(jclass clazz, const char *name,
- const char *sig) {
- return functions->GetMethodID(this,clazz,name,sig);
- }
-
- jobject CallObjectMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jobject result;
- va_start(args,methodID);
- result = functions->CallObjectMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jobject CallObjectMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallObjectMethodV(this,obj,methodID,args);
- }
- jobject CallObjectMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallObjectMethodA(this,obj,methodID,args);
- }
-
- jboolean CallBooleanMethod(jobject obj,
- jmethodID methodID, ...) {
- va_list args;
- jboolean result;
- va_start(args,methodID);
- result = functions->CallBooleanMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jboolean CallBooleanMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallBooleanMethodV(this,obj,methodID,args);
- }
- jboolean CallBooleanMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallBooleanMethodA(this,obj,methodID, args);
- }
-
- jbyte CallByteMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jbyte result;
- va_start(args,methodID);
- result = functions->CallByteMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jbyte CallByteMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallByteMethodV(this,obj,methodID,args);
- }
- jbyte CallByteMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallByteMethodA(this,obj,methodID,args);
- }
-
- jchar CallCharMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jchar result;
- va_start(args,methodID);
- result = functions->CallCharMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jchar CallCharMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallCharMethodV(this,obj,methodID,args);
- }
- jchar CallCharMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallCharMethodA(this,obj,methodID,args);
- }
-
- jshort CallShortMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jshort result;
- va_start(args,methodID);
- result = functions->CallShortMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jshort CallShortMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallShortMethodV(this,obj,methodID,args);
- }
- jshort CallShortMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallShortMethodA(this,obj,methodID,args);
- }
-
- jint CallIntMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jint result;
- va_start(args,methodID);
- result = functions->CallIntMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jint CallIntMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallIntMethodV(this,obj,methodID,args);
- }
- jint CallIntMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallIntMethodA(this,obj,methodID,args);
- }
-
- jlong CallLongMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jlong result;
- va_start(args,methodID);
- result = functions->CallLongMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jlong CallLongMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallLongMethodV(this,obj,methodID,args);
- }
- jlong CallLongMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallLongMethodA(this,obj,methodID,args);
- }
-
- jfloat CallFloatMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jfloat result;
- va_start(args,methodID);
- result = functions->CallFloatMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jfloat CallFloatMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallFloatMethodV(this,obj,methodID,args);
- }
- jfloat CallFloatMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallFloatMethodA(this,obj,methodID,args);
- }
-
- jdouble CallDoubleMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jdouble result;
- va_start(args,methodID);
- result = functions->CallDoubleMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jdouble CallDoubleMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallDoubleMethodV(this,obj,methodID,args);
- }
- jdouble CallDoubleMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallDoubleMethodA(this,obj,methodID,args);
- }
-
- void CallVoidMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- va_start(args,methodID);
- functions->CallVoidMethodV(this,obj,methodID,args);
- va_end(args);
- }
- void CallVoidMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- functions->CallVoidMethodV(this,obj,methodID,args);
- }
- void CallVoidMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- functions->CallVoidMethodA(this,obj,methodID,args);
- }
-
- jobject CallNonvirtualObjectMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jobject result;
- va_start(args,methodID);
- result = functions->CallNonvirtualObjectMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jobject CallNonvirtualObjectMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualObjectMethodV(this,obj,clazz,
- methodID,args);
- }
- jobject CallNonvirtualObjectMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualObjectMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jboolean CallNonvirtualBooleanMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jboolean result;
- va_start(args,methodID);
- result = functions->CallNonvirtualBooleanMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jboolean CallNonvirtualBooleanMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualBooleanMethodV(this,obj,clazz,
- methodID,args);
- }
- jboolean CallNonvirtualBooleanMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualBooleanMethodA(this,obj,clazz,
- methodID, args);
- }
-
- jbyte CallNonvirtualByteMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jbyte result;
- va_start(args,methodID);
- result = functions->CallNonvirtualByteMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jbyte CallNonvirtualByteMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualByteMethodV(this,obj,clazz,
- methodID,args);
- }
- jbyte CallNonvirtualByteMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualByteMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jchar CallNonvirtualCharMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jchar result;
- va_start(args,methodID);
- result = functions->CallNonvirtualCharMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jchar CallNonvirtualCharMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualCharMethodV(this,obj,clazz,
- methodID,args);
- }
- jchar CallNonvirtualCharMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualCharMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jshort CallNonvirtualShortMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jshort result;
- va_start(args,methodID);
- result = functions->CallNonvirtualShortMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jshort CallNonvirtualShortMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualShortMethodV(this,obj,clazz,
- methodID,args);
- }
- jshort CallNonvirtualShortMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualShortMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jint CallNonvirtualIntMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jint result;
- va_start(args,methodID);
- result = functions->CallNonvirtualIntMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jint CallNonvirtualIntMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualIntMethodV(this,obj,clazz,
- methodID,args);
- }
- jint CallNonvirtualIntMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualIntMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jlong CallNonvirtualLongMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jlong result;
- va_start(args,methodID);
- result = functions->CallNonvirtualLongMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jlong CallNonvirtualLongMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualLongMethodV(this,obj,clazz,
- methodID,args);
- }
- jlong CallNonvirtualLongMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualLongMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jfloat CallNonvirtualFloatMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jfloat result;
- va_start(args,methodID);
- result = functions->CallNonvirtualFloatMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jfloat CallNonvirtualFloatMethodV(jobject obj, jclass clazz,
- jmethodID methodID,
- va_list args) {
- return functions->CallNonvirtualFloatMethodV(this,obj,clazz,
- methodID,args);
- }
- jfloat CallNonvirtualFloatMethodA(jobject obj, jclass clazz,
- jmethodID methodID,
- const jvalue * args) {
- return functions->CallNonvirtualFloatMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jdouble CallNonvirtualDoubleMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jdouble result;
- va_start(args,methodID);
- result = functions->CallNonvirtualDoubleMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jdouble CallNonvirtualDoubleMethodV(jobject obj, jclass clazz,
- jmethodID methodID,
- va_list args) {
- return functions->CallNonvirtualDoubleMethodV(this,obj,clazz,
- methodID,args);
- }
- jdouble CallNonvirtualDoubleMethodA(jobject obj, jclass clazz,
- jmethodID methodID,
- const jvalue * args) {
- return functions->CallNonvirtualDoubleMethodA(this,obj,clazz,
- methodID,args);
- }
-
- void CallNonvirtualVoidMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- va_start(args,methodID);
- functions->CallNonvirtualVoidMethodV(this,obj,clazz,methodID,args);
- va_end(args);
- }
- void CallNonvirtualVoidMethodV(jobject obj, jclass clazz,
- jmethodID methodID,
- va_list args) {
- functions->CallNonvirtualVoidMethodV(this,obj,clazz,methodID,args);
- }
- void CallNonvirtualVoidMethodA(jobject obj, jclass clazz,
- jmethodID methodID,
- const jvalue * args) {
- functions->CallNonvirtualVoidMethodA(this,obj,clazz,methodID,args);
- }
-
- jfieldID GetFieldID(jclass clazz, const char *name,
- const char *sig) {
- return functions->GetFieldID(this,clazz,name,sig);
- }
-
- jobject GetObjectField(jobject obj, jfieldID fieldID) {
- return functions->GetObjectField(this,obj,fieldID);
- }
- jboolean GetBooleanField(jobject obj, jfieldID fieldID) {
- return functions->GetBooleanField(this,obj,fieldID);
- }
- jbyte GetByteField(jobject obj, jfieldID fieldID) {
- return functions->GetByteField(this,obj,fieldID);
- }
- jchar GetCharField(jobject obj, jfieldID fieldID) {
- return functions->GetCharField(this,obj,fieldID);
- }
- jshort GetShortField(jobject obj, jfieldID fieldID) {
- return functions->GetShortField(this,obj,fieldID);
- }
- jint GetIntField(jobject obj, jfieldID fieldID) {
- return functions->GetIntField(this,obj,fieldID);
- }
- jlong GetLongField(jobject obj, jfieldID fieldID) {
- return functions->GetLongField(this,obj,fieldID);
- }
- jfloat GetFloatField(jobject obj, jfieldID fieldID) {
- return functions->GetFloatField(this,obj,fieldID);
- }
- jdouble GetDoubleField(jobject obj, jfieldID fieldID) {
- return functions->GetDoubleField(this,obj,fieldID);
- }
-
- void SetObjectField(jobject obj, jfieldID fieldID, jobject val) {
- functions->SetObjectField(this,obj,fieldID,val);
- }
- void SetBooleanField(jobject obj, jfieldID fieldID,
- jboolean val) {
- functions->SetBooleanField(this,obj,fieldID,val);
- }
- void SetByteField(jobject obj, jfieldID fieldID,
- jbyte val) {
- functions->SetByteField(this,obj,fieldID,val);
- }
- void SetCharField(jobject obj, jfieldID fieldID,
- jchar val) {
- functions->SetCharField(this,obj,fieldID,val);
- }
- void SetShortField(jobject obj, jfieldID fieldID,
- jshort val) {
- functions->SetShortField(this,obj,fieldID,val);
- }
- void SetIntField(jobject obj, jfieldID fieldID,
- jint val) {
- functions->SetIntField(this,obj,fieldID,val);
- }
- void SetLongField(jobject obj, jfieldID fieldID,
- jlong val) {
- functions->SetLongField(this,obj,fieldID,val);
- }
- void SetFloatField(jobject obj, jfieldID fieldID,
- jfloat val) {
- functions->SetFloatField(this,obj,fieldID,val);
- }
- void SetDoubleField(jobject obj, jfieldID fieldID,
- jdouble val) {
- functions->SetDoubleField(this,obj,fieldID,val);
- }
-
- jmethodID GetStaticMethodID(jclass clazz, const char *name,
- const char *sig) {
- return functions->GetStaticMethodID(this,clazz,name,sig);
- }
-
- jobject CallStaticObjectMethod(jclass clazz, jmethodID methodID,
- ...) {
- va_list args;
- jobject result;
- va_start(args,methodID);
- result = functions->CallStaticObjectMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jobject CallStaticObjectMethodV(jclass clazz, jmethodID methodID,
- va_list args) {
- return functions->CallStaticObjectMethodV(this,clazz,methodID,args);
- }
- jobject CallStaticObjectMethodA(jclass clazz, jmethodID methodID,
- const jvalue *args) {
- return functions->CallStaticObjectMethodA(this,clazz,methodID,args);
- }
-
- jboolean CallStaticBooleanMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jboolean result;
- va_start(args,methodID);
- result = functions->CallStaticBooleanMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jboolean CallStaticBooleanMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticBooleanMethodV(this,clazz,methodID,args);
- }
- jboolean CallStaticBooleanMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticBooleanMethodA(this,clazz,methodID,args);
- }
-
- jbyte CallStaticByteMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jbyte result;
- va_start(args,methodID);
- result = functions->CallStaticByteMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jbyte CallStaticByteMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticByteMethodV(this,clazz,methodID,args);
- }
- jbyte CallStaticByteMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticByteMethodA(this,clazz,methodID,args);
- }
-
- jchar CallStaticCharMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jchar result;
- va_start(args,methodID);
- result = functions->CallStaticCharMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jchar CallStaticCharMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticCharMethodV(this,clazz,methodID,args);
- }
- jchar CallStaticCharMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticCharMethodA(this,clazz,methodID,args);
- }
-
- jshort CallStaticShortMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jshort result;
- va_start(args,methodID);
- result = functions->CallStaticShortMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jshort CallStaticShortMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticShortMethodV(this,clazz,methodID,args);
- }
- jshort CallStaticShortMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticShortMethodA(this,clazz,methodID,args);
- }
-
- jint CallStaticIntMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jint result;
- va_start(args,methodID);
- result = functions->CallStaticIntMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jint CallStaticIntMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticIntMethodV(this,clazz,methodID,args);
- }
- jint CallStaticIntMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticIntMethodA(this,clazz,methodID,args);
- }
-
- jlong CallStaticLongMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jlong result;
- va_start(args,methodID);
- result = functions->CallStaticLongMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jlong CallStaticLongMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticLongMethodV(this,clazz,methodID,args);
- }
- jlong CallStaticLongMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticLongMethodA(this,clazz,methodID,args);
- }
-
- jfloat CallStaticFloatMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jfloat result;
- va_start(args,methodID);
- result = functions->CallStaticFloatMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jfloat CallStaticFloatMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticFloatMethodV(this,clazz,methodID,args);
- }
- jfloat CallStaticFloatMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticFloatMethodA(this,clazz,methodID,args);
- }
-
- jdouble CallStaticDoubleMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jdouble result;
- va_start(args,methodID);
- result = functions->CallStaticDoubleMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jdouble CallStaticDoubleMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticDoubleMethodV(this,clazz,methodID,args);
- }
- jdouble CallStaticDoubleMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticDoubleMethodA(this,clazz,methodID,args);
- }
-
- void CallStaticVoidMethod(jclass cls, jmethodID methodID, ...) {
- va_list args;
- va_start(args,methodID);
- functions->CallStaticVoidMethodV(this,cls,methodID,args);
- va_end(args);
- }
- void CallStaticVoidMethodV(jclass cls, jmethodID methodID,
- va_list args) {
- functions->CallStaticVoidMethodV(this,cls,methodID,args);
- }
- void CallStaticVoidMethodA(jclass cls, jmethodID methodID,
- const jvalue * args) {
- functions->CallStaticVoidMethodA(this,cls,methodID,args);
- }
-
- jfieldID GetStaticFieldID(jclass clazz, const char *name,
- const char *sig) {
- return functions->GetStaticFieldID(this,clazz,name,sig);
- }
- jobject GetStaticObjectField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticObjectField(this,clazz,fieldID);
- }
- jboolean GetStaticBooleanField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticBooleanField(this,clazz,fieldID);
- }
- jbyte GetStaticByteField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticByteField(this,clazz,fieldID);
- }
- jchar GetStaticCharField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticCharField(this,clazz,fieldID);
- }
- jshort GetStaticShortField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticShortField(this,clazz,fieldID);
- }
- jint GetStaticIntField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticIntField(this,clazz,fieldID);
- }
- jlong GetStaticLongField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticLongField(this,clazz,fieldID);
- }
- jfloat GetStaticFloatField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticFloatField(this,clazz,fieldID);
- }
- jdouble GetStaticDoubleField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticDoubleField(this,clazz,fieldID);
- }
-
- void SetStaticObjectField(jclass clazz, jfieldID fieldID,
- jobject value) {
- functions->SetStaticObjectField(this,clazz,fieldID,value);
- }
- void SetStaticBooleanField(jclass clazz, jfieldID fieldID,
- jboolean value) {
- functions->SetStaticBooleanField(this,clazz,fieldID,value);
- }
- void SetStaticByteField(jclass clazz, jfieldID fieldID,
- jbyte value) {
- functions->SetStaticByteField(this,clazz,fieldID,value);
- }
- void SetStaticCharField(jclass clazz, jfieldID fieldID,
- jchar value) {
- functions->SetStaticCharField(this,clazz,fieldID,value);
- }
- void SetStaticShortField(jclass clazz, jfieldID fieldID,
- jshort value) {
- functions->SetStaticShortField(this,clazz,fieldID,value);
- }
- void SetStaticIntField(jclass clazz, jfieldID fieldID,
- jint value) {
- functions->SetStaticIntField(this,clazz,fieldID,value);
- }
- void SetStaticLongField(jclass clazz, jfieldID fieldID,
- jlong value) {
- functions->SetStaticLongField(this,clazz,fieldID,value);
- }
- void SetStaticFloatField(jclass clazz, jfieldID fieldID,
- jfloat value) {
- functions->SetStaticFloatField(this,clazz,fieldID,value);
- }
- void SetStaticDoubleField(jclass clazz, jfieldID fieldID,
- jdouble value) {
- functions->SetStaticDoubleField(this,clazz,fieldID,value);
- }
-
- jstring NewString(const jchar *unicode, jsize len) {
- return functions->NewString(this,unicode,len);
- }
- jsize GetStringLength(jstring str) {
- return functions->GetStringLength(this,str);
- }
- const jchar *GetStringChars(jstring str, jboolean *isCopy) {
- return functions->GetStringChars(this,str,isCopy);
- }
- void ReleaseStringChars(jstring str, const jchar *chars) {
- functions->ReleaseStringChars(this,str,chars);
- }
-
- jstring NewStringUTF(const char *utf) {
- return functions->NewStringUTF(this,utf);
- }
- jsize GetStringUTFLength(jstring str) {
- return functions->GetStringUTFLength(this,str);
- }
- const char* GetStringUTFChars(jstring str, jboolean *isCopy) {
- return functions->GetStringUTFChars(this,str,isCopy);
- }
- void ReleaseStringUTFChars(jstring str, const char* chars) {
- functions->ReleaseStringUTFChars(this,str,chars);
- }
-
- jsize GetArrayLength(jarray array) {
- return functions->GetArrayLength(this,array);
- }
-
- jobjectArray NewObjectArray(jsize len, jclass clazz,
- jobject init) {
- return functions->NewObjectArray(this,len,clazz,init);
- }
- jobject GetObjectArrayElement(jobjectArray array, jsize index) {
- return functions->GetObjectArrayElement(this,array,index);
- }
- void SetObjectArrayElement(jobjectArray array, jsize index,
- jobject val) {
- functions->SetObjectArrayElement(this,array,index,val);
- }
-
- jbooleanArray NewBooleanArray(jsize len) {
- return functions->NewBooleanArray(this,len);
- }
- jbyteArray NewByteArray(jsize len) {
- return functions->NewByteArray(this,len);
- }
- jcharArray NewCharArray(jsize len) {
- return functions->NewCharArray(this,len);
- }
- jshortArray NewShortArray(jsize len) {
- return functions->NewShortArray(this,len);
- }
- jintArray NewIntArray(jsize len) {
- return functions->NewIntArray(this,len);
- }
- jlongArray NewLongArray(jsize len) {
- return functions->NewLongArray(this,len);
- }
- jfloatArray NewFloatArray(jsize len) {
- return functions->NewFloatArray(this,len);
- }
- jdoubleArray NewDoubleArray(jsize len) {
- return functions->NewDoubleArray(this,len);
- }
-
- jboolean * GetBooleanArrayElements(jbooleanArray array, jboolean *isCopy) {
- return functions->GetBooleanArrayElements(this,array,isCopy);
- }
- jbyte * GetByteArrayElements(jbyteArray array, jboolean *isCopy) {
- return functions->GetByteArrayElements(this,array,isCopy);
- }
- jchar * GetCharArrayElements(jcharArray array, jboolean *isCopy) {
- return functions->GetCharArrayElements(this,array,isCopy);
- }
- jshort * GetShortArrayElements(jshortArray array, jboolean *isCopy) {
- return functions->GetShortArrayElements(this,array,isCopy);
- }
- jint * GetIntArrayElements(jintArray array, jboolean *isCopy) {
- return functions->GetIntArrayElements(this,array,isCopy);
- }
- jlong * GetLongArrayElements(jlongArray array, jboolean *isCopy) {
- return functions->GetLongArrayElements(this,array,isCopy);
- }
- jfloat * GetFloatArrayElements(jfloatArray array, jboolean *isCopy) {
- return functions->GetFloatArrayElements(this,array,isCopy);
- }
- jdouble * GetDoubleArrayElements(jdoubleArray array, jboolean *isCopy) {
- return functions->GetDoubleArrayElements(this,array,isCopy);
- }
-
- void ReleaseBooleanArrayElements(jbooleanArray array,
- jboolean *elems,
- jint mode) {
- functions->ReleaseBooleanArrayElements(this,array,elems,mode);
- }
- void ReleaseByteArrayElements(jbyteArray array,
- jbyte *elems,
- jint mode) {
- functions->ReleaseByteArrayElements(this,array,elems,mode);
- }
- void ReleaseCharArrayElements(jcharArray array,
- jchar *elems,
- jint mode) {
- functions->ReleaseCharArrayElements(this,array,elems,mode);
- }
- void ReleaseShortArrayElements(jshortArray array,
- jshort *elems,
- jint mode) {
- functions->ReleaseShortArrayElements(this,array,elems,mode);
- }
- void ReleaseIntArrayElements(jintArray array,
- jint *elems,
- jint mode) {
- functions->ReleaseIntArrayElements(this,array,elems,mode);
- }
- void ReleaseLongArrayElements(jlongArray array,
- jlong *elems,
- jint mode) {
- functions->ReleaseLongArrayElements(this,array,elems,mode);
- }
- void ReleaseFloatArrayElements(jfloatArray array,
- jfloat *elems,
- jint mode) {
- functions->ReleaseFloatArrayElements(this,array,elems,mode);
- }
- void ReleaseDoubleArrayElements(jdoubleArray array,
- jdouble *elems,
- jint mode) {
- functions->ReleaseDoubleArrayElements(this,array,elems,mode);
- }
-
- void GetBooleanArrayRegion(jbooleanArray array,
- jsize start, jsize len, jboolean *buf) {
- functions->GetBooleanArrayRegion(this,array,start,len,buf);
- }
- void GetByteArrayRegion(jbyteArray array,
- jsize start, jsize len, jbyte *buf) {
- functions->GetByteArrayRegion(this,array,start,len,buf);
- }
- void GetCharArrayRegion(jcharArray array,
- jsize start, jsize len, jchar *buf) {
- functions->GetCharArrayRegion(this,array,start,len,buf);
- }
- void GetShortArrayRegion(jshortArray array,
- jsize start, jsize len, jshort *buf) {
- functions->GetShortArrayRegion(this,array,start,len,buf);
- }
- void GetIntArrayRegion(jintArray array,
- jsize start, jsize len, jint *buf) {
- functions->GetIntArrayRegion(this,array,start,len,buf);
- }
- void GetLongArrayRegion(jlongArray array,
- jsize start, jsize len, jlong *buf) {
- functions->GetLongArrayRegion(this,array,start,len,buf);
- }
- void GetFloatArrayRegion(jfloatArray array,
- jsize start, jsize len, jfloat *buf) {
- functions->GetFloatArrayRegion(this,array,start,len,buf);
- }
- void GetDoubleArrayRegion(jdoubleArray array,
- jsize start, jsize len, jdouble *buf) {
- functions->GetDoubleArrayRegion(this,array,start,len,buf);
- }
-
- void SetBooleanArrayRegion(jbooleanArray array, jsize start, jsize len,
- const jboolean *buf) {
- functions->SetBooleanArrayRegion(this,array,start,len,buf);
- }
- void SetByteArrayRegion(jbyteArray array, jsize start, jsize len,
- const jbyte *buf) {
- functions->SetByteArrayRegion(this,array,start,len,buf);
- }
- void SetCharArrayRegion(jcharArray array, jsize start, jsize len,
- const jchar *buf) {
- functions->SetCharArrayRegion(this,array,start,len,buf);
- }
- void SetShortArrayRegion(jshortArray array, jsize start, jsize len,
- const jshort *buf) {
- functions->SetShortArrayRegion(this,array,start,len,buf);
- }
- void SetIntArrayRegion(jintArray array, jsize start, jsize len,
- const jint *buf) {
- functions->SetIntArrayRegion(this,array,start,len,buf);
- }
- void SetLongArrayRegion(jlongArray array, jsize start, jsize len,
- const jlong *buf) {
- functions->SetLongArrayRegion(this,array,start,len,buf);
- }
- void SetFloatArrayRegion(jfloatArray array, jsize start, jsize len,
- const jfloat *buf) {
- functions->SetFloatArrayRegion(this,array,start,len,buf);
- }
- void SetDoubleArrayRegion(jdoubleArray array, jsize start, jsize len,
- const jdouble *buf) {
- functions->SetDoubleArrayRegion(this,array,start,len,buf);
- }
-
- jint RegisterNatives(jclass clazz, const JNINativeMethod *methods,
- jint nMethods) {
- return functions->RegisterNatives(this,clazz,methods,nMethods);
- }
- jint UnregisterNatives(jclass clazz) {
- return functions->UnregisterNatives(this,clazz);
- }
-
- jint MonitorEnter(jobject obj) {
- return functions->MonitorEnter(this,obj);
- }
- jint MonitorExit(jobject obj) {
- return functions->MonitorExit(this,obj);
- }
-
- jint GetJavaVM(JavaVM **vm) {
- return functions->GetJavaVM(this,vm);
- }
-
- void GetStringRegion(jstring str, jsize start, jsize len, jchar *buf) {
- functions->GetStringRegion(this,str,start,len,buf);
- }
- void GetStringUTFRegion(jstring str, jsize start, jsize len, char *buf) {
- functions->GetStringUTFRegion(this,str,start,len,buf);
- }
-
- void * GetPrimitiveArrayCritical(jarray array, jboolean *isCopy) {
- return functions->GetPrimitiveArrayCritical(this,array,isCopy);
- }
- void ReleasePrimitiveArrayCritical(jarray array, void *carray, jint mode) {
- functions->ReleasePrimitiveArrayCritical(this,array,carray,mode);
- }
-
- const jchar * GetStringCritical(jstring string, jboolean *isCopy) {
- return functions->GetStringCritical(this,string,isCopy);
- }
- void ReleaseStringCritical(jstring string, const jchar *cstring) {
- functions->ReleaseStringCritical(this,string,cstring);
- }
-
- jweak NewWeakGlobalRef(jobject obj) {
- return functions->NewWeakGlobalRef(this,obj);
- }
- void DeleteWeakGlobalRef(jweak ref) {
- functions->DeleteWeakGlobalRef(this,ref);
- }
-
- jboolean ExceptionCheck() {
- return functions->ExceptionCheck(this);
- }
-
- jobject NewDirectByteBuffer(void* address, jlong capacity) {
- return functions->NewDirectByteBuffer(this, address, capacity);
- }
- void* GetDirectBufferAddress(jobject buf) {
- return functions->GetDirectBufferAddress(this, buf);
- }
- jlong GetDirectBufferCapacity(jobject buf) {
- return functions->GetDirectBufferCapacity(this, buf);
- }
- jobjectRefType GetObjectRefType(jobject obj) {
- return functions->GetObjectRefType(this, obj);
- }
-
-#endif /* __cplusplus */
-};
-
-typedef struct JavaVMOption {
- char *optionString;
- void *extraInfo;
-} JavaVMOption;
-
-typedef struct JavaVMInitArgs {
- jint version;
-
- jint nOptions;
- JavaVMOption *options;
- jboolean ignoreUnrecognized;
-} JavaVMInitArgs;
-
-typedef struct JavaVMAttachArgs {
- jint version;
-
- char *name;
- jobject group;
-} JavaVMAttachArgs;
-
-/* These will be VM-specific. */
-
-#define JDK1_2
-#define JDK1_4
-
-/* End VM-specific. */
-
-struct JNIInvokeInterface_ {
- void *reserved0;
- void *reserved1;
- void *reserved2;
-
-#if !TARGET_RT_MAC_CFM && defined(__ppc__)
- void* cfm_vectors[4];
-#endif /* !TARGET_RT_MAC_CFM && defined(__ppc__) */
-
- jint (JNICALL *DestroyJavaVM)(JavaVM *vm);
-
- jint (JNICALL *AttachCurrentThread)(JavaVM *vm, void **penv, void *args);
-
- jint (JNICALL *DetachCurrentThread)(JavaVM *vm);
-
- jint (JNICALL *GetEnv)(JavaVM *vm, void **penv, jint version);
-
- jint (JNICALL *AttachCurrentThreadAsDaemon)(JavaVM *vm, void **penv, void *args);
-
-#if TARGET_RT_MAC_CFM && defined(__ppc__)
- void* real_functions[5];
-#endif /* TARGET_RT_MAC_CFM && defined(__ppc__) */
-};
-
-struct JavaVM_ {
- const struct JNIInvokeInterface_ *functions;
-#ifdef __cplusplus
-
- jint DestroyJavaVM() {
- return functions->DestroyJavaVM(this);
- }
- jint AttachCurrentThread(void **penv, void *args) {
- return functions->AttachCurrentThread(this, penv, args);
- }
- jint DetachCurrentThread() {
- return functions->DetachCurrentThread(this);
- }
-
- jint GetEnv(void **penv, jint version) {
- return functions->GetEnv(this, penv, version);
- }
- jint AttachCurrentThreadAsDaemon(void **penv, void *args) {
- return functions->AttachCurrentThreadAsDaemon(this, penv, args);
- }
-#endif
-};
-
-#ifdef _JNI_IMPLEMENTATION_
-#define _JNI_IMPORT_OR_EXPORT_ JNIEXPORT
-#else
-#define _JNI_IMPORT_OR_EXPORT_ JNIIMPORT
-#endif
-_JNI_IMPORT_OR_EXPORT_ jint JNICALL
-JNI_GetDefaultJavaVMInitArgs(void *args);
-
-_JNI_IMPORT_OR_EXPORT_ jint JNICALL
-JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *args);
-
-_JNI_IMPORT_OR_EXPORT_ jint JNICALL
-JNI_GetCreatedJavaVMs(JavaVM **, jsize, jsize *);
-
-/* Defined by native libraries. */
-JNIEXPORT jint JNICALL
-JNI_OnLoad(JavaVM *vm, void *reserved);
-
-JNIEXPORT void JNICALL
-JNI_OnUnload(JavaVM *vm, void *reserved);
-
-#define JNI_VERSION_1_1 0x00010001
-#define JNI_VERSION_1_2 0x00010002
-#define JNI_VERSION_1_4 0x00010004
-#define JNI_VERSION_1_6 0x00010006
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif /* __cplusplus */
-
-#endif /* !_JAVASOFT_JNI_H_ */
-
-
-
diff --git a/jni/jni_md.h b/jni/jni_md.h
deleted file mode 100755
index a3289ee..0000000
--- a/jni/jni_md.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * @(#)jni_md.h 1.19 05/11/17
- *
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
- */
-
-#ifndef _JAVASOFT_JNI_MD_H_
-#define _JAVASOFT_JNI_MD_H_
-
-#define JNIEXPORT __attribute__((visibility("default")))
-#define JNIIMPORT
-#define JNICALL
-
-#if __LP64__
-typedef int jint;
-#else
-typedef long jint;
-#endif
-typedef long long jlong;
-typedef signed char jbyte;
-
-#endif /* !_JAVASOFT_JNI_MD_H_ */
diff --git a/pom.xml b/pom.xml
index 0bfc37c..184d92d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,18 +1,23 @@
- 4.0.0
- org.gmssl
- GmSSL-Java
- 2.1.0-develop
- GmSSL-Java
- GmSSL Java SDK
-
-
- UTF-8
- 11
- 11
- 11
- false
-
+ 4.0.0
+ org.gmssl
+ GmSSLJNI
+ 3.1.1
+ GmSSL-Java
+ jar
+ GmSSL Java SDK
+
+
+ UTF-8
+ 11
+ 11
+ false
+
+ Debug
+
+ gmssljni
+
+
@@ -42,7 +47,7 @@
- ${project.build.directory}/${platform}/build
+ ${project.build.directory}/build
-
- value
+ ${cmake.compile.config}
+ ${libName}
- ${project.build.directory}/${platform}/build
+ ${project.build.directory}/build
- value
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- 3.1.2
-
-
- -Djava.library.path=${project.build.directory}/classes
-
-
-
-
org.apache.maven.plugins
maven-clean-plugin
@@ -113,15 +100,21 @@
false
- ${basedir}/src/main/resources/lib/${platform}
+ ${basedir}/src/main/resources/lib
*.dll
- *.pdb
*.so
*.dylib
false
+
+ ${basedir}
+
+ ROOTCA.pem
+
+ false
+
@@ -142,24 +135,29 @@
${project.build.directory}
- ${project.build.directory}/${platform}/build
+ ${project.build.directory}/build/${cmake.compile.config}
*.dll
- *.pdb
*.so
*.dylib
- ${basedir}/target/classes/lib/${platform}
+ ${basedir}/target/classes/lib
- ${project.build.directory}/${platform}/build
+ ${project.build.directory}/build/${cmake.compile.config}
*.dll
- *.pdb
*.so
*.dylib
- ${basedir}/src/main/resources/lib/${platform}
+ ${basedir}/src/main/resources/lib
+
+
+ ${project.build.directory}/build
+
+ ROOTCA.pem
+
+ ${basedir}
@@ -169,24 +167,6 @@
-
-
- linux-x86_64
-
- true
-
-
- linux-x86_64
-
-
-
- win-x86_64
-
- win-x86_64
-
-
-
-
central-maven2
diff --git a/src/main/c/CMakeLists.txt b/src/main/c/CMakeLists.txt
index 3035ba8..a16c4b3 100644
--- a/src/main/c/CMakeLists.txt
+++ b/src/main/c/CMakeLists.txt
@@ -1,19 +1,47 @@
cmake_minimum_required(VERSION 3.11)
project(gmssljni)
-add_library(gmssljni-native SHARED gmssljni.c)
-target_include_directories(gmssljni-native PUBLIC ${CMAKE_SOURCE_DIR}/src/include)
-target_link_libraries(gmssljni-native -L/usr/local/lib)
-target_link_libraries(gmssljni-native gmssl)
-set_target_properties(gmssljni-native PROPERTIES OUTPUT_NAME gmssljni)
+find_program(GMSSL_EXECUTABLE NAMES gmssl)
+if(GMSSL_EXECUTABLE)
+ get_filename_component(GMSSL_BIN_DIR "${GMSSL_EXECUTABLE}" DIRECTORY)
+ get_filename_component(GMSSL_PARENT_DIR "${GMSSL_BIN_DIR}" DIRECTORY)
+else()
+ message(FATAL_ERROR "gmssl not found!")
+endif()
-
-find_package(Java REQUIRED)
-include(UseJava)
-include_directories(jni)
-include_directories(/usr/local/include)
-
-enable_testing()
+if(WIN32)
+ message(STATUS "->Now is windows")
+ link_directories(${GMSSL_PARENT_DIR}/lib)
+ add_library(gmssljni-native SHARED gmssljni.c)
+ target_include_directories(gmssljni-native PUBLIC ${GMSSL_PARENT_DIR}/include)
+ #target_include_directories(gmssljni-native PUBLIC ${CMAKE_SOURCE_DIR}/jni)
+ find_package(JNI REQUIRED)
+ include_directories(${JNI_INCLUDE_DIRS})
+ target_link_libraries(gmssljni-native gmssl)
+ set_target_properties(gmssljni-native PROPERTIES OUTPUT_NAME lib$ENV{libName})
+elseif(APPLE)
+ message(STATUS "->Now is Apple systems.")
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$ENV{libSubFolder})
+ add_library(gmssljni-native SHARED gmssljni.c)
+ target_link_libraries(gmssljni-native -L"${GMSSL_PARENT_DIR}/lib")
+ find_package(JNI REQUIRED)
+ include_directories(${JNI_INCLUDE_DIRS})
+ include_directories(${GMSSL_PARENT_DIR}/include)
+ target_link_libraries(gmssljni-native gmssl)
+ set_target_properties(gmssljni-native PROPERTIES OUTPUT_NAME $ENV{libName})
+elseif(UNIX)
+ message(STATUS "->Now is UNIX-like OS's.")
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$ENV{libSubFolder})
+ add_library(gmssljni-native SHARED gmssljni.c)
+ target_link_libraries(gmssljni-native -L"${GMSSL_PARENT_DIR}/lib")
+ find_package(JNI REQUIRED)
+ include_directories(${JNI_INCLUDE_DIRS})
+ include_directories(${GMSSL_PARENT_DIR}/include)
+ target_link_libraries(gmssljni-native gmssl)
+ set_target_properties(gmssljni-native PROPERTIES OUTPUT_NAME $ENV{libName})
+else()
+ message(FATAL_ERROR "->Now is other systems.")
+endif()
set(certfile
"-----BEGIN CERTIFICATE-----\n"
@@ -28,6 +56,4 @@ set(certfile
"53W+CKOPl2PknmWEq/lMhtn25HkCIQDaHDgWxWFtnCrBjH16/W3Ezn7/U/Vjo5xI\n"
"pDoiVhsLwg==\n"
"-----END CERTIFICATE-----\n")
-file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/ROOTCA.pem ${certfile})
-
-
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/ROOTCA.pem ${certfile})
\ No newline at end of file
diff --git a/src/main/c/gmssljni.c b/src/main/c/gmssljni.c
index beb1dbd..fe1cc72 100644
--- a/src/main/c/gmssljni.c
+++ b/src/main/c/gmssljni.c
@@ -21,6 +21,7 @@
#include
#include
#include
+#include
#include
#include "gmssljni.h"
@@ -352,6 +353,61 @@ JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1hmac_1finish(
return ret;
}
+/*
+ * Class: org_gmssl_GmSSLJNI
+ * Method: sm3_pbkdf2
+ * Signature: (Ljava/lang/String;[BII)[B
+ */
+JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm3_1pbkdf2(
+ JNIEnv *env, jclass this,
+ jstring pass, jbyteArray salt, jint iter, jint keylen)
+{
+ jbyteArray ret = NULL;
+ uint8_t keybuf[256];
+ const char *pass_str = NULL;
+ jbyte *saltbuf = NULL;
+ jlong saltlen;
+
+ if (!(pass_str = (*env)->GetStringUTFChars(env, pass, 0))) {
+ error_print();
+ goto end;
+ }
+ if (iter < PBKDF2_MIN_ITER || iter > PBKDF2_MAX_ITER) {
+ error_print();
+ goto end;
+ }
+ if (!(saltbuf = (*env)->GetByteArrayElements(env, salt, NULL))) {
+ error_print();
+ goto end;
+ }
+ saltlen = (*env)->GetArrayLength(env, salt);
+ if (saltlen < 1 || saltlen > PBKDF2_MAX_SALT_SIZE) {
+ error_print();
+ goto end;
+ }
+ if (keylen < 1 || keylen > sizeof(keybuf)) {
+ error_print();
+ goto end;
+ }
+
+ if (pbkdf2_hmac_sm3_genkey(pass_str, strlen(pass_str),
+ (const uint8_t *)saltbuf, saltlen, iter, keylen, keybuf) != 1) {
+ error_print();
+ goto end;
+ }
+
+ if (!(ret = (*env)->NewByteArray(env, keylen))) {
+ error_print();
+ goto end;
+ }
+ (*env)->SetByteArrayRegion(env, ret, 0, keylen, (jbyte *)keybuf);
+
+end:
+ if (pass_str) (*env)->ReleaseStringUTFChars(env, pass, pass_str);
+ if (saltbuf) (*env)->ReleaseByteArrayElements(env, salt, saltbuf, JNI_ABORT);
+ return ret;
+}
+
/*
* Class: org_gmssl_GmSSLJNI
* Method: sm4_key_new
diff --git a/src/main/c/gmssljni.h b/src/main/c/gmssljni.h
index 9b6ed31..f9dbe2a 100644
--- a/src/main/c/gmssljni.h
+++ b/src/main/c/gmssljni.h
@@ -13,10 +13,24 @@ extern "C" {
#define org_gmssl_GmSSLJNI_SM3_HMAC_SIZE 32L
#undef org_gmssl_GmSSLJNI_SM3_HMAC_MIN_KEY_SIZE
#define org_gmssl_GmSSLJNI_SM3_HMAC_MIN_KEY_SIZE 16L
+#undef org_gmssl_GmSSLJNI_SM3_PBKDF2_MIN_ITER
+#define org_gmssl_GmSSLJNI_SM3_PBKDF2_MIN_ITER 10000L
+#undef org_gmssl_GmSSLJNI_SM3_PBKDF2_MAX_ITER
+#define org_gmssl_GmSSLJNI_SM3_PBKDF2_MAX_ITER 16777216L
+#undef org_gmssl_GmSSLJNI_SM3_PBKDF2_MAX_SALT_SIZE
+#define org_gmssl_GmSSLJNI_SM3_PBKDF2_MAX_SALT_SIZE 64L
+#undef org_gmssl_GmSSLJNI_SM3_PBKDF2_DEFAULT_SALT_SIZE
+#define org_gmssl_GmSSLJNI_SM3_PBKDF2_DEFAULT_SALT_SIZE 8L
+#undef org_gmssl_GmSSLJNI_SM3_PBKDF2_MAX_KEY_SIZE
+#define org_gmssl_GmSSLJNI_SM3_PBKDF2_MAX_KEY_SIZE 256L
#undef org_gmssl_GmSSLJNI_SM4_KEY_SIZE
#define org_gmssl_GmSSLJNI_SM4_KEY_SIZE 16L
#undef org_gmssl_GmSSLJNI_SM4_BLOCK_SIZE
#define org_gmssl_GmSSLJNI_SM4_BLOCK_SIZE 16L
+#undef org_gmssl_GmSSLJNI_SM4_CBC_IV_SIZE
+#define org_gmssl_GmSSLJNI_SM4_CBC_IV_SIZE 16L
+#undef org_gmssl_GmSSLJNI_SM4_CTR_IV_SIZE
+#define org_gmssl_GmSSLJNI_SM4_CTR_IV_SIZE 16L
#undef org_gmssl_GmSSLJNI_SM4_GCM_MIN_IV_SIZE
#define org_gmssl_GmSSLJNI_SM4_GCM_MIN_IV_SIZE 1L
#undef org_gmssl_GmSSLJNI_SM4_GCM_MAX_IV_SIZE
@@ -137,6 +151,14 @@ JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1hmac_1update
JNIEXPORT jint JNICALL Java_org_gmssl_GmSSLJNI_sm3_1hmac_1finish
(JNIEnv *, jclass, jlong, jbyteArray);
+/*
+ * Class: org_gmssl_GmSSLJNI
+ * Method: sm3_pbkdf2
+ * Signature: (Ljava/lang/String;[BII)[B
+ */
+JNIEXPORT jbyteArray JNICALL Java_org_gmssl_GmSSLJNI_sm3_1pbkdf2
+ (JNIEnv *, jclass, jstring, jbyteArray, jint, jint);
+
/*
* Class: org_gmssl_GmSSLJNI
* Method: sm4_key_new
diff --git a/src/main/c/jni/jni.h b/src/main/c/jni/jni.h
deleted file mode 100644
index 10070c0..0000000
--- a/src/main/c/jni/jni.h
+++ /dev/null
@@ -1,1961 +0,0 @@
-/*
- * @(#)jni.h 1.62 06/02/02
- *
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
- */
-
-/*
- * We used part of Netscape's Java Runtime Interface (JRI) as the starting
- * point of our design and implementation.
- */
-
-/******************************************************************************
- * Java Runtime Interface
- * Copyright (c) 1996 Netscape Communications Corporation. All rights reserved.
- *****************************************************************************/
-
-#ifndef _JAVASOFT_JNI_H_
-#define _JAVASOFT_JNI_H_
-
-#include
-#include
-
-/* jni_md.h contains the machine-dependent typedefs for jbyte, jint
- and jlong */
-
-#include "jni_md.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * JNI Types
- */
-
-#ifndef JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H
-
-typedef unsigned char jboolean;
-typedef unsigned short jchar;
-typedef short jshort;
-typedef float jfloat;
-typedef double jdouble;
-
-typedef jint jsize;
-
-#ifdef __cplusplus
-
-class _jobject {};
-class _jclass : public _jobject {};
-class _jthrowable : public _jobject {};
-class _jstring : public _jobject {};
-class _jarray : public _jobject {};
-class _jbooleanArray : public _jarray {};
-class _jbyteArray : public _jarray {};
-class _jcharArray : public _jarray {};
-class _jshortArray : public _jarray {};
-class _jintArray : public _jarray {};
-class _jlongArray : public _jarray {};
-class _jfloatArray : public _jarray {};
-class _jdoubleArray : public _jarray {};
-class _jobjectArray : public _jarray {};
-
-typedef _jobject *jobject;
-typedef _jclass *jclass;
-typedef _jthrowable *jthrowable;
-typedef _jstring *jstring;
-typedef _jarray *jarray;
-typedef _jbooleanArray *jbooleanArray;
-typedef _jbyteArray *jbyteArray;
-typedef _jcharArray *jcharArray;
-typedef _jshortArray *jshortArray;
-typedef _jintArray *jintArray;
-typedef _jlongArray *jlongArray;
-typedef _jfloatArray *jfloatArray;
-typedef _jdoubleArray *jdoubleArray;
-typedef _jobjectArray *jobjectArray;
-
-#else
-
-struct _jobject;
-
-typedef struct _jobject *jobject;
-typedef jobject jclass;
-typedef jobject jthrowable;
-typedef jobject jstring;
-typedef jobject jarray;
-typedef jarray jbooleanArray;
-typedef jarray jbyteArray;
-typedef jarray jcharArray;
-typedef jarray jshortArray;
-typedef jarray jintArray;
-typedef jarray jlongArray;
-typedef jarray jfloatArray;
-typedef jarray jdoubleArray;
-typedef jarray jobjectArray;
-
-#endif
-
-typedef jobject jweak;
-
-typedef union jvalue {
- jboolean z;
- jbyte b;
- jchar c;
- jshort s;
- jint i;
- jlong j;
- jfloat f;
- jdouble d;
- jobject l;
-} jvalue;
-
-struct _jfieldID;
-typedef struct _jfieldID *jfieldID;
-
-struct _jmethodID;
-typedef struct _jmethodID *jmethodID;
-
-/* Return values from jobjectRefType */
-typedef enum _jobjectType {
- JNIInvalidRefType = 0,
- JNILocalRefType = 1,
- JNIGlobalRefType = 2,
- JNIWeakGlobalRefType = 3
-} jobjectRefType;
-
-
-#endif /* JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H */
-
-/*
- * jboolean constants
- */
-
-#define JNI_FALSE 0
-#define JNI_TRUE 1
-
-/*
- * possible return values for JNI functions.
- */
-
-#define JNI_OK 0 /* success */
-#define JNI_ERR (-1) /* unknown error */
-#define JNI_EDETACHED (-2) /* thread detached from the VM */
-#define JNI_EVERSION (-3) /* JNI version error */
-#define JNI_ENOMEM (-4) /* not enough memory */
-#define JNI_EEXIST (-5) /* VM already created */
-#define JNI_EINVAL (-6) /* invalid arguments */
-
-/*
- * used in ReleaseScalarArrayElements
- */
-
-#define JNI_COMMIT 1
-#define JNI_ABORT 2
-
-/*
- * used in RegisterNatives to describe native method name, signature,
- * and function pointer.
- */
-
-typedef struct {
- char *name;
- char *signature;
- void *fnPtr;
-} JNINativeMethod;
-
-/*
- * JNI Native Method Interface.
- */
-
-struct JNINativeInterface_;
-
-struct JNIEnv_;
-
-#ifdef __cplusplus
-typedef JNIEnv_ JNIEnv;
-#else
-typedef const struct JNINativeInterface_ *JNIEnv;
-#endif
-
-/*
- * JNI Invocation Interface.
- */
-
-struct JNIInvokeInterface_;
-
-struct JavaVM_;
-
-#ifdef __cplusplus
-typedef JavaVM_ JavaVM;
-#else
-typedef const struct JNIInvokeInterface_ *JavaVM;
-#endif
-
-struct JNINativeInterface_ {
- void *reserved0;
- void *reserved1;
- void *reserved2;
-
- void *reserved3;
-
-#if !TARGET_RT_MAC_CFM && defined(__ppc__)
- void* cfm_vectors[225];
-#endif /* !TARGET_RT_MAC_CFM && defined(__ppc__) */
-
- jint (JNICALL *GetVersion)(JNIEnv *env);
-
- jclass (JNICALL *DefineClass)
- (JNIEnv *env, const char *name, jobject loader, const jbyte *buf,
- jsize len);
- jclass (JNICALL *FindClass)
- (JNIEnv *env, const char *name);
-
- jmethodID (JNICALL *FromReflectedMethod)
- (JNIEnv *env, jobject method);
- jfieldID (JNICALL *FromReflectedField)
- (JNIEnv *env, jobject field);
-
- jobject (JNICALL *ToReflectedMethod)
- (JNIEnv *env, jclass cls, jmethodID methodID, jboolean isStatic);
-
- jclass (JNICALL *GetSuperclass)
- (JNIEnv *env, jclass sub);
- jboolean (JNICALL *IsAssignableFrom)
- (JNIEnv *env, jclass sub, jclass sup);
-
- jobject (JNICALL *ToReflectedField)
- (JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic);
-
- jint (JNICALL *Throw)
- (JNIEnv *env, jthrowable obj);
- jint (JNICALL *ThrowNew)
- (JNIEnv *env, jclass clazz, const char *msg);
- jthrowable (JNICALL *ExceptionOccurred)
- (JNIEnv *env);
- void (JNICALL *ExceptionDescribe)
- (JNIEnv *env);
- void (JNICALL *ExceptionClear)
- (JNIEnv *env);
- void (JNICALL *FatalError)
- (JNIEnv *env, const char *msg);
-
- jint (JNICALL *PushLocalFrame)
- (JNIEnv *env, jint capacity);
- jobject (JNICALL *PopLocalFrame)
- (JNIEnv *env, jobject result);
-
- jobject (JNICALL *NewGlobalRef)
- (JNIEnv *env, jobject lobj);
- void (JNICALL *DeleteGlobalRef)
- (JNIEnv *env, jobject gref);
- void (JNICALL *DeleteLocalRef)
- (JNIEnv *env, jobject obj);
- jboolean (JNICALL *IsSameObject)
- (JNIEnv *env, jobject obj1, jobject obj2);
- jobject (JNICALL *NewLocalRef)
- (JNIEnv *env, jobject ref);
- jint (JNICALL *EnsureLocalCapacity)
- (JNIEnv *env, jint capacity);
-
- jobject (JNICALL *AllocObject)
- (JNIEnv *env, jclass clazz);
- jobject (JNICALL *NewObject)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jobject (JNICALL *NewObjectV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jobject (JNICALL *NewObjectA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jclass (JNICALL *GetObjectClass)
- (JNIEnv *env, jobject obj);
- jboolean (JNICALL *IsInstanceOf)
- (JNIEnv *env, jobject obj, jclass clazz);
-
- jmethodID (JNICALL *GetMethodID)
- (JNIEnv *env, jclass clazz, const char *name, const char *sig);
-
- jobject (JNICALL *CallObjectMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jobject (JNICALL *CallObjectMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jobject (JNICALL *CallObjectMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue * args);
-
- jboolean (JNICALL *CallBooleanMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jboolean (JNICALL *CallBooleanMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jboolean (JNICALL *CallBooleanMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue * args);
-
- jbyte (JNICALL *CallByteMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jbyte (JNICALL *CallByteMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jbyte (JNICALL *CallByteMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- jchar (JNICALL *CallCharMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jchar (JNICALL *CallCharMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jchar (JNICALL *CallCharMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- jshort (JNICALL *CallShortMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jshort (JNICALL *CallShortMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jshort (JNICALL *CallShortMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- jint (JNICALL *CallIntMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jint (JNICALL *CallIntMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jint (JNICALL *CallIntMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- jlong (JNICALL *CallLongMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jlong (JNICALL *CallLongMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jlong (JNICALL *CallLongMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- jfloat (JNICALL *CallFloatMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jfloat (JNICALL *CallFloatMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jfloat (JNICALL *CallFloatMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- jdouble (JNICALL *CallDoubleMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- jdouble (JNICALL *CallDoubleMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- jdouble (JNICALL *CallDoubleMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
-
- void (JNICALL *CallVoidMethod)
- (JNIEnv *env, jobject obj, jmethodID methodID, ...);
- void (JNICALL *CallVoidMethodV)
- (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
- void (JNICALL *CallVoidMethodA)
- (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue * args);
-
- jobject (JNICALL *CallNonvirtualObjectMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jobject (JNICALL *CallNonvirtualObjectMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jobject (JNICALL *CallNonvirtualObjectMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue * args);
-
- jboolean (JNICALL *CallNonvirtualBooleanMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jboolean (JNICALL *CallNonvirtualBooleanMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jboolean (JNICALL *CallNonvirtualBooleanMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue * args);
-
- jbyte (JNICALL *CallNonvirtualByteMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jbyte (JNICALL *CallNonvirtualByteMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jbyte (JNICALL *CallNonvirtualByteMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- jchar (JNICALL *CallNonvirtualCharMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jchar (JNICALL *CallNonvirtualCharMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jchar (JNICALL *CallNonvirtualCharMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- jshort (JNICALL *CallNonvirtualShortMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jshort (JNICALL *CallNonvirtualShortMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jshort (JNICALL *CallNonvirtualShortMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- jint (JNICALL *CallNonvirtualIntMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jint (JNICALL *CallNonvirtualIntMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jint (JNICALL *CallNonvirtualIntMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- jlong (JNICALL *CallNonvirtualLongMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jlong (JNICALL *CallNonvirtualLongMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jlong (JNICALL *CallNonvirtualLongMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- jfloat (JNICALL *CallNonvirtualFloatMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jfloat (JNICALL *CallNonvirtualFloatMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jfloat (JNICALL *CallNonvirtualFloatMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- jdouble (JNICALL *CallNonvirtualDoubleMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- jdouble (JNICALL *CallNonvirtualDoubleMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- jdouble (JNICALL *CallNonvirtualDoubleMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue *args);
-
- void (JNICALL *CallNonvirtualVoidMethod)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
- void (JNICALL *CallNonvirtualVoidMethodV)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- va_list args);
- void (JNICALL *CallNonvirtualVoidMethodA)
- (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID,
- const jvalue * args);
-
- jfieldID (JNICALL *GetFieldID)
- (JNIEnv *env, jclass clazz, const char *name, const char *sig);
-
- jobject (JNICALL *GetObjectField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jboolean (JNICALL *GetBooleanField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jbyte (JNICALL *GetByteField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jchar (JNICALL *GetCharField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jshort (JNICALL *GetShortField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jint (JNICALL *GetIntField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jlong (JNICALL *GetLongField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jfloat (JNICALL *GetFloatField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
- jdouble (JNICALL *GetDoubleField)
- (JNIEnv *env, jobject obj, jfieldID fieldID);
-
- void (JNICALL *SetObjectField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jobject val);
- void (JNICALL *SetBooleanField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jboolean val);
- void (JNICALL *SetByteField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jbyte val);
- void (JNICALL *SetCharField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jchar val);
- void (JNICALL *SetShortField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jshort val);
- void (JNICALL *SetIntField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jint val);
- void (JNICALL *SetLongField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jlong val);
- void (JNICALL *SetFloatField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jfloat val);
- void (JNICALL *SetDoubleField)
- (JNIEnv *env, jobject obj, jfieldID fieldID, jdouble val);
-
- jmethodID (JNICALL *GetStaticMethodID)
- (JNIEnv *env, jclass clazz, const char *name, const char *sig);
-
- jobject (JNICALL *CallStaticObjectMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jobject (JNICALL *CallStaticObjectMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jobject (JNICALL *CallStaticObjectMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jboolean (JNICALL *CallStaticBooleanMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jboolean (JNICALL *CallStaticBooleanMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jboolean (JNICALL *CallStaticBooleanMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jbyte (JNICALL *CallStaticByteMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jbyte (JNICALL *CallStaticByteMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jbyte (JNICALL *CallStaticByteMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jchar (JNICALL *CallStaticCharMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jchar (JNICALL *CallStaticCharMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jchar (JNICALL *CallStaticCharMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jshort (JNICALL *CallStaticShortMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jshort (JNICALL *CallStaticShortMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jshort (JNICALL *CallStaticShortMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jint (JNICALL *CallStaticIntMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jint (JNICALL *CallStaticIntMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jint (JNICALL *CallStaticIntMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jlong (JNICALL *CallStaticLongMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jlong (JNICALL *CallStaticLongMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jlong (JNICALL *CallStaticLongMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jfloat (JNICALL *CallStaticFloatMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jfloat (JNICALL *CallStaticFloatMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jfloat (JNICALL *CallStaticFloatMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- jdouble (JNICALL *CallStaticDoubleMethod)
- (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
- jdouble (JNICALL *CallStaticDoubleMethodV)
- (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
- jdouble (JNICALL *CallStaticDoubleMethodA)
- (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
-
- void (JNICALL *CallStaticVoidMethod)
- (JNIEnv *env, jclass cls, jmethodID methodID, ...);
- void (JNICALL *CallStaticVoidMethodV)
- (JNIEnv *env, jclass cls, jmethodID methodID, va_list args);
- void (JNICALL *CallStaticVoidMethodA)
- (JNIEnv *env, jclass cls, jmethodID methodID, const jvalue * args);
-
- jfieldID (JNICALL *GetStaticFieldID)
- (JNIEnv *env, jclass clazz, const char *name, const char *sig);
- jobject (JNICALL *GetStaticObjectField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jboolean (JNICALL *GetStaticBooleanField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jbyte (JNICALL *GetStaticByteField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jchar (JNICALL *GetStaticCharField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jshort (JNICALL *GetStaticShortField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jint (JNICALL *GetStaticIntField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jlong (JNICALL *GetStaticLongField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jfloat (JNICALL *GetStaticFloatField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
- jdouble (JNICALL *GetStaticDoubleField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID);
-
- void (JNICALL *SetStaticObjectField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value);
- void (JNICALL *SetStaticBooleanField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value);
- void (JNICALL *SetStaticByteField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value);
- void (JNICALL *SetStaticCharField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value);
- void (JNICALL *SetStaticShortField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value);
- void (JNICALL *SetStaticIntField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jint value);
- void (JNICALL *SetStaticLongField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value);
- void (JNICALL *SetStaticFloatField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value);
- void (JNICALL *SetStaticDoubleField)
- (JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value);
-
- jstring (JNICALL *NewString)
- (JNIEnv *env, const jchar *unicode, jsize len);
- jsize (JNICALL *GetStringLength)
- (JNIEnv *env, jstring str);
- const jchar *(JNICALL *GetStringChars)
- (JNIEnv *env, jstring str, jboolean *isCopy);
- void (JNICALL *ReleaseStringChars)
- (JNIEnv *env, jstring str, const jchar *chars);
-
- jstring (JNICALL *NewStringUTF)
- (JNIEnv *env, const char *utf);
- jsize (JNICALL *GetStringUTFLength)
- (JNIEnv *env, jstring str);
- const char* (JNICALL *GetStringUTFChars)
- (JNIEnv *env, jstring str, jboolean *isCopy);
- void (JNICALL *ReleaseStringUTFChars)
- (JNIEnv *env, jstring str, const char* chars);
-
-
- jsize (JNICALL *GetArrayLength)
- (JNIEnv *env, jarray array);
-
- jobjectArray (JNICALL *NewObjectArray)
- (JNIEnv *env, jsize len, jclass clazz, jobject init);
- jobject (JNICALL *GetObjectArrayElement)
- (JNIEnv *env, jobjectArray array, jsize index);
- void (JNICALL *SetObjectArrayElement)
- (JNIEnv *env, jobjectArray array, jsize index, jobject val);
-
- jbooleanArray (JNICALL *NewBooleanArray)
- (JNIEnv *env, jsize len);
- jbyteArray (JNICALL *NewByteArray)
- (JNIEnv *env, jsize len);
- jcharArray (JNICALL *NewCharArray)
- (JNIEnv *env, jsize len);
- jshortArray (JNICALL *NewShortArray)
- (JNIEnv *env, jsize len);
- jintArray (JNICALL *NewIntArray)
- (JNIEnv *env, jsize len);
- jlongArray (JNICALL *NewLongArray)
- (JNIEnv *env, jsize len);
- jfloatArray (JNICALL *NewFloatArray)
- (JNIEnv *env, jsize len);
- jdoubleArray (JNICALL *NewDoubleArray)
- (JNIEnv *env, jsize len);
-
- jboolean * (JNICALL *GetBooleanArrayElements)
- (JNIEnv *env, jbooleanArray array, jboolean *isCopy);
- jbyte * (JNICALL *GetByteArrayElements)
- (JNIEnv *env, jbyteArray array, jboolean *isCopy);
- jchar * (JNICALL *GetCharArrayElements)
- (JNIEnv *env, jcharArray array, jboolean *isCopy);
- jshort * (JNICALL *GetShortArrayElements)
- (JNIEnv *env, jshortArray array, jboolean *isCopy);
- jint * (JNICALL *GetIntArrayElements)
- (JNIEnv *env, jintArray array, jboolean *isCopy);
- jlong * (JNICALL *GetLongArrayElements)
- (JNIEnv *env, jlongArray array, jboolean *isCopy);
- jfloat * (JNICALL *GetFloatArrayElements)
- (JNIEnv *env, jfloatArray array, jboolean *isCopy);
- jdouble * (JNICALL *GetDoubleArrayElements)
- (JNIEnv *env, jdoubleArray array, jboolean *isCopy);
-
- void (JNICALL *ReleaseBooleanArrayElements)
- (JNIEnv *env, jbooleanArray array, jboolean *elems, jint mode);
- void (JNICALL *ReleaseByteArrayElements)
- (JNIEnv *env, jbyteArray array, jbyte *elems, jint mode);
- void (JNICALL *ReleaseCharArrayElements)
- (JNIEnv *env, jcharArray array, jchar *elems, jint mode);
- void (JNICALL *ReleaseShortArrayElements)
- (JNIEnv *env, jshortArray array, jshort *elems, jint mode);
- void (JNICALL *ReleaseIntArrayElements)
- (JNIEnv *env, jintArray array, jint *elems, jint mode);
- void (JNICALL *ReleaseLongArrayElements)
- (JNIEnv *env, jlongArray array, jlong *elems, jint mode);
- void (JNICALL *ReleaseFloatArrayElements)
- (JNIEnv *env, jfloatArray array, jfloat *elems, jint mode);
- void (JNICALL *ReleaseDoubleArrayElements)
- (JNIEnv *env, jdoubleArray array, jdouble *elems, jint mode);
-
- void (JNICALL *GetBooleanArrayRegion)
- (JNIEnv *env, jbooleanArray array, jsize start, jsize l, jboolean *buf);
- void (JNICALL *GetByteArrayRegion)
- (JNIEnv *env, jbyteArray array, jsize start, jsize len, jbyte *buf);
- void (JNICALL *GetCharArrayRegion)
- (JNIEnv *env, jcharArray array, jsize start, jsize len, jchar *buf);
- void (JNICALL *GetShortArrayRegion)
- (JNIEnv *env, jshortArray array, jsize start, jsize len, jshort *buf);
- void (JNICALL *GetIntArrayRegion)
- (JNIEnv *env, jintArray array, jsize start, jsize len, jint *buf);
- void (JNICALL *GetLongArrayRegion)
- (JNIEnv *env, jlongArray array, jsize start, jsize len, jlong *buf);
- void (JNICALL *GetFloatArrayRegion)
- (JNIEnv *env, jfloatArray array, jsize start, jsize len, jfloat *buf);
- void (JNICALL *GetDoubleArrayRegion)
- (JNIEnv *env, jdoubleArray array, jsize start, jsize len, jdouble *buf);
-
- void (JNICALL *SetBooleanArrayRegion)
- (JNIEnv *env, jbooleanArray array, jsize start, jsize l, const jboolean *buf);
- void (JNICALL *SetByteArrayRegion)
- (JNIEnv *env, jbyteArray array, jsize start, jsize len, const jbyte *buf);
- void (JNICALL *SetCharArrayRegion)
- (JNIEnv *env, jcharArray array, jsize start, jsize len, const jchar *buf);
- void (JNICALL *SetShortArrayRegion)
- (JNIEnv *env, jshortArray array, jsize start, jsize len, const jshort *buf);
- void (JNICALL *SetIntArrayRegion)
- (JNIEnv *env, jintArray array, jsize start, jsize len, const jint *buf);
- void (JNICALL *SetLongArrayRegion)
- (JNIEnv *env, jlongArray array, jsize start, jsize len, const jlong *buf);
- void (JNICALL *SetFloatArrayRegion)
- (JNIEnv *env, jfloatArray array, jsize start, jsize len, const jfloat *buf);
- void (JNICALL *SetDoubleArrayRegion)
- (JNIEnv *env, jdoubleArray array, jsize start, jsize len, const jdouble *buf);
-
- jint (JNICALL *RegisterNatives)
- (JNIEnv *env, jclass clazz, const JNINativeMethod *methods,
- jint nMethods);
- jint (JNICALL *UnregisterNatives)
- (JNIEnv *env, jclass clazz);
-
- jint (JNICALL *MonitorEnter)
- (JNIEnv *env, jobject obj);
- jint (JNICALL *MonitorExit)
- (JNIEnv *env, jobject obj);
-
- jint (JNICALL *GetJavaVM)
- (JNIEnv *env, JavaVM **vm);
-
- void (JNICALL *GetStringRegion)
- (JNIEnv *env, jstring str, jsize start, jsize len, jchar *buf);
- void (JNICALL *GetStringUTFRegion)
- (JNIEnv *env, jstring str, jsize start, jsize len, char *buf);
-
- void * (JNICALL *GetPrimitiveArrayCritical)
- (JNIEnv *env, jarray array, jboolean *isCopy);
- void (JNICALL *ReleasePrimitiveArrayCritical)
- (JNIEnv *env, jarray array, void *carray, jint mode);
-
- const jchar * (JNICALL *GetStringCritical)
- (JNIEnv *env, jstring string, jboolean *isCopy);
- void (JNICALL *ReleaseStringCritical)
- (JNIEnv *env, jstring string, const jchar *cstring);
-
- jweak (JNICALL *NewWeakGlobalRef)
- (JNIEnv *env, jobject obj);
- void (JNICALL *DeleteWeakGlobalRef)
- (JNIEnv *env, jweak ref);
-
- jboolean (JNICALL *ExceptionCheck)
- (JNIEnv *env);
-
- jobject (JNICALL *NewDirectByteBuffer)
- (JNIEnv* env, void* address, jlong capacity);
- void* (JNICALL *GetDirectBufferAddress)
- (JNIEnv* env, jobject buf);
- jlong (JNICALL *GetDirectBufferCapacity)
- (JNIEnv* env, jobject buf);
-
- /* New JNI 1.6 Features */
-
- jobjectRefType (JNICALL *GetObjectRefType)
- (JNIEnv* env, jobject obj);
-
- #if TARGET_RT_MAC_CFM && defined(__ppc__)
- void* real_functions[228];
- #endif /* TARGET_RT_MAC_CFM && defined(__ppc__) */
-};
-
-/*
- * We use inlined functions for C++ so that programmers can write:
- *
- * env->FindClass("java/lang/String")
- *
- * in C++ rather than:
- *
- * (*env)->FindClass(env, "java/lang/String")
- *
- * in C.
- */
-
-struct JNIEnv_ {
- const struct JNINativeInterface_ *functions;
-#ifdef __cplusplus
-
- jint GetVersion() {
- return functions->GetVersion(this);
- }
- jclass DefineClass(const char *name, jobject loader, const jbyte *buf,
- jsize len) {
- return functions->DefineClass(this, name, loader, buf, len);
- }
- jclass FindClass(const char *name) {
- return functions->FindClass(this, name);
- }
- jmethodID FromReflectedMethod(jobject method) {
- return functions->FromReflectedMethod(this,method);
- }
- jfieldID FromReflectedField(jobject field) {
- return functions->FromReflectedField(this,field);
- }
-
- jobject ToReflectedMethod(jclass cls, jmethodID methodID, jboolean isStatic) {
- return functions->ToReflectedMethod(this, cls, methodID, isStatic);
- }
-
- jclass GetSuperclass(jclass sub) {
- return functions->GetSuperclass(this, sub);
- }
- jboolean IsAssignableFrom(jclass sub, jclass sup) {
- return functions->IsAssignableFrom(this, sub, sup);
- }
-
- jobject ToReflectedField(jclass cls, jfieldID fieldID, jboolean isStatic) {
- return functions->ToReflectedField(this,cls,fieldID,isStatic);
- }
-
- jint Throw(jthrowable obj) {
- return functions->Throw(this, obj);
- }
- jint ThrowNew(jclass clazz, const char *msg) {
- return functions->ThrowNew(this, clazz, msg);
- }
- jthrowable ExceptionOccurred() {
- return functions->ExceptionOccurred(this);
- }
- void ExceptionDescribe() {
- functions->ExceptionDescribe(this);
- }
- void ExceptionClear() {
- functions->ExceptionClear(this);
- }
- void FatalError(const char *msg) {
- functions->FatalError(this, msg);
- }
-
- jint PushLocalFrame(jint capacity) {
- return functions->PushLocalFrame(this,capacity);
- }
- jobject PopLocalFrame(jobject result) {
- return functions->PopLocalFrame(this,result);
- }
-
- jobject NewGlobalRef(jobject lobj) {
- return functions->NewGlobalRef(this,lobj);
- }
- void DeleteGlobalRef(jobject gref) {
- functions->DeleteGlobalRef(this,gref);
- }
- void DeleteLocalRef(jobject obj) {
- functions->DeleteLocalRef(this, obj);
- }
-
- jboolean IsSameObject(jobject obj1, jobject obj2) {
- return functions->IsSameObject(this,obj1,obj2);
- }
-
- jobject NewLocalRef(jobject ref) {
- return functions->NewLocalRef(this,ref);
- }
- jint EnsureLocalCapacity(jint capacity) {
- return functions->EnsureLocalCapacity(this,capacity);
- }
-
- jobject AllocObject(jclass clazz) {
- return functions->AllocObject(this,clazz);
- }
- jobject NewObject(jclass clazz, jmethodID methodID, ...) {
- va_list args;
- jobject result;
- va_start(args, methodID);
- result = functions->NewObjectV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jobject NewObjectV(jclass clazz, jmethodID methodID,
- va_list args) {
- return functions->NewObjectV(this,clazz,methodID,args);
- }
- jobject NewObjectA(jclass clazz, jmethodID methodID,
- const jvalue *args) {
- return functions->NewObjectA(this,clazz,methodID,args);
- }
-
- jclass GetObjectClass(jobject obj) {
- return functions->GetObjectClass(this,obj);
- }
- jboolean IsInstanceOf(jobject obj, jclass clazz) {
- return functions->IsInstanceOf(this,obj,clazz);
- }
-
- jmethodID GetMethodID(jclass clazz, const char *name,
- const char *sig) {
- return functions->GetMethodID(this,clazz,name,sig);
- }
-
- jobject CallObjectMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jobject result;
- va_start(args,methodID);
- result = functions->CallObjectMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jobject CallObjectMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallObjectMethodV(this,obj,methodID,args);
- }
- jobject CallObjectMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallObjectMethodA(this,obj,methodID,args);
- }
-
- jboolean CallBooleanMethod(jobject obj,
- jmethodID methodID, ...) {
- va_list args;
- jboolean result;
- va_start(args,methodID);
- result = functions->CallBooleanMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jboolean CallBooleanMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallBooleanMethodV(this,obj,methodID,args);
- }
- jboolean CallBooleanMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallBooleanMethodA(this,obj,methodID, args);
- }
-
- jbyte CallByteMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jbyte result;
- va_start(args,methodID);
- result = functions->CallByteMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jbyte CallByteMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallByteMethodV(this,obj,methodID,args);
- }
- jbyte CallByteMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallByteMethodA(this,obj,methodID,args);
- }
-
- jchar CallCharMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jchar result;
- va_start(args,methodID);
- result = functions->CallCharMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jchar CallCharMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallCharMethodV(this,obj,methodID,args);
- }
- jchar CallCharMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallCharMethodA(this,obj,methodID,args);
- }
-
- jshort CallShortMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jshort result;
- va_start(args,methodID);
- result = functions->CallShortMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jshort CallShortMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallShortMethodV(this,obj,methodID,args);
- }
- jshort CallShortMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallShortMethodA(this,obj,methodID,args);
- }
-
- jint CallIntMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jint result;
- va_start(args,methodID);
- result = functions->CallIntMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jint CallIntMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallIntMethodV(this,obj,methodID,args);
- }
- jint CallIntMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallIntMethodA(this,obj,methodID,args);
- }
-
- jlong CallLongMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jlong result;
- va_start(args,methodID);
- result = functions->CallLongMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jlong CallLongMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallLongMethodV(this,obj,methodID,args);
- }
- jlong CallLongMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallLongMethodA(this,obj,methodID,args);
- }
-
- jfloat CallFloatMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jfloat result;
- va_start(args,methodID);
- result = functions->CallFloatMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jfloat CallFloatMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallFloatMethodV(this,obj,methodID,args);
- }
- jfloat CallFloatMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallFloatMethodA(this,obj,methodID,args);
- }
-
- jdouble CallDoubleMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- jdouble result;
- va_start(args,methodID);
- result = functions->CallDoubleMethodV(this,obj,methodID,args);
- va_end(args);
- return result;
- }
- jdouble CallDoubleMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- return functions->CallDoubleMethodV(this,obj,methodID,args);
- }
- jdouble CallDoubleMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- return functions->CallDoubleMethodA(this,obj,methodID,args);
- }
-
- void CallVoidMethod(jobject obj, jmethodID methodID, ...) {
- va_list args;
- va_start(args,methodID);
- functions->CallVoidMethodV(this,obj,methodID,args);
- va_end(args);
- }
- void CallVoidMethodV(jobject obj, jmethodID methodID,
- va_list args) {
- functions->CallVoidMethodV(this,obj,methodID,args);
- }
- void CallVoidMethodA(jobject obj, jmethodID methodID,
- const jvalue * args) {
- functions->CallVoidMethodA(this,obj,methodID,args);
- }
-
- jobject CallNonvirtualObjectMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jobject result;
- va_start(args,methodID);
- result = functions->CallNonvirtualObjectMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jobject CallNonvirtualObjectMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualObjectMethodV(this,obj,clazz,
- methodID,args);
- }
- jobject CallNonvirtualObjectMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualObjectMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jboolean CallNonvirtualBooleanMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jboolean result;
- va_start(args,methodID);
- result = functions->CallNonvirtualBooleanMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jboolean CallNonvirtualBooleanMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualBooleanMethodV(this,obj,clazz,
- methodID,args);
- }
- jboolean CallNonvirtualBooleanMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualBooleanMethodA(this,obj,clazz,
- methodID, args);
- }
-
- jbyte CallNonvirtualByteMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jbyte result;
- va_start(args,methodID);
- result = functions->CallNonvirtualByteMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jbyte CallNonvirtualByteMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualByteMethodV(this,obj,clazz,
- methodID,args);
- }
- jbyte CallNonvirtualByteMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualByteMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jchar CallNonvirtualCharMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jchar result;
- va_start(args,methodID);
- result = functions->CallNonvirtualCharMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jchar CallNonvirtualCharMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualCharMethodV(this,obj,clazz,
- methodID,args);
- }
- jchar CallNonvirtualCharMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualCharMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jshort CallNonvirtualShortMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jshort result;
- va_start(args,methodID);
- result = functions->CallNonvirtualShortMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jshort CallNonvirtualShortMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualShortMethodV(this,obj,clazz,
- methodID,args);
- }
- jshort CallNonvirtualShortMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualShortMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jint CallNonvirtualIntMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jint result;
- va_start(args,methodID);
- result = functions->CallNonvirtualIntMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jint CallNonvirtualIntMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualIntMethodV(this,obj,clazz,
- methodID,args);
- }
- jint CallNonvirtualIntMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualIntMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jlong CallNonvirtualLongMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jlong result;
- va_start(args,methodID);
- result = functions->CallNonvirtualLongMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jlong CallNonvirtualLongMethodV(jobject obj, jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallNonvirtualLongMethodV(this,obj,clazz,
- methodID,args);
- }
- jlong CallNonvirtualLongMethodA(jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args) {
- return functions->CallNonvirtualLongMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jfloat CallNonvirtualFloatMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jfloat result;
- va_start(args,methodID);
- result = functions->CallNonvirtualFloatMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jfloat CallNonvirtualFloatMethodV(jobject obj, jclass clazz,
- jmethodID methodID,
- va_list args) {
- return functions->CallNonvirtualFloatMethodV(this,obj,clazz,
- methodID,args);
- }
- jfloat CallNonvirtualFloatMethodA(jobject obj, jclass clazz,
- jmethodID methodID,
- const jvalue * args) {
- return functions->CallNonvirtualFloatMethodA(this,obj,clazz,
- methodID,args);
- }
-
- jdouble CallNonvirtualDoubleMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jdouble result;
- va_start(args,methodID);
- result = functions->CallNonvirtualDoubleMethodV(this,obj,clazz,
- methodID,args);
- va_end(args);
- return result;
- }
- jdouble CallNonvirtualDoubleMethodV(jobject obj, jclass clazz,
- jmethodID methodID,
- va_list args) {
- return functions->CallNonvirtualDoubleMethodV(this,obj,clazz,
- methodID,args);
- }
- jdouble CallNonvirtualDoubleMethodA(jobject obj, jclass clazz,
- jmethodID methodID,
- const jvalue * args) {
- return functions->CallNonvirtualDoubleMethodA(this,obj,clazz,
- methodID,args);
- }
-
- void CallNonvirtualVoidMethod(jobject obj, jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- va_start(args,methodID);
- functions->CallNonvirtualVoidMethodV(this,obj,clazz,methodID,args);
- va_end(args);
- }
- void CallNonvirtualVoidMethodV(jobject obj, jclass clazz,
- jmethodID methodID,
- va_list args) {
- functions->CallNonvirtualVoidMethodV(this,obj,clazz,methodID,args);
- }
- void CallNonvirtualVoidMethodA(jobject obj, jclass clazz,
- jmethodID methodID,
- const jvalue * args) {
- functions->CallNonvirtualVoidMethodA(this,obj,clazz,methodID,args);
- }
-
- jfieldID GetFieldID(jclass clazz, const char *name,
- const char *sig) {
- return functions->GetFieldID(this,clazz,name,sig);
- }
-
- jobject GetObjectField(jobject obj, jfieldID fieldID) {
- return functions->GetObjectField(this,obj,fieldID);
- }
- jboolean GetBooleanField(jobject obj, jfieldID fieldID) {
- return functions->GetBooleanField(this,obj,fieldID);
- }
- jbyte GetByteField(jobject obj, jfieldID fieldID) {
- return functions->GetByteField(this,obj,fieldID);
- }
- jchar GetCharField(jobject obj, jfieldID fieldID) {
- return functions->GetCharField(this,obj,fieldID);
- }
- jshort GetShortField(jobject obj, jfieldID fieldID) {
- return functions->GetShortField(this,obj,fieldID);
- }
- jint GetIntField(jobject obj, jfieldID fieldID) {
- return functions->GetIntField(this,obj,fieldID);
- }
- jlong GetLongField(jobject obj, jfieldID fieldID) {
- return functions->GetLongField(this,obj,fieldID);
- }
- jfloat GetFloatField(jobject obj, jfieldID fieldID) {
- return functions->GetFloatField(this,obj,fieldID);
- }
- jdouble GetDoubleField(jobject obj, jfieldID fieldID) {
- return functions->GetDoubleField(this,obj,fieldID);
- }
-
- void SetObjectField(jobject obj, jfieldID fieldID, jobject val) {
- functions->SetObjectField(this,obj,fieldID,val);
- }
- void SetBooleanField(jobject obj, jfieldID fieldID,
- jboolean val) {
- functions->SetBooleanField(this,obj,fieldID,val);
- }
- void SetByteField(jobject obj, jfieldID fieldID,
- jbyte val) {
- functions->SetByteField(this,obj,fieldID,val);
- }
- void SetCharField(jobject obj, jfieldID fieldID,
- jchar val) {
- functions->SetCharField(this,obj,fieldID,val);
- }
- void SetShortField(jobject obj, jfieldID fieldID,
- jshort val) {
- functions->SetShortField(this,obj,fieldID,val);
- }
- void SetIntField(jobject obj, jfieldID fieldID,
- jint val) {
- functions->SetIntField(this,obj,fieldID,val);
- }
- void SetLongField(jobject obj, jfieldID fieldID,
- jlong val) {
- functions->SetLongField(this,obj,fieldID,val);
- }
- void SetFloatField(jobject obj, jfieldID fieldID,
- jfloat val) {
- functions->SetFloatField(this,obj,fieldID,val);
- }
- void SetDoubleField(jobject obj, jfieldID fieldID,
- jdouble val) {
- functions->SetDoubleField(this,obj,fieldID,val);
- }
-
- jmethodID GetStaticMethodID(jclass clazz, const char *name,
- const char *sig) {
- return functions->GetStaticMethodID(this,clazz,name,sig);
- }
-
- jobject CallStaticObjectMethod(jclass clazz, jmethodID methodID,
- ...) {
- va_list args;
- jobject result;
- va_start(args,methodID);
- result = functions->CallStaticObjectMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jobject CallStaticObjectMethodV(jclass clazz, jmethodID methodID,
- va_list args) {
- return functions->CallStaticObjectMethodV(this,clazz,methodID,args);
- }
- jobject CallStaticObjectMethodA(jclass clazz, jmethodID methodID,
- const jvalue *args) {
- return functions->CallStaticObjectMethodA(this,clazz,methodID,args);
- }
-
- jboolean CallStaticBooleanMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jboolean result;
- va_start(args,methodID);
- result = functions->CallStaticBooleanMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jboolean CallStaticBooleanMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticBooleanMethodV(this,clazz,methodID,args);
- }
- jboolean CallStaticBooleanMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticBooleanMethodA(this,clazz,methodID,args);
- }
-
- jbyte CallStaticByteMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jbyte result;
- va_start(args,methodID);
- result = functions->CallStaticByteMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jbyte CallStaticByteMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticByteMethodV(this,clazz,methodID,args);
- }
- jbyte CallStaticByteMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticByteMethodA(this,clazz,methodID,args);
- }
-
- jchar CallStaticCharMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jchar result;
- va_start(args,methodID);
- result = functions->CallStaticCharMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jchar CallStaticCharMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticCharMethodV(this,clazz,methodID,args);
- }
- jchar CallStaticCharMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticCharMethodA(this,clazz,methodID,args);
- }
-
- jshort CallStaticShortMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jshort result;
- va_start(args,methodID);
- result = functions->CallStaticShortMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jshort CallStaticShortMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticShortMethodV(this,clazz,methodID,args);
- }
- jshort CallStaticShortMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticShortMethodA(this,clazz,methodID,args);
- }
-
- jint CallStaticIntMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jint result;
- va_start(args,methodID);
- result = functions->CallStaticIntMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jint CallStaticIntMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticIntMethodV(this,clazz,methodID,args);
- }
- jint CallStaticIntMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticIntMethodA(this,clazz,methodID,args);
- }
-
- jlong CallStaticLongMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jlong result;
- va_start(args,methodID);
- result = functions->CallStaticLongMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jlong CallStaticLongMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticLongMethodV(this,clazz,methodID,args);
- }
- jlong CallStaticLongMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticLongMethodA(this,clazz,methodID,args);
- }
-
- jfloat CallStaticFloatMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jfloat result;
- va_start(args,methodID);
- result = functions->CallStaticFloatMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jfloat CallStaticFloatMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticFloatMethodV(this,clazz,methodID,args);
- }
- jfloat CallStaticFloatMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticFloatMethodA(this,clazz,methodID,args);
- }
-
- jdouble CallStaticDoubleMethod(jclass clazz,
- jmethodID methodID, ...) {
- va_list args;
- jdouble result;
- va_start(args,methodID);
- result = functions->CallStaticDoubleMethodV(this,clazz,methodID,args);
- va_end(args);
- return result;
- }
- jdouble CallStaticDoubleMethodV(jclass clazz,
- jmethodID methodID, va_list args) {
- return functions->CallStaticDoubleMethodV(this,clazz,methodID,args);
- }
- jdouble CallStaticDoubleMethodA(jclass clazz,
- jmethodID methodID, const jvalue *args) {
- return functions->CallStaticDoubleMethodA(this,clazz,methodID,args);
- }
-
- void CallStaticVoidMethod(jclass cls, jmethodID methodID, ...) {
- va_list args;
- va_start(args,methodID);
- functions->CallStaticVoidMethodV(this,cls,methodID,args);
- va_end(args);
- }
- void CallStaticVoidMethodV(jclass cls, jmethodID methodID,
- va_list args) {
- functions->CallStaticVoidMethodV(this,cls,methodID,args);
- }
- void CallStaticVoidMethodA(jclass cls, jmethodID methodID,
- const jvalue * args) {
- functions->CallStaticVoidMethodA(this,cls,methodID,args);
- }
-
- jfieldID GetStaticFieldID(jclass clazz, const char *name,
- const char *sig) {
- return functions->GetStaticFieldID(this,clazz,name,sig);
- }
- jobject GetStaticObjectField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticObjectField(this,clazz,fieldID);
- }
- jboolean GetStaticBooleanField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticBooleanField(this,clazz,fieldID);
- }
- jbyte GetStaticByteField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticByteField(this,clazz,fieldID);
- }
- jchar GetStaticCharField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticCharField(this,clazz,fieldID);
- }
- jshort GetStaticShortField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticShortField(this,clazz,fieldID);
- }
- jint GetStaticIntField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticIntField(this,clazz,fieldID);
- }
- jlong GetStaticLongField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticLongField(this,clazz,fieldID);
- }
- jfloat GetStaticFloatField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticFloatField(this,clazz,fieldID);
- }
- jdouble GetStaticDoubleField(jclass clazz, jfieldID fieldID) {
- return functions->GetStaticDoubleField(this,clazz,fieldID);
- }
-
- void SetStaticObjectField(jclass clazz, jfieldID fieldID,
- jobject value) {
- functions->SetStaticObjectField(this,clazz,fieldID,value);
- }
- void SetStaticBooleanField(jclass clazz, jfieldID fieldID,
- jboolean value) {
- functions->SetStaticBooleanField(this,clazz,fieldID,value);
- }
- void SetStaticByteField(jclass clazz, jfieldID fieldID,
- jbyte value) {
- functions->SetStaticByteField(this,clazz,fieldID,value);
- }
- void SetStaticCharField(jclass clazz, jfieldID fieldID,
- jchar value) {
- functions->SetStaticCharField(this,clazz,fieldID,value);
- }
- void SetStaticShortField(jclass clazz, jfieldID fieldID,
- jshort value) {
- functions->SetStaticShortField(this,clazz,fieldID,value);
- }
- void SetStaticIntField(jclass clazz, jfieldID fieldID,
- jint value) {
- functions->SetStaticIntField(this,clazz,fieldID,value);
- }
- void SetStaticLongField(jclass clazz, jfieldID fieldID,
- jlong value) {
- functions->SetStaticLongField(this,clazz,fieldID,value);
- }
- void SetStaticFloatField(jclass clazz, jfieldID fieldID,
- jfloat value) {
- functions->SetStaticFloatField(this,clazz,fieldID,value);
- }
- void SetStaticDoubleField(jclass clazz, jfieldID fieldID,
- jdouble value) {
- functions->SetStaticDoubleField(this,clazz,fieldID,value);
- }
-
- jstring NewString(const jchar *unicode, jsize len) {
- return functions->NewString(this,unicode,len);
- }
- jsize GetStringLength(jstring str) {
- return functions->GetStringLength(this,str);
- }
- const jchar *GetStringChars(jstring str, jboolean *isCopy) {
- return functions->GetStringChars(this,str,isCopy);
- }
- void ReleaseStringChars(jstring str, const jchar *chars) {
- functions->ReleaseStringChars(this,str,chars);
- }
-
- jstring NewStringUTF(const char *utf) {
- return functions->NewStringUTF(this,utf);
- }
- jsize GetStringUTFLength(jstring str) {
- return functions->GetStringUTFLength(this,str);
- }
- const char* GetStringUTFChars(jstring str, jboolean *isCopy) {
- return functions->GetStringUTFChars(this,str,isCopy);
- }
- void ReleaseStringUTFChars(jstring str, const char* chars) {
- functions->ReleaseStringUTFChars(this,str,chars);
- }
-
- jsize GetArrayLength(jarray array) {
- return functions->GetArrayLength(this,array);
- }
-
- jobjectArray NewObjectArray(jsize len, jclass clazz,
- jobject init) {
- return functions->NewObjectArray(this,len,clazz,init);
- }
- jobject GetObjectArrayElement(jobjectArray array, jsize index) {
- return functions->GetObjectArrayElement(this,array,index);
- }
- void SetObjectArrayElement(jobjectArray array, jsize index,
- jobject val) {
- functions->SetObjectArrayElement(this,array,index,val);
- }
-
- jbooleanArray NewBooleanArray(jsize len) {
- return functions->NewBooleanArray(this,len);
- }
- jbyteArray NewByteArray(jsize len) {
- return functions->NewByteArray(this,len);
- }
- jcharArray NewCharArray(jsize len) {
- return functions->NewCharArray(this,len);
- }
- jshortArray NewShortArray(jsize len) {
- return functions->NewShortArray(this,len);
- }
- jintArray NewIntArray(jsize len) {
- return functions->NewIntArray(this,len);
- }
- jlongArray NewLongArray(jsize len) {
- return functions->NewLongArray(this,len);
- }
- jfloatArray NewFloatArray(jsize len) {
- return functions->NewFloatArray(this,len);
- }
- jdoubleArray NewDoubleArray(jsize len) {
- return functions->NewDoubleArray(this,len);
- }
-
- jboolean * GetBooleanArrayElements(jbooleanArray array, jboolean *isCopy) {
- return functions->GetBooleanArrayElements(this,array,isCopy);
- }
- jbyte * GetByteArrayElements(jbyteArray array, jboolean *isCopy) {
- return functions->GetByteArrayElements(this,array,isCopy);
- }
- jchar * GetCharArrayElements(jcharArray array, jboolean *isCopy) {
- return functions->GetCharArrayElements(this,array,isCopy);
- }
- jshort * GetShortArrayElements(jshortArray array, jboolean *isCopy) {
- return functions->GetShortArrayElements(this,array,isCopy);
- }
- jint * GetIntArrayElements(jintArray array, jboolean *isCopy) {
- return functions->GetIntArrayElements(this,array,isCopy);
- }
- jlong * GetLongArrayElements(jlongArray array, jboolean *isCopy) {
- return functions->GetLongArrayElements(this,array,isCopy);
- }
- jfloat * GetFloatArrayElements(jfloatArray array, jboolean *isCopy) {
- return functions->GetFloatArrayElements(this,array,isCopy);
- }
- jdouble * GetDoubleArrayElements(jdoubleArray array, jboolean *isCopy) {
- return functions->GetDoubleArrayElements(this,array,isCopy);
- }
-
- void ReleaseBooleanArrayElements(jbooleanArray array,
- jboolean *elems,
- jint mode) {
- functions->ReleaseBooleanArrayElements(this,array,elems,mode);
- }
- void ReleaseByteArrayElements(jbyteArray array,
- jbyte *elems,
- jint mode) {
- functions->ReleaseByteArrayElements(this,array,elems,mode);
- }
- void ReleaseCharArrayElements(jcharArray array,
- jchar *elems,
- jint mode) {
- functions->ReleaseCharArrayElements(this,array,elems,mode);
- }
- void ReleaseShortArrayElements(jshortArray array,
- jshort *elems,
- jint mode) {
- functions->ReleaseShortArrayElements(this,array,elems,mode);
- }
- void ReleaseIntArrayElements(jintArray array,
- jint *elems,
- jint mode) {
- functions->ReleaseIntArrayElements(this,array,elems,mode);
- }
- void ReleaseLongArrayElements(jlongArray array,
- jlong *elems,
- jint mode) {
- functions->ReleaseLongArrayElements(this,array,elems,mode);
- }
- void ReleaseFloatArrayElements(jfloatArray array,
- jfloat *elems,
- jint mode) {
- functions->ReleaseFloatArrayElements(this,array,elems,mode);
- }
- void ReleaseDoubleArrayElements(jdoubleArray array,
- jdouble *elems,
- jint mode) {
- functions->ReleaseDoubleArrayElements(this,array,elems,mode);
- }
-
- void GetBooleanArrayRegion(jbooleanArray array,
- jsize start, jsize len, jboolean *buf) {
- functions->GetBooleanArrayRegion(this,array,start,len,buf);
- }
- void GetByteArrayRegion(jbyteArray array,
- jsize start, jsize len, jbyte *buf) {
- functions->GetByteArrayRegion(this,array,start,len,buf);
- }
- void GetCharArrayRegion(jcharArray array,
- jsize start, jsize len, jchar *buf) {
- functions->GetCharArrayRegion(this,array,start,len,buf);
- }
- void GetShortArrayRegion(jshortArray array,
- jsize start, jsize len, jshort *buf) {
- functions->GetShortArrayRegion(this,array,start,len,buf);
- }
- void GetIntArrayRegion(jintArray array,
- jsize start, jsize len, jint *buf) {
- functions->GetIntArrayRegion(this,array,start,len,buf);
- }
- void GetLongArrayRegion(jlongArray array,
- jsize start, jsize len, jlong *buf) {
- functions->GetLongArrayRegion(this,array,start,len,buf);
- }
- void GetFloatArrayRegion(jfloatArray array,
- jsize start, jsize len, jfloat *buf) {
- functions->GetFloatArrayRegion(this,array,start,len,buf);
- }
- void GetDoubleArrayRegion(jdoubleArray array,
- jsize start, jsize len, jdouble *buf) {
- functions->GetDoubleArrayRegion(this,array,start,len,buf);
- }
-
- void SetBooleanArrayRegion(jbooleanArray array, jsize start, jsize len,
- const jboolean *buf) {
- functions->SetBooleanArrayRegion(this,array,start,len,buf);
- }
- void SetByteArrayRegion(jbyteArray array, jsize start, jsize len,
- const jbyte *buf) {
- functions->SetByteArrayRegion(this,array,start,len,buf);
- }
- void SetCharArrayRegion(jcharArray array, jsize start, jsize len,
- const jchar *buf) {
- functions->SetCharArrayRegion(this,array,start,len,buf);
- }
- void SetShortArrayRegion(jshortArray array, jsize start, jsize len,
- const jshort *buf) {
- functions->SetShortArrayRegion(this,array,start,len,buf);
- }
- void SetIntArrayRegion(jintArray array, jsize start, jsize len,
- const jint *buf) {
- functions->SetIntArrayRegion(this,array,start,len,buf);
- }
- void SetLongArrayRegion(jlongArray array, jsize start, jsize len,
- const jlong *buf) {
- functions->SetLongArrayRegion(this,array,start,len,buf);
- }
- void SetFloatArrayRegion(jfloatArray array, jsize start, jsize len,
- const jfloat *buf) {
- functions->SetFloatArrayRegion(this,array,start,len,buf);
- }
- void SetDoubleArrayRegion(jdoubleArray array, jsize start, jsize len,
- const jdouble *buf) {
- functions->SetDoubleArrayRegion(this,array,start,len,buf);
- }
-
- jint RegisterNatives(jclass clazz, const JNINativeMethod *methods,
- jint nMethods) {
- return functions->RegisterNatives(this,clazz,methods,nMethods);
- }
- jint UnregisterNatives(jclass clazz) {
- return functions->UnregisterNatives(this,clazz);
- }
-
- jint MonitorEnter(jobject obj) {
- return functions->MonitorEnter(this,obj);
- }
- jint MonitorExit(jobject obj) {
- return functions->MonitorExit(this,obj);
- }
-
- jint GetJavaVM(JavaVM **vm) {
- return functions->GetJavaVM(this,vm);
- }
-
- void GetStringRegion(jstring str, jsize start, jsize len, jchar *buf) {
- functions->GetStringRegion(this,str,start,len,buf);
- }
- void GetStringUTFRegion(jstring str, jsize start, jsize len, char *buf) {
- functions->GetStringUTFRegion(this,str,start,len,buf);
- }
-
- void * GetPrimitiveArrayCritical(jarray array, jboolean *isCopy) {
- return functions->GetPrimitiveArrayCritical(this,array,isCopy);
- }
- void ReleasePrimitiveArrayCritical(jarray array, void *carray, jint mode) {
- functions->ReleasePrimitiveArrayCritical(this,array,carray,mode);
- }
-
- const jchar * GetStringCritical(jstring string, jboolean *isCopy) {
- return functions->GetStringCritical(this,string,isCopy);
- }
- void ReleaseStringCritical(jstring string, const jchar *cstring) {
- functions->ReleaseStringCritical(this,string,cstring);
- }
-
- jweak NewWeakGlobalRef(jobject obj) {
- return functions->NewWeakGlobalRef(this,obj);
- }
- void DeleteWeakGlobalRef(jweak ref) {
- functions->DeleteWeakGlobalRef(this,ref);
- }
-
- jboolean ExceptionCheck() {
- return functions->ExceptionCheck(this);
- }
-
- jobject NewDirectByteBuffer(void* address, jlong capacity) {
- return functions->NewDirectByteBuffer(this, address, capacity);
- }
- void* GetDirectBufferAddress(jobject buf) {
- return functions->GetDirectBufferAddress(this, buf);
- }
- jlong GetDirectBufferCapacity(jobject buf) {
- return functions->GetDirectBufferCapacity(this, buf);
- }
- jobjectRefType GetObjectRefType(jobject obj) {
- return functions->GetObjectRefType(this, obj);
- }
-
-#endif /* __cplusplus */
-};
-
-typedef struct JavaVMOption {
- char *optionString;
- void *extraInfo;
-} JavaVMOption;
-
-typedef struct JavaVMInitArgs {
- jint version;
-
- jint nOptions;
- JavaVMOption *options;
- jboolean ignoreUnrecognized;
-} JavaVMInitArgs;
-
-typedef struct JavaVMAttachArgs {
- jint version;
-
- char *name;
- jobject group;
-} JavaVMAttachArgs;
-
-/* These will be VM-specific. */
-
-#define JDK1_2
-#define JDK1_4
-
-/* End VM-specific. */
-
-struct JNIInvokeInterface_ {
- void *reserved0;
- void *reserved1;
- void *reserved2;
-
-#if !TARGET_RT_MAC_CFM && defined(__ppc__)
- void* cfm_vectors[4];
-#endif /* !TARGET_RT_MAC_CFM && defined(__ppc__) */
-
- jint (JNICALL *DestroyJavaVM)(JavaVM *vm);
-
- jint (JNICALL *AttachCurrentThread)(JavaVM *vm, void **penv, void *args);
-
- jint (JNICALL *DetachCurrentThread)(JavaVM *vm);
-
- jint (JNICALL *GetEnv)(JavaVM *vm, void **penv, jint version);
-
- jint (JNICALL *AttachCurrentThreadAsDaemon)(JavaVM *vm, void **penv, void *args);
-
-#if TARGET_RT_MAC_CFM && defined(__ppc__)
- void* real_functions[5];
-#endif /* TARGET_RT_MAC_CFM && defined(__ppc__) */
-};
-
-struct JavaVM_ {
- const struct JNIInvokeInterface_ *functions;
-#ifdef __cplusplus
-
- jint DestroyJavaVM() {
- return functions->DestroyJavaVM(this);
- }
- jint AttachCurrentThread(void **penv, void *args) {
- return functions->AttachCurrentThread(this, penv, args);
- }
- jint DetachCurrentThread() {
- return functions->DetachCurrentThread(this);
- }
-
- jint GetEnv(void **penv, jint version) {
- return functions->GetEnv(this, penv, version);
- }
- jint AttachCurrentThreadAsDaemon(void **penv, void *args) {
- return functions->AttachCurrentThreadAsDaemon(this, penv, args);
- }
-#endif
-};
-
-#ifdef _JNI_IMPLEMENTATION_
-#define _JNI_IMPORT_OR_EXPORT_ JNIEXPORT
-#else
-#define _JNI_IMPORT_OR_EXPORT_ JNIIMPORT
-#endif
-_JNI_IMPORT_OR_EXPORT_ jint JNICALL
-JNI_GetDefaultJavaVMInitArgs(void *args);
-
-_JNI_IMPORT_OR_EXPORT_ jint JNICALL
-JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *args);
-
-_JNI_IMPORT_OR_EXPORT_ jint JNICALL
-JNI_GetCreatedJavaVMs(JavaVM **, jsize, jsize *);
-
-/* Defined by native libraries. */
-JNIEXPORT jint JNICALL
-JNI_OnLoad(JavaVM *vm, void *reserved);
-
-JNIEXPORT void JNICALL
-JNI_OnUnload(JavaVM *vm, void *reserved);
-
-#define JNI_VERSION_1_1 0x00010001
-#define JNI_VERSION_1_2 0x00010002
-#define JNI_VERSION_1_4 0x00010004
-#define JNI_VERSION_1_6 0x00010006
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif /* __cplusplus */
-
-#endif /* !_JAVASOFT_JNI_H_ */
-
-
-
diff --git a/src/main/c/jni/jni_md.h b/src/main/c/jni/jni_md.h
deleted file mode 100644
index 7a2116f..0000000
--- a/src/main/c/jni/jni_md.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * @(#)jni_md.h 1.19 05/11/17
- *
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
- */
-
-#ifndef _JAVASOFT_JNI_MD_H_
-#define _JAVASOFT_JNI_MD_H_
-
-#define JNIEXPORT __attribute__((visibility("default")))
-#define JNIIMPORT
-#define JNICALL
-
-#if __LP64__
-typedef int jint;
-#else
-typedef long jint;
-#endif
-typedef long long jlong;
-typedef signed char jbyte;
-
-#endif /* !_JAVASOFT_JNI_MD_H_ */
diff --git a/src/main/java/org/gmssl/GmSSLException.java b/src/main/java/org/gmssl/GmSSLException.java
index 011e66e..393db56 100644
--- a/src/main/java/org/gmssl/GmSSLException.java
+++ b/src/main/java/org/gmssl/GmSSLException.java
@@ -9,6 +9,9 @@
package org.gmssl;
+/**
+ * @author gmssl
+ */
public class GmSSLException extends RuntimeException {
public GmSSLException(String reason) {
diff --git a/src/main/java/org/gmssl/GmSSLJNI.java b/src/main/java/org/gmssl/GmSSLJNI.java
index daaf827..64e6dbb 100644
--- a/src/main/java/org/gmssl/GmSSLJNI.java
+++ b/src/main/java/org/gmssl/GmSSLJNI.java
@@ -11,7 +11,7 @@
public class GmSSLJNI {
- public final static String GMSSL_JNI_VERSION = "GmSSL JNI 2.1.0 dev";
+ public final static String GMSSL_JNI_VERSION = "GmSSL JNI 3.1.1";
public final static int SM3_DIGEST_SIZE = 32;
public final static int SM3_HMAC_SIZE = 32;
@@ -357,6 +357,6 @@ public static void main(String[] args) {
}
static {
- NativeLoader.load("libgmssljni");
+ NativeLoader.load(NativeLoader.GMSSLJNILIB_NAME);
}
}
diff --git a/src/main/java/org/gmssl/NativeLoader.java b/src/main/java/org/gmssl/NativeLoader.java
index c21cc1b..dc119b8 100644
--- a/src/main/java/org/gmssl/NativeLoader.java
+++ b/src/main/java/org/gmssl/NativeLoader.java
@@ -9,12 +9,11 @@
package org.gmssl;
import java.io.*;
-import java.net.URL;
-import java.nio.channels.Channels;
-import java.nio.channels.FileChannel;
-import java.nio.channels.ReadableByteChannel;
-import java.util.Arrays;
-import java.util.concurrent.CopyOnWriteArraySet;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import java.util.Properties;
/**
* @author yongfei.li
@@ -24,53 +23,50 @@
*/
public class NativeLoader {
- private static final CopyOnWriteArraySet LOADED_LIBARAY_SET=new CopyOnWriteArraySet<>();
-
/* custom jni library prefix path relative to project resources */
private static final String RESOURCELIB_PREFIXPATH = "lib";
+ static final String GMSSLJNILIB_NAME="libgmssljni";
+
+ private static final Properties PROPERTIES = new Properties();
+
+ static {
+ try (InputStream input = NativeLoader.class.getClassLoader().getResourceAsStream("config.properties")) {
+ if (input == null) {
+ throw new GmSSLException("can't find config file: config.properties");
+ }
+ PROPERTIES.load(input);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new GmSSLException("can't load config file: config.properties");
+ }
+ }
+
/**
- * load jin lib:
- * load personal jni library,the path must be a full path relative to the operating system,the lib file extension must be given too.
- * load custom jni library,the default path is resources/lib of this project,load the corresponding class library according to the operating system.
- * load the corresponding system jni library according to the operating system.
- * @param libaray ... lib path eg:/home/lib/libxxx.so,/gmssl/libxxx,libxxx
+ * load jni lib from resources path,the parameter does not contain the path and suffix.
+ * @param libaray libarayName
*
*/
- public synchronized static void load (String... libaray){
- if(null == libaray || libaray.length<1){
- throw new GmSSLException("Library is empty exception!");
- }
- for(String lib:libaray){
- if(LOADED_LIBARAY_SET.contains(lib)){
- continue;
- }
- //load personal jni library,the path must be a full path relative to the operating system,the lib file extension must be given too.
- File personalLibFile = new File(lib).getAbsoluteFile();
- if(personalLibFile.exists() && personalLibFile.isFile()){
- loadLibFile(personalLibFile,lib);
- }else{
- //load custom jni library,the default path is resources/lib of this project,load the corresponding class library according to the operating system.
- String resourceLibPath=RESOURCELIB_PREFIXPATH+"/" + platform()+"/"+lib+"."+libExtension();
- URL resourceUrl = NativeLoader.class.getClassLoader().getResource(resourceLibPath);
- if(null !=resourceUrl){
- File tmpLibFile= createTmpLibFile(resourceLibPath);
- loadLibFile(tmpLibFile,lib);
- tmpLibFile.deleteOnExit();
- }else{
- //load the corresponding system jni library according to the operating system.
- String[] sysLibPathS = System.getProperty("java.library.path").split(File.pathSeparator);
- for(String sysLibPath:sysLibPathS){
- File sysLibFile = new File(sysLibPath, lib+"."+libExtension()).getAbsoluteFile();
- loadLibFile(sysLibFile,lib);
- break;
- }
- }
+ public synchronized static void load (String libaray){
+ String resourceLibPath = RESOURCELIB_PREFIXPATH + "/" + libaray + "." + libExtension();
+ try (InputStream inputStream = NativeLoader.class.getClassLoader().getResourceAsStream(resourceLibPath)) {
+ if (null == inputStream) {
+ throw new GmSSLException("lib file not found in JAR: " + resourceLibPath);
}
-
+ Path tempFile = Files.createTempFile(libaray, "."+libExtension());
+ tempFile.toFile().deleteOnExit();
+ Files.copy(inputStream, tempFile, StandardCopyOption.REPLACE_EXISTING);
+ checkReferencedLib();
+ System.load(tempFile.toAbsolutePath().toString());
+ } catch (Exception e) {
+ throw new GmSSLException("Unable to load lib from JAR");
}
}
+ /**
+ * Get the operating system type.
+ * @return operating system name
+ */
static String osType(){
String os="unknown";
String osName = System.getProperty("os.name").toLowerCase();
@@ -89,24 +85,12 @@ static String osType(){
os="osx";
}
return os;
-
- }
-
- static String archType(){
- String arch="unknown";
- String archName = System.getProperty("os.arch").toLowerCase();
- if ("i386".equals(archName) || "i686".equals(archName)){
- arch="x86";
- }
- if ("x86_64".equals(archName) || "amd64".equals(archName)){
- arch="x86_64";
- }
- if ("arm".equals(archName)) {
- arch = "arm";
- }
- return arch;
}
+ /**
+ * Get the library extension name based on the operating system type.
+ * @return extension name
+ */
static String libExtension(){
String osType=osType();
String libExtension=null;
@@ -114,7 +98,7 @@ static String libExtension(){
libExtension="dll";
}
if("osx".equals(osType)){
- libExtension="jnilib";
+ libExtension="dylib";
}
if("linux".equals(osType)){
libExtension="so";
@@ -122,42 +106,26 @@ static String libExtension(){
return libExtension;
}
- private static String platform(){
- String os=osType();
- String arch=archType();
- return os+"-"+arch;
- }
-
- private static void loadLibFile(File file,String libName){
- if (file.exists() && file.isFile()) {
- System.load(file.getAbsolutePath());
- LOADED_LIBARAY_SET.add(libName);
- }else{
- throw new GmSSLException("lib file is not found!");
- }
- }
- private static File createTmpLibFile(String resourceLibPath){
- InputStream in = NativeLoader.class.getClassLoader().getResourceAsStream(resourceLibPath);
- String tmpDirName = System.getProperty("java.io.tmpdir");
- File tmpDir = new File(tmpDirName);
- if (!tmpDir.exists()) {
- tmpDir.mkdir();
- }
- File file = null;
- try {
- file=File.createTempFile(resourceLibPath, null, tmpDir);
- assert in != null;
- ReadableByteChannel srcChannel = Channels.newChannel(in);
- FileChannel targetChannel = new FileOutputStream(file).getChannel();
- targetChannel.transferFrom(srcChannel, 0, Long.MAX_VALUE);
- } catch (FileNotFoundException e) {
- throw new GmSSLException("FileNotFoundException");
- } catch (IOException e) {
- throw new GmSSLException("IOException");
- }
- return file;
- }
+ /**
+ * In macOS systems, the execution of library calls relies on loading gmssl.3.dylib from the installed gmssl library,
+ * in order to correct the @rpath path issue. Alternatively, you can manually execute the command
+ * "install_name_tool -change @rpath/libgmssl.3.dylib /usr/local/lib/libgmssl.3.dylib xxx/lib/libgmssljni.dylib" to fix the library reference path issue.
+ * This has already been loaded and manual execution is unnecessary.
+ *
+ */
+ private static void checkReferencedLib(){
+ if("osx".equals(osType())){
+ String macReferencedLib=PROPERTIES.getProperty("macReferencedLib");
+ Optional optionalStr = Optional.ofNullable(macReferencedLib);
+ if(optionalStr.isPresent() && !optionalStr.get().isEmpty()){
+ File libFile = new File(macReferencedLib);
+ if(libFile.exists()){
+ System.load(macReferencedLib);
+ }
+ }
+ }
+ }
}
diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties
new file mode 100644
index 0000000..fb89108
--- /dev/null
+++ b/src/main/resources/config.properties
@@ -0,0 +1,3 @@
+# The address of the gmssl library referenced in the generated library call chain in the macOS environment.
+# The call chain situation can be viewed using the otool -L tool.
+macReferencedLib=/usr/local/lib/libgmssl.3.dylib
\ No newline at end of file
diff --git a/src/test/java/org/gmssl/HexUtil.java b/src/test/java/org/gmssl/HexUtil.java
index 797c706..26b43cf 100644
--- a/src/test/java/org/gmssl/HexUtil.java
+++ b/src/test/java/org/gmssl/HexUtil.java
@@ -9,6 +9,8 @@
package org.gmssl;
+import java.math.BigInteger;
+
/**
* @author yongfeili
* @email 290836576@qq.com
@@ -17,30 +19,31 @@
*/
public class HexUtil {
- private static final char HexCharArr[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
-
- private static final String HexStr = "0123456789abcdef";
-
+ /**
+ * convert byte array to hex string
+ * @param btArr
+ * @return String
+ */
public static String byteToHex(byte[] btArr) {
- char strArr[] = new char[btArr.length * 2];
- int i = 0;
- for (byte bt : btArr) {
- strArr[i++] = HexCharArr[bt>>>4 & 0xf];
- strArr[i++] = HexCharArr[bt & 0xf];
- }
- return new String(strArr);
+ BigInteger bigInteger = new BigInteger(1, btArr);
+ return bigInteger.toString(16);
}
- public static byte[] hexToByte(String hexStr) {
- char[] charArr = hexStr.toCharArray();
- byte btArr[] = new byte[charArr.length / 2];
- int index = 0;
- for (int i = 0; i < charArr.length; i++) {
- int highBit = HexStr.indexOf(charArr[i]);
- int lowBit = HexStr.indexOf(charArr[++i]);
- btArr[index] = (byte) (highBit << 4 | lowBit);
- index++;
+ /**
+ * convert hex string to byte array
+ * @param hexString
+ * @return byte[]
+ */
+ public static byte[] hexToByte(String hexString) {
+ byte[] byteArray = new BigInteger(hexString, 16)
+ .toByteArray();
+ if (byteArray[0] == 0) {
+ byte[] output = new byte[byteArray.length - 1];
+ System.arraycopy(
+ byteArray, 1, output,
+ 0, output.length);
+ return output;
}
- return btArr;
+ return byteArray;
}
-}
+}
\ No newline at end of file
diff --git a/src/test/java/org/gmssl/Sm2Test.java b/src/test/java/org/gmssl/Sm2Test.java
index 9ff11d7..70ec8e3 100644
--- a/src/test/java/org/gmssl/Sm2Test.java
+++ b/src/test/java/org/gmssl/Sm2Test.java
@@ -21,55 +21,111 @@
*/
public class Sm2Test {
- Sm2Key sm2_key=null;
+ Sm2Key sm2_key;
+ byte[] privateKeyInfo;
+ byte[] publicKeyInfo;
+ Sm2Key priKey,pubKey;
+ byte[] dgst;
@Before
public void beforeTest(){
sm2_key = new Sm2Key();
sm2_key.generateKey();
+
+ //byte[] privateKeyInfo=sm2_key.exportPrivateKeyInfoDer();
+ String privateKeyInfoHex="308193020100301306072a8648ce3d020106082a811ccf5501822d0479307702010104207fef3e258348873c47117c15093266e9dad99e131f1778e53d362b2b70649f85a00a06082a811ccf5501822da14403420004f94c0abb6cd00c6f0918cb9c54162213501d5cc278f5d3fcf63886f4e1dc6322b1b110e33a25216f258c4cce5fd52ab320d3b086ee5390f7387218c92578c3ab";
+ privateKeyInfo = HexUtil.hexToByte(privateKeyInfoHex);
+
+ //byte[] publicKeyInfo = sm2_key.exportPublicKeyInfoDer();
+ String publicKeyInfoHex = "3059301306072a8648ce3d020106082a811ccf5501822d03420004f94c0abb6cd00c6f0918cb9c54162213501d5cc278f5d3fcf63886f4e1dc6322b1b110e33a25216f258c4cce5fd52ab320d3b086ee5390f7387218c92578c3ab";
+ publicKeyInfo = HexUtil.hexToByte(publicKeyInfoHex);
+
+ priKey = new Sm2Key();
+ priKey.importPrivateKeyInfoDer(privateKeyInfo);
+ priKey.exportEncryptedPrivateKeyInfoPem("Password", "sm2.pem");
+ priKey.importEncryptedPrivateKeyInfoPem("Password", "sm2.pem");
+
+ pubKey = new Sm2Key();
+ pubKey.importPublicKeyInfoDer(publicKeyInfo);
+ pubKey.exportPublicKeyInfoPem("sm2.pem");
+ pubKey.importPublicKeyInfoPem("sm2.pem");
+
+ //byte[] dgst = rng.randBytes(Sm3.DIGEST_SIZE);
+ String dgstHex="372a28b963da9733515640f163dd017ae8544cafa78097d5765e4169348c030b";
+ dgst=HexUtil.hexToByte(dgstHex);
+
}
@Test
public void computeZTest(){
- byte[] z = sm2_key.computeZ(Sm2Key.DEFAULT_ID);
+ byte[] z = pubKey.computeZ(Sm2Key.DEFAULT_ID);
String hexZ= HexUtil.byteToHex(z);
//System.out.println("z:"+hexZ);
- Assert.assertNotNull("数据为空异常",hexZ);
+ Assert.assertNotNull("data is empty exception!",hexZ);
}
@Test
- public void verifyTest(){
- Random rng = new Random();
- byte[] dgst = rng.randBytes(Sm3.DIGEST_SIZE);
- byte[] sig = sm2_key.sign(dgst);
- boolean verify_ret = sm2_key.verify(dgst, sig);
+ public void signTest(){
+ byte[] sig = priKey.sign(dgst);
+ String sigHex = HexUtil.byteToHex(sig);
+ //System.out.println("sigHex : "+sigHex);
+ Assert.assertNotNull("data is empty exception!",sig);
+ }
+
+ @Test
+ public void verifySignTest(){
+ String sigHex="3046022100c2a92338bf430b0bd1ed68ea9910168cbd6bbb6f8de0992e1350e894296273b1022100e4814ac9ea6dab86334f47b2de6122923a0abbb7ec0687a2a1974773eb9a9542";
+ byte[] sig=HexUtil.hexToByte(sigHex);
+
+ boolean verify_ret = pubKey.verify(dgst, sig);
//System.out.println("Verify result = " + verify_ret);
- Assert.assertTrue("数据不为真异常",verify_ret);
+ Assert.assertTrue("Verification of the signature failed!",verify_ret);
}
@Test
- public void encryptAndDecryptTest(){
+ public void encryptTest(){
String testStr="gmssl";
- byte[] ciphertext = sm2_key.encrypt(testStr.getBytes());
- byte[] plaintext = sm2_key.decrypt(ciphertext);
- String originalStr= new String(plaintext);
- //System.out.printf("Plaintext : "+originalStr);
- Assert.assertEquals("原值与加解密后期望值不相等异常",testStr,originalStr);
+
+ byte[] ciphertext = pubKey.encrypt(testStr.getBytes());
+ //System.out.println("ciphertext : "+HexUtil.byteToHex(ciphertext));
+ Assert.assertNotNull("data is empty exception!",ciphertext);
}
@Test
- public void verifySignatureTest(){
- String testStr="gmssl";
- Sm2Signature sign = new Sm2Signature(sm2_key, Sm2Key.DEFAULT_ID, true);
- sign.update(testStr.getBytes());
+ public void decryptTest(){
+ String ciphertextHex="306e022100d5d193d99876b6b2a2456356c09db06074aceb3ad6ae736d415d6988bdd4392902207ffbef363ae9584703d10b799609aff0fcb7a026b04aeec14021c9e12d22d2470420bbcc0a0bd07ffde6d0f5d5ee6e81eb47debbd9c6c0fca55107b1891cea29f742040526af292b75";
+ byte[] ciphertext = HexUtil.hexToByte(ciphertextHex);
+
+ byte[] plaintext = priKey.decrypt(ciphertext);
+ String plaintextStr= new String(plaintext);
+ //System.out.printf("Plaintext : "+plaintextStr);
+ Assert.assertEquals("The original value is not equal to the expected value after decryption!","gmssl",plaintextStr);
+ }
+
+ @Test
+ public void signatureTest(){
+ String signatureContentStr="gmssl";
+
+ Sm2Signature sign = new Sm2Signature(priKey, Sm2Key.DEFAULT_ID, true);
+ sign.update(signatureContentStr.getBytes());
byte[] sig = sign.sign();
+ String sigHex = HexUtil.byteToHex(sig);
+ //System.out.println("signatureContentHex : "+sigHex);
+ Assert.assertNotNull("data is empty exception!",sig);
+ }
+
+ @Test
+ public void verifySignatureTest(){
+ String signatureContentStr = "gmssl";
+ String signatureContentHex = "3046022100cf526564d0964225f857856bc6ef181df5fcf1c87d630ccf6b992d4371772ed3022100915a309279e90ed00a02e84617991aaf1baa70586cc6cce395e52b7105bb73fa";
+ byte[] sig=HexUtil.hexToByte(signatureContentHex);
- Sm2Signature verify = new Sm2Signature(sm2_key, Sm2Key.DEFAULT_ID, false);
- verify.update(testStr.getBytes());
+ Sm2Signature verify = new Sm2Signature(pubKey, Sm2Key.DEFAULT_ID, false);
+ verify.update(signatureContentStr.getBytes());
boolean verify_ret = verify.verify(sig);
//System.out.println("Verify result = " + verify_ret);
- Assert.assertTrue("数据不为真异常",verify_ret);
+ Assert.assertTrue("Verification of the signature failed!",verify_ret);
}
}
diff --git a/src/test/java/org/gmssl/Sm3HmacTest.java b/src/test/java/org/gmssl/Sm3HmacTest.java
index 79dd2e4..ba3e943 100644
--- a/src/test/java/org/gmssl/Sm3HmacTest.java
+++ b/src/test/java/org/gmssl/Sm3HmacTest.java
@@ -31,7 +31,7 @@ public void macTest(){
String maxHex= HexUtil.byteToHex(mac);
//System.out.println(maxHex);
- Assert.assertNotNull("数据为空异常",maxHex);
+ Assert.assertNotNull("data is empty exception!",maxHex);
}
}
diff --git a/src/test/java/org/gmssl/Sm3Pbkdf2Test.java b/src/test/java/org/gmssl/Sm3Pbkdf2Test.java
new file mode 100644
index 0000000..f1aae21
--- /dev/null
+++ b/src/test/java/org/gmssl/Sm3Pbkdf2Test.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License); you may
+ * not use this file except in compliance with the License.
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.gmssl;
+
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author yongfeili
+ * @email 290836576@qq.com
+ * @date 2023/10/20
+ * @description Sm3Pbkdf2 unit test
+ */
+public class Sm3Pbkdf2Test {
+
+ /**
+ * PBKDF2 (Password-Based Key Derivation Function 2) is a cryptographic algorithm used to derive a key from a password.
+ * It employs a pseudorandom function to generate the key, and the length of the derived key can be arbitrarily chosen. However, PBKDF2 allows for multiple iterations of the computation to further enhance security.
+ * By incorporating a salt value (random data) along with the plaintext password, PBKDF2 generates a salted key, which greatly improves resistance against attacks like rainbow table attacks.
+ */
+ @Test
+ public void deriveKeyTest(){
+ Sm3Pbkdf2 kdf = new Sm3Pbkdf2();
+
+ Random rng = new Random();
+ byte[] salt = rng.randBytes(Sm3Pbkdf2.DEFAULT_SALT_SIZE);
+
+ String pass = "P@ssw0rd";
+ byte[] key = kdf.deriveKey(pass, salt, Sm3Pbkdf2.MIN_ITER * 2, 16);
+ String keyHexStr = HexUtil.byteToHex(key);
+ //System.out.println(keyHexStr);
+ Assert.assertNotNull("data is empty exception!",keyHexStr);
+ }
+
+}
diff --git a/src/test/java/org/gmssl/Sm3Test.java b/src/test/java/org/gmssl/Sm3Test.java
index f7c3440..a869dbf 100644
--- a/src/test/java/org/gmssl/Sm3Test.java
+++ b/src/test/java/org/gmssl/Sm3Test.java
@@ -22,17 +22,13 @@ public class Sm3Test {
@Test
public void digestTest(){
String testStr="gmssl";
- try(Sm3 sm3 = new Sm3()) {
- sm3.update(testStr.getBytes());
- byte[] dgst = sm3.digest();
-
- String dgstHex= HexUtil.byteToHex(dgst);
- //System.out.println(dgstHex);
- Assert.assertNotNull("数据为空异常",dgstHex);
- }catch (Exception e){
- e.printStackTrace();
- }
+ Sm3 sm3 = new Sm3();
+ sm3.update(testStr.getBytes());
+ byte[] dgst = sm3.digest();
+ String dgstHex= HexUtil.byteToHex(dgst);
+ //System.out.println(dgstHex);
+ Assert.assertNotNull("data is empty exception!",dgstHex);
}
}
diff --git a/src/test/java/org/gmssl/Sm4CbcTest.java b/src/test/java/org/gmssl/Sm4CbcTest.java
index 90161ca..7e7a30c 100644
--- a/src/test/java/org/gmssl/Sm4CbcTest.java
+++ b/src/test/java/org/gmssl/Sm4CbcTest.java
@@ -23,33 +23,46 @@
*/
public class Sm4CbcTest {
- Sm4Cbc sm4Cbc=null;
- Random rng = new Random();
- byte[] key = rng.randBytes(Sm4Cbc.KEY_SIZE);
- byte[] iv = rng.randBytes(Sm4Cbc.IV_SIZE);
+ Sm4Cbc sm4Cbc;
+ byte[] key , iv ;
@Before
public void beforeTest(){
sm4Cbc = new Sm4Cbc();
+ key = new byte[]{-73, -55, -122, -95, 0, -4, 51, -38, 125, -31, 38, 12, 112, 8, -50, -92};
+ iv = new byte[]{88, 121, -51, 88, 32, -85, 98, 56, 108, 18, 102, -73, -122, -59, -97, -25};
}
@Test
public void encryptTest(){
- String testStr="abc";
- byte[] ciphertext = new byte[Sm4Cbc.BLOCK_SIZE * 2];
+ String testStr="gmssl";
+
+ byte[] plaintext = testStr.getBytes();
+ byte[] ciphertext = new byte[plaintext.length+Sm4Cbc.BLOCK_SIZE];
sm4Cbc.init(key, iv, true);
- int cipherlen = sm4Cbc.update(testStr.getBytes(), 0, 3, ciphertext, 0);
+ int cipherlen = sm4Cbc.update(plaintext, 0, plaintext.length, ciphertext, 0);
cipherlen += sm4Cbc.doFinal(ciphertext, cipherlen);
-
- byte[] ciphertextEnd =Arrays.copyOfRange(ciphertext,0,cipherlen);
- //System.out.println("cipher:"+HexUtil.byteToHex(ciphertextEnd));
- Assert.assertNotNull("数据为空异常",HexUtil.byteToHex(ciphertextEnd));
+ byte[] ciphertext1 =Arrays.copyOfRange(ciphertext,0,cipherlen);
+ //System.out.println("cipher:"+HexUtil.byteToHex(ciphertext1));
+ Assert.assertNotNull("data is empty exception!",HexUtil.byteToHex(ciphertext1));
}
@Test
public void decryptTest(){
-
-
+ String cipherHex="ccedec05b742098b33e0fc8c5c006365";
+ byte[] ciphertext=HexUtil.hexToByte(cipherHex);
+ sm4Cbc.init(key, iv, false);
+ byte[] decrypted = new byte[ciphertext.length + Sm4Cbc.BLOCK_SIZE]; // prepare large enough plaintext buffer
+ int decryptedOffset = 0;
+ int decryptedLen;
+ int ciphertextOffset = 0;
+ decryptedLen = sm4Cbc.update(ciphertext, ciphertextOffset, ciphertext.length, decrypted, decryptedOffset);
+ decryptedOffset += decryptedLen;
+ decryptedLen += sm4Cbc.doFinal(decrypted, decryptedOffset);
+ byte[] plaintext =Arrays.copyOfRange(decrypted,0,decryptedLen);
+ String plaintextStr=new String(plaintext);
+ //System.out.println(plaintextStr);
+ Assert.assertEquals("original value is not equal to the expected value after decryption!","gmssl",plaintextStr);
}
}
diff --git a/src/test/java/org/gmssl/Sm4CtrTest.java b/src/test/java/org/gmssl/Sm4CtrTest.java
index ac0a32b..7dd030d 100644
--- a/src/test/java/org/gmssl/Sm4CtrTest.java
+++ b/src/test/java/org/gmssl/Sm4CtrTest.java
@@ -23,7 +23,7 @@ public class Sm4CtrTest {
private Sm4Ctr sm4Ctr;
- byte[] key = null,iv = null;
+ byte[] key ,iv ;
@Before
public void beforeTest(){
@@ -43,7 +43,7 @@ public void encryptTest(){
cipherlen += sm4Ctr.doFinal(ciphertext, cipherlen);
byte[] ciphertextEnd = Arrays.copyOfRange(ciphertext,0,cipherlen);
//System.out.println(HexUtil.byteToHex(ciphertextEnd));
- Assert.assertNotNull("数据为空异常",HexUtil.byteToHex(ciphertextEnd));
+ Assert.assertNotNull("data is empty exception!",HexUtil.byteToHex(ciphertextEnd));
}
@Test
@@ -58,7 +58,7 @@ public void decryptTest(){
plainlen += sm4Ctr.doFinal(plaintext, plainlen);
plaintext=Arrays.copyOfRange(plaintext,0,plainlen);
//System.out.println(new String(plaintext));
- Assert.assertEquals(plainText,new String(plaintext));
+ Assert.assertEquals("original value is not equal to the expected value after decryption!",plainText,new String(plaintext));
}
}
diff --git a/src/test/java/org/gmssl/Sm4EcbTest.java b/src/test/java/org/gmssl/Sm4EcbTest.java
new file mode 100644
index 0000000..b218c09
--- /dev/null
+++ b/src/test/java/org/gmssl/Sm4EcbTest.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License); you may
+ * not use this file except in compliance with the License.
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.gmssl;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+/**
+ * @author yongfeili
+ * @email 290836576@qq.com
+ * @date 2023/09/25
+ * @description Sm4Ecb unit test
+ */
+public class Sm4EcbTest {
+
+ byte[] key;
+
+ @Before
+ public void beforeTest(){
+ key=new byte[]{74, 97, -73, 5, -31, 1, -88, -21, -7, -2, -65, 98, 70, 5, -54, 15};
+ }
+
+ @Test
+ public void encryptTest(){
+ String test_plaintext="gmssl";
+ byte[] paddingPlaintext=pkcs5padding(test_plaintext.getBytes(),Sm4.BLOCK_SIZE);
+ byte[] encrypted = encrypt(paddingPlaintext,key);
+ //System.out.println("encrypted data:"+HexUtil.byteToHex(encrypted));
+ Assert.assertNotNull("data is empty exception!",encrypted);
+ }
+
+ @Test
+ public void decryptTest(){
+ String test_hex_chipertext="31acce3f0317026c30accba2be9d326f";
+ String test_plaintext="gmssl";
+ byte[] encrypted =HexUtil.hexToByte(test_hex_chipertext);
+ byte[] plaintextArray = decrypt(encrypted,key);
+ byte[] unpaddingPlaintextArray = pkcs5Unpadding(plaintextArray);
+ String plaintext=new String(unpaddingPlaintextArray);
+ //System.out.println("chipertext:"+plaintext);
+ Assert.assertEquals("original value is not equal to the expected value after decryption!",plaintext,test_plaintext);
+ }
+
+
+ /**
+ * The purpose of PKCS5Padding is to pad the data to the block size required by the encryption algorithm, ensuring that the data length meets the requirements of the encryption algorithm.
+ * In special cases where the data length is already a multiple of the block size, according to the PKCS5 rule, padding is still added at the end.
+ * This is done to ensure consistent handling of padding during encryption and decryption processes.
+ * @param ciphertextArray
+ * @param blockSize
+ * @return byte[] ciphertext
+ */
+ private static byte[] pkcs5padding(byte[] ciphertextArray, int blockSize) {
+ int paddingLength = blockSize - (ciphertextArray.length % blockSize);
+ byte[] padding = new byte[paddingLength];
+ Arrays.fill(padding, (byte) paddingLength);
+ byte[] result = new byte[ciphertextArray.length + padding.length];
+ System.arraycopy(ciphertextArray, 0, result, 0, ciphertextArray.length);
+ System.arraycopy(padding, 0, result, ciphertextArray.length, padding.length);
+ return result;
+ }
+
+ /**
+ * unpadding the plaintext
+ * @param plaintextArray
+ * @return byte[] plaintext
+ * @throws IllegalArgumentException
+ */
+ private static byte[] pkcs5Unpadding(byte[] plaintextArray) throws IllegalArgumentException {
+ int paddingSize = plaintextArray[plaintextArray.length - 1];
+ if (paddingSize <= 0 || paddingSize > plaintextArray.length) {
+ throw new IllegalArgumentException("Invalid pkcs#5 padding!");
+ }
+ for (int i = plaintextArray.length - paddingSize; i < plaintextArray.length; i++) {
+ if (plaintextArray[i] != paddingSize) {
+ throw new IllegalArgumentException("Invalid pkcs#5 padding!");
+ }
+ }
+ return Arrays.copyOfRange(plaintextArray, 0, plaintextArray.length - paddingSize);
+ }
+
+
+ /**
+ * Encrypt data by block
+ * @param data data to be encrypted
+ * @param key
+ * @return byte[] encrypted data
+ */
+ private static byte[] encrypt(byte[] data, byte[] key) {
+ byte[] ciphertext = new byte[data.length];
+ Sm4 sm4 = new Sm4(key, true);
+ for (int i = 0; i < data.length; i += Sm4.BLOCK_SIZE) {
+ sm4.encrypt(data, i, ciphertext, i);
+ }
+ return ciphertext;
+ }
+
+ /**
+ * Decrypt data by block
+ * @param data data to be decrypted
+ * @param key
+ * @return byte[] decrypted data
+ */
+ private static byte[] decrypt(byte[] data, byte[] key) {
+ byte[] plaintext=new byte[data.length];
+ Sm4 sm4 = new Sm4(key, false);
+ for (int i = 0; i < data.length; i += 16) {
+ sm4.encrypt(data, i, plaintext, i);
+ }
+ return plaintext;
+ }
+
+}
diff --git a/src/test/java/org/gmssl/Sm4GcmTest.java b/src/test/java/org/gmssl/Sm4GcmTest.java
new file mode 100644
index 0000000..ade9919
--- /dev/null
+++ b/src/test/java/org/gmssl/Sm4GcmTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License); you may
+ * not use this file except in compliance with the License.
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.gmssl;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+/**
+ * @author yongfeili
+ * @email 290836576@qq.com
+ * @date 2023/09/26
+ * @description Sm4Gcm unit test.
+ * In SM4 GCM mode, GCM provides both encryption and authentication functionalities.
+ * Encryption is performed using the SM4 algorithm, while authentication is provided by the GCM mode through message authentication codes.
+ * Additionally, GCM offers additional data integrity checks to detect if the data has been tampered with.
+ */
+public class Sm4GcmTest {
+
+ Sm4Gcm sm4gcm;
+ byte[] key ,iv ;
+ int taglen;
+ byte[] aad;
+
+ @Before
+ public void beforeTest(){
+ sm4gcm=new Sm4Gcm();
+ key=new byte[]{52, -63, -74, 123, 75, -42, -109, -94, -108, -35, 117, -70, 95, 126, -71, 6};
+ iv=new byte[]{-97, -42, 38, -65, 37, -75, -26, -119, -19, 124, -116, -27};
+ taglen=Sm4Gcm.MAX_TAG_SIZE;
+ aad = "Hello: ".getBytes();
+ }
+
+ /**
+ * sm4Gcm encrypt
+ * GCM operates on fixed size blocks (usually 128 bits), unlike other encryption modes such as CBC or ECB that require padding.
+ */
+ @Test
+ public void encryptTest(){
+ String testStr="gmssl";
+ byte[] palaintextByte=testStr.getBytes();
+ int blockLength= (int)Math.ceil((palaintextByte.length+taglen)/(double)Sm4.BLOCK_SIZE);
+ byte[] tempCiphertextByte=new byte[blockLength*Sm4.BLOCK_SIZE];
+ int cipherlen;
+ sm4gcm.init(key, iv, aad, taglen, true);
+ cipherlen = sm4gcm.update(palaintextByte, 0, palaintextByte.length, tempCiphertextByte, 0);
+ cipherlen += sm4gcm.doFinal(tempCiphertextByte, cipherlen);
+ byte[] ciphertextByte = Arrays.copyOfRange(tempCiphertextByte,0,cipherlen);
+ //System.out.println("ciphertext:"+HexUtil.byteToHex(ciphertextByte));
+ Assert.assertNotNull("data is empty exception!",ciphertextByte);
+ }
+
+ @Test
+ public void decryptTest(){
+ String test_plaintext="gmssl";
+ String test_hex_ciphertext="b4a20037dc223f3e3474304dbb464a86423fa6c6db";
+ byte[] ciphertextByte=HexUtil.hexToByte(test_hex_ciphertext);
+ byte[] tempPlaintextByte = new byte[ciphertextByte.length+taglen];
+ sm4gcm.init(key, iv, aad, taglen, false);
+ int plainlen = sm4gcm.update(ciphertextByte, 0, ciphertextByte.length, tempPlaintextByte, 0);
+ plainlen += sm4gcm.doFinal(tempPlaintextByte, plainlen);
+ byte[] plaintextByte = Arrays.copyOfRange(tempPlaintextByte,0,plainlen);
+ String plaintext=new String(plaintextByte);
+ //System.out.println("plaintext:"+plaintext);
+ Assert.assertEquals("original value is not equal to the expected value after decryption!",plaintext,test_plaintext);
+ }
+
+}
+
diff --git a/src/test/java/org/gmssl/Sm4Test.java b/src/test/java/org/gmssl/Sm4Test.java
new file mode 100644
index 0000000..817062f
--- /dev/null
+++ b/src/test/java/org/gmssl/Sm4Test.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License); you may
+ * not use this file except in compliance with the License.
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.gmssl;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author yongfeili
+ * @email 290836576@qq.com
+ * @date 2023/10/20
+ * @description Sm4 unit test
+ */
+public class Sm4Test {
+
+ byte[] key;
+
+ @Before
+ public void beforeTest(){
+ key=new byte[]{49, 50, 51, 52, 53, 54, 55, 56, 56, 55, 54, 53, 52, 51, 50, 49};
+ }
+
+ @Test
+ public void encryptTest(){
+ String plaintextStr="1234567887654321";
+ byte[] plaintext=plaintextStr.getBytes();
+ byte[] ciphertext=new byte[Sm4.BLOCK_SIZE];
+ Sm4 sm4enc = new Sm4(key, true);
+ sm4enc.encrypt(plaintext, 0, ciphertext, 0);
+ String ciphertextHex = HexUtil.byteToHex(ciphertext);
+ //System.out.println(ciphertextHex);
+ Assert.assertNotNull("data is empty exception!",ciphertextHex);
+ }
+
+ @Test
+ public void decryptTest(){
+ String ciphertextHex="4a7dc8fc6f7fb9bac989bbf8a5f194a7";
+ byte[] ciphertext = HexUtil.hexToByte(ciphertextHex);
+ byte[] plaintext = new byte[ciphertext.length];
+ Sm4 sm4dec = new Sm4(key, false);
+ sm4dec.encrypt(ciphertext, 0, plaintext, 0);
+ String plaintext1=new String(plaintext);
+ //System.out.println(plaintext1);
+ Assert.assertEquals("original value is not equal to the expected value after decryption!","1234567887654321",plaintext1);
+ }
+
+}
diff --git a/src/test/java/org/gmssl/Sm9Test.java b/src/test/java/org/gmssl/Sm9Test.java
new file mode 100644
index 0000000..dbee0f0
--- /dev/null
+++ b/src/test/java/org/gmssl/Sm9Test.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License); you may
+ * not use this file except in compliance with the License.
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.gmssl;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+import java.io.*;
+import java.util.Map;
+
+/**
+ * @author yongfei.li
+ * @email 290836576@qq.com
+ * @date 2023/10/20
+ * @description sm9 unit test
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class Sm9Test {
+
+ @Test
+ public void signTest() {
+ String singContentStr = "gmssl";
+ byte[] singContent = singContentStr.getBytes();
+
+ Sm9SignMasterKey sign_master_key = new Sm9SignMasterKey();
+ sign_master_key.generateMasterKey();
+ Sm9SignKey sign_key = sign_master_key.extractKey("testKey");
+ Sm9Signature sign = new Sm9Signature(true);
+ sign.update(singContent);
+ byte[] sig = sign.sign(sign_key);
+ sign_master_key.exportPublicMasterKeyPem("sm9sign.mpk");
+
+ String hexSig = HexUtil.byteToHex(sig);
+ //System.out.println(hexSig);
+ writeFile("sm9SignData.txt",hexSig);
+ Assert.assertNotNull("data is empty exception!",hexSig);
+ }
+
+ @Test
+ public void verifyTest(){
+ String hexSig=readFile("sm9SignData.txt");
+ byte[] sig=HexUtil.hexToByte(hexSig);
+ String singContentStr = "gmssl";
+ byte[] singContent = singContentStr.getBytes();
+
+ Sm9SignMasterKey sign_master_pub_key = new Sm9SignMasterKey();
+ sign_master_pub_key.importPublicMasterKeyPem("sm9sign.mpk");
+ Sm9Signature verify = new Sm9Signature(false);
+ verify.update(singContent);
+ boolean verify_ret = verify.verify(sig, sign_master_pub_key, "testKey");
+
+ //System.out.println("Verify result = " + verify_ret);
+ Assert.assertTrue("Verification of the signature failed!",verify_ret);
+
+ }
+
+ /**
+ * The encryption test method will generate a file, which will be used by the decryption test method ,
+ * the encryption test method needs to be run before the decryption test method.
+ */
+ @Test
+ public void _encryptTest(){
+ String plaintextStr = "gmssl";
+ byte[] plaintext = plaintextStr.getBytes();
+
+ Sm9EncMasterKey enc_master_key = new Sm9EncMasterKey();
+ enc_master_key.generateMasterKey();
+ enc_master_key.exportEncryptedMasterKeyInfoPem("password","sm9enc.mpk");
+
+ Sm9EncMasterKey enc_master_pub_key = new Sm9EncMasterKey();
+ enc_master_pub_key.importEncryptedMasterKeyInfoPem("password","sm9enc.mpk");
+ byte[] ciphertext = enc_master_pub_key.encrypt(plaintext, "testKey");
+
+ String ciphertextHex=HexUtil.byteToHex(ciphertext);
+ //System.out.println(ciphertextHex);
+ writeFile("sm9EncryptData.txt",ciphertextHex);
+ Assert.assertNotNull("data is empty exception!",ciphertextHex);
+ }
+
+ @Test
+ public void decryptTest(){
+ String ciphertextHex=readFile("sm9EncryptData.txt");
+ byte[] ciphertext=HexUtil.hexToByte(ciphertextHex);
+
+ Sm9EncMasterKey enc_master_key = new Sm9EncMasterKey();
+ enc_master_key.importEncryptedMasterKeyInfoPem("password","sm9enc.mpk");
+ Sm9EncKey enc_key = enc_master_key.extractKey("testKey");
+ byte[] plaintext = enc_key.decrypt(ciphertext);
+
+ String plaintextStr = new String(plaintext);
+ //System.out.print(plaintextStr);
+ Assert.assertEquals("The original value is not equal to the expected value after decryption!","gmssl",plaintextStr);
+ }
+
+ /**
+ * Write string data to a temporary file.
+ * @param fileName
+ * @param data
+ */
+ private void writeFile(String fileName,String data){
+ File tempFile = new File("./"+ fileName);
+ try {
+ if(tempFile.exists()){
+ tempFile.delete();
+ }else {
+ tempFile.createNewFile();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter("./" + fileName))) {
+ writer.write(data);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Read string data from a temporary file.
+ * @param fileName
+ * @return String data
+ */
+ private String readFile(String fileName){
+ FileReader fileReader = null;
+ StringBuilder data= new StringBuilder();
+ try {
+ fileReader = new FileReader(new File( "./"+fileName));
+ BufferedReader bufferedReader = new BufferedReader(fileReader);
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ data.append(line);
+ }
+ bufferedReader.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ return data.toString();
+ }
+
+}
diff --git a/src/test/java/org/gmssl/ZucTest.java b/src/test/java/org/gmssl/ZucTest.java
index 5c23d73..d5c8e1a 100644
--- a/src/test/java/org/gmssl/ZucTest.java
+++ b/src/test/java/org/gmssl/ZucTest.java
@@ -10,9 +10,12 @@
import org.junit.Assert;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import java.util.Arrays;
+
/**
* @author yongfei.li
* @email 290836576@qq.com
@@ -21,15 +24,15 @@
*/
public class ZucTest {
- Random rng = new Random();
- byte[] key = rng.randBytes(Zuc.KEY_SIZE);
- byte[] iv = rng.randBytes(Zuc.IV_SIZE);
- static Zuc zuc;
+ byte[] key , iv;
+ Zuc zuc;
- @BeforeClass
- public static void beforeClass() throws Exception {
+ @Before
+ public void beforeTest(){
zuc = new Zuc();
+ key=new byte[]{-58, -106, -55, 98, -75, 49, -74, -101, -50, 1, -79, 43, -33, -86, -57, -106};
+ iv=new byte[]{-119, 19, 24, 45, 83, 17, -89, 102, -72, -104, 91, -31, -25, -109, -28, 30};
}
/**
@@ -37,23 +40,21 @@ public static void beforeClass() throws Exception {
*/
@Test
public void encryptTest(){
- byte[] ciphertext = new byte[32];
+ String plaintextStr = "gmss";
+ byte[] plaintext = plaintextStr.getBytes();
+ int ciphertextLen = 2 * Zuc.BLOCK_SIZE * (int)Math.ceil((plaintext.length)/(double)Zuc.BLOCK_SIZE);
+ byte[] ciphertext = new byte[Math.max(16,ciphertextLen)];
int cipherlen;
zuc.init(key, iv);
- cipherlen = zuc.update("abc".getBytes(), 0, 3, ciphertext, 0);
+ cipherlen = zuc.update(plaintext, 0, plaintext.length, ciphertext, 0);
cipherlen += zuc.doFinal(ciphertext, cipherlen);
- //System.out.print("ciphertext : ");
- byte[] ciphertextEnd = new byte[cipherlen];
- for (int i = 0; i < cipherlen; i++) {
- //System.out.printf("%02x", ciphertext[i]);
- ciphertextEnd[i]=ciphertext[i];
- }
- String ciphertextHex= HexUtil.byteToHex(ciphertextEnd);
+ ciphertext = Arrays.copyOfRange(ciphertext,0,cipherlen);
+ String ciphertextHex= HexUtil.byteToHex(ciphertext);
//System.out.println(ciphertextHex);
- Assert.assertNotNull("数据为空异常",ciphertextHex);
+ Assert.assertNotNull("data is empty exception!",ciphertextHex);
}
/**
@@ -61,27 +62,21 @@ public void encryptTest(){
*/
@Test
public void decryptTest(){
- String plaintextStr="abc";
+ String ciphertextHex = "91a99db164";
- key=new byte[]{-58, -106, -55, 98, -75, 49, -74, -101, -50, 1, -79, 43, -33, -86, -57, -106};
- iv=new byte[]{-119, 19, 24, 45, 83, 17, -89, 102, -72, -104, 91, -31, -25, -109, -28, 30};
- int cipherlen=3;
int plainlen;
- byte[] ciphertext=new byte[]{-105, -90, -115, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- byte[] plaintext = new byte[32];
+ byte[] ciphertext=HexUtil.hexToByte(ciphertextHex);
+ int plaintextLen = 2 * Zuc.BLOCK_SIZE * (int)Math.ceil((ciphertext.length)/(double)Zuc.BLOCK_SIZE);
+ byte[] plaintext = new byte[Math.max(16,plaintextLen)];
zuc.init(key, iv);
- plainlen = zuc.update(ciphertext, 0, cipherlen, plaintext, 0);
+ plainlen = zuc.update(ciphertext, 0, ciphertext.length, plaintext, 0);
plainlen += zuc.doFinal(plaintext, plainlen);
- //System.out.print("plaintext : ");
- byte[] plaintextEnd = new byte[plainlen];
- for (int i = 0; i < plainlen; i++) {
- //System.out.printf("%02x", plaintext[i]);
- plaintextEnd[i]=plaintext[i];
- }
- //System.out.println(new String(plaintextEnd));
- Assert.assertEquals(plaintextStr,new String(plaintextEnd));
+ plaintext=Arrays.copyOfRange(plaintext,0,plainlen);
+ String plaintextStr = new String(plaintext);
+ //System.out.println(plaintextStr);
+ Assert.assertEquals("original value is not equal to the expected value after decryption!","gmssl",plaintextStr);
}