Commit 0ae67f02 authored by Yann Garcia's avatar Yann Garcia

Update ITS tools

parent 50dbe24a
<?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>{A5E5C89A-7B89-443A-9972-E0145DBA3B7E}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>comspirentitssecurity</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>StaticLibrary</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>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>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<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>
<AdditionalLibraryDirectories>$(ProjectDir)..\x64\Release;C:\Program Files\OpenSSL-Win64\lib\VC;C:\Program Files\Java\jre1.8.0_241\bin</AdditionalLibraryDirectories>
</Link>
</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>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_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)'=='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>
<ClInclude Include="..\..\..\..\com_spirent_its_security_NativeSecurity.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="com_spirent_its_security_NativeSecurity.c" />
</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 "com_spirent_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: com_spirent_its_security_NativeSecurity
* Method: hashWithSha256
* Signature: ([B)[B
*/
JNIEXPORT jbyteArray JNICALL Java_com_spirent_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)to_be_hashed_data_length);
if (result == 0) {
(*env)->SetByteArrayRegion(env, java_hashed_data, 0, (jsize)to_be_hashed_data_length, (jbyte*)hashed_data);
}
// Free allocated resources
free(hashed_data);
return java_hashed_data;
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_spirent_its_security_NativeSecurity */
#ifndef _Included_com_spirent_its_security
#define _Included_com_spirent_its_security
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_spirent_its_security_NativeSecurity
* Method: hashWithSha256
* Signature: ([B)[B
*/
JNIEXPORT jbyteArray JNICALL Java_com_spirent_its_security_NativeSecurity_hashWithSha256
(JNIEnv *, jobject, jbyteArray);
/*
* Class: com_spirent_its_security_NativeSecurity
* Method: hmac_sha256
* Signature: ([B[B)[B
*/
JNIEXPORT jbyteArray JNICALL Java_com_spirent_its_security_NativeSecurity_hmac_1sha256
(JNIEnv *, jobject, jbyteArray, jbyteArray);
#ifdef __cplusplus
}
#endif
#endif
package com.spirent.its.security;
class JniTest
{
static {
System.loadLibrary("com_spirent_its_security.dll");
}
public static void main(String args[])
{
System.out.println("Hello, World");
byte[] toBeHashed = new byte[] { (byte)0xca, (byte)0xfe, (byte)0xde, (byte)0xca };
byte[] hashedData = NativeSecurity.getInstance().hashWithSha256(toBeHashed);
if (hashedData == null) {
System.err.println("Failed");
} else {
System.out.println("Succeed");
}
}
}
package com.spirent.its.security;;
class NativeSecurity
{
private static final NativeSecurity _instance = new NativeSecurity();
private NativeSecurity() { };
public native byte[] hashWithSha256(byte[] p_toBeHashedData);
public static NativeSecurity getInstance() { return _instance; };
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment