Subversion Repositories Kolibri OS

Rev

Rev 6419 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6419 hidnplayr 1
;    modexp.asm - Modular exponentiation test suite
2
;
6922 hidnplayr 3
;    Copyright (C) 2015-2017 Jeffrey Amelynck
6419 hidnplayr 4
;
5
;    This program is free software: you can redistribute it and/or modify
6
;    it under the terms of the GNU General Public License as published by
7
;    the Free Software Foundation, either version 3 of the License, or
8
;    (at your option) any later version.
9
;
10
;    This program is distributed in the hope that it will be useful,
11
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;    GNU General Public License for more details.
14
;
15
;    You should have received a copy of the GNU General Public License
16
;    along with this program.  If not, see .
17
 
18
format binary as ""
19
 
20
__DEBUG__       = 1
21
__DEBUG_LEVEL__ = 1
22
 
6922 hidnplayr 23
MAX_BITS        = 512
6419 hidnplayr 24
 
25
use32
26
 
27
        db      'MENUET01'      ; signature
28
        dd      1               ; header version
29
        dd      start           ; entry point
30
        dd      i_end           ; initialized size
6922 hidnplayr 31
        dd      mem+65536       ; required memory
32
        dd      mem+65536       ; stack pointer
6419 hidnplayr 33
        dd      0               ; parameters
34
        dd      0               ; path
35
 
36
include '../../../macros.inc'
37
purge mov,add,sub
38
include '../../../proc32.inc'
39
include '../../../debug-fdo.inc'
40
 
41
include '../mpint.inc'
42
 
43
start:
44
 
45
        DEBUGF  1, "ModExp Test suite\n"
46
 
6922 hidnplayr 47
        DEBUGF  1, "mpint_print(0x0)\n"
48
        mov     dword[mpint_A+00], 0
6419 hidnplayr 49
        stdcall mpint_print, mpint_A
50
 
51
        mov     dword[mpint_A+00], 32
52
        mov     dword[mpint_A+04], 0xCAFEBABE
53
        mov     dword[mpint_A+08], 0xDEADBEEF
54
        mov     dword[mpint_A+12], 0xCAFEBABE
55
        mov     dword[mpint_A+16], 0xDEADBEEF
56
        mov     dword[mpint_A+20], 0xCAFEBABE
57
        mov     dword[mpint_A+24], 0xDEADBEEF
58
        mov     dword[mpint_A+28], 0xCAFEBABE
59
        mov     dword[mpint_A+32], 0xDEADBEEF
6922 hidnplayr 60
        DEBUGF  1, "mpint_print(0xCAFEBABEDEADBEEF...)\n"
6419 hidnplayr 61
        stdcall mpint_print, mpint_A
62
 
6922 hidnplayr 63
        DEBUGF  1, "mpint_shl(A, 3)\n"
6419 hidnplayr 64
        stdcall mpint_shl, mpint_A, 3
65
        stdcall mpint_print, mpint_A
66
 
6922 hidnplayr 67
        DEBUGF  1, "mpint_shl(A, 29)\n"
68
        stdcall mpint_shl, mpint_A, 29
6419 hidnplayr 69
        stdcall mpint_print, mpint_A
70
 
71
        DEBUGF  1, "8 times mpint_shl1\n"
72
        stdcall mpint_shl1, mpint_A
6922 hidnplayr 73
        stdcall mpint_print, mpint_A
6419 hidnplayr 74
        stdcall mpint_shl1, mpint_A
6922 hidnplayr 75
        stdcall mpint_print, mpint_A
6419 hidnplayr 76
        stdcall mpint_shl1, mpint_A
6922 hidnplayr 77
        stdcall mpint_print, mpint_A
6419 hidnplayr 78
        stdcall mpint_shl1, mpint_A
6922 hidnplayr 79
        stdcall mpint_print, mpint_A
6419 hidnplayr 80
        stdcall mpint_shl1, mpint_A
6922 hidnplayr 81
        stdcall mpint_print, mpint_A
6419 hidnplayr 82
        stdcall mpint_shl1, mpint_A
6922 hidnplayr 83
        stdcall mpint_print, mpint_A
6419 hidnplayr 84
        stdcall mpint_shl1, mpint_A
6922 hidnplayr 85
        stdcall mpint_print, mpint_A
6419 hidnplayr 86
        stdcall mpint_shl1, mpint_A
87
        stdcall mpint_print, mpint_A
88
 
89
        mov     dword[mpint_B+00], 32
90
        mov     dword[mpint_B+04], 0xCAFEBABE
91
        mov     dword[mpint_B+08], 0xDEADBEEF
92
        mov     dword[mpint_B+12], 0xCAFEBABE
93
        mov     dword[mpint_B+16], 0xDEADBEEF
94
        mov     dword[mpint_B+20], 0xCAFEBABE
95
        mov     dword[mpint_B+24], 0xDEADBEEF
96
        mov     dword[mpint_B+28], 0xCAFEBABE
97
        mov     dword[mpint_B+32], 0xDEADBEEF
6922 hidnplayr 98
        DEBUGF  1, "mpint_print(A)\n"
6419 hidnplayr 99
        stdcall mpint_print, mpint_A
6922 hidnplayr 100
        DEBUGF  1, "mpint_print(B)\n"
