MOTION  0.01
Framework for mixed-protocol multi-party computation
aesni_primitives.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2018-2020 Lennart Braun
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #pragma once
24 
25 #include <cstddef>
26 #include <cstdint>
27 
28 constexpr std::size_t kAesKeySize128 = 16;
29 constexpr std::size_t kAesBlockSize = 16;
30 constexpr std::size_t kAesRoundKeysSize128 = 176;
31 constexpr std::size_t kAesNumRoundKeys128 = 11;
32 
33 // expand the round_keys with the assumptions:
34 // * first round key == aes key is already placed at the start of the buffer
35 // * round_keys is 16B aligned
36 void AesniKeyExpansion128(void* round_keys);
37 
38 // generate number_of_blocks of random bytes using AES in counter mode
39 // * round_keys and output are 16B aligned
40 void AesniCtrStreamBlocks128(const void* round_keys, std::uint64_t* counter, void* output,
41  std::size_t number_of_blocks);
42 
43 // generate number_of_blocks of random bytes using AES in counter mode
44 // * round_keys are 16B aligned
45 void AesniCtrStreamBlocks128Unaligned(const void* round_keys, std::uint64_t* counter, void* output,
46  std::size_t number_of_blocks);
47 
48 // generate a single block of random bytes using AES in counter mode
49 // * round_keys are 16B aligned
50 void AesniCtrStreamSingleBlock128Unaligned(const void* round_keys, std::uint64_t* counter,
51  void* output);
52 
53 // Compute the fixed-key contruction TMMO^\pi from Guo et al.
54 // (https://eprint.iacr.org/2019/074) on four input blocks inplace.
55 //
56 // TMMO^\pi(x, i) = \pi(\pi(x) ^ i) ^ \pi(x)
57 //
58 // * round_keys and output are 16B aligned
59 void AesniTmmoBatch4(const void* round_keys, void* input, __uint128_t tweak);
60 
61 // Compute the fixed-key contruction MMO^\pi from Guo et al.
62 // (https://eprint.iacr.org/2019/074).
63 //
64 // MMO^\pi(x) = \pi(x) ^ x
65 //
66 // * round_keys are 16B aligned
67 void AesniMmoSingle(const void* round_keys, void* input);
68 
69 // Compute the dual-key cipher A2/D1 by Bellare et al.
70 // (https://eprint.iacr.org/2013/426).
71 //
72 // Computes `number_of_parties` invocation of the DKC:
73 // E^\pi(A, B, T, _) = \pi(K) ^ K
74 // where
75 // - \pi is AES with the expanded key from `round_keys`
76 // - K = 4A + 2B + T and with multiplication in GF(2^128)
77 // - T = gate_id || party_id
78 // - `party_id` ranges from 0 to number_of_parties - 1
79 // The output is xored into `output`.
80 void AesniBmrDkc(const void* round_keys, const void* key_a, const void* key_b,
81  std::uint64_t gate_id, std::size_t number_of_parties, void* output);
encrypto::motion::AccumulatedCommunicationStatistics::Add
void Add(const communication::TransportStatistics &statistics)
Definition: analysis.cpp:125
kAesRoundKeysSize128
constexpr std::size_t kAesRoundKeysSize128
Definition: aesni_primitives.h:30
analysis.h
party.h
encrypto::motion::AccumulatedRunTimeStatistics
Definition: analysis.h:43
AesniKeyExpansion128
void AesniKeyExpansion128(void *round_keys_input)
Definition: aesni_primitives.cpp:55
AesniCtrStreamBlocks128Unaligned
void AesniCtrStreamBlocks128Unaligned(const void *round_keys, std::uint64_t *counter, void *output, std::size_t number_of_blocks)
Definition: aesni_primitives.cpp:151
CreateParty
encrypto::motion::PartyPointer CreateParty(const program_options::variables_map &user_options)
Definition: aes128_main.cpp:182
aes128.h
encrypto::motion::MpcProtocol::kBmr
@ kBmr
AesniBmrDkc
void AesniBmrDkc(const void *round_keys_input, const void *key_a, const void *key_b, std::uint64_t gate_id, std::size_t number_of_parties, void *output_input_pointer)
Definition: aesni_primitives.cpp:339
encrypto::motion::PartyPointer
std::unique_ptr< Party > PartyPointer
Definition: party.h:387
AesKeyExpand
static __m128i AesKeyExpand(__m128i xmm1)
Definition: aesni_primitives.cpp:29
kAesBlockSize
constexpr std::size_t kAesBlockSize
Definition: aesni_primitives.h:29
AesniTmmoBatch4
void AesniTmmoBatch4(const void *round_keys, void *input, __uint128_t tweak)
Definition: aesni_primitives.cpp:235
AesniKeyExpansion128
void AesniKeyExpansion128(void *round_keys)
Definition: aesni_primitives.cpp:55
AesniMmoSingle
void AesniMmoSingle(const void *round_keys_input, void *input)
Definition: aesni_primitives.cpp:280
CheckPartyArgumentSyntax
bool CheckPartyArgumentSyntax(const std::string &party_argument)
Definition: aes128_main.cpp:96
encrypto::motion::MpcProtocol::kBooleanGmw
@ kBooleanGmw
encrypto::motion::communication::TcpSetupHelper
Definition: tcp_transport.h:69
communication_layer.h
aesni_primitives.h
ParseProgramOptions
std::pair< program_options::variables_map, bool > ParseProgramOptions(int ac, char *av[])
Definition: aes128_main.cpp:112
kAesNumRoundKeys128
constexpr std::size_t kAesNumRoundKeys128
Definition: aesni_primitives.h:31
kAesKeySize128
constexpr std::size_t kAesKeySize128
Definition: aesni_primitives.h:28
AesniXorEncrypt
static __m128i AesniXorEncrypt(const __m128i *round_keys, __m128i in)
Definition: aesni_primitives.cpp:323
encrypto::motion::communication::TcpPartiesConfiguration
std::vector< TcpConnectionConfiguration > TcpPartiesConfiguration
Definition: tcp_transport.h:62
AesniMmoSingle
void AesniMmoSingle(const void *round_keys, void *input)
Definition: aesni_primitives.cpp:280
geninput.help
help
Definition: geninput.py:150
AesniMixKeys
static __m128i AesniMixKeys(__m128i key_a, __m128i key_b)
Definition: aesni_primitives.cpp:305
main
int main(int ac, char *av[])
Definition: aes128_main.cpp:49
AesniCtrStreamBlocks128
void AesniCtrStreamBlocks128(const void *round_keys, std::uint64_t *counter, void *output, std::size_t number_of_blocks)
Definition: aesni_primitives.cpp:92
AesniCtrStreamSingleBlock128Unaligned
void AesniCtrStreamSingleBlock128Unaligned(const void *round_keys_input, std::uint64_t *counter, void *output)
Definition: aesni_primitives.cpp:214
encrypto::motion::PrintStatistics
std::string PrintStatistics(const std::string &experiment_name, const AccumulatedRunTimeStatistics &execution_statistics, const AccumulatedCommunicationStatistics &communication_statistics)
Definition: analysis.cpp:176
EvaluateProtocol
encrypto::motion::RunTimeStatistics EvaluateProtocol(encrypto::motion::PartyPointer &party, std::size_t number_of_simd, encrypto::motion::MpcProtocol protocol, bool check)
Definition: aes128.cpp:56
AesniCtrStreamSingleBlock128Unaligned
void AesniCtrStreamSingleBlock128Unaligned(const void *round_keys, std::uint64_t *counter, void *output)
Definition: aesni_primitives.cpp:214
encrypto::motion::MpcProtocol
MpcProtocol
Definition: typedefs.h:140
AesniBmrDkc
void AesniBmrDkc(const void *round_keys, const void *key_a, const void *key_b, std::uint64_t gate_id, std::size_t number_of_parties, void *output)
Definition: aesni_primitives.cpp:339
AesniCtrStreamBlocks128Unaligned
void AesniCtrStreamBlocks128Unaligned(const void *round_keys_input, std::uint64_t *counter_input_pointer, void *output_input_pointer, std::size_t number_of_blocks)
Definition: aesni_primitives.cpp:151
kPartyArgumentRegex
const std::regex kPartyArgumentRegex("(\\d+),(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}),(\\d{1,5})")
AesniTmmoBatch4
void AesniTmmoBatch4(const void *round_keys_input, void *input, __uint128_t tweak)
Definition: aesni_primitives.cpp:235
tcp_transport.h
ParsePartyArgument
std::tuple< std::size_t, std::string, std::uint16_t > ParsePartyArgument(const std::string &party_argument)
Definition: aes128_main.cpp:101
encrypto::motion::AccumulatedCommunicationStatistics
Definition: analysis.h:65
AesniCtrStreamBlocks128
void AesniCtrStreamBlocks128(const void *round_keys_input, std::uint64_t *counter_input_pointer, void *output_input_pointer, std::size_t number_of_blocks)
Definition: aesni_primitives.cpp:92
encrypto::motion::communication::TcpSetupHelper::SetupConnections
std::vector< std::unique_ptr< Transport > > SetupConnections()
Definition: tcp_transport.cpp:203