Skip to content

Commit

Permalink
Merge pull request #252 from cconlon/classRename
Browse files Browse the repository at this point in the history
Refactor wolfCrypt level classes to avoid `wolfcrypt-jni` namespace conflicts
  • Loading branch information
JacobBarthelmeh authored Jan 31, 2025
2 parents 5e56b00 + 36bfbd1 commit 7cf0c4e
Show file tree
Hide file tree
Showing 40 changed files with 1,009 additions and 226 deletions.
6 changes: 3 additions & 3 deletions IDE/Android/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ add_library(wolfssljni SHARED
${wolfssljni_DIR}/native/com_wolfssl_WolfSSLSession.c
${wolfssljni_DIR}/native/com_wolfssl_WolfSSLX509Name.c
${wolfssljni_DIR}/native/com_wolfssl_WolfSSLX509StoreCtx.c
${wolfssljni_DIR}/native/com_wolfssl_wolfcrypt_ECC.c
${wolfssljni_DIR}/native/com_wolfssl_wolfcrypt_EccKey.c
${wolfssljni_DIR}/native/com_wolfssl_wolfcrypt_RSA.c
${wolfssljni_DIR}/native/com_wolfssl_WolfCryptECC.c
${wolfssljni_DIR}/native/com_wolfssl_WolfCryptEccKey.c
${wolfssljni_DIR}/native/com_wolfssl_WolfCryptRSA.c
)

# set_target_properties(wolfssljni PROPERTIES LIBRARY_OUTPUT_DIRECTORY
Expand Down
14 changes: 7 additions & 7 deletions IDE/WIN/wolfssljni.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\native\com_wolfssl_wolfcrypt_ECC.c" />
<ClCompile Include="..\..\native\com_wolfssl_wolfcrypt_EccKey.c" />
<ClCompile Include="..\..\native\com_wolfssl_wolfcrypt_RSA.c" />
<ClCompile Include="..\..\native\com_wolfssl_WolfCryptECC.c" />
<ClCompile Include="..\..\native\com_wolfssl_WolfCryptEccKey.c" />
<ClCompile Include="..\..\native\com_wolfssl_WolfCryptRSA.c" />
<ClCompile Include="..\..\native\com_wolfssl_WolfSSL.c" />
<ClCompile Include="..\..\native\com_wolfssl_WolfSSLCertificate.c" />
<ClCompile Include="..\..\native\com_wolfssl_WolfSSLCertManager.c" />
Expand All @@ -49,9 +49,9 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\native\com_wolfssl_globals.h" />
<ClInclude Include="..\..\native\com_wolfssl_wolfcrypt_ECC.h" />
<ClInclude Include="..\..\native\com_wolfssl_wolfcrypt_EccKey.h" />
<ClInclude Include="..\..\native\com_wolfssl_wolfcrypt_RSA.h" />
<ClInclude Include="..\..\native\com_wolfssl_WolfCryptECC.h" />
<ClInclude Include="..\..\native\com_wolfssl_WolfCryptEccKey.h" />
<ClInclude Include="..\..\native\com_wolfssl_WolfCryptRSA.h" />
<ClInclude Include="..\..\native\com_wolfssl_WolfSSL.h" />
<ClInclude Include="..\..\native\com_wolfssl_WolfSSLCertificate.h" />
<ClInclude Include="..\..\native\com_wolfssl_WolfSSLCertManager.h" />
Expand Down Expand Up @@ -432,4 +432,4 @@ ant</Command>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
12 changes: 6 additions & 6 deletions IDE/WIN/wolfssljni.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\native\com_wolfssl_wolfcrypt_ECC.c">
<ClCompile Include="..\..\native\com_wolfssl_WolfCryptECC.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\native\com_wolfssl_wolfcrypt_EccKey.c">
<ClCompile Include="..\..\native\com_wolfssl_WolfCryptEccKey.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\native\com_wolfssl_wolfcrypt_RSA.c">
<ClCompile Include="..\..\native\com_wolfssl_WolfCryptRSA.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\native\com_wolfssl_WolfSSL.c">
Expand Down Expand Up @@ -53,13 +53,13 @@
<ClInclude Include="..\..\native\com_wolfssl_globals.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\native\com_wolfssl_wolfcrypt_ECC.h">
<ClInclude Include="..\..\native\com_wolfssl_WolfCryptECC.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\native\com_wolfssl_wolfcrypt_EccKey.h">
<ClInclude Include="..\..\native\com_wolfssl_WolfCryptEccKey.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\native\com_wolfssl_wolfcrypt_RSA.h">
<ClInclude Include="..\..\native\com_wolfssl_WolfCryptRSA.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\native\com_wolfssl_WolfSSL.h">
Expand Down
7 changes: 3 additions & 4 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@
<class name="com.wolfssl.WolfSSLContext"/>
<class name="com.wolfssl.WolfSSLSession"/>
<class name="com.wolfssl.WolfSSLX509StoreCtx"/>
<class name="com.wolfssl.wolfcrypt.ECC"/>
<class name="com.wolfssl.wolfcrypt.EccKey"/>
<class name="com.wolfssl.wolfcrypt.RSA"/>
<class name="com.wolfssl.WolfCryptECC"/>
<class name="com.wolfssl.WolfCryptEccKey"/>
<class name="com.wolfssl.WolfCryptRSA"/>
</javah>
</target>

