-
Notifications
You must be signed in to change notification settings - Fork 1
/
Encryption.inc
81 lines (74 loc) · 1.75 KB
/
Encryption.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
%include "Substitution.inc" ; Substitution functions
%include "Rotation.inc" ; Rotation functions
%include "ColumnMixing.inc" ; Column mixing functions
%include "RoundKey.inc" ; Round key generation functions
%include "AuxillaryFunctions.inc" ; Auxillary misc. functions
section .data
mixedMessage TIMES 16 db 0
currentRoundKey TIMES 16 db 0
section .text
; Takes:
; esi: message
; edi: key
; Encrypts the message in esi
Encrypt:
; Add first round key
mov esi, key
mov edi, message
call XOR4x4Matrices
; Create the round keys
mov esi, key
call CreateRoundKeys
mov ecx, 10
mov ebx, 1
.NextRound:
push ebx
push ecx
mov ecx, 16
mov esi, message
mov edi, message
push ebx
mov bh,1
call SubstituteMessage
pop ebx
; mov esi, message
; call Print4x4Matrix
mov esi, message
mov bh,1
call RotateMessage
;mov esi, message
;call Print4x4Matrix
pop ecx
cmp ecx, 1
push ecx
je .skip
mov esi, message
mov edi, mixedMessage
call MixColumns
cld
mov esi, mixedMessage
mov edi, message
mov ecx, 16
rep movsb
; mov esi, message
; call Print4x4Matrix
.skip:
mov edi, currentRoundKey
pop ecx
pop ebx
mov eax, ebx
push ebx
push ecx
call GetRoundKey
; mov esi, currentRoundKey
; call Print4x4Matrix
mov esi, currentRoundKey
mov edi, message
call XOR4x4Matrices
; mov esi, mixedMessage
; call Print4x4Matrix
pop ecx
pop ebx
inc ebx
loop .NextRound
ret