From 6ba8da275de0798bde5824f6c4b79c592819e5df Mon Sep 17 00:00:00 2001 From: Pointcheval Hugo Date: Thu, 17 Dec 2020 22:11:03 +0100 Subject: [PATCH] Add Key Encapsulation Mechanism (KEM) interface --- lib/src/kem.dart | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 lib/src/kem.dart diff --git a/lib/src/kem.dart b/lib/src/kem.dart new file mode 100644 index 0000000..e91d557 --- /dev/null +++ b/lib/src/kem.dart @@ -0,0 +1,50 @@ +// Copyright (c) 2020 +// Author: Hugo Pointcheval + +import 'dart:typed_data'; + +import 'key.dart'; + +enum KemMode { ENCAPSULATION, DECAPSULATION } + +abstract class KeyEncapsulationMechanism { + /// Returns the standard algorithm name for this kem + String get algorithm; + + /// Returns the parameters used for this kem + Object get options; + + /// Returns true if kem is initialized + bool get isInitialized; + + /// Returns mode used in this kem. + KemMode get mode; + + /// Returns key pair used in this kem. + /// + /// Can be an incomplete if just have public key + /// for example. + KeyPair get keypair; + + /// Encapsulate key. + /// + /// Returns an [Encapsulation]. + Future encapsulate(); + + /// Decapsulate key. + /// + /// Takes [Encapsulation] as parameter. + /// And returns plain text key as [SecretKey]. + Future decapsulate(Encapsulation encapsulation); +} + +abstract class Encapsulation { + /// Returns the standard algorithm name used for this encapsulation + String get algorithm; + + /// Returns the secret key used in this encapsulation + SecretKey get secretKey; + + /// Returns the encapsulated key + Uint8List get key; +}