forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to secure NAND flash ?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
pspZorba



Joined: 22 Sep 2007
Posts: 156
Location: NY

PostPosted: Wed Feb 27, 2008 2:48 pm    Post subject: How to secure NAND flash ? Reply with quote

Hi all,

I am writting an homebrew, one of its functionality is to bakcup and restore the nand.
I would like to secure the flash part. I imagine I handled the code ;-/ , but I was wondering what kind of controls I could do on the file to flash to avoid as much as possible bricks and idstorage loss by flashing a wrong file.

The obvious one being the file size, but do you have any other ideas?
_________________
--pspZorba--
NO to K1.5 !
Back to top
View user's profile Send private message
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Wed Feb 27, 2008 8:12 pm    Post subject: Reply with quote

You want to make it so your app knows if the backup file it produced has
been changed or corrupted? Calculate a checksum for it.

One method I've used is start with a byte value like 0x3F, XOR it with the
first byte of the file to get a new value in the checksum byte, XOR that
value with the second byte to get yet another value, then keep going till the
end of the file. The value you have in the checksum byte can be repeated
for reading, or reversed back to the value 0x3F that you began with if the
file wasn't changed. To be more secure you can do it with another checksum
variable, only do it a different way, or use a different start value.

You could append the NAND file with the values, or better still, write it in an accompanying file.
Art.
_________________
If not actually, then potentially.
Back to top
View user's profile Send private message
pspZorba



Joined: 22 Sep 2007
Posts: 156
Location: NY

PostPosted: Wed Feb 27, 2008 10:01 pm    Post subject: Reply with quote

Good idea, that way you can know if the file is corrupt or not, I will add it.

Do you think it's possible to do some checks to be sure the dump is the dump of the psp that is about to be flashed ?
_________________
--pspZorba--
NO to K1.5 !
Back to top
View user's profile Send private message
Hellcat



Joined: 24 Jan 2007
Posts: 84

PostPosted: Wed Feb 27, 2008 10:20 pm    Post subject: Reply with quote

You can add some PSP specific details into the checksum calculation, or make a seperate checksum for that.

Like one of the IDS keys or such.
Back to top
View user's profile Send private message
jean



Joined: 05 Jan 2008
Posts: 489

PostPosted: Wed Feb 27, 2008 10:53 pm    Post subject: Reply with quote

Without entering too in detail in a tough argument, the canonical way to implement simple but effective hashes from scratch is :

Code:

   unsigned int startHashCode(){
        return aSmallNumber;
    }
   
    unsigned int addDataToHashCode(unsigned int data, unsigned int hash) {
        return (aBigNumber * hash + data);
    }

    // usage example:
    void main(...){
        unsigned int myHash = startHashCode();
        while(!endOfFile){
           myData = readDataFromFile();
           myHash = addDataToHash(myData, myHash);
        }

        // ...use myHash somehow...

    }


being aSmallNumber something between 0 and 10, and aBigNumber something between 10 and 100 (both are fixed at compile-time, and both are better if odd or prime); hash is a number of bits of your choice (the higher, the lower collisions you'll obtain), while data can be of any number of bits supported by cpu...when an operation exceeds type ranges, the result re-raises from 0 following the well known pacman-rule :)
But things can change much... just experiment on a typical file of yours....or -obviously- you can use an already made hash function.

jean
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Thu Feb 28, 2008 4:02 am    Post subject: Reply with quote

The PSP has in built SHA1 hash functions, I recommend using something like that as some simple XOR or checksum is completely unreliable.
Back to top
View user's profile Send private message
pspZorba



Joined: 22 Sep 2007
Posts: 156
Location: NY

PostPosted: Thu Feb 28, 2008 5:08 am    Post subject: Reply with quote

Thanks guys for your answers.

so if I have well understood.

1) I apply a first SHA-1 hash function when I dump the NAND (on the whole dump file), I keep this first message digest. when I want to restore the nand I apply the SHA1 fonction on the dump file and compare the two message disgest. if they are equal then the file is not corrupt.

2) I apply a second SHA-1 on some IDS keys, I keep this second message disgest. when I want to restore the NAND, I apply again the SHA-1 to the ID Keys (of the actual NAND), I compare the results if they are the same then this dump is a dump of this PSP.

right ?
_________________
--pspZorba--
NO to K1.5 !
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group