summaryrefslogtreecommitdiff
path: root/assembly/passworddoor/sha256sum.S
diff options
context:
space:
mode:
Diffstat (limited to 'assembly/passworddoor/sha256sum.S')
-rw-r--r--assembly/passworddoor/sha256sum.S19
1 files changed, 18 insertions, 1 deletions
diff --git a/assembly/passworddoor/sha256sum.S b/assembly/passworddoor/sha256sum.S
index c2add42..657f4c5 100644
--- a/assembly/passworddoor/sha256sum.S
+++ b/assembly/passworddoor/sha256sum.S
@@ -2,6 +2,14 @@
sha256sum:
# WARNING: Clobbers a whole bunch of registers!
+
+csrr t0,mstatush
+bexti t0,t0,5 # Get current MBE
+la t1,origendian
+sb t0,0(t1) # Save it for later
+li t0,0x20
+csrs mstatush,t0 # And go big-endian
+
# Count the message length and replace the null terminator with 0x80
la t0,message
li t1,0
@@ -159,7 +167,14 @@ la t0,w
cbo.zero (t0) # Wipe memory used by hashing function
la t0,message
cbo.zero (t0) # Making sure to wipe the input too
-ret
+
+la t0,origendian
+lb t0,0(t0) # Read what MBE was at the start
+bnez t0,1f
+li t0,0x20
+csrc mstatush,t0 # If it was little, then put it back to little
+
+1: ret
horig: .word 0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19
h: .skip 8*4
@@ -180,3 +195,5 @@ w: .skip 64*4
message:
.word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
.word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
+
+origendian: .byte 0