format ELF
public _start

extrn SHA_HashBlock

section '.text' executable

_start:
    pusha

; Call all test vectors

    push    HashSize1
    push    OutHash1
    push    InHash1
    call    SHA_HashBlock

    push    HashSize2
    push    OutHash2
    push    InHash2
    call    SHA_HashBlock

    push    HashSize3
    push    OutHash3
    push    InHash3
    call    SHA_HashBlock

    push    HashSize4
    push    OutHash4
    push    InHash4
    call    SHA_HashBlock

    push    HashSize5
    push    OutHash5
    push    InHash5
    call    SHA_HashBlock

; Compare the results

    mov     edi, OutHash1
    mov     esi, Test1
	mov     ecx, 40

db 0xF3, 0xA7
    
    jnz     .e


; If success, output to console

	mov eax, 4
	mov ebx, 1
	mov ecx, SuccessMsg
	mov edx, SuccessMsg.len
	int 0x80
    jmp     .a

; On error, output error string

.e: mov eax, 4
	mov ebx, 1
	mov ecx, ErrorMsg
	mov edx, ErrorMsg.len
	int 0x80

.a:
	mov eax, 4
	mov ebx, 1
	mov ecx, KeyMsg
	mov edx, KeyMsg.len
	int 0x80

    popa

	mov eax, 1
	mov ebx, 0
	int 0x80


section '.data' writeable

; Hash sizes

HashSize1 = 3
HashSize2 = 56
HashSize3 = 43
HashSize4 = 43
HashSize5 = 0

; Hash string test vectors

InHash1 db 'abc'
InHash2 db 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
InHash3 db 'The quick brown fox jumps over the lazy dog'
InHash4 db 'The quick brown fox jumps over the lazy cog'
InHash5 db ''

; Hash function output buffers

OutHash1 rd 8
OutHash2 rd 8
OutHash3 rd 8
OutHash4 rd 8
OutHash5 rd 8

; Test vector hashed values

Test1	dd 0xba7816bf,0x8f01cfea,0x414140de,0x5dae2223
	dd 0xb00361a3,0x96177a9c,0xb410ff61,0xf20015ad

Test2	dd 0x248d6a61,0xd20638b8,0xe5c02693,0x0c3e6039
	dd 0xa33ce459,0x64ff2167,0xf6ecedd4,0x19db06c1

Test3	dd 0xd7a8fbb3,0x07d78094,0x69ca9abc,0xb0082e4f
	dd 0x8d5651e4,0x6d3cdb76,0x2d02d0bf,0x37c9e592

Test4	dd 0xe4c4d8f3,0xbf76b692,0xde791a17,0x3e053211
	dd 0x50f7a345,0xb46484fe,0x427f6acc,0x7ecc81be

Test5	dd 0xe3b0c442,0x98fc1c14,0x9afbf4c8,0x996fb924
	dd 0x27ae41e4,0x649b934c,0xa495991b,0x7852b855

; Error string

ErrorMsg db 'The code is not hashing correctly, please contact',13,10,'Alex Patterson at AlexPatterson@Hasd.org for support.',13,10
.len = $ - ErrorMsg

SuccessMsg db 'The code is working.  All five testing vectors have passed.',13,10
.len = $ - SuccessMsg

KeyMsg db 'Done.',13,10
.len = $ - KeyMsg

