Debian Codegraph @

cipher/asm-poly1305-s390x.h

raw
1 /* asm-common-amd64.h - Poly1305 macros for zSeries assembly
2 *
3 * Copyright (C) 2020 Jussi Kivilinna <[email protected]>
4 *
5 * This file is part of Libgcrypt.
6 *
7 * Libgcrypt is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * Libgcrypt is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef GCRY_ASM_POLY1305_S390X_H
22 #define GCRY_ASM_POLY1305_S390X_H
23
24 #include "asm-common-s390x.h"
25
26 /**********************************************************************
27 poly1305 for stitched chacha20-poly1305
28 **********************************************************************/
29
30 #define POLY_RSTATE %r1
31 #define POLY_RSRC %r14
32
33 #define POLY_R_H0_TMP_HI %r6 // even-
34 #define POLY_R_H0 %r7 // odd pair
35 #define POLY_R_H1_TMP_HI %r8 // even-
36 #define POLY_R_H1 %r9 // odd pair
37 #define POLY_R_H2 %r10
38 #define POLY_R_R0 %r11
39 #define POLY_R_R1 %r12
40 #define POLY_R_R1_MUL5 %r13
41 #define POLY_R_X0_HI %r2 // even-
42 #define POLY_R_X0_LO %r3 // odd pair
43 #define POLY_R_X1_HI %r4 // even-
44 #define POLY_R_X1_LO %r5 // odd pair
45
46 #define POLY_S_R0 (4 * 4 + 0 * 8)(POLY_RSTATE)
47 #define POLY_S_R1 (4 * 4 + 1 * 8)(POLY_RSTATE)
48 #define POLY_S_H0 (4 * 4 + 2 * 8 + 0 * 8)(POLY_RSTATE)
49 #define POLY_S_H1 (4 * 4 + 2 * 8 + 1 * 8)(POLY_RSTATE)
50 #define POLY_S_H2d (4 * 4 + 2 * 8 + 2 * 8)(POLY_RSTATE)
51
52 #define INC_POLY1305_SRC(a) \
53 aghi POLY_RSRC, (a);
54
55 #define POLY1305_LOAD_STATE() \
56 lg POLY_R_H0, POLY_S_H0; \
57 lg POLY_R_H1, POLY_S_H1; \
58 llgf POLY_R_H2, POLY_S_H2d; \
59 rllg POLY_R_H0, POLY_R_H0, 32; \
60 rllg POLY_R_H1, POLY_R_H1, 32; \
61 lg POLY_R_R0, POLY_S_R0; \
62 lg POLY_R_R1, POLY_S_R1; \
63 rllg POLY_R_R0, POLY_R_R0, 32; \
64 rllg POLY_R_R1, POLY_R_R1, 32; \
65 srlg POLY_R_R1_MUL5, POLY_R_R1, 2; \
66 algr POLY_R_R1_MUL5, POLY_R_R1;
67
68 #define POLY1305_STORE_STATE() \
69 rllg POLY_R_H0, POLY_R_H0, 32; \
70 rllg POLY_R_H1, POLY_R_H1, 32; \
71 stg POLY_R_H0, POLY_S_H0; \
72 stg POLY_R_H1, POLY_S_H1; \
73 st POLY_R_H2, POLY_S_H2d;
74
75 /* a = h + m */
76 #define POLY1305_BLOCK_PART1_HB(src_offset, high_pad) \
77 lrvg POLY_R_X0_HI, ((src_offset) + 1 * 8)(POLY_RSRC); \
78 lrvg POLY_R_X0_LO, ((src_offset) + 0 * 8)(POLY_RSRC); \
79 lghi POLY_R_H1_TMP_HI, (high_pad);
80
81 #define POLY1305_BLOCK_PART1(src_offset) \
82 POLY1305_BLOCK_PART1_HB(src_offset, 1);
83
84 #define POLY1305_BLOCK_PART2() \
85 algr POLY_R_H0, POLY_R_X0_LO; \
86 alcgr POLY_R_H1, POLY_R_X0_HI; \
87 alcgr POLY_R_H2, POLY_R_H1_TMP_HI; \
88 lgr POLY_R_X1_LO, POLY_R_H0; \
89 lgr POLY_R_X0_LO, POLY_R_H0;
90
91 #define POLY1305_BLOCK_PART3() \
92 /* h = a * r (partial mod 2^130-5): */ \
93 \
94 /* h0 * r1 */ \
95 mlgr POLY_R_X1_HI, POLY_R_R1; \
96 \
97 /* h1 * r0 */ \
98 lgr POLY_R_H0, POLY_R_H1; \
99 mlgr POLY_R_H0_TMP_HI, POLY_R_R0; \
100 \
101 /* h1 * r1 mod 2^130-5 */ \
102 mlgr POLY_R_H1_TMP_HI, POLY_R_R1_MUL5;
103
104 #define POLY1305_BLOCK_PART4() \
105 \
106 /* h0 * r0 */ \
107 mlgr POLY_R_X0_HI, POLY_R_R0; \
108 \
109 algr POLY_R_X1_LO, POLY_R_H0; \
110 alcgr POLY_R_X1_HI, POLY_R_H0_TMP_HI; \
111 \
112 lgr POLY_R_H0_TMP_HI, POLY_R_H2; \
113 msgr POLY_R_H0_TMP_HI, POLY_R_R1_MUL5; /* h2 * r1 mod 2^130-5 */ \
114 msgr POLY_R_H2, POLY_R_R0; /* h2 * r0 */
115
116 #define POLY1305_BLOCK_PART5() \
117 \
118 algr POLY_R_X0_LO, POLY_R_H1; \
119 alcgr POLY_R_X0_HI, POLY_R_H1_TMP_HI;
120
121 #define POLY1305_BLOCK_PART6() \
122 \
123 algrk POLY_R_H1, POLY_R_H0_TMP_HI, POLY_R_X1_LO; \
124 alcgr POLY_R_H2, POLY_R_X1_HI;
125
126 #define POLY1305_BLOCK_PART7() \
127 \
128 /* carry propagation */ \
129 srlg POLY_R_H0, POLY_R_H2, 2; \
130 risbgn POLY_R_X1_LO, POLY_R_H2, 0, 0x80 | 61, 0; \
131 lghi POLY_R_H1_TMP_HI, 0; \
132 agr POLY_R_H0, POLY_R_X1_LO; \
133 risbgn POLY_R_H2, POLY_R_H2, 62, 0x80 | 63, 0;
134
135 #define POLY1305_BLOCK_PART8() \
136 algr POLY_R_H0, POLY_R_X0_LO; \
137 alcgr POLY_R_H1, POLY_R_X0_HI; \
138 alcgr POLY_R_H2, POLY_R_H1_TMP_HI;
139
140 #endif /* GCRY_ASM_POLY1305_AMD64_H */