[72] | 1 | /* |
---|
| 2 | * $Id: Encryption.cpp 81 2008-04-15 18:40:01Z rosiere $ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "Behavioural/Custom/include/Encryption.h" |
---|
| 9 | |
---|
| 10 | namespace morpheo { |
---|
| 11 | namespace behavioural { |
---|
| 12 | namespace custom { |
---|
| 13 | namespace encryption { |
---|
| 14 | |
---|
| 15 | static uint32_t _num_group; |
---|
| 16 | |
---|
| 17 | Encryption::Encryption (uint32_t num_group, |
---|
| 18 | Toperation_t operation_encrypt, |
---|
| 19 | Toperation_t operation_decrypt) : |
---|
| 20 | _operation_encrypt (operation_encrypt), |
---|
| 21 | _operation_decrypt (operation_decrypt) |
---|
| 22 | { |
---|
| 23 | _num_group = num_group; |
---|
| 24 | }; |
---|
| 25 | |
---|
| 26 | uint32_t Encryption::get_nb_register (void) |
---|
| 27 | { |
---|
| 28 | return 3; |
---|
| 29 | }; |
---|
| 30 | |
---|
| 31 | access_mode_t Encryption::get_access_mode (uint32_t reg) |
---|
| 32 | { |
---|
| 33 | // All reg is access by supervisor |
---|
| 34 | return access_mode_t (SPR_ACCESS_MODE_NONE, SPR_ACCESS_MODE_READ_WRITE); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | custom_decod_t * Encryption::get_custom_decod (Toperation_t operation) |
---|
| 38 | { |
---|
| 39 | // TODO !!!!! |
---|
| 40 | return NULL; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | custom_execute_genMoore_t * Encryption::get_custom_execute_genMoore (Toperation_t operation) |
---|
| 44 | { |
---|
| 45 | if (operation == _operation_encrypt) |
---|
| 46 | return &(morpheo::behavioural::custom::encryption::Encryption::function_encrypt); |
---|
| 47 | if (operation == _operation_decrypt) |
---|
| 48 | return &(morpheo::behavioural::custom::encryption::Encryption::function_decrypt); |
---|
| 49 | |
---|
| 50 | return &(morpheo::behavioural::core::multi_execute_loop::execute_loop::multi_execute_unit::execute_unit::functionnal_unit::operation_unimplemented); // unimplemented function |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | custom_execute_transition_t * Encryption::get_custom_execute_transition (void) |
---|
| 54 | { |
---|
| 55 | // No treatment a the end cycle |
---|
| 56 | return NULL; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | custom_execute_transition_t * Encryption::get_custom_execute_reset (void) |
---|
| 60 | { |
---|
| 61 | // No treatment a the end cycle |
---|
| 62 | return NULL; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | void Encryption::function_encrypt (morpheo::behavioural::core::multi_execute_loop::execute_loop::multi_execute_unit::execute_unit::functionnal_unit::execute_operation_t * op, |
---|
| 66 | morpheo::behavioural::core::multi_execute_loop::execute_loop::multi_execute_unit::execute_unit::functionnal_unit::execute_register_t * reg, |
---|
| 67 | morpheo::behavioural::core::multi_execute_loop::execute_loop::multi_execute_unit::execute_unit::functionnal_unit::execute_param_t * param) |
---|
| 68 | { |
---|
| 69 | std::cout << "<Encryption::function_decrypt> Operation : encrypt" << std::endl; |
---|
| 70 | |
---|
| 71 | Tgeneral_data_t data = unsigned(op->_data_ra); |
---|
| 72 | |
---|
| 73 | Tgeneral_data_t key = reg->_spr[_num_group][num_register_key ]; |
---|
| 74 | Tgeneral_data_t shift = reg->_spr[_num_group][num_register_shift]; |
---|
| 75 | Tgeneral_data_t rool = reg->_spr[_num_group][num_register_role ]; |
---|
| 76 | |
---|
| 77 | for (Tgeneral_data_t i=0 ; i<rool; i++) |
---|
| 78 | { |
---|
| 79 | data ^= key; |
---|
| 80 | data = rotate_right<Tgeneral_data_t>(param->_size_data,data,shift); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | // Result |
---|
| 84 | |
---|
| 85 | op->_timing = morpheo::behavioural::core::multi_execute_loop::execute_loop::multi_execute_unit::execute_unit::functionnal_unit::execute_timing_t(rool, rool); |
---|
| 86 | op->_data_rd = data; |
---|
| 87 | //op->_data_re = 0; |
---|
| 88 | op->_exception = EXCEPTION_ALU_NONE; |
---|
| 89 | op->_no_sequence = 0; |
---|
| 90 | //op->_address = 0; |
---|
| 91 | }; |
---|
| 92 | |
---|
| 93 | void Encryption::function_decrypt (morpheo::behavioural::core::multi_execute_loop::execute_loop::multi_execute_unit::execute_unit::functionnal_unit::execute_operation_t * op, |
---|
| 94 | morpheo::behavioural::core::multi_execute_loop::execute_loop::multi_execute_unit::execute_unit::functionnal_unit::execute_register_t * reg, |
---|
| 95 | morpheo::behavioural::core::multi_execute_loop::execute_loop::multi_execute_unit::execute_unit::functionnal_unit::execute_param_t * param) |
---|
| 96 | { |
---|
| 97 | std::cout << "<Encryption::function_decrypt> Operation : decrypt" << std::endl; |
---|
| 98 | |
---|
| 99 | Tgeneral_data_t data = unsigned(op->_data_ra); |
---|
| 100 | |
---|
| 101 | Tgeneral_data_t key = reg->_spr[_num_group][num_register_key ]; |
---|
| 102 | Tgeneral_data_t shift = reg->_spr[_num_group][num_register_shift]; |
---|
| 103 | Tgeneral_data_t rool = reg->_spr[_num_group][num_register_role ]; |
---|
| 104 | |
---|
| 105 | for (Tgeneral_data_t i=0 ; i<rool; i++) |
---|
| 106 | { |
---|
| 107 | data = rotate_left<Tgeneral_data_t>(param->_size_data,data,shift); |
---|
| 108 | data ^= key; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | // Result |
---|
| 112 | op->_timing = morpheo::behavioural::core::multi_execute_loop::execute_loop::multi_execute_unit::execute_unit::functionnal_unit::execute_timing_t(rool, rool); |
---|
| 113 | op->_data_rd = data; |
---|
| 114 | //op->_data_re = 0; |
---|
| 115 | op->_exception = EXCEPTION_ALU_NONE; |
---|
| 116 | op->_no_sequence = 0; |
---|
| 117 | //op->_address = 0; |
---|
| 118 | }; |
---|
| 119 | |
---|
| 120 | }; // end namespace encryption |
---|
| 121 | }; // end namespace custom |
---|
| 122 | }; // end namespace behavioural |
---|
| 123 | }; // end namespace morpheo |
---|