Skip to content

Commit 6ded306

Browse files
committed
review comments
1 parent 70bdefc commit 6ded306

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

examples/include/crypto-accelerator.p4

+16-21
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,28 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
/// Crypto accelerator Extern
18-
enum bit<8> crypto_algorithm_e {
19-
AES_GCM = 1
20-
}
21-
enum bit<8> crypto_results_e {
22-
SUCCESS = 0,
23-
AUTH_FAILURE = 1,
24-
HW_ERROR = 2
17+
/// Crypto accelerator Extern definition
18+
19+
/// Crypto accelerator object is instantiated for each crypto algorithm
20+
enum crypto_algorithm_e {
21+
AES_GCM
2522
}
2623

27-
enum bit<8> crypto_error_action_e {
28-
NO_ACTION = 0,
29-
DROP_PACKET = 1,
30-
SEND_TO_PORT = 2
24+
/// Results from crypto accelerator
25+
enum crypto_results_e {
26+
SUCCESS,
27+
AUTH_FAILURE,
28+
HW_ERROR
3129
}
3230

31+
/// special value to indicate that ICV is after the crypto payload
3332
#define ICV_AFTER_PAYLOAD ((int<32>)-1)
3433

3534
/// The crypto_accelerator engine used in this example uses AES-GCM algorithm.
3635
/// It is assumed to be agnostic to wire protocols i.e. does not understand protocol
3736
/// specific headers like ESP, AH etc
3837
///
39-
/// Note that crypto accelerator does not modify the packet outside the payload area and ICV
38+
/// The crypto accelerator does not modify the packet outside the payload area and ICV
4039
/// Any wire-protocol header, trailer add/remove is handled by P4 pipeline
4140
/// The engine does not perform additional functions such as anti-replay protection, it
4241
/// is done in P4 pipeline
@@ -56,12 +55,12 @@ enum bit<8> crypto_error_action_e {
5655
/// Packet presented to the engine -
5756
/// +------------------+--------------------------+-----------+
5857
/// | Headers not to | Encryption protocol | payload |
59-
/// | Encrypted | headers (E.g Esp, Esp-IV)| |
58+
/// | be Encrypted | headers (E.g Esp, Esp-IV)| |
6059
/// +------------------+----------------------- -+-----------+
6160
/// Packet after Encryption:
6261
/// +------------------+--------------------------+-----------+-----------+
6362
/// | Headers not to | Encryption protocol | Encrypted | ICV (opt) |
64-
/// | Encrypted | headers (E.g Esp, Esp-IV)| Payload | |
63+
/// | be Encrypted | headers (E.g Esp, Esp-IV)| Payload | |
6564
/// +------------------+--------------------------+-----------+-----------+
6665
/// ICV can be inserted either before or right after the encrypted payload
6766
/// as specified by icv_location/size
@@ -127,10 +126,6 @@ extern crypto_accelerator {
127126
// whichever method is called last overrides the previous calls
128127
void disable();
129128

130-
crypto_results_e get_results(); // get results of the previous operation
131-
132-
// set_error_action() indicates behavior on encoutering an error
133-
// Default action is NO_ACTION i.e. report error via get_results()
134-
// Certain actions may need action parameters, e.g send_to_port
135-
void set_error_action<T>(crypto_error_action_e error_action, in T action_param);
129+
// get results of the previous operation
130+
crypto_results_e get_results();
136131
}

examples/ipsec-acc.p4

+12-9
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ control ipsec_crypto( inout headers_t hdr,
253253
bit<64> esn) {
254254

255255
// IV(nonce) needed for AES-GCM algorithm
256-
// if consists of iv that is sent on the wire plus an internally maintained salt value
256+
// it consists of iv that is sent on the wire plus an internally maintained salt value
257257
bit<128> iv = (bit<128>)(salt ++ hdr.esp_iv.iv);
258258
ipsec_acc.set_iv(iv);
259259

@@ -270,10 +270,9 @@ control ipsec_crypto( inout headers_t hdr,
270270
bit<16> aad_len = hdr.esp.minSizeInBytes();
271271

272272
// Action parameter esn is expected to be stateful, i.e. the following operations
273-
// are possible to update esn and check every packet against expected seq number
274-
// to perform anti-replay checks.. this is not shown in this example
275-
// esn = esn + 1;
276-
273+
// esn checking / anti-replay attack prevention is not shown in this example
274+
// as it can be implemented in P4 pipeline and does not affect use of
275+
// the extern object shown in this example
277276
ipsec_acc.set_auth_data_offset(aad_offset);
278277
ipsec_acc.set_auth_data_len(aad_len);
279278

@@ -300,7 +299,7 @@ control ipsec_crypto( inout headers_t hdr,
300299
hdr.recirc_header.ipsec_len = encr_pyld_len;
301300
hdr.recirc_header.setValid();
302301

303-
// TODO: recirc_packet() is hardware specific extern
302+
// TODO: recirc_packet() is hardware specific extern, or it can be standardized
304303
recirc_packet();
305304
}
306305

@@ -312,7 +311,9 @@ control ipsec_crypto( inout headers_t hdr,
312311
bit<1> enable_auth,
313312
bit<64> esn) {
314313

315-
// Initialize the ipsec accelerator
314+
// update sequence number for each transmitted packet
315+
// This can be done using stateful registers currently defined in P4
316+
// it is not shown in this example
316317
// esn = esn + 1;
317318

318319
// Set IV information needed for encryption
@@ -363,7 +364,7 @@ control ipsec_crypto( inout headers_t hdr,
363364

364365
// instruct engine to add icv after encrypted payload
365366
ipsec_acc.set_icv_offset(ICV_AFTER_PAYLOAD);
366-
ipsec_acc.set_icv_len((bit<32>)4); // Four bytes of ICV value.
367+
ipsec_acc.set_icv_len(32w4); // Four bytes of ICV value.
367368

368369
// run encryption w/ authentication
369370
ipsec_acc.enable_encrypt(enable_auth);
@@ -386,8 +387,10 @@ control ipsec_crypto( inout headers_t hdr,
386387
ipsec_esp_decrypt(spi, salt, key, key_size, ext_esn_en, auth_en, esn);
387388
}
388389
}
389-
// setup crypto accelerator for decryption - get info from sa table
390+
// setup crypto accelerator for encryption/decryption - get info from sa table
390391
// lookup sa_table using esp.spi
392+
// In this example same SA index is used for encrypt/decrypt, in real
393+
// implementation it can be separated into two entries
391394
table ipsec_sa {
392395
key = {
393396
// For encrypt case get sa_idx from parser

0 commit comments

Comments
 (0)