Expand All @@ -177,7 +177,6 @@
</manifest>
<fileset dir="${build.dir}">
<include name="com/wolfssl/*.class"/>
<include name="com/wolfssl/wolfcrypt/*.class"/>
</fileset>
</jar>
</target>
Expand Down
11 changes: 11 additions & 0 deletions examples/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ public void run(String[] args) {
MyDecryptVerifyCallback dvcb = new MyDecryptVerifyCallback();
sslCtx.setMacEncryptCb(mecb);
sslCtx.setDecryptVerifyCb(dvcb);

if (WolfSSL.encryptThenMacEnabled()) {
MyVerifyDecryptCallback vdcb =
new MyVerifyDecryptCallback();
sslCtx.setVerifyDecryptCb(vdcb);
}
}

/* register public key callbacks, ctx setup is later */
Expand Down Expand Up @@ -521,6 +527,11 @@ public void run(String[] args) {
MyAtomicDecCtx decCtx = new MyAtomicDecCtx();
ssl.setMacEncryptCtx(encCtx);
ssl.setDecryptVerifyCtx(decCtx);

if (WolfSSL.encryptThenMacEnabled()) {
MyAtomicDecCtx vdCtx = new MyAtomicDecCtx();
ssl.setVerifyDecryptCtx(vdCtx);
}
}

