| Remote Access Control | |||||
Definition at line 57 of file createtxhex.cpp.
Public Member Functions | |
| size_t | GetCounterSize () const |
| const std::vector< byte > & | GetCounterValue () const |
| std::string | GetCounterValueString () const |
| const std::string & | GetFilename () const |
| size_t | GetKeySize () const |
| const std::vector< byte > & | GetSecretKey () const |
| std::string | GetSecretKeyString () const |
| const std::vector< byte > & | GetSerialNo () const |
| size_t | GetSerialNoSize () const |
| std::string | GetSerialNoString () const |
| const std::vector< byte > & | GetSharedKey () const |
| std::string | GetSharedKeyString () const |
| ParameterParser (size_t argc, const char **argv) | |
| ~ParameterParser () | |
Private Member Functions | |
| std::string | CreateHexString (const std::vector< byte > &byteVector) const |
| std::vector< byte > | ParseHexString (const std::string &hexString) const |
Private Attributes | |
| size_t | m_counterSize |
| std::vector< byte > | m_counterValue |
| std::string | m_filename |
| size_t | m_keySize |
| std::vector< byte > | m_secretKey |
| std::vector< byte > | m_serialNo |
| size_t | m_serialNoSize |
| std::vector< byte > | m_sharedKey |
| ParameterParser::ParameterParser | ( | size_t | argc, | |
| const char ** | argv | |||
| ) |
Ctor taking the argc and argv parameters typically given to any main() function.
Definition at line 144 of file createtxhex.cpp.
References m_counterSize, m_counterValue, m_filename, m_keySize, m_secretKey, m_serialNo, m_serialNoSize, m_sharedKey, and ParseHexString().
00145 { 00146 // Check that argument count is valid. 00147 if( argc != 9 ) { 00148 std::cout << "Parameters:\n" 00149 " filename - Filename for resulting Intel HEX file\n" 00150 " keysize - Size in bits of the AES secret and shared keys (128, 192 or 256)\n" 00151 " serialnosize - Size in bytes of the serial number (1, 2 or 4)\n" 00152 " countersize - Size in bytes of the sequential counter (1, 2 or 4)\n" 00153 " sharedkey - Hex representation of the shared key (32, 48 or 64 digits)\n" 00154 " secretkey - Hex representation of the secret key (32, 48 or 64 digits)\n" 00155 " serialno - Hex representation of the serial number (2, 4 or 8 digits)\n" 00156 " countervalue - Hex representation of the current counter value (2, 4 or 8 digits)\n" 00157 << std::endl; 00158 throw std::runtime_error( "Not exactly 8 parameters" ); 00159 } 00160 00161 // 00162 // Create strings or string streams from argument character arrays. 00163 // 00164 std::string arg1( argv[1] ); // Filename 00165 std::istringstream arg2( argv[2] ); // Key size 00166 std::istringstream arg3( argv[3] ); // Serial no size 00167 std::istringstream arg4( argv[4] ); // Counter size 00168 std::string arg5( argv[5] ); // Shared key 00169 std::string arg6( argv[6] ); // Secret key 00170 std::string arg7( argv[7] ); // Serial number 00171 std::string arg8( argv[8] ); // Counter Value 00172 00173 // 00174 // Copy string arguments and parse non-string arguments. 00175 // 00176 m_filename = arg1; 00177 00178 arg2 >> m_keySize; 00179 if( !arg2 ) { 00180 throw std::runtime_error( "Error parsing key size argument" ); 00181 } 00182 00183 arg3 >> m_serialNoSize; 00184 if( !arg3 ) { 00185 throw std::runtime_error( "Error parsing serial no size argument" ); 00186 } 00187 00188 arg4 >> m_counterSize; 00189 if( !arg4 ) { 00190 throw std::runtime_error( "Error parsing counter size argument" ); 00191 } 00192 00193 m_sharedKey = ParseHexString( arg5 ); 00194 m_secretKey = ParseHexString( arg6 ); 00195 m_serialNo = ParseHexString( arg7 ); 00196 m_counterValue = ParseHexString( arg8 ); 00197 00198 // 00199 // Check argument validity. 00200 // 00201 if( m_keySize != 128 && m_keySize != 192 && m_keySize != 256 ) { 00202 throw std::runtime_error( "Key size is not 128, 192 or 256 bits" ); 00203 } 00204 00205 if( m_serialNoSize != 1 && m_serialNoSize != 2 && m_serialNoSize != 4 ) { 00206 throw std::runtime_error( "Serial no is not 1, 2 or 4 bytes" ); 00207 } 00208 00209 if( m_counterSize != 1 && m_counterSize != 2 && m_counterSize != 4 ) { 00210 throw std::runtime_error( "Counter is not 1, 2 or 4 bytes" ); 00211 } 00212 00213 if( m_sharedKey.size() != m_keySize / 8 ) { 00214 throw std::runtime_error( "Shared key has invalid length" ); 00215 } 00216 00217 if( m_secretKey.size() != m_keySize / 8 ) { 00218 throw std::runtime_error( "Secret key has invalid length" ); 00219 } 00220 00221 if( m_serialNo.size() != m_serialNoSize ) { 00222 throw std::runtime_error( "Serial number has invalid length" ); 00223 } 00224 00225 if( m_counterValue.size() != m_counterSize ) { 00226 throw std::runtime_error( "Counter value has invalid length" ); 00227 } 00228 }
Here is the call graph for this function:

| ParameterParser::~ParameterParser | ( | ) | [inline] |
| std::string ParameterParser::CreateHexString | ( | const std::vector< byte > & | byteVector | ) | const [private] |
Creates an HEX string from a vector of data bytes. Space between every two digits, ie. byte.
Definition at line 124 of file createtxhex.cpp.
Referenced by GetCounterValueString(), GetSecretKeyString(), GetSerialNoString(), and GetSharedKeyString().
00125 { 00126 std::ostringstream oss; 00127 oss << std::setfill('0') << std::hex; 00128 00129 // Add all byte last byte with spaces in between. 00130 for( size_t idx = 0; idx < byteVector.size() - 1; ++idx ) { 00131 oss << std::setw(2) << byteVector.at( idx ) << ' '; 00132 } 00133 00134 // Add last byte. 00135 if( byteVector.size() > 0 ) { 00136 oss << std::setw(2) << byteVector.at( byteVector.size()-1 ); 00137 } 00138 00139 return oss.str(); 00140 }
| size_t ParameterParser::GetCounterSize | ( | ) | const [inline] |
Definition at line 85 of file createtxhex.cpp.
References m_counterSize.
Referenced by main().
00085 { return m_counterSize; }
| const std::vector< byte >& ParameterParser::GetCounterValue | ( | ) | const [inline] |
Definition at line 89 of file createtxhex.cpp.
References m_counterValue.
Referenced by CreateHEXFile(), and GetCounterValueString().
00089 { return m_counterValue; }
| std::string ParameterParser::GetCounterValueString | ( | ) | const [inline] |
Definition at line 94 of file createtxhex.cpp.
References CreateHexString(), and GetCounterValue().
Referenced by main().
00094 { return CreateHexString( GetCounterValue() ); }
Here is the call graph for this function:

| const std::string& ParameterParser::GetFilename | ( | ) | const [inline] |
Definition at line 82 of file createtxhex.cpp.
References m_filename.
Referenced by CreateHEXFile(), and main().
00082 { return m_filename; }
| size_t ParameterParser::GetKeySize | ( | ) | const [inline] |
Definition at line 83 of file createtxhex.cpp.
References m_keySize.
Referenced by main().
00083 { return m_keySize; }
| const std::vector< byte >& ParameterParser::GetSecretKey | ( | ) | const [inline] |
Definition at line 87 of file createtxhex.cpp.
References m_secretKey.
Referenced by CreateHEXFile(), and GetSecretKeyString().
00087 { return m_secretKey; }
| std::string ParameterParser::GetSecretKeyString | ( | ) | const [inline] |
Definition at line 92 of file createtxhex.cpp.
References CreateHexString(), and GetSecretKey().
Referenced by main().
00092 { return CreateHexString( GetSecretKey() ); }
Here is the call graph for this function:

| const std::vector< byte >& ParameterParser::GetSerialNo | ( | ) | const [inline] |
Definition at line 88 of file createtxhex.cpp.
References m_serialNo.
Referenced by CreateHEXFile(), and GetSerialNoString().
00088 { return m_serialNo; }
| size_t ParameterParser::GetSerialNoSize | ( | ) | const [inline] |
Definition at line 84 of file createtxhex.cpp.
References m_serialNoSize.
Referenced by main().
00084 { return m_serialNoSize; }
| std::string ParameterParser::GetSerialNoString | ( | ) | const [inline] |
Definition at line 93 of file createtxhex.cpp.
References CreateHexString(), and GetSerialNo().
Referenced by main().
00093 { return CreateHexString( GetSerialNo() ); }
Here is the call graph for this function:

| const std::vector< byte >& ParameterParser::GetSharedKey | ( | ) | const [inline] |
Definition at line 86 of file createtxhex.cpp.
References m_sharedKey.
Referenced by CreateHEXFile(), and GetSharedKeyString().
00086 { return m_sharedKey; }
| std::string ParameterParser::GetSharedKeyString | ( | ) | const [inline] |
Definition at line 91 of file createtxhex.cpp.
References CreateHexString(), and GetSharedKey().
Referenced by main().
00091 { return CreateHexString( GetSharedKey() ); }
Here is the call graph for this function:

| std::vector< byte > ParameterParser::ParseHexString | ( | const std::string & | hexString | ) | const [private] |
Parses an unformatted HEX number string. Must be pairs of HEX digits, ie. bytes.
Definition at line 99 of file createtxhex.cpp.
Referenced by ParameterParser().
00100 { 00101 // String must be even number of hex digits. 00102 if( hexString.size() % 2 != 0 ) { 00103 throw std::runtime_error( "Hex string does not have even character count" ); 00104 } 00105 00106 // 00107 // Parse hex digit pairs and insert into byte vector. 00108 // 00109 std::vector< byte > bytes; 00110 for( size_t idx = 0; idx < hexString.size(); idx += 2 ) { 00111 std::istringstream iss( hexString.substr( idx, 2 ) ); 00112 byte data; 00113 iss >> std::hex >> data; 00114 if( !iss ) { 00115 throw std::runtime_error( "Error parsing hex string \"" + hexString + "\"" ); 00116 } 00117 bytes.push_back( data ); 00118 } 00119 return bytes; 00120 }
size_t ParameterParser::m_counterSize [private] |
Stores synchronization counter size parameter.
Definition at line 63 of file createtxhex.cpp.
Referenced by GetCounterSize(), and ParameterParser().
std::vector< byte > ParameterParser::m_counterValue [private] |
Stores synchronization counter value.
Definition at line 67 of file createtxhex.cpp.
Referenced by GetCounterValue(), and ParameterParser().
std::string ParameterParser::m_filename [private] |
Stores filename parameter.
Definition at line 60 of file createtxhex.cpp.
Referenced by GetFilename(), and ParameterParser().
size_t ParameterParser::m_keySize [private] |
Stores key size parameter.
Definition at line 61 of file createtxhex.cpp.
Referenced by GetKeySize(), and ParameterParser().
std::vector< byte > ParameterParser::m_secretKey [private] |
Stores secret key parameter.
Definition at line 65 of file createtxhex.cpp.
Referenced by GetSecretKey(), and ParameterParser().
std::vector< byte > ParameterParser::m_serialNo [private] |
Stores serial number.
Definition at line 66 of file createtxhex.cpp.
Referenced by GetSerialNo(), and ParameterParser().
size_t ParameterParser::m_serialNoSize [private] |
Stores serial number size parameter.
Definition at line 62 of file createtxhex.cpp.
Referenced by GetSerialNoSize(), and ParameterParser().
std::vector< byte > ParameterParser::m_sharedKey [private] |
Stores shared key parameter.
Definition at line 64 of file createtxhex.cpp.
Referenced by GetSharedKey(), and ParameterParser().
Generated on Fri Aug 8 11:02:44 2008 for AVR411 Secure Rolling Code Algorithm (PC Tools - createtxhex) by 1.4.7
|