Skip to content

Commit

Permalink
Updated tests - Auth not working on Android with devices armv7
Browse files Browse the repository at this point in the history
  • Loading branch information
gurpreet- committed Nov 27, 2018
1 parent df6fed8 commit 3a73818
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 121 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -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."
}
Expand Down
120 changes: 0 additions & 120 deletions src/test/java/AuthAndroidTest.java
Expand Up @@ -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;
Expand All @@ -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);
}
}
142 changes: 142 additions & 0 deletions 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);
}
}

0 comments on commit 3a73818

Please sign in to comment.