diff options
| author | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-03-22 16:41:34 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-03-22 16:52:21 +0100 |
| commit | e83abe9fdbab07e6df80443240d4d649303a3dd4 (patch) | |
| tree | 76febb030151dff29ef62a4b27145ed73bd57b42 /src/add_python/lilliput/__init__.py | |
| parent | ba01ba773731cb2c906beb6855dfea588dc8cf09 (diff) | |
| download | lilliput-ae-implem-e83abe9fdbab07e6df80443240d4d649303a3dd4.tar.xz | |
[implem-python] Déplacement dans le dossier SOUMISSION_NIST
Et ajout d'un métascript pour vérifier la conformité.
Il ne reste plus qu'à… (bis)
Diffstat (limited to 'src/add_python/lilliput/__init__.py')
| -rw-r--r-- | src/add_python/lilliput/__init__.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/add_python/lilliput/__init__.py b/src/add_python/lilliput/__init__.py new file mode 100644 index 0000000..5fbc0de --- /dev/null +++ b/src/add_python/lilliput/__init__.py @@ -0,0 +1,31 @@ +from . import lilliput_ae_1 +from . import lilliput_ae_2 +from .constants import NONCE_BYTES + + +_AE_MODES = { + 1: lilliput_ae_1, + 2: lilliput_ae_2 +} + + +def _check_inputs(key, mode, nonce): + valid_key_lengths = (128, 192, 256) + if len(key)*8 not in valid_key_lengths: + raise ValueError('invalid key size: {} not in {}'.format(len(key)*8, valid_key_lengths)) + + if mode not in _AE_MODES: + raise ValueError('invalid mode: {} not in {}'.format(mode, tuple(_AE_MODES))) + + if len(nonce) != NONCE_BYTES: + raise ValueError('invalid nonce size: expecting {}, have {}'.format(NONCE_BYTES, len(nonce))) + + +def encrypt(plaintext, adata, key, nonce, mode): + _check_inputs(key, mode, nonce) + return _AE_MODES[mode].encrypt(adata, plaintext, nonce, key) + + +def decrypt(ciphertext, tag, adata, key, nonce, mode): + _check_inputs(key, mode, nonce) + return _AE_MODES[mode].decrypt(adata, ciphertext, nonce, tag, key) |
