Skip to content

Commit 0b9c78a

Browse files
loalanAlan Lo
authored and
Alan Lo
committed
This example expands on the definition of crypto_accelerator (p4lang#53).
The example adds two methods for encrypt/decrypt that assumes that inline accelerators operate immediately on the packet (e.g. deparse, decrypt and reparse). Packet recirculation is not necessary for either inline method. The example shows the use of inline encrypt and decrypt, as well as how the crypto accelerator results can be used.
1 parent ebb2b6c commit 0b9c78a

File tree

2 files changed

+463
-0
lines changed

2 files changed

+463
-0
lines changed

examples/include/crypto-accelerator.p4

+51
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ enum crypto_results_e {
2828
HW_ERROR
2929
}
3030

31+
enum crypto_mode_e {
32+
TUNNEL,
33+
TRANSPORT,
34+
TRANSPORT_NAT_T
35+
}
36+
3137
/// special value to indicate that ICV is after the crypto payload
3238
#define ICV_AFTER_PAYLOAD ((int<32>)-1)
3339

@@ -122,6 +128,51 @@ extern crypto_accelerator {
122128
void enable_encrypt<T>(in T enable_auth);
123129
void enable_decrypt<T>(in T enable_auth);
124130

131+
// crypto accelerator runs immediately and returns control flow to the current pipeline
132+
// stage. The method is responsible for defining the contents of the ESP header,
133+
// calculating the payload offset and lengths, encrypting the payload appropriately and
134+
// reparsing the packet. User can decide if to proceed or reinject.
135+
//
136+
// Pre-conditions: The parser must have been executed prior to this extern. The packet
137+
// headers and metadata from the parser are provided as inout params.
138+
// Post-conditions: The deparser will be executed with encapsulation, the packet bitstream
139+
// will be updated and encryption will be performed on the payload. The packet will be
140+
// reparsed and parser states updated.
141+
// Side-effects: parser states will be re-evaluated if crypto has succeeded.
142+
//
143+
// H - inout Headers is the output of the parser block
144+
// M - inout Metadata is from the parser block and shared with the control
145+
// T - in enable_auth flag enables authentication check
146+
// S - in seq is the optional sequence number
147+
// I - in iv is the initialization vector
148+
crypto_results_e encrypt_inline<H,M,T,S,I>(inout H hdr, inout M meta,
149+
in crypto_mode_e mode,
150+
in T enable_auth,
151+
in bit<32> spi,
152+
in S seq,
153+
in I iv);
154+
155+
// crypto accelerator runs immediately and returns control flow to the current pipeline
156+
// stage. The method is responsible for decrypting the payload appropriately, removing
157+
// the ESP header, calculating the payload offset and lengths, and reparsing the packet.
158+
// The user should then check the status.
159+
//
160+
// Pre-conditions: The parser will have been executed prior to this extern. The packet
161+
// headers and metadata from the parser are provided as inout params.
162+
// Post-conditions: The deparser will be executed with decapsulation, packet bitstream
163+
// will be updated and decryption will be performed on the payload. The packet will be
164+
// reparsed and parser states recalculated.
165+
// Side-effects - parser states will be re-evaluated if crypto has succeeded.
166+
//
167+
// H - inout Headers is the output of the parser block
168+
// M - inout Metadata is from the parser block and shared with the control
169+
// T - in enable_auth flag enables authentication check
170+
// S - in seq is the optional sequence number
171+
crypto_results_e decrypt_inline<H,M,T,S>(inout H hdr, inout M meta,
172+
in crypto_mode_e mode,
173+
in T enable_auth,
174+
in S seq);
175+
125176
// disable crypto engine. Between enable and disable methods,
126177
// whichever method is called last overrides the previous calls
127178
void disable();

0 commit comments

Comments
 (0)