|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
One of the encryption shemes in NCSIM is utilizingRC5 to encrypt the keyblock. The encrypted part ismarked with// Pragma protect key_keyname = CDS_KEY// Pragma protect key_method = RC5style directives.The key_block section that this scheme RC5 encryptsis a text snippet that in term includes the encryption methodof the data_block, normally it is AES and the AES key.An example of the key_block section:--------- Before decrypt -----------// Pragma protect key_blockCPuqmTjFp2LUUeeTQCmjXOtQIYdyxp0M4cUOb1KoZjg + IZHFIf / lII1Gcm36dPgTdOL8xO0E1LGVCab1wSMzG9r5keP4bLvlYgPV / xfFb + kJ3xprGZJwz2L9HjIX4NhCafDnbYui0WnFdgCie / wO3qZOwTPUnTzSsQ / mohys88s5 + 6CDx9iJ0w ==// Pragma protect end_key_block-------------------------------------------- After decrypt -----------@fbaWIKWEo [NCP: ENG_VER = 1.100000]// Pragma protect data_method = AES// Pragma protect data_decrypt_keyxSzOPdVsfyMAAAAAAAAA ==-----------------------------------Here is the keys / method to decrypt it:NCSIM uses RC5_CBC. This is similar to AES_CBS inthat it runs a decrypt round and a final xor using. A runtime vector The RC5_CBC parameters are:RC5 key: 96e8dfd8354fb228RC5_CBC iv: 636164656e636500RC5 rounds: 0x14For the AES key that is inside the key_block sectionthe initialization vector used by aes_cbc is:AES iv: 636164656e63652064657369676e2073The RC5 keyschedule is standard RC5 In OpenSSL terminology.:RC5_32_set_key (& key, 8, d, 20);(Note that OpenSSL does only implement RC5 up to RC5_16_ROUNDS,you have to patch OpenSSL to increase the supported RC5 roundsand unroll RC5_32_decrypt to support it. Note also that youneed to use linux-x32 so that "long int" is 32 bit)The decrypt is again standard RC5, in Openssl terminology:RC5_32_decrypt (p, & key);where 2 ints are decrypted on each call.The complete RC5_CBC algo used by ncsim: unsigned int * p = ..; int len = ..; char key [] = {0x96, 0xe8, 0xdf, 0xd8, 0x35, 0x4f, 0xb2, 0x28}; unsigned long iv0 = 0x65646163; / * cade * / unsigned long iv1 = 0x0065636e; / * nce \ 0 * / RC5_32_set_key (& key, 8, d, 20); for (i = 0; i <len; i + = 2) { unsigned int o0, o1; o0 = p [i + 0]; o1 = p [i + 1]; RC5_32_decrypt (p + i, & key); p [i + 0] ^ = iv0; p [i + 1] ^ = iv1; iv0 = o0; iv1 = o1; } |
|