Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# Formatting rules for clang-format tool used by the OpenJCEPlus project.
BasedOnStyle: Google
UseTab: Never
InsertBraces: True
IndentWidth: 4
SortIncludes: false
ColumnLimit: 80
AlignConsecutiveDeclarations: true
AlignConsecutiveAssignments: true
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@
/src/main/native/com_ibm_crypto_plus_provider_ock_*.h

# Files generated by tests.
/0Test*.txt
/0Test*.txt

# Allow tracked changes for configuration file used by the
# clang-format tool for formatting C code.
!.clang-format
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ Signature | SHA512withRSA |X |X

The following contribution guidelines should be followed:

1. Code should be styled according to the included [style.xml](style.xml) eclipse rules.
1. Java code should be styled according to the included [style.xml](style.xml) eclipse rules.

1. C code should be styled using the clang-format tool using the included [.clang-format](.clang-format) rules.

1. A pull request should be sent for review only after the github action associated with this repository is automatically executed when a pull request is created.

Expand All @@ -360,11 +362,9 @@ The following contribution guidelines should be followed:
- You MUST validate that the use of the GenAI tool does not produce protected code (i.e. code that is copyrighted or licensed outside of our project's current licenses).

An example of a tagging would be:
```console
/* Start code generated by <GenAI tool> */


```console
/* Start code generated by <GenAI tool> */

/* End code generated by <GenAI tool> */
```

```
189 changes: 94 additions & 95 deletions src/main/native/BasicRandom.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,43 @@
* Method: RAND_nextBytes
* Signature: (J[B)V
*/
JNIEXPORT void JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAND_1nextBytes
(JNIEnv * env, jclass thisObj, jlong ockContextId, jbyteArray bytes)
{
static const char * functionName = "NativeInterface.RAND_nextbytes";

ICC_CTX * ockCtx = (ICC_CTX *)((intptr_t) ockContextId);
unsigned char * bytesNative = NULL;
jboolean isCopy;
jint size;
int rc = ICC_OK;

if( debug ) {
gslogFunctionEntry(functionName);
}

bytesNative = (*env)->GetPrimitiveArrayCritical(env, bytes, &isCopy);
if( bytesNative == NULL ) {
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical!");
} else {
size = (*env)->GetArrayLength(env, bytes);
JNIEXPORT void JNICALL
Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAND_1nextBytes(
JNIEnv *env, jclass thisObj, jlong ockContextId, jbyteArray bytes) {
static const char *functionName = "NativeInterface.RAND_nextbytes";

ICC_CTX *ockCtx = (ICC_CTX *)((intptr_t)ockContextId);
unsigned char *bytesNative = NULL;
jboolean isCopy;
jint size;
int rc = ICC_OK;

if (debug) {
gslogFunctionEntry(functionName);
}

bytesNative = (*env)->GetPrimitiveArrayCritical(env, bytes, &isCopy);
if (bytesNative == NULL) {
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical!");
} else {
size = (*env)->GetArrayLength(env, bytes);
#ifdef DEBUG_RANDOM_DETAIL
gslogMessage ("DETAIL_RANDOM size=%d", (int) size);
gslogMessage("DETAIL_RANDOM size=%d", (int)size);
#endif
rc = ICC_RAND_bytes(ockCtx, bytesNative, size);
if( rc != ICC_OSSL_SUCCESS ) {
ockCheckStatus(ockCtx);
throwOCKException(env, 0, "ICC_RAND_BYTES failed");
rc = ICC_RAND_bytes(ockCtx, bytesNative, size);
if (rc != ICC_OSSL_SUCCESS) {
ockCheckStatus(ockCtx);
throwOCKException(env, 0, "ICC_RAND_BYTES failed");
}
}
}

if( bytesNative != NULL ) {
(*env)->ReleasePrimitiveArrayCritical(env, bytes, bytesNative, 0);
}
if (bytesNative != NULL) {
(*env)->ReleasePrimitiveArrayCritical(env, bytes, bytesNative, 0);
}

if( debug ) {
gslogFunctionExit(functionName);
}
if (debug) {
gslogFunctionExit(functionName);
}
}

//============================================================================
Expand All @@ -68,39 +68,39 @@ JNIEXPORT void JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAN
* Method: RAND_setSeed
* Signature: (J[B)V
*/
JNIEXPORT void JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAND_1setSeed
(JNIEnv * env, jclass thisObj, jlong ockContextId, jbyteArray seed)
{
static const char * functionName = "NativeInterface.RAND_setSeed";

ICC_CTX * ockCtx = (ICC_CTX *)((intptr_t) ockContextId);
unsigned char * seedNative = NULL;
jboolean isCopy;
jint size;

if( debug ) {
gslogFunctionEntry(functionName);
}

seedNative = (*env)->GetPrimitiveArrayCritical(env, seed, &isCopy);
if( seedNative == NULL ) {
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical!");
} else {
size = (*env)->GetArrayLength(env, seed);
JNIEXPORT void JNICALL
Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAND_1setSeed(
JNIEnv *env, jclass thisObj, jlong ockContextId, jbyteArray seed) {
static const char *functionName = "NativeInterface.RAND_setSeed";

ICC_CTX *ockCtx = (ICC_CTX *)((intptr_t)ockContextId);
unsigned char *seedNative = NULL;
jboolean isCopy;
jint size;

if (debug) {
gslogFunctionEntry(functionName);
}

seedNative = (*env)->GetPrimitiveArrayCritical(env, seed, &isCopy);
if (seedNative == NULL) {
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical!");
} else {
size = (*env)->GetArrayLength(env, seed);
#ifdef DEBUG_RANDOM_DETAIL
gslogMessage ("DETAIL_RANDOM size=%d", (int) size);
gslogMessage("DETAIL_RANDOM size=%d", (int)size);
#endif

ICC_RAND_seed(ockCtx, seedNative, size);
}
ICC_RAND_seed(ockCtx, seedNative, size);
}

if( seedNative != NULL ) {
(*env)->ReleasePrimitiveArrayCritical(env, seed, seedNative, 0);
}
if (seedNative != NULL) {
(*env)->ReleasePrimitiveArrayCritical(env, seed, seedNative, 0);
}

if( debug ) {
gslogFunctionExit(functionName);
}
if (debug) {
gslogFunctionExit(functionName);
}
}

//============================================================================
Expand All @@ -109,43 +109,42 @@ JNIEXPORT void JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAN
* Method: RAND_generateSeed
* Signature: (J[B)V
*/
JNIEXPORT void JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAND_1generateSeed
(JNIEnv * env, jclass thisObj, jlong ockContextId, jbyteArray seed)
{
static const char * functionName = "NativeInterface.RAND_generateSeed";

ICC_CTX * ockCtx = (ICC_CTX *)((intptr_t) ockContextId);
unsigned char * seedNative = NULL;
jboolean isCopy;
jint size;
ICC_STATUS status;

if( debug ) {
gslogFunctionEntry(functionName);
}

seedNative = (*env)->GetPrimitiveArrayCritical(env, seed, &isCopy);
if( seedNative == NULL ) {
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical!");
} else {
size = (*env)->GetArrayLength(env, seed);

ICC_GenerateRandomSeed(ockCtx, &status, size, seedNative);
JNIEXPORT void JNICALL
Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAND_1generateSeed(
JNIEnv *env, jclass thisObj, jlong ockContextId, jbyteArray seed) {
static const char *functionName = "NativeInterface.RAND_generateSeed";

ICC_CTX *ockCtx = (ICC_CTX *)((intptr_t)ockContextId);
unsigned char *seedNative = NULL;
jboolean isCopy;
jint size;
ICC_STATUS status;

if (debug) {
gslogFunctionEntry(functionName);
}

seedNative = (*env)->GetPrimitiveArrayCritical(env, seed, &isCopy);
if (seedNative == NULL) {
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical!");
} else {
size = (*env)->GetArrayLength(env, seed);

ICC_GenerateRandomSeed(ockCtx, &status, size, seedNative);
#ifdef DEBUG_RANDOM_DETAIL
if( debug ) {
gslogMessage ("DETAIL_RAND size=%d", (int) size);
gslogMessagePrefix ("DETAIL_RAND size =%d", (int) size);
gslogMessageHex ((char *)seedNative, 0, (int) size, 0, 0, NULL);
}
if (debug) {
gslogMessage("DETAIL_RAND size=%d", (int)size);
gslogMessagePrefix("DETAIL_RAND size =%d", (int)size);
gslogMessageHex((char *)seedNative, 0, (int)size, 0, 0, NULL);
}
#endif
}
}

if( seedNative != NULL ) {
(*env)->ReleasePrimitiveArrayCritical(env, seed, seedNative, 0);
}
if (seedNative != NULL) {
(*env)->ReleasePrimitiveArrayCritical(env, seed, seedNative, 0);
}

if( debug ) {
gslogFunctionExit(functionName);
}
if (debug) {
gslogFunctionExit(functionName);
}
}

50 changes: 25 additions & 25 deletions src/main/native/BuildDate.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,45 @@
* Method: getLibraryBuildDate
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterface_getLibraryBuildDate
(JNIEnv * env, jclass thisObj)
{
static const char * functionName = "NativeInterface.getLibraryBuildDate";
const char * buildDateString = NULL;
jstring retValue = NULL;
JNIEXPORT jstring JNICALL
Java_com_ibm_crypto_plus_provider_ock_NativeInterface_getLibraryBuildDate(
JNIEnv* env, jclass thisObj) {
static const char* functionName = "NativeInterface.getLibraryBuildDate";
const char* buildDateString = NULL;
jstring retValue = NULL;

if( debug ) {
gslogFunctionEntry(functionName);
}
if (debug) {
gslogFunctionEntry(functionName);
}

#ifdef __MVS__
#pragma convert("ISO8859-1")
#pragma convert("ISO8859-1")
#endif

#if defined(BUILD_DATE)
// Compile flag specifying the build date
buildDateString = BUILD_DATE;
// Compile flag specifying the build date
buildDateString = BUILD_DATE;
#elif defined(__DATE__) && defined(__TIME__)
// Pre-processor macros
buildDateString = __DATE__ " " __TIME__;
// Pre-processor macros
buildDateString = __DATE__ " " __TIME__;
#elif defined(__DATE__)
// Pre-processor macro
buildDateString = __DATE__;
// Pre-processor macro
buildDateString = __DATE__;
#else
buildDateString = "<UNKNOWN>";
buildDateString = "<UNKNOWN>";
#endif

#ifdef __MVS__
#pragma convert(pop)
#pragma convert(pop)
#endif

if( buildDateString != NULL ) {
retValue = (*env)->NewStringUTF(env, buildDateString);
}
if (buildDateString != NULL) {
retValue = (*env)->NewStringUTF(env, buildDateString);
}

if( debug ) {
gslogFunctionExit(functionName);
}
if (debug) {
gslogFunctionExit(functionName);
}

return retValue;
return retValue;
}
Loading