1
2
3
4
5
6
7 package nistec
8
9 import (
10 "syscall"
11 "testing"
12 "unsafe"
13 )
14
15
16
17 func dangerousObjs[T any](t *testing.T) (start *T, end *T) {
18 pagesize := syscall.Getpagesize()
19 b, err := syscall.Mmap(0, 0, 3*pagesize, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANONYMOUS|syscall.MAP_PRIVATE)
20 if err != nil {
21 t.Fatalf("mmap failed %s", err)
22 }
23 err = syscall.Mprotect(b[:pagesize], syscall.PROT_NONE)
24 if err != nil {
25 t.Fatalf("mprotect low failed %s\n", err)
26 }
27 err = syscall.Mprotect(b[2*pagesize:], syscall.PROT_NONE)
28 if err != nil {
29 t.Fatalf("mprotect high failed %s\n", err)
30 }
31 b = b[pagesize : 2*pagesize]
32 end = (*T)(unsafe.Pointer(&b[len(b)-(int)(unsafe.Sizeof(*end))]))
33 start = (*T)(unsafe.Pointer(&b[0]))
34 return start, end
35 }
36
37 func TestP256SelectAffinePageBoundary(t *testing.T) {
38 var out p256AffinePoint
39 begintp, endtp := dangerousObjs[p256AffineTable](t)
40 for i := 0; i < 31; i++ {
41 p256SelectAffine(&out, begintp, i)
42 p256SelectAffine(&out, endtp, i)
43 }
44 }
45
46 func TestP256SelectPageBoundary(t *testing.T) {
47 var out P256Point
48 begintp, endtp := dangerousObjs[p256Table](t)
49 for i := 0; i < 15; i++ {
50 p256Select(&out, begintp, i)
51 p256Select(&out, endtp, i)
52 }
53 }
54
View as plain text