-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
There was a problem hiding this 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
9743509
to
1d0b2a7
Compare
There was a problem hiding this 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XSalsa20Engine xsalsa20 = new XSalsa20Engine(); | |
XSalsa20Engine cipher = new XSalsa20Engine(); |
checkLength(nonce, Util.NONCE_SIZE); | ||
|
||
XSalsa20Engine xsalsa20 = new XSalsa20Engine(); | ||
Poly1305 poly1305 = new Poly1305(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// hash ciphertext and prepend mac to ciphertext | |
// hash the ciphertext |
assertNotNull(randomBytes); | ||
assertEquals(size, randomBytes.length); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import static io.xconn.cryptobox.SecretBox.MAC_SIZE; |
There was a problem hiding this comment.
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
- standard library
- third-party
- project code
static void boxOpen(byte[] output, byte[] nonce, byte[] ciphertext, byte[] key) { | ||
checkLength(nonce, Util.NONCE_SIZE); | ||
|
||
XSalsa20Engine xsalsa20 = new XSalsa20Engine(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XSalsa20Engine xsalsa20 = new XSalsa20Engine(); | |
XSalsa20Engine cipher = new XSalsa20Engine(); |
checkLength(nonce, Util.NONCE_SIZE); | ||
|
||
XSalsa20Engine xsalsa20 = new XSalsa20Engine(); | ||
Poly1305 poly1305 = new Poly1305(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Poly1305 poly1305 = new Poly1305(); | |
Poly1305 mac = new Poly1305(); |
|
||
static int MAC_SIZE = 16; | ||
|
||
public static byte[] box(byte[] message, byte[] key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static byte[] box(byte[] message, byte[] key) { | |
public static byte[] box(byte[] message, byte[] privateKey) { |
There was a problem hiding this comment.
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
closed #2