Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

* update gradle v6.3 -> v6.7.1

* update khex v0.6 -> v1.0.0

* add build config to gradle.properties

* add symbolic link to gradle.properties under buildSrc

* add mpp-module.gradle.kts

* add khex as a commonTest dependency

* enable 'InlineClasses' language feature for all test sourcesets

* add common tests config to mpp-module.gradle.kts

* allow gradual conversion of submodules to MPP

* use 'mavenLocal' deployment of MPP khex temporarily

* increase tests timeout for nodeJS

* TODO: enable strict 'explicitApi'

* convert Keccak submodule to MPP (depend on com.ionspin.kotlin:bignum for MPP BigInteger)

* update kotlin v1.4.21 -> v.1.4.30

* update bignum v0.2.4-SNAPSHOT -> v0.2.4 (stable)

* convert ripemd160 module to multiplatform

* convert sha256 module to multiplatform

* convert sha512 module to multiplatform

* remove non-multiplatform subprojects config

* define dependency versions in Versions.kt

* enabled strict 'explicitApi' mode

* added compilation options for js

* update gradle v6.7.1 -> v6.8.1

* set jvm target to 1.8 (default is 1.6)

* simplify test tasks logging config

* fetch KHex from GitHub Packages

* config dependencyResolutionManagement in settings.gradle.kts

* add comment for the GitHub Packages public access workaround

* fix KHex dependency group name

* add aggregate test report task to root project

* fix KHex dependency groupId

* add GitHub Actions workflows

* swap names of workflows

* add 'maven-publish' with Github Packages config

* increase mocha test timeout to 300s

* update 'com.ionspin.kotlin:bignum' v0.2.4 -> v0.2.8

* use KHex from GitHub Packages of the origin repo

* update gradle v6.8.1 -> v6.8.2

* update KHex vmaster-SNAPSHOT -> v1.1.0

* update README.md

* remove 'version' from gradle.properties
9cfabe9

Git stats

Files

Permalink
Failed to load latest commit information.

README.md

CI

KHash

KHash is a Kotlin multiplatform library implementing common hashing functions.

A part from that, it also provides some useful extensions functions.

The implemented hashing functions are the following.

Get it

GitHub Packages

This library is available through GitHub Packages.

badge badge

In order to use it, first include the GitHub Packages maven repository inside your project build.gradle.kts file:

repositories {
    maven {
        name = "komputing/KHash GitHub Packages"
        url = uri("https://maven.pkg.github.com/komputing/KHash")
        credentials {
            username = "token"
            password = "\u0039\u0032\u0037\u0034\u0031\u0064\u0038\u0033\u0064\u0036\u0039\u0061\u0063\u0061\u0066\u0031\u0062\u0034\u0061\u0030\u0034\u0035\u0033\u0061\u0063\u0032\u0036\u0038\u0036\u0062\u0036\u0032\u0035\u0065\u0034\u0061\u0065\u0034\u0032\u0062"
        }
    }
}

When 'username' could be anything and 'password' is an encoded access token for public access.

JitPack (JVM only!)

This library is available on Jitpack. The current version is:

badge

In order to use it, first include the Jitpack maven repository inside your project build.gradle.kts file:

repositories {
    maven { url="https://jitpack.io" }
}

Set it up

Include the modules inside your project:

dependencies {
    implementation("com.github.komputing.khash:<module>:<version>")
}

Where <version> can be either a release or <branch>-SNAPSHOT such as master-SNAPHOT.

Usage

keccak

Module containing the implementation of the Kecccak hashing algorithms.

Object usage

// Compute the Keccak digest of a byte array based on the given parameter
Keccak.digest(byteArrayOf(1, 2, 3), KeccakParameter.KECCAK_512) 
Keccak.digest(byteArrayOf(1, 2, 3), KeccakParameter.SHA3_224) 
Keccak.digest(byteArrayOf(1, 2, 3), KeccakParameter.SHAKE_128) 

Extension functions

// Compute a specific Keccak digest of a byte array based on the given parameter
byteArrayOf(1, 2, 3).digestKeccak(KeccakParameter.KECCAK_512)

// Compute a specific Keccak digest of a string based on the given parameter
"The quick brown fox jumps over the lazy dog".digestKeccak(parameter = KeccakParameter.SHA3_384)

ripemd160

Module containing the implementation of the RIPEMD160 hashing algorithms.

Object usage

// Compute the RIPEMD160 digest of a byte array
val input = byteArrayOf(1, 2, 3)
val output = ByteArray(Ripemd160Digest.DIGEST_LENGTH)
Ripemd160Digest().apply {
  update(input, 0, input.size)
  doFinal(output, 0)
} 

Extension functions

// Compute the RIPEMD160 digest of a byte array
byteArrayOf(1, 2, 3).ripemd160()

// Compute the RIPEMD160 digest of a string
"The quick brown fox jumps over the lazy dog".ripemd160()

sha256

Module containing the implementation of the SHA256 hashing algorithms.

Object usage

// Compute the SHA-256 digest of a byte array 
Sha256.digest(byteArrayOf(1, 2, 3))

Extension functions

// Compute the SHA-256 digest of a byte array
byteArrayOf(1, 2, 3).sha256()

// Compute the SHA-256 digest of a string
"The quick brown fox jumps over the lazy dog".sha256()

Disclaimer

The results should be correct as the Nist test vectors pass and also second degree tests pass in KEthereum. That said there should be more eyes on this project before it is used in really critical situations. If you can spare some time please have a look at the code - feedback is very welcome.

Also this code is not hardened against side channel attacks. Keep this in mind when hashing sensitive content! I would be really happy about input from security researchers here - there is also an open issue with a bounty for this.

Links

Projects using this library

License

MIT