kcrypt / scala-blake3 Goto Github PK
View Code? Open in Web Editor NEWThis is a highly optimized blake3 implementation for scala, scala-js and scala-native
License: Other
This is a highly optimized blake3 implementation for scala, scala-js and scala-native
License: Other
I have test data based on the official test vectors where I have a 64 byte array with each byte in the array having the value of its index. i.e. my input is an Array[Byte]
with value data = [0, 1, 2, …, 63]
Running Blake3.newHasher().update(data).doneHex(16)
results in 4eed7141ea4a5cd4
matching the expected result.
However, if instead I split the data into two 32-byte chunks, data1 = [0, 1, …, 31]
and data2 = [32, 32, …, 63]
and run Blake3.newHasher().update(data1).update(data2).doneHex(16)
I should expect the same output but instead get cdc46473e43a732a
.
Weirdly splitting a 63 byte array into 32 and 31 bytes and performing the same results in the correct data so I'm not sure if there's something funky going on that I'm missing.
The same can also be observed for other sized arrays of data, for example 128, 1024, 2048 when split in two.
I wrote the following test to show this in action, although I apologise for the code being in Kotlin, I'm not a Scala developer (yet)!
class Testing {
@Test
fun sixtyThree() {
val hasher1 = Blake3.newHasher()
hasher1.update(ByteArray(63) { it.toByte() })
val expected = hasher1.doneHex(16)
val hasher2 = Blake3.newHasher()
hasher2.update(ByteArray(32) { it.toByte() })
hasher2.update(ByteArray(31) { (it + 32).toByte() })
val actual = hasher2.doneHex(16)
// works as expected
assertEquals(expected, actual)
}
@Test
fun sixtyFour() {
val hasher1 = Blake3.newHasher()
hasher1.update(ByteArray(64) { it.toByte() })
val expected = hasher1.doneHex(16)
val hasher2 = Blake3.newHasher()
hasher2.update(ByteArray(32) { it.toByte() })
hasher2.update(ByteArray(32) { (it + 32).toByte() })
val actual = hasher2.doneHex(16)
// fails
assertEquals(expected, actual)
}
}
Local root 1dd6492 fails as:
[info] All possibly bytes where inputLen
[info] - when 1024
[info] - when 2048
[info] - when 16665 *** FAILED ***
[info] "...ddd2840c53e45c2a20aa[]" was not equal to "...ddd2840c53e45c2a20aa[f0ed94]" (TestVector.scala:191)
...
[info] *** 1 TEST FAILED ***
[error] Failed tests:
[error] ky.korins.blake3.AdditionalTestVectorsTest
[info] Fast optimizing /home/runner/work/scala-blake3/scala-blake3/js/target/scala-2.12/blake3-test-fastopt
The stack trace:
java.lang.ArrayIndexOutOfBoundsException: Index 37 out of bounds for length 37
at ky.korins.blake3.Output.rootBytes(Output.scala:81)
at ky.korins.blake3.HasherImpl.done(HasherImpl.scala:202)
...
it happened when rootBytes(..)
is called with:
out
as Array[Byte](37)
;off
is 0
;len
is 37
.An issue happened inside this match:
lim - pos match {
case 1 =>
case 2 =>
case 3 =>
case _ =>
}
on case _ =>
condition, after pos += 1
it fails on out(pos)
.
ENV:
2.8.0
2.13.6
OpenJDK 64-Bit Server VM Temurin-11.0.13+8 (build 11.0.13+8, mixed mode)
Seems like a rare GC bug.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.