ABY Framework  1.0
Arithmetic Bool Yao Framework
 All Classes Files Functions Variables Enumerations Enumerator Macros
aescircuit.h
Go to the documentation of this file.
1 
19 #ifndef __AESCIRCUIT_H_
20 #define __AESCIRCUIT_H_
21 
22 #include "../../../abycore/circuit/circuit.h"
23 #include "../../../abycore/aby/abyparty.h"
24 #include "../../../abycore/util/crypto/crypto.h"
25 #include <cassert>
26 
27 #define AES_ROUNDS 10
28 #define AES_STATE_SIZE 16
29 #define AES_STATE_SIZE_BITS 128
30 
31 //Size of the expanded key
32 #define AES_EXP_KEY_BITS 1408
33 #define AES_EXP_KEY_BYTES AES_EXP_KEY_BITS/8
34 
35 #define AES_STATE_COLS 4
36 #define AES_STATE_ROWS AES_STATE_SIZE/AES_STATE_COLS
37 #define INV_GATE_ID 666
38 
39 const uint8_t AES_TEST_KEY[AES_KEY_BYTES] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
40 
41 const uint8_t AES_TEST_INPUT[AES_BYTES] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
42 
43 const uint8_t AES_TEST_EXPANDED_KEY[AES_EXP_KEY_BITS] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x63, 0x63, 0x63,
44  0x62, 0x63, 0x63, 0x63, 0x62, 0x63, 0x63, 0x63, 0x62, 0x63, 0x63, 0x63, 0x9b, 0x98, 0x98, 0xc9, 0xf9, 0xfb, 0xfb, 0xaa, 0x9b, 0x98, 0x98, 0xc9, 0xf9, 0xfb, 0xfb, 0xaa,
45  0x90, 0x97, 0x34, 0x50, 0x69, 0x6c, 0xcf, 0xfa, 0xf2, 0xf4, 0x57, 0x33, 0x0b, 0x0f, 0xac, 0x99, 0xee, 0x06, 0xda, 0x7b, 0x87, 0x6a, 0x15, 0x81, 0x75, 0x9e, 0x42, 0xb2,
46  0x7e, 0x91, 0xee, 0x2b, 0x7f, 0x2e, 0x2b, 0x88, 0xf8, 0x44, 0x3e, 0x09, 0x8d, 0xda, 0x7c, 0xbb, 0xf3, 0x4b, 0x92, 0x90, 0xec, 0x61, 0x4b, 0x85, 0x14, 0x25, 0x75, 0x8c,
47  0x99, 0xff, 0x09, 0x37, 0x6a, 0xb4, 0x9b, 0xa7, 0x21, 0x75, 0x17, 0x87, 0x35, 0x50, 0x62, 0x0b, 0xac, 0xaf, 0x6b, 0x3c, 0xc6, 0x1b, 0xf0, 0x9b, 0x0e, 0xf9, 0x03, 0x33,
48  0x3b, 0xa9, 0x61, 0x38, 0x97, 0x06, 0x0a, 0x04, 0x51, 0x1d, 0xfa, 0x9f, 0xb1, 0xd4, 0xd8, 0xe2, 0x8a, 0x7d, 0xb9, 0xda, 0x1d, 0x7b, 0xb3, 0xde, 0x4c, 0x66, 0x49, 0x41,
49  0xb4, 0xef, 0x5b, 0xcb, 0x3e, 0x92, 0xe2, 0x11, 0x23, 0xe9, 0x51, 0xcf, 0x6f, 0x8f, 0x18, 0x8e };
50 
51 //is the gate an AND or an XOR gate
52 const BOOL isANDGate[140] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0,
53  0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
54  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
55 
56 //gate mapping of the AES Sbox
57 const uint32_t wire_mapping[140][2] = { { 7, 4 }, { 7, 2 }, { 7, 1 }, { 4, 2 }, { 3, 1 }, { 8, 8 + 4 }, { 6, 5 }, { 0, 8 + 5 }, { 0, 8 + 6 }, { 8 + 5, 8 + 6 }, { 6, 2 }, { 5, 2 },
58  { 8 + 2, 8 + 3 }, { 8 + 5, 8 + 10 }, { 8 + 4, 8 + 10 }, { 8 + 4, 8 + 11 }, { 8 + 8, 8 + 15 }, { 4, 0 }, { 8 + 6, 8 + 17 }, { 8, 8 + 18 }, { 1, 0 }, { 8 + 6, 8 + 20 }, { 8
59  + 1, 8 + 21 }, { 8 + 1, 8 + 9 }, { 8 + 19, 8 + 16 }, { 8 + 2, 8 + 15 }, { 8, 8 + 11 }, { 8 + 12, 8 + 5 }, { 8 + 22, 8 + 7 }, { 8 + 13, 35 }, { 8 + 18, 0 }, { 35
60  + 3, 35 }, { 8 + 2, 8 + 15 }, { 8 + 21, 8 + 8 }, { 8 + 25, 35 + 5 }, { 8 + 19, 8 + 16 }, { 35 + 8, 35 + 5 }, { 8, 8 + 14 }, { 8 + 3, 8 + 26 }, { 35 + 11, 35 + 10 },
61  { 8 + 1, 8 + 9 }, { 35 + 13, 35 + 10 }, { 35 + 2, 35 + 1 }, { 35 + 4, 8 + 23 }, { 35 + 7, 35 + 6 }, { 35 + 9, 35 + 14 }, { 35 + 15, 35 + 12 }, { 35 + 16, 35 + 14 }, { 35
62  + 17, 35 + 12 }, { 35 + 18, 8 + 24 }, { 35 + 21, 35 + 22 }, { 35 + 21, 35 + 19 }, { 35 + 20, 35 + 24 }, { 35 + 19, 35 + 20 }, { 35 + 22, 35 + 24 }, { 35 + 27, 35
63  + 26 }, { 35 + 25, 35 + 23 }, { 35 + 19, 35 + 22 }, { 35 + 26, 35 + 30 }, { 35 + 26, 35 + 24 }, { 35 + 20, 35 + 21 }, { 35 + 23, 35 + 33 }, { 35 + 23, 35 + 24 }, {
64  35 + 20, 35 + 28 }, { 35 + 31, 35 + 32 }, { 35 + 22, 35 + 29 }, { 35 + 34, 35 + 35 }, { 35 + 37, 35 + 39 }, { 35 + 36, 35 + 38 }, { 35 + 36, 35 + 37 }, { 35 + 38,
65  35 + 39 }, { 35 + 41, 35 + 40 }, { 35 + 43, 8 + 5 }, { 35 + 39, 8 + 7 }, { 35 + 38, 0 }, { 35 + 42, 8 + 15 }, { 35 + 37, 8 + 8 }, { 35 + 36, 8 + 16 }, { 35 + 41, 8
66  + 14 }, { 35 + 44, 8 + 26 }, { 35 + 40, 8 + 9 }, { 35 + 43, 8 + 12 }, { 35 + 39, 8 + 22 }, { 35 + 38, 8 + 18 }, { 35 + 42, 8 + 2 }, { 35 + 37, 8 + 21 }, { 35 + 36,
67  8 + 19 }, { 35 + 41, 8 }, { 35 + 44, 8 + 3 }, { 35 + 40, 8 + 1 }, { 35 + 60, 35 + 61 }, { 35 + 49, 35 + 55 }, { 35 + 45, 35 + 47 }, { 35 + 46, 35 + 54 }, { 35 + 53,
68  35 + 57 }, { 35 + 48, 35 + 60 }, { 35 + 61, 98 + 5 }, { 35 + 45, 98 + 3 }, { 35 + 50, 35 + 58 }, { 35 + 51, 35 + 52 }, { 35 + 52, 98 + 4 }, { 35 + 59, 98 + 2 }, {
69  35 + 47, 35 + 50 }, { 35 + 49, 98 }, { 35 + 51, 35 + 60 }, { 35 + 54, 98 + 1 }, { 35 + 55, 98 }, { 35 + 56, 98 + 1 }, { 35 + 57, 98 + 8 }, { 35 + 62, 98 + 4 }, {
70  98, 98 + 1 }, { 98 + 1, 98 + 7 }, { 98 + 3, 98 + 12 }, { 98 + 18, 98 + 2 }, { 98 + 15, 98 + 9 }, { 98 + 6, 98 + 10 }, { 98 + 7, 98 + 9 }, { 98 + 8, 98 + 10 }, { 98
71  + 11, 98 + 14 }, { 98 + 11, 98 + 17 }, { 98 + 16, INV_GATE_ID }, { 98 + 19, INV_GATE_ID }, { 98 + 13, INV_GATE_ID }, { 98 + 6, INV_GATE_ID }, { 98 + 33, 98 + 23 },
72  { 98 + 32, 98 + 27 }, { 98 + 25, 98 + 29 }, { 98 + 20, 98 + 22 }, { 98 + 6, 98 + 21 }, { 98 + 31, 98 + 28 }, { 98 + 30, 98 + 26 }, { 98 + 6, 98 + 24 } };
73 
74 void verify_AES_encryption(uint8_t* input, uint8_t* key, uint32_t nvals, uint8_t* out, crypto* crypt);
75 int32_t test_aes_circuit(e_role role, char* address, seclvl seclvl, uint32_t nvals, uint32_t nthreads, e_mt_gen_alg mt_alg, e_sharing sharing);
76 share* BuildAESCircuit(share* val, share* key, BooleanCircuit* circ);
77 vector<uint32_t> AddAESRoundKey(vector<uint32_t>& val, vector<uint32_t>& key, uint32_t keyaddr, BooleanCircuit* circ);
78 vector<uint32_t> Mul2(vector<uint32_t>& element, BooleanCircuit* circ);
79 vector<vector<uint32_t> > PutAESMixColumnGate(vector<vector<uint32_t> >& rows, BooleanCircuit* circ);
80 vector<uint32_t> AESSBox_Forward_BP(vector<uint32_t>& input, BooleanCircuit* circ);
81 
82 #endif /* __AESCIRCUIT_H_ */
Definition: booleancircuits.h:27
Definition: crypto.h:58
e_mt_gen_alg
Enumeration which defines the method that is used for arithmetic multiplication triple generation...
Definition: constants.h:55
Definition: circuit.h:258
e_role
Defines the role of the party or the source / target for certain operations (e.g., input/output)
Definition: constants.h:139
Definition: typedefs.h:79
e_sharing
Enumeration which defines the different sharing which are there in the framework. ...
Definition: constants.h:124