Omnimaga
Calculator Community => TI Calculators => Axe => Topic started 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.
-
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:
GetCalc("prgmTEST")->P
0->A
{P-2}r+P-1->E
For(X,P,E
A+{X}->A
End
Disp A>Dec
-
And what should the sum be? How do I use it to decide if something is not right?
-
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.
-
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?
-
Every checksum is different. It all depends on the guy who made it.
-
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")
-
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.
-
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.
-
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.
-
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)
-
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.
-
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
-
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?
-
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.
-
So what would you recommend?
-
Here's the source code and hex for the checksumming routine
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
F3DB06F52100000100071821DB02CB6F200DCB7F200501181F18120678180EDB21CB47200501343F180301747F78D3061100401A856F8C9567137AFE8038F40579B838E979B728C4F1D306C9
I'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).
-
There are built in MD5 bcalls by the way to validate apps, but that would probably be overkill anyway.
-
Here's the source code and hex for the checksumming routine
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
F3DB06F52100000100071821DB02CB6F200DCB7F200501181F18120678180EDB21CB47200501343F180301747F78D3061100401A856F8C9567137AFE8038F40579B838E979B728C4F1D306C9
I'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?
-
Use it like this:
Disp sub(C)>Dec
Return
Lbl C
.ASM code from above
Use it as you would any other expression. (My example displays the checksum)
-
Excellent. And how would I save the result into an arbitrary appvar?
-
Supposing the appvar is called "appvCHECKSUM"
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.
-
thanks