Skip to content

Commit

Permalink
Hooks the AES crypto function, which converts an Enhanced Privacy key…
Browse files Browse the repository at this point in the history
… into a 59-bit XOR keystream.
  • Loading branch information
travisgoodspeed committed Mar 26, 2016
1 parent 5dd5842 commit c18f6dd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion applet/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SRCS = main.c usb.c gfx.c dmr.c printf.c dmesg.c stm32f4xx_it.c system_stm32f4xx.c os.c menu.c
SRCS = main.c usb.c gfx.c dmr.c printf.c dmesg.c stm32f4xx_it.c system_stm32f4xx.c os.c menu.c aes.c
PROJ_NAME=main


Expand Down
6 changes: 6 additions & 0 deletions applet/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ def hookbl(self,adr,handler,oldhandler=None):
merger.hookbl(0x0802e4b0,sapplet.getadr("print_DebugLine"),0);
merger.hookbl(0x0802e582,sapplet.getadr("print_DebugLine"),0);

#Function that calls aes_cipher() twice. When are these called?
merger.hookbl(0x0802177c,sapplet.getadr("aes_cipher_hook"),0);
merger.hookbl(0x0802182c,sapplet.getadr("aes_cipher_hook"),0);
#c5000_dmr_init() calls aes_cipher() once, with Enhanced Privacy Key as input.
merger.hookbl(0x0803df16,sapplet.getadr("aes_cipher_hook"),0);

print "Hooking a menu call.";
merger.setword(0x08039d98,
sapplet.getadr("main_menu_hook")+1);
Expand Down
31 changes: 31 additions & 0 deletions applet/src/aes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

#include <stdio.h>
#include <string.h>

#include "md380.h"
#include "printf.h"
#include "dmesg.h"
#include "version.h"
#include "tooldfu.h"
#include "config.h"
#include "gfx.h"


/* This hook intercepts calls to aes_cipher(), which is used to turn
the 128-bit Enhanced Privacy Key into a 59-bit sequence that gets
XORed with the audio before transmission and after reception.
By changing the output to match Motorola's Basic Privacy, we can
patch the MD380 to be compatible with a Motorola network.
*/

int *aes_cipher_hook(int *pkt){
int *res;
printf("aes_cipher(0x%08x);\nIN :",pkt);
printhex((char*) pkt,16); //Print the Enhanced Privacy Key
printf("\nOUT :");
res=aes_cipher(pkt);
printhex((char*) res,16); //Print the keystream it produces. (First 59 bits are XOR'ed with the audio.)
printf("\n");
return res;
}
3 changes: 3 additions & 0 deletions applet/src/md380-2.032.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ void (*OS_EXIT_CRITICAL)(int) = 0x08041e01;

void (*c5000_spi0_readreg)(int reg, char*buf)=0x0803e2f5;
void (*c5000_spi0_writereg)(int reg, int val)=0x0803e2a9;


int* (*aes_cipher)(int *pkt)=0x080356b1;
4 changes: 4 additions & 0 deletions applet/src/md380.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ extern void (*c5000_spi0_readreg)(int reg, char *buf);

//! Writes a register in the C5000.
extern void (*c5000_spi0_writereg)(int reg, int val);


//! Unknown AES function.
extern int* (*aes_cipher)(int *pkt);

0 comments on commit c18f6dd

Please sign in to comment.