Add more doc copied from libsodium

This commit is contained in:
Ugljesa Jovanovic 2020-11-14 13:27:42 +01:00
parent 10a3526b8e
commit 48d81f257e
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
9 changed files with 203 additions and 1 deletions

View File

@ -108,6 +108,7 @@ And here is the usage sample
The functions are mapped from libsodium to kotiln objects, so `crypto_secretstream_xchacha20poly1305_init_push` becomes
`SecretStream.xChaCha20Poly1305InitPush`
![Alt text](./doc/res/libsodium_api_mapping.svg)
At the moment you should refer to original libsodium documentation for instructions on how to use the library
@ -139,6 +140,7 @@ Currently supported native platforms:
- Android testing
- Fix browser testing, both locally and in CI/CD
- LobsodiumUtil `unpad` and `fromBase64` native implementations use a nasty hack to support shared native sourceset. The hack either needs to be removed and replaced with another solution or additional safeguards need to be added.
- Complete exposing libsodium constants

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="297mm"
height="210mm"
viewBox="0 0 297 210"
version="1.1"
id="svg8"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)"
sodipodi:docname="libsodium_api_mapping.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.7"
inkscape:cx="554.56493"
inkscape:cy="538.66625"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
inkscape:document-rotation="0"
showgrid="false"
inkscape:window-width="1276"
inkscape:window-height="1396"
inkscape:window-x="3840"
inkscape:window-y="20"
inkscape:window-maximized="0" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<text
xml:space="preserve"
style="font-size:10.5833px;line-height:1.25;font-family:sans-serif;word-spacing:0px;stroke-width:0.264583"
x="9.5235968"
y="64.991554"
id="text12"><tspan
sodipodi:role="line"
id="tspan10"
x="9.5235968"
y="64.991554"
style="stroke-width:0.264583"><tspan
style="fill:#ff0000"
id="tspan18">crypto</tspan>_<tspan
style="fill:#008000"
id="tspan20">secretstream</tspan>_<tspan
style="fill:#0000ff"
id="tspan22">xchacha20poly1305</tspan>_<tspan
style="fill:#0000ff"
id="tspan28">init</tspan>_<tspan
style="fill:#0000ff"
id="tspan30">push</tspan></tspan></text>
<text
xml:space="preserve"
style="font-size:10.5833px;line-height:1.25;font-family:sans-serif;word-spacing:0px;stroke-width:0.264583"
x="47.202728"
y="94.062126"
id="text16"><tspan
sodipodi:role="line"
id="tspan14"
x="47.202728"
y="94.062126"
style="stroke-width:0.264583"><tspan
style="fill:#008000"
id="tspan34">SecretStream</tspan>.<tspan
style="fill:#0000ff"
id="tspan32">xChaCha20Poly1305InitPush</tspan></tspan></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -19,6 +19,40 @@ data class BoxEncryptedDataAndTag(val ciphertext: UByteArray, val tag: UByteArra
class BoxCorruptedOrTamperedDataException() : RuntimeException("MAC validation failed. Data is corrupted or tampered with.")
/**
* Authenticated encryption (crypto_box_* API)
*
* Using public-key authenticated encryption, Bob can encrypt a confidential message specifically for Alice, using Alice's public key.
* Using Bob's public key, Alice can compute a shared secret key. Using Alice's public key and his secret key,
* Bob can compute the exact same shared secret key. That shared secret key can be used to verify that the encrypted
* message was not tampered with, before eventually decrypting it.
* Alice only needs Bob's public key, the nonce and the ciphertext. Bob should never ever share his secret key,
* even with Alice.
* And in order to send messages to Alice, Bob only needs Alice's public key. Alice should never ever share her secret
* key either, even with Bob.
* Alice can reply to Bob using the same system, without having to generate a distinct key pair.
* The nonce doesn't have to be confidential, but it should be used with just one invocation of crypto_box_easy() for a
* particular pair of public and secret keys.
* One easy way to generate a nonce is to use randombytes_buf(), considering the size of the nonces the risk of any
* random collisions is negligible. For some applications, if you wish to use nonces to detect missing messages or to
* ignore replayed messages, it is also acceptable to use a simple incrementing counter as a nonce. A better alternative
* is to use the crypto_secretstream() API.
* When doing so you must ensure that the same value can never be re-used (for example you may have multiple threads
* or even hosts generating messages using the same key pairs).
* As stated above, senders can decrypt their own messages, and compute a valid authentication tag for any messages
* encrypted with a given shared secret key. This is generally not an issue for online protocols. If this is not
* acceptable, check out the Sealed Boxes section, as well as the Key Exchange section in this documentation.
*
*
* Sealed boxes (crypto_box_seal_* API)
*
* Sealed boxes are designed to anonymously send messages to a recipient given its public key.
* Only the recipient can decrypt these messages, using its private key. While the recipient can verify the integrity
* of the message, it cannot verify the identity of the sender.
* A message is encrypted using an ephemeral key pair, whose secret part is destroyed right after the encryption process.
* Without knowing the secret key used for a given message, the sender cannot decrypt its own message later.
* And without additional data, a message cannot be correlated with the identity of its sender.
*/
expect object Box {
/**
* The crypto_box_keypair() function randomly generates a secret key and a corresponding public key.
@ -87,4 +121,4 @@ expect object Box {
fun sealOpen(ciphertext: UByteArray, recipientsPublicKey: UByteArray, recipientsSecretKey: UByteArray) : UByteArray
}
}

View File

@ -0,0 +1,36 @@
package com.ionspin.kotlin.crypto.sample
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.hexStringToUByteArray
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 30-Oct-2020
*/
interface DataPackage {
fun getContentAsUByteArray() : UByteArray
fun getStringRepresentation() : String
}
data class Utf8StringData(val content: String) : DataPackage {
override fun getContentAsUByteArray(): UByteArray {
return content.encodeToUByteArray()
}
override fun getStringRepresentation(): String {
return content
}
}
data class HexadecimalStringData(val content: String) : DataPackage {
override fun getContentAsUByteArray(): UByteArray {
return content.hexStringToUByteArray()
}
override fun getStringRepresentation(): String {
return content
}
}
data class FileData(val filePath: )

View File

@ -0,0 +1,11 @@
package com.ionspin.kotlin.crypto.sample
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 30-Oct-2020
*/
expect class FileWrapper(path: String) {
fun exists() : Boolean
fun rea
}

View File

@ -7,4 +7,5 @@ package com.ionspin.kotlin.crypto.sample.ui
*/
class LandingController {
}

View File

@ -0,0 +1,7 @@
package com.ionspin.kotlin.crypto.sample.workbench
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 30-Oct-2020
*/

View File

@ -0,0 +1,10 @@
package com.ionspin.kotlin.crypto.sample.workbench
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 30-Oct-2020
*/
interface WorkbenchElement {
}

View File

@ -0,0 +1,10 @@
package com.ionspin.kotlin.crypto.sample.workbench
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 30-Oct-2020
*/
interface WorkbenchView {
}