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

Feature/makesomenoise #37

Merged
merged 204 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
204 commits
Select commit Hold shift + click to select a range
1956dc5
Update NetworkTest to pass mplex negotiation
Nashatyrev Jul 5, 2019
6086ea8
Very initial draft of MultistreamHandler
Nashatyrev Jul 9, 2019
fe63764
Refactor MultistreamChannel/Handler: extract abstract classes
Nashatyrev Jul 11, 2019
3cfaef0
Merge remote-tracking branch 'origin/master' into feature/multistream…
Nashatyrev Jul 11, 2019
d6e0403
Create child channel on eventLoop for thread-safety
Nashatyrev Jul 11, 2019
215a5f8
Correctly process any type of channel close, add support for multiple…
Nashatyrev Jul 11, 2019
80a720c
Merge branch 'sketch' of https://github.com/libp2p/jvm-libp2p into fe…
snazha-blkio Jul 11, 2019
d07398c
WIP - Skeleton for stream mplex implementation
snazha-blkio Jul 11, 2019
0aacfde
Fix multistream Negotiator to correctly handle varint prefixes. Add '…
Nashatyrev Jul 12, 2019
0f60f73
Change the test to cover Negotiator and ProtocolSelect handlers
Nashatyrev Jul 12, 2019
d23ff03
Fix lint warning
Nashatyrev Jul 12, 2019
e021410
WIP - varint support for ByteArray.
snazha-blkio Jul 14, 2019
fed44c8
Merge branch 'master' of https://github.com/libp2p/jvm-libp2p into fe…
snazha-blkio Jul 14, 2019
775551f
WIP - stream state management
snazha-blkio Jul 16, 2019
5c3d06d
Merge branch 'feature/multistream-handler' of https://github.com/libp…
snazha-blkio Jul 16, 2019
c822376
Merge pull request #30 from libp2p/fix/multistream-varint
Nashatyrev Jul 16, 2019
4c43350
WIP - Linting
snazha-blkio Jul 16, 2019
2d5339f
Merge branch 'feature/multistream-handler' of https://github.com/libp…
snazha-blkio Jul 16, 2019
d3d1ee4
Add a bit more logic to TcpTransport
Nashatyrev Jul 17, 2019
aa772cf
Remove debug out
Nashatyrev Jul 17, 2019
6aae8e7
Add test logging for mplex frames
Nashatyrev Jul 17, 2019
cf30874
Add Multistream wrapper class
Nashatyrev Jul 18, 2019
e75f83d
Refactor Transport API: dial/listen now requires sync callback which …
Nashatyrev Jul 18, 2019
d29b148
Fix lint errors
Nashatyrev Jul 18, 2019
86baa1a
Switch to openjdk8 since oraclejdk8 is no more available on Travis
Nashatyrev Jul 18, 2019
f2b8454
Merge pull request #26 from libp2p/feature/mplex
Nashatyrev Jul 18, 2019
e39332c
Merge branch 'feature/multistream-handler' of https://github.com/libp…
Nashatyrev Jul 18, 2019
58a17f6
Refactor mplex codec
Nashatyrev Jul 18, 2019
65d98a5
Merge branch 'feature/framework-adjust' into feature/multistream-handler
Nashatyrev Jul 18, 2019
b764c5c
Working EchoSampleTest
Nashatyrev Jul 22, 2019
0a4bf34
Move multistream related classes to the corresponding package
Nashatyrev Jul 23, 2019
bbf6840
forEachFlushedMessage doesn't remove messages from the buffer. Need t…
Nashatyrev Jul 23, 2019
5e4ccba
Return back Transport.dial Future<Connection> return type. Minor refa…
Nashatyrev Jul 23, 2019
8d26e21
Add default client Bootstrap to TcpTransport
Nashatyrev Jul 23, 2019
68a8749
Fix lint warns
Nashatyrev Jul 23, 2019
b71e94d
Remove duplicate NettyExt.kt
Nashatyrev Jul 23, 2019
632af2c
Merge remote-tracking branch 'origin/master' into feature/multistream…
Nashatyrev Jul 23, 2019
31ce613
Use Logger in the test
Nashatyrev Jul 23, 2019
d3ea617
Fix lint warn
Nashatyrev Jul 23, 2019
583f843
Data class can't handle ByteArray so the equals/hashcode methods shou…
Nashatyrev Jul 24, 2019
902315f
Complete TCPTransport class. Fix several issues with futures
Nashatyrev Jul 24, 2019
94c7ddd
Merge remote-tracking branch 'origin/master' into feature/tcp-transport
Nashatyrev Jul 25, 2019
e10eda0
Add back the file deleted while merge
Nashatyrev Jul 25, 2019
b5ef4b3
Add initial pubsub interfaces and floodsub draft implementation
Nashatyrev Jul 25, 2019
ebe46cd
basic commit with noise and start of integration. cleanup is pending.
shahankhatch Jul 25, 2019
aee1161
Initial floodsub implementation
Nashatyrev Jul 26, 2019
ffe897c
Extend router test
Nashatyrev Jul 30, 2019
4905f15
Initial setup for Noise Curve25519 keys in libp2p w proto backing.
shahankhatch Jul 30, 2019
e994898
Start of Noise implementation of libp2p channel for Curve25519 session.
shahankhatch Aug 1, 2019
64467d8
Initial gossip router implementation
Nashatyrev Aug 2, 2019
84a7cce
Fix Floodsub router: messages should be flooded to subscribers only
Nashatyrev Aug 2, 2019
a8f46ab
Make pubsub AbstractRouter thread-safe by executing all the tasks on …
Nashatyrev Aug 6, 2019
ae04600
Noise handshake test with some starting integration points with libp2…
shahankhatch Aug 7, 2019
e9c8ee7
Implementation of Noise in libp2p that aims to start conformign to th…
shahankhatch Aug 8, 2019
2ba7386
Make ordered iteration of tasks scheduled to the same time
Nashatyrev Aug 8, 2019
dd0c41c
Fix a couple of bugs. Add deterministic pubsub network tests
Nashatyrev Aug 9, 2019
0f9c762
Fix pubsub decoder
Nashatyrev Aug 9, 2019
e76e4ba
Add libp2p Daemon control code for testing
Nashatyrev Aug 12, 2019
3e16dd1
Add PubsubApi implementation
Nashatyrev Aug 12, 2019
7b9584e
Sending/receiving pubsub messages works now with libp2p daemon:
Nashatyrev Aug 13, 2019
c7699ba
Fix issue with activating semi-duplex peer. Fix test setups
Nashatyrev Aug 14, 2019
3855b28
Fix lint errors
Nashatyrev Aug 14, 2019
b9576bb
Move java sources to java folder
Nashatyrev Aug 15, 2019
41a65e6
Gossiping according to spec: to subset of topic peers NOT in mesh or …
Nashatyrev Aug 15, 2019
6ba5e39
Merge remote-tracking branch 'origin/master' into feature/gossip
Nashatyrev Aug 15, 2019
b0bf5d4
Fix test. The star center node can't 100% deliver a message to all it…
Nashatyrev Aug 16, 2019
73c406d
Add classes docs
Nashatyrev Aug 16, 2019
2667d0e
Fix test: add waiting some time for assertion since future listeners …
Nashatyrev Aug 19, 2019
cd09ddd
Fix lint warns
Nashatyrev Aug 19, 2019
1b6c3e1
Correct handling of returned publish() Future
Nashatyrev Aug 20, 2019
58fdde2
Fix synchronisation issue
Nashatyrev Aug 20, 2019
6a8cf8e
Ping protocol template
Nashatyrev Aug 20, 2019
4b1206b
Draft config fixes
Nashatyrev Aug 20, 2019
d522c01
Clean up ByteBuf refcounting, fix all detected leaks
Nashatyrev Aug 20, 2019
b4f10c3
Fix lint warn
Nashatyrev Aug 21, 2019
e347f5e
Merge remote-tracking branch 'origin/master' into feature/gossip
Nashatyrev Aug 21, 2019
d67e53b
Merge branch 'feature/gossip' into feature/ping
Nashatyrev Aug 21, 2019
7b9367c
Some redesign: hide ChannelInitializer from StreamHandler interface
Nashatyrev Aug 21, 2019
b7df245
Add ping protocol
Nashatyrev Aug 21, 2019
caa6ea6
Complete ping futures with ClosedException when channel is closed
Nashatyrev Aug 22, 2019
c07ca20
Removing unused files.
shahankhatch Aug 22, 2019
42527ee
Make P2PAbstractHandler the base class of any other protocol handlers
Nashatyrev Aug 22, 2019
0bd7f8f
Close server transport after test
Nashatyrev Aug 23, 2019
bc4f377
Fix lint warns
Nashatyrev Aug 23, 2019
9d44374
Merge branch 'feature/ping' into feature/config
Nashatyrev Aug 27, 2019
37d0057
Complete Network class, complete and test Builders
Nashatyrev Aug 27, 2019
c9b8ebe
Make the StreamMuxer return both Stream and TController futures
Nashatyrev Aug 28, 2019
c4ba966
Rewrite Multistream Negotiator to respect different ProtocolMatchers.…
Nashatyrev Aug 28, 2019
06544ac
Fix the test: now initializing the ChannelPipeline beforehand doesn't…
Nashatyrev Aug 28, 2019
d5c00b6
Simplify interfaces
Nashatyrev Aug 28, 2019
d216637
Add Builders Java API, port HostTest to Java
Nashatyrev Aug 29, 2019
05e3e58
Add Host and Network interfaces
Nashatyrev Aug 29, 2019
b01f041
Remove StreamHandler notion from Transport and Network
Nashatyrev Aug 29, 2019
f1870a8
Add Stream.getProtocol()
Nashatyrev Aug 29, 2019
254fac1
Complete Host implementation
Nashatyrev Aug 30, 2019
839763b
Fix lint warns
Nashatyrev Aug 31, 2019
ea708f7
Sort out packages: leave only interfaces and core data classes in the…
Nashatyrev Aug 31, 2019
3f31bb0
Add some kdocs
Nashatyrev Aug 31, 2019
2b383cf
Remove obsolete file
Nashatyrev Aug 31, 2019
8a157ae
Java interop minor fixes
Nashatyrev Sep 7, 2019
184e297
Merge remote-tracking branch 'remotes/origin/feature/cleanup' into fe…
shahankhatch Sep 8, 2019
42d0551
Add sources maven artifact
Nashatyrev Sep 9, 2019
91ef0b6
Fix PeerId generation
Nashatyrev Sep 9, 2019
8551769
Add Network.connect() variant where peerId is embedded as /p2p protocol
Nashatyrev Sep 9, 2019
4747283
Fix p2p protocol binary deserialize
Nashatyrev Sep 9, 2019
609dd4f
Fix secp256k1 signing/verifying: sha256(data) should be signed verified
Nashatyrev Sep 10, 2019
b10e94f
Fix lint warns
Nashatyrev Sep 10, 2019
bf2c82f
Merge remote-tracking branch 'remotes/origin/feature/cleanup' into fe…
shahankhatch Sep 10, 2019
33df9f0
Pass remote PeerId to SecureChannel when available to validate it on …
Nashatyrev Sep 11, 2019
08b0f11
Merge remote-tracking branch 'remotes/origin/feature/cleanup' into fe…
shahankhatch Sep 11, 2019
a0ea1d7
Some changes towards completing handshake before sending client data …
shahankhatch Sep 11, 2019
a551932
Add Identify protocol stub
Nashatyrev Sep 11, 2019
1a48844
Fix Identify message encode/decode
Nashatyrev Sep 12, 2019
b9768f8
Fix adding debug handler after security handler
Nashatyrev Sep 12, 2019
7585e3e
Futures should fail correctly on protocol negotiation failures
Nashatyrev Sep 12, 2019
0c05837
Don't throw exceptions when receiving remote CLOSE after local RESET
Nashatyrev Sep 12, 2019
1c6a647
Add remote peerIds to test to check peerId validity
Nashatyrev Sep 12, 2019
c844197
Disable validator in test since our messages via p2pd are sent unsigned
Nashatyrev Sep 12, 2019
c0d0361
Close the Identify stream with CLOSE instead of RESET
Nashatyrev Sep 12, 2019
53e1da5
Appropriate reaction for the case when stream is tried to be created …
Nashatyrev Sep 12, 2019
355730f
Can now supply Identify with response message
Nashatyrev Sep 12, 2019
5aead9f
Fix test
Nashatyrev Sep 12, 2019
001d6cc
Fix lint
Nashatyrev Sep 12, 2019
703f6f2
Check PeerId bytes boundaries
Nashatyrev Sep 12, 2019
9c95709
Store var sized serialized protocol values without len prefix
Nashatyrev Sep 12, 2019
846afd9
Cut the Pubsub.seqno if it is longer than 8 bytes. This relaxing aims…
Nashatyrev Sep 13, 2019
b22b19c
Add sample test with parsing message dump from logs
Nashatyrev Sep 13, 2019
0165d79
Working noise channel that will establish a secure connection then en…
shahankhatch Sep 16, 2019
123bc71
After refactoring, adding shared class
shahankhatch Sep 16, 2019
18b52a2
Added imports
shahankhatch Sep 16, 2019
bce5fd5
run through linter
shahankhatch Sep 16, 2019
6bd58ae
Merge remote-tracking branch 'remotes/origin/feature/cleanup' into fe…
shahankhatch Sep 16, 2019
50aee4c
Move noise impl out of core to implementation packages
Nashatyrev Sep 16, 2019
b7abfc9
Move Curve25519 Key impl out of core to implementation packages
Nashatyrev Sep 16, 2019
36cbaae
Embed properties to class constructor
Nashatyrev Sep 16, 2019
b62c84d
Updating to address PR comments:
shahankhatch Sep 17, 2019
00aba54
Removed super calls.
shahankhatch Sep 17, 2019
485821a
Add Transport, remoteAddress, localAddress properties to Connection
Nashatyrev Sep 17, 2019
eefcd73
Complete Identify protocol
Nashatyrev Sep 17, 2019
ca645b1
Make separate Libp2p Daemon runner. Run tests with p2pd when available
Nashatyrev Sep 17, 2019
aee6b4f
Some more docs
Nashatyrev Sep 17, 2019
7fa518e
Add some more docs
Nashatyrev Sep 17, 2019
e4395f8
Fix lint warns
Nashatyrev Sep 17, 2019
3bad131
enabled read decoding ability
shahankhatch Sep 21, 2019
81686f6
Added write encoding
shahankhatch Sep 21, 2019
80bd6fb
minor cleanup
shahankhatch Sep 21, 2019
ee7d3c8
more cleanup
shahankhatch Sep 21, 2019
af686e4
more cleanup
shahankhatch Sep 21, 2019
ad44741
more cleanup
shahankhatch Sep 21, 2019
f2a0121
corrected calls to pipeline to use ByteBuf so that encrypter and decr…
shahankhatch Sep 21, 2019
bde0a63
updated to use lateinit
shahankhatch Sep 21, 2019
3cf6412
changed to lateinit, and applied linting and formatting
shahankhatch Sep 21, 2019
12efd47
Merge remote-tracking branch 'remotes/origin/feature/cleanup' into fe…
shahankhatch Sep 21, 2019
3d8d765
Reinstate handles(addr) tests
jezhiggins Sep 24, 2019
ed8152d
Move logger up into companion object
jezhiggins Sep 24, 2019
a75a331
Extract bindListeners helper fun
jezhiggins Sep 24, 2019
9feac30
Pull out unbindListeners
jezhiggins Sep 24, 2019
e662654
Use no-op upgrader in listen test
jezhiggins Sep 24, 2019
c148b96
Split testListenClose into three separate tests
jezhiggins Sep 24, 2019
23740df
Further small clarifications in the listen tests
jezhiggins Sep 24, 2019
cc60a95
Temporarily disable dial test
jezhiggins Sep 24, 2019
6f0f846
Gather TcpTransport tests into nested classes, grouped by operation
jezhiggins Sep 24, 2019
e0440f2
recommence work on TcpTransport dial tests
jezhiggins Sep 24, 2019
e0d1fcb
establish connection and disconnection on transport close
jezhiggins Sep 24, 2019
5375799
Move asserts to end of tests, so we don't accidentally leave sockets …
jezhiggins Sep 25, 2019
076ad61
Prevent Secio handshake from blocking on some platforms
jezhiggins Sep 25, 2019
efdca3b
Merge branch 'bugfix/stop-secio-handshake-blocking' into feature/test…
jezhiggins Sep 25, 2019
57f8772
Pulled out helpers to simply body of test
jezhiggins Sep 25, 2019
dbbdccc
Dial multiple connections. Ensure they're all closed
jezhiggins Sep 25, 2019
37b7031
Avoid race conditions counting incoming connections
jezhiggins Sep 25, 2019
dbec25e
test disconnection on server close
jezhiggins Sep 25, 2019
fe1c171
disconnect dialled channels test
jezhiggins Sep 25, 2019
aacf4b9
Disabling parallelism in test runs for the time being due to port col…
shahankhatch Sep 27, 2019
e47aeaf
Suppress unused parameter warning
jezhiggins Sep 30, 2019
dcff9aa
Correct unused variable warning
jezhiggins Sep 30, 2019
95eada4
Match parameter name to base class name
jezhiggins Sep 30, 2019
e447ff2
Fix name shadowing
jezhiggins Sep 30, 2019
ee1b119
Comment out unused variables
jezhiggins Sep 30, 2019
17ee724
Fixed unused variable warning
jezhiggins Sep 30, 2019
9076330
Match parameter name with corresponding name in base class
jezhiggins Sep 30, 2019
f1e342a
Fix shadowed name
jezhiggins Sep 30, 2019
ccb51bd
lint fixes
jezhiggins Sep 30, 2019
b8366ad
We do need conn1_2 - make sure it's closed properly
jezhiggins Sep 30, 2019
35e55a2
Dial down assert to informational
jezhiggins Sep 30, 2019
249b874
Decompose Noise Cipher from Handshake classes
Nashatyrev Oct 2, 2019
3137f40
Attempting to use NoiseXXSecureChannel in HostTest
shahankhatch Oct 2, 2019
3bbe71a
Refactored tests
jezhiggins Oct 2, 2019
99ea4cb
s/msg1.array/msg1.toByteArray/
jezhiggins Oct 2, 2019
8b9959d
Lint fixes
jezhiggins Oct 2, 2019
8ee63d5
Made HostTest abstract so JUnit doesn't try to run it
jezhiggins Oct 2, 2019
324fbca
add tags
jezhiggins Oct 2, 2019
d7bb124
Change when handlers are removed - the setup is sensitive to this. No…
jezhiggins Oct 2, 2019
5f928c9
Add NoiseXXCodec after signalling session - Boom, now it works.
jezhiggins Oct 2, 2019
cee5b19
Lint fixes
jezhiggins Oct 2, 2019
dce8204
Payload is identity public key and signed noise static key
shahankhatch Oct 6, 2019
63362dd
Added string prefix to signed data and verification
shahankhatch Oct 7, 2019
f7e16a8
Fixes to Noise channel and also enables multiple parallel connections
shahankhatch Oct 13, 2019
66f1b5d
Making Noise protocol implementation more robust to timeouts and errors.
shahankhatch Oct 14, 2019
666f1e3
Fix for recognizing successful connections
shahankhatch Oct 14, 2019
f31f47f
Fix lint warns
Nashatyrev Oct 16, 2019
a8830c9
Updates for PR comments on logging and message buffer sizes
shahankhatch Oct 21, 2019
f9d094e
linted
shahankhatch Oct 21, 2019
5017a28
Merge remote-tracking branch 'remotes/origin/develop' into feature/ma…
shahankhatch Oct 22, 2019
94d1d4b
Some minor code clean up changes
Nashatyrev Oct 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,12 @@ $RECYCLE.BIN/
*.msp

