Permalink
Browse files

PSGradePIC fully working. Enjoy :D. BTW, it's based on TI-89 port, th…

…ank you very much Brandon Wilson ^^.
  • Loading branch information...
1 parent 4a9f288 commit e75e2ad0f741c8c723f5bc21c4efe461b17ffb81 @Noltari committed Dec 9, 2010
Showing with 487 additions and 393 deletions.
  1. +0 −93 hmac.c
  2. +0 −38 hmac.h
  3. +31 −18 main.c
  4. +454 −195 sha1.c
  5. +0 −36 sha1.h
  6. +2 −13 usb_desc.h
View
93 hmac.c
@@ -1,93 +0,0 @@
-/*
-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
-*/
-
-#include <stdint.h>
-#include <string.h>
-#include "sha1.h"
-#include "sha1.c"
-
-#define SHA1_DIGESTSIZE 20
-#define SHA1_BLOCKSIZE 64
-
-unsigned char hmackey[SHA1_BLOCKSIZE];
-
-// Initializes HMAC algorithm with given key
-// key must be smaller than 64 bytes
-void HMACInit(unsigned char* key, uint8_t len) {
- uint8_t i;
-
- // copy key, XOR it for the inner digest, pad it to block size
- for (i=0;i<len;i++) {
- hmackey[i] = 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, uint8_t 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) {
- uint8_t i;
- unsigned char temp[SHA1_DIGESTSIZE];
-
- // terminate inner digest and store it
- SHA1Done();
- memcpy(temp, shadigest, 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(unsigned char* key, uint8_t klen,
- 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
38 hmac.h
@@ -1,38 +0,0 @@
-/*
-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 <stdint.h>
-#include "sha1.h"
-
-#define hmacdigest shadigest
-
-void HMACInit(unsigned char* key, uint8_t len);
-void HMACBlock(unsigned char* data, uint8_t len);
-void HMACDone(void);
-void HMACOnce(unsigned char* key, uint8_t klen,
- unsigned char* data, int len);
-
-#endif
View
49 main.c
@@ -4,8 +4,6 @@
#use rs232(baud=115200, xmit=pin_c6, rcv=pin_c7)
-#define CHALLENGE_INDEX 7
-
/////////////////////////
// Bootloader Memory Space
// USB HID Bootloader
@@ -39,8 +37,7 @@ char const USB_STRING_DESC[] = {5, USB_DESC_STRING_TYPE, 'H', 0, 'O', 0, 'L', 0,
#include "pic18_usb.c"
#include "usb.c"
-#include "hmac.h"
-#include "hmac.c"
+#include "sha1.c"
#define PORT_EMPTY 0x0100
#define PORT_FULL 0x0103
@@ -255,30 +252,40 @@ void main() {
int i;
unsigned char c;
Chirp();
- c = usb_get_packet(2, TxBuf, 8);
+ /*
+ c = usb_get_packet(2, TxBuf, 8);
for(i = 0; i < 8; i++) {
- jig_challenge_res[8 * nJigs + i] = TxBuf[i];
+ jigChallengeData[8 * nJigs + i] = TxBuf[i];
}
+ */
+
+ c = usb_get_packet(2, jigChallengeData + nJigs * 8, 8);
nJigs++;
EP_BDxST_I(1) = 0x40; //Clear IN endpoint
if(nJigs == 8) {
- //prepare the response
- jig_challenge_res[1]--;
- jig_challenge_res[3]++;
- jig_challenge_res[6]++;
+ //Calculate jig response
+ HMACInit();
+ HMACAddBytes(jigChallengeData+7, 20);
- HMACBlock(&jig_challenge_res[CHALLENGE_INDEX],20);
+ for (i = 0; i < 64; i++) {
+ jigResponseData[i] = 0x00;
+ }
- HMACDone();
+ 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_challenge_res[7] = jig_id[0];
- jig_challenge_res[8] = jig_id[1];
+ //usb_task();
- for( i = 0; i < 20; i++) {
- jig_challenge_res[9+i] = hmacdigest[i];
- }
+ HMACDone(jigResponseData+9);
nJigs = 0;
WaitJig = 2;
@@ -289,7 +296,7 @@ void main() {
else {
int n = 0;
for(n = 0; n < 8; ++n) {
- TxBuf[n] = jig_challenge_res[8 * nJigs + n];
+ TxBuf[n] = jigResponseData[8 * nJigs + n];
}
if(usb_put_packet(1, TxBuf, 8, nJigs == 0 ? 0 : USB_DTS_TOGGLE)) {
Delay10ms(1);
@@ -300,6 +307,12 @@ void main() {
WaitJig = 0;
Delay10ms(50);
Disconnect = 5;
+
+ /*
+ nJigs = 0;
+ WaitJig = 0;
+ OnDongleOK();
+ */
}
}
}
Oops, something went wrong.

0 comments on commit e75e2ad

Please sign in to comment.