Permalink
Browse files

Changed the source to match the previous PSGradePIC attempt. Thanks t…

…o PS3Break Team who accepted to send me the source :). This code is smaller and fits in PIC18F2450.
  • Loading branch information...
1 parent e75e2ad commit 09071f238f879ff5f110130a201b123a7ba956d3 @Noltari committed Dec 11, 2010
Showing with 436 additions and 489 deletions.
  1. +53 −0 Make.bat
  2. +8 −11 Makefile
  3. +94 −0 hmac.c
  4. +37 −0 hmac.h
  5. +14 −34 main.c
  6. +185 −440 sha1.c
  7. +33 −0 sha1.h
  8. +12 −4 usb_desc.h
View
@@ -0,0 +1,53 @@
+@echo off
+title PSGradePIC Generator
+
+set CCS_COMPILER=ccsc
+set CCS_SOURCE=main.c
+set CCS_FLAGS_NBL=+FH +Y9 -T -L -E -M -P -J -D -A
+set CCS_FLAGS_WBLHID=%CCS_FLAGS_NBL% +GWBOOTLOADERHID="true"
+set CCS_FLAGS_WBLMCHP=%CCS_FLAGS_NBL% +GWBOOTLOADERMCHP="true"
+set CCS_FLAGS_LEDS=+GLEDR1="PIN_B4" +GLEDR2="PIN_B1" +GLEDR3="PIN_C0" +GLEDG1="PIN_B5" +GLEDG2="PIN_C1"
+
+set BUILD_DIR=build
+
+set CLEAN_FILES=*.err *.esym *.cod *.sym *.hex *.lst
+
+rmdir /s /q %BUILD_DIR%
+del %CLEAN_FILES% /f /q /s
+
+echo HEX with HID Bootloader.
+%CCS_COMPILER% %CCS_FLAGS_WBLHID% %CCS_FLAGS_LEDS% %CCS_SOURCE%
+
+echo HEX with MCHP Bootloader.
+%CCS_COMPILER% %CCS_FLAGS_WBLMCHP% %CCS_FLAGS_LEDS% %CCS_SOURCE%
+
+echo HEX without Bootloader.
+%CCS_COMPILER% %CCS_FLAGS_NBL% %CCS_FLAGS_LEDS% %CCS_SOURCE%
+
+echo Create %BUILD_DIR% directory.
+mkdir %BUILD_DIR%
+
+echo Fix MCHP Bootloader.
+type "PSGradePIC_wBTL_MCHP.hex"
+:code
+set "header=:020000040000FA.."
+
+setlocal enabledelayedexpansion;
+set /a contador=0
+for /f "tokens=*" %%_ in (PSGradePIC_wBTL_MCHP.hex) do (
+set /a contador+=1
+set "array[!contador!]=%%_";
+)
+:: Truncar el archivo:
+echo !header! > "PSGradePIC_wBTL_MCHP.hex"
+:: Volcar el resto de las variables:
+for /l %%_ in (1desde, 1incremento, !contador!hasta) do (
+echo !array[%%_]! >> "PSGradePIC_wBTL_MCHP.hex"
+)
+type "PSGradePIC_wBTL_MCHP.hex"
+
+echo Move files to %BUILD_DIR%.
+move PSGradePIC*.hex %BUILD_DIR%
+
+echo Remove unused files.
+del %CLEAN_FILES%
View
@@ -1,42 +1,39 @@
CCS_COMPILER = ccsc
CCS_SOURCE = main.c
-CCS_FLAGS_NBL = +FH +Y9 -L -A -E -M -P -J -D
+CCS_FLAGS_NBL = +FH +Y9 -T -L -E -M -P -J -D -A
CCS_FLAGS_WBLHID = $(CCS_FLAGS_NBL) +GWBOOTLOADERHID="true"
CCS_FLAGS_WBLMCHP = $(CCS_FLAGS_NBL) +GWBOOTLOADERMCHP="true"
CCS_FLAGS_LEDS = +GLEDR1="PIN_B4" +GLEDR2="PIN_B1" +GLEDR3="PIN_C0" +GLEDG1="PIN_B5" +GLEDG2="PIN_C1"
ZIP = zip -r
BUILD_DIR = build
-CLEAN_FILES = *.err *.esym *.cod *.sym *.hex *.zip $(BUILD_DIR)
-
-BOOTLOADER_BUILDS = nBTL \
- wBTL_HID \
- wBTL_MCHP
+CLEAN_FILES = *.err *.esym *.cod *.sym *.hex *.lst *.zip $(BUILD_DIR)
VERSION = $(shell git rev-parse HEAD)
all:
#HEX with HID Bootloader.
- $(CCS_COMPILER) $(CCS_FLAGS_WBLHID) $(CCS_FLAGS_LEDS) +GFW$(fw_pic)="true" +GPAYLOAD="$(pl_pic)" +GPAYLOAD_DIR=$(PAYLOAD_DIR) $(CCS_SOURCE)
+ $(CCS_COMPILER) $(CCS_FLAGS_WBLHID) $(CCS_FLAGS_LEDS) $(CCS_SOURCE)
#HEX with MCHP Bootloader.
- $(CCS_COMPILER) $(CCS_FLAGS_WBLMCHP) $(CCS_FLAGS_LEDS) +GFW$(fw_pic)="true" +GPAYLOAD="$(pl_pic)" +GPAYLOAD_DIR=$(PAYLOAD_DIR) $(CCS_SOURCE)
+ $(CCS_COMPILER) $(CCS_FLAGS_WBLMCHP) $(CCS_FLAGS_LEDS) $(CCS_SOURCE)
#HEX without Bootloader.
- $(CCS_COMPILER) $(CCS_FLAGS_NBL) $(CCS_FLAGS_LEDS) +GFW$(fw_pic)="true" +GPAYLOAD="$(pl_pic)" +GPAYLOAD_DIR=$(PAYLOAD_DIR) $(CCS_SOURCE)
+ $(CCS_COMPILER) $(CCS_FLAGS_NBL) $(CCS_FLAGS_LEDS) $(CCS_SOURCE)
#Create build structure.
+ rm -f -r $(BUILD_DIR)
mkdir $(BUILD_DIR);
- $(foreach bl_pic, $(BOOTLOADER_BUILDS), mkdir $(BUILD_DIR)/$(bl_pic); )
#Fix MCHP Bootloader
sed -i '1i :020000040000FA..' PSGradePIC*_wBTL_MCHP.hex
#Move each payload to its directory.
- $(foreach bl_pic, $(BOOTLOADER_BUILDS), mv *_$(bl_pic).hex $(BUILD_DIR)/$(bl_pic); )
+ mv PSGradePIC*.hex $(BUILD_DIR);
#Zip all HEX.
cd $(BUILD_DIR) && $(ZIP) "PSGradePIC_$(VERSION)" *
mv build/PSGradePIC_$(VERSION).zip ./
+ rm -f -r $(BUILD_DIR)
clean:
#Clean files.
View
94 hmac.c
@@ -0,0 +1,94 @@
+/* HMAC-SHA-1 - an implementation of the HMAC message authentication
+ Version as of March 4th 2007
+
+ Copyright (C) 2007 CHZ-Soft, Christian Zietz, <czietz@gmx.net>
+ See README file for more information.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA
+*/
+
+#define SHA1_DIGESTSIZE 20
+#define SHA1_BLOCKSIZE 64
+
+#include "hmac.h"
+
+unsigned char hmackey[SHA1_BLOCKSIZE];
+
+// Initializes HMAC algorithm with given key
+// key must be smaller than 64 bytes
+void HMACInit(unsigned char len) {
+ unsigned char i;
+
+ // copy key, XOR it for the inner digest, pad it to block size
+ for (i=0;i<len;i++) {
+ hmackey[i] = jig_key[i] ^ 0x36;
+ }
+ for (i=len;i<SHA1_BLOCKSIZE;i++) {
+ hmackey[i] = 0x36;
+ }
+
+ // initialize SHA1 and hash key
+ SHA1Init();
+ SHA1Block(hmackey, SHA1_BLOCKSIZE);
+}
+
+// Authenticates blocks of 64 bytes of data.
+// Only the last block *must* be smaller than 64 bytes.
+void HMACBlock(unsigned char* data, unsigned char len) {
+ SHA1Block(data, len);
+}
+
+// Calculates the MAC, hmacdigest will contain the result
+// Assumes that the last call to HMACBlock was done with len<64
+void HMACDone(void) {
+ unsigned char i;
+ unsigned char temp[SHA1_DIGESTSIZE];
+
+ // terminate inner digest and store it
+ SHA1Done();
+ //memcpy(temp, shadigest, SHA1_DIGESTSIZE); //highlight by cheng
+ SHA1MemCpy(temp, SHA1_DIGESTSIZE);
+
+ // prepare key for outer digest
+ // buffer will contain the original key xor 0x5c
+ for (i=0;i<SHA1_BLOCKSIZE;i++) {
+ hmackey[i] ^= 0x6a;
+ }
+
+ // initialize SHA1 and hash key
+ SHA1Init();
+ SHA1Block(hmackey, SHA1_BLOCKSIZE);
+ // hash inner digest and terminate hash
+ SHA1Block(temp, SHA1_DIGESTSIZE);
+ SHA1Done();
+}
+
+/*
+// Authenticates just one arbitrarily sized chunk of data
+void HMACOnce(const unsigned char* key, const unsigned char klen,
+ const unsigned char* data, int len) {
+ HMACInit(key, klen);
+ while (len>=0) {
+ HMACBlock(data, len>SHA1_BLOCKSIZE?SHA1_BLOCKSIZE:len);
+ len -= SHA1_BLOCKSIZE;
+ data += SHA1_BLOCKSIZE;
+ }
+ HMACDone();
+}
+*/
+
+
+
View
37 hmac.h
@@ -0,0 +1,37 @@
+/* HMAC-SHA-1 - an implementation of the HMAC message authentication
+ Version as of March 4th 2007
+
+ Copyright (C) 2007 CHZ-Soft, Christian Zietz, <czietz@gmx.net>
+ See README file for more information.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA
+*/
+
+#ifndef __HMAC_H__
+#define __HMAC_H__
+
+#include "sha1.h"
+
+#define hmacdigest shadigest
+
+void HMACInit(unsigned char len);
+void HMACBlock(unsigned char* data, unsigned char len);
+void HMACDone(void);
+void HMACOnce(unsigned char* key, unsigned char klen,
+ unsigned char* data, int len);
+
+#endif
+
View
48 main.c
@@ -38,6 +38,7 @@ char const USB_STRING_DESC[] = {5, USB_DESC_STRING_TYPE, 'H', 0, 'O', 0, 'L', 0,
#include "usb.c"
#include "sha1.c"
+#include "hmac.c"
#define PORT_EMPTY 0x0100
#define PORT_FULL 0x0103
@@ -249,43 +250,28 @@ void main() {
if(WaitJig) {
if(WaitJig == 1) {
if(usb_kbhit(2)) {
- int i;
- unsigned char c;
Chirp();
- /*
- c = usb_get_packet(2, TxBuf, 8);
- for(i = 0; i < 8; i++) {
- jigChallengeData[8 * nJigs + i] = TxBuf[i];
- }
- */
-
- c = usb_get_packet(2, jigChallengeData + nJigs * 8, 8);
+ usb_get_packet(2, jig_response + nJigs * 8, 8);
nJigs++;
EP_BDxST_I(1) = 0x40; //Clear IN endpoint
+
if(nJigs == 8) {
//Calculate jig response
- HMACInit();
- HMACAddBytes(jigChallengeData+7, 20);
-
- for (i = 0; i < 64; i++) {
- jigResponseData[i] = 0x00;
- }
+ HMACInit(SHA1_DIGESTSIZE);
- jigResponseData[0] = 0x00;
- jigResponseData[1] = 0x00;
- jigResponseData[2] = 0xFF;
- jigResponseData[3] = 0x00;
- jigResponseData[4] = 0x2E;
- jigResponseData[5] = 0x02;
- jigResponseData[6] = 0x02;
- jigResponseData[7] = 0xAA;
- jigResponseData[8] = 0xAA;
+ jig_response[1]--;
+ jig_response[3]++;
+ jig_response[6]++;
- //usb_task();
+ HMACBlock(jig_response + JIG_DATA_HEADER_LEN, SHA1_DIGESTSIZE);
+ HMACDone();
+
+ jig_response[7] = jig_id[0];
+ jig_response[8] = jig_id[1];
- HMACDone(jigResponseData+9);
+ SHA1MemCpy(jig_response + 9, SHA1_DIGESTSIZE);
nJigs = 0;
WaitJig = 2;
@@ -296,7 +282,7 @@ void main() {
else {
int n = 0;
for(n = 0; n < 8; ++n) {
- TxBuf[n] = jigResponseData[8 * nJigs + n];
+ TxBuf[n] = jig_response[8 * nJigs + n];
}
if(usb_put_packet(1, TxBuf, 8, nJigs == 0 ? 0 : USB_DTS_TOGGLE)) {
Delay10ms(1);
@@ -307,12 +293,6 @@ void main() {
WaitJig = 0;
Delay10ms(50);
Disconnect = 5;
-
- /*
- nJigs = 0;
- WaitJig = 0;
- OnDongleOK();
- */
}
}
}
Oops, something went wrong.

0 comments on commit 09071f2

Please sign in to comment.