1/* Copyright (c) 2015, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15/* This file is adapted from crypto_scalarmult/curve25519/amd64-51/ in
16 * SUPERCOP 20141124 (http://bench.cr.yp.to/supercop.html). That code is public
17 * domain licensed but the standard ISC license is included above to keep
18 * licensing simple. */
19
20.data
21.p2align 4
22
23#if defined(__APPLE__)
24/* OS X's C ABI prefixes functions with underscore. */
25#define C_ABI(x) _ ## x
26#define HIDDEN .private_extern
27#else
28#define C_ABI(x) x
29#define HIDDEN .hidden
30#endif
31
32x25519_x86_64_REDMASK51:   .quad 0x0007FFFFFFFFFFFF
33x25519_x86_64_121666_213:  .quad 996687872
34x25519_x86_64_2P0:         .quad 0xFFFFFFFFFFFDA
35x25519_x86_64_2P1234:      .quad 0xFFFFFFFFFFFFE
36x25519_x86_64_4P0:         .quad 0x1FFFFFFFFFFFB4
37x25519_x86_64_4P1234:      .quad 0x1FFFFFFFFFFFFC
38x25519_x86_64_MU0:         .quad 0xED9CE5A30A2C131B
39x25519_x86_64_MU1:         .quad 0x2106215D086329A7
40x25519_x86_64_MU2:         .quad 0xFFFFFFFFFFFFFFEB
41x25519_x86_64_MU3:         .quad 0xFFFFFFFFFFFFFFFF
42x25519_x86_64_MU4:         .quad 0x000000000000000F
43x25519_x86_64_ORDER0:      .quad 0x5812631A5CF5D3ED
44x25519_x86_64_ORDER1:      .quad 0x14DEF9DEA2F79CD6
45x25519_x86_64_ORDER2:      .quad 0x0000000000000000
46x25519_x86_64_ORDER3:      .quad 0x1000000000000000
47x25519_x86_64_EC2D0:       .quad 1859910466990425
48x25519_x86_64_EC2D1:       .quad 932731440258426
49x25519_x86_64_EC2D2:       .quad 1072319116312658
50x25519_x86_64_EC2D3:       .quad 1815898335770999
51x25519_x86_64_EC2D4:       .quad 633789495995903
52x25519_x86_64__38:         .quad 38
53
54.text
55.p2align 5
56
57.globl C_ABI(x25519_x86_64_freeze)
58HIDDEN C_ABI(x25519_x86_64_freeze)
59C_ABI(x25519_x86_64_freeze):
60mov %rsp,%r11
61and $31,%r11
62add $64,%r11
63sub %r11,%rsp
64movq %r11,0(%rsp)
65movq %r12,8(%rsp)
66movq %r13,16(%rsp)
67movq %r14,24(%rsp)
68movq %r15,32(%rsp)
69movq %rbx,40(%rsp)
70movq %rbp,48(%rsp)
71movq   0(%rdi),%rsi
72movq   8(%rdi),%rdx
73movq   16(%rdi),%rcx
74movq   24(%rdi),%r8
75movq   32(%rdi),%r9
76movq x25519_x86_64_REDMASK51(%rip),%rax
77mov  %rax,%r10
78sub  $18,%r10
79mov  $3,%r11
80._reduceloop:
81mov  %rsi,%r12
82shr  $51,%r12
83and  %rax,%rsi
84add  %r12,%rdx
85mov  %rdx,%r12
86shr  $51,%r12
87and  %rax,%rdx
88add  %r12,%rcx
89mov  %rcx,%r12
90shr  $51,%r12
91and  %rax,%rcx
92add  %r12,%r8
93mov  %r8,%r12
94shr  $51,%r12
95and  %rax,%r8
96add  %r12,%r9
97mov  %r9,%r12
98shr  $51,%r12
99and  %rax,%r9
100imulq  $19,%r12,%r12
101add  %r12,%rsi
102sub  $1,%r11
103ja ._reduceloop
104mov  $1,%r12
105cmp  %r10,%rsi
106cmovl %r11,%r12
107cmp  %rax,%rdx
108cmovne %r11,%r12
109cmp  %rax,%rcx
110cmovne %r11,%r12
111cmp  %rax,%r8
112cmovne %r11,%r12
113cmp  %rax,%r9
114cmovne %r11,%r12
115neg  %r12
116and  %r12,%rax
117and  %r12,%r10
118sub  %r10,%rsi
119sub  %rax,%rdx
120sub  %rax,%rcx
121sub  %rax,%r8
122sub  %rax,%r9
123movq   %rsi,0(%rdi)
124movq   %rdx,8(%rdi)
125movq   %rcx,16(%rdi)
126movq   %r8,24(%rdi)
127movq   %r9,32(%rdi)
128movq 0(%rsp),%r11
129movq 8(%rsp),%r12
130movq 16(%rsp),%r13
131movq 24(%rsp),%r14
132movq 32(%rsp),%r15
133movq 40(%rsp),%rbx
134movq 48(%rsp),%rbp
135add %r11,%rsp
136mov %rdi,%rax
137mov %rsi,%rdx
138ret
139
140.p2align 5
141.globl C_ABI(x25519_x86_64_mul)
142HIDDEN C_ABI(x25519_x86_64_mul)
143C_ABI(x25519_x86_64_mul):
144mov %rsp,%r11
145and $31,%r11
146add $96,%r11
147sub %r11,%rsp
148movq %r11,0(%rsp)
149movq %r12,8(%rsp)
150movq %r13,16(%rsp)
151movq %r14,24(%rsp)
152movq %r15,32(%rsp)
153movq %rbx,40(%rsp)
154movq %rbp,48(%rsp)
155movq %rdi,56(%rsp)
156mov  %rdx,%rcx
157movq   24(%rsi),%rdx
158imulq  $19,%rdx,%rax
159movq %rax,64(%rsp)
160mulq  16(%rcx)
161mov  %rax,%r8
162mov  %rdx,%r9
163movq   32(%rsi),%rdx
164imulq  $19,%rdx,%rax
165movq %rax,72(%rsp)
166mulq  8(%rcx)
167add  %rax,%r8
168adc %rdx,%r9
169movq   0(%rsi),%rax
170mulq  0(%rcx)
171add  %rax,%r8
172adc %rdx,%r9
173movq   0(%rsi),%rax
174mulq  8(%rcx)
175mov  %rax,%r10
176mov  %rdx,%r11
177movq   0(%rsi),%rax
178mulq  16(%rcx)
179mov  %rax,%r12
180mov  %rdx,%r13
181movq   0(%rsi),%rax
182mulq  24(%rcx)
183mov  %rax,%r14
184mov  %rdx,%r15
185movq   0(%rsi),%rax
186mulq  32(%rcx)
187mov  %rax,%rbx
188mov  %rdx,%rbp
189movq   8(%rsi),%rax
190mulq  0(%rcx)
191add  %rax,%r10
192adc %rdx,%r11
193movq   8(%rsi),%rax
194mulq  8(%rcx)
195add  %rax,%r12
196adc %rdx,%r13
197movq   8(%rsi),%rax
198mulq  16(%rcx)
199add  %rax,%r14
200adc %rdx,%r15
201movq   8(%rsi),%rax
202mulq  24(%rcx)
203add  %rax,%rbx
204adc %rdx,%rbp
205movq   8(%rsi),%rdx
206imulq  $19,%rdx,%rax
207mulq  32(%rcx)
208add  %rax,%r8
209adc %rdx,%r9
210movq   16(%rsi),%rax
211mulq  0(%rcx)
212add  %rax,%r12
213adc %rdx,%r13
214movq   16(%rsi),%rax
215mulq  8(%rcx)
216add  %rax,%r14
217adc %rdx,%r15
218movq   16(%rsi),%rax
219mulq  16(%rcx)
220add  %rax,%rbx
221adc %rdx,%rbp
222movq   16(%rsi),%rdx
223imulq  $19,%rdx,%rax
224mulq  24(%rcx)
225add  %rax,%r8
226adc %rdx,%r9
227movq   16(%rsi),%rdx
228imulq  $19,%rdx,%rax
229mulq  32(%rcx)
230add  %rax,%r10
231adc %rdx,%r11
232movq   24(%rsi),%rax
233mulq  0(%rcx)
234add  %rax,%r14
235adc %rdx,%r15
236movq   24(%rsi),%rax
237mulq  8(%rcx)
238add  %rax,%rbx
239adc %rdx,%rbp
240movq 64(%rsp),%rax
241mulq  24(%rcx)
242add  %rax,%r10
243adc %rdx,%r11
244movq 64(%rsp),%rax
245mulq  32(%rcx)
246add  %rax,%r12
247adc %rdx,%r13
248movq   32(%rsi),%rax
249mulq  0(%rcx)
250add  %rax,%rbx
251adc %rdx,%rbp
252movq 72(%rsp),%rax
253mulq  16(%rcx)
254add  %rax,%r10
255adc %rdx,%r11
256movq 72(%rsp),%rax
257mulq  24(%rcx)
258add  %rax,%r12
259adc %rdx,%r13
260movq 72(%rsp),%rax
261mulq  32(%rcx)
262add  %rax,%r14
263adc %rdx,%r15
264movq x25519_x86_64_REDMASK51(%rip),%rsi
265shld $13,%r8,%r9
266and  %rsi,%r8
267shld $13,%r10,%r11
268and  %rsi,%r10
269add  %r9,%r10
270shld $13,%r12,%r13
271and  %rsi,%r12
272add  %r11,%r12
273shld $13,%r14,%r15
274and  %rsi,%r14
275add  %r13,%r14
276shld $13,%rbx,%rbp
277and  %rsi,%rbx
278add  %r15,%rbx
279imulq  $19,%rbp,%rdx
280add  %rdx,%r8
281mov  %r8,%rdx
282shr  $51,%rdx
283add  %r10,%rdx
284mov  %rdx,%rcx
285shr  $51,%rdx
286and  %rsi,%r8
287add  %r12,%rdx
288mov  %rdx,%r9
289shr  $51,%rdx
290and  %rsi,%rcx
291add  %r14,%rdx
292mov  %rdx,%rax
293shr  $51,%rdx
294and  %rsi,%r9
295add  %rbx,%rdx
296mov  %rdx,%r10
297shr  $51,%rdx
298and  %rsi,%rax
299imulq  $19,%rdx,%rdx
300add  %rdx,%r8
301and  %rsi,%r10
302movq   %r8,0(%rdi)
303movq   %rcx,8(%rdi)
304movq   %r9,16(%rdi)
305movq   %rax,24(%rdi)
306movq   %r10,32(%rdi)
307movq 0(%rsp),%r11
308movq 8(%rsp),%r12
309movq 16(%rsp),%r13
310movq 24(%rsp),%r14
311movq 32(%rsp),%r15
312movq 40(%rsp),%rbx
313movq 48(%rsp),%rbp
314add %r11,%rsp
315mov %rdi,%rax
316mov %rsi,%rdx
317ret
318
319.p2align 5
320.globl C_ABI(x25519_x86_64_square)
321HIDDEN C_ABI(x25519_x86_64_square)
322C_ABI(x25519_x86_64_square):
323mov %rsp,%r11
324and $31,%r11
325add $64,%r11
326sub %r11,%rsp
327movq %r11,0(%rsp)
328movq %r12,8(%rsp)
329movq %r13,16(%rsp)
330movq %r14,24(%rsp)
331movq %r15,32(%rsp)
332movq %rbx,40(%rsp)
333movq %rbp,48(%rsp)
334movq   0(%rsi),%rax
335mulq  0(%rsi)
336mov  %rax,%rcx
337mov  %rdx,%r8
338movq   0(%rsi),%rax
339shl  $1,%rax
340mulq  8(%rsi)
341mov  %rax,%r9
342mov  %rdx,%r10
343movq   0(%rsi),%rax
344shl  $1,%rax
345mulq  16(%rsi)
346mov  %rax,%r11
347mov  %rdx,%r12
348movq   0(%rsi),%rax
349shl  $1,%rax
350mulq  24(%rsi)
351mov  %rax,%r13
352mov  %rdx,%r14
353movq   0(%rsi),%rax
354shl  $1,%rax
355mulq  32(%rsi)
356mov  %rax,%r15
357mov  %rdx,%rbx
358movq   8(%rsi),%rax
359mulq  8(%rsi)
360add  %rax,%r11
361adc %rdx,%r12
362movq   8(%rsi),%rax
363shl  $1,%rax
364mulq  16(%rsi)
365add  %rax,%r13
366adc %rdx,%r14
367movq   8(%rsi),%rax
368shl  $1,%rax
369mulq  24(%rsi)
370add  %rax,%r15
371adc %rdx,%rbx
372movq   8(%rsi),%rdx
373imulq  $38,%rdx,%rax
374mulq  32(%rsi)
375add  %rax,%rcx
376adc %rdx,%r8
377movq   16(%rsi),%rax
378mulq  16(%rsi)
379add  %rax,%r15
380adc %rdx,%rbx
381movq   16(%rsi),%rdx
382imulq  $38,%rdx,%rax
383mulq  24(%rsi)
384add  %rax,%rcx
385adc %rdx,%r8
386movq   16(%rsi),%rdx
387imulq  $38,%rdx,%rax
388mulq  32(%rsi)
389add  %rax,%r9
390adc %rdx,%r10
391movq   24(%rsi),%rdx
392imulq  $19,%rdx,%rax
393mulq  24(%rsi)
394add  %rax,%r9
395adc %rdx,%r10
396movq   24(%rsi),%rdx
397imulq  $38,%rdx,%rax
398mulq  32(%rsi)
399add  %rax,%r11
400adc %rdx,%r12
401movq   32(%rsi),%rdx
402imulq  $19,%rdx,%rax
403mulq  32(%rsi)
404add  %rax,%r13
405adc %rdx,%r14
406movq x25519_x86_64_REDMASK51(%rip),%rsi
407shld $13,%rcx,%r8
408and  %rsi,%rcx
409shld $13,%r9,%r10
410and  %rsi,%r9
411add  %r8,%r9
412shld $13,%r11,%r12
413and  %rsi,%r11
414add  %r10,%r11
415shld $13,%r13,%r14
416and  %rsi,%r13
417add  %r12,%r13
418shld $13,%r15,%rbx
419and  %rsi,%r15
420add  %r14,%r15
421imulq  $19,%rbx,%rdx
422add  %rdx,%rcx
423mov  %rcx,%rdx
424shr  $51,%rdx
425add  %r9,%rdx
426and  %rsi,%rcx
427mov  %rdx,%r8
428shr  $51,%rdx
429add  %r11,%rdx
430and  %rsi,%r8
431mov  %rdx,%r9
432shr  $51,%rdx
433add  %r13,%rdx
434and  %rsi,%r9
435mov  %rdx,%rax
436shr  $51,%rdx
437add  %r15,%rdx
438and  %rsi,%rax
439mov  %rdx,%r10
440shr  $51,%rdx
441imulq  $19,%rdx,%rdx
442add  %rdx,%rcx
443and  %rsi,%r10
444movq   %rcx,0(%rdi)
445movq   %r8,8(%rdi)
446movq   %r9,16(%rdi)
447movq   %rax,24(%rdi)
448movq   %r10,32(%rdi)
449movq 0(%rsp),%r11
450movq 8(%rsp),%r12
451movq 16(%rsp),%r13
452movq 24(%rsp),%r14
453movq 32(%rsp),%r15
454movq 40(%rsp),%rbx
455movq 48(%rsp),%rbp
456add %r11,%rsp
457mov %rdi,%rax
458mov %rsi,%rdx
459ret
460
461.p2align 5
462.globl C_ABI(x25519_x86_64_ladderstep)
463HIDDEN C_ABI(x25519_x86_64_ladderstep)
464C_ABI(x25519_x86_64_ladderstep):
465mov %rsp,%r11
466and $31,%r11
467add $352,%r11
468sub %r11,%rsp
469movq %r11,0(%rsp)
470movq %r12,8(%rsp)
471movq %r13,16(%rsp)
472movq %r14,24(%rsp)
473movq %r15,32(%rsp)
474movq %rbx,40(%rsp)
475movq %rbp,48(%rsp)
476movq   40(%rdi),%rsi
477movq   48(%rdi),%rdx
478movq   56(%rdi),%rcx
479movq   64(%rdi),%r8
480movq   72(%rdi),%r9
481mov  %rsi,%rax
482mov  %rdx,%r10
483mov  %rcx,%r11
484mov  %r8,%r12
485mov  %r9,%r13
486add  x25519_x86_64_2P0(%rip),%rax
487add  x25519_x86_64_2P1234(%rip),%r10
488add  x25519_x86_64_2P1234(%rip),%r11
489add  x25519_x86_64_2P1234(%rip),%r12
490add  x25519_x86_64_2P1234(%rip),%r13
491addq 80(%rdi),%rsi
492addq 88(%rdi),%rdx
493addq 96(%rdi),%rcx
494addq 104(%rdi),%r8
495addq 112(%rdi),%r9
496subq 80(%rdi),%rax
497subq 88(%rdi),%r10
498subq 96(%rdi),%r11
499subq 104(%rdi),%r12
500subq 112(%rdi),%r13
501movq %rsi,56(%rsp)
502movq %rdx,64(%rsp)
503movq %rcx,72(%rsp)
504movq %r8,80(%rsp)
505movq %r9,88(%rsp)
506movq %rax,96(%rsp)
507movq %r10,104(%rsp)
508movq %r11,112(%rsp)
509movq %r12,120(%rsp)
510movq %r13,128(%rsp)
511movq 96(%rsp),%rax
512mulq  96(%rsp)
513mov  %rax,%rsi
514mov  %rdx,%rcx
515movq 96(%rsp),%rax
516shl  $1,%rax
517mulq  104(%rsp)
518mov  %rax,%r8
519mov  %rdx,%r9
520movq 96(%rsp),%rax
521shl  $1,%rax
522mulq  112(%rsp)
523mov  %rax,%r10
524mov  %rdx,%r11
525movq 96(%rsp),%rax
526shl  $1,%rax
527mulq  120(%rsp)
528mov  %rax,%r12
529mov  %rdx,%r13
530movq 96(%rsp),%rax
531shl  $1,%rax
532mulq  128(%rsp)
533mov  %rax,%r14
534mov  %rdx,%r15
535movq 104(%rsp),%rax
536mulq  104(%rsp)
537add  %rax,%r10
538adc %rdx,%r11
539movq 104(%rsp),%rax
540shl  $1,%rax
541mulq  112(%rsp)
542add  %rax,%r12
543adc %rdx,%r13
544movq 104(%rsp),%rax
545shl  $1,%rax
546mulq  120(%rsp)
547add  %rax,%r14
548adc %rdx,%r15
549movq 104(%rsp),%rdx
550imulq  $38,%rdx,%rax
551mulq  128(%rsp)
552add  %rax,%rsi
553adc %rdx,%rcx
554movq 112(%rsp),%rax
555mulq  112(%rsp)
556add  %rax,%r14
557adc %rdx,%r15
558movq 112(%rsp),%rdx
559imulq  $38,%rdx,%rax
560mulq  120(%rsp)
561add  %rax,%rsi
562adc %rdx,%rcx
563movq 112(%rsp),%rdx
564imulq  $38,%rdx,%rax
565mulq  128(%rsp)
566add  %rax,%r8
567adc %rdx,%r9
568movq 120(%rsp),%rdx
569imulq  $19,%rdx,%rax
570mulq  120(%rsp)
571add  %rax,%r8
572adc %rdx,%r9
573movq 120(%rsp),%rdx
574imulq  $38,%rdx,%rax
575mulq  128(%rsp)
576add  %rax,%r10
577adc %rdx,%r11
578movq 128(%rsp),%rdx
579imulq  $19,%rdx,%rax
580mulq  128(%rsp)
581add  %rax,%r12
582adc %rdx,%r13
583movq x25519_x86_64_REDMASK51(%rip),%rdx
584shld $13,%rsi,%rcx
585and  %rdx,%rsi
586shld $13,%r8,%r9
587and  %rdx,%r8
588add  %rcx,%r8
589shld $13,%r10,%r11
590and  %rdx,%r10
591add  %r9,%r10
592shld $13,%r12,%r13
593and  %rdx,%r12
594add  %r11,%r12
595shld $13,%r14,%r15
596and  %rdx,%r14
597add  %r13,%r14
598imulq  $19,%r15,%rcx
599add  %rcx,%rsi
600mov  %rsi,%rcx
601shr  $51,%rcx
602add  %r8,%rcx
603and  %rdx,%rsi
604mov  %rcx,%r8
605shr  $51,%rcx
606add  %r10,%rcx
607and  %rdx,%r8
608mov  %rcx,%r9
609shr  $51,%rcx
610add  %r12,%rcx
611and  %rdx,%r9
612mov  %rcx,%rax
613shr  $51,%rcx
614add  %r14,%rcx
615and  %rdx,%rax
616mov  %rcx,%r10
617shr  $51,%rcx
618imulq  $19,%rcx,%rcx
619add  %rcx,%rsi
620and  %rdx,%r10
621movq %rsi,136(%rsp)
622movq %r8,144(%rsp)
623movq %r9,152(%rsp)
624movq %rax,160(%rsp)
625movq %r10,168(%rsp)
626movq 56(%rsp),%rax
627mulq  56(%rsp)
628mov  %rax,%rsi
629mov  %rdx,%rcx
630movq 56(%rsp),%rax
631shl  $1,%rax
632mulq  64(%rsp)
633mov  %rax,%r8
634mov  %rdx,%r9
635movq 56(%rsp),%rax
636shl  $1,%rax
637mulq  72(%rsp)
638mov  %rax,%r10
639mov  %rdx,%r11
640movq 56(%rsp),%rax
641shl  $1,%rax
642mulq  80(%rsp)
643mov  %rax,%r12
644mov  %rdx,%r13
645movq 56(%rsp),%rax
646shl  $1,%rax
647mulq  88(%rsp)
648mov  %rax,%r14
649mov  %rdx,%r15
650movq 64(%rsp),%rax
651mulq  64(%rsp)
652add  %rax,%r10
653adc %rdx,%r11
654movq 64(%rsp),%rax
655shl  $1,%rax
656mulq  72(%rsp)
657add  %rax,%r12
658adc %rdx,%r13
659movq 64(%rsp),%rax
660shl  $1,%rax
661mulq  80(%rsp)
662add  %rax,%r14
663adc %rdx,%r15
664movq 64(%rsp),%rdx
665imulq  $38,%rdx,%rax
666mulq  88(%rsp)
667add  %rax,%rsi
668adc %rdx,%rcx
669movq 72(%rsp),%rax
670mulq  72(%rsp)
671add  %rax,%r14
672adc %rdx,%r15
673movq 72(%rsp),%rdx
674imulq  $38,%rdx,%rax
675mulq  80(%rsp)
676add  %rax,%rsi
677adc %rdx,%rcx
678movq 72(%rsp),%rdx
679imulq  $38,%rdx,%rax
680mulq  88(%rsp)
681add  %rax,%r8
682adc %rdx,%r9
683movq 80(%rsp),%rdx
684imulq  $19,%rdx,%rax
685mulq  80(%rsp)
686add  %rax,%r8
687adc %rdx,%r9
688movq 80(%rsp),%rdx
689imulq  $38,%rdx,%rax
690mulq  88(%rsp)
691add  %rax,%r10
692adc %rdx,%r11
693movq 88(%rsp),%rdx
694imulq  $19,%rdx,%rax
695mulq  88(%rsp)
696add  %rax,%r12
697adc %rdx,%r13
698movq x25519_x86_64_REDMASK51(%rip),%rdx
699shld $13,%rsi,%rcx
700and  %rdx,%rsi
701shld $13,%r8,%r9
702and  %rdx,%r8
703add  %rcx,%r8
704shld $13,%r10,%r11
705and  %rdx,%r10
706add  %r9,%r10
707shld $13,%r12,%r13
708and  %rdx,%r12
709add  %r11,%r12
710shld $13,%r14,%r15
711and  %rdx,%r14
712add  %r13,%r14
713imulq  $19,%r15,%rcx
714add  %rcx,%rsi
715mov  %rsi,%rcx
716shr  $51,%rcx
717add  %r8,%rcx
718and  %rdx,%rsi
719mov  %rcx,%r8
720shr  $51,%rcx
721add  %r10,%rcx
722and  %rdx,%r8
723mov  %rcx,%r9
724shr  $51,%rcx
725add  %r12,%rcx
726and  %rdx,%r9
727mov  %rcx,%rax
728shr  $51,%rcx
729add  %r14,%rcx
730and  %rdx,%rax
731mov  %rcx,%r10
732shr  $51,%rcx
733imulq  $19,%rcx,%rcx
734add  %rcx,%rsi
735and  %rdx,%r10
736movq %rsi,176(%rsp)
737movq %r8,184(%rsp)
738movq %r9,192(%rsp)
739movq %rax,200(%rsp)
740movq %r10,208(%rsp)
741mov  %rsi,%rsi
742mov  %r8,%rdx
743mov  %r9,%rcx
744mov  %rax,%r8
745mov  %r10,%r9
746add  x25519_x86_64_2P0(%rip),%rsi
747add  x25519_x86_64_2P1234(%rip),%rdx
748add  x25519_x86_64_2P1234(%rip),%rcx
749add  x25519_x86_64_2P1234(%rip),%r8
750add  x25519_x86_64_2P1234(%rip),%r9
751subq 136(%rsp),%rsi
752subq 144(%rsp),%rdx
753subq 152(%rsp),%rcx
754subq 160(%rsp),%r8
755subq 168(%rsp),%r9
756movq %rsi,216(%rsp)
757movq %rdx,224(%rsp)
758movq %rcx,232(%rsp)
759movq %r8,240(%rsp)
760movq %r9,248(%rsp)
761movq   120(%rdi),%rsi
762movq   128(%rdi),%rdx
763movq   136(%rdi),%rcx
764movq   144(%rdi),%r8
765movq   152(%rdi),%r9
766mov  %rsi,%rax
767mov  %rdx,%r10
768mov  %rcx,%r11
769mov  %r8,%r12
770mov  %r9,%r13
771add  x25519_x86_64_2P0(%rip),%rax
772add  x25519_x86_64_2P1234(%rip),%r10
773add  x25519_x86_64_2P1234(%rip),%r11
774add  x25519_x86_64_2P1234(%rip),%r12
775add  x25519_x86_64_2P1234(%rip),%r13
776addq 160(%rdi),%rsi
777addq 168(%rdi),%rdx
778addq 176(%rdi),%rcx
779addq 184(%rdi),%r8
780addq 192(%rdi),%r9
781subq 160(%rdi),%rax
782subq 168(%rdi),%r10
783subq 176(%rdi),%r11
784subq 184(%rdi),%r12
785subq 192(%rdi),%r13
786movq %rsi,256(%rsp)
787movq %rdx,264(%rsp)
788movq %rcx,272(%rsp)
789movq %r8,280(%rsp)
790movq %r9,288(%rsp)
791movq %rax,296(%rsp)
792movq %r10,304(%rsp)
793movq %r11,312(%rsp)
794movq %r12,320(%rsp)
795movq %r13,328(%rsp)
796movq 280(%rsp),%rsi
797imulq  $19,%rsi,%rax
798movq %rax,336(%rsp)
799mulq  112(%rsp)
800mov  %rax,%rsi
801mov  %rdx,%rcx
802movq 288(%rsp),%rdx
803imulq  $19,%rdx,%rax
804movq %rax,344(%rsp)
805mulq  104(%rsp)
806add  %rax,%rsi
807adc %rdx,%rcx
808movq 256(%rsp),%rax
809mulq  96(%rsp)
810add  %rax,%rsi
811adc %rdx,%rcx
812movq 256(%rsp),%rax
813mulq  104(%rsp)
814mov  %rax,%r8
815mov  %rdx,%r9
816movq 256(%rsp),%rax
817mulq  112(%rsp)
818mov  %rax,%r10
819mov  %rdx,%r11
820movq 256(%rsp),%rax
821mulq  120(%rsp)
822mov  %rax,%r12
823mov  %rdx,%r13
824movq 256(%rsp),%rax
825mulq  128(%rsp)
826mov  %rax,%r14
827mov  %rdx,%r15
828movq 264(%rsp),%rax
829mulq  96(%rsp)
830add  %rax,%r8
831adc %rdx,%r9
832movq 264(%rsp),%rax
833mulq  104(%rsp)
834add  %rax,%r10
835adc %rdx,%r11
836movq 264(%rsp),%rax
837mulq  112(%rsp)
838add  %rax,%r12
839adc %rdx,%r13
840movq 264(%rsp),%rax
841mulq  120(%rsp)
842add  %rax,%r14
843adc %rdx,%r15
844movq 264(%rsp),%rdx
845imulq  $19,%rdx,%rax
846mulq  128(%rsp)
847add  %rax,%rsi
848adc %rdx,%rcx
849movq 272(%rsp),%rax
850mulq  96(%rsp)
851add  %rax,%r10
852adc %rdx,%r11
853movq 272(%rsp),%rax
854mulq  104(%rsp)
855add  %rax,%r12
856adc %rdx,%r13
857movq 272(%rsp),%rax
858mulq  112(%rsp)
859add  %rax,%r14
860adc %rdx,%r15
861movq 272(%rsp),%rdx
862imulq  $19,%rdx,%rax
863mulq  120(%rsp)
864add  %rax,%rsi
865adc %rdx,%rcx
866movq 272(%rsp),%rdx
867imulq  $19,%rdx,%rax
868mulq  128(%rsp)
869add  %rax,%r8
870adc %rdx,%r9
871movq 280(%rsp),%rax
872mulq  96(%rsp)
873add  %rax,%r12
874adc %rdx,%r13
875movq 280(%rsp),%rax
876mulq  104(%rsp)
877add  %rax,%r14
878adc %rdx,%r15
879movq 336(%rsp),%rax
880mulq  120(%rsp)
881add  %rax,%r8
882adc %rdx,%r9
883movq 336(%rsp),%rax
884mulq  128(%rsp)
885add  %rax,%r10
886adc %rdx,%r11
887movq 288(%rsp),%rax
888mulq  96(%rsp)
889add  %rax,%r14
890adc %rdx,%r15
891movq 344(%rsp),%rax
892mulq  112(%rsp)
893add  %rax,%r8
894adc %rdx,%r9
895movq 344(%rsp),%rax
896mulq  120(%rsp)
897add  %rax,%r10
898adc %rdx,%r11
899movq 344(%rsp),%rax
900mulq  128(%rsp)
901add  %rax,%r12
902adc %rdx,%r13
903movq x25519_x86_64_REDMASK51(%rip),%rdx
904shld $13,%rsi,%rcx
905and  %rdx,%rsi
906shld $13,%r8,%r9
907and  %rdx,%r8
908add  %rcx,%r8
909shld $13,%r10,%r11
910and  %rdx,%r10
911add  %r9,%r10
912shld $13,%r12,%r13
913and  %rdx,%r12
914add  %r11,%r12
915shld $13,%r14,%r15
916and  %rdx,%r14
917add  %r13,%r14
918imulq  $19,%r15,%rcx
919add  %rcx,%rsi
920mov  %rsi,%rcx
921shr  $51,%rcx
922add  %r8,%rcx
923mov  %rcx,%r8
924shr  $51,%rcx
925and  %rdx,%rsi
926add  %r10,%rcx
927mov  %rcx,%r9
928shr  $51,%rcx
929and  %rdx,%r8
930add  %r12,%rcx
931mov  %rcx,%rax
932shr  $51,%rcx
933and  %rdx,%r9
934add  %r14,%rcx
935mov  %rcx,%r10
936shr  $51,%rcx
937and  %rdx,%rax
938imulq  $19,%rcx,%rcx
939add  %rcx,%rsi
940and  %rdx,%r10
941movq %rsi,96(%rsp)
942movq %r8,104(%rsp)
943movq %r9,112(%rsp)
944movq %rax,120(%rsp)
945movq %r10,128(%rsp)
946movq 320(%rsp),%rsi
947imulq  $19,%rsi,%rax
948movq %rax,256(%rsp)
949mulq  72(%rsp)
950mov  %rax,%rsi
951mov  %rdx,%rcx
952movq 328(%rsp),%rdx
953imulq  $19,%rdx,%rax
954movq %rax,264(%rsp)
955mulq  64(%rsp)
956add  %rax,%rsi
957adc %rdx,%rcx
958movq 296(%rsp),%rax
959mulq  56(%rsp)
960add  %rax,%rsi
961adc %rdx,%rcx
962movq 296(%rsp),%rax
963mulq  64(%rsp)
964mov  %rax,%r8
965mov  %rdx,%r9
966movq 296(%rsp),%rax
967mulq  72(%rsp)
968mov  %rax,%r10
969mov  %rdx,%r11
970movq 296(%rsp),%rax
971mulq  80(%rsp)
972mov  %rax,%r12
973mov  %rdx,%r13
974movq 296(%rsp),%rax
975mulq  88(%rsp)
976mov  %rax,%r14
977mov  %rdx,%r15
978movq 304(%rsp),%rax
979mulq  56(%rsp)
980add  %rax,%r8
981adc %rdx,%r9
982movq 304(%rsp),%rax
983mulq  64(%rsp)
984add  %rax,%r10
985adc %rdx,%r11
986movq 304(%rsp),%rax
987mulq  72(%rsp)
988add  %rax,%r12
989adc %rdx,%r13
990movq 304(%rsp),%rax
991mulq  80(%rsp)
992add  %rax,%r14
993adc %rdx,%r15
994movq 304(%rsp),%rdx
995imulq  $19,%rdx,%rax
996mulq  88(%rsp)
997add  %rax,%rsi
998adc %rdx,%rcx
999movq 312(%rsp),%rax
1000mulq  56(%rsp)
1001add  %rax,%r10
1002adc %rdx,%r11
1003movq 312(%rsp),%rax
1004mulq  64(%rsp)
1005add  %rax,%r12
1006adc %rdx,%r13
1007movq 312(%rsp),%rax
1008mulq  72(%rsp)
1009add  %rax,%r14
1010adc %rdx,%r15
1011movq 312(%rsp),%rdx
1012imulq  $19,%rdx,%rax
1013mulq  80(%rsp)
1014add  %rax,%rsi
1015adc %rdx,%rcx
1016movq 312(%rsp),%rdx
1017imulq  $19,%rdx,%rax
1018mulq  88(%rsp)
1019add  %rax,%r8
1020adc %rdx,%r9
1021movq 320(%rsp),%rax
1022mulq  56(%rsp)
1023add  %rax,%r12
1024adc %rdx,%r13
1025movq 320(%rsp),%rax
1026mulq  64(%rsp)
1027add  %rax,%r14
1028adc %rdx,%r15
1029movq 256(%rsp),%rax
1030mulq  80(%rsp)
1031add  %rax,%r8
1032adc %rdx,%r9
1033movq 256(%rsp),%rax
1034mulq  88(%rsp)
1035add  %rax,%r10
1036adc %rdx,%r11
1037movq 328(%rsp),%rax
1038mulq  56(%rsp)
1039add  %rax,%r14
1040adc %rdx,%r15
1041movq 264(%rsp),%rax
1042mulq  72(%rsp)
1043add  %rax,%r8
1044adc %rdx,%r9
1045movq 264(%rsp),%rax
1046mulq  80(%rsp)
1047add  %rax,%r10
1048adc %rdx,%r11
1049movq 264(%rsp),%rax
1050mulq  88(%rsp)
1051add  %rax,%r12
1052adc %rdx,%r13
1053movq x25519_x86_64_REDMASK51(%rip),%rdx
1054shld $13,%rsi,%rcx
1055and  %rdx,%rsi
1056shld $13,%r8,%r9
1057and  %rdx,%r8
1058add  %rcx,%r8
1059shld $13,%r10,%r11
1060and  %rdx,%r10
1061add  %r9,%r10
1062shld $13,%r12,%r13
1063and  %rdx,%r12
1064add  %r11,%r12
1065shld $13,%r14,%r15
1066and  %rdx,%r14
1067add  %r13,%r14
1068imulq  $19,%r15,%rcx
1069add  %rcx,%rsi
1070mov  %rsi,%rcx
1071shr  $51,%rcx
1072add  %r8,%rcx
1073mov  %rcx,%r8
1074shr  $51,%rcx
1075and  %rdx,%rsi
1076add  %r10,%rcx
1077mov  %rcx,%r9
1078shr  $51,%rcx
1079and  %rdx,%r8
1080add  %r12,%rcx
1081mov  %rcx,%rax
1082shr  $51,%rcx
1083and  %rdx,%r9
1084add  %r14,%rcx
1085mov  %rcx,%r10
1086shr  $51,%rcx
1087and  %rdx,%rax
1088imulq  $19,%rcx,%rcx
1089add  %rcx,%rsi
1090and  %rdx,%r10
1091mov  %rsi,%rdx
1092mov  %r8,%rcx
1093mov  %r9,%r11
1094mov  %rax,%r12
1095mov  %r10,%r13
1096add  x25519_x86_64_2P0(%rip),%rdx
1097add  x25519_x86_64_2P1234(%rip),%rcx
1098add  x25519_x86_64_2P1234(%rip),%r11
1099add  x25519_x86_64_2P1234(%rip),%r12
1100add  x25519_x86_64_2P1234(%rip),%r13
1101addq 96(%rsp),%rsi
1102addq 104(%rsp),%r8
1103addq 112(%rsp),%r9
1104addq 120(%rsp),%rax
1105addq 128(%rsp),%r10
1106subq 96(%rsp),%rdx
1107subq 104(%rsp),%rcx
1108subq 112(%rsp),%r11
1109subq 120(%rsp),%r12
1110subq 128(%rsp),%r13
1111movq   %rsi,120(%rdi)
1112movq   %r8,128(%rdi)
1113movq   %r9,136(%rdi)
1114movq   %rax,144(%rdi)
1115movq   %r10,152(%rdi)
1116movq   %rdx,160(%rdi)
1117movq   %rcx,168(%rdi)
1118movq   %r11,176(%rdi)
1119movq   %r12,184(%rdi)
1120movq   %r13,192(%rdi)
1121movq   120(%rdi),%rax
1122mulq  120(%rdi)
1123mov  %rax,%rsi
1124mov  %rdx,%rcx
1125movq   120(%rdi),%rax
1126shl  $1,%rax
1127mulq  128(%rdi)
1128mov  %rax,%r8
1129mov  %rdx,%r9
1130movq   120(%rdi),%rax
1131shl  $1,%rax
1132mulq  136(%rdi)
1133mov  %rax,%r10
1134mov  %rdx,%r11
1135movq   120(%rdi),%rax
1136shl  $1,%rax
1137mulq  144(%rdi)
1138mov  %rax,%r12
1139mov  %rdx,%r13
1140movq   120(%rdi),%rax
1141shl  $1,%rax
1142mulq  152(%rdi)
1143mov  %rax,%r14
1144mov  %rdx,%r15
1145movq   128(%rdi),%rax
1146mulq  128(%rdi)
1147add  %rax,%r10
1148adc %rdx,%r11
1149movq   128(%rdi),%rax
1150shl  $1,%rax
1151mulq  136(%rdi)
1152add  %rax,%r12
1153adc %rdx,%r13
1154movq   128(%rdi),%rax
1155shl  $1,%rax
1156mulq  144(%rdi)
1157add  %rax,%r14
1158adc %rdx,%r15
1159movq   128(%rdi),%rdx
1160imulq  $38,%rdx,%rax
1161mulq  152(%rdi)
1162add  %rax,%rsi
1163adc %rdx,%rcx
1164movq   136(%rdi),%rax
1165mulq  136(%rdi)
1166add  %rax,%r14
1167adc %rdx,%r15
1168movq   136(%rdi),%rdx
1169imulq  $38,%rdx,%rax
1170mulq  144(%rdi)
1171add  %rax,%rsi
1172adc %rdx,%rcx
1173movq   136(%rdi),%rdx
1174imulq  $38,%rdx,%rax
1175mulq  152(%rdi)
1176add  %rax,%r8
1177adc %rdx,%r9
1178movq   144(%rdi),%rdx
1179imulq  $19,%rdx,%rax
1180mulq  144(%rdi)
1181add  %rax,%r8
1182adc %rdx,%r9
1183movq   144(%rdi),%rdx
1184imulq  $38,%rdx,%rax
1185mulq  152(%rdi)
1186add  %rax,%r10
1187adc %rdx,%r11
1188movq   152(%rdi),%rdx
1189imulq  $19,%rdx,%rax
1190mulq  152(%rdi)
1191add  %rax,%r12
1192adc %rdx,%r13
1193movq x25519_x86_64_REDMASK51(%rip),%rdx
1194shld $13,%rsi,%rcx
1195and  %rdx,%rsi
1196shld $13,%r8,%r9
1197and  %rdx,%r8
1198add  %rcx,%r8
1199shld $13,%r10,%r11
1200and  %rdx,%r10
1201add  %r9,%r10
1202shld $13,%r12,%r13
1203and  %rdx,%r12
1204add  %r11,%r12
1205shld $13,%r14,%r15
1206and  %rdx,%r14
1207add  %r13,%r14
1208imulq  $19,%r15,%rcx
1209add  %rcx,%rsi
1210mov  %rsi,%rcx
1211shr  $51,%rcx
1212add  %r8,%rcx
1213and  %rdx,%rsi
1214mov  %rcx,%r8
1215shr  $51,%rcx
1216add  %r10,%rcx
1217and  %rdx,%r8
1218mov  %rcx,%r9
1219shr  $51,%rcx
1220add  %r12,%rcx
1221and  %rdx,%r9
1222mov  %rcx,%rax
1223shr  $51,%rcx
1224add  %r14,%rcx
1225and  %rdx,%rax
1226mov  %rcx,%r10
1227shr  $51,%rcx
1228imulq  $19,%rcx,%rcx
1229add  %rcx,%rsi
1230and  %rdx,%r10
1231movq   %rsi,120(%rdi)
1232movq   %r8,128(%rdi)
1233movq   %r9,136(%rdi)
1234movq   %rax,144(%rdi)
1235movq   %r10,152(%rdi)
1236movq   160(%rdi),%rax
1237mulq  160(%rdi)
1238mov  %rax,%rsi
1239mov  %rdx,%rcx
1240movq   160(%rdi),%rax
1241shl  $1,%rax
1242mulq  168(%rdi)
1243mov  %rax,%r8
1244mov  %rdx,%r9
1245movq   160(%rdi),%rax
1246shl  $1,%rax
1247mulq  176(%rdi)
1248mov  %rax,%r10
1249mov  %rdx,%r11
1250movq   160(%rdi),%rax
1251shl  $1,%rax
1252mulq  184(%rdi)
1253mov  %rax,%r12
1254mov  %rdx,%r13
1255movq   160(%rdi),%rax
1256shl  $1,%rax
1257mulq  192(%rdi)
1258mov  %rax,%r14
1259mov  %rdx,%r15
1260movq   168(%rdi),%rax
1261mulq  168(%rdi)
1262add  %rax,%r10
1263adc %rdx,%r11
1264movq   168(%rdi),%rax
1265shl  $1,%rax
1266mulq  176(%rdi)
1267add  %rax,%r12
1268adc %rdx,%r13
1269movq   168(%rdi),%rax
1270shl  $1,%rax
1271mulq  184(%rdi)
1272add  %rax,%r14
1273adc %rdx,%r15
1274movq   168(%rdi),%rdx
1275imulq  $38,%rdx,%rax
1276mulq  192(%rdi)
1277add  %rax,%rsi
1278adc %rdx,%rcx
1279movq   176(%rdi),%rax
1280mulq  176(%rdi)
1281add  %rax,%r14
1282adc %rdx,%r15
1283movq   176(%rdi),%rdx
1284imulq  $38,%rdx,%rax
1285mulq  184(%rdi)
1286add  %rax,%rsi
1287adc %rdx,%rcx
1288movq   176(%rdi),%rdx
1289imulq  $38,%rdx,%rax
1290mulq  192(%rdi)
1291add  %rax,%r8
1292adc %rdx,%r9
1293movq   184(%rdi),%rdx
1294imulq  $19,%rdx,%rax
1295mulq  184(%rdi)
1296add  %rax,%r8
1297adc %rdx,%r9
1298movq   184(%rdi),%rdx
1299imulq  $38,%rdx,%rax
1300mulq  192(%rdi)
1301add  %rax,%r10
1302adc %rdx,%r11
1303movq   192(%rdi),%rdx
1304imulq  $19,%rdx,%rax
1305mulq  192(%rdi)
1306add  %rax,%r12
1307adc %rdx,%r13
1308movq x25519_x86_64_REDMASK51(%rip),%rdx
1309shld $13,%rsi,%rcx
1310and  %rdx,%rsi
1311shld $13,%r8,%r9
1312and  %rdx,%r8
1313add  %rcx,%r8
1314shld $13,%r10,%r11
1315and  %rdx,%r10
1316add  %r9,%r10
1317shld $13,%r12,%r13
1318and  %rdx,%r12
1319add  %r11,%r12
1320shld $13,%r14,%r15
1321and  %rdx,%r14
1322add  %r13,%r14
1323imulq  $19,%r15,%rcx
1324add  %rcx,%rsi
1325mov  %rsi,%rcx
1326shr  $51,%rcx
1327add  %r8,%rcx
1328and  %rdx,%rsi
1329mov  %rcx,%r8
1330shr  $51,%rcx
1331add  %r10,%rcx
1332and  %rdx,%r8
1333mov  %rcx,%r9
1334shr  $51,%rcx
1335add  %r12,%rcx
1336and  %rdx,%r9
1337mov  %rcx,%rax
1338shr  $51,%rcx
1339add  %r14,%rcx
1340and  %rdx,%rax
1341mov  %rcx,%r10
1342shr  $51,%rcx
1343imulq  $19,%rcx,%rcx
1344add  %rcx,%rsi
1345and  %rdx,%r10
1346movq   %rsi,160(%rdi)
1347movq   %r8,168(%rdi)
1348movq   %r9,176(%rdi)
1349movq   %rax,184(%rdi)
1350movq   %r10,192(%rdi)
1351movq   184(%rdi),%rsi
1352imulq  $19,%rsi,%rax
1353movq %rax,56(%rsp)
1354mulq  16(%rdi)
1355mov  %rax,%rsi
1356mov  %rdx,%rcx
1357movq   192(%rdi),%rdx
1358imulq  $19,%rdx,%rax
1359movq %rax,64(%rsp)
1360mulq  8(%rdi)
1361add  %rax,%rsi
1362adc %rdx,%rcx
1363movq   160(%rdi),%rax
1364mulq  0(%rdi)
1365add  %rax,%rsi
1366adc %rdx,%rcx
1367movq   160(%rdi),%rax
1368mulq  8(%rdi)
1369mov  %rax,%r8
1370mov  %rdx,%r9
1371movq   160(%rdi),%rax
1372mulq  16(%rdi)
1373mov  %rax,%r10
1374mov  %rdx,%r11
1375movq   160(%rdi),%rax
1376mulq  24(%rdi)
1377mov  %rax,%r12
1378mov  %rdx,%r13
1379movq   160(%rdi),%rax
1380mulq  32(%rdi)
1381mov  %rax,%r14
1382mov  %rdx,%r15
1383movq   168(%rdi),%rax
1384mulq  0(%rdi)
1385add  %rax,%r8
1386adc %rdx,%r9
1387movq   168(%rdi),%rax
1388mulq  8(%rdi)
1389add  %rax,%r10
1390adc %rdx,%r11
1391movq   168(%rdi),%rax
1392mulq  16(%rdi)
1393add  %rax,%r12
1394adc %rdx,%r13
1395movq   168(%rdi),%rax
1396mulq  24(%rdi)
1397add  %rax,%r14
1398adc %rdx,%r15
1399movq   168(%rdi),%rdx
1400imulq  $19,%rdx,%rax
1401mulq  32(%rdi)
1402add  %rax,%rsi
1403adc %rdx,%rcx
1404movq   176(%rdi),%rax
1405mulq  0(%rdi)
1406add  %rax,%r10
1407adc %rdx,%r11
1408movq   176(%rdi),%rax
1409mulq  8(%rdi)
1410add  %rax,%r12
1411adc %rdx,%r13
1412movq   176(%rdi),%rax
1413mulq  16(%rdi)
1414add  %rax,%r14
1415adc %rdx,%r15
1416movq   176(%rdi),%rdx
1417imulq  $19,%rdx,%rax
1418mulq  24(%rdi)
1419add  %rax,%rsi
1420adc %rdx,%rcx
1421movq   176(%rdi),%rdx
1422imulq  $19,%rdx,%rax
1423mulq  32(%rdi)
1424add  %rax,%r8
1425adc %rdx,%r9
1426movq   184(%rdi),%rax
1427mulq  0(%rdi)
1428add  %rax,%r12
1429adc %rdx,%r13
1430movq   184(%rdi),%rax
1431mulq  8(%rdi)
1432add  %rax,%r14
1433adc %rdx,%r15
1434movq 56(%rsp),%rax
1435mulq  24(%rdi)
1436add  %rax,%r8
1437adc %rdx,%r9
1438movq 56(%rsp),%rax
1439mulq  32(%rdi)
1440add  %rax,%r10
1441adc %rdx,%r11
1442movq   192(%rdi),%rax
1443mulq  0(%rdi)
1444add  %rax,%r14
1445adc %rdx,%r15
1446movq 64(%rsp),%rax
1447mulq  16(%rdi)
1448add  %rax,%r8
1449adc %rdx,%r9
1450movq 64(%rsp),%rax
1451mulq  24(%rdi)
1452add  %rax,%r10
1453adc %rdx,%r11
1454movq 64(%rsp),%rax
1455mulq  32(%rdi)
1456add  %rax,%r12
1457adc %rdx,%r13
1458movq x25519_x86_64_REDMASK51(%rip),%rdx
1459shld $13,%rsi,%rcx
1460and  %rdx,%rsi
1461shld $13,%r8,%r9
1462and  %rdx,%r8
1463add  %rcx,%r8
1464shld $13,%r10,%r11
1465and  %rdx,%r10
1466add  %r9,%r10
1467shld $13,%r12,%r13
1468and  %rdx,%r12
1469add  %r11,%r12
1470shld $13,%r14,%r15
1471and  %rdx,%r14
1472add  %r13,%r14
1473imulq  $19,%r15,%rcx
1474add  %rcx,%rsi
1475mov  %rsi,%rcx
1476shr  $51,%rcx
1477add  %r8,%rcx
1478mov  %rcx,%r8
1479shr  $51,%rcx
1480and  %rdx,%rsi
1481add  %r10,%rcx
1482mov  %rcx,%r9
1483shr  $51,%rcx
1484and  %rdx,%r8
1485add  %r12,%rcx
1486mov  %rcx,%rax
1487shr  $51,%rcx
1488and  %rdx,%r9
1489add  %r14,%rcx
1490mov  %rcx,%r10
1491shr  $51,%rcx
1492and  %rdx,%rax
1493imulq  $19,%rcx,%rcx
1494add  %rcx,%rsi
1495and  %rdx,%r10
1496movq   %rsi,160(%rdi)
1497movq   %r8,168(%rdi)
1498movq   %r9,176(%rdi)
1499movq   %rax,184(%rdi)
1500movq   %r10,192(%rdi)
1501movq 200(%rsp),%rsi
1502imulq  $19,%rsi,%rax
1503movq %rax,56(%rsp)
1504mulq  152(%rsp)
1505mov  %rax,%rsi
1506mov  %rdx,%rcx
1507movq 208(%rsp),%rdx
1508imulq  $19,%rdx,%rax
1509movq %rax,64(%rsp)
1510mulq  144(%rsp)
1511add  %rax,%rsi
1512adc %rdx,%rcx
1513movq 176(%rsp),%rax
1514mulq  136(%rsp)
1515add  %rax,%rsi
1516adc %rdx,%rcx
1517movq 176(%rsp),%rax
1518mulq  144(%rsp)
1519mov  %rax,%r8
1520mov  %rdx,%r9
1521movq 176(%rsp),%rax
1522mulq  152(%rsp)
1523mov  %rax,%r10
1524mov  %rdx,%r11
1525movq 176(%rsp),%rax
1526mulq  160(%rsp)
1527mov  %rax,%r12
1528mov  %rdx,%r13
1529movq 176(%rsp),%rax
1530mulq  168(%rsp)
1531mov  %rax,%r14
1532mov  %rdx,%r15
1533movq 184(%rsp),%rax
1534mulq  136(%rsp)
1535add  %rax,%r8
1536adc %rdx,%r9
1537movq 184(%rsp),%rax
1538mulq  144(%rsp)
1539add  %rax,%r10
1540adc %rdx,%r11
1541movq 184(%rsp),%rax
1542mulq  152(%rsp)
1543add  %rax,%r12
1544adc %rdx,%r13
1545movq 184(%rsp),%rax
1546mulq  160(%rsp)
1547add  %rax,%r14
1548adc %rdx,%r15
1549movq 184(%rsp),%rdx
1550imulq  $19,%rdx,%rax
1551mulq  168(%rsp)
1552add  %rax,%rsi
1553adc %rdx,%rcx
1554movq 192(%rsp),%rax
1555mulq  136(%rsp)
1556add  %rax,%r10
1557adc %rdx,%r11
1558movq 192(%rsp),%rax
1559mulq  144(%rsp)
1560add  %rax,%r12
1561adc %rdx,%r13
1562movq 192(%rsp),%rax
1563mulq  152(%rsp)
1564add  %rax,%r14
1565adc %rdx,%r15
1566movq 192(%rsp),%rdx
1567imulq  $19,%rdx,%rax
1568mulq  160(%rsp)
1569add  %rax,%rsi
1570adc %rdx,%rcx
1571movq 192(%rsp),%rdx
1572imulq  $19,%rdx,%rax
1573mulq  168(%rsp)
1574add  %rax,%r8
1575adc %rdx,%r9
1576movq 200(%rsp),%rax
1577mulq  136(%rsp)
1578add  %rax,%r12
1579adc %rdx,%r13
1580movq 200(%rsp),%rax
1581mulq  144(%rsp)
1582add  %rax,%r14
1583adc %rdx,%r15
1584movq 56(%rsp),%rax
1585mulq  160(%rsp)
1586add  %rax,%r8
1587adc %rdx,%r9
1588movq 56(%rsp),%rax
1589mulq  168(%rsp)
1590add  %rax,%r10
1591adc %rdx,%r11
1592movq 208(%rsp),%rax
1593mulq  136(%rsp)
1594add  %rax,%r14
1595adc %rdx,%r15
1596movq 64(%rsp),%rax
1597mulq  152(%rsp)
1598add  %rax,%r8
1599adc %rdx,%r9
1600movq 64(%rsp),%rax
1601mulq  160(%rsp)
1602add  %rax,%r10
1603adc %rdx,%r11
1604movq 64(%rsp),%rax
1605mulq  168(%rsp)
1606add  %rax,%r12
1607adc %rdx,%r13
1608movq x25519_x86_64_REDMASK51(%rip),%rdx
1609shld $13,%rsi,%rcx
1610and  %rdx,%rsi
1611shld $13,%r8,%r9
1612and  %rdx,%r8
1613add  %rcx,%r8
1614shld $13,%r10,%r11
1615and  %rdx,%r10
1616add  %r9,%r10
1617shld $13,%r12,%r13
1618and  %rdx,%r12
1619add  %r11,%r12
1620shld $13,%r14,%r15
1621and  %rdx,%r14
1622add  %r13,%r14
1623imulq  $19,%r15,%rcx
1624add  %rcx,%rsi
1625mov  %rsi,%rcx
1626shr  $51,%rcx
1627add  %r8,%rcx
1628mov  %rcx,%r8
1629shr  $51,%rcx
1630and  %rdx,%rsi
1631add  %r10,%rcx
1632mov  %rcx,%r9
1633shr  $51,%rcx
1634and  %rdx,%r8
1635add  %r12,%rcx
1636mov  %rcx,%rax
1637shr  $51,%rcx
1638and  %rdx,%r9
1639add  %r14,%rcx
1640mov  %rcx,%r10
1641shr  $51,%rcx
1642and  %rdx,%rax
1643imulq  $19,%rcx,%rcx
1644add  %rcx,%rsi
1645and  %rdx,%r10
1646movq   %rsi,40(%rdi)
1647movq   %r8,48(%rdi)
1648movq   %r9,56(%rdi)
1649movq   %rax,64(%rdi)
1650movq   %r10,72(%rdi)
1651movq 216(%rsp),%rax
1652mulq  x25519_x86_64_121666_213(%rip)
1653shr  $13,%rax
1654mov  %rax,%rsi
1655mov  %rdx,%rcx
1656movq 224(%rsp),%rax
1657mulq  x25519_x86_64_121666_213(%rip)
1658shr  $13,%rax
1659add  %rax,%rcx
1660mov  %rdx,%r8
1661movq 232(%rsp),%rax
1662mulq  x25519_x86_64_121666_213(%rip)
1663shr  $13,%rax
1664add  %rax,%r8
1665mov  %rdx,%r9
1666movq 240(%rsp),%rax
1667mulq  x25519_x86_64_121666_213(%rip)
1668shr  $13,%rax
1669add  %rax,%r9
1670mov  %rdx,%r10
1671movq 248(%rsp),%rax
1672mulq  x25519_x86_64_121666_213(%rip)
1673shr  $13,%rax
1674add  %rax,%r10
1675imulq  $19,%rdx,%rdx
1676add  %rdx,%rsi
1677addq 136(%rsp),%rsi
1678addq 144(%rsp),%rcx
1679addq 152(%rsp),%r8
1680addq 160(%rsp),%r9
1681addq 168(%rsp),%r10
1682movq   %rsi,80(%rdi)
1683movq   %rcx,88(%rdi)
1684movq   %r8,96(%rdi)
1685movq   %r9,104(%rdi)
1686movq   %r10,112(%rdi)
1687movq   104(%rdi),%rsi
1688imulq  $19,%rsi,%rax
1689movq %rax,56(%rsp)
1690mulq  232(%rsp)
1691mov  %rax,%rsi
1692mov  %rdx,%rcx
1693movq   112(%rdi),%rdx
1694imulq  $19,%rdx,%rax
1695movq %rax,64(%rsp)
1696mulq  224(%rsp)
1697add  %rax,%rsi
1698adc %rdx,%rcx
1699movq   80(%rdi),%rax
1700mulq  216(%rsp)
1701add  %rax,%rsi
1702adc %rdx,%rcx
1703movq   80(%rdi),%rax
1704mulq  224(%rsp)
1705mov  %rax,%r8
1706mov  %rdx,%r9
1707movq   80(%rdi),%rax
1708mulq  232(%rsp)
1709mov  %rax,%r10
1710mov  %rdx,%r11
1711movq   80(%rdi),%rax
1712mulq  240(%rsp)
1713mov  %rax,%r12
1714mov  %rdx,%r13
1715movq   80(%rdi),%rax
1716mulq  248(%rsp)
1717mov  %rax,%r14
1718mov  %rdx,%r15
1719movq   88(%rdi),%rax
1720mulq  216(%rsp)
1721add  %rax,%r8
1722adc %rdx,%r9
1723movq   88(%rdi),%rax
1724mulq  224(%rsp)
1725add  %rax,%r10
1726adc %rdx,%r11
1727movq   88(%rdi),%rax
1728mulq  232(%rsp)
1729add  %rax,%r12
1730adc %rdx,%r13
1731movq   88(%rdi),%rax
1732mulq  240(%rsp)
1733add  %rax,%r14
1734adc %rdx,%r15
1735movq   88(%rdi),%rdx
1736imulq  $19,%rdx,%rax
1737mulq  248(%rsp)
1738add  %rax,%rsi
1739adc %rdx,%rcx
1740movq   96(%rdi),%rax
1741mulq  216(%rsp)
1742add  %rax,%r10
1743adc %rdx,%r11
1744movq   96(%rdi),%rax
1745mulq  224(%rsp)
1746add  %rax,%r12
1747adc %rdx,%r13
1748movq   96(%rdi),%rax
1749mulq  232(%rsp)
1750add  %rax,%r14
1751adc %rdx,%r15
1752movq   96(%rdi),%rdx
1753imulq  $19,%rdx,%rax
1754mulq  240(%rsp)
1755add  %rax,%rsi
1756adc %rdx,%rcx
1757movq   96(%rdi),%rdx
1758imulq  $19,%rdx,%rax
1759mulq  248(%rsp)
1760add  %rax,%r8
1761adc %rdx,%r9
1762movq   104(%rdi),%rax
1763mulq  216(%rsp)
1764add  %rax,%r12
1765adc %rdx,%r13
1766movq   104(%rdi),%rax
1767mulq  224(%rsp)
1768add  %rax,%r14
1769adc %rdx,%r15
1770movq 56(%rsp),%rax
1771mulq  240(%rsp)
1772add  %rax,%r8
1773adc %rdx,%r9
1774movq 56(%rsp),%rax
1775mulq  248(%rsp)
1776add  %rax,%r10
1777adc %rdx,%r11
1778movq   112(%rdi),%rax
1779mulq  216(%rsp)
1780add  %rax,%r14
1781adc %rdx,%r15
1782movq 64(%rsp),%rax
1783mulq  232(%rsp)
1784add  %rax,%r8
1785adc %rdx,%r9
1786movq 64(%rsp),%rax
1787mulq  240(%rsp)
1788add  %rax,%r10
1789adc %rdx,%r11
1790movq 64(%rsp),%rax
1791mulq  248(%rsp)
1792add  %rax,%r12
1793adc %rdx,%r13
1794movq x25519_x86_64_REDMASK51(%rip),%rdx
1795shld $13,%rsi,%rcx
1796and  %rdx,%rsi
1797shld $13,%r8,%r9
1798and  %rdx,%r8
1799add  %rcx,%r8
1800shld $13,%r10,%r11
1801and  %rdx,%r10
1802add  %r9,%r10
1803shld $13,%r12,%r13
1804and  %rdx,%r12
1805add  %r11,%r12
1806shld $13,%r14,%r15
1807and  %rdx,%r14
1808add  %r13,%r14
1809imulq  $19,%r15,%rcx
1810add  %rcx,%rsi
1811mov  %rsi,%rcx
1812shr  $51,%rcx
1813add  %r8,%rcx
1814mov  %rcx,%r8
1815shr  $51,%rcx
1816and  %rdx,%rsi
1817add  %r10,%rcx
1818mov  %rcx,%r9
1819shr  $51,%rcx
1820and  %rdx,%r8
1821add  %r12,%rcx
1822mov  %rcx,%rax
1823shr  $51,%rcx
1824and  %rdx,%r9
1825add  %r14,%rcx
1826mov  %rcx,%r10
1827shr  $51,%rcx
1828and  %rdx,%rax
1829imulq  $19,%rcx,%rcx
1830add  %rcx,%rsi
1831and  %rdx,%r10
1832movq   %rsi,80(%rdi)
1833movq   %r8,88(%rdi)
1834movq   %r9,96(%rdi)
1835movq   %rax,104(%rdi)
1836movq   %r10,112(%rdi)
1837movq 0(%rsp),%r11
1838movq 8(%rsp),%r12
1839movq 16(%rsp),%r13
1840movq 24(%rsp),%r14
1841movq 32(%rsp),%r15
1842movq 40(%rsp),%rbx
1843movq 48(%rsp),%rbp
1844add %r11,%rsp
1845mov %rdi,%rax
1846mov %rsi,%rdx
1847ret
1848
1849.p2align 5
1850.globl C_ABI(x25519_x86_64_work_cswap)
1851HIDDEN C_ABI(x25519_x86_64_work_cswap)
1852C_ABI(x25519_x86_64_work_cswap):
1853mov %rsp,%r11
1854and $31,%r11
1855add $0,%r11
1856sub %r11,%rsp
1857cmp  $1,%rsi
1858movq   0(%rdi),%rsi
1859movq   80(%rdi),%rdx
1860movq   8(%rdi),%rcx
1861movq   88(%rdi),%r8
1862mov  %rsi,%r9
1863cmove %rdx,%rsi
1864cmove %r9,%rdx
1865mov  %rcx,%r9
1866cmove %r8,%rcx
1867cmove %r9,%r8
1868movq   %rsi,0(%rdi)
1869movq   %rdx,80(%rdi)
1870movq   %rcx,8(%rdi)
1871movq   %r8,88(%rdi)
1872movq   16(%rdi),%rsi
1873movq   96(%rdi),%rdx
1874movq   24(%rdi),%rcx
1875movq   104(%rdi),%r8
1876mov  %rsi,%r9
1877cmove %rdx,%rsi
1878cmove %r9,%rdx
1879mov  %rcx,%r9
1880cmove %r8,%rcx
1881cmove %r9,%r8
1882movq   %rsi,16(%rdi)
1883movq   %rdx,96(%rdi)
1884movq   %rcx,24(%rdi)
1885movq   %r8,104(%rdi)
1886movq   32(%rdi),%rsi
1887movq   112(%rdi),%rdx
1888movq   40(%rdi),%rcx
1889movq   120(%rdi),%r8
1890mov  %rsi,%r9
1891cmove %rdx,%rsi
1892cmove %r9,%rdx
1893mov  %rcx,%r9
1894cmove %r8,%rcx
1895cmove %r9,%r8
1896movq   %rsi,32(%rdi)
1897movq   %rdx,112(%rdi)
1898movq   %rcx,40(%rdi)
1899movq   %r8,120(%rdi)
1900movq   48(%rdi),%rsi
1901movq   128(%rdi),%rdx
1902movq   56(%rdi),%rcx
1903movq   136(%rdi),%r8
1904mov  %rsi,%r9
1905cmove %rdx,%rsi
1906cmove %r9,%rdx
1907mov  %rcx,%r9
1908cmove %r8,%rcx
1909cmove %r9,%r8
1910movq   %rsi,48(%rdi)
1911movq   %rdx,128(%rdi)
1912movq   %rcx,56(%rdi)
1913movq   %r8,136(%rdi)
1914movq   64(%rdi),%rsi
1915movq   144(%rdi),%rdx
1916movq   72(%rdi),%rcx
1917movq   152(%rdi),%r8
1918mov  %rsi,%r9
1919cmove %rdx,%rsi
1920cmove %r9,%rdx
1921mov  %rcx,%r9
1922cmove %r8,%rcx
1923cmove %r9,%r8
1924movq   %rsi,64(%rdi)
1925movq   %rdx,144(%rdi)
1926movq   %rcx,72(%rdi)
1927movq   %r8,152(%rdi)
1928add %r11,%rsp
1929mov %rdi,%rax
1930mov %rsi,%rdx
1931ret
1932