Skip to content

Commit

Permalink
lib.ipsec.esp: optimize padding by specializing for power of two
Browse files Browse the repository at this point in the history
Saves some cycles during encapsulation by specializing the padding function for
power of two alignments.
  • Loading branch information
eugeneia committed Sep 11, 2018
1 parent 66a0dbb commit 796c177
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/ipsec/esp.lua
Expand Up @@ -30,6 +30,7 @@ local lib = require("core.lib")
local ffi = require("ffi")
local C = ffi.C
local logger = lib.logger_new({ rate = 32, module = 'esp' })
local band = bit.band

local htons, htonl, ntohl = lib.htons, lib.htonl, lib.ntohl

Expand All @@ -51,7 +52,8 @@ local ESP_TAIL_SIZE = esp_tail:sizeof()

local TRANSPORT6_PAYLOAD_OFFSET = ETHERNET_SIZE + IPV6_SIZE

local function padding (a, l) return (a - l%a) % a end
-- NB: `a' must be a power of two
local function padding (a, l) return bit.band(-l, a-1) end

-- AEAD identifier from:
-- https://github.com/YangModels/yang/blob/master/experimental/ietf-extracted-YANG-modules/ietf-ipsec@2018-01-08.yang
Expand Down

0 comments on commit 796c177

Please sign in to comment.