if (pkCallbacks == 1) {
Expand Down
34 changes: 17 additions & 17 deletions examples/MyDecryptVerifyCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
import java.nio.ByteBuffer;
import com.wolfssl.*;

/*
* Example Decrypt Verify callback implementation.
* NOTE: if native HAVE_ENCRYPT_THEN_MAC is defined, the VerifyDecrypt
* callback needs to be used.
*/
class MyDecryptVerifyCallback implements WolfSSLDecryptVerifyCallback
{
public int decryptVerifyCallback(WolfSSLSession ssl, ByteBuffer decOut,
Expand Down Expand Up @@ -115,23 +120,18 @@ public int decryptVerifyCallback(WolfSSLSession ssl, ByteBuffer decOut,
ssl.setTlsHmacInner(myInner, macInSz, macContent, macVerify);
int hmacType = ssl.getHmacType();

switch (hmacType) {
case WolfSSL.SHA:
hmacString = "HmacSHA1";
break;
case WolfSSL.SHA256:
hmacString = "HmacSHA256";
break;
case WolfSSL.SHA384:
hmacString = "HmacSHA384";
break;
case WolfSSL.SHA512:
hmacString = "HmacSHA512";
break;
default:
System.out.println("Unsupported HMAC hash type in " +
"MyDecryptVerifyCallback");
return -1;
if (hmacType == WolfSSL.SHA) {
hmacString = "HmacSHA1";
} else if (hmacType == WolfSSL.SHA256) {
hmacString = "HmacSHA256";
} else if (hmacType == WolfSSL.SHA384) {
hmacString = "HmacSHA384";
} else if (hmacType == WolfSSL.SHA512) {
hmacString = "HmacSHA512";
} else {
System.out.println("Unsupported HMAC hash type in " +
"MyDecryptVerifyCallback: " + hmacType);
return -1;
}

/* get Hmac SHA-1 key */
Expand Down
7 changes: 3 additions & 4 deletions examples/MyEccSharedSecretCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.net.*;
import java.nio.ByteBuffer;
import com.wolfssl.*;
import com.wolfssl.wolfcrypt.*;

import java.security.KeyFactory;
import java.security.interfaces.ECPublicKey;
Expand All @@ -47,9 +46,9 @@
*/
class MyEccSharedSecretCallback implements WolfSSLEccSharedSecretCallback
{
public int eccSharedSecretCallback(WolfSSLSession ssl, EccKey otherKey,
ByteBuffer pubKeyDer, long[] pubKeyDerSz, ByteBuffer out,
long[] outSz, int side, Object ctx) {
public int eccSharedSecretCallback(WolfSSLSession ssl,
WolfCryptEccKey otherKey, ByteBuffer pubKeyDer, long[] pubKeyDerSz,
ByteBuffer out, long[] outSz, int side, Object ctx) {

int ret = -1;
ECPublicKey ecPubKey = null;
Expand Down
3 changes: 1 addition & 2 deletions examples/MyEccSignCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.net.*;
import java.nio.ByteBuffer;
import com.wolfssl.*;
import com.wolfssl.wolfcrypt.*;

class MyEccSignCallback implements WolfSSLEccSignCallback
{
Expand All @@ -34,7 +33,7 @@ public int eccSignCallback(WolfSSLSession ssl, ByteBuffer in, long inSz,
System.out.println("---------- Entered MyEccSignCallback ----------");

int ret = -1;
ECC ecc = new ECC();
WolfCryptECC ecc = new WolfCryptECC();
MyEccSignCtx eccSignCtx = (MyEccSignCtx)ctx;

ret = ecc.doSign(in, inSz, out, outSz, keyDer, keySz);
Expand Down
3 changes: 1 addition & 2 deletions examples/MyEccVerifyCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.net.*;
import java.nio.ByteBuffer;
import com.wolfssl.*;
import com.wolfssl.wolfcrypt.*;

class MyEccVerifyCallback implements WolfSSLEccVerifyCallback
{
Expand All @@ -34,7 +33,7 @@ public int eccVerifyCallback(WolfSSLSession ssl, ByteBuffer sig,
System.out.println("---------- Entered MyEccVerifyCallback ----------");

int ret = -1;
ECC ecc = new ECC();
WolfCryptECC ecc = new WolfCryptECC();
MyEccVerifyCtx eccVerifyCtx = (MyEccVerifyCtx)ctx;

ret = ecc.doVerify(sig, sigSz, hash, hashSz, keyDer, keySz, result);
Expand Down
29 changes: 12 additions & 17 deletions examples/MyMacEncryptCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,18 @@ public int macEncryptCallback(WolfSSLSession ssl, ByteBuffer macOut,
}

int hmacType = ssl.getHmacType();
switch (hmacType) {
case WolfSSL.SHA:
hmacString = "HmacSHA1";
break;
case WolfSSL.SHA256:
hmacString = "HmacSHA256";
break;
case WolfSSL.SHA384:
hmacString = "HmacSHA384";
break;
case WolfSSL.SHA512:
hmacString = "HmacSHA512";
break;
default:
System.out.println("Unsupported HMAC hash type in " +
"MyMacEncryptCallback");
return -1;
if (hmacType == WolfSSL.SHA) {
hmacString = "HmacSHA1";
} else if (hmacType == WolfSSL.SHA256) {
hmacString = "HmacSHA256";
} else if (hmacType == WolfSSL.SHA384) {
hmacString = "HmacSHA384";
} else if (hmacType == WolfSSL.SHA512) {
hmacString = "HmacSHA512";
} else {
System.out.println("Unsupported HMAC hash type in " +
"MyMacEncryptCallback");
return -1;
}

/* hmac, not needed if aead mode */
Expand Down
3 changes: 1 addition & 2 deletions examples/MyRsaDecCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.net.*;
import java.nio.*;
import com.wolfssl.*;
import com.wolfssl.wolfcrypt.*;

class MyRsaDecCallback implements WolfSSLRsaDecCallback
{
Expand All @@ -34,7 +33,7 @@ public int rsaDecCallback(WolfSSLSession ssl, ByteBuffer in, long inSz,
System.out.println("---------- Entering MyRsaDecCallback ----------");
int ret = -1;

RSA rsa = new RSA();
WolfCryptRSA rsa = new WolfCryptRSA();
MyRsaDecCtx rsaDecCtx = (MyRsaDecCtx)ctx;

ret = rsa.doDec(in, inSz, out, outSz, keyDer, keySz);
Expand Down
3 changes: 1 addition & 2 deletions examples/MyRsaEncCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.net.*;
import java.nio.*;
import com.wolfssl.*;
import com.wolfssl.wolfcrypt.*;

class MyRsaEncCallback implements WolfSSLRsaEncCallback
{
Expand All @@ -34,7 +33,7 @@ public int rsaEncCallback(WolfSSLSession ssl, ByteBuffer in, long inSz,
System.out.println("---------- Entering MyRsaEncCallback ----------");
int ret = -1;

RSA rsa = new RSA();
WolfCryptRSA rsa = new WolfCryptRSA();
MyRsaEncCtx rsaEncCtx = (MyRsaEncCtx)ctx;

ret = rsa.doEnc(in, inSz, out, outSz, keyDer, keySz);
Expand Down
3 changes: 1 addition & 2 deletions examples/MyRsaSignCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.net.*;
import java.nio.*;
import com.wolfssl.*;
import com.wolfssl.wolfcrypt.*;

class MyRsaSignCallback implements WolfSSLRsaSignCallback
{
Expand All @@ -34,7 +33,7 @@ public int rsaSignCallback(WolfSSLSession ssl, ByteBuffer in, long inSz,
System.out.println("---------- Entering MyRsaSignCallback ----------");
int ret = -1;

RSA rsa = new RSA();
WolfCryptRSA rsa = new WolfCryptRSA();
MyRsaSignCtx rsaSignCtx = (MyRsaSignCtx)ctx;

ret = rsa.doSign(in, inSz, out, outSz, keyDer, keySz);
Expand Down
3 changes: 1 addition & 2 deletions examples/MyRsaVerifyCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.net.*;
import java.nio.*;
import com.wolfssl.*;
import com.wolfssl.wolfcrypt.*;

class MyRsaVerifyCallback implements WolfSSLRsaVerifyCallback
{
Expand All @@ -34,7 +33,7 @@ public int rsaVerifyCallback(WolfSSLSession ssl, ByteBuffer sig,
System.out.println("---------- Entered MyRsaVerifyCallback ----------");
int ret = -1;

RSA rsa = new RSA();
WolfCryptRSA rsa = new WolfCryptRSA();
MyRsaVerifyCtx rsaVerifyCtx = (MyRsaVerifyCtx)ctx;

ret = rsa.doVerify(sig, sigSz, out, outSz, keyDer, keySz);
Expand Down
Loading

0 comments on commit 7cf0c4e

Please sign in to comment.