Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: ACagliano on September 14, 2010, 07:53:32 pm

Title: CheckSums in Axe?
Post by: ACagliano on September 14, 2010, 07:53:32 pm
First off, what exactly is a checksum on a calculator? What does it check and how does it work?

And, can it be calculated using Axe? If so, how exactly would I perform a checksum on all programs in either RAM or Archive, but only the programs and nothing else?

Then, how would you perform a checksum on the operating system?

**I would like to do this in Axe, if possible.
Title: Re: CheckSums in Axe?
Post by: calcdude84se on September 14, 2010, 07:56:35 pm
Checksum? There are several forms. The simplest is the sum of all bytes mod 16.
Example code that displays the checksum of prgmTEST in RAM:
Code: [Select]
GetCalc("prgmTEST")->P
0->A
{P-2}r+P-1->E
For(X,P,E
A+{X}->A
End
Disp A>Dec
Title: Re: CheckSums in Axe?
Post by: ACagliano on September 14, 2010, 08:01:16 pm
And what should the sum be? How do I use it to decide if something is not right?
Title: Re: CheckSums in Axe?
Post by: calcdude84se on September 14, 2010, 08:04:35 pm
It depends on what you're checksumming ;D
In short, you'd calculate it for the normal version, and check with something else.
Also, there are more advanced algorithms which make faking more difficult. (The checksum example I gave is more for error-checking than anything else, and is easily bypassed) However, I'm not sure how practical some of them are.
Title: Re: CheckSums in Axe?
Post by: ACagliano on September 14, 2010, 08:08:15 pm
Ok. What sort of errors would your above method check for?

And can the OS itself be checksummed in Axe, or would that need asm?
Title: Re: CheckSums in Axe?
Post by: Deep Toaster on September 14, 2010, 08:15:50 pm
Every checksum is different. It all depends on the guy who made it.
Title: Re: CheckSums in Axe?
Post by: calcdude84se on September 14, 2010, 08:17:41 pm
Typically transmission errors (TI's transfer protocol uses it).
It can as soon as the degree sign (for address-of) becomes official. (You have to be able to select an arbitrary page, which can be done by manually setting a "file pointer")
Title: Re: CheckSums in Axe?
Post by: ACagliano on September 14, 2010, 08:19:33 pm
Could someone, if they have the time, write an asm routine that calculates a simple checksum of the OS and saves it to an appvar, "BChkSav", overwriting an old one if it is found. If it isn't too much of a problem. It might be an interesting addition to a secret program I am working on.
Title: Re: CheckSums in Axe?
Post by: jnesselr on September 14, 2010, 09:03:32 pm
Could someone, if they have the time, write an asm routine that calculates a simple checksum of the OS and saves it to an appvar, "BChkSav", overwriting an old one if it is found. If it isn't too much of a problem. It might be an interesting addition to a secret program I am working on.
Your better off with something like an MD5 hash, as a checksum could be easily foiled by adding an extra word somewhere so the checksums align themselves.
Title: Re: CheckSums in Axe?
Post by: ACagliano on September 15, 2010, 10:03:28 am
Well, what exactly does an MD5 hash do?

And, in that case can someone please write one for the OS, since I don't know asm.
Title: Re: CheckSums in Axe?
Post by: calcdude84se on September 15, 2010, 06:57:08 pm
MD5... that seems to be a bit too much :P
It's another hash function, and has some desirable features including the difficulty of making something with a certain hash.
Only problem is computing it will take a bit longer than you would probably like (probably on the scale of a couple programs a second) because it involves 32-bit calculations, which are more difficult in Axe.
However, MD5 is not very secure (a few seconds on a modern PC to break it), and moving to SHA-2 is, best put, ridiculous.
It mainly depends on the protection you want. If you want more than a simple checksum or variations thereof, I can only think of MD5...
Somebody else can probably tell you more than I have ;D
Link to documentation on MD5 (http://en.wikipedia.org/wiki/MD5)
Title: Re: CheckSums in Axe?
Post by: ACagliano on September 16, 2010, 06:34:20 pm
What would be the best sort of a check to search for basic errors or changes in OS data due to a badly written or malicious program. That's what my goal is.
Title: Re: CheckSums in Axe?
Post by: calcdude84se on September 16, 2010, 06:44:39 pm
Badly written is easy. Malicious is what's difficult.
For badly written, a checksum is more than enough. You just need to increase the size of the checksum to increase security (Though only 2 bytes should be necessary anyway)
Malicious is harder, but by increasing the checksum size to, say, 4 bytes instead of 2, it becomes harder for a program to change the OS without changing the checksum.
I'll write some ASM to create a 2-byte checksum of the OS and return it in hl (for Axe purposes).
* calcdude goes and codes
Title: Re: CheckSums in Axe?
Post by: ACagliano on September 16, 2010, 07:30:42 pm
Thank you very much.


Oh, and question.

Would a properly written OS patch, like the PTT patch change the checksum, or would it only change for something badly written?
Title: Re: CheckSums in Axe?
Post by: thepenguin77 on September 16, 2010, 08:34:32 pm
Any change to the OS good or bad would change the checksum. Also, I wouldn't worry about accidental changes to the OS because that is close to impossible to do by accident. Besides, the ones that happen by accident require an OS reinstall because the calculator would not even be able to boot.
Title: Re: CheckSums in Axe?
Post by: ACagliano on September 17, 2010, 06:26:55 pm
So what would you recommend?
Title: Re: CheckSums in Axe?
Post by: calcdude84se on September 17, 2010, 07:24:19 pm
Here's the source code and hex for the checksumming routine
Code: [Select]
  di
  in a,($06)
  push af
  ld hl,$0000
  ld bc,$0700
  jr go
ComeBack:
  in a,($02)
  bit 5,a
  jr nz,TI84P
  bit 7,a
  jr nz,TI83PSE
  ld bc,$1F18
  jr go
TI83PSE:
  ld b,$7F78
  jr go
TI84P:
  in a,($21)
  bit 0,a
  jr nz,TI84PSE
  ld bc,$3F34
  jr go
TI84PSE:
  ld bc,$7F74
go:
  ld a,b
  out ($06),a
  ld de,$4000
loopi:
  ld a,(de)
  add a,l
  ld l,a
  adc a,h
  sub l
  ld h,a
  inc de
  ld a,d
  cp $80
  jr c,loopi
  dec b
  ld a,c
  cp b
  jr c,go
  ld a,c
  or a
  jr z,ComeBack
  pop af
  out ($06),a
  ret
Code: [Select]
F3DB06F52100000100071821DB02CB6F200DCB7F200501181F18120678180EDB21CB47200501343F180301747F78D3061100401A856F8C9567137AFE8038F40579B838E979B728C4F1D306C9I've tested it and it doesn't crash. Note that it should be its own subroutine because it returns when it's done.
On my calc, it took a couple seconds to run (I enclosed it in an Axe program).
Title: Re: CheckSums in Axe?
Post by: Quigibo on September 17, 2010, 08:36:45 pm
There are built in MD5 bcalls by the way to validate apps, but that would probably be overkill anyway.
Title: Re: CheckSums in Axe?
Post by: ACagliano on September 18, 2010, 09:50:02 am
Here's the source code and hex for the checksumming routine
Code: [Select]
 di
  in a,($06)
  push af
  ld hl,$0000
  ld bc,$0700
  jr go
ComeBack:
  in a,($02)
  bit 5,a
  jr nz,TI84P
  bit 7,a
  jr nz,TI83PSE
  ld bc,$1F18
  jr go
TI83PSE:
  ld b,$7F78
  jr go
TI84P:
  in a,($21)
  bit 0,a
  jr nz,TI84PSE
  ld bc,$3F34
  jr go
TI84PSE:
  ld bc,$7F74
go:
  ld a,b
  out ($06),a
  ld de,$4000
loopi:
  ld a,(de)
  add a,l
  ld l,a
  adc a,h
  sub l
  ld h,a
  inc de
  ld a,d
  cp $80
  jr c,loopi
  dec b
  ld a,c
  cp b
  jr c,go
  ld a,c
  or a
  jr z,ComeBack
  pop af
  out ($06),a
  ret
Code: [Select]
F3DB06F52100000100071821DB02CB6F200DCB7F200501181F18120678180EDB21CB47200501343F180301747F78D3061100401A856F8C9567137AFE8038F40579B838E979B728C4F1D306C9I've tested it and it doesn't crash. Note that it should be its own subroutine because it returns when it's done.
On my calc, it took a couple seconds to run (I enclosed it in an Axe program).

Ran it. It returns 0. Is that right, or is it not working?  And what var does it return into? How do I access it from Axe?
Title: Re: CheckSums in Axe?
Post by: calcdude84se on September 19, 2010, 11:53:35 am
Use it like this:
Code: [Select]
Disp sub(C)>Dec
Return
Lbl C
.ASM code from above
Use it as you would any other expression. (My example displays the checksum)
Title: Re: CheckSums in Axe?
Post by: ACagliano on September 19, 2010, 02:30:31 pm
Excellent. And how would I save the result into an arbitrary appvar?
Title: Re: CheckSums in Axe?
Post by: calcdude84se on September 19, 2010, 02:35:50 pm
Supposing the appvar is called "appvCHECKSUM"
Code: [Select]
Return!If GetCalc("appvCHECKSUM",2)->X
sub(C)->{X}r
Note that this example doesn't check if the appvar already exists, and assumes subroutine C as above.
And again, the process takes a couple seconds.
Title: Re: CheckSums in Axe?
Post by: ACagliano on September 19, 2010, 02:44:32 pm
thanks