xref: /linux/tools/testing/selftests/arm64/pauth/helper.c (revision cbecf716ca618fd44feda6bd9a64a8179d031fc5)
1*766d95b1SBoyan Karatotev // SPDX-License-Identifier: GPL-2.0
2*766d95b1SBoyan Karatotev // Copyright (C) 2020 ARM Limited
3*766d95b1SBoyan Karatotev 
4*766d95b1SBoyan Karatotev #include "helper.h"
5*766d95b1SBoyan Karatotev 
keyia_sign(size_t ptr)6*766d95b1SBoyan Karatotev size_t keyia_sign(size_t ptr)
7*766d95b1SBoyan Karatotev {
8*766d95b1SBoyan Karatotev 	asm volatile("paciza %0" : "+r" (ptr));
9*766d95b1SBoyan Karatotev 	return ptr;
10*766d95b1SBoyan Karatotev }
11*766d95b1SBoyan Karatotev 
keyib_sign(size_t ptr)12*766d95b1SBoyan Karatotev size_t keyib_sign(size_t ptr)
13*766d95b1SBoyan Karatotev {
14*766d95b1SBoyan Karatotev 	asm volatile("pacizb %0" : "+r" (ptr));
15*766d95b1SBoyan Karatotev 	return ptr;
16*766d95b1SBoyan Karatotev }
17*766d95b1SBoyan Karatotev 
keyda_sign(size_t ptr)18*766d95b1SBoyan Karatotev size_t keyda_sign(size_t ptr)
19*766d95b1SBoyan Karatotev {
20*766d95b1SBoyan Karatotev 	asm volatile("pacdza %0" : "+r" (ptr));
21*766d95b1SBoyan Karatotev 	return ptr;
22*766d95b1SBoyan Karatotev }
23*766d95b1SBoyan Karatotev 
keydb_sign(size_t ptr)24*766d95b1SBoyan Karatotev size_t keydb_sign(size_t ptr)
25*766d95b1SBoyan Karatotev {
26*766d95b1SBoyan Karatotev 	asm volatile("pacdzb %0" : "+r" (ptr));
27*766d95b1SBoyan Karatotev 	return ptr;
28*766d95b1SBoyan Karatotev }
29*766d95b1SBoyan Karatotev 
keyg_sign(size_t ptr)30*766d95b1SBoyan Karatotev size_t keyg_sign(size_t ptr)
31*766d95b1SBoyan Karatotev {
32*766d95b1SBoyan Karatotev 	/* output is encoded in the upper 32 bits */
33*766d95b1SBoyan Karatotev 	size_t dest = 0;
34*766d95b1SBoyan Karatotev 	size_t modifier = 0;
35*766d95b1SBoyan Karatotev 
36*766d95b1SBoyan Karatotev 	asm volatile("pacga %0, %1, %2" : "=r" (dest) : "r" (ptr), "r" (modifier));
37*766d95b1SBoyan Karatotev 
38*766d95b1SBoyan Karatotev 	return dest;
39*766d95b1SBoyan Karatotev }
40