6419 hidnplayr 101
        stdcall mpint_print, mpint_B
6922 hidnplayr 102
        DEBUGF  1, "mpint_add(B, A)\n"
6419 hidnplayr 103
        stdcall mpint_add, mpint_B, mpint_A
104
        stdcall mpint_print, mpint_B
6922 hidnplayr 105
        DEBUGF  1, "mpint_sub(B, A)\n"
6419 hidnplayr 106
        stdcall mpint_sub, mpint_B, mpint_A
107
        stdcall mpint_print, mpint_B
108
 
6922 hidnplayr 109
        mov     dword[mpint_B+00], 24
6419 hidnplayr 110
        mov     dword[mpint_B+04], 0xCAFEBABE
111
        mov     dword[mpint_B+08], 0xDEADBEEF
112
        mov     dword[mpint_B+12], 0xCAFEBABE
113
        mov     dword[mpint_B+16], 0xDEADBEEF
114
        mov     dword[mpint_B+20], 0xCAFEBABE
115
        mov     dword[mpint_B+24], 0xDEADBEEF
6922 hidnplayr 116
        DEBUGF  1, "mpint_print(A)\n"
6419 hidnplayr 117
        stdcall mpint_print, mpint_A
6922 hidnplayr 118
        DEBUGF  1, "mpint_print(B)\n"
6419 hidnplayr 119
        stdcall mpint_print, mpint_B
6922 hidnplayr 120
        DEBUGF  1, "mpint_mod(A, B)\n"
6419 hidnplayr 121
        stdcall mpint_mod, mpint_A, mpint_B
122
        stdcall mpint_print, mpint_A
123
 
124
        mov     dword[mpint_A+0], 2
125
        mov     dword[mpint_A+4], 1936
126
        mov     dword[mpint_B+0], 2
127
        mov     dword[mpint_B+4], 497
128
        stdcall mpint_cmp, mpint_A, mpint_B
129
        stdcall mpint_mod, mpint_A, mpint_B
6922 hidnplayr 130
        DEBUGF  1, "mpint_mod(936, 497)\n"
6419 hidnplayr 131
        stdcall mpint_print, mpint_A
132
 
133
        mov     dword[mpint_A+00], 32
6922 hidnplayr 134
        mov     dword[mpint_A+04], 0x11111111
135
        mov     dword[mpint_A+08], 0x22222222
136
        mov     dword[mpint_A+12], 0x33333333
137
        mov     dword[mpint_A+16], 0x44444444
138
        mov     dword[mpint_A+20], 0x55555555
139
        mov     dword[mpint_A+24], 0x88888888
140
        mov     dword[mpint_A+28], 0xAAAAAAAA
141
        mov     dword[mpint_A+32], 0xCCCCCCCC
142
 
6419 hidnplayr 143
        mov     dword[mpint_B+0], 2
144
        mov     dword[mpint_B+4], 0x0100
6922 hidnplayr 145
        DEBUGF  1, "mpint_print(A)\n"
6419 hidnplayr 146
        stdcall mpint_print, mpint_A
6922 hidnplayr 147
        DEBUGF  1, "mpint_print(B)\n"
6419 hidnplayr 148
        stdcall mpint_print, mpint_B
6922 hidnplayr 149
        DEBUGF  1, "mpint_mul(C, A, B)\n"
6419 hidnplayr 150
        stdcall mpint_mul, mpint_C, mpint_A, mpint_B
151
        stdcall mpint_print, mpint_C
152
        stdcall mpint_print, mpint_A
153
        stdcall mpint_print, mpint_B
6922 hidnplayr 154
        DEBUGF  1, "mpint_mul(C, B, A)\n"
6419 hidnplayr 155
        stdcall mpint_mul, mpint_C, mpint_B, mpint_A
156
        stdcall mpint_print, mpint_C
157
 
158
        stdcall mpint_hob, mpint_C
6922 hidnplayr 159
        DEBUGF  1, "mpint_hob(C): %u\n", eax
6419 hidnplayr 160
 
161
        mov     dword[mpint_A+0], 1
6922 hidnplayr 162
        mov     dword[mpint_A+4], 3
6419 hidnplayr 163
        mov     dword[mpint_B+0], 1
6922 hidnplayr 164
        mov     dword[mpint_B+4], 4
6419 hidnplayr 165
        mov     dword[mpint_C+0], 2
6922 hidnplayr 166
        mov     dword[mpint_C+4], 5
6419 hidnplayr 167
        stdcall mpint_modexp, mpint_D, mpint_A, mpint_B, mpint_C
6922 hidnplayr 168
        DEBUGF  1, "mpint_modexp(3, 4, 5)\n"
6419 hidnplayr 169
        stdcall mpint_print, mpint_D
170
 
171
        mcall   -1
172
 
173
i_end:
174
 
175
mpint_A         rb MPINT_MAX_LEN+4
176
mpint_B         rb MPINT_MAX_LEN+4
177
mpint_C         rb MPINT_MAX_LEN+4
178
mpint_D         rb MPINT_MAX_LEN+4
179
 
180
mpint_tmp       rb MPINT_MAX_LEN+4
181
 
182
include_debug_strings
183
 
184
mem: