@@ -253,7 +253,7 @@ control ipsec_crypto( inout headers_t hdr,
253
253
bit <64 > esn ) {
254
254
255
255
// 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
257
257
bit <128 > iv = (bit <128 >)(salt ++ hdr .esp_iv .iv );
258
258
ipsec_acc .set_iv (iv );
259
259
@@ -270,10 +270,9 @@ control ipsec_crypto( inout headers_t hdr,
270
270
bit <16 > aad_len = hdr .esp .minSizeInBytes ();
271
271
272
272
// 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
277
276
ipsec_acc .set_auth_data_offset (aad_offset );
278
277
ipsec_acc .set_auth_data_len (aad_len );
279
278
@@ -300,7 +299,7 @@ control ipsec_crypto( inout headers_t hdr,
300
299
hdr .recirc_header .ipsec_len = encr_pyld_len ;
301
300
hdr .recirc_header .setValid ();
302
301
303
- // TODO: recirc_packet() is hardware specific extern
302
+ // TODO: recirc_packet() is hardware specific extern, or it can be standardized
304
303
recirc_packet ();
305
304
}
306
305
@@ -312,7 +311,9 @@ control ipsec_crypto( inout headers_t hdr,
312
311
bit <1 > enable_auth ,
313
312
bit <64 > esn ) {
314
313
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
316
317
// esn = esn + 1;
317
318
318
319
// Set IV information needed for encryption
@@ -363,7 +364,7 @@ control ipsec_crypto( inout headers_t hdr,
363
364
364
365
// instruct engine to add icv after encrypted payload
365
366
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 (32 w4 ); // Four bytes of ICV value.
367
368
368
369
// run encryption w/ authentication
369
370
ipsec_acc .enable_encrypt (enable_auth );
@@ -386,8 +387,10 @@ control ipsec_crypto( inout headers_t hdr,
386
387
ipsec_esp_decrypt (spi , salt , key , key_size , ext_esn_en , auth_en , esn );
387
388
}
388
389
}
389
- // setup crypto accelerator for decryption - get info from sa table
390
+ // setup crypto accelerator for encryption/ decryption - get info from sa table
390
391
// 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
391
394
table ipsec_sa {
392
395
key = {
393
396
// For encrypt case get sa_idx from parser
0 commit comments