76 return (0==strncmp ((
char *) name0, (
char *)name1, len0));
111 u16 id = profile->
id;
120 if (profile && !profile->
in_use)
123 profile->
prime = prime;
138 if (profile && !profile->
in_use)
148 u64 secret_share,
u64 prime,
u64 lpc,
u64 pre_split,
double prime_inv)
150 u64 share_random = 0;
151 u64 cumulative_new = 0;
156 share_random =
add64_mod(pre_split, random, prime, prime_inv);
161 share_random =
add64_mod(share_random, secret_share, prime, prime_inv);
162 share_random =
mul64_mod(share_random, lpc, prime, prime_inv);
164 cumulative_new =
add64_mod(cumulative, share_random, prime, prime_inv);
166 return (cumulative_new);
171 if (profile && profile->
valid != 0)
181 u64 cumulative,
u64 random)
183 if (cumulative == (random + secret))
187 else if (cumulative ==
add64_mod(random, secret, prime, prime_inv))
202 profile->
primeinv, cumulative, random));
224 random &= 0xffffffff;
225 random = random << 32;
231 random |= second_half;
244 if (profile && !profile->
in_use)
246 sizeInBits =
sizeof(profile->
bit_mask) * 8;
249 sizeInBits ? (
u64) - 1 : (
u64) ((
u64) 1 << (
u64) bits) - 1);
271 .path =
"clear pot profile",
272 .short_help =
"clear pot profile [<index>|all]",
285 u64 lpc = 0, poly2 = 0;
287 u8 *profile_list_name =
NULL;
294 &profile_list_name));
295 else if (
unformat(input,
"id %d", &profile_id))
297 else if (
unformat(input,
"validate-key 0x%Lx", &secret_key))
299 else if (
unformat(input,
"prime-number 0x%Lx", &prime))
301 else if (
unformat(input,
"secret_share 0x%Lx", &secret_share))
303 else if (
unformat(input,
"polynomial2 0x%Lx", &poly2))
305 else if (
unformat(input,
"lpc 0x%Lx", &lpc))
307 else if (
unformat(input,
"bits-in-random %d", &bits))
316 if (profile_list_name == 0)
336 .path =
"set pot profile",
337 .short_help =
"set pot profile name <string> id [0-1] [validator-key 0xu64] \ 338 prime-number 0xu64 secret_share 0xu64 lpc 0xu64 \ 339 polynomial2 0xu64 bits-in-random [0-64] ",
347 u8 *profile_list_name =
NULL;
354 &profile_list_name));
355 else if (
unformat(input,
"id %d", &
id))
361 if (profile_list_name == 0)
379 .path =
"set pot profile-active",
380 .short_help =
"set pot profile-active name <string> id [0-1]",
394 s =
format(s,
"POT Profiles not configured\n");
404 s =
format(s,
"POT Profile at index: %d\n", i);
406 s =
format(s,
" Validator : %s (%d)\n",
409 s =
format(s,
" Secret key : 0x%Lx (%Ld)\n",
411 s =
format(s,
" Secret share : 0x%Lx (%Ld)\n",
413 s =
format(s,
" Prime number : 0x%Lx (%Ld)\n",
415 s =
format(s,
"2nd polynomial(eval) : 0x%Lx (%Ld)\n",
419 s =
format(s,
" Bit mask : 0x%Lx (%Ld)\n",
427 s =
format(s,
"Pkts passed : 0x%Lx (%Ld)\n",
431 s =
format(s,
" This is Decap node. \n");
433 s =
format(s,
"\nProfile index in use: None\n");
443 .path =
"show pot profile",
444 .short_help =
"show pot profile",
void clear_pot_profiles()
sll srl srl sll sra u16x4 i
static uword random_default_seed(void)
Default random seed (unix/linux user-mode)
pot_profile * pot_profile_find(u8 id)
int pot_profile_create(pot_profile *profile, u64 prime, u64 poly2, u64 lpc, u64 secret_share)
static clib_error_t * set_pot_profile_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static u64 mul64_mod(u64 a, u64 b, u64 p, double pi)
static u64 add64_mod(u64 a, u64 b, u64 p, double pi)
static void pot_main_profiles_reset(void)
static clib_error_t * show_pot_profile_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static u8 pot_validate_inline(u64 secret, u64 prime, double prime_inv, u64 cumulative, u64 random)
static int pot_profile_name_equal(u8 *name0, u8 *name1)
static int pot_profile_set_active(u8 id)
static clib_error_t * set_pot_profile_activate_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static void pot_profile_cleanup(pot_profile *profile)
#define vec_dup(V)
Return copy of vector (no header, no alignment)
u8 pot_validate(pot_profile *profile, u64 cumulative, u64 random)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static u64 pot_update_cumulative_inline(u64 cumulative, u64 random, u64 secret_share, u64 prime, u64 lpc, u64 pre_split, double prime_inv)
u64 total_pkts_using_this_profile
#define vec_free(V)
Free vector's memory (no header).
u64 pot_generate_random(pot_profile *profile)
pot_profile profile_list[MAX_POT_PROFILES]
int pot_set_validator(pot_profile *profile, u64 key)
static void pot_profile_init(pot_profile *new, u8 id)
VLIB_CLI_COMMAND(set_interface_ip_source_and_port_range_check_command, static)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
clib_error_t * clear_pot_profile_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u64 pot_update_cumulative(pot_profile *profile, u64 cumulative, u64 random)
void pot_profile_list_init(u8 *profile_list_name)
int pot_profile_list_is_enabled(u8 *name)
static u32 random_u32(u32 *seed)
32-bit random number generator
static u8 pot_is_decap(pot_profile *p)
#define clib_error_return(e, args...)
int pot_profile_set_bit_mask(pot_profile *profile, u16 bits)