Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit e75e2ad0f741c8c723f5bc21c4efe461b17ffb81 1 parent 4a9f288
@Noltari authored
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();
+ */
}
}
}
View
649 sha1.c
@@ -1,195 +1,454 @@
-/*
-SHA-1 - an implementation of the Secure Hash Algorithm in C
-Version as of September 22nd 2006
-
-Copyright (C) 2006 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 this on little endian architectures
-#define SHA_LITTLE_ENDIAN
-
-// define this if you want to process more then 65535 bytes
-/* #define SHA_BIG_DATA */
-
-#include <stdint.h>
-#include <string.h>
-
-// initial values
-#define init_h0 0x67452301
-#define init_h1 0xEFCDAB89
-#define init_h2 0x98BADCFE
-#define init_h3 0x10325476
-#define init_h4 0xC3D2E1F0
-
-// bit-shift-operation
-#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
-
-union _message {
- unsigned char data[64];
- uint32_t w[16];
-} message;
-
-struct shastate {
- uint32_t h0,h1,h2,h3,h4;
-#ifdef SHA_BIG_DATA
- uint32_t count;
-#else
- uint16_t count;
-#endif
-};
-
-union _digest {
- unsigned char data[20];
- struct shastate state;
-} shadigest2;
-
-// processes one endianess-corrected block, provided in message
-void SHA1(void) {
- uint8_t i;
- uint32_t a,b,c,d,e,f,k,t;
-
- a = shadigest2.state.h0;
- b = shadigest2.state.h1;
- c = shadigest2.state.h2;
- d = shadigest2.state.h3;
- e = shadigest2.state.h4;
-
- // main loop: 80 rounds
- for (i=0; i<=79; i++) {
- if (i<=19) {
- f = d ^ (b & (c ^ d));
- k = 0x5A827999;
- } else if (i<=39) {
- f = b ^ c ^ d;
- k = 0x6ED9EBA1;
- } else if (i<=59) {
- f = (b & c) | (d & (b | c));
- k = 0x8F1BBCDC;
- } else {
- f = b ^ c ^ d;
- k = 0xCA62C1D6;
- }
-
- // blow up to 80 dwords while in the loop, save some RAM
- if (i>=16) {
- t = rol(message.w[(i+13)&15] ^ message.w[(i+8)&15] ^ message.w[(i+2)&15] ^ message.w[i&15], 1);
- message.w[i&15] = t;
- }
-
- t = rol(a, 5) + f + e + k + message.w[i&15];
- e = d;
- d = c;
- c = rol(b, 30);
- b = a;
- a = t;
- }
-
- shadigest2.state.h0 += a;
- shadigest2.state.h1 += b;
- shadigest2.state.h2 += c;
- shadigest2.state.h3 += d;
- shadigest2.state.h4 += e;
-}
-
-void SHA1Init(void) {
- shadigest2.state.h0 = init_h0;
- shadigest2.state.h1 = init_h1;
- shadigest2.state.h2 = init_h2;
- shadigest2.state.h3 = init_h3;
- shadigest2.state.h4 = init_h4;
- shadigest2.state.count = 0;
-}
-
-// Hashes blocks of 64 bytes of data.
-// Only the last block *must* be smaller than 64 bytes.
-void SHA1Block(unsigned char* data, uint8_t len) {
- uint8_t i;
-
- // clear all bytes in data block that are not overwritten anyway
- for (i=len>>2;i<=15;i++) {
- message.w[i] = 0;
- }
-
-#ifdef SHA_LITTLE_ENDIAN
- // swap bytes
- for (i=0;i<len;i+=4) {
- message.data[i] = data[i+3];
- message.data[i+1] = data[i+2];
- message.data[i+2] = data[i+1];
- message.data[i+3] = data[i];
- }
-#else
- memcpy(message.data, data, len);
-#endif
-
- // remember number of bytes processed for final block
- shadigest2.state.count += len;
-
- if (len<64) {
- // final block: mask bytes accidentally copied by for-loop
- // and do the padding
- message.w[len >> 2] &= 0xffffffffL << (((~len & 3)*8)+8);
- message.w[len >> 2] |= 0x80L << ((~len & 3)*8);
- // there is space for a qword containing the size at the end
- // of the block
- if (len<=55) {
- message.w[15] = (uint32_t)(shadigest2.state.count) * 8;
- }
- }
-
- SHA1();
-
- // was last data block, but there wasn't space for the size:
- // process another block
- if ((len>=56) && (len<64)) {
- for (i=0; i<=14; i++) {
- message.w[i] = 0;
- }
- message.w[15] = (uint32_t)(shadigest2.state.count) * 8;
- SHA1();
- }
-}
-
-// Correct the endianess if needed
-void SHA1Done(void) {
-#ifdef SHA_LITTLE_ENDIAN
- uint8_t i;
- unsigned char j;
- // swap bytes
- for (i=0;i<=4;i++) {
- j = shadigest2.data[4*i];
- shadigest2.data[4*i] = shadigest2.data[4*i+3];
- shadigest2.data[4*i+3] = j;
- j = shadigest2.data[4*i+1];
- shadigest2.data[4*i+1] = shadigest2.data[4*i+2];
- shadigest2.data[4*i+2] = j;
- }
-#endif
-}
-
-// Hashes just one arbitrarily sized chunk of data
-void SHA1Once(unsigned char* data, int len) {
- SHA1Init();
- while (len>=0) {
- SHA1Block(data, len>64?64:len);
- len -= 64;
- data += 64;
- }
- SHA1Done();
-}
+/*
+ * sha1.c
+ *
+ * Copyright (C) 1998, 2009
+ * Paul E. Jones <paulej@packetizer.com>
+ * All Rights Reserved
+ *
+ *****************************************************************************
+ * $Id: sha1.c 12 2009-06-22 19:34:25Z paulej $
+ *****************************************************************************
+ *
+ * Description:
+ * This file implements the Secure Hashing Standard as defined
+ * in FIPS PUB 180-1 published April 17, 1995.
+ *
+ * The Secure Hashing Standard, which uses the Secure Hashing
+ * Algorithm (SHA), produces a 160-bit message digest for a
+ * given data stream. In theory, it is highly improbable that
+ * two messages will produce the same message digest. Therefore,
+ * this algorithm can serve as a means of providing a "fingerprint"
+ * for a message.
+ *
+ * Portability Issues:
+ * SHA-1 is defined in terms of 32-bit "words". This code was
+ * written with the expectation that the processor has at least
+ * a 32-bit machine word size. If the machine word size is larger,
+ * the code should still function properly. One caveat to that
+ * is that the input functions taking characters and character
+ * arrays assume that only 8 bits of information are stored in each
+ * character.
+ *
+ * Caveats:
+ * SHA-1 is designed to work with messages less than 2^64 bits
+ * long. Although SHA-1 allows a message digest to be generated for
+ * messages of any number of bits less than 2^64, this
+ * implementation only works with messages with a length that is a
+ * multiple of the size of an 8-bit character.
+ *
+ */
+
+/*
+ * This structure will hold context information for the hashing
+ * operation
+ */
+typedef struct SHA1Context
+{
+ unsigned int32 Message_Digest[5]; /* Message Digest (output) */
+
+ unsigned int32 Length_Low; /* Message length in bits */
+ unsigned int32 Length_High; /* Message length in bits */
+
+ unsigned char Message_Block[64]; /* 512-bit message blocks */
+ int Message_Block_Index; /* Index into message block array */
+
+ int Computed; /* Is the digest computed? */
+ int Corrupted; /* Is the message digest corruped? */
+} SHA1Context;
+
+/*
+ * Function Prototypes
+ */
+void SHA1Reset(SHA1Context *);
+int SHA1Result(SHA1Context *);
+void SHA1Input( SHA1Context *,
+ unsigned char *,
+ unsigned int32);
+
+void HMACInit();
+void HMACAddBytes(unsigned char* buffer, unsigned int32 length);
+void HMACDone(unsigned char* result);
+
+/*
+ * Define the circular shift macro
+ */
+#define SHA1CircularShift(bits,word) \
+ ((((word) << (bits)) & 0xFFFFFFFF) | \
+ ((word) >> (32-(bits))))
+
+SHA1Context _context;
+unsigned char _hmacKey[64];
+
+void HMACInit()
+{
+ const unsigned char jigKey[] = {0x04, 0x4E, 0x61, 0x1B, 0xA6, 0xA6, 0xE3, 0x9A,
+ 0x98, 0xCF, 0x35, 0x81, 0x2C, 0x80, 0x68, 0xC7,
+ 0xFC, 0x5F, 0x7A, 0xE8};
+ int i;
+
+ SHA1Reset(&_context);
+
+ for (i = 0; i < 20; i++)
+ _hmacKey[i] = (jigKey[i] ^ 0x36);
+ for (i = 20; i < 64; i++)
+ _hmacKey[i] = 0x36;
+ HMACAddBytes(_hmacKey, 64);
+}
+
+void HMACAddBytes(unsigned char* buffer, unsigned int32 length)
+{
+ SHA1Input(&_context, buffer, length);
+}
+
+void HMACDone(unsigned char* result)
+{
+ int i;
+ unsigned char digest[20];
+ SHA1Result(&_context);
+ for (i = 0; i < 5; i++)
+ {
+ digest[i*4+0] = ((_context.Message_Digest[i] >> 24) & 0xFF);
+ digest[i*4+1] = ((_context.Message_Digest[i] >> 16) & 0xFF);
+ digest[i*4+2] = ((_context.Message_Digest[i] >> 8) & 0xFF);
+ digest[i*4+3] = (_context.Message_Digest[i] & 0xFF);
+ }
+
+ SHA1Context c;
+ SHA1Reset(&c);
+ for (i = 0; i < 64; i++)
+ _hmacKey[i] ^= 0x6A;
+ SHA1Input(&c, _hmacKey, 64);
+ SHA1Input(&c, digest, 20);
+ SHA1Result(&c);
+
+ for (i = 0; i < 5; i++)
+ {
+ result[i*4+0] = ((c.Message_Digest[i] >> 24) & 0xFF);
+ result[i*4+1] = ((c.Message_Digest[i] >> 16) & 0xFF);
+ result[i*4+2] = ((c.Message_Digest[i] >> 8) & 0xFF);
+ result[i*4+3] = (c.Message_Digest[i] & 0xFF);
+ }
+}
+
+/* Function prototypes */
+void SHA1ProcessMessageBlock(SHA1Context *);
+void SHA1PadMessage(SHA1Context *);
+
+/*
+ * SHA1Reset
+ *
+ * Description:
+ * This function will initialize the SHA1Context in preparation
+ * for computing a new message digest.
+ *
+ * Parameters:
+ * context: [in/out]
+ * The context to reset.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1Reset(SHA1Context *context)
+{
+ context->Length_Low = 0;
+ context->Length_High = 0;
+ context->Message_Block_Index = 0;
+
+ context->Message_Digest[0] = 0x67452301;
+ context->Message_Digest[1] = 0xEFCDAB89;
+ context->Message_Digest[2] = 0x98BADCFE;
+ context->Message_Digest[3] = 0x10325476;
+ context->Message_Digest[4] = 0xC3D2E1F0;
+
+ context->Computed = 0;
+ context->Corrupted = 0;
+}
+
+/*
+ * SHA1Result
+ *
+ * Description:
+ * This function will return the 160-bit message digest into the
+ * Message_Digest array within the SHA1Context provided
+ *
+ * Parameters:
+ * context: [in/out]
+ * The context to use to calculate the SHA-1 hash.
+ *
+ * Returns:
+ * 1 if successful, 0 if it failed.
+ *
+ * Comments:
+ *
+ */
+int SHA1Result(SHA1Context *context)
+{
+
+ if (context->Corrupted)
+ {
+ return 0;
+ }
+
+ if (!context->Computed)
+ {
+ SHA1PadMessage(context);
+ context->Computed = 1;
+ }
+
+ return 1;
+}
+
+/*
+ * SHA1Input
+ *
+ * Description:
+ * This function accepts an array of octets as the next portion of
+ * the message.
+ *
+ * Parameters:
+ * context: [in/out]
+ * The SHA-1 context to update
+ * message_array: [in]
+ * An array of characters representing the next portion of the
+ * message.
+ * length: [in]
+ * The length of the message in message_array
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1Input( SHA1Context *context,
+ unsigned char *message_array,
+ unsigned int32 length)
+{
+ if (!length)
+ {
+ return;
+ }
+
+ if (context->Computed || context->Corrupted)
+ {
+ context->Corrupted = 1;
+ return;
+ }
+
+ while(length-- && !context->Corrupted)
+ {
+ context->Message_Block[context->Message_Block_Index++] =
+ (*message_array & 0xFF);
+
+ context->Length_Low += 8;
+ /* Force it to 32 bits */
+ context->Length_Low &= 0xFFFFFFFF;
+ if (context->Length_Low == 0)
+ {
+ context->Length_High++;
+ /* Force it to 32 bits */
+ context->Length_High &= 0xFFFFFFFF;
+ if (context->Length_High == 0)
+ {
+ /* Message is too long */
+ context->Corrupted = 1;
+ }
+ }
+
+ if (context->Message_Block_Index == 64)
+ {
+ SHA1ProcessMessageBlock(context);
+ }
+
+ message_array++;
+ }
+}
+
+/*
+ * SHA1ProcessMessageBlock
+ *
+ * Description:
+ * This function will process the next 512 bits of the message
+ * stored in the Message_Block array.
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ * Many of the variable names in the SHAContext, especially the
+ * single character names, were used because those were the names
+ * used in the publication.
+ *
+ *
+ */
+void SHA1ProcessMessageBlock(SHA1Context *context)
+{
+ const unsigned int32 K[] = /* Constants defined in SHA-1 */
+ {
+ 0x5A827999,
+ 0x6ED9EBA1,
+ 0x8F1BBCDC,
+ 0xCA62C1D6
+ };
+ int t; /* Loop counter */
+ unsigned int32 temp; /* Temporary word value */
+ unsigned int32 W[80]; /* Word sequence */
+ unsigned int32 A, B, C, D, E; /* Word buffers */
+
+ /*
+ * Initialize the first 16 words in the array W
+ */
+ for(t = 0; t < 16; t++)
+ {
+ W[t] = ((unsigned int32) context->Message_Block[t * 4]) << 24;
+ W[t] |= ((unsigned int32) context->Message_Block[t * 4 + 1]) << 16;
+ W[t] |= ((unsigned int32) context->Message_Block[t * 4 + 2]) << 8;
+ W[t] |= ((unsigned int32) context->Message_Block[t * 4 + 3]);
+ }
+
+ for(t = 16; t < 80; t++)
+ {
+ W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
+ }
+
+ A = context->Message_Digest[0];
+ B = context->Message_Digest[1];
+ C = context->Message_Digest[2];
+ D = context->Message_Digest[3];
+ E = context->Message_Digest[4];
+
+ for(t = 0; t < 20; t++)
+ {
+ temp = SHA1CircularShift(5,A) +
+ ((B & C) | ((~B) & D)) + E + W[t] + K[0];
+ temp &= 0xFFFFFFFF;
+ E = D;
+ D = C;
+ C = SHA1CircularShift(30,B);
+ B = A;
+ A = temp;
+ }
+
+ for(t = 20; t < 40; t++)
+ {
+ temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1];
+ temp &= 0xFFFFFFFF;
+ E = D;
+ D = C;
+ C = SHA1CircularShift(30,B);
+ B = A;
+ A = temp;
+ }
+
+ for(t = 40; t < 60; t++)
+ {
+ temp = SHA1CircularShift(5,A) +
+ ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
+ temp &= 0xFFFFFFFF;
+ E = D;
+ D = C;
+ C = SHA1CircularShift(30,B);
+ B = A;
+ A = temp;
+ }
+
+ for(t = 60; t < 80; t++)
+ {
+ temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3];
+ temp &= 0xFFFFFFFF;
+ E = D;
+ D = C;
+ C = SHA1CircularShift(30,B);
+ B = A;
+ A = temp;
+ }
+
+ context->Message_Digest[0] =
+ (context->Message_Digest[0] + A) & 0xFFFFFFFF;
+ context->Message_Digest[1] =
+ (context->Message_Digest[1] + B) & 0xFFFFFFFF;
+ context->Message_Digest[2] =
+ (context->Message_Digest[2] + C) & 0xFFFFFFFF;
+ context->Message_Digest[3] =
+ (context->Message_Digest[3] + D) & 0xFFFFFFFF;
+ context->Message_Digest[4] =
+ (context->Message_Digest[4] + E) & 0xFFFFFFFF;
+
+ context->Message_Block_Index = 0;
+}
+
+/*
+ * SHA1PadMessage
+ *
+ * Description:
+ * According to the standard, the message must be padded to an even
+ * 512 bits. The first padding bit must be a '1'. The last 64
+ * bits represent the length of the original message. All bits in
+ * between should be 0. This function will pad the message
+ * according to those rules by filling the Message_Block array
+ * accordingly. It will also call SHA1ProcessMessageBlock()
+ * appropriately. When it returns, it can be assumed that the
+ * message digest has been computed.
+ *
+ * Parameters:
+ * context: [in/out]
+ * The context to pad
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1PadMessage(SHA1Context *context)
+{
+ /*
+ * Check to see if the current message block is too small to hold
+ * the initial padding bits and length. If so, we will pad the
+ * block, process it, and then continue padding into a second
+ * block.
+ */
+ if (context->Message_Block_Index > 55)
+ {
+ context->Message_Block[context->Message_Block_Index++] = 0x80;
+ while(context->Message_Block_Index < 64)
+ {
+ context->Message_Block[context->Message_Block_Index++] = 0;
+ }
+
+ SHA1ProcessMessageBlock(context);
+
+ while(context->Message_Block_Index < 56)
+ {
+ context->Message_Block[context->Message_Block_Index++] = 0;
+ }
+ }
+ else
+ {
+ context->Message_Block[context->Message_Block_Index++] = 0x80;
+ while(context->Message_Block_Index < 56)
+ {
+ context->Message_Block[context->Message_Block_Index++] = 0;
+ }
+ }
+
+ /*
+ * Store the message length as the last 8 octets
+ */
+ context->Message_Block[56] = (context->Length_High >> 24) & 0xFF;
+ context->Message_Block[57] = (context->Length_High >> 16) & 0xFF;
+ context->Message_Block[58] = (context->Length_High >> 8) & 0xFF;
+ context->Message_Block[59] = (context->Length_High) & 0xFF;
+ context->Message_Block[60] = (context->Length_Low >> 24) & 0xFF;
+ context->Message_Block[61] = (context->Length_Low >> 16) & 0xFF;
+ context->Message_Block[62] = (context->Length_Low >> 8) & 0xFF;
+ context->Message_Block[63] = (context->Length_Low) & 0xFF;
+
+ SHA1ProcessMessageBlock(context);
+}
View
36 sha1.h
@@ -1,36 +0,0 @@
-/*
-SHA-1 - an implementation of the Secure Hash Algorithm in C
-Version as of September 22nd 2006
-
-Copyright (C) 2006 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 __SHA1_H__
-#define __SHA1_H__
-
-#include <stdint.h>
-
-unsigned char shadigest[20];
-
-void SHA1Init(void);
-void SHA1Block(unsigned char* data, uint8_t len);
-void SHA1Done(void);
-void SHA1Once(unsigned char* data, int len);
-
-#endif
View
15 usb_desc.h
@@ -46,19 +46,8 @@ const unsigned int8 USB_CONFIG_DESC[] = {
0x07, 0x05, 0x81, 0x02, 0x08, 0x00, 0x00,
};
-const unsigned int8 jig_key[20] = {
-// RETAIL
- 0x04, 0x4E, 0x61, 0x1B, 0xA6, 0xA6, 0xE3, 0x9A, 0x98, 0xCF,
- 0x35, 0x81, 0x2C, 0x80, 0x68, 0xC7, 0xFC, 0x5F, 0x7A, 0xE8
-
-// CEB / DEBUG / TEST
-// 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC,
-// 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0xF0, 0xE1, 0xD2, 0xC3
-};
-
-const unsigned int8 jig_id [] = {0xaa, 0xaa};
-
-static unsigned int8 jig_challenge_res[64];
+unsigned char jigChallengeData[64]; //Buffer used for jig challenge data
+unsigned char jigResponseData[64];
#define HUB_DEVICE_SIZE 0x0012
Please sign in to comment.
Something went wrong with that request. Please try again.