From 3a73818103a7807d03bccdd4e2db5d75643899fe Mon Sep 17 00:00:00 2001 From: Gurpreet Paul Date: Tue, 27 Nov 2018 17:36:20 +0000 Subject: [PATCH] Updated tests - Auth not working on Android with devices armv7 --- build.gradle | 2 +- src/test/java/AuthAndroidTest.java | 120 ------------------------ src/test/java/AuthTest.java | 142 +++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 121 deletions(-) create mode 100644 src/test/java/AuthTest.java diff --git a/build.gradle b/build.gradle index 1c38c1f..e42189f 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ plugins { ext { artifactId = "lazysodium-java" groupId = "com.goterl.lazycode" - version = '3.4.0' + version = '3.4.1' description = "Lazysodium (Java) makes it effortless for Java " + "developers to get started with Libsodium's cryptography." } diff --git a/src/test/java/AuthAndroidTest.java b/src/test/java/AuthAndroidTest.java index 637df6a..7591eda 100644 --- a/src/test/java/AuthAndroidTest.java +++ b/src/test/java/AuthAndroidTest.java @@ -11,9 +11,7 @@ */ import com.goterl.lazycode.lazysodium.exceptions.SodiumException; -import com.goterl.lazycode.lazysodium.interfaces.Auth; import com.goterl.lazycode.lazysodium.utils.Key; -import junit.framework.TestCase; import org.junit.Test; import static org.junit.Assert.assertTrue; @@ -34,122 +32,4 @@ public void authKeygenAndVerify() throws SodiumException { } - @Test - public void auth256KeygenAndVerify() { - String m = "A simple message."; - - Key k = lazySodium.cryptoAuthHMACShaKeygen(Auth.Type.SHA256); - String shaResult = lazySodium.cryptoAuthHMACSha(Auth.Type.SHA256, m, k); - boolean isTrue = lazySodium.cryptoAuthHMACShaVerify(Auth.Type.SHA256, shaResult, m, k); - assertTrue(isTrue); - } - - @Test - public void auth512KeygenAndVerify() { - String m = "A simple message."; - - Key k = lazySodium.cryptoAuthHMACShaKeygen(Auth.Type.SHA512); - String shaResult = lazySodium.cryptoAuthHMACSha(Auth.Type.SHA512, m, k); - boolean isTrue = lazySodium.cryptoAuthHMACShaVerify(Auth.Type.SHA512, shaResult, m, k); - assertTrue(isTrue); - } - - @Test - public void auth512256KeygenAndVerify() { - String m = "Follow us on twitter @terlacious"; - - Key k = lazySodium.cryptoAuthHMACShaKeygen(Auth.Type.SHA512256); - String shaResult = lazySodium.cryptoAuthHMACSha(Auth.Type.SHA512256, m, k); - boolean isTrue = lazySodium.cryptoAuthHMACShaVerify(Auth.Type.SHA512256, shaResult, m, k); - assertTrue(isTrue); - } - - @Test - public void auth256StreamKeygenAndVerify() throws SodiumException { - String m = "Terl is "; - String m2 = "the best"; - - Key k = lazySodium.cryptoAuthHMACShaKeygen(Auth.Type.SHA256); - Auth.StateHMAC256 state = new Auth.StateHMAC256.ByReference(); - - - boolean res = lazySodium.cryptoAuthHMACShaInit(state, k); - if (!res) { - TestCase.fail("Could not initialise HMAC Sha."); - return; - } - - boolean res2 = lazySodium.cryptoAuthHMACShaUpdate(state, m); - if (!res2) { - TestCase.fail("Could not update HMAC Sha."); - return; - } - - boolean res3 = lazySodium.cryptoAuthHMACShaUpdate(state, m2); - if (!res3) { - TestCase.fail("Could not update HMAC Sha (part 2)."); - return; - } - - String sha = lazySodium.cryptoAuthHMACShaFinal(state); - - boolean isTrue = lazySodium.cryptoAuthHMACShaVerify(Auth.Type.SHA256, sha, m + m2, k); - assertTrue(isTrue); - } - - - @Test - public void auth512StreamKeygenAndVerify() throws SodiumException { - String m = "Lazysodium makes devs lazy"; - String m2 = " but don't tell your manager that!"; - - Key k = lazySodium.cryptoAuthHMACShaKeygen(Auth.Type.SHA512); - Auth.StateHMAC512 state = new Auth.StateHMAC512.ByReference(); - - - boolean res = lazySodium.cryptoAuthHMACShaInit(state, k); - if (!res) { - TestCase.fail("Could not initialise HMAC Sha."); - return; - } - - boolean res2 = lazySodium.cryptoAuthHMACShaUpdate(state, m); - if (!res2) { - TestCase.fail("Could not update HMAC Sha."); - return; - } - - boolean res3 = lazySodium.cryptoAuthHMACShaUpdate(state, m2); - if (!res3) { - TestCase.fail("Could not update HMAC Sha (part 2)."); - return; - } - - String sha = lazySodium.cryptoAuthHMACShaFinal(state); - - boolean isTrue = lazySodium.cryptoAuthHMACShaVerify(Auth.Type.SHA512, sha, m + m2, k); - assertTrue(isTrue); - } - - - @Test - public void auth512256StreamKeygenAndVerify() throws SodiumException { - String m = "A string that "; - String m2 = "is sha512256 sha mac'd "; - String m3 = "is super secure."; - - Key k = lazySodium.cryptoAuthHMACShaKeygen(Auth.Type.SHA512256); - Auth.StateHMAC512256 state = new Auth.StateHMAC512256.ByReference(); - - - boolean res = lazySodium.cryptoAuthHMACShaInit(state, k); - boolean res2 = lazySodium.cryptoAuthHMACShaUpdate(state, m); - boolean res3 = lazySodium.cryptoAuthHMACShaUpdate(state, m2); - boolean res4 = lazySodium.cryptoAuthHMACShaUpdate(state, m3); - - String sha = lazySodium.cryptoAuthHMACShaFinal(state); - - boolean isTrue = lazySodium.cryptoAuthHMACShaVerify(Auth.Type.SHA512256, sha, m + m2 + m3, k); - assertTrue(isTrue); - } } diff --git a/src/test/java/AuthTest.java b/src/test/java/AuthTest.java new file mode 100644 index 0000000..e854f40 --- /dev/null +++ b/src/test/java/AuthTest.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) Terl Tech Ltd • 27/11/18 17:35 • goterl.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* + * This Java source file was generated by the Gradle 'init' task. + */ + +import com.goterl.lazycode.lazysodium.exceptions.SodiumException; +import com.goterl.lazycode.lazysodium.interfaces.Auth; +import com.goterl.lazycode.lazysodium.utils.Key; +import junit.framework.TestCase; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class AuthTest extends BaseTest { + + + @Test + public void auth256KeygenAndVerify() { + String m = "A simple message."; + + Key k = lazySodium.cryptoAuthHMACShaKeygen(Auth.Type.SHA256); + String shaResult = lazySodium.cryptoAuthHMACSha(Auth.Type.SHA256, m, k); + boolean isTrue = lazySodium.cryptoAuthHMACShaVerify(Auth.Type.SHA256, shaResult, m, k); + assertTrue(isTrue); + } + + @Test + public void auth512KeygenAndVerify() { + String m = "A simple message."; + + Key k = lazySodium.cryptoAuthHMACShaKeygen(Auth.Type.SHA512); + String shaResult = lazySodium.cryptoAuthHMACSha(Auth.Type.SHA512, m, k); + boolean isTrue = lazySodium.cryptoAuthHMACShaVerify(Auth.Type.SHA512, shaResult, m, k); + assertTrue(isTrue); + } + + @Test + public void auth512256KeygenAndVerify() { + String m = "Follow us on twitter @terlacious"; + + Key k = lazySodium.cryptoAuthHMACShaKeygen(Auth.Type.SHA512256); + String shaResult = lazySodium.cryptoAuthHMACSha(Auth.Type.SHA512256, m, k); + boolean isTrue = lazySodium.cryptoAuthHMACShaVerify(Auth.Type.SHA512256, shaResult, m, k); + assertTrue(isTrue); + } + + @Test + public void auth256StreamKeygenAndVerify() throws SodiumException { + String m = "Terl is "; + String m2 = "the best"; + + Key k = lazySodium.cryptoAuthHMACShaKeygen(Auth.Type.SHA256); + Auth.StateHMAC256 state = new Auth.StateHMAC256.ByReference(); + + + boolean res = lazySodium.cryptoAuthHMACShaInit(state, k); + if (!res) { + TestCase.fail("Could not initialise HMAC Sha."); + return; + } + + boolean res2 = lazySodium.cryptoAuthHMACShaUpdate(state, m); + if (!res2) { + TestCase.fail("Could not update HMAC Sha."); + return; + } + + boolean res3 = lazySodium.cryptoAuthHMACShaUpdate(state, m2); + if (!res3) { + TestCase.fail("Could not update HMAC Sha (part 2)."); + return; + } + + String sha = lazySodium.cryptoAuthHMACShaFinal(state); + + boolean isTrue = lazySodium.cryptoAuthHMACShaVerify(Auth.Type.SHA256, sha, m + m2, k); + assertTrue(isTrue); + } + + + @Test + public void auth512StreamKeygenAndVerify() throws SodiumException { + String m = "Lazysodium makes devs lazy"; + String m2 = " but don't tell your manager that!"; + + Key k = lazySodium.cryptoAuthHMACShaKeygen(Auth.Type.SHA512); + Auth.StateHMAC512 state = new Auth.StateHMAC512.ByReference(); + + + boolean res = lazySodium.cryptoAuthHMACShaInit(state, k); + if (!res) { + TestCase.fail("Could not initialise HMAC Sha."); + return; + } + + boolean res2 = lazySodium.cryptoAuthHMACShaUpdate(state, m); + if (!res2) { + TestCase.fail("Could not update HMAC Sha."); + return; + } + + boolean res3 = lazySodium.cryptoAuthHMACShaUpdate(state, m2); + if (!res3) { + TestCase.fail("Could not update HMAC Sha (part 2)."); + return; + } + + String sha = lazySodium.cryptoAuthHMACShaFinal(state); + + boolean isTrue = lazySodium.cryptoAuthHMACShaVerify(Auth.Type.SHA512, sha, m + m2, k); + assertTrue(isTrue); + } + + + @Test + public void auth512256StreamKeygenAndVerify() throws SodiumException { + String m = "A string that "; + String m2 = "is sha512256 sha mac'd "; + String m3 = "is super secure."; + + Key k = lazySodium.cryptoAuthHMACShaKeygen(Auth.Type.SHA512256); + Auth.StateHMAC512256 state = new Auth.StateHMAC512256.ByReference(); + + + boolean res = lazySodium.cryptoAuthHMACShaInit(state, k); + boolean res2 = lazySodium.cryptoAuthHMACShaUpdate(state, m); + boolean res3 = lazySodium.cryptoAuthHMACShaUpdate(state, m2); + boolean res4 = lazySodium.cryptoAuthHMACShaUpdate(state, m3); + + String sha = lazySodium.cryptoAuthHMACShaFinal(state); + + boolean isTrue = lazySodium.cryptoAuthHMACShaVerify(Auth.Type.SHA512256, sha, m + m2 + m3, k); + assertTrue(isTrue); + } +}