4 void do_test(uint64_t value
)
7 uint64_t encode
, decode
;
10 * With TBI enabled and a 48-bit VA, there are 7 bits of auth,
11 * and so a 1/128 chance of encode = pac(value,key,salt) producing
12 * an auth for which leaves value unchanged.
13 * Iterate until we find a salt for which encode != value.
15 for (salt1
= 1; ; salt1
++) {
16 asm volatile("pacda %0, %2" : "=r"(encode
) : "0"(value
), "r"(salt1
));
17 if (encode
!= value
) {
22 /* A valid salt must produce a valid authorization. */
23 asm volatile("autda %0, %2" : "=r"(decode
) : "0"(encode
), "r"(salt1
));
24 assert(decode
== value
);
27 * An invalid salt usually fails authorization, but again there
28 * is a chance of choosing another salt that works.
29 * Iterate until we find another salt which does fail.
31 for (salt2
= salt1
+ 1; ; salt2
++) {
32 asm volatile("autda %0, %2" : "=r"(decode
) : "0"(encode
), "r"(salt2
));
33 if (decode
!= value
) {
38 /* The VA bits, bit 55, and the TBI bits, should be unchanged. */
39 assert(((decode
^ value
) & 0xff80ffffffffffffull
) == 0);
42 * Bits [54:53] are an error indicator based on the key used;
43 * the DA key above is keynumber 0, so error == 0b01. Otherwise
44 * bit 55 of the original is sign-extended into the rest of the auth.
46 if ((value
>> 55) & 1) {
47 assert(((decode
>> 48) & 0xff) == 0b10111111);
49 assert(((decode
>> 48) & 0xff) == 0b00100000);
56 do_test(0xda004acedeadbeefull
);