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))
315 if (profile_list_name == 0)
335 .path =
"set pot profile",
336 .short_help =
"set pot profile name <string> id [0-1] [validator-key 0xu64] \ 337 prime-number 0xu64 secret_share 0xu64 lpc 0xu64 \ 338 polynomial2 0xu64 bits-in-random [0-64] ",
346 u8 *profile_list_name =
NULL;
353 &profile_list_name));
354 else if (
unformat(input,
"id %d", &
id))
360 if (profile_list_name == 0)
378 .path =
"set pot profile-active",
379 .short_help =
"set pot profile-active name <string> id [0-1]",
393 s =
format(s,
"POT Profiles not configured\n");
403 s =
format(s,
"POT Profile at index: %d\n", i);
405 s =
format(s,
" Validator : %s (%d)\n",
408 s =
format(s,
" Secret key : 0x%Lx (%Ld)\n",
410 s =
format(s,
" Secret share : 0x%Lx (%Ld)\n",
412 s =
format(s,
" Prime number : 0x%Lx (%Ld)\n",
414 s =
format(s,
"2nd polynomial(eval) : 0x%Lx (%Ld)\n",
418 s =
format(s,
" Bit mask : 0x%Lx (%Ld)\n",
426 s =
format(s,
"Pkts passed : 0x%Lx (%Ld)\n",
430 s =
format(s,
" This is Decap node. \n");
432 s =
format(s,
"\nProfile index in use: None\n");
442 .path =
"show pot profile",
443 .short_help =
"show pot profile",
void clear_pot_profiles()
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)
Optimized string handling code, including c11-compliant "safe C library" variants.
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)
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
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)
#define clib_error_return(e, args...)
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)
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)
#define VLIB_CLI_COMMAND(x,...)
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)
#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)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
int pot_profile_set_bit_mask(pot_profile *profile, u16 bits)