From 9211a922fed9ce46f9407ccf0916d4ec5fd2d13f Mon Sep 17 00:00:00 2001 From: Donovan Date: Thu, 4 Jul 2024 14:33:40 -0500 Subject: [PATCH] remove medium identity matrix --- darc_tutorial.ipynb | 130 +++++++++++++++++++++----------------------- src/server_darc.py | 6 +- test/test_darc.py | 6 +- 3 files changed, 67 insertions(+), 75 deletions(-) diff --git a/darc_tutorial.ipynb b/darc_tutorial.ipynb index 8c7f6a3..e59a6c4 100644 --- a/darc_tutorial.ipynb +++ b/darc_tutorial.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 36, + "execution_count": 121, "outputs": [], "source": [ "from src.models import SubstitutionKey, OuterKey, Mask, ServerKeys, MutualKeys, ClientKeys\n", @@ -11,14 +11,14 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:05:07.552043Z", - "start_time": "2024-07-04T18:05:07.542908Z" + "end_time": "2024-07-04T19:31:39.644601Z", + "start_time": "2024-07-04T19:31:39.628805Z" } } }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 122, "outputs": [], "source": [ "def create_random_message(message_len, height):\n", @@ -28,14 +28,14 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:05:07.552147Z", - "start_time": "2024-07-04T18:05:07.546164Z" + "end_time": "2024-07-04T19:31:39.644729Z", + "start_time": "2024-07-04T19:31:39.630714Z" } } }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 123, "outputs": [], "source": [ "height = 70\n", @@ -46,14 +46,14 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:05:07.552308Z", - "start_time": "2024-07-04T18:05:07.549140Z" + "end_time": "2024-07-04T19:31:39.645110Z", + "start_time": "2024-07-04T19:31:39.634024Z" } } }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 124, "outputs": [], "source": [ "server_substitution_data = SubstitutionKey.init_matrix(width, height)\n", @@ -77,20 +77,19 @@ "client_keys.persistent.data.alpha_key = client_substitution_data\n", "client_keys.persistent.medium.alpha_key = client_substitution_medium\n", "\n", - "alphabet = SubstitutionKey.init_matrix(width, height, 255)\n", - "medium = SubstitutionKey(matrix=[[0 for _ in range(width)] for _ in range(height)])" + "alphabet = SubstitutionKey.init_matrix(width, height, 255)" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:05:07.580066Z", - "start_time": "2024-07-04T18:05:07.553448Z" + "end_time": "2024-07-04T19:31:39.666246Z", + "start_time": "2024-07-04T19:31:39.638300Z" } } }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 125, "outputs": [], "source": [ "sdi1 = server_keys.persistent.data.inner_key_1 << server_keys.ephemeral.data.inner_key_1\n", @@ -134,14 +133,14 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:05:07.593317Z", - "start_time": "2024-07-04T18:05:07.587709Z" + "end_time": "2024-07-04T19:31:39.676976Z", + "start_time": "2024-07-04T19:31:39.672058Z" } } }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 126, "outputs": [], "source": [ "cdo1_cdo2 = cdo1 << cdo2\n", @@ -152,14 +151,14 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:05:07.593468Z", - "start_time": "2024-07-04T18:05:07.590552Z" + "end_time": "2024-07-04T19:31:39.677097Z", + "start_time": "2024-07-04T19:31:39.674721Z" } } }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 127, "outputs": [], "source": [ "m_func_1 = lambda x: (x < mdo1) << (mdi1 < mdo2)\n", @@ -171,35 +170,35 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:05:07.595183Z", - "start_time": "2024-07-04T18:05:07.593423Z" + "end_time": "2024-07-04T19:31:39.679186Z", + "start_time": "2024-07-04T19:31:39.677255Z" } } }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 128, "outputs": [], "source": [ - "medium_phase1 = medium ^ m_func_2(spma ^ sema)" + "medium_phase1 = m_func_2(spma ^ sema)" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:05:07.598748Z", - "start_time": "2024-07-04T18:05:07.596986Z" + "end_time": "2024-07-04T19:31:39.682789Z", + "start_time": "2024-07-04T19:31:39.681048Z" } } }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 129, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 52, + "execution_count": 129, "metadata": {}, "output_type": "execute_result" } @@ -214,7 +213,6 @@ "medium_phase2 == (\n", " (\n", " (\n", - " medium ^\n", " m_func_2(server_substitution_medium ^ sema ^ cema)\n", " ) << (cmi1 < mmo3)\n", " ) < cmo1_cmo2\n", @@ -223,20 +221,20 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:05:42.393236Z", - "start_time": "2024-07-04T18:05:42.389787Z" + "end_time": "2024-07-04T19:31:39.697827Z", + "start_time": "2024-07-04T19:31:39.687941Z" } } }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 130, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 59, + "execution_count": 130, "metadata": {}, "output_type": "execute_result" } @@ -248,7 +246,6 @@ " ) << (mpmi2 < mmo3) < cmo1_cmo2\n", "\n", "medium_phase3 == ((\n", - " medium ^\n", " m_func_2(server_substitution_medium ^ sema ^ cpma ^ mema)\n", " ) << (mpmi2 < mmo3) < cmo1_cmo2\n", ")" @@ -256,14 +253,14 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:16:20.923343Z", - "start_time": "2024-07-04T18:16:20.920280Z" + "end_time": "2024-07-04T19:31:39.712580Z", + "start_time": "2024-07-04T19:31:39.696392Z" } } }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 131, "outputs": [], "source": [ "translated_alphabet = (\n", @@ -279,20 +276,20 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:05:07.665047Z", - "start_time": "2024-07-04T18:05:07.639926Z" + "end_time": "2024-07-04T19:31:39.712704Z", + "start_time": "2024-07-04T19:31:39.704054Z" } } }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 132, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 62, + "execution_count": 132, "metadata": {}, "output_type": "execute_result" } @@ -313,20 +310,20 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:29:06.076785Z", - "start_time": "2024-07-04T18:29:06.071174Z" + "end_time": "2024-07-04T19:31:39.727975Z", + "start_time": "2024-07-04T19:31:39.712372Z" } } }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 133, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 72, + "execution_count": 133, "metadata": {}, "output_type": "execute_result" } @@ -347,14 +344,14 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:40:21.743276Z", - "start_time": "2024-07-04T18:40:21.739864Z" + "end_time": "2024-07-04T19:31:39.742787Z", + "start_time": "2024-07-04T19:31:39.721754Z" } } }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 134, "outputs": [], "source": [ "eof_msg_mask = Mask.init_matrix(width, height, message_len)\n", @@ -365,20 +362,20 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:05:07.678354Z", - "start_time": "2024-07-04T18:05:07.643198Z" + "end_time": "2024-07-04T19:31:39.742960Z", + "start_time": "2024-07-04T19:31:39.726783Z" } } }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 135, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 75, + "execution_count": 135, "metadata": {}, "output_type": "execute_result" } @@ -392,7 +389,6 @@ "darc_message == (\n", " ((\n", " ((\n", - " medium ^\n", " m_func_2(server_substitution_medium ^ sema ^ cpma ^ mema)\n", " ) << (mpmi2 < mmo3)) ^\n", " (((((\n", @@ -405,20 +401,20 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:46:10.473478Z", - "start_time": "2024-07-04T18:46:10.457255Z" + "end_time": "2024-07-04T19:31:39.743236Z", + "start_time": "2024-07-04T19:31:39.739866Z" } } }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 136, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 102, + "execution_count": 136, "metadata": {}, "output_type": "execute_result" } @@ -434,14 +430,14 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T19:21:34.911369Z", - "start_time": "2024-07-04T19:21:34.908479Z" + "end_time": "2024-07-04T19:31:39.761839Z", + "start_time": "2024-07-04T19:31:39.748041Z" } } }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 137, "outputs": [], "source": [ "orignal_message = resolve_message(translated_alphabet, unwrapped_medium)" @@ -449,20 +445,20 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:05:07.678472Z", - "start_time": "2024-07-04T18:05:07.656814Z" + "end_time": "2024-07-04T19:31:39.761929Z", + "start_time": "2024-07-04T19:31:39.751011Z" } } }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 138, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 50, + "execution_count": 138, "metadata": {}, "output_type": "execute_result" } @@ -473,8 +469,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-04T18:05:07.678731Z", - "start_time": "2024-07-04T18:05:07.659154Z" + "end_time": "2024-07-04T19:31:39.761994Z", + "start_time": "2024-07-04T19:31:39.753450Z" } } } diff --git a/src/server_darc.py b/src/server_darc.py index ef5ffbe..f7e4ac6 100644 --- a/src/server_darc.py +++ b/src/server_darc.py @@ -5,7 +5,7 @@ from src.models import ( ) -def darc_phase1(alphabet: SubstitutionKey, medium: SubstitutionKey, server_keys: ServerKeys, mutual_keys: MutualKeys): +def darc_phase1(alphabet: SubstitutionKey, server_keys: ServerKeys, mutual_keys: MutualKeys): alphabet_phase1 = translate_data( alphabet, server_keys.persistent.data, @@ -14,7 +14,6 @@ def darc_phase1(alphabet: SubstitutionKey, medium: SubstitutionKey, server_keys: mutual_keys.ephemeral.data ) medium_phase1 = translate_medium( - medium, server_keys.persistent.medium, server_keys.ephemeral.medium, mutual_keys.persistent.medium, @@ -49,7 +48,6 @@ def translate_data( def translate_medium( - medium: SubstitutionKey, server_persistent_medium_keys: ServerPersistentMediumKeys, server_ephemeral_medium_keys: ServerEphemeralMediumKeys, mutual_persistent_medium_keys: MutualPersistentMediumKeys, @@ -61,7 +59,7 @@ def translate_medium( spma = server_persistent_medium_keys.alpha_key sema = server_ephemeral_medium_keys.alpha_key - medium_phase1 = medium ^ (((spma ^ sema) < mmo1) << (mmi1 < mmo2)) + medium_phase1 = ((spma ^ sema) < mmo1) << (mmi1 < mmo2) return medium_phase1 diff --git a/test/test_darc.py b/test/test_darc.py index 420e0f2..57357a8 100644 --- a/test/test_darc.py +++ b/test/test_darc.py @@ -12,13 +12,12 @@ import pytest ) def test_darc(height, width, message_len): alphabet = SubstitutionKey.init_matrix(width, height, 255) - medium = SubstitutionKey.init_identity_matrix(width, height) server_keys, mutual_keys, client_keys = generate_keys(height, width) original_message = OuterKey.init_matrix(height).matrix[0] original_message = original_message[:message_len] - (alphabet_phase1, medium_phase1) = darc_phase1(alphabet, medium, server_keys, mutual_keys) + (alphabet_phase1, medium_phase1) = darc_phase1(alphabet, server_keys, mutual_keys) (alphabet_phase2, medium_phase2) = darc_phase2(alphabet_phase1, medium_phase1, client_keys, mutual_keys) (phase3_alphabet, phase3_medium) = darc_phase3(alphabet_phase2, medium_phase2, client_keys, mutual_keys) @@ -36,13 +35,12 @@ def test_darc(height, width, message_len): ) def test_darc_no_client(height, width, message_len): alphabet = SubstitutionKey.init_matrix(width, height, 255) - medium = SubstitutionKey(matrix=[[0 for _ in range(width)] for _ in range(height)]) server_keys, mutual_keys, client_keys = generate_keys(height, width) original_message = OuterKey.init_matrix(height).matrix[0] original_message = original_message[:message_len] - (alphabet_phase1, medium_phase1) = darc_phase1(alphabet, medium, server_keys, mutual_keys) + (alphabet_phase1, medium_phase1) = darc_phase1(alphabet, server_keys, mutual_keys) (phase3_alphabet, phase3_medium) = darc_phase_2_3(alphabet_phase1, medium_phase1, mutual_keys) darc_message = merge_message_no_client(phase3_alphabet, phase3_medium, mutual_keys, original_message)