mirror of
https://github.com/xenia-project/xell-reloaded.git
synced 2024-11-23 11:59:46 +00:00
Moved xb360/ and crypt/ to libxenon
This commit is contained in:
parent
0ad668cfea
commit
80adf883d4
@ -17,7 +17,7 @@ include $(DEVKITXENON)/rules
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := stage2
|
||||
BUILD := build
|
||||
SOURCES := source/lv2 source/lv2/crypt source/lv2/xb360 source/lv2/tftp source/lv2/httpd source/lv2/linux source/lv2/kboot
|
||||
SOURCES := source/lv2 source/lv2/tftp source/lv2/httpd source/lv2/linux source/lv2/kboot
|
||||
DATA := data
|
||||
INCLUDES := source/lv2
|
||||
|
||||
|
@ -1,747 +0,0 @@
|
||||
/*
|
||||
* FIPS-46-3 compliant Triple-DES implementation
|
||||
*
|
||||
* Copyright (C) 2006-2007 Christophe Devine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License, version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* DES, on which TDES is based, was originally designed by Hans Feistel
|
||||
* at IBM in 1974, and was adopted as a standard by NIST (formerly NBS).
|
||||
*
|
||||
* http://csrc.nist.gov/publications/fips/fips46-3/fips46-3.pdf
|
||||
*/
|
||||
|
||||
//#include "xyssl/config.h"
|
||||
|
||||
#define XYSSL_DES_C
|
||||
|
||||
#if defined(XYSSL_DES_C)
|
||||
|
||||
#include "des.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (big endian)
|
||||
*/
|
||||
#ifndef GET_ULONG_BE
|
||||
#define GET_ULONG_BE(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (unsigned long) (b)[(i) ] << 24 ) \
|
||||
| ( (unsigned long) (b)[(i) + 1] << 16 ) \
|
||||
| ( (unsigned long) (b)[(i) + 2] << 8 ) \
|
||||
| ( (unsigned long) (b)[(i) + 3] ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_ULONG_BE
|
||||
#define PUT_ULONG_BE(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Expanded DES S-boxes
|
||||
*/
|
||||
static const unsigned long SB1[64] =
|
||||
{
|
||||
0x01010400, 0x00000000, 0x00010000, 0x01010404,
|
||||
0x01010004, 0x00010404, 0x00000004, 0x00010000,
|
||||
0x00000400, 0x01010400, 0x01010404, 0x00000400,
|
||||
0x01000404, 0x01010004, 0x01000000, 0x00000004,
|
||||
0x00000404, 0x01000400, 0x01000400, 0x00010400,
|
||||
0x00010400, 0x01010000, 0x01010000, 0x01000404,
|
||||
0x00010004, 0x01000004, 0x01000004, 0x00010004,
|
||||
0x00000000, 0x00000404, 0x00010404, 0x01000000,
|
||||
0x00010000, 0x01010404, 0x00000004, 0x01010000,
|
||||
0x01010400, 0x01000000, 0x01000000, 0x00000400,
|
||||
0x01010004, 0x00010000, 0x00010400, 0x01000004,
|
||||
0x00000400, 0x00000004, 0x01000404, 0x00010404,
|
||||
0x01010404, 0x00010004, 0x01010000, 0x01000404,
|
||||
0x01000004, 0x00000404, 0x00010404, 0x01010400,
|
||||
0x00000404, 0x01000400, 0x01000400, 0x00000000,
|
||||
0x00010004, 0x00010400, 0x00000000, 0x01010004
|
||||
};
|
||||
|
||||
static const unsigned long SB2[64] =
|
||||
{
|
||||
0x80108020, 0x80008000, 0x00008000, 0x00108020,
|
||||
0x00100000, 0x00000020, 0x80100020, 0x80008020,
|
||||
0x80000020, 0x80108020, 0x80108000, 0x80000000,
|
||||
0x80008000, 0x00100000, 0x00000020, 0x80100020,
|
||||
0x00108000, 0x00100020, 0x80008020, 0x00000000,
|
||||
0x80000000, 0x00008000, 0x00108020, 0x80100000,
|
||||
0x00100020, 0x80000020, 0x00000000, 0x00108000,
|
||||
0x00008020, 0x80108000, 0x80100000, 0x00008020,
|
||||
0x00000000, 0x00108020, 0x80100020, 0x00100000,
|
||||
0x80008020, 0x80100000, 0x80108000, 0x00008000,
|
||||
0x80100000, 0x80008000, 0x00000020, 0x80108020,
|
||||
0x00108020, 0x00000020, 0x00008000, 0x80000000,
|
||||
0x00008020, 0x80108000, 0x00100000, 0x80000020,
|
||||
0x00100020, 0x80008020, 0x80000020, 0x00100020,
|
||||
0x00108000, 0x00000000, 0x80008000, 0x00008020,
|
||||
0x80000000, 0x80100020, 0x80108020, 0x00108000
|
||||
};
|
||||
|
||||
static const unsigned long SB3[64] =
|
||||
{
|
||||
0x00000208, 0x08020200, 0x00000000, 0x08020008,
|
||||
0x08000200, 0x00000000, 0x00020208, 0x08000200,
|
||||
0x00020008, 0x08000008, 0x08000008, 0x00020000,
|
||||
0x08020208, 0x00020008, 0x08020000, 0x00000208,
|
||||
0x08000000, 0x00000008, 0x08020200, 0x00000200,
|
||||
0x00020200, 0x08020000, 0x08020008, 0x00020208,
|
||||
0x08000208, 0x00020200, 0x00020000, 0x08000208,
|
||||
0x00000008, 0x08020208, 0x00000200, 0x08000000,
|
||||
0x08020200, 0x08000000, 0x00020008, 0x00000208,
|
||||
0x00020000, 0x08020200, 0x08000200, 0x00000000,
|
||||
0x00000200, 0x00020008, 0x08020208, 0x08000200,
|
||||
0x08000008, 0x00000200, 0x00000000, 0x08020008,
|
||||
0x08000208, 0x00020000, 0x08000000, 0x08020208,
|
||||
0x00000008, 0x00020208, 0x00020200, 0x08000008,
|
||||
0x08020000, 0x08000208, 0x00000208, 0x08020000,
|
||||
0x00020208, 0x00000008, 0x08020008, 0x00020200
|
||||
};
|
||||
|
||||
static const unsigned long SB4[64] =
|
||||
{
|
||||
0x00802001, 0x00002081, 0x00002081, 0x00000080,
|
||||
0x00802080, 0x00800081, 0x00800001, 0x00002001,
|
||||
0x00000000, 0x00802000, 0x00802000, 0x00802081,
|
||||
0x00000081, 0x00000000, 0x00800080, 0x00800001,
|
||||
0x00000001, 0x00002000, 0x00800000, 0x00802001,
|
||||
0x00000080, 0x00800000, 0x00002001, 0x00002080,
|
||||
0x00800081, 0x00000001, 0x00002080, 0x00800080,
|
||||
0x00002000, 0x00802080, 0x00802081, 0x00000081,
|
||||
0x00800080, 0x00800001, 0x00802000, 0x00802081,
|
||||
0x00000081, 0x00000000, 0x00000000, 0x00802000,
|
||||
0x00002080, 0x00800080, 0x00800081, 0x00000001,
|
||||
0x00802001, 0x00002081, 0x00002081, 0x00000080,
|
||||
0x00802081, 0x00000081, 0x00000001, 0x00002000,
|
||||
0x00800001, 0x00002001, 0x00802080, 0x00800081,
|
||||
0x00002001, 0x00002080, 0x00800000, 0x00802001,
|
||||
0x00000080, 0x00800000, 0x00002000, 0x00802080
|
||||
};
|
||||
|
||||
static const unsigned long SB5[64] =
|
||||
{
|
||||
0x00000100, 0x02080100, 0x02080000, 0x42000100,
|
||||
0x00080000, 0x00000100, 0x40000000, 0x02080000,
|
||||
0x40080100, 0x00080000, 0x02000100, 0x40080100,
|
||||
0x42000100, 0x42080000, 0x00080100, 0x40000000,
|
||||
0x02000000, 0x40080000, 0x40080000, 0x00000000,
|
||||
0x40000100, 0x42080100, 0x42080100, 0x02000100,
|
||||
0x42080000, 0x40000100, 0x00000000, 0x42000000,
|
||||
0x02080100, 0x02000000, 0x42000000, 0x00080100,
|
||||
0x00080000, 0x42000100, 0x00000100, 0x02000000,
|
||||
0x40000000, 0x02080000, 0x42000100, 0x40080100,
|
||||
0x02000100, 0x40000000, 0x42080000, 0x02080100,
|
||||
0x40080100, 0x00000100, 0x02000000, 0x42080000,
|
||||
0x42080100, 0x00080100, 0x42000000, 0x42080100,
|
||||
0x02080000, 0x00000000, 0x40080000, 0x42000000,
|
||||
0x00080100, 0x02000100, 0x40000100, 0x00080000,
|
||||
0x00000000, 0x40080000, 0x02080100, 0x40000100
|
||||
};
|
||||
|
||||
static const unsigned long SB6[64] =
|
||||
{
|
||||
0x20000010, 0x20400000, 0x00004000, 0x20404010,
|
||||
0x20400000, 0x00000010, 0x20404010, 0x00400000,
|
||||
0x20004000, 0x00404010, 0x00400000, 0x20000010,
|
||||
0x00400010, 0x20004000, 0x20000000, 0x00004010,
|
||||
0x00000000, 0x00400010, 0x20004010, 0x00004000,
|
||||
0x00404000, 0x20004010, 0x00000010, 0x20400010,
|
||||
0x20400010, 0x00000000, 0x00404010, 0x20404000,
|
||||
0x00004010, 0x00404000, 0x20404000, 0x20000000,
|
||||
0x20004000, 0x00000010, 0x20400010, 0x00404000,
|
||||
0x20404010, 0x00400000, 0x00004010, 0x20000010,
|
||||
0x00400000, 0x20004000, 0x20000000, 0x00004010,
|
||||
0x20000010, 0x20404010, 0x00404000, 0x20400000,
|
||||
0x00404010, 0x20404000, 0x00000000, 0x20400010,
|
||||
0x00000010, 0x00004000, 0x20400000, 0x00404010,
|
||||
0x00004000, 0x00400010, 0x20004010, 0x00000000,
|
||||
0x20404000, 0x20000000, 0x00400010, 0x20004010
|
||||
};
|
||||
|
||||
static const unsigned long SB7[64] =
|
||||
{
|
||||
0x00200000, 0x04200002, 0x04000802, 0x00000000,
|
||||
0x00000800, 0x04000802, 0x00200802, 0x04200800,
|
||||
0x04200802, 0x00200000, 0x00000000, 0x04000002,
|
||||
0x00000002, 0x04000000, 0x04200002, 0x00000802,
|
||||
0x04000800, 0x00200802, 0x00200002, 0x04000800,
|
||||
0x04000002, 0x04200000, 0x04200800, 0x00200002,
|
||||
0x04200000, 0x00000800, 0x00000802, 0x04200802,
|
||||
0x00200800, 0x00000002, 0x04000000, 0x00200800,
|
||||
0x04000000, 0x00200800, 0x00200000, 0x04000802,
|
||||
0x04000802, 0x04200002, 0x04200002, 0x00000002,
|
||||
0x00200002, 0x04000000, 0x04000800, 0x00200000,
|
||||
0x04200800, 0x00000802, 0x00200802, 0x04200800,
|
||||
0x00000802, 0x04000002, 0x04200802, 0x04200000,
|
||||
0x00200800, 0x00000000, 0x00000002, 0x04200802,
|
||||
0x00000000, 0x00200802, 0x04200000, 0x00000800,
|
||||
0x04000002, 0x04000800, 0x00000800, 0x00200002
|
||||
};
|
||||
|
||||
static const unsigned long SB8[64] =
|
||||
{
|
||||
0x10001040, 0x00001000, 0x00040000, 0x10041040,
|
||||
0x10000000, 0x10001040, 0x00000040, 0x10000000,
|
||||
0x00040040, 0x10040000, 0x10041040, 0x00041000,
|
||||
0x10041000, 0x00041040, 0x00001000, 0x00000040,
|
||||
0x10040000, 0x10000040, 0x10001000, 0x00001040,
|
||||
0x00041000, 0x00040040, 0x10040040, 0x10041000,
|
||||
0x00001040, 0x00000000, 0x00000000, 0x10040040,
|
||||
0x10000040, 0x10001000, 0x00041040, 0x00040000,
|
||||
0x00041040, 0x00040000, 0x10041000, 0x00001000,
|
||||
0x00000040, 0x10040040, 0x00001000, 0x00041040,
|
||||
0x10001000, 0x00000040, 0x10000040, 0x10040000,
|
||||
0x10040040, 0x10000000, 0x00040000, 0x10001040,
|
||||
0x00000000, 0x10041040, 0x00040040, 0x10000040,
|
||||
0x10040000, 0x10001000, 0x10001040, 0x00000000,
|
||||
0x10041040, 0x00041000, 0x00041000, 0x00001040,
|
||||
0x00001040, 0x00040040, 0x10000000, 0x10041000
|
||||
};
|
||||
|
||||
/*
|
||||
* PC1: left and right halves bit-swap
|
||||
*/
|
||||
static const unsigned long LHs[16] =
|
||||
{
|
||||
0x00000000, 0x00000001, 0x00000100, 0x00000101,
|
||||
0x00010000, 0x00010001, 0x00010100, 0x00010101,
|
||||
0x01000000, 0x01000001, 0x01000100, 0x01000101,
|
||||
0x01010000, 0x01010001, 0x01010100, 0x01010101
|
||||
};
|
||||
|
||||
static const unsigned long RHs[16] =
|
||||
{
|
||||
0x00000000, 0x01000000, 0x00010000, 0x01010000,
|
||||
0x00000100, 0x01000100, 0x00010100, 0x01010100,
|
||||
0x00000001, 0x01000001, 0x00010001, 0x01010001,
|
||||
0x00000101, 0x01000101, 0x00010101, 0x01010101,
|
||||
};
|
||||
|
||||
/*
|
||||
* Initial Permutation macro
|
||||
*/
|
||||
#define DES_IP(X,Y) \
|
||||
{ \
|
||||
T = ((X >> 4) ^ Y) & 0x0F0F0F0F; Y ^= T; X ^= (T << 4); \
|
||||
T = ((X >> 16) ^ Y) & 0x0000FFFF; Y ^= T; X ^= (T << 16); \
|
||||
T = ((Y >> 2) ^ X) & 0x33333333; X ^= T; Y ^= (T << 2); \
|
||||
T = ((Y >> 8) ^ X) & 0x00FF00FF; X ^= T; Y ^= (T << 8); \
|
||||
Y = ((Y << 1) | (Y >> 31)) & 0xFFFFFFFF; \
|
||||
T = (X ^ Y) & 0xAAAAAAAA; Y ^= T; X ^= T; \
|
||||
X = ((X << 1) | (X >> 31)) & 0xFFFFFFFF; \
|
||||
}
|
||||
|
||||
/*
|
||||
* Final Permutation macro
|
||||
*/
|
||||
#define DES_FP(X,Y) \
|
||||
{ \
|
||||
X = ((X << 31) | (X >> 1)) & 0xFFFFFFFF; \
|
||||
T = (X ^ Y) & 0xAAAAAAAA; X ^= T; Y ^= T; \
|
||||
Y = ((Y << 31) | (Y >> 1)) & 0xFFFFFFFF; \
|
||||
T = ((Y >> 8) ^ X) & 0x00FF00FF; X ^= T; Y ^= (T << 8); \
|
||||
T = ((Y >> 2) ^ X) & 0x33333333; X ^= T; Y ^= (T << 2); \
|
||||
T = ((X >> 16) ^ Y) & 0x0000FFFF; Y ^= T; X ^= (T << 16); \
|
||||
T = ((X >> 4) ^ Y) & 0x0F0F0F0F; Y ^= T; X ^= (T << 4); \
|
||||
}
|
||||
|
||||
/*
|
||||
* DES round macro
|
||||
*/
|
||||
#define DES_ROUND(X,Y) \
|
||||
{ \
|
||||
T = *SK++ ^ X; \
|
||||
Y ^= SB8[ (T ) & 0x3F ] ^ \
|
||||
SB6[ (T >> 8) & 0x3F ] ^ \
|
||||
SB4[ (T >> 16) & 0x3F ] ^ \
|
||||
SB2[ (T >> 24) & 0x3F ]; \
|
||||
\
|
||||
T = *SK++ ^ ((X << 28) | (X >> 4)); \
|
||||
Y ^= SB7[ (T ) & 0x3F ] ^ \
|
||||
SB5[ (T >> 8) & 0x3F ] ^ \
|
||||
SB3[ (T >> 16) & 0x3F ] ^ \
|
||||
SB1[ (T >> 24) & 0x3F ]; \
|
||||
}
|
||||
|
||||
#define SWAP(a,b) { unsigned long t = a; a = b; b = t; t = 0; }
|
||||
|
||||
static void des_setkey( unsigned long SK[32], unsigned char key[8] )
|
||||
{
|
||||
int i;
|
||||
unsigned long X, Y, T;
|
||||
|
||||
GET_ULONG_BE( X, key, 0 );
|
||||
GET_ULONG_BE( Y, key, 4 );
|
||||
|
||||
/*
|
||||
* Permuted Choice 1
|
||||
*/
|
||||
T = ((Y >> 4) ^ X) & 0x0F0F0F0F; X ^= T; Y ^= (T << 4);
|
||||
T = ((Y ) ^ X) & 0x10101010; X ^= T; Y ^= (T );
|
||||
|
||||
X = (LHs[ (X ) & 0xF] << 3) | (LHs[ (X >> 8) & 0xF ] << 2)
|
||||
| (LHs[ (X >> 16) & 0xF] << 1) | (LHs[ (X >> 24) & 0xF ] )
|
||||
| (LHs[ (X >> 5) & 0xF] << 7) | (LHs[ (X >> 13) & 0xF ] << 6)
|
||||
| (LHs[ (X >> 21) & 0xF] << 5) | (LHs[ (X >> 29) & 0xF ] << 4);
|
||||
|
||||
Y = (RHs[ (Y >> 1) & 0xF] << 3) | (RHs[ (Y >> 9) & 0xF ] << 2)
|
||||
| (RHs[ (Y >> 17) & 0xF] << 1) | (RHs[ (Y >> 25) & 0xF ] )
|
||||
| (RHs[ (Y >> 4) & 0xF] << 7) | (RHs[ (Y >> 12) & 0xF ] << 6)
|
||||
| (RHs[ (Y >> 20) & 0xF] << 5) | (RHs[ (Y >> 28) & 0xF ] << 4);
|
||||
|
||||
X &= 0x0FFFFFFF;
|
||||
Y &= 0x0FFFFFFF;
|
||||
|
||||
/*
|
||||
* calculate subkeys
|
||||
*/
|
||||
for( i = 0; i < 16; i++ )
|
||||
{
|
||||
if( i < 2 || i == 8 || i == 15 )
|
||||
{
|
||||
X = ((X << 1) | (X >> 27)) & 0x0FFFFFFF;
|
||||
Y = ((Y << 1) | (Y >> 27)) & 0x0FFFFFFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
X = ((X << 2) | (X >> 26)) & 0x0FFFFFFF;
|
||||
Y = ((Y << 2) | (Y >> 26)) & 0x0FFFFFFF;
|
||||
}
|
||||
|
||||
*SK++ = ((X << 4) & 0x24000000) | ((X << 28) & 0x10000000)
|
||||
| ((X << 14) & 0x08000000) | ((X << 18) & 0x02080000)
|
||||
| ((X << 6) & 0x01000000) | ((X << 9) & 0x00200000)
|
||||
| ((X >> 1) & 0x00100000) | ((X << 10) & 0x00040000)
|
||||
| ((X << 2) & 0x00020000) | ((X >> 10) & 0x00010000)
|
||||
| ((Y >> 13) & 0x00002000) | ((Y >> 4) & 0x00001000)
|
||||
| ((Y << 6) & 0x00000800) | ((Y >> 1) & 0x00000400)
|
||||
| ((Y >> 14) & 0x00000200) | ((Y ) & 0x00000100)
|
||||
| ((Y >> 5) & 0x00000020) | ((Y >> 10) & 0x00000010)
|
||||
| ((Y >> 3) & 0x00000008) | ((Y >> 18) & 0x00000004)
|
||||
| ((Y >> 26) & 0x00000002) | ((Y >> 24) & 0x00000001);
|
||||
|
||||
*SK++ = ((X << 15) & 0x20000000) | ((X << 17) & 0x10000000)
|
||||
| ((X << 10) & 0x08000000) | ((X << 22) & 0x04000000)
|
||||
| ((X >> 2) & 0x02000000) | ((X << 1) & 0x01000000)
|
||||
| ((X << 16) & 0x00200000) | ((X << 11) & 0x00100000)
|
||||
| ((X << 3) & 0x00080000) | ((X >> 6) & 0x00040000)
|
||||
| ((X << 15) & 0x00020000) | ((X >> 4) & 0x00010000)
|
||||
| ((Y >> 2) & 0x00002000) | ((Y << 8) & 0x00001000)
|
||||
| ((Y >> 14) & 0x00000808) | ((Y >> 9) & 0x00000400)
|
||||
| ((Y ) & 0x00000200) | ((Y << 7) & 0x00000100)
|
||||
| ((Y >> 7) & 0x00000020) | ((Y >> 3) & 0x00000011)
|
||||
| ((Y << 2) & 0x00000004) | ((Y >> 21) & 0x00000002);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* DES key schedule (56-bit, encryption)
|
||||
*/
|
||||
void des_setkey_enc( des_context *ctx, unsigned char key[8] )
|
||||
{
|
||||
des_setkey( ctx->sk, key );
|
||||
}
|
||||
|
||||
/*
|
||||
* DES key schedule (56-bit, decryption)
|
||||
*/
|
||||
void des_setkey_dec( des_context *ctx, unsigned char key[8] )
|
||||
{
|
||||
int i;
|
||||
|
||||
des_setkey( ctx->sk, key );
|
||||
|
||||
for( i = 0; i < 16; i += 2 )
|
||||
{
|
||||
SWAP( ctx->sk[i ], ctx->sk[30 - i] );
|
||||
SWAP( ctx->sk[i + 1], ctx->sk[31 - i] );
|
||||
}
|
||||
}
|
||||
|
||||
static void des3_set2key( unsigned long esk[96],
|
||||
unsigned long dsk[96],
|
||||
unsigned char key[16] )
|
||||
{
|
||||
int i;
|
||||
|
||||
des_setkey( esk, key );
|
||||
des_setkey( dsk + 32, key + 8 );
|
||||
|
||||
for( i = 0; i < 32; i += 2 )
|
||||
{
|
||||
dsk[i ] = esk[30 - i];
|
||||
dsk[i + 1] = esk[31 - i];
|
||||
|
||||
esk[i + 32] = dsk[62 - i];
|
||||
esk[i + 33] = dsk[63 - i];
|
||||
|
||||
esk[i + 64] = esk[i ];
|
||||
esk[i + 65] = esk[i + 1];
|
||||
|
||||
dsk[i + 64] = dsk[i ];
|
||||
dsk[i + 65] = dsk[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Triple-DES key schedule (112-bit, encryption)
|
||||
*/
|
||||
void des3_set2key_enc( des3_context *ctx, unsigned char key[16] )
|
||||
{
|
||||
unsigned long sk[96];
|
||||
|
||||
des3_set2key( ctx->sk, sk, key );
|
||||
memset( sk, 0, sizeof( sk ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Triple-DES key schedule (112-bit, decryption)
|
||||
*/
|
||||
void des3_set2key_dec( des3_context *ctx, unsigned char key[16] )
|
||||
{
|
||||
unsigned long sk[96];
|
||||
|
||||
des3_set2key( sk, ctx->sk, key );
|
||||
memset( sk, 0, sizeof( sk ) );
|
||||
}
|
||||
|
||||
static void des3_set3key( unsigned long esk[96],
|
||||
unsigned long dsk[96],
|
||||
unsigned char key[24] )
|
||||
{
|
||||
int i;
|
||||
|
||||
des_setkey( esk, key );
|
||||
des_setkey( dsk + 32, key + 8 );
|
||||
des_setkey( esk + 64, key + 16 );
|
||||
|
||||
for( i = 0; i < 32; i += 2 )
|
||||
{
|
||||
dsk[i ] = esk[94 - i];
|
||||
dsk[i + 1] = esk[95 - i];
|
||||
|
||||
esk[i + 32] = dsk[62 - i];
|
||||
esk[i + 33] = dsk[63 - i];
|
||||
|
||||
dsk[i + 64] = esk[30 - i];
|
||||
dsk[i + 65] = esk[31 - i];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Triple-DES key schedule (168-bit, encryption)
|
||||
*/
|
||||
void des3_set3key_enc( des3_context *ctx, unsigned char key[24] )
|
||||
{
|
||||
unsigned long sk[96];
|
||||
|
||||
des3_set3key( ctx->sk, sk, key );
|
||||
memset( sk, 0, sizeof( sk ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Triple-DES key schedule (168-bit, decryption)
|
||||
*/
|
||||
void des3_set3key_dec( des3_context *ctx, unsigned char key[24] )
|
||||
{
|
||||
unsigned long sk[96];
|
||||
|
||||
des3_set3key( sk, ctx->sk, key );
|
||||
memset( sk, 0, sizeof( sk ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* DES-ECB block encryption/decryption
|
||||
*/
|
||||
void des_crypt_ecb( des_context *ctx,
|
||||
unsigned char input[8],
|
||||
unsigned char output[8] )
|
||||
{
|
||||
int i;
|
||||
unsigned long X, Y, T, *SK;
|
||||
|
||||
SK = ctx->sk;
|
||||
|
||||
GET_ULONG_BE( X, input, 0 );
|
||||
GET_ULONG_BE( Y, input, 4 );
|
||||
|
||||
DES_IP( X, Y );
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
DES_ROUND( Y, X );
|
||||
DES_ROUND( X, Y );
|
||||
}
|
||||
|
||||
DES_FP( Y, X );
|
||||
|
||||
PUT_ULONG_BE( Y, output, 0 );
|
||||
PUT_ULONG_BE( X, output, 4 );
|
||||
}
|
||||
|
||||
/*
|
||||
* DES-CBC buffer encryption/decryption
|
||||
*/
|
||||
void des_crypt_cbc( des_context *ctx,
|
||||
int mode,
|
||||
int length,
|
||||
unsigned char iv[8],
|
||||
unsigned char *input,
|
||||
unsigned char *output )
|
||||
{
|
||||
int i;
|
||||
unsigned char temp[8];
|
||||
|
||||
if( mode == DES_ENCRYPT )
|
||||
{
|
||||
while( length > 0 )
|
||||
{
|
||||
for( i = 0; i < 8; i++ )
|
||||
output[i] = (unsigned char)( input[i] ^ iv[i] );
|
||||
|
||||
des_crypt_ecb( ctx, output, output );
|
||||
memcpy( iv, output, 8 );
|
||||
|
||||
input += 8;
|
||||
output += 8;
|
||||
length -= 8;
|
||||
}
|
||||
}
|
||||
else /* DES_DECRYPT */
|
||||
{
|
||||
while( length > 0 )
|
||||
{
|
||||
memcpy( temp, input, 8 );
|
||||
des_crypt_ecb( ctx, input, output );
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
output[i] = (unsigned char)( output[i] ^ iv[i] );
|
||||
|
||||
memcpy( iv, temp, 8 );
|
||||
|
||||
input += 8;
|
||||
output += 8;
|
||||
length -= 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 3DES-ECB block encryption/decryption
|
||||
*/
|
||||
void des3_crypt_ecb( des3_context *ctx,
|
||||
unsigned char input[8],
|
||||
unsigned char output[8] )
|
||||
{
|
||||
int i;
|
||||
unsigned long X, Y, T, *SK;
|
||||
|
||||
SK = ctx->sk;
|
||||
|
||||
GET_ULONG_BE( X, input, 0 );
|
||||
GET_ULONG_BE( Y, input, 4 );
|
||||
|
||||
DES_IP( X, Y );
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
DES_ROUND( Y, X );
|
||||
DES_ROUND( X, Y );
|
||||
}
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
DES_ROUND( X, Y );
|
||||
DES_ROUND( Y, X );
|
||||
}
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
DES_ROUND( Y, X );
|
||||
DES_ROUND( X, Y );
|
||||
}
|
||||
|
||||
DES_FP( Y, X );
|
||||
|
||||
PUT_ULONG_BE( Y, output, 0 );
|
||||
PUT_ULONG_BE( X, output, 4 );
|
||||
}
|
||||
|
||||
/*
|
||||
* 3DES-CBC buffer encryption/decryption
|
||||
*/
|
||||
void des3_crypt_cbc( des3_context *ctx,
|
||||
int mode,
|
||||
int length,
|
||||
unsigned char iv[8],
|
||||
unsigned char *input,
|
||||
unsigned char *output )
|
||||
{
|
||||
int i;
|
||||
unsigned char temp[8];
|
||||
|
||||
if( mode == DES_ENCRYPT )
|
||||
{
|
||||
while( length > 0 )
|
||||
{
|
||||
for( i = 0; i < 8; i++ )
|
||||
output[i] = (unsigned char)( input[i] ^ iv[i] );
|
||||
|
||||
des3_crypt_ecb( ctx, output, output );
|
||||
memcpy( iv, output, 8 );
|
||||
|
||||
input += 8;
|
||||
output += 8;
|
||||
length -= 8;
|
||||
}
|
||||
}
|
||||
else /* DES_DECRYPT */
|
||||
{
|
||||
while( length > 0 )
|
||||
{
|
||||
memcpy( temp, input, 8 );
|
||||
des3_crypt_ecb( ctx, input, output );
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
output[i] = (unsigned char)( output[i] ^ iv[i] );
|
||||
|
||||
memcpy( iv, temp, 8 );
|
||||
|
||||
input += 8;
|
||||
output += 8;
|
||||
length -= 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(XYSSL_SELF_TEST)
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* DES/3DES test vectors (source: NIST, tripledes-vectors.zip)
|
||||
*/
|
||||
static const unsigned char DES3_keys[24] =
|
||||
{
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
|
||||
0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
|
||||
0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23
|
||||
};
|
||||
|
||||
static const unsigned char DES3_init[8] =
|
||||
{
|
||||
0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74
|
||||
};
|
||||
|
||||
static const unsigned char DES3_enc_test[3][8] =
|
||||
{
|
||||
{ 0x6A, 0x2A, 0x19, 0xF4, 0x1E, 0xCA, 0x85, 0x4B },
|
||||
{ 0x03, 0xE6, 0x9F, 0x5B, 0xFA, 0x58, 0xEB, 0x42 },
|
||||
{ 0xDD, 0x17, 0xE8, 0xB8, 0xB4, 0x37, 0xD2, 0x32 }
|
||||
};
|
||||
|
||||
static const unsigned char DES3_dec_test[3][8] =
|
||||
{
|
||||
{ 0xCD, 0xD6, 0x4F, 0x2F, 0x94, 0x27, 0xC1, 0x5D },
|
||||
{ 0x69, 0x96, 0xC8, 0xFA, 0x47, 0xA2, 0xAB, 0xEB },
|
||||
{ 0x83, 0x25, 0x39, 0x76, 0x44, 0x09, 0x1A, 0x0A }
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int des_self_test( int verbose )
|
||||
{
|
||||
int i, j, u, v;
|
||||
des_context ctx;
|
||||
des3_context ctx3;
|
||||
unsigned char buf[8];
|
||||
|
||||
for( i = 0; i < 6; i++ )
|
||||
{
|
||||
u = i >> 1;
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " DES%c-ECB-%3d (%s): ",
|
||||
( u == 0 ) ? ' ' : '3', 56 + u * 56,
|
||||
( v == 0 ) ? "enc" : "dec" );
|
||||
|
||||
memcpy( buf, DES3_init, 8 );
|
||||
|
||||
switch( u )
|
||||
{
|
||||
case 0:
|
||||
if( v == 0 )
|
||||
des_setkey_enc( &ctx, (unsigned char *) DES3_keys );
|
||||
if( v == 1 )
|
||||
des_setkey_dec( &ctx, (unsigned char *) DES3_keys );
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if( v == 0 )
|
||||
des3_set2key_enc( &ctx3, (unsigned char *) DES3_keys );
|
||||
if( v == 1 )
|
||||
des3_set2key_dec( &ctx3, (unsigned char *) DES3_keys );
|
||||
break;
|
||||
|
||||
default:
|
||||
if( v == 0 )
|
||||
des3_set3key_enc( &ctx3, (unsigned char *) DES3_keys );
|
||||
if( v == 1 )
|
||||
des3_set3key_dec( &ctx3, (unsigned char *) DES3_keys );
|
||||
break;
|
||||
}
|
||||
|
||||
for( j = 0; j < 10000; j++ )
|
||||
{
|
||||
if( u == 0 )
|
||||
des_crypt_ecb( &ctx, buf, buf );
|
||||
else
|
||||
des3_crypt_ecb( &ctx3, buf, buf );
|
||||
}
|
||||
|
||||
if( ( v == 0 && memcmp( buf, DES3_enc_test[u], 8 ) != 0 ) ||
|
||||
( v == 1 && memcmp( buf, DES3_dec_test[u], 8 ) != 0 ) )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,149 +0,0 @@
|
||||
/**
|
||||
* \file des.h
|
||||
*/
|
||||
#ifndef XYSSL_DES_H
|
||||
#define XYSSL_DES_H
|
||||
|
||||
#define DES_ENCRYPT 0
|
||||
#define DES_DECRYPT 1
|
||||
|
||||
/**
|
||||
* \brief DES context structure
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int mode; /*!< encrypt/decrypt */
|
||||
unsigned long sk[32]; /*!< DES subkeys */
|
||||
}
|
||||
des_context;
|
||||
|
||||
/**
|
||||
* \brief Triple-DES context structure
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int mode; /*!< encrypt/decrypt */
|
||||
unsigned long sk[96]; /*!< 3DES subkeys */
|
||||
}
|
||||
des3_context;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief DES key schedule (56-bit, encryption)
|
||||
*
|
||||
* \param ctx DES context to be initialized
|
||||
* \param key 8-byte secret key
|
||||
*/
|
||||
void des_setkey_enc( des_context *ctx, unsigned char key[8] );
|
||||
|
||||
/**
|
||||
* \brief DES key schedule (56-bit, decryption)
|
||||
*
|
||||
* \param ctx DES context to be initialized
|
||||
* \param key 8-byte secret key
|
||||
*/
|
||||
void des_setkey_dec( des_context *ctx, unsigned char key[8] );
|
||||
|
||||
/**
|
||||
* \brief Triple-DES key schedule (112-bit, encryption)
|
||||
*
|
||||
* \param ctx 3DES context to be initialized
|
||||
* \param key 16-byte secret key
|
||||
*/
|
||||
void des3_set2key_enc( des3_context *ctx, unsigned char key[16] );
|
||||
|
||||
/**
|
||||
* \brief Triple-DES key schedule (112-bit, decryption)
|
||||
*
|
||||
* \param ctx 3DES context to be initialized
|
||||
* \param key 16-byte secret key
|
||||
*/
|
||||
void des3_set2key_dec( des3_context *ctx, unsigned char key[16] );
|
||||
|
||||
/**
|
||||
* \brief Triple-DES key schedule (168-bit, encryption)
|
||||
*
|
||||
* \param ctx 3DES context to be initialized
|
||||
* \param key 24-byte secret key
|
||||
*/
|
||||
void des3_set3key_enc( des3_context *ctx, unsigned char key[24] );
|
||||
|
||||
/**
|
||||
* \brief Triple-DES key schedule (168-bit, decryption)
|
||||
*
|
||||
* \param ctx 3DES context to be initialized
|
||||
* \param key 24-byte secret key
|
||||
*/
|
||||
void des3_set3key_dec( des3_context *ctx, unsigned char key[24] );
|
||||
|
||||
/**
|
||||
* \brief DES-ECB block encryption/decryption
|
||||
*
|
||||
* \param ctx DES context
|
||||
* \param input 64-bit input block
|
||||
* \param output 64-bit output block
|
||||
*/
|
||||
void des_crypt_ecb( des_context *ctx,
|
||||
unsigned char input[8],
|
||||
unsigned char output[8] );
|
||||
|
||||
/**
|
||||
* \brief DES-CBC buffer encryption/decryption
|
||||
*
|
||||
* \param ctx DES context
|
||||
* \param mode DES_ENCRYPT or DES_DECRYPT
|
||||
* \param length length of the input data
|
||||
* \param iv initialization vector (updated after use)
|
||||
* \param input buffer holding the input data
|
||||
* \param output buffer holding the output data
|
||||
*/
|
||||
void des_crypt_cbc( des_context *ctx,
|
||||
int mode,
|
||||
int length,
|
||||
unsigned char iv[8],
|
||||
unsigned char *input,
|
||||
unsigned char *output );
|
||||
|
||||
/**
|
||||
* \brief 3DES-ECB block encryption/decryption
|
||||
*
|
||||
* \param ctx 3DES context
|
||||
* \param input 64-bit input block
|
||||
* \param output 64-bit output block
|
||||
*/
|
||||
void des3_crypt_ecb( des3_context *ctx,
|
||||
unsigned char input[8],
|
||||
unsigned char output[8] );
|
||||
|
||||
/**
|
||||
* \brief 3DES-CBC buffer encryption/decryption
|
||||
*
|
||||
* \param ctx 3DES context
|
||||
* \param mode DES_ENCRYPT or DES_DECRYPT
|
||||
* \param length length of the input data
|
||||
* \param iv initialization vector (updated after use)
|
||||
* \param input buffer holding the input data
|
||||
* \param output buffer holding the output data
|
||||
*/
|
||||
void des3_crypt_cbc( des3_context *ctx,
|
||||
int mode,
|
||||
int length,
|
||||
unsigned char iv[8],
|
||||
unsigned char *input,
|
||||
unsigned char *output );
|
||||
|
||||
/*
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*/
|
||||
int des_self_test( int verbose );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* des.h */
|
@ -1,208 +0,0 @@
|
||||
/*
|
||||
* hmac_sha1.c
|
||||
*
|
||||
* Version 1.0.0
|
||||
*
|
||||
* Written by Aaron D. Gifford <me@aarongifford.com>
|
||||
*
|
||||
* Copyright 1998, 2000 Aaron D. Gifford. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The HMAC-SHA1 has is defined as:
|
||||
*
|
||||
* HMAC = SHA1(K XOR opad, SHA1(K XOR ipad, message))
|
||||
*
|
||||
* "opad" is 64 bytes filled with 0x5c
|
||||
* "ipad" is 64 bytes filled with 0x36
|
||||
* "K" is the key material
|
||||
*
|
||||
* If the key material "K" is longer than 64 bytes, then the key material
|
||||
* will first be digested (K = SHA1(K)) resulting in a 20-byte hash.
|
||||
* If the key material is shorter than 64 bytes, it is padded with zero
|
||||
* bytes.
|
||||
*
|
||||
* This code precomputes "K XOR ipad" and "K XOR opad" since that just makes
|
||||
* sense.
|
||||
*
|
||||
* This code was heavily influenced by Eric A. Young's in how the interface
|
||||
* was designed and how this file is formatted.
|
||||
*/
|
||||
|
||||
#ifndef __HMAC_SHA1_H__
|
||||
#define __HMAC_SHA1_H__
|
||||
|
||||
#include "hmac_sha1.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Filler bytes: */
|
||||
#define IPAD_BYTE 0x36
|
||||
#define OPAD_BYTE 0x5c
|
||||
#define ZERO_BYTE 0x00
|
||||
|
||||
void HMAC_SHA1_Init(HMAC_SHA1_CTX *ctx) {
|
||||
memset(&(ctx->key[0]), ZERO_BYTE, HMAC_SHA1_BLOCK_LENGTH);
|
||||
memset(&(ctx->ipad[0]), IPAD_BYTE, HMAC_SHA1_BLOCK_LENGTH);
|
||||
memset(&(ctx->opad[0]), OPAD_BYTE, HMAC_SHA1_BLOCK_LENGTH);
|
||||
ctx->keylen = 0;
|
||||
ctx->hashkey = 0;
|
||||
}
|
||||
|
||||
void HMAC_SHA1_UpdateKey(HMAC_SHA1_CTX *ctx, unsigned char *key, unsigned int keylen) {
|
||||
|
||||
/* Do we have anything to work with? If not, return right away. */
|
||||
if (keylen < 1)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Is the total key length (current data and any previous data)
|
||||
* longer than the hash block length?
|
||||
*/
|
||||
if (ctx->hashkey !=0 || (keylen + ctx->keylen) > HMAC_SHA1_BLOCK_LENGTH) {
|
||||
/*
|
||||
* Looks like the key data exceeds the hash block length,
|
||||
* so that means we use a hash of the key as the key data
|
||||
* instead.
|
||||
*/
|
||||
if (ctx->hashkey == 0) {
|
||||
/*
|
||||
* Ah, we haven't started hashing the key
|
||||
* data yet, so we must init. the hash
|
||||
* monster to begin feeding it.
|
||||
*/
|
||||
|
||||
/* Set the hash key flag to true (non-zero) */
|
||||
ctx->hashkey = 1;
|
||||
|
||||
/* Init. the hash beastie... */
|
||||
SHA1_Init(&ctx->shactx);
|
||||
|
||||
/* If there's any previous key data, use it */
|
||||
if (ctx->keylen > 0) {
|
||||
SHA1_Update(&ctx->shactx, &(ctx->key[0]), ctx->keylen);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset the key length to the future true
|
||||
* key length, HMAC_SHA1_DIGEST_LENGTH
|
||||
*/
|
||||
ctx->keylen = HMAC_SHA1_DIGEST_LENGTH;
|
||||
}
|
||||
/* Now feed the latest key data to the has monster */
|
||||
SHA1_Update(&ctx->shactx, key, keylen);
|
||||
} else {
|
||||
/*
|
||||
* Key data length hasn't yet exceeded the hash
|
||||
* block length (HMAC_SHA1_BLOCK_LENGTH), so theres
|
||||
* no need to hash the key data (yet). Copy it
|
||||
* into the key buffer.
|
||||
*/
|
||||
memcpy(&(ctx->key[ctx->keylen]), key, keylen);
|
||||
ctx->keylen += keylen;
|
||||
}
|
||||
}
|
||||
|
||||
void HMAC_SHA1_EndKey(HMAC_SHA1_CTX *ctx) {
|
||||
unsigned char *ipad, *opad, *key;
|
||||
int i;
|
||||
|
||||
/* Did we end up hashing the key? */
|
||||
if (ctx->hashkey) {
|
||||
memset(&(ctx->key[0]), ZERO_BYTE, HMAC_SHA1_BLOCK_LENGTH);
|
||||
/* Yes, so finish up and copy the key data */
|
||||
SHA1_Final(&(ctx->key[0]), &ctx->shactx);
|
||||
/* ctx->keylen was already set correctly */
|
||||
}
|
||||
/* Pad the key if necessary with zero bytes */
|
||||
if ((i = HMAC_SHA1_BLOCK_LENGTH - ctx->keylen) > 0) {
|
||||
memset(&(ctx->key[ctx->keylen]), ZERO_BYTE, i);
|
||||
}
|
||||
|
||||
ipad = &(ctx->ipad[0]);
|
||||
opad = &(ctx->opad[0]);
|
||||
|
||||
/* Precompute the respective pads XORed with the key */
|
||||
key = &(ctx->key[0]);
|
||||
for (i = 0; i < ctx->keylen; i++, key++) {
|
||||
/* XOR the key byte with the appropriate pad filler byte */
|
||||
*ipad++ ^= *key;
|
||||
*opad++ ^= *key;
|
||||
}
|
||||
}
|
||||
|
||||
void HMAC_SHA1_StartMessage(HMAC_SHA1_CTX *ctx) {
|
||||
SHA1_Init(&ctx->shactx);
|
||||
SHA1_Update(&ctx->shactx, &(ctx->ipad[0]), HMAC_SHA1_BLOCK_LENGTH);
|
||||
}
|
||||
|
||||
void HMAC_SHA1_UpdateMessage(HMAC_SHA1_CTX *ctx, unsigned char *data, unsigned int datalen) {
|
||||
SHA1_Update(&ctx->shactx, data, datalen);
|
||||
}
|
||||
|
||||
void HMAC_SHA1_EndMessage(unsigned char *out, HMAC_SHA1_CTX *ctx) {
|
||||
unsigned char buf[HMAC_SHA1_DIGEST_LENGTH];
|
||||
SHA_CTX *c = &ctx->shactx;
|
||||
|
||||
SHA1_Final(&(buf[0]), c);
|
||||
SHA1_Init(c);
|
||||
SHA1_Update(c, &(ctx->opad[0]), HMAC_SHA1_BLOCK_LENGTH);
|
||||
SHA1_Update(c, buf, HMAC_SHA1_DIGEST_LENGTH);
|
||||
SHA1_Final(out, c);
|
||||
}
|
||||
|
||||
void HMAC_SHA1_Done(HMAC_SHA1_CTX *ctx) {
|
||||
/* Just to be safe, toast all context data */
|
||||
memset(&(ctx->ipad[0]), ZERO_BYTE, HMAC_SHA1_BLOCK_LENGTH);
|
||||
memset(&(ctx->ipad[0]), ZERO_BYTE, HMAC_SHA1_BLOCK_LENGTH);
|
||||
memset(&(ctx->key[0]), ZERO_BYTE, HMAC_SHA1_BLOCK_LENGTH);
|
||||
ctx->keylen = 0;
|
||||
ctx->hashkey = 0;
|
||||
}
|
||||
|
||||
void HMAC_SHA1(void *secret, void *data, void *res, int len)
|
||||
{
|
||||
unsigned char out[20];
|
||||
HMAC_SHA1_CTX ctx;
|
||||
HMAC_SHA1_Init(&ctx);
|
||||
HMAC_SHA1_UpdateKey(&ctx, (unsigned char *) secret, 0x10);
|
||||
HMAC_SHA1_EndKey(&ctx);
|
||||
HMAC_SHA1_StartMessage(&ctx);
|
||||
HMAC_SHA1_UpdateMessage(&ctx, (unsigned char *) data, len);
|
||||
HMAC_SHA1_EndMessage(out, &ctx);
|
||||
HMAC_SHA1_Done(&ctx);
|
||||
memcpy(res, out, 0x10);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
* hmac_sha1.h
|
||||
*
|
||||
* Version 1.0.0
|
||||
*
|
||||
* Written by Aaron D. Gifford <me@aarongifford.com>
|
||||
*
|
||||
* Copyright 1998, 2000 Aaron D. Gifford. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef HEADER_HMAC_SHA1_H
|
||||
#define HEADER_HMAC_SHA1_H
|
||||
|
||||
/*
|
||||
* Include SHA-1 stuff - CHOOSE WHICH SOURCE to use for the SHA1 functions
|
||||
*
|
||||
* Use the below include if your system has a library with SHA1 and be sure
|
||||
* to link to the library:
|
||||
*/
|
||||
|
||||
/* #include <sha.h> */
|
||||
|
||||
/*
|
||||
* Or you can use Steve Reid's public domain SHA1 implementation:
|
||||
*/
|
||||
|
||||
#include "sha.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define HMAC_SHA1_DIGEST_LENGTH 20
|
||||
#define HMAC_SHA1_BLOCK_LENGTH 64
|
||||
|
||||
/* The HMAC_SHA1 structure: */
|
||||
typedef struct _HMAC_SHA1_CTX {
|
||||
unsigned char ipad[HMAC_SHA1_BLOCK_LENGTH];
|
||||
unsigned char opad[HMAC_SHA1_BLOCK_LENGTH];
|
||||
SHA_CTX shactx;
|
||||
unsigned char key[HMAC_SHA1_BLOCK_LENGTH];
|
||||
unsigned int keylen;
|
||||
unsigned int hashkey;
|
||||
} HMAC_SHA1_CTX;
|
||||
|
||||
#ifndef NOPROTO
|
||||
void HMAC_SHA1_Init(HMAC_SHA1_CTX *ctx);
|
||||
void HMAC_SHA1_UpdateKey(HMAC_SHA1_CTX *ctx, unsigned char *key, unsigned int keylen);
|
||||
void HMAC_SHA1_EndKey(HMAC_SHA1_CTX *ctx);
|
||||
void HMAC_SHA1_StartMessage(HMAC_SHA1_CTX *ctx);
|
||||
void HMAC_SHA1_UpdateMessage(HMAC_SHA1_CTX *ctx, unsigned char *data, unsigned int datalen);
|
||||
void HMAC_SHA1_EndMessage(unsigned char *out, HMAC_SHA1_CTX *ctx);
|
||||
void HMAC_SHA1_Done(HMAC_SHA1_CTX *ctx);
|
||||
void HMAC_SHA1(void *secret, void *data, void *res, int len);
|
||||
#else
|
||||
void HMAC_SHA1_Init();
|
||||
void HMAC_SHA1_UpdateKey();
|
||||
void HMAC_SHA1_EndKey();
|
||||
void HMAC_SHA1_StartMessage();
|
||||
void HMAC_SHA1_UpdateMessage();
|
||||
void HMAC_SHA1_EndMessage();
|
||||
void HMAC_SHA1_Done();
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,37 +0,0 @@
|
||||
//#include "stdafx.h"
|
||||
#include "rc4.h"
|
||||
|
||||
|
||||
void rc4_init(unsigned char *state, unsigned char *key, int len)
|
||||
{
|
||||
//FYI state = unsigned char rc4[0x100];
|
||||
|
||||
int i, j=0, t;
|
||||
|
||||
for (i=0; i < 256; ++i)
|
||||
state[i] = i;
|
||||
|
||||
for (i=0; i < 256; ++i) {
|
||||
j = (j + state[i] + key[i % len]) % 256;
|
||||
t = state[i];
|
||||
state[i] = state[j];
|
||||
state[j] = t;
|
||||
}
|
||||
}
|
||||
|
||||
void rc4_crypt(unsigned char *state, unsigned char *data, int len)
|
||||
{
|
||||
//FYI state = unsigned char rc4[0x100];
|
||||
|
||||
int i=0,j=0,x,t;
|
||||
|
||||
for (x=0; x < len; ++x) {
|
||||
i = (i + 1) % 256;
|
||||
j = (j + state[i]) % 256;
|
||||
t = state[i];
|
||||
state[i] = state[j];
|
||||
state[j] = t;
|
||||
*data++ ^= state[(state[i] + state[j]) % 256];
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
#ifndef _RC4_H_
|
||||
#define _RC4_H_
|
||||
|
||||
void rc4_init(unsigned char *state, unsigned char *key, int len);
|
||||
void rc4_crypt(unsigned char *state, unsigned char *data, int len);
|
||||
|
||||
#endif // _RC4_H_
|
||||
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* sha.h
|
||||
*
|
||||
* Originally taken from the public domain SHA1 implementation
|
||||
* written by by Steve Reid <steve@edmweb.com>
|
||||
*
|
||||
* Modified by Aaron D. Gifford <agifford@infowest.com>
|
||||
*
|
||||
* NO COPYRIGHT - THIS IS 100% IN THE PUBLIC DOMAIN
|
||||
*
|
||||
* The original unmodified version is available at:
|
||||
* ftp://ftp.funet.fi/pub/crypt/hash/sha/sha1.c
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __SHA1_H__
|
||||
#define __SHA1_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Define this if your machine is LITTLE_ENDIAN, otherwise #undef it: */
|
||||
#undef LITTLE_ENDIAN
|
||||
|
||||
/* Make sure you define these types for your architecture: */
|
||||
typedef unsigned int sha1_quadbyte; /* 4 byte type */
|
||||
typedef unsigned char sha1_byte; /* single byte type */
|
||||
|
||||
/*
|
||||
* Be sure to get the above definitions right. For instance, on my
|
||||
* x86 based FreeBSD box, I define LITTLE_ENDIAN and use the type
|
||||
* "unsigned long" for the quadbyte. On FreeBSD on the Alpha, however,
|
||||
* while I still use LITTLE_ENDIAN, I must define the quadbyte type
|
||||
* as "unsigned int" instead.
|
||||
*/
|
||||
|
||||
#define SHA1_BLOCK_LENGTH 64
|
||||
#define SHA1_DIGEST_LENGTH 20
|
||||
|
||||
/* The SHA1 structure: */
|
||||
typedef struct _SHA_CTX {
|
||||
sha1_quadbyte state[5];
|
||||
sha1_quadbyte count[2];
|
||||
sha1_byte buffer[SHA1_BLOCK_LENGTH];
|
||||
} SHA_CTX;
|
||||
|
||||
#ifndef NOPROTO
|
||||
void SHA1_Init(SHA_CTX *context);
|
||||
void SHA1_Update(SHA_CTX *context, sha1_byte *data, unsigned int len);
|
||||
void SHA1_Final(sha1_byte digest[SHA1_DIGEST_LENGTH], SHA_CTX* context);
|
||||
#else
|
||||
void SHA1_Init();
|
||||
void SHA1_Update();
|
||||
void SHA1_Final();
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -1,156 +0,0 @@
|
||||
/*
|
||||
* sha1.c
|
||||
*
|
||||
* Originally witten by Steve Reid <steve@edmweb.com>
|
||||
*
|
||||
* Modified by Aaron D. Gifford <agifford@infowest.com>
|
||||
*
|
||||
* NO COPYRIGHT - THIS IS 100% IN THE PUBLIC DOMAIN
|
||||
*
|
||||
* The original unmodified version is available at:
|
||||
* ftp://ftp.funet.fi/pub/crypt/hash/sha/sha1.c
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
//#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sha.h"
|
||||
|
||||
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
||||
|
||||
/* blk0() and blk() perform the initial expand. */
|
||||
/* I got the idea of expanding during the round function from SSLeay */
|
||||
|
||||
#ifdef LITTLE_ENDIAN
|
||||
#define blk0(i) (block->l[i] = (rol(block->l[i],24)&(sha1_quadbyte)0xFF00FF00) | (rol(block->l[i],8)&(sha1_quadbyte)0x00FF00FF))
|
||||
#else
|
||||
#define blk0(i) block->l[i]
|
||||
#endif
|
||||
|
||||
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
|
||||
^block->l[(i+2)&15]^block->l[i&15],1))
|
||||
|
||||
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
|
||||
#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
|
||||
#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
|
||||
#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
|
||||
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
|
||||
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
|
||||
|
||||
typedef union _BYTE64QUAD16 {
|
||||
sha1_byte c[64];
|
||||
sha1_quadbyte l[16];
|
||||
} BYTE64QUAD16;
|
||||
|
||||
/* Hash a single 512-bit block. This is the core of the algorithm. */
|
||||
void SHA1_Transform(sha1_quadbyte state[5], sha1_byte buffer[64]) {
|
||||
sha1_quadbyte a, b, c, d, e;
|
||||
BYTE64QUAD16 *block;
|
||||
|
||||
block = (BYTE64QUAD16*)buffer;
|
||||
/* Copy context->state[] to working vars */
|
||||
a = state[0];
|
||||
b = state[1];
|
||||
c = state[2];
|
||||
d = state[3];
|
||||
e = state[4];
|
||||
/* 4 rounds of 20 operations each. Loop unrolled. */
|
||||
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
|
||||
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
|
||||
R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
|
||||
R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
|
||||
R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
|
||||
R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
|
||||
R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
|
||||
R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
|
||||
R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
|
||||
R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
|
||||
R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
|
||||
R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
|
||||
R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
|
||||
R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
|
||||
R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
|
||||
R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
|
||||
R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
|
||||
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
|
||||
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
|
||||
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
|
||||
/* Add the working vars back into context.state[] */
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
/* Wipe variables */
|
||||
a = b = c = d = e = 0;
|
||||
}
|
||||
|
||||
|
||||
/* SHA1_Init - Initialize new context */
|
||||
void SHA1_Init(SHA_CTX* context) {
|
||||
/* SHA1 initialization constants */
|
||||
context->state[0] = 0x67452301;
|
||||
context->state[1] = 0xEFCDAB89;
|
||||
context->state[2] = 0x98BADCFE;
|
||||
context->state[3] = 0x10325476;
|
||||
context->state[4] = 0xC3D2E1F0;
|
||||
context->count[0] = context->count[1] = 0;
|
||||
}
|
||||
|
||||
/* Run your data through this. */
|
||||
void SHA1_Update(SHA_CTX *context, sha1_byte *data, unsigned int len) {
|
||||
unsigned int i, j;
|
||||
|
||||
j = (context->count[0] >> 3) & 63;
|
||||
if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++;
|
||||
context->count[1] += (len >> 29);
|
||||
if ((j + len) > 63) {
|
||||
memcpy(&context->buffer[j], data, (i = 64-j));
|
||||
SHA1_Transform(context->state, context->buffer);
|
||||
for ( ; i + 63 < len; i += 64) {
|
||||
SHA1_Transform(context->state, &data[i]);
|
||||
}
|
||||
j = 0;
|
||||
}
|
||||
else i = 0;
|
||||
memcpy(&context->buffer[j], &data[i], len - i);
|
||||
}
|
||||
|
||||
|
||||
/* Add padding and return the message digest. */
|
||||
void SHA1_Final(sha1_byte digest[SHA1_DIGEST_LENGTH], SHA_CTX *context) {
|
||||
sha1_quadbyte i, j;
|
||||
sha1_byte finalcount[8];
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
finalcount[i] = (sha1_byte)((context->count[(i >= 4 ? 0 : 1)]
|
||||
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
|
||||
}
|
||||
SHA1_Update(context, (sha1_byte *)"\200", 1);
|
||||
while ((context->count[0] & 504) != 448) {
|
||||
SHA1_Update(context, (sha1_byte *)"\0", 1);
|
||||
}
|
||||
/* Should cause a SHA1_Transform() */
|
||||
SHA1_Update(context, finalcount, 8);
|
||||
for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
|
||||
digest[i] = (sha1_byte)
|
||||
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
|
||||
}
|
||||
/* Wipe variables */
|
||||
i = j = 0;
|
||||
memset(context->buffer, 0, SHA1_BLOCK_LENGTH);
|
||||
memset(context->state, 0, SHA1_DIGEST_LENGTH);
|
||||
memset(context->count, 0, 8);
|
||||
memset(&finalcount, 0, 8);
|
||||
}
|
||||
|
@ -18,10 +18,10 @@ used for zlib support ...
|
||||
#include <usb/usbmain.h>
|
||||
#include <ppc/timebase.h>
|
||||
#include <xenon_nand/xenon_sfcx.h>
|
||||
#include <xb360/xb360.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "file.h"
|
||||
#include "xb360/xb360.h"
|
||||
#include "kboot/kbootconf.h"
|
||||
#include "tftp/tftp.h"
|
||||
|
||||
|
@ -7,14 +7,14 @@
|
||||
#define mem_free free
|
||||
#define mem_malloc malloc
|
||||
#else
|
||||
#include "lwip/debug.h"
|
||||
#include "lwip/stats.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include <lwip/debug.h>
|
||||
#include <lwip/stats.h>
|
||||
#include <lwip/tcp.h>
|
||||
#endif
|
||||
|
||||
#include "httpd/httpd.h"
|
||||
|
||||
#include "network/network.h"
|
||||
#include <network/network.h>
|
||||
#include "httpd/httpd_flash.h"
|
||||
#include "httpd/httpd_fuse.h"
|
||||
#include "httpd_keyvault.h"
|
||||
|
@ -11,11 +11,11 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <xenon_nand/xenon_sfcx.h>
|
||||
#include <crypt/hmac_sha1.h>
|
||||
#include <crypt/rc4.h>
|
||||
#include <xb360/xb360.h>
|
||||
#include <network/network.h>
|
||||
|
||||
#include "network/network.h"
|
||||
#include "crypt/hmac_sha1.h"
|
||||
#include "crypt/rc4.h"
|
||||
#include "xb360/xb360.h"
|
||||
#include "httpd.h"
|
||||
#include "httpd_flash.h"
|
||||
|
||||
|
@ -7,15 +7,15 @@
|
||||
|
||||
//#include "lwip/debug.h"
|
||||
//#include "lwip/stats.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include <lwip/tcp.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <xetypes.h>
|
||||
|
||||
#include "network/network.h"
|
||||
#include "crypt/hmac_sha1.h"
|
||||
#include "crypt/rc4.h"
|
||||
#include "xb360/xb360.h"
|
||||
#include <network/network.h>
|
||||
#include <crypt/hmac_sha1.h>
|
||||
#include <crypt/rc4.h>
|
||||
#include <xb360/xb360.h>
|
||||
#include <xenon_soc/xenon_io.h>
|
||||
|
||||
#include "httpd.h"
|
||||
|
@ -13,8 +13,8 @@
|
||||
#include <lwip/tcp.h>
|
||||
#include <xenon_soc/xenon_io.h>
|
||||
|
||||
#include "network/network.h"
|
||||
#include "xb360/xb360.h"
|
||||
#include <network/network.h>
|
||||
#include <xb360/xb360.h>
|
||||
|
||||
#include "httpd.h"
|
||||
#include "httpd_index.h"
|
||||
|
@ -8,13 +8,13 @@
|
||||
|
||||
//#include "lwip/debug.h"
|
||||
//#include "lwip/stats.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include <lwip/tcp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "network/network.h"
|
||||
#include "xb360/xb360.h"
|
||||
#include <network/network.h>
|
||||
#include <xb360/xb360.h>
|
||||
|
||||
#include "httpd.h"
|
||||
#include "httpd_index.h"
|
||||
|
@ -8,12 +8,12 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <xenon_nand/xenon_sfcx.h>
|
||||
#include <xb360/xb360.h>
|
||||
//#include <lwip/debug.h>
|
||||
//#include <lwip/stats.h>
|
||||
#include <lwip/tcp.h>
|
||||
#include <network/network.h>
|
||||
|
||||
#include "xb360/xb360.h"
|
||||
//#include "lwip/debug.h"
|
||||
//#include "lwip/stats.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include "network/network.h"
|
||||
#include "httpd.h"
|
||||
#include "httpd_index.h"
|
||||
|
||||
|
@ -1,384 +0,0 @@
|
||||
/*
|
||||
* xb360.c
|
||||
*
|
||||
* Created on: Sep 4, 2008
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time/time.h>
|
||||
#include <xenon_nand/xenon_sfcx.h>
|
||||
#include <xenon_nand/xenon_config.h>
|
||||
#include <xenon_soc/xenon_secotp.h>
|
||||
#include <crypt/hmac_sha1.h>
|
||||
#include <crypt/rc4.h>
|
||||
|
||||
#include "xb360.h"
|
||||
|
||||
extern char elfhdr[];
|
||||
extern struct XCONFIG_SECURED_SETTINGS secured_settings;
|
||||
extern void wait_and_cleanup_line();
|
||||
|
||||
extern struct sfc sfc;
|
||||
|
||||
static const kventry kvlookup[] =
|
||||
{
|
||||
{XEKEY_MANUFACTURING_MODE, 0x18, 0x01},
|
||||
{XEKEY_ALTERNATE_KEY_VAULT, 0x19, 0x01},
|
||||
{XEKEY_RESERVED_BYTE2, 0x1A, 0x01},
|
||||
{XEKEY_RESERVED_BYTE3, 0x1B, 0x01},
|
||||
{XEKEY_RESERVED_WORD1, 0x1C, 0x02},
|
||||
{XEKEY_RESERVED_WORD2, 0x1E, 0x02},
|
||||
{XEKEY_RESTRICTED_HVEXT_LOADER, 0x20, 0x02},
|
||||
{XEKEY_RESERVED_DWORD2, 0x24, 0x04},
|
||||
{XEKEY_RESERVED_DWORD3, 0x28, 0x04},
|
||||
{XEKEY_RESERVED_DWORD4, 0x2c, 0x04},
|
||||
{XEKEY_RESTRICTED_PRIVILEDGES, 0x30, 0x08},
|
||||
{XEKEY_RESERVED_QWORD2, 0x38, 0x08},
|
||||
{XEKEY_RESERVED_QWORD3, 0x40, 0x08},
|
||||
{XEKEY_RESERVED_QWORD4, 0x48, 0x08},
|
||||
{XEKEY_RESERVED_KEY1, 0x50, 0x10},
|
||||
{XEKEY_RESERVED_KEY2, 0x60, 0x10},
|
||||
{XEKEY_RESERVED_KEY3, 0x70, 0x10},
|
||||
{XEKEY_RESERVED_KEY4, 0x80, 0x10},
|
||||
{XEKEY_RESERVED_RANDOM_KEY1, 0x90, 0x10},
|
||||
{XEKEY_RESERVED_RANDOM_KEY2, 0xA0, 0x10},
|
||||
{XEKEY_CONSOLE_SERIAL_NUMBER, 0xB0, 0x0C},
|
||||
{XEKEY_MOBO_SERIAL_NUMBER, 0xBC, 0x0C},
|
||||
{XEKEY_GAME_REGION, 0xC8, 0x02},
|
||||
{XEKEY_CONSOLE_OBFUSCATION_KEY, 0xD0, 0x10},
|
||||
{XEKEY_KEY_OBFUSCATION_KEY, 0xE0, 0x10},
|
||||
{XEKEY_ROAMABLE_OBFUSCATION_KEY, 0xF0, 0x10},
|
||||
{XEKEY_DVD_KEY, 0x100, 0x10},
|
||||
{XEKEY_PRIMARY_ACTIVATION_KEY, 0x110, 0x18},
|
||||
{XEKEY_SECONDARY_ACTIVATION_KEY, 0x128, 0x10},
|
||||
{XEKEY_GLOBAL_DEVICE_2DES_KEY1, 0x138, 0x10},
|
||||
{XEKEY_GLOBAL_DEVICE_2DES_KEY2, 0x148, 0x10},
|
||||
{XEKEY_WIRELESS_CONTROLLER_MS_2DES_KEY1, 0x158, 0x10},
|
||||
{XEKEY_WIRELESS_CONTROLLER_MS_2DES_KEY2 , 0x168, 0x10},
|
||||
{XEKEY_WIRED_WEBCAM_MS_2DES_KEY1, 0x178, 0x10},
|
||||
{XEKEY_WIRED_WEBCAM_MS_2DES_KEY2, 0x188, 0x10},
|
||||
{XEKEY_WIRED_CONTROLLER_MS_2DES_KEY1, 0x198, 0x10},
|
||||
{XEKEY_WIRED_CONTROLLER_MS_2DES_KEY2, 0x1A8, 0x10},
|
||||
{XEKEY_MEMORY_UNIT_MS_2DES_KEY1, 0x1B8, 0x10},
|
||||
{XEKEY_MEMORY_UNIT_MS_2DES_KEY2, 0x1C8, 0x10},
|
||||
{XEKEY_OTHER_XSM3_DEVICE_MS_2DES_KEY1, 0x1D8, 0x10},
|
||||
{XEKEY_OTHER_XSM3_DEVICE_MS_2DES_KEY2, 0x1E8, 0x10},
|
||||
{XEKEY_WIRELESS_CONTROLLER_3P_2DES_KEY1, 0x1F8, 0x10},
|
||||
{XEKEY_WIRELESS_CONTROLLER_3P_2DES_KEY2, 0x208, 0x10},
|
||||
{XEKEY_WIRED_WEBCAM_3P_2DES_KEY1, 0x218, 0x10},
|
||||
{XEKEY_WIRED_WEBCAM_3P_2DES_KEY2, 0x228, 0x10},
|
||||
{XEKEY_WIRED_CONTROLLER_3P_2DES_KEY1, 0x238, 0x10},
|
||||
{XEKEY_WIRED_CONTROLLER_3P_2DES_KEY2, 0x248, 0x10},
|
||||
{XEKEY_MEMORY_UNIT_3P_2DES_KEY1, 0x258, 0x10},
|
||||
{XEKEY_MEMORY_UNIT_3P_2DES_KEY2, 0x268, 0x10},
|
||||
{XEKEY_OTHER_XSM3_DEVICE_3P_2DES_KEY1, 0x278, 0x10},
|
||||
{XEKEY_OTHER_XSM3_DEVICE_3P_2DES_KEY2, 0x288, 0x10},
|
||||
{XEKEY_CONSOLE_PRIVATE_KEY, 0x298, 0x1D0},
|
||||
{XEKEY_XEIKA_PRIVATE_KEY, 0x468, 0x390},
|
||||
{XEKEY_CARDEA_PRIVATE_KEY, 0x7F8, 0x1D0},
|
||||
{XEKEY_CONSOLE_CERTIFICATE, 0x9C8, 0x1A8},
|
||||
{XEKEY_XEIKA_CERTIFICATE, 0xB70, 0x1388},
|
||||
{XEKEY_CARDEA_CERTIFICATE, 0x1EF8, 0x2108}
|
||||
};
|
||||
|
||||
void print_key(char *name, unsigned char *data)
|
||||
{
|
||||
int i=0;
|
||||
printf("%s: ", name);
|
||||
for(i=0; i<16; i++)
|
||||
printf("%02X",data[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int cpu_get_key(unsigned char *data)
|
||||
{
|
||||
*(unsigned long long*)&data[0] = xenon_secotp_read_line(3);
|
||||
*(unsigned long long*)&data[8] = xenon_secotp_read_line(5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int virtualfuses_read(unsigned char *data)
|
||||
{
|
||||
int vfuses_offset = 0x95000; //Page (0x4A8 * 0x200)
|
||||
if (sfc.initialized != SFCX_INITIALIZED)
|
||||
return 1;
|
||||
|
||||
int status = sfcx_read_page(data, vfuses_offset, 0);
|
||||
|
||||
//read from nand
|
||||
if (!SFCX_SUCCESS(status))
|
||||
return 2; //failure
|
||||
else
|
||||
return 0; //success
|
||||
}
|
||||
|
||||
|
||||
int get_virtual_cpukey(unsigned char *data)
|
||||
{
|
||||
int result = 0;
|
||||
unsigned char buffer[MAX_PAGE_SZ];
|
||||
result = virtualfuses_read(buffer);
|
||||
|
||||
if (result!=0)
|
||||
{
|
||||
printf(" ! SFCX error while reading virtualfuses\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
//if we got here then it was at least able to read from nand
|
||||
//now we need to verify the data somehow
|
||||
if (buffer[0]==0xC0 && buffer[1]==0xFF && buffer[2]==0xFF && buffer[3]==0xFF)
|
||||
{
|
||||
memcpy(data,&buffer[0x20],0x10);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
/* No Virtual Fuses were found at 0x95000*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int kv_get_key(unsigned char keyid, unsigned char *keybuf, int *keybuflen, unsigned char *keyvault)
|
||||
{
|
||||
if (keyid > 0x38)
|
||||
return 1;
|
||||
|
||||
if (*keybuflen != kvlookup[keyid].length)
|
||||
{
|
||||
*keybuflen = kvlookup[keyid].length;
|
||||
return 2;
|
||||
}
|
||||
memcpy(keybuf, keyvault + kvlookup[keyid].offset, kvlookup[keyid].length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int kv_read(unsigned char *data, int virtualcpukey)
|
||||
{
|
||||
int page=0;
|
||||
int pages=0;
|
||||
int togo=0;
|
||||
int kv_offset = 0;
|
||||
int cntr = 0;
|
||||
|
||||
if (sfc.initialized != SFCX_INITIALIZED)
|
||||
return 1;
|
||||
|
||||
unsigned char buffer[MAX_PAGE_SZ];
|
||||
memset(buffer, '\0', sizeof(buffer));
|
||||
|
||||
sfcx_read_page(buffer, 0, 0);
|
||||
|
||||
kv_offset = buffer[KV_FLASH_PTR+0]; kv_offset <<= 8;
|
||||
kv_offset |= buffer[KV_FLASH_PTR+1]; kv_offset <<= 8;
|
||||
kv_offset |= buffer[KV_FLASH_PTR+2]; kv_offset <<= 8;
|
||||
kv_offset |= buffer[KV_FLASH_PTR+3];
|
||||
|
||||
//printf("kv_read: kv_offset: %d\n", kv_offset);
|
||||
|
||||
page = (kv_offset / sfc.page_sz);
|
||||
pages = KV_FLASH_PAGES;
|
||||
togo = pages;
|
||||
|
||||
while(togo)
|
||||
{
|
||||
sfcx_read_page((unsigned char*) &data[cntr * sfc.page_sz], page * sfc.page_sz, 0);
|
||||
page++;
|
||||
cntr++;
|
||||
togo--;
|
||||
}
|
||||
|
||||
unsigned char cpu_key[0x10];
|
||||
if (virtualcpukey)
|
||||
get_virtual_cpukey(cpu_key);
|
||||
else
|
||||
cpu_get_key(cpu_key);
|
||||
//print_key("kv_read: cpu key", cpu_key);
|
||||
|
||||
unsigned char hmac_key[0x10];
|
||||
memcpy(hmac_key, data, 0x10);
|
||||
//print_key("kv_read: hmac key", hmac_key);
|
||||
|
||||
unsigned char rc4_key[0x10];
|
||||
memset(rc4_key, 0, 0x10);
|
||||
|
||||
HMAC_SHA1(cpu_key, hmac_key, rc4_key, 0x10);
|
||||
//print_key("kv_read: rc4 key", rc4_key);
|
||||
|
||||
unsigned char rc4_state[0x100];
|
||||
memset(rc4_state, 0, 0x100);
|
||||
|
||||
rc4_init(rc4_state, rc4_key ,0x10);
|
||||
rc4_crypt(rc4_state, (unsigned char*) &data[0x10], KV_FLASH_SIZE - 0x10);
|
||||
|
||||
//Now then do a little check to make sure it is somewhat correct
|
||||
//We check the hmac_sha1 of the data and compare that to
|
||||
//the hmac_sha1 key in the header of the keyvault
|
||||
//basically the reverse of what we did to generate the key for rc4
|
||||
unsigned char data2[KV_FLASH_SIZE];
|
||||
unsigned char out[20];
|
||||
unsigned char tmp[] = {0x07, 0x12};
|
||||
HMAC_SHA1_CTX ctx;
|
||||
|
||||
//the hmac_sha1 seems destructive
|
||||
//so we make a copy of the data
|
||||
memcpy(data2, data, KV_FLASH_SIZE);
|
||||
|
||||
HMAC_SHA1_Init(&ctx);
|
||||
HMAC_SHA1_UpdateKey(&ctx, (unsigned char *) cpu_key, 0x10);
|
||||
HMAC_SHA1_EndKey(&ctx);
|
||||
|
||||
HMAC_SHA1_StartMessage(&ctx);
|
||||
|
||||
HMAC_SHA1_UpdateMessage(&ctx, (unsigned char*) &data2[0x10], KV_FLASH_SIZE - 0x10);
|
||||
HMAC_SHA1_UpdateMessage(&ctx, (unsigned char*) &tmp[0x00], 0x02); //Special appendage
|
||||
|
||||
HMAC_SHA1_EndMessage(out, &ctx);
|
||||
HMAC_SHA1_Done(&ctx);
|
||||
|
||||
int index = 0;
|
||||
while (index < 0x10)
|
||||
{
|
||||
if (data[index] != out[index])
|
||||
{
|
||||
// Hmm something is wrong, hmac is not matching
|
||||
//printf(" ! kv_read: kv hash check failed\n");
|
||||
return 2;
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int kv_get_dvd_key(unsigned char *dvd_key)
|
||||
{
|
||||
unsigned char buffer[KV_FLASH_SIZE], tmp[0x10];
|
||||
int result = 0;
|
||||
int keylen = 0x10;
|
||||
|
||||
result = kv_read(buffer, 0);
|
||||
if (result == 2 && get_virtual_cpukey(tmp) == 0){
|
||||
printf("! Attempting to decrypt DVDKey with Virtual CPU Key !\n");
|
||||
result = kv_read(buffer, 1);
|
||||
}
|
||||
if (result != 0){
|
||||
printf(" ! kv_get_dvd_key Failure: kv_read\n");
|
||||
if (result == 2){ //Hash failure
|
||||
printf(" ! the hash check failed probably as a result of decryption failure\n");
|
||||
printf(" ! make sure that the CORRECT key vault for this console is in flash\n");
|
||||
printf(" ! the key vault should be at offset 0x4200 for a length of 0x4200\n");
|
||||
printf(" ! in the 'raw' flash binary from THIS console\n");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
result = kv_get_key(XEKEY_DVD_KEY, dvd_key, &keylen, buffer);
|
||||
if (result != 0){
|
||||
printf(" ! kv_get_dvd_key Failure: kv_get_key %d\n", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
//print_key("dvd key", dvd_key);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void print_cpu_dvd_keys(void)
|
||||
{
|
||||
unsigned char key[0x10];
|
||||
|
||||
printf("\n");
|
||||
|
||||
memset(key, '\0', sizeof(key));
|
||||
if (cpu_get_key(key)==0)
|
||||
print_key(" * your cpu key", key);
|
||||
|
||||
memset(key, '\0',sizeof(key));
|
||||
if (get_virtual_cpukey(key)==0)
|
||||
print_key(" * your virtual cpu key", key);
|
||||
|
||||
memset(key, '\0', sizeof(key));
|
||||
if (kv_get_dvd_key(key)==0)
|
||||
print_key(" * your dvd key", key);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int updateXeLL(void * addr, unsigned len)
|
||||
{
|
||||
int i, j, k, startblock, current, offsetinblock, blockcnt;
|
||||
unsigned char *user, *spare;
|
||||
|
||||
if (sfc.initialized != SFCX_INITIALIZED){
|
||||
printf(" ! sfcx is not initialized! Unable to update XeLL in NAND!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("\n * found XeLL update. press power NOW if you don't want to update.\n");
|
||||
delay(15);
|
||||
|
||||
for (k = 0; k < XELL_OFFSET_COUNT; k++)
|
||||
{
|
||||
current = xelloffsets[k];
|
||||
offsetinblock = current % sfc.block_sz;
|
||||
startblock = current/sfc.block_sz;
|
||||
blockcnt = offsetinblock ? (XELL_SIZE/sfc.block_sz)+1 : (XELL_SIZE/sfc.block_sz);
|
||||
|
||||
|
||||
spare = (unsigned char*)malloc(blockcnt*sfc.pages_in_block*sfc.meta_sz);
|
||||
if(!spare){
|
||||
printf(" ! Error while memallocating filebuffer (spare)\n");
|
||||
return -1;
|
||||
}
|
||||
user = (unsigned char*)malloc(blockcnt*sfc.block_sz);
|
||||
if(!user){
|
||||
printf(" ! Error while memallocating filebuffer (user)\n");
|
||||
return -1;
|
||||
}
|
||||
j = 0;
|
||||
unsigned char pagebuf[MAX_PAGE_SZ];
|
||||
|
||||
for (i = (startblock*sfc.pages_in_block); i< (startblock+blockcnt)*sfc.pages_in_block; i++)
|
||||
{
|
||||
sfcx_read_page(pagebuf, (i*sfc.page_sz), 1);
|
||||
//Split rawpage into user & spare
|
||||
memcpy(&user[j*sfc.page_sz],pagebuf,sfc.page_sz);
|
||||
memcpy(&spare[j*sfc.meta_sz],&pagebuf[sfc.page_sz],sfc.meta_sz);
|
||||
j++;
|
||||
}
|
||||
|
||||
if (memcmp(&user[offsetinblock+(XELL_FOOTER_OFFSET)],XELL_FOOTER,XELL_FOOTER_LENGTH) == 0){
|
||||
printf(" * XeLL Binary in NAND found @ 0x%08X\n", (startblock*sfc.block_sz)+offsetinblock);
|
||||
|
||||
memcpy(&user[offsetinblock], addr,len); //Copy over updxell.bin
|
||||
printf(" * Writing to NAND!\n");
|
||||
j = 0;
|
||||
for (i = startblock*sfc.pages_in_block; i < (startblock+blockcnt)*sfc.pages_in_block; i ++)
|
||||
{
|
||||
if (!(i%sfc.pages_in_block))
|
||||
sfcx_erase_block(i*sfc.page_sz);
|
||||
|
||||
/* Copy user & spare data together in a single rawpage */
|
||||
memcpy(pagebuf,&user[j*sfc.page_sz],sfc.page_sz);
|
||||
memcpy(&pagebuf[sfc.page_sz],&spare[j*sfc.meta_sz],sfc.meta_sz);
|
||||
j++;
|
||||
|
||||
if (!(sfcx_is_pageerased(pagebuf))) // We dont need to write to erased pages
|
||||
{
|
||||
memset(&pagebuf[sfc.page_sz+0x0C],0x0, 4); //zero only EDC bytes
|
||||
sfcx_calcecc((unsigned int *)pagebuf); //recalc EDC bytes
|
||||
sfcx_write_page(pagebuf, i*sfc.page_sz);
|
||||
}
|
||||
}
|
||||
printf(" * XeLL flashed! Reboot the xbox to enjoy the new build\n");
|
||||
for(;;);
|
||||
|
||||
}
|
||||
}
|
||||
printf(" ! Couldn't locate XeLL binary in NAND. Aborting!\n");
|
||||
return -1;
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
/*
|
||||
* xb360.h
|
||||
*
|
||||
* Created on: Sep 4, 2008
|
||||
*/
|
||||
|
||||
#ifndef __XB360_H
|
||||
#define __XB360_H
|
||||
|
||||
#define XEKEY_MANUFACTURING_MODE 0x00
|
||||
#define XEKEY_ALTERNATE_KEY_VAULT 0x01
|
||||
#define XEKEY_RESERVED_BYTE2 0x02
|
||||
#define XEKEY_RESERVED_BYTE3 0x03
|
||||
#define XEKEY_RESERVED_WORD1 0x04
|
||||
#define XEKEY_RESERVED_WORD2 0x05
|
||||
#define XEKEY_RESTRICTED_HVEXT_LOADER 0x06
|
||||
#define XEKEY_RESERVED_DWORD2 0x07
|
||||
#define XEKEY_RESERVED_DWORD3 0x08
|
||||
#define XEKEY_RESERVED_DWORD4 0x09
|
||||
#define XEKEY_RESTRICTED_PRIVILEDGES 0x0A
|
||||
#define XEKEY_RESERVED_QWORD2 0x0B
|
||||
#define XEKEY_RESERVED_QWORD3 0x0C
|
||||
#define XEKEY_RESERVED_QWORD4 0x0D
|
||||
#define XEKEY_RESERVED_KEY1 0x0E
|
||||
#define XEKEY_RESERVED_KEY2 0x0F
|
||||
#define XEKEY_RESERVED_KEY3 0x10
|
||||
#define XEKEY_RESERVED_KEY4 0x11
|
||||
#define XEKEY_RESERVED_RANDOM_KEY1 0x12
|
||||
#define XEKEY_RESERVED_RANDOM_KEY2 0x13
|
||||
#define XEKEY_CONSOLE_SERIAL_NUMBER 0x14
|
||||
#define XEKEY_MOBO_SERIAL_NUMBER 0x15
|
||||
#define XEKEY_GAME_REGION 0x16
|
||||
#define XEKEY_CONSOLE_OBFUSCATION_KEY 0x17
|
||||
#define XEKEY_KEY_OBFUSCATION_KEY 0x18
|
||||
#define XEKEY_ROAMABLE_OBFUSCATION_KEY 0x19
|
||||
#define XEKEY_DVD_KEY 0x1A
|
||||
#define XEKEY_PRIMARY_ACTIVATION_KEY 0x1B
|
||||
#define XEKEY_SECONDARY_ACTIVATION_KEY 0x1C
|
||||
#define XEKEY_GLOBAL_DEVICE_2DES_KEY1 0x1D
|
||||
#define XEKEY_GLOBAL_DEVICE_2DES_KEY2 0x1E
|
||||
#define XEKEY_WIRELESS_CONTROLLER_MS_2DES_KEY1 0x1F
|
||||
#define XEKEY_WIRELESS_CONTROLLER_MS_2DES_KEY2 0x20
|
||||
#define XEKEY_WIRED_WEBCAM_MS_2DES_KEY1 0x21
|
||||
#define XEKEY_WIRED_WEBCAM_MS_2DES_KEY2 0x22
|
||||
#define XEKEY_WIRED_CONTROLLER_MS_2DES_KEY1 0x23
|
||||
#define XEKEY_WIRED_CONTROLLER_MS_2DES_KEY2 0x24
|
||||
#define XEKEY_MEMORY_UNIT_MS_2DES_KEY1 0x25
|
||||
#define XEKEY_MEMORY_UNIT_MS_2DES_KEY2 0x26
|
||||
#define XEKEY_OTHER_XSM3_DEVICE_MS_2DES_KEY1 0x27
|
||||
#define XEKEY_OTHER_XSM3_DEVICE_MS_2DES_KEY2 0x28
|
||||
#define XEKEY_WIRELESS_CONTROLLER_3P_2DES_KEY1 0x29
|
||||
#define XEKEY_WIRELESS_CONTROLLER_3P_2DES_KEY2 0x2A
|
||||
#define XEKEY_WIRED_WEBCAM_3P_2DES_KEY1 0x2B
|
||||
#define XEKEY_WIRED_WEBCAM_3P_2DES_KEY2 0x2C
|
||||
#define XEKEY_WIRED_CONTROLLER_3P_2DES_KEY1 0x2D
|
||||
#define XEKEY_WIRED_CONTROLLER_3P_2DES_KEY2 0x2E
|
||||
#define XEKEY_MEMORY_UNIT_3P_2DES_KEY1 0x2F
|
||||
#define XEKEY_MEMORY_UNIT_3P_2DES_KEY2 0x30
|
||||
#define XEKEY_OTHER_XSM3_DEVICE_3P_2DES_KEY1 0x31
|
||||
#define XEKEY_OTHER_XSM3_DEVICE_3P_2DES_KEY2 0x32
|
||||
#define XEKEY_CONSOLE_PRIVATE_KEY 0x33
|
||||
#define XEKEY_XEIKA_PRIVATE_KEY 0x34
|
||||
#define XEKEY_CARDEA_PRIVATE_KEY 0x35
|
||||
#define XEKEY_CONSOLE_CERTIFICATE 0x36
|
||||
#define XEKEY_XEIKA_CERTIFICATE 0x37
|
||||
#define XEKEY_CARDEA_CERTIFICATE 0x38
|
||||
|
||||
#define KV_FLASH_SIZE 0x4000
|
||||
#define KV_FLASH_PAGES KV_FLASH_SIZE / 0x200
|
||||
#define KV_FLASH_PTR 0x6C
|
||||
#define VFUSES_SIZE 0x60
|
||||
|
||||
#define XELL_SIZE (256*1024)
|
||||
#define XELL_FOOTER_OFFSET (256*1024-16)
|
||||
#define XELL_FOOTER_LENGTH 16
|
||||
#define XELL_FOOTER "xxxxxxxxxxxxxxxx"
|
||||
|
||||
#define XELL_OFFSET_COUNT 6
|
||||
static const unsigned int xelloffsets[XELL_OFFSET_COUNT] = {0x70000, // ggBoot main xell-gggggg
|
||||
0x95060, // FreeBOOT Single-NAND main xell-2f
|
||||
0x100000, // XeLL-Only Image
|
||||
0xC0000,
|
||||
0xE0000,
|
||||
0xB80000};
|
||||
|
||||
typedef struct kventry {
|
||||
char id;
|
||||
int offset;
|
||||
int length;
|
||||
} kventry;
|
||||
|
||||
|
||||
void print_key(char *name, unsigned char *data);
|
||||
int cpu_get_key(unsigned char *data);
|
||||
int virtualfuses_read(unsigned char *data);
|
||||
int get_virtual_cpukey(unsigned char *data);
|
||||
int kv_read(unsigned char *data, int virtualcpukey);
|
||||
int kv_get_dvd_key(unsigned char *dvd_key);
|
||||
int kv_get_key(unsigned char keyid, unsigned char *keybuf, int *keybuflen, unsigned char *keyvault);
|
||||
void print_cpu_dvd_keys(void);
|
||||
int updateXeLL(void * addr, unsigned len);
|
||||
|
||||
#endif /* XB360_H_ */
|
Loading…
Reference in New Issue
Block a user