Omnimaga

Calculator Community => TI Calculators => General Calculator Help => Topic started by: SirCmpwn on December 31, 2010, 08:56:52 pm

Title: Signing Programatically
Post by: SirCmpwn on December 31, 2010, 08:56:52 pm
Hello,
How would I programmatically sign an app or OS?
Title: Re: Signing Programatically
Post by: calcdude84se on December 31, 2010, 08:59:16 pm
Programmatically? What exactly do you mean? There is RabbitSign (http://www.ticalc.org/archives/files/fileinfo/420/42035.html) if you need a program.
Title: Re: Signing Programatically
Post by: DJ Omnimaga on December 31, 2010, 08:59:57 pm
Moved to calc help since this isn't exclusively KOS-related
Title: Re: Signing Programatically
Post by: SirCmpwn on December 31, 2010, 09:07:30 pm
How does RabbitSign work, I mean.
Title: Re: Signing Programatically
Post by: calcdude84se on December 31, 2010, 09:16:48 pm
It takes an unsigned .8xu and signs it. For an idea of how it works (and what other tools you need), you can look at my build script here (http://partesos.googlecode.com/svn-history/r12/trunk/build.bat)
Relevant lines:
Quote
..\tools\ostools-0.1\multihex 00 "Page $00.hex" 1D "Page $1D.hex" > os.hex
..\tools\ostools-0.1\packxxu os.hex -o os84.8xu -t 83p -q 0A -v 0.01 -h 255
..\tools\rabbitsign\rabbitsign -t 8xu -k ..\tools\keys\0A.key -K 0A -g -p -r os84.8xu
multihex (part of OS Tools (http://www.ticalc.org/archives/files/fileinfo/413/41336.html)) takes alternating page numbers and hex files for each page and generates a hex file for the whole OS.
packxxu, also from OS Tools, takes the unsigned hex file, a key ID, and a couple other things and generates an unsigned .8xu
rabbitsign, linked above, takes the key and the unsigned .8xu file and produces a signed one.
Title: Re: Signing Programatically
Post by: SirCmpwn on December 31, 2010, 09:17:49 pm
That's what it *does,* I want to know how it does it.
Title: Re: Signing Programatically
Post by: calcdude84se on December 31, 2010, 09:43:58 pm
As in, to write a tool yourself? Rabbitsign is opensource (written in C), so you could look at the source. I don't know the details, sorry :/
Title: Re: Signing Programatically
Post by: SirCmpwn on December 31, 2010, 11:08:34 pm
That's what I'm planning, for tiDE.  Thanks for the help :)
Title: Re: Signing Programatically
Post by: jnesselr on December 31, 2010, 11:09:47 pm
I think it uses the rabin Algorithm, yes?
Title: Re: Signing Programatically
Post by: SirCmpwn on December 31, 2010, 11:10:32 pm
Where is that algorithm documented?
Title: Re: Signing Programatically
Post by: DJ Omnimaga on December 31, 2010, 11:18:12 pm
From BrandonW on IRC

Quote
[23:14:25] <+BrandonW> A signature is an RSA-encrypted MD5 hash of the data you're wanting to sign.
[23:14:54] <+BrandonW> So you just MD5 hash the contents, and then encrypt it with 512-bit RSA using the private key associated with the ID you're wanting to sign with.
[23:15:15] <+BrandonW> So for example, to sign an OS with the 04 key, you take the 04 private key and use it to encrypt the MD5 hash of the OS.
Title: Re: Signing Programatically
Post by: SirCmpwn on December 31, 2010, 11:30:30 pm
Oh, okay.  And where does the signature data go?
Title: Re: Signing Programatically
Post by: jnesselr on December 31, 2010, 11:36:19 pm
At the en of the file, iirc. I believe you can use rabbitsign to see if the hash is correct. Md5 hashes are implemented in most popular languages.
Title: Re: Signing Programatically
Post by: BrandonW on December 31, 2010, 11:37:55 pm
That's a pretty loaded question and would take a while to answer. At the risk of sounding rude, I would recommend reading the source to see where it puts the signature after it calculates it ("MD5" and "Rabin"/"RSA" are things to look for to find where it calculates the signature and then does something with it).
Title: Re: Signing Programatically
Post by: SirCmpwn on January 01, 2011, 12:12:08 am
Thanks, will do.
Title: Re: Signing Programatically
Post by: FloppusMaximus on January 01, 2011, 06:37:28 pm
To be clear: RabbitSign implements both application and OS signing, which work somewhat differently, both in terms of the file formats, and in terms of the algorithms used (Rabin for Z80 applications; RSA for 68k apps and both Z80 and 68k OSes.)  Are you interested in signing apps, or OSes, or both?

You may want to read up on the Rabin (http://en.wikipedia.org/wiki/Rabin_cryptosystem) and RSA (http://en.wikipedia.org/wiki/RSA) algorithms before trying to understand how TI's system works.
Title: Re: Signing Programatically
Post by: jnesselr on January 01, 2011, 06:42:32 pm
He's probably interested in signing OSes, for KOS.

EDIT: or this is for tiDE, in which case, both.
Title: Re: Signing Programatically
Post by: FloppusMaximus on January 01, 2011, 07:38:36 pm
Well, to compute an OS signature, you take the MD5 hash of the complete OS (the OS header followed by each of the pages, in the order they're listed in the 8xu file), and sign that number using RSA, with a validation exponent of 17 decimal (if x is the MD5 hash, you want to find s such that s17x mod n.)

The signature, then, consists of the bytes 02 0D, followed by the length of s (in bytes), followed by the bytes of s in little-endian order (least significant first.)  Look at the OS files from TI to see how it's stored in the 8xu file.
Title: Re: Signing Programatically
Post by: jnesselr on January 01, 2011, 07:48:52 pm
Well, to compute an OS signature, you take the MD5 hash of the complete OS (the OS header followed by each of the pages, in the order they're listed in the 8xu file), and sign that number using RSA, with a validation exponent of 17 decimal (if x is the MD5 hash, you want to find s such that s17x mod n.)

The signature, then, consists of the bytes 02 0D, followed by the length of s (in bytes), followed by the bytes of s in little-endian order (least significant first.)  Look at the OS files from TI to see how it's stored in the 8xu file.
the "=" in "s17x mod n" is supposed to be congruence, correct?
Title: Re: Signing Programatically
Post by: FloppusMaximus on January 01, 2011, 09:13:07 pm
That's right.