xref: /freebsd/contrib/llvm-project/clang/lib/Headers/riscv_crypto.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1*5f757f3fSDimitry Andric /*===---- riscv_crypto.h - RISC-V Zk* intrinsics ---------------------------===
2*5f757f3fSDimitry Andric  *
3*5f757f3fSDimitry Andric  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*5f757f3fSDimitry Andric  * See https://llvm.org/LICENSE.txt for license information.
5*5f757f3fSDimitry Andric  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*5f757f3fSDimitry Andric  *
7*5f757f3fSDimitry Andric  *===-----------------------------------------------------------------------===
8*5f757f3fSDimitry Andric  */
9*5f757f3fSDimitry Andric 
10*5f757f3fSDimitry Andric #ifndef __RISCV_CRYPTO_H
11*5f757f3fSDimitry Andric #define __RISCV_CRYPTO_H
12*5f757f3fSDimitry Andric 
13*5f757f3fSDimitry Andric #include <stdint.h>
14*5f757f3fSDimitry Andric 
15*5f757f3fSDimitry Andric #if defined(__cplusplus)
16*5f757f3fSDimitry Andric extern "C" {
17*5f757f3fSDimitry Andric #endif
18*5f757f3fSDimitry Andric 
19*5f757f3fSDimitry Andric #if defined(__riscv_zknd)
20*5f757f3fSDimitry Andric #if __riscv_xlen == 32
21*5f757f3fSDimitry Andric #define __riscv_aes32dsi(x, y, bs) __builtin_riscv_aes32dsi(x, y, bs)
22*5f757f3fSDimitry Andric #define __riscv_aes32dsmi(x, y, bs) __builtin_riscv_aes32dsmi(x, y, bs)
23*5f757f3fSDimitry Andric #endif
24*5f757f3fSDimitry Andric 
25*5f757f3fSDimitry Andric #if __riscv_xlen == 64
26*5f757f3fSDimitry Andric static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
27*5f757f3fSDimitry Andric __riscv_aes64ds(uint64_t __x, uint64_t __y) {
28*5f757f3fSDimitry Andric   return __builtin_riscv_aes64ds(__x, __y);
29*5f757f3fSDimitry Andric }
30*5f757f3fSDimitry Andric 
31*5f757f3fSDimitry Andric static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
32*5f757f3fSDimitry Andric __riscv_aes64dsm(uint64_t __x, uint64_t __y) {
33*5f757f3fSDimitry Andric   return __builtin_riscv_aes64dsm(__x, __y);
34*5f757f3fSDimitry Andric }
35*5f757f3fSDimitry Andric 
36*5f757f3fSDimitry Andric static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
37*5f757f3fSDimitry Andric __riscv_aes64im(uint64_t __x) {
38*5f757f3fSDimitry Andric   return __builtin_riscv_aes64im(__x);
39*5f757f3fSDimitry Andric }
40*5f757f3fSDimitry Andric #endif
41*5f757f3fSDimitry Andric #endif // defined(__riscv_zknd)
42*5f757f3fSDimitry Andric 
43*5f757f3fSDimitry Andric #if defined(__riscv_zkne)
44*5f757f3fSDimitry Andric #if __riscv_xlen == 32
45*5f757f3fSDimitry Andric #define __riscv_aes32esi(x, y, bs) __builtin_riscv_aes32esi(x, y, bs)
46*5f757f3fSDimitry Andric #define __riscv_aes32esmi(x, y, bs) __builtin_riscv_aes32esmi(x, y, bs)
47*5f757f3fSDimitry Andric #endif
48*5f757f3fSDimitry Andric 
49*5f757f3fSDimitry Andric #if __riscv_xlen == 64
50*5f757f3fSDimitry Andric static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
51*5f757f3fSDimitry Andric __riscv_aes64es(uint64_t __x, uint64_t __y) {
52*5f757f3fSDimitry Andric   return __builtin_riscv_aes64es(__x, __y);
53*5f757f3fSDimitry Andric }
54*5f757f3fSDimitry Andric 
55*5f757f3fSDimitry Andric static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
56*5f757f3fSDimitry Andric __riscv_aes64esm(uint64_t __x, uint64_t __y) {
57*5f757f3fSDimitry Andric   return __builtin_riscv_aes64esm(__x, __y);
58*5f757f3fSDimitry Andric }
59*5f757f3fSDimitry Andric #endif
60*5f757f3fSDimitry Andric #endif // defined(__riscv_zkne)
61*5f757f3fSDimitry Andric 
62*5f757f3fSDimitry Andric #if defined(__riscv_zknd) || defined(__riscv_zkne)
63*5f757f3fSDimitry Andric #if __riscv_xlen == 64
64*5f757f3fSDimitry Andric #define __riscv_aes64ks1i(x, rnum) __builtin_riscv_aes64ks1i(x, rnum)
65*5f757f3fSDimitry Andric 
66*5f757f3fSDimitry Andric static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
67*5f757f3fSDimitry Andric __riscv_aes64ks2(uint64_t __x, uint64_t __y) {
68*5f757f3fSDimitry Andric   return __builtin_riscv_aes64ks2(__x, __y);
69*5f757f3fSDimitry Andric }
70*5f757f3fSDimitry Andric #endif
71*5f757f3fSDimitry Andric #endif // defined(__riscv_zknd) || defined(__riscv_zkne)
72*5f757f3fSDimitry Andric 
73*5f757f3fSDimitry Andric #if defined(__riscv_zknh)
74*5f757f3fSDimitry Andric static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
75*5f757f3fSDimitry Andric __riscv_sha256sig0(uint32_t __x) {
76*5f757f3fSDimitry Andric   return __builtin_riscv_sha256sig0(__x);
77*5f757f3fSDimitry Andric }
78*5f757f3fSDimitry Andric 
79*5f757f3fSDimitry Andric static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
80*5f757f3fSDimitry Andric __riscv_sha256sig1(uint32_t __x) {
81*5f757f3fSDimitry Andric   return __builtin_riscv_sha256sig1(__x);
82*5f757f3fSDimitry Andric }
83*5f757f3fSDimitry Andric 
84*5f757f3fSDimitry Andric static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
85*5f757f3fSDimitry Andric __riscv_sha256sum0(uint32_t __x) {
86*5f757f3fSDimitry Andric   return __builtin_riscv_sha256sum0(__x);
87*5f757f3fSDimitry Andric }
88*5f757f3fSDimitry Andric 
89*5f757f3fSDimitry Andric static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
90*5f757f3fSDimitry Andric __riscv_sha256sum1(uint32_t __x) {
91*5f757f3fSDimitry Andric   return __builtin_riscv_sha256sum1(__x);
92*5f757f3fSDimitry Andric }
93*5f757f3fSDimitry Andric 
94*5f757f3fSDimitry Andric #if __riscv_xlen == 32
95*5f757f3fSDimitry Andric static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
96*5f757f3fSDimitry Andric __riscv_sha512sig0h(uint32_t __x, uint32_t __y) {
97*5f757f3fSDimitry Andric   return __builtin_riscv_sha512sig0h(__x, __y);
98*5f757f3fSDimitry Andric }
99*5f757f3fSDimitry Andric 
100*5f757f3fSDimitry Andric static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
101*5f757f3fSDimitry Andric __riscv_sha512sig0l(uint32_t __x, uint32_t __y) {
102*5f757f3fSDimitry Andric   return __builtin_riscv_sha512sig0l(__x, __y);
103*5f757f3fSDimitry Andric }
104*5f757f3fSDimitry Andric 
105*5f757f3fSDimitry Andric static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
106*5f757f3fSDimitry Andric __riscv_sha512sig1h(uint32_t __x, uint32_t __y) {
107*5f757f3fSDimitry Andric   return __builtin_riscv_sha512sig1h(__x, __y);
108*5f757f3fSDimitry Andric }
109*5f757f3fSDimitry Andric 
110*5f757f3fSDimitry Andric static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
111*5f757f3fSDimitry Andric __riscv_sha512sig1l(uint32_t __x, uint32_t __y) {
112*5f757f3fSDimitry Andric   return __builtin_riscv_sha512sig1l(__x, __y);
113*5f757f3fSDimitry Andric }
114*5f757f3fSDimitry Andric 
115*5f757f3fSDimitry Andric static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
116*5f757f3fSDimitry Andric __riscv_sha512sum0r(uint32_t __x, uint32_t __y) {
117*5f757f3fSDimitry Andric   return __builtin_riscv_sha512sum0r(__x, __y);
118*5f757f3fSDimitry Andric }
119*5f757f3fSDimitry Andric 
120*5f757f3fSDimitry Andric static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
121*5f757f3fSDimitry Andric __riscv_sha512sum1r(uint32_t __x, uint32_t __y) {
122*5f757f3fSDimitry Andric   return __builtin_riscv_sha512sum1r(__x, __y);
123*5f757f3fSDimitry Andric }
124*5f757f3fSDimitry Andric #endif
125*5f757f3fSDimitry Andric 
126*5f757f3fSDimitry Andric #if __riscv_xlen == 64
127*5f757f3fSDimitry Andric static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
128*5f757f3fSDimitry Andric __riscv_sha512sig0(uint64_t __x) {
129*5f757f3fSDimitry Andric   return __builtin_riscv_sha512sig0(__x);
130*5f757f3fSDimitry Andric }
131*5f757f3fSDimitry Andric 
132*5f757f3fSDimitry Andric static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
133*5f757f3fSDimitry Andric __riscv_sha512sig1(uint64_t __x) {
134*5f757f3fSDimitry Andric   return __builtin_riscv_sha512sig1(__x);
135*5f757f3fSDimitry Andric }
136*5f757f3fSDimitry Andric 
137*5f757f3fSDimitry Andric static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
138*5f757f3fSDimitry Andric __riscv_sha512sum0(uint64_t __x) {
139*5f757f3fSDimitry Andric   return __builtin_riscv_sha512sum0(__x);
140*5f757f3fSDimitry Andric }
141*5f757f3fSDimitry Andric 
142*5f757f3fSDimitry Andric static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
143*5f757f3fSDimitry Andric __riscv_sha512sum1(uint64_t __x) {
144*5f757f3fSDimitry Andric   return __builtin_riscv_sha512sum1(__x);
145*5f757f3fSDimitry Andric }
146*5f757f3fSDimitry Andric #endif
147*5f757f3fSDimitry Andric #endif // defined(__riscv_zknh)
148*5f757f3fSDimitry Andric 
149*5f757f3fSDimitry Andric #if defined(__riscv_zksh)
150*5f757f3fSDimitry Andric static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
151*5f757f3fSDimitry Andric __riscv_sm3p0(uint32_t __x) {
152*5f757f3fSDimitry Andric   return __builtin_riscv_sm3p0(__x);
153*5f757f3fSDimitry Andric }
154*5f757f3fSDimitry Andric 
155*5f757f3fSDimitry Andric static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
156*5f757f3fSDimitry Andric __riscv_sm3p1(uint32_t __x) {
157*5f757f3fSDimitry Andric   return __builtin_riscv_sm3p1(__x);
158*5f757f3fSDimitry Andric }
159*5f757f3fSDimitry Andric #endif // defined(__riscv_zksh)
160*5f757f3fSDimitry Andric 
161*5f757f3fSDimitry Andric #if defined(__riscv_zksed)
162*5f757f3fSDimitry Andric #define __riscv_sm4ed(x, y, bs) __builtin_riscv_sm4ed(x, y, bs);
163*5f757f3fSDimitry Andric #define __riscv_sm4ks(x, y, bs) __builtin_riscv_sm4ks(x, y, bs);
164*5f757f3fSDimitry Andric #endif // defined(__riscv_zksed)
165*5f757f3fSDimitry Andric 
166*5f757f3fSDimitry Andric #if defined(__cplusplus)
167*5f757f3fSDimitry Andric }
168*5f757f3fSDimitry Andric #endif
169*5f757f3fSDimitry Andric 
170*5f757f3fSDimitry Andric #endif
171