Commit cb8cf8a4 authored by Yann Garcia's avatar Yann Garcia
Browse files

Bug fixed in lib_its_security

parent 381d1a3a
PROJECTROOT = ..
BUILDROOT = ../../build
PROJECT = org_etsi_its_security
DEBUG = yes
testdir =
alibs = $(PROJECT)
solibs = $(PROJECT)
sources := org_etsi_its_security_NativeSecurity.c
sources-WIN32 :=
headers := org_etsi_its_security_NativeSecurity.h
cflags += -Werror
packages += openssl
includes += ../../lib_its_security /usr/lib/jvm/java-11-openjdk-amd64/include /usr/lib/jvm/java-11-openjdk-amd64/include/linux
libs += $(outdir)/libItsSecurity.a
include ../../common.mk
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{B5C77DAC-BC05-426F-8E13-E60BD2732A02}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>orgetsiitssecurity</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_Win64;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>C:\Program Files\OpenSSL-Win64\include;C:\Program Files\Java\jdk1.8.0_241\include;C:\Program Files\Java\jdk1.8.0_241\include\win32;$(ProjectDir)../lib_its_security;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(ProjectDir)..\x64\Release;C:\Program Files\OpenSSL-Win64\lib\VC</AdditionalLibraryDirectories>
<AdditionalDependencies>lib_its_security.lib;libcrypto64MDd.lib;libssl64MDd.lib;Ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>cp "$(TargetPath)" "$(MSBuildProjectDirectory)\..\..\..\javasrc\nativeLibs\win32\x86_64"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_Win64;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>C:\Program Files\OpenSSL-Win64\include;C:\Program Files\Java\jdk1.8.0_241\include;C:\Program Files\Java\jdk1.8.0_241\include\win32;$(ProjectDir)../lib_its_security;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>lib_its_security.lib;libcrypto64MDd.lib;libssl64MDd.lib;Ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Lib>
<AdditionalLibraryDirectories>$(ProjectDir)..\x64\Debug;C:\Program Files\OpenSSL-Win64\lib\VC</AdditionalLibraryDirectories>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="org_etsi_its_security_NativeSecurity.c" />
<ClCompile Include="org_etsi_its_security_NativeSecurity.h">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
\ No newline at end of file
/* system headers */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <errno.h>
//add whatever is needed
#include <jni.h>
#include "org_etsi_its_security_NativeSecurity.h"
#include "lib_its_security.h"
//if you use other memory allocation function, please inform me!
#ifdef WIN32
DLLAPI void* _tt_calloc(size_t, size_t);
#define calloc(NUM, SIZE) _tt_calloc(NUM, SIZE)
DLLAPI void _tt_free(void*);
#define free(PTR) _tt_free(PTR)
#else
#endif //WIN32
#ifdef WIN32
void* _tt_calloc(size_t num, size_t elemSize) {
#if (_MSC_VER >= 1700) // newer than Visual Studio 2012
size_t size = num * elemSize;
void* res = CoTaskMemAlloc(size);
memset(res, 0, size);
return res;
#else
return HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY, (num) * (elemSize));
#endif
}
void _tt_free(void* ptr) {
#if (_MSC_VER >= 1700) // newer than Visual Studio 2012
CoTaskMemFree(ptr);
#else
HeapFree(GetProcessHeap(), 0, ptr);
#endif
}
#endif //WIN32
/*
* Class: org_etsi_its_security_NativeSecurity
* Method: hashWithSha384
* Signature: ([B)[B
*/
JNIEXPORT jbyteArray JNICALL Java_org_etsi_its_security_NativeSecurity_hashWithSha256(JNIEnv* env, jobject jobj, jbyteArray p_toBeHashedData) {
jbyteArray java_hashed_data;
int32_t result;
// Extract buffers
size_t to_be_hashed_data_length = (*env)->GetArrayLength(env, p_toBeHashedData);
uint8_t* to_be_hashed_data = (uint8_t*)calloc(sizeof(uint8_t), to_be_hashed_data_length);
(*env)->GetByteArrayRegion(env, p_toBeHashedData, 0, (jsize)to_be_hashed_data_length, (jbyte*)to_be_hashed_data);
// Call lib_its_security implementation
uint8_t* hashed_data = NULL;
result = hash_with_sha256(to_be_hashed_data, to_be_hashed_data_length, &hashed_data);
// Prepare return value
java_hashed_data = (*env)->NewByteArray(env, (jsize)32);
if (result == 0) {
(*env)->SetByteArrayRegion(env, java_hashed_data, 0, (jsize)32, (jbyte*)hashed_data);
}
// Free allocated resources
free(hashed_data);
return java_hashed_data;
}
/*
* Class: org_etsi_its_security_NativeSecurity
* Method: hashWithSha384
* Signature: ([B)[B
*/
JNIEXPORT jbyteArray JNICALL Java_org_etsi_its_security_NativeSecurity_hashWithSha384(JNIEnv* env, jobject jobj, jbyteArray p_toBeHashedData) {
jbyteArray java_hashed_data;
int32_t result;
// Extract buffers
size_t to_be_hashed_data_length = (*env)->GetArrayLength(env, p_toBeHashedData);
uint8_t* to_be_hashed_data = (uint8_t*)calloc(sizeof(uint8_t), to_be_hashed_data_length);
(*env)->GetByteArrayRegion(env, p_toBeHashedData, 0, (jsize)to_be_hashed_data_length, (jbyte*)to_be_hashed_data);
// Call lib_its_security implementation
uint8_t* hashed_data = NULL;
result = hash_with_sha384(to_be_hashed_data, to_be_hashed_data_length, &hashed_data);
// Prepare return value
java_hashed_data = (*env)->NewByteArray(env, (jsize)48);
if (result == 0) {
(*env)->SetByteArrayRegion(env, java_hashed_data, 0, (jsize)48, (jbyte*)hashed_data);
}
// Free allocated resources
free(hashed_data);
return java_hashed_data;
}
/*
* Class: org_etsi_its_security_NativeSecurity
* Method: hmacWithSha256
* Signature: ([B[B)[B
*/
JNIEXPORT jbyteArray JNICALL Java_org_etsi_its_security_NativeSecurity_hmacWithSha256(JNIEnv* env, jobject jobj, jbyteArray p_secretKey, jbyteArray p_message) {
jbyteArray java_hmac;
int32_t result;
// Extract buffers
size_t secret_key_length = (*env)->GetArrayLength(env, p_secretKey);
uint8_t* secret_key = (uint8_t*)calloc(sizeof(uint8_t), secret_key_length);
(*env)->GetByteArrayRegion(env, p_secretKey, 0, (jsize)secret_key_length, (jbyte*)secret_key);
size_t message_length = (*env)->GetArrayLength(env, p_message);
uint8_t* message = (uint8_t*)calloc(sizeof(uint8_t), message_length);
(*env)->GetByteArrayRegion(env, p_message, 0, (jsize)message_length, (jbyte*)message);
// Call lib_its_security implementation
uint8_t* hmac = NULL;
result = hmac_sha256(secret_key, secret_key_length, message, message_length, &hmac);
// Prepare return value
java_hmac = (*env)->NewByteArray(env, (jsize)16); // HMAC with SHA256 of the message resized to 16 bytes
if (result == 0) {
(*env)->SetByteArrayRegion(env, java_hmac, 0, (jsize)16, (jbyte*)hmac);
}
// Free allocated resources
free(secret_key);
free(message);
free(hmac);
return java_hmac;
}
/*
* Class: org_etsi_its_security_NativeSecurity
* Method: signWithEcdsaNistp256WithSha256
* Signature: ([B[B[B)[B
*/
JNIEXPORT jbyteArray JNICALL Java_org_etsi_its_security_NativeSecurity_signWithEcdsaNistp256WithSha256
(JNIEnv* env, jobject jobj, jbyteArray p_to_be_signed_secured_message, jbyteArray p_certificate_issuer, jbyteArray p_private_key) {
jbyteArray java_signature = NULL;
//fprintf(stderr, ">>> Java_org_etsi_its_security_NativeSecurity_signWithEcdsaNistp256WithSha256\n");
// Create intermal context
lib_its_security_context_t* lib_its_security_context = NULL;
int32_t result = initialize(nist_p_256, &lib_its_security_context);
// fprintf(stderr, "Java_org_etsi_its_security_NativeSecurity_signWithEcdsaNistp256WithSha256: result=%d\n", result);
if (result == 0) {
// Extract buffers
size_t to_be_signed_secured_message_length = (*env)->GetArrayLength(env, p_to_be_signed_secured_message);
//fprintf(stderr, "Java_org_etsi_its_security_NativeSecurity_signWithEcdsaNistp256WithSha256: to_be_signed_secured_message_length=%ld\n", to_be_signed_secured_message_length);
uint8_t* to_be_signed_secured_message = (uint8_t*)calloc(sizeof(uint8_t), to_be_signed_secured_message_length);
(*env)->GetByteArrayRegion(env, p_to_be_signed_secured_message, 0, (jsize)to_be_signed_secured_message_length, (jbyte*)to_be_signed_secured_message);
size_t certificate_issuer_length = 32;//(*env)->GetArrayLength(env, p_certificate_issuer);
//fprintf(stderr, "Java_org_etsi_its_security_NativeSecurity_signWithEcdsaNistp256WithSha256: certificate_issuer_length=%ld\n", certificate_issuer_length);
uint8_t* certificate_issuer = (uint8_t*)calloc(sizeof(uint8_t), certificate_issuer_length);
(*env)->GetByteArrayRegion(env, p_certificate_issuer, 0, (jsize)certificate_issuer_length, (jbyte*)certificate_issuer);
fprintf(stderr, "Java_org_etsi_its_security_NativeSecurity_signWithEcdsaNistp256WithSha256: certificate_issuer=%02x%02x%02x%02x%02x%02x\n", *certificate_issuer, *(certificate_issuer + 1), *(certificate_issuer + 2), *(certificate_issuer + 3), *(certificate_issuer + 4), *(certificate_issuer + 5));
size_t private_key_length = (*env)->GetArrayLength(env, p_private_key);
//fprintf(stderr, "Java_org_etsi_its_security_NativeSecurity_signWithEcdsaNistp256WithSha256: private_key_length=%ld\n", private_key_length);
uint8_t* private_key = (uint8_t*)calloc(sizeof(uint8_t), private_key_length);
(*env)->GetByteArrayRegion(env, p_private_key, 0, (jsize)private_key_length, (jbyte*)private_key);
uint8_t* signature = NULL;
result = sign_with_ecdsa_nistp256_with_sha256(lib_its_security_context, to_be_signed_secured_message, to_be_signed_secured_message_length, certificate_issuer, private_key, &signature);
//fprintf(stderr, "Java_org_etsi_its_security_NativeSecurity_signWithEcdsaNistp256WithSha256: result=%d\n", result);
if (result == 0) {
// Prepare return value
java_signature = (*env)->NewByteArray(env, (jsize)64);
(*env)->SetByteArrayRegion(env, java_signature, 0, (jsize)64, (jbyte*)signature);
// Free allocated resources
free(signature);
}
free(to_be_signed_secured_message);
free(certificate_issuer);
free(private_key);
uninitialize(&lib_its_security_context);
}
return java_signature;
}
/*
* Class: org_etsi_its_security_NativeSecurity
* Method: signWithEcdsaBrainpoolp256r1WithSha256
* Signature: ([B[B[B)[B
*/
JNIEXPORT jbyteArray JNICALL Java_org_etsi_its_security_NativeSecurity_signWithEcdsaBrainpoolp256r1WithSha256
(JNIEnv* env, jobject jobj, jbyteArray p_to_be_signed_secured_message, jbyteArray p_certificate_issuer, jbyteArray p_private_key) {
jbyteArray java_signature = NULL;
// Create intermal context
lib_its_security_context_t* lib_its_security_context = NULL;
int32_t result = initialize(brainpool_p_256_r1, &lib_its_security_context);
if (result == 0) {
// Extract buffers
size_t to_be_signed_secured_message_length = (*env)->GetArrayLength(env, p_to_be_signed_secured_message);
uint8_t* to_be_signed_secured_message = (uint8_t*)calloc(sizeof(uint8_t), to_be_signed_secured_message_length);
(*env)->GetByteArrayRegion(env, p_to_be_signed_secured_message, 0, (jsize)to_be_signed_secured_message_length, (jbyte*)to_be_signed_secured_message);
size_t certificate_issuer_length = (*env)->GetArrayLength(env, p_certificate_issuer);
uint8_t* certificate_issuer = (uint8_t*)calloc(sizeof(uint8_t), certificate_issuer_length);
(*env)->GetByteArrayRegion(env, p_certificate_issuer, 0, (jsize)certificate_issuer_length, (jbyte*)certificate_issuer);
size_t private_key_length = (*env)->GetArrayLength(env, p_private_key);
uint8_t* private_key = (uint8_t*)calloc(sizeof(uint8_t), private_key_length);
(*env)->GetByteArrayRegion(env, p_private_key, 0, (jsize)private_key_length, (jbyte*)private_key);
uint8_t* signature = NULL;
result = sign_with_ecdsa_brainpoolp256r1_with_sha256(lib_its_security_context, to_be_signed_secured_message, to_be_signed_secured_message_length, certificate_issuer, private_key, &signature);
if (result == 0) {
// Prepare return value
java_signature = (*env)->NewByteArray(env, (jsize)64);
(*env)->SetByteArrayRegion(env, java_signature, 0, (jsize)64, (jbyte*)signature);
// Free allocated resources
free(signature);
}
free(to_be_signed_secured_message);
free(certificate_issuer);
free(private_key);
uninitialize(&lib_its_security_context);
}
return java_signature;
}
/*
* Class: org_etsi_its_security_NativeSecurity
* Method: signWithEcdsaBrainpoolp384r1WithSha384
* Signature: ([B[B[B)[B
*/
JNIEXPORT jbyteArray JNICALL Java_org_etsi_its_security_NativeSecurity_signWithEcdsaBrainpoolp384r1WithSha384
(JNIEnv* env, jobject jobj, jbyteArray p_to_be_signed_secured_message, jbyteArray p_certificate_issuer, jbyteArray p_private_key) {
jbyteArray java_signature = NULL;
// Create intermal context
lib_its_security_context_t* lib_its_security_context = NULL;
int32_t result = initialize(brainpool_p_384_r1, &lib_its_security_context);
if (result == 0) {
// Extract buffers
size_t to_be_signed_secured_message_length = (*env)->GetArrayLength(env, p_to_be_signed_secured_message);
uint8_t* to_be_signed_secured_message = (uint8_t*)calloc(sizeof(uint8_t), to_be_signed_secured_message_length);
(*env)->GetByteArrayRegion(env, p_to_be_signed_secured_message, 0, (jsize)to_be_signed_secured_message_length, (jbyte*)to_be_signed_secured_message);
size_t certificate_issuer_length = (*env)->GetArrayLength(env, p_certificate_issuer);
uint8_t* certificate_issuer = (uint8_t*)calloc(sizeof(uint8_t), certificate_issuer_length);
(*env)->GetByteArrayRegion(env, p_certificate_issuer, 0, (jsize)certificate_issuer_length, (jbyte*)certificate_issuer);
size_t private_key_length = (*env)->GetArrayLength(env, p_private_key);
uint8_t* private_key = (uint8_t*)calloc(sizeof(uint8_t), private_key_length);
(*env)->GetByteArrayRegion(env, p_private_key, 0, (jsize)private_key_length, (jbyte*)private_key);
uint8_t* signature = NULL;
result = sign_with_ecdsa_brainpoolp384r1_with_sha384(lib_its_security_context, to_be_signed_secured_message, to_be_signed_secured_message_length, certificate_issuer, private_key, &signature);
if (result == 0) {
// Prepare return value
java_signature = (*env)->NewByteArray(env, (jsize)96);
(*env)->SetByteArrayRegion(env, java_signature, 0, (jsize)96, (jbyte*)signature);
// Free allocated resources
free(signature);
}
free(to_be_signed_secured_message);
free(certificate_issuer);
free(private_key);
uninitialize(&lib_its_security_context);
}
return java_signature;
}
/*
* Class: org_etsi_its_security_NativeSecurity
* Method: verifyWithEcdsaNistp256WithSha256
* Signature: ([B[B[B[BI)I
*/
JNIEXPORT jint JNICALL Java_org_etsi_its_security_NativeSecurity_verifyWithEcdsaNistp256WithSha256
(JNIEnv* env, jobject jobj, jbyteArray p_to_be_verified_data, jbyteArray p_certificate_issuer, jbyteArray p_signature, jbyteArray p_ecdsaNistp256PublicKeyCompressed, jint p_compressed_mode) {
fprintf(stderr, ">>> Java_org_etsi_its_security_NativeSecurity_verifyWithEcdsaNistp256WithSha256\n");
// Create intermal context
lib_its_security_context_t* lib_its_security_context = NULL;
int32_t result = initialize(nist_p_256, &lib_its_security_context);
//fprintf(stderr, "Java_org_etsi_its_security_NativeSecurity_verifyWithEcdsaNistp256WithSha256: result=%d\n", result);
if (result == 0) {
// Extract buffers
size_t to_be_verified_data_length = (*env)->GetArrayLength(env, p_to_be_verified_data);
//fprintf(stderr, "Java_org_etsi_its_security_NativeSecurity_verifyWithEcdsaNistp256WithSha256: to_be_verified_data_length=%ld\n", to_be_verified_data_length);
uint8_t* to_be_verified_data = (uint8_t*)calloc(sizeof(uint8_t), to_be_verified_data_length);
(*env)->GetByteArrayRegion(env, p_to_be_verified_data, 0, (jsize)to_be_verified_data_length, (jbyte*)to_be_verified_data);
size_t certificate_issuer_length = (*env)->GetArrayLength(env, p_certificate_issuer);
//fprintf(stderr, "Java_org_etsi_its_security_NativeSecurity_verifyWithEcdsaNistp256WithSha256: certificate_issuer_length=%ld\n", certificate_issuer_length);
uint8_t* certificate_issuer = (uint8_t*)calloc(sizeof(uint8_t), certificate_issuer_length);
(*env)->GetByteArrayRegion(env, p_certificate_issuer, 0, (jsize)certificate_issuer_length, (jbyte*)certificate_issuer);
size_t signature_length = (*env)->GetArrayLength(env, p_signature);
//fprintf(stderr, "Java_org_etsi_its_security_NativeSecurity_verifyWithEcdsaNistp256WithSha256: signature_length=%ld\n", signature_length);
uint8_t* signature = (uint8_t*)calloc(sizeof(uint8_t), signature_length);
(*env)->GetByteArrayRegion(env, p_signature, 0, (jsize)signature_length, (jbyte*)signature);
size_t compressed_key_length = (*env)->GetArrayLength(env, p_ecdsaNistp256PublicKeyCompressed);
//fprintf(stderr, "Java_org_etsi_its_security_NativeSecurity_verifyWithEcdsaNistp256WithSha256: compressed_key_length=%ld\n", compressed_key_length);
uint8_t* compressed_key = (uint8_t*)calloc(sizeof(uint8_t), compressed_key_length);
(*env)->GetByteArrayRegion(env, p_ecdsaNistp256PublicKeyCompressed, 0, (jsize)compressed_key_length, (jbyte*)compressed_key);
result = verify_with_ecdsa_nistp256_with_sha256(lib_its_security_context, to_be_verified_data, to_be_verified_data_length, certificate_issuer, signature, compressed_key, (int32_t)p_compressed_mode);
//fprintf(stderr, "Java_org_etsi_its_security_NativeSecurity_verifyWithEcdsaNistp256WithSha256: result=%d\n", result);
free(to_be_verified_data);
free(certificate_issuer);
free(signature);
free(compressed_key);
uninitialize(&lib_its_security_context);
}
return (jint)result;
}
/*
* Class: org_etsi_its_security_NativeSecurity
* Method: verifyWithEcdsaBrainpoolp256r1WithSha256
* Signature: ([B[B[B[BI)I
*/
JNIEXPORT jint JNICALL Java_org_etsi_its_security_NativeSecurity_verifyWithEcdsaBrainpoolp256r1WithSha256
(JNIEnv* env, jobject jobj, jbyteArray p_to_be_verified_data, jbyteArray p_certificate_issuer, jbyteArray p_signature, jbyteArray p_ecdsaNistp256PublicKeyCompressed, jint p_compressed_mode) {
// Create intermal context
lib_its_security_context_t* lib_its_security_context = NULL;
int32_t result = initialize(brainpool_p_256_r1, &lib_its_security_context);
if (result == 0) {
// Extract buffers
size_t to_be_verified_data_length = (*env)->GetArrayLength(env, p_to_be_verified_data);
uint8_t* to_be_verified_data = (uint8_t*)calloc(sizeof(uint8_t), to_be_verified_data_length);
(*env)->GetByteArrayRegion(env, p_to_be_verified_data, 0, (jsize)to_be_verified_data_length, (jbyte*)to_be_verified_data);
size_t certificate_issuer_length = (*env)->GetArrayLength(env, p_certificate_issuer);
uint8_t* certificate_issuer = (uint8_t*)calloc(sizeof(uint8_t), certificate_issuer_length);
(*env)->GetByteArrayRegion(env, p_certificate_issuer, 0, (jsize)certificate_issuer_length, (jbyte*)certificate_issuer);
size_t signature_length = (*env)->GetArrayLength(env, p_signature);
uint8_t* signature = (uint8_t*)calloc(sizeof(uint8_t), signature_length);
(*env)->GetByteArrayRegion(env, p_signature, 0, (jsize)signature_length, (jbyte*)signature);
size_t compressed_key_length = (*env)->GetArrayLength(env, p_ecdsaNistp256PublicKeyCompressed);
uint8_t* compressed_key = (uint8_t*)calloc(sizeof(uint8_t), compressed_key_length);
(*env)->GetByteArrayRegion(env, p_ecdsaNistp256PublicKeyCompressed, 0, (jsize)compressed_key_length, (jbyte*)compressed_key);
result = verify_with_ecdsa_brainpoolp256r1_with_sha256(lib_its_security_context, to_be_verified_data, to_be_verified_data_length, certificate_issuer, signature, compressed_key, (int32_t)p_compressed_mode);
free(to_be_verified_data);
free(certificate_issuer);
free(signature);
free(compressed_key);
uninitialize(&lib_its_security_context);
}
return (jint)result;
}
/*
* Class: org_etsi_its_security_NativeSecurity
* Method: fx_verifyWithEcdsaBrainpoolp384r1WithSha384
* Signature: ([B[B[B[BI)I
*/
JNIEXPORT jint JNICALL Java_org_etsi_its_security_NativeSecurity_verifyWithEcdsaBrainpoolp384r1WithSha384
(JNIEnv* env, jobject jobj, jbyteArray p_to_be_verified_data, jbyteArray p_certificate_issuer, jbyteArray p_signature, jbyteArray p_ecdsaNistp384PublicKeyCompressed, jint p_compressed_mode) {
// Create intermal context
lib_its_security_context_t* lib_its_security_context = NULL;
int32_t result = initialize(brainpool_p_384_r1, &lib_its_security_context);
if (result == 0) {
// Extract buffers
size_t to_be_verified_data_length = (*env)->GetArrayLength(env, p_to_be_verified_data);
uint8_t* to_be_verified_data = (uint8_t*)calloc(sizeof(uint8_t), to_be_verified_data_length);
(*env)->GetByteArrayRegion(env, p_to_be_verified_data, 0, (jsize)to_be_verified_data_length, (jbyte*)to_be_verified_data);
size_t certificate_issuer_length = (*env)->GetArrayLength(env, p_certificate_issuer);
uint8_t* certificate_issuer = (uint8_t*)calloc(sizeof(uint8_t), certificate_issuer_length);
(*env)->GetByteArrayRegion(env, p_certificate_issuer, 0, (jsize)certificate_issuer_length, (jbyte*)certificate_issuer);
size_t signature_length = (*env)->GetArrayLength(env, p_signature);
uint8_t* signature = (uint8_t*)calloc(sizeof(uint8_t), signature_length);
(*env)->GetByteArrayRegion(env, p_signature, 0,