Skip to content

Commit c8e64bc

Browse files
authored
Merge pull request #200 from ueno/wip/merge-crau2
Replace dist/audit.h with the crau library
2 parents 4df5d90 + 37ac065 commit c8e64bc

File tree

8 files changed

+547
-92
lines changed

8 files changed

+547
-92
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ You can open the generated `flamegraph.html` with your browser.
204204
## License
205205

206206
- `agent/src/bpf/audit.bpf.c`: GPL-2.0-or-later
207-
- `dist/audit.h`: MIT
207+
- `dist/crau/*`: MIT OR Unlicense
208208
- `scripts/flamegraph.py`: GPL-2.0-only
209209
- everything else: GPL-3.0-or-later
210210

dist/audit.h

Lines changed: 0 additions & 91 deletions
This file was deleted.

dist/crau/.dir-locals.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
((c-mode . ((c-file-style . "linux"))))

dist/crau/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Daiki Ueno
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

dist/crau/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# crau
2+
3+
`crau` is a header-only library to help define
4+
[crypto-auditing][crypto-auditing] probes in C applications.
5+
6+
## Getting started
7+
8+
1. Define `ENABLE_CRYPTO_AUDITING` to 1, e.g., through
9+
`<config.h>`. Also check if `<sys/sdt.h>` is installed and
10+
`DTRACE_PROBE*` macros are defined there.
11+
12+
1. Include `<crau/crau.h>`. One of the C files should define
13+
`CRAU_IMPLEMENTATION` to get the functions defined. Also decide
14+
where to manage the context stack: if it is part of another struct,
15+
add field with type `struct crau_context_stack_st`; if it is
16+
maintained globally as thread-local, define a thread-local
17+
variable.
18+
19+
1. (Optional) Customize the implementation with configuration macros,
20+
e.g., `CRAU_CONTEXT_STACK_DEPTH` for your needs. See
21+
`<crau/crau.h>` for the details.
22+
23+
1. Instrument the code as follows. See `<crau/crau.h>` and
24+
`<crau/macros.h>` for the documentation:
25+
26+
```c
27+
/* Public key signing operation starts (but the algorithm is not known yet) */
28+
crau_new_context_with_data(
29+
&stack,
30+
"name", CRAU_STRING, "pk::sign",
31+
NULL)
32+
...
33+
/* Signing algorithm and bits are known at this point */
34+
crau_data(
35+
&stack,
36+
"pk::algorithm", CRAU_STRING, "mldsa",
37+
"pk::bits", CRAU_WORD, 1952 * 8,
38+
NULL)
39+
40+
/* Do the operation */
41+
sig = mldsa_sign(...);
42+
43+
/* Pop the operation context */
44+
crau_pop_context(&stack);
45+
```
46+
47+
## Low level macros
48+
49+
Instead of using those helper functions (`crau_*`), it is also
50+
possible to directly instrument the library with `CRAU_` macros
51+
defined in `macros.h`:
52+
53+
```c
54+
/* Public key signing operation starts (but the algorithm is not known yet) */
55+
CRAU_NEW_CONTEXT_WITH_DATAV(
56+
(long)this_function,
57+
(long)parent_function,
58+
CRAU_STRING_DATA("name", "pk::sign"));
59+
...
60+
/* Signing algorithm and bits are known at this point */
61+
CRAU_DATAV(
62+
(long)this_function,
63+
CRAU_STRING_DATA("pk::algorithm", "mldsa"),
64+
CRAU_WORD_DATA("pk::bits", 1952 * 8))
65+
66+
/* Do the operation */
67+
sig = mldsa_sign(...);
68+
```
69+
70+
Note that those macros don't do context management.
71+
72+
## License
73+
74+
MIT OR Unlicense
75+
76+
[crypto-auditing]: https://github.com/latchset/crypto-auditing

dist/crau/UNLICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org/>

0 commit comments

Comments
 (0)