# Windows shortcuts
*.lnk
*.lnk
/.project
/.idea/codeStyles/codeStyleConfig.xml
/.idea/jvm-libp2p.iml
/.idea/kotlinScripting.xml
/.idea/misc.xml
/.idea/modules.xml
/.idea/codeStyles/Project.xml
/.idea/vcs.xml
7 changes: 5 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ dependencies {
compile("org.apache.logging.log4j:log4j-api:${log4j2Version}")
compile("org.apache.logging.log4j:log4j-core:${log4j2Version}")

compile("javax.xml.bind:jaxb-api:2.3.1")

testCompile("org.junit.jupiter:junit-jupiter-api:5.4.2")
testCompile("org.junit.jupiter:junit-jupiter-params:5.4.2")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.2")
Expand Down Expand Up @@ -92,9 +94,10 @@ tasks.test {
events("PASSED", "FAILED", "SKIPPED")
}

// disabling the parallel test runs for the time being due to port collisions
// If GRADLE_MAX_TEST_FORKS is not set, use half the available processors
maxParallelForks = (System.getenv("GRADLE_MAX_TEST_FORKS")?.toInt() ?:
Runtime.getRuntime().availableProcessors().div(2))
// maxParallelForks = (System.getenv("GRADLE_MAX_TEST_FORKS")?.toInt() ?:
// Runtime.getRuntime().availableProcessors().div(2))
}

