FreeCalypso > hg > freecalypso-tools
comparison rvinterf/etmsync/pirimei.c @ 14:3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 03 Oct 2016 07:00:55 +0000 |
parents | e7502631a0f9 |
children | 6d9b10633f10 |
comparison
equal
deleted
inserted
replaced
13:46ad66a231af | 14:3d148edb87c2 |
---|---|
1 /* | 1 /* |
2 * Reading and decryption of Pirelli's factory IMEI record | 2 * Reading and decryption of Pirelli's factory IMEI record |
3 */ | 3 */ |
4 | 4 |
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <openssl/des.h> | |
7 #include <stdio.h> | 6 #include <stdio.h> |
8 #include <stdlib.h> | 7 #include <stdlib.h> |
9 #include <string.h> | 8 #include <string.h> |
10 #include <strings.h> | 9 #include <strings.h> |
10 #include "cl_des.h" | |
11 #include "exitcodes.h" | 11 #include "exitcodes.h" |
12 | 12 |
13 u_char pirelli_imeisv[8]; | 13 u_char pirelli_imeisv[8]; |
14 | 14 |
15 get_pirelli_imei() | 15 get_pirelli_imei() |
16 { | 16 { |
17 DES_cblock ciphertext[2], dieid_key, decrypted[2]; | 17 u_char ciphertext[2][8], dieid_key[8], decrypted[2][8]; |
18 DES_key_schedule keysched; | |
19 int rc; | 18 int rc; |
20 static char failmsg[] = | 19 static char failmsg[] = |
21 "decryption failed: no valid IMEI record or incompatible firmware\n"; | 20 "decryption failed: no valid IMEI record or incompatible firmware\n"; |
22 | 21 |
23 printf("Requesting Calypso die ID\n"); | 22 printf("Requesting Calypso die ID\n"); |
26 return(rc); | 25 return(rc); |
27 printf("Reading IMEI record in Pirelli's factory data block\n"); | 26 printf("Reading IMEI record in Pirelli's factory data block\n"); |
28 rc = do_memory_read(0x027F0504, ciphertext, 16); | 27 rc = do_memory_read(0x027F0504, ciphertext, 16); |
29 if (rc) | 28 if (rc) |
30 return(rc); | 29 return(rc); |
31 DES_set_key_unchecked(&dieid_key, &keysched); | 30 cl_des(ciphertext[0], dieid_key, decrypted[0], CL_DES_DECRYPTION); |
32 DES_ecb_encrypt(&ciphertext[0], &decrypted[0], &keysched, DES_DECRYPT); | 31 cl_des(ciphertext[1], dieid_key, decrypted[1], CL_DES_DECRYPTION); |
33 DES_ecb_encrypt(&ciphertext[1], &decrypted[1], &keysched, DES_DECRYPT); | |
34 if (bcmp(decrypted[1], dieid_key, 8)) { | 32 if (bcmp(decrypted[1], dieid_key, 8)) { |
35 printf(failmsg); | 33 printf(failmsg); |
36 return(ERROR_TARGET); | 34 return(ERROR_TARGET); |
37 } | 35 } |
38 bcopy(decrypted[0], pirelli_imeisv, 8); | 36 bcopy(decrypted[0], pirelli_imeisv, 8); |