appmattus / crypto Goto Github PK
View Code? Open in Web Editor NEWA collection of Kotlin Multiplatform cryptographic hashing functions.
License: Apache License 2.0
A collection of Kotlin Multiplatform cryptographic hashing functions.
License: Apache License 2.0
Using Swifts async/await feature and Task.detached {}
I load some files in the background where I want to calculate the checksum for.
My code looks like this:
do {
let digest = Algorithm.XXH3_128().createDigest().platform()
let data = try Data(contentsOf: URL(fileURLWithPath: photo.url))
return digest.digest(input_: data)
} catch {
Log.error("Failed creating checksum", error: error)
}
If I execute that a IncorrectDereferenceException
occurs as follows:
Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
at 0 shared 0x000000010f091b9d ThrowIncorrectDereferenceException + 93
at 1 shared 0x000000010f6ffd9b kfun:com.appmattus.crypto.internal.core.xxh3#XXH3_128bits_reset(com.appmattus.crypto.internal.core.xxh3.XXH3_state_s){}com.appmattus.crypto.internal.core.xxh3.XXH_errorcode + 171
at 2 shared 0x000000010f6f7833 kfun:com.appmattus.crypto.internal.core.xxh3.XXH3_128#reset(){} + 435
at 3 shared 0x000000010f6f7104 kfun:com.appmattus.crypto.internal.core.xxh3.XXH3_128#<init>(com.appmattus.crypto.Algorithm.XXH3_128){} + 276
at 4 shared 0x000000010f2acde5 kfun:com.appmattus.crypto.internal.CoreDigest#create(com.appmattus.crypto.Algorithm){}com.appmattus.crypto.Digest<*> + 18277
It works if I wrap that into DispatchQueue.main.async {}
which of course causes my UI to hang.
This relates to Kotlin/Native memory model.
Maybe you can see if you can fix it in a way that it can be used on background threads. :)
Create PR into https://github.com/terrakok/kmm-awesome so the library is better known.
From a cryptohash perspective we already implement various algorithms that have feature requests in the krypto library:
Hi there!
Thanks for your great library.
I have a question: why nonce size in XChaCha20
is strictly 32 in bytes, or NONCE_SIZE
== 24.
In my case i need NONCE_SIZE
to be eqal to 12.
Encryption with 12 value works fine, but decryption in method hChaCha20
fails with crash.
Not sure whats up, my project includes ton of libs from maven central, but this lib can't be resolved for some reason:
:desktop:jvmMain: Could not resolve com.appmattus.crypto:cryptohash:0.10.1.
But, obviously it's there:
https://central.sonatype.com/artifact/com.appmattus.crypto/cryptohash/0.10.1/overview
Some short inputs with 1,2, or 3 bytes lead to different hash values compared to the native reference implementation from https://github.com/Cyan4973/xxHash. The behavior can be reproduced with this unit test https://github.com/dynatrace-oss/hash4j/blob/01e8ed429c61acd7735967b2ba472c80d4616337/src/test/java/com/dynatrace/hash4j/hashing/CrossCheckTest.java#L195 which checks the compatibility with the reference implementation.
Now as Kotlin 1.5.30 is out it would be nice if you could add the targets macosArm64
and iosSimulatorArm64
.
I need SHA-256 for my project. Looking through the code, it seems like it's supported, so it should probably be added to the README.
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.