kotlinter {
Expand Down
243 changes: 243 additions & 0 deletions src/main/java/com/southernstorm/noise/crypto/Blake2bMessageDigest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
/*
* Copyright (C) 2016 Southern Storm Software, Pty Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

package com.southernstorm.noise.crypto;

import com.southernstorm.noise.protocol.Destroyable;

import java.security.DigestException;
import java.security.MessageDigest;
import java.util.Arrays;

/**
* Fallback implementation of BLAKE2b for the Noise library.
*
* This implementation only supports message digesting with an output
* length of 64 bytes and a limit of 2^64 - 1 bytes of input.
* Keyed hashing and variable-length digests are not supported.
*/
public class Blake2bMessageDigest extends MessageDigest implements Destroyable {

private long[] h;
private byte[] block;
private long[] m;
private long[] v;
private long length;
private int posn;

/**
* Constructs a new BLAKE2b message digest object.
*/
public Blake2bMessageDigest() {
super("BLAKE2B-512");
h = new long [8];
block = new byte [128];
m = new long [16];
v = new long [16];
engineReset();
}

@Override
protected byte[] engineDigest() {
byte[] digest = new byte [64];
try {
engineDigest(digest, 0, 64);
} catch (DigestException e) {
// Shouldn't happen, but just in case.
Arrays.fill(digest, (byte)0);
}
return digest;
}

@Override
protected int engineDigest(byte[] buf, int offset, int len) throws DigestException
{
if (len < 64)
throw new DigestException("Invalid digest length for BLAKE2b");
Arrays.fill(block, posn, 128, (byte)0);
transform(-1);
for (int index = 0; index < 8; ++index) {
long value = h[index];
buf[offset++] = (byte)value;
buf[offset++] = (byte)(value >> 8);
buf[offset++] = (byte)(value >> 16);
buf[offset++] = (byte)(value >> 24);
buf[offset++] = (byte)(value >> 32);
buf[offset++] = (byte)(value >> 40);
buf[offset++] = (byte)(value >> 48);
buf[offset++] = (byte)(value >> 56);
}
return 32;
}

@Override
protected int engineGetDigestLength() {
return 64;
}

@Override
protected void engineReset() {
h[0] = 0x6a09e667f3bcc908L ^ 0x01010040;
h[1] = 0xbb67ae8584caa73bL;
h[2] = 0x3c6ef372fe94f82bL;
h[3] = 0xa54ff53a5f1d36f1L;
h[4] = 0x510e527fade682d1L;
h[5] = 0x9b05688c2b3e6c1fL;
h[6] = 0x1f83d9abfb41bd6bL;
h[7] = 0x5be0cd19137e2179L;
length = 0;
posn = 0;
}

@Override
protected void engineUpdate(byte input) {
if (posn >= 128) {
transform(0);
posn = 0;
}
block[posn++] = input;
++length;
}

@Override
protected void engineUpdate(byte[] input, int offset, int len) {
while (len > 0) {
if (posn >= 128) {
transform(0);
posn = 0;
}
int temp = (128 - posn);
if (temp > len)
temp = len;
System.arraycopy(input, offset, block, posn, temp);
posn += temp;
length += temp;
offset += temp;
len -= temp;
}
}

// Permutation on the message input state for BLAKE2b.
static final byte[][] sigma = {
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4},
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8},
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13},
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9},
{12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11},
{13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10},
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5},
{10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0},
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
};

