summaryrefslogtreecommitdiff
path: root/crypto/bn/asm/x86w16.asm
blob: 74a933a8cddbe9a8e80ad9744a7b7b7eb390d360 (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
;	Static Name Aliases
;
	TITLE   bn_mulw.c
	.8087
F_TEXT	SEGMENT  WORD PUBLIC 'CODE'
F_TEXT	ENDS
_DATA	SEGMENT  WORD PUBLIC 'DATA'
_DATA	ENDS
CONST	SEGMENT  WORD PUBLIC 'CONST'
CONST	ENDS
_BSS	SEGMENT  WORD PUBLIC 'BSS'
_BSS	ENDS
DGROUP	GROUP	CONST, _BSS, _DATA
	ASSUME DS: DGROUP, SS: DGROUP
F_TEXT      SEGMENT
	ASSUME	CS: F_TEXT
	PUBLIC	_bn_mul_add_words
_bn_mul_add_words	PROC FAR
; Line 58
	push	bp
	push	bx
	push	si
	push	di
	push	ds
	push	es
	mov	bp,sp
;	w = 26
;	num = 24
;	ap = 20
;	rp = 16
	xor	si,si			;c=0;
	mov	di,WORD PTR [bp+16]	; load r
	mov	ds,WORD PTR [bp+18]	; load r
	mov	bx,WORD PTR [bp+20]	; load a
	mov	es,WORD PTR [bp+22]	; load a
	mov	cx,WORD PTR [bp+26]	; load w
	mov	bp,WORD PTR [bp+24]	; load num

	shr	bp,1	; div count by 4 and do groups of 4
	shr	bp,1
	je	$L555

$L546:
	mov	ax,cx
	mul	WORD PTR es:[bx]	; w* *a
	add	ax,WORD PTR ds:[di]	; + *r
	adc	dx,0
	adc	ax,si
	adc	dx,0
	mov	WORD PTR ds:[di],ax
	mov	si,dx
	;
	mov	ax,cx
	mul	WORD PTR es:[bx+2]	; w* *a
	add	ax,WORD PTR ds:[di+2]	; + *r
	adc	dx,0
	adc	ax,si
	adc	dx,0
	mov	WORD PTR ds:[di+2],ax
	mov	si,dx
	;
	mov	ax,cx
	mul	WORD PTR es:[bx+4]	; w* *a
	add	ax,WORD PTR ds:[di+4]	; + *r
	adc	dx,0
	adc	ax,si
	adc	dx,0
	mov	WORD PTR ds:[di+4],ax
	mov	si,dx
	;
	mov	ax,cx
	mul	WORD PTR es:[bx+6]	; w* *a
	add	ax,WORD PTR ds:[di+6]	; + *r
	adc	dx,0
	adc	ax,si
	adc	dx,0
	mov	WORD PTR ds:[di+6],ax
	mov	si,dx
	;
	add	bx,8
	add	di,8
	;
	dec	bp
	je	$L555
	jmp	$L546
;
;
$L555:
	mov	bp,sp
	mov	bp,WORD PTR [bp+24]	; load num
	and	bp,3
	dec	bp
	js	$L547

	mov	ax,cx
	mul	WORD PTR es:[bx]	; w* *a
	add	ax,WORD PTR ds:[di]	; + *r
	adc	dx,0
	adc	ax,si
	adc	dx,0
	mov	WORD PTR ds:[di],ax
	mov	si,dx
	dec	bp
	js	$L547			; Note that we are now testing for -1
	;
	mov	ax,cx
	mul	WORD PTR es:[bx+2]	; w* *a
	add	ax,WORD PTR ds:[di+2]	; + *r
	adc	dx,0
	adc	ax,si
	adc	dx,0
	mov	WORD PTR ds:[di+2],ax
	mov	si,dx
	dec	bp
	js	$L547
	;
	mov	ax,cx
	mul	WORD PTR es:[bx+4]	; w* *a
	add	ax,WORD PTR ds:[di+4]	; + *r
	adc	dx,0
	adc	ax,si
	adc	dx,0
	mov	WORD PTR ds:[di+4],ax
	mov	si,dx
$L547:
	mov	ax,si
	pop	es
	pop	ds
	pop	di
	pop	si
	pop	bx
	pop	bp
	ret	
	nop	

_bn_mul_add_words	ENDP
	PUBLIC	_bn_mul_words
_bn_mul_words	PROC FAR
; Line 76
	push	bp
	push	bx
	push	si
	push	di
	push	ds
	push	es
	xor	si,si
	mov	bp,sp
	mov	di,WORD PTR [bp+16]	; r
	mov	ds,WORD PTR [bp+18]
	mov	bx,WORD PTR [bp+20]	; a
	mov	es,WORD PTR [bp+22]
	mov	cx,WORD PTR [bp+26]	; w
	mov	bp,WORD PTR [bp+24]	; num 
$FC743:
	mov	ax,cx
	mul	WORD PTR es:[bx]
	add	ax,si
	adc	dx,0
	mov	WORD PTR ds:[di],ax
	mov	si,dx
	dec	bp
	je	$L764
	;
	mov	ax,cx
	mul	WORD PTR es:[bx+2]
	add	ax,si
	adc	dx,0
	mov	WORD PTR ds:[di+2],ax
	mov	si,dx
	dec	bp
	je	$L764
	;
	mov	ax,cx
	mul	WORD PTR es:[bx+4]
	add	ax,si
	adc	dx,0
	mov	WORD PTR ds:[di+4],ax
	mov	si,dx
	dec	bp
	je	$L764
	;
	mov	ax,cx
	mul	WORD PTR es:[bx+6]
	add	ax,si
	adc	dx,0
	mov	WORD PTR ds:[di+6],ax
	mov	si,dx
	dec	bp
	je	$L764
	;
	add	bx,8
	add	di,8
	jmp	$FC743
	nop
$L764:
	mov	ax,si
	pop	es
	pop	ds
	pop	di
	pop	si
	pop	bx
	pop	bp
	ret	
	nop	
_bn_mul_words	ENDP
	PUBLIC	_bn_sqr_words
_bn_sqr_words	PROC FAR
; Line 92
	push	bp
	push	bx
	push	si
	push	di
	push	ds
	push	es
	mov	bp,sp
	mov	si,WORD PTR [bp+16]
	mov	ds,WORD PTR [bp+18]
	mov	di,WORD PTR [bp+20]
	mov	es,WORD PTR [bp+22]
	mov	bx,WORD PTR [bp+24]

	mov	bp,bx	; save a memory lookup later
	shr	bx,1	; div count by 4 and do groups of 4
	shr	bx,1
	je	$L666

$L765:
	mov	ax,WORD PTR es:[di]
	mul	ax
	mov	WORD PTR ds:[si],ax
	mov	WORD PTR ds:[si+2],dx
	;
	mov	ax,WORD PTR es:[di+2]
	mul	ax
	mov	WORD PTR ds:[si+4],ax
	mov	WORD PTR ds:[si+6],dx
	;
	mov	ax,WORD PTR es:[di+4]
	mul	ax
	mov	WORD PTR ds:[si+8],ax
	mov	WORD PTR ds:[si+10],dx
	;
	mov	ax,WORD PTR es:[di+6]
	mul	ax
	mov	WORD PTR ds:[si+12],ax
	mov	WORD PTR ds:[si+14],dx
	;
	add	di,8
	add	si,16
	dec	bx
	je	$L666
	jmp	$L765
$L666:
	and	bp,3
	dec	bp	; The copied value of bx (num)
	js	$L645
	;
	mov	ax,WORD PTR es:[di]
	mul	ax
	mov	WORD PTR ds:[si],ax
	mov	WORD PTR ds:[si+2],dx
	dec	bp
	js	$L645
	;
	mov	ax,WORD PTR es:[di+2]
	mul	ax
	mov	WORD PTR ds:[si+4],ax
	mov	WORD PTR ds:[si+6],dx
	dec	bp
	js	$L645
	;
	mov	ax,WORD PTR es:[di+4]
	mul	ax
	mov	WORD PTR ds:[si+8],ax
	mov	WORD PTR ds:[si+10],dx
$L645:
	pop	es
	pop	ds
	pop	di
	pop	si
	pop	bx
	pop	bp
	ret	

_bn_sqr_words	ENDP
	PUBLIC	_bn_div64
_bn_div64	PROC FAR
	push	bp
	mov	bp,sp
	mov	dx, WORD PTR [bp+6]
	mov	ax, WORD PTR [bp+8]
	div	WORD PTR [bp+10]
	pop	bp
	ret	
_bn_div64	ENDP
F_TEXT	ENDS
END