SpinalHDL / SpinalCrypto

SpinalHDL - Cryptography libraries
MIT License
50 stars 19 forks source link

Inheritance error occurred while using SHA2Core_Std() #18

Closed TealerLinkGuo closed 4 months ago

TealerLinkGuo commented 4 months ago

I want to use the hash IP provided by Spinalcrypto, but when I tested them, I encountered an error message

[info] **********************************************************************************************
[info] [Warning] Elaboration failed (0 error).
[info]           Spinal will restart with scala trace to help you to find the problem.
[info] **********************************************************************************************
[info] [Progress] at 0.478 : Elaborate components
[error] Exception in thread "main" java.lang.AbstractMethodError: Receiver class spinal.crypto.hash.HashCoreIO does not define or inherit an implementation of the resolved method 'abstract void spinal$lib$IMasterSlave$$_isMasterInterface_$eq(scala.Option)' of interface spinal.lib.IMasterSlave.
[error]         at spinal.lib.IMasterSlave$class.$init$(MasterSlave.scala:14)
[error]         at spinal.crypto.hash.HashCoreIO.<init>(Hash.scala:74)
[error]         at spinal.crypto.hash.sha3.SHA3Core_Std.<init>(SHA3Core_Std.scala:50)
[error]         at SHA256.<init>(sha256.scala:26)
[error]         at Test_SHA256$$anonfun$1.apply(sha256_sim.scala:6)
[error]         at Test_SHA256$$anonfun$1.apply(sha256_sim.scala:6)
[error]         at spinal.core.internals.PhaseCreateComponent$$anonfun$impl$67.apply(Phase.scala:2561)
[error]         at spinal.core.fiber.Engine$$anonfun$create$1.apply$mcV$sp(AsyncCtrl.scala:173)
[error]         at spinal.core.fiber.AsyncThread$$anonfun$1.apply$mcV$sp(AsyncThread.scala:60)
[error]         at spinal.core.fiber.EngineContext$$anonfun$newJvmThread$1.apply$mcV$sp(AsyncCtrl.scala:39)
[error]         at spinal.sim.JvmThread.run(SimManager.scala:51)
[error] Nonzero exit code returned from runner: 1
[error] (Compile / run) Nonzero exit code returned from runner: 1
[error] Total time: 6 s, completed Jul 18, 2024, 8:10:16 PM

Here is my code, It simply initialized SHA2Core_Std(), I checked the source code of HashCoreIO() in hash.scale and found that it inherits from IMasterSlave, but sbt run still reports an error

import spinal.core._
import spinal.lib._

import spinal.crypto.hash._
import spinal.crypto.hash.sha2._
import spinal.crypto.hash.sha3._

class SHA256() extends Component
{
    val io = new Bundle
    {
        val init  = in Bool()

        val valid = in Bool()
        val ready = in Bool()
        val last  = in Bool()

        val msg_data_size = in UInt(80 bits)
        val msg_data      = in Bits(640 bits)

        val sha256_hash = out Bits(256 bits)
        val out_valid   = out Bool()
    }

    val sha256_core = new SHA2Core_Std(SHA2_256, 640 bits)

    sha256_core.io.init      := io.init
    sha256_core.io.cmd.valid := io.valid
    sha256_core.io.cmd.msg   := io.msg_data
    sha256_core.io.cmd.last  := io.last
    sha256_core.io.cmd.size  := io.msg_data_size
    sha256_core.io.cmd.ready := io.ready

    io.sha256_hash := sha256_core.io.rsp.digest
    io.out_valid   := sha256_core.io.rsp.valid

}

Here is the Sim code if Sha256

import spinal.core._
import spinal.core.sim._

object Test_SHA256 extends App
{
    SimConfig.withWave.compile(new SHA256()).doSim{ dut =>
        dut.io.init #= true

        dut.io.valid #= false
        dut.io.ready #= false

        dut.io.msg_data #= 0
        dut.io.msg_data_size #= 0

        dut.io.last #= false
        dut.io.msg_data #= 0

        sleep(2)

        dut.io.init #= false
        dut.io.valid #= true
        dut.io.ready #= true

        dut.io.msg_data #= 123
        dut.io.msg_data_size #= 8

        dut.io.last #= true

        sleep(2)
    }
}
Dolu1990 commented 4 months ago

Hi,

I updated the SpinalCrypto to recent version of SpinalHDL. With it your issue seems to disapear. Can you give a try ? Note this also jump to scala 2.12.18 by default

TealerLinkGuo commented 4 months ago

Thank you for your prompt reply, but it is still can't run, After updating my build.sbt, sbt run now gives the following error message

[warn]
[warn]  Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading com.github.spinalhdl:spinalhdl-crypto_2.11:1.2.0
[error]   Not found
[error]   Not found
[error]   not found: /home/tealer_u/.ivy2/local/com.github.spinalhdl/spinalhdl-crypto_2.11/1.2.0/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/com/github/spinalhdl/spinalhdl-crypto_2.11/1.2.0/spinalhdl-crypto_2.11-1.2.0.pom
[error]         at lmcoursier.CoursierDependencyResolution.unresolvedWarningOrThrow(CoursierDependencyResolution.scala:346)
[error]         at lmcoursier.CoursierDependencyResolution.$anonfun$update$39(CoursierDependencyResolution.scala:315)
[error]         at scala.util.Either$LeftProjection.map(Either.scala:573)
[error]         at lmcoursier.CoursierDependencyResolution.update(CoursierDependencyResolution.scala:315)
[error]         at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:60)
[error]         at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:60)
[error]         at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$12(LibraryManagement.scala:142)
[error]         at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:74)
[error]         at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11(LibraryManagement.scala:144)
[error]         at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11$adapted(LibraryManagement.scala:131)
[error]         at sbt.util.Tracked$.$anonfun$inputChangedW$1(Tracked.scala:220)
[error]         at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:169)
[error]         at sbt.Classpaths$.$anonfun$updateTask0$1(Defaults.scala:3867)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error]         at sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error]         at sbt.Execute.work(Execute.scala:292)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error]         at java.base/java.lang.Thread.run(Thread.java:840)
[error] (update) sbt.librarymanagement.ResolveException: Error downloading com.github.spinalhdl:spinalhdl-crypto_2.11:1.2.0
[error]   Not found
[error]   Not found
[error]   not found: /home/tealer_u/.ivy2/local/com.github.spinalhdl/spinalhdl-crypto_2.11/1.2.0/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/com/github/spinalhdl/spinalhdl-crypto_2.11/1.2.0/spinalhdl-crypto_2.11-1.2.0.pom
[error] Total time: 3 s, completed Jul 19, 2024, 5:00:06 PM

Here is my build.sbt file

hisBuild / version := "1.0"
ThisBuild / scalaVersion := "2.11.12"
ThisBuild / organization := "org.example"

val spinalVersion = "latest.release"
val spinalCore = "com.github.spinalhdl" %% "spinalhdl-core" % spinalVersion
val spinalLib = "com.github.spinalhdl" %% "spinalhdl-lib" % spinalVersion
val spinalIdslPlugin = compilerPlugin("com.github.spinalhdl" %% "spinalhdl-idsl-plugin" % spinalVersion)

lazy val projectname = (project in file("."))
  .settings(
    Compile / scalaSource := baseDirectory.value / "spinalhdl_hls",
    libraryDependencies ++= Seq(spinalCore, spinalLib, spinalIdslPlugin)
  )
  .dependsOn(spinalCrypto)

lazy val spinalCrypto = RootProject(file("./SpinalCrypto"))

fork := true
Dolu1990 commented 4 months ago

Hi,

"2.11.12" => "2.12.18" "latest.release" => "2.10.2a"

Should clear most of the issues.