diff --git a/resources/models/aes_classes.puml b/resources/models/aes_classes.puml new file mode 100644 index 0000000..fa0ae97 --- /dev/null +++ b/resources/models/aes_classes.puml @@ -0,0 +1,25 @@ +@startuml aes_classes + +abstract class Cipher { + encrypt(plainText: Uint8List): CipherText + decrypt(cipherText: CipherText): Uint8List + encryptFile(plainTextFile: Path, cipherTextFile: Path) + decryptFile(cipherTextFile: Path, plainTextFile: Path) +} + +class AES extends Cipher { + key: SecretKey + mode: AESMode + padding: Padding + chunkSize: int + + encrypt(plainText: Uint8List): CipherText + decrypt(cipherText: CipherText): Uint8List + encryptFile(plainTextFile: Path, cipherTextFile: Path) + decryptFile(cipherTextFile: Path, plainTextFile: Path) + + encryptWithIV(plainText: Uint8List, iv: Uint8List): AESCipherChunk + decryptWithIV(cipherChunk: AESCipherChunk, iv: Uint8List): Uint8List +} + +@enduml \ No newline at end of file diff --git a/resources/models/aes_dss.puml b/resources/models/aes_dss.puml new file mode 100644 index 0000000..dd2d7d3 --- /dev/null +++ b/resources/models/aes_dss.puml @@ -0,0 +1,44 @@ +@startuml aes_dss + +actor user +participant AES as aes +participant CipherText as ct +participant CipherChunk as cc +participant NativeCrypto as nc + +user -> aes : new(key: SecretKey, mode: Mode, padding: Padding, chunkSize: int) +activate aes +aes --> user : AES +user -> aes : encrypt(plainText: Uint8List) + +loop for each chunk in plainText + aes -> nc : encrypt(chunk: Uint8List, key: Uint8List, "aes/gcm/NoPadding") + nc --> aes : Uint8List + aes -> cc : new(chunk: Uint8List) + cc --> aes : CipherChunk +end + +aes -> ct : new(chunks: List) +ct --> aes : CipherText +aes --> user : CipherText + +user -> aes : decrypt(cipherText: CipherText) +loop for each chunk in cipherText.chunks + aes -> nc : decrypt(chunk: Uint8List, key: Uint8List, "aes/gcm/NoPadding") + nc --> aes : Uint8List + aes --> aes : concat Uint8List +end + +aes --> user : Uint8List + +user -> aes : encryptFile(plainTextFile: File, cipherTextFile: File) +aes -> nc : encryptFile(plainTextFile: File, cipherTextFile: File, key: Uint8List, "aes/gcm/NoPadding") +nc --> aes : void +aes --> user : void + +user -> aes : decryptFile(cipherTextFile: File, plainTextFile: File) +aes -> nc : decryptFile(cipherTextFile: File, plainTextFile: File, key: Uint8List, "aes/gcm/NoPadding") +nc --> aes : void +aes --> user : void + +@enduml \ No newline at end of file diff --git a/resources/models/cipher_text_classes.puml b/resources/models/cipher_text_classes.puml new file mode 100644 index 0000000..ee96cb1 --- /dev/null +++ b/resources/models/cipher_text_classes.puml @@ -0,0 +1,63 @@ +@startuml cipher_text_classes + +abstract class ByteArray { + bytes : Uint8List + length : int + + ByteArray(bytes: Uint8List) + + fromList(list: List) + fromLength(length: int, {fill: int = 0}) + fromUtf16(encoded: String) + fromUtf8(encoded: String) + fromBase64(encoded: String) + fromBase16(encoded: String) + + toList() : List + toUtf16() : String + toUtf8() : String + toBase64() : String + toBase16() : String +} + +class CipherChunk extends ByteArray { + CipherChunk(bytes: Uint8List) + + fromList(list: List) + fromUtf16(encoded: String) + fromUtf8(encoded: String) + fromBase64(encoded: String) + fromBase16(encoded: String) +} + +class CipherText extends ByteArray { + chunkSize : int + chunks : List + + CipherText(bytes: Uint8List, {chunkSize: int = 33554432}) + + fromList(list: List) + fromUtf16(encoded: String) + fromUtf8(encoded: String) + fromBase64(encoded: String) + fromBase16(encoded: String) + + toList() : List + toUtf16() : String + toUtf8() : String + toBase64() : String + toBase16() : String + + fromChunks(chunks: List) + toChunks() : List + toBytes() : Uint8List +} + +class AESCipherChunk extends CipherChunk { + iv : Uint8List + message : Uint8List + tag : Uint8List +} + + +@enduml \ No newline at end of file diff --git a/resources/models/cipher_text_dss.puml b/resources/models/cipher_text_dss.puml new file mode 100644 index 0000000..653102d --- /dev/null +++ b/resources/models/cipher_text_dss.puml @@ -0,0 +1,19 @@ +@startuml cipher_text_dss + +actor user +participant CipherText as ct +participant CipherChunk as cc + +user -> ct : new(bytes) +loop for each chunk + ct -> cc : new(bytes) + cc --> ct +end +ct --> user : CipherText + +user -> ct : new(bytes, chunkSize: bytes.length) +ct -> cc : new(bytes) +cc --> ct +ct --> user : CipherText + +@enduml \ No newline at end of file diff --git a/resources/models/digest_classes.puml b/resources/models/digest_classes.puml new file mode 100644 index 0000000..f1bd9fc --- /dev/null +++ b/resources/models/digest_classes.puml @@ -0,0 +1,25 @@ +@startuml digest_classes + +abstract class Hash { + digest(data: Uint8List): Uint8List +} + +abstract class Hmac { + digest(data: Uint8List, key: Uint8List): Uint8List +} + +Hmac o-- Hash + +class Sha256 extends Hash { + static instance: Sha256 +} + +class Sha512 extends Hash { + static instance: Sha512 +} + +class HmacSha256 extends Hmac { + static instance: HmacSha256 +} + +@enduml \ No newline at end of file diff --git a/resources/models/digest_dss.puml b/resources/models/digest_dss.puml new file mode 100644 index 0000000..d4d21ce --- /dev/null +++ b/resources/models/digest_dss.puml @@ -0,0 +1,29 @@ +@startuml digest_dss + +actor user +participant Flutter as flt +participant Sha256 as sha +participant HmacSha256 as hmac +participant NativeCrypto as nc + +user -> flt : getDigest("sha256") +flt -> sha : getInstance() +sha --> flt : Sha256 +flt --> user : Sha256 + +user -> sha : digest(data) +sha --> nc : hash(data, "sha256") +nc --> sha : digest +sha --> user : digest + +user -> flt : getDigest("hmacSha256") +flt -> hmac : getInstance() +hmac --> flt : HmacSha256 +flt --> user : HmacSha256 + +user -> hmac : digest(data) +hmac --> nc : hmac(data, key, "sha256") +nc --> hmac : digest +hmac --> user : digest + +@enduml \ No newline at end of file diff --git a/resources/models/generator_classes.puml b/resources/models/generator_classes.puml new file mode 100644 index 0000000..a5cfad1 --- /dev/null +++ b/resources/models/generator_classes.puml @@ -0,0 +1,9 @@ +@startuml generator_classes + +abstract class Random { + generate(bytes: int): Uint8List +} + +class SecureRandom extends Random {} + +@enduml \ No newline at end of file diff --git a/resources/models/generator_dss.puml b/resources/models/generator_dss.puml new file mode 100644 index 0000000..97a877c --- /dev/null +++ b/resources/models/generator_dss.puml @@ -0,0 +1,15 @@ +@startuml generator_dss + +actor user +participant SecureRandom as rand +participant NativeCrypto as nc + +user -> rand : new() +rand --> user : SecureRandom + +user -> rand : generate(32) +rand -> nc : generateRandomBytes(32) +nc --> rand : Uint8List(32) +rand --> user : Uint8List(32) + +@enduml \ No newline at end of file diff --git a/resources/models/kdf_classes.puml b/resources/models/kdf_classes.puml new file mode 100644 index 0000000..6af06ae --- /dev/null +++ b/resources/models/kdf_classes.puml @@ -0,0 +1,17 @@ +@startuml kdf_classes + +abstract class KeyDerivationFunction { + derive(keyMaterial: Uint8List) : Uint8List + verify(keyMaterial: Uint8List, expected: Uint8List) : bool +} + +class PBKDF2 extends KeyDerivationFunction { + hashAlgorithm: Hash + iterations: int + salt: Uint8List + length: int + + call({password: String}) : SecretKey +} + +@enduml \ No newline at end of file diff --git a/resources/models/kdf_dss.puml b/resources/models/kdf_dss.puml new file mode 100644 index 0000000..3850996 --- /dev/null +++ b/resources/models/kdf_dss.puml @@ -0,0 +1,20 @@ +@startuml kdf_dss + +actor user +participant Pbkdf2 as kdf +participant NativeCrypto as nc + +user -> kdf: new(hash, iterations, salt, length) +kdf--> user : Pbkdf2 + +user -> kdf: derive(password) +kdf--> nc : pbkdf2(password, hash, iterations, salt, length) +nc --> kdf: Uint8List(length) +kdf--> user : SecretKey + +user -> kdf : verify(password, key) +kdf--> nc : pbkdf2(password, hash, iterations, salt, length) +nc --> kdf: Uint8List(length) +kdf--> user : bool + +@enduml \ No newline at end of file diff --git a/resources/models/key_classes.puml b/resources/models/key_classes.puml new file mode 100644 index 0000000..07fbdc7 --- /dev/null +++ b/resources/models/key_classes.puml @@ -0,0 +1,40 @@ +@startuml key_classes + +abstract class ByteArray { + bytes : Uint8List + length : int + + fromList(list: List ) + fromLength(length: int, {fill: int = 0}) + fromUtf16(encoded: String) + fromUtf8(encoded: String) + fromBase64(encoded: String) + fromBase16(encoded: String) + + toList() : List + toUtf16() : String + toUtf8() : String + toBase64() : String + toBase16() : String + +} + +abstract class Key extends ByteArray { + fromList(list: List ) + fromUtf16(encoded: String) + fromUtf8(encoded: String) + fromBase64(encoded: String) + fromBase16(encoded: String) +} + +class SecretKey extends Key { + fromList(list: List) + fromUtf16(encoded: String) + fromUtf8(encoded: String) + fromBase64(encoded: String) + fromBase16(encoded: String) + + async fromSecureRandom(bytes: int) +} + +@enduml \ No newline at end of file diff --git a/resources/models/key_dss.puml b/resources/models/key_dss.puml new file mode 100644 index 0000000..135a850 --- /dev/null +++ b/resources/models/key_dss.puml @@ -0,0 +1,17 @@ +@startuml key_dss + +actor user +participant SecretKey as sk +participant SecureRandom as rand +participant NativeCrypto as nc + +user -> sk : fromSecureRandom(32) +sk -> rand : new() +rand --> sk : SecureRandom +sk -> rand : generate(32) +rand -> nc : generateRandomBytes(32) +nc --> rand : Uint8List(32) +rand --> sk : Uint8List(32) +sk --> user : SecretKey + +@enduml \ No newline at end of file