private void transform(long f0)
{
int index;
int offset;

// Unpack the input block from little-endian into host-endian.
for (index = 0, offset = 0; index < 16; ++index, offset += 8) {
m[index] = (block[offset] & 0xFFL) |
((block[offset + 1] & 0xFFL) << 8) |
((block[offset + 2] & 0xFFL) << 16) |
((block[offset + 3] & 0xFFL) << 24) |
((block[offset + 4] & 0xFFL) << 32) |
((block[offset + 5] & 0xFFL) << 40) |
((block[offset + 6] & 0xFFL) << 48) |
((block[offset + 7] & 0xFFL) << 56);
}

// Format the block to be hashed.
for (index = 0; index < 8; ++index)
v[index] = h[index];
v[8] = 0x6a09e667f3bcc908L;
v[9] = 0xbb67ae8584caa73bL;
v[10] = 0x3c6ef372fe94f82bL;
v[11] = 0xa54ff53a5f1d36f1L;
v[12] = 0x510e527fade682d1L ^ length;
v[13] = 0x9b05688c2b3e6c1fL;
v[14] = 0x1f83d9abfb41bd6bL ^ f0;
v[15] = 0x5be0cd19137e2179L;

// Perform the 12 BLAKE2b rounds.
for (index = 0; index < 12; ++index) {
// Column round.
quarterRound(0, 4, 8, 12, 0, index);
quarterRound(1, 5, 9, 13, 1, index);
quarterRound(2, 6, 10, 14, 2, index);
quarterRound(3, 7, 11, 15, 3, index);

// Diagonal round.
quarterRound(0, 5, 10, 15, 4, index);
quarterRound(1, 6, 11, 12, 5, index);
quarterRound(2, 7, 8, 13, 6, index);
quarterRound(3, 4, 9, 14, 7, index);
}

// Combine the new and old hash values.
for (index = 0; index < 8; ++index)
h[index] ^= (v[index] ^ v[index + 8]);
}

private static long rightRotate32(long v)
{
return v << 32 | (v >>> 32);
}

private static long rightRotate24(long v)
{
return v << 40 | (v >>> 24);
}

private static long rightRotate16(long v)
{
return v << 48 | (v >>> 16);
}

private static long rightRotate63(long v)
{
return v << 1 | (v >>> 63);
}

private void quarterRound(int a, int b, int c, int d, int i, int row)
{
v[a] += v[b] + m[sigma[row][2 * i]];
v[d] = rightRotate32(v[d] ^ v[a]);
v[c] += v[d];
v[b] = rightRotate24(v[b] ^ v[c]);
v[a] += v[b] + m[sigma[row][2 * i + 1]];
v[d] = rightRotate16(v[d] ^ v[a]);
v[c] += v[d];
v[b] = rightRotate63(v[b] ^ v[c]);
}

@Override
public void destroy() {
Arrays.fill(h, (long)0);
Arrays.fill(block, (byte)0);
Arrays.fill(m, (long)0);
Arrays.fill(v, (long)0);
}
}
Loading