Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SecretBox #7

Merged
merged 8 commits into from
Feb 28, 2024
Merged

Implement SecretBox #7

merged 8 commits into from
Feb 28, 2024

Conversation

muzzammilshahid
Copy link
Member

closed #2

Copy link
Member

@Mahad-10 Mahad-10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one suggestion

src/main/java/io/xconn/cryptobox/SecretBox.java Outdated Show resolved Hide resolved
Copy link
Member

@om26er om26er left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first batch of review


public class SecretBox {

static int Poly1305MacSize = 16;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static int Poly1305MacSize = 16;
static int MAC_SIZE = 16;

static void box(byte[] output, byte[] nonce, byte[] plaintext, byte[] key) {
checkLength(nonce, Util.NONCE_SIZE);

XSalsa20Engine xsalsa20 = new XSalsa20Engine();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
XSalsa20Engine xsalsa20 = new XSalsa20Engine();
XSalsa20Engine cipher = new XSalsa20Engine();

checkLength(nonce, Util.NONCE_SIZE);

XSalsa20Engine xsalsa20 = new XSalsa20Engine();
Poly1305 poly1305 = new Poly1305();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Poly1305 poly1305 = new Poly1305();
Poly1305 mac = new Poly1305();

byte[] cipherWithoutNonce = new byte[plaintext.length + poly1305.getMacSize()];
xsalsa20.processBytes(plaintext, 0, plaintext.length, cipherWithoutNonce, poly1305.getMacSize());

// hash ciphertext and prepend mac to ciphertext
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// hash ciphertext and prepend mac to ciphertext
// hash the ciphertext

assertNotNull(randomBytes);
assertEquals(size, randomBytes.length);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import static io.xconn.cryptobox.SecretBox.MAC_SIZE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should order the imports

  1. standard library
  2. third-party
  3. project code

static void boxOpen(byte[] output, byte[] nonce, byte[] ciphertext, byte[] key) {
checkLength(nonce, Util.NONCE_SIZE);

XSalsa20Engine xsalsa20 = new XSalsa20Engine();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
XSalsa20Engine xsalsa20 = new XSalsa20Engine();
XSalsa20Engine cipher = new XSalsa20Engine();

checkLength(nonce, Util.NONCE_SIZE);

XSalsa20Engine xsalsa20 = new XSalsa20Engine();
Poly1305 poly1305 = new Poly1305();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Poly1305 poly1305 = new Poly1305();
Poly1305 mac = new Poly1305();


static int MAC_SIZE = 16;

public static byte[] box(byte[] message, byte[] key) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static byte[] box(byte[] message, byte[] key) {
public static byte[] box(byte[] message, byte[] privateKey) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and in all other places

@om26er om26er merged commit 6c5b0ca into main Feb 28, 2024
2 checks passed
@muzzammilshahid muzzammilshahid deleted the secret-box branch March 2, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement SecretBox
3 participants