Giter Site home page Giter Site logo

kcrypt / scala-blake3 Goto Github PK

View Code? Open in Web Editor NEW
25.0 2.0 6.0 3.66 MB

This is a highly optimized blake3 implementation for scala, scala-js and scala-native

License: Other

Scala 99.43% Shell 0.05% Python 0.52%
scala scala-js scalajs scala-native blake3

scala-blake3's Issues

Chunking data results in different hash to using the data non-chunked

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)
    }
}

CI fails on unittests

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

`ArrayIndexOutOfBoundsException` on JVM

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:

  • scala-blake3: 2.8.0
  • scala: 2.13.6
  • JVM: OpenJDK 64-Bit Server VM Temurin-11.0.13+8 (build 11.0.13+8, mixed mode)

Seems like a rare GC bug.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.