56 if (
id >= 0 &&
id < max)
58 return (&profile_list[
id]);
72 memcpy(
chain_path_name, path_name, strlen((
const char *)path_name) + 1);
98 profile->
prime = prime;
119 u64 secret_share,
u64 prime,
u64 lpc,
u64 pre_split,
double prime_inv)
121 u64 share_random = 0;
122 u64 cumulative_new = 0;
127 share_random =
add64_mod(pre_split, random, prime, prime_inv);
132 share_random =
add64_mod(share_random, secret_share, prime, prime_inv);
133 share_random =
mul64_mod(share_random, lpc, prime, prime_inv);
135 cumulative_new =
add64_mod(cumulative, share_random, prime, prime_inv);
137 return (cumulative_new);
142 if (profile && profile->
validity != 0)
152 u64 cumulative,
u64 random)
154 if (cumulative == (random + secret))
158 else if (cumulative ==
add64_mod(random, secret, prime, prime_inv))
173 profile->
primeinv, cumulative, random));
195 random &= 0xffffffff;
196 random = random << 32;
202 random |= second_half;
217 sizeInBits =
sizeof(profile->
bit_mask) * 8;
220 sizeInBits ? (
u64) - 1 : (
u64) ((
u64) 1 << (
u64) bits) - 1);
227 #define MAX_SERVICES 16 262 .path =
"clear scv profile",
263 .short_help =
"clear scv profile [<index>|all]",
271 u64 secret_share, validity;
276 u64 lpc = 0, poly2 = 0;
283 if (
unformat(input,
"id %d", &profile_id))
285 else if (
unformat(input,
"validate-key 0x%Lx", &secret_key))
287 else if (
unformat(input,
"prime-number 0x%Lx", &prime))
289 else if (
unformat(input,
"secret_share 0x%Lx", &secret_share))
291 else if (
unformat(input,
"polynomial2 0x%Lx", &poly2))
293 else if (
unformat(input,
"lpc 0x%Lx", &lpc))
295 else if (
unformat(input,
"validity 0x%Lx", &validity))
297 else if (
unformat(input,
"bits-in-random %d", &bits))
323 .path =
"set scv profile",
324 .short_help =
"set scv profile id [0-16] [validator-key 0xu64] \ 325 prime-number 0xu64 secret_share 0xu64 lpc 0xu64 \ 326 polynomial2 0xu64 bits-in-random [0-64] ",
339 s =
format(s,
"SCV Profiles not configured\n");
349 s =
format(s,
"SCV Profile at index: %d\n", i);
351 s =
format(s,
" Validator : %s (%d)\n",
354 s =
format(s,
" Secret key : 0x%Lx (%Ld)\n",
356 s =
format(s,
" Secret share : 0x%Lx (%Ld)\n",
358 s =
format(s,
" Prime number : 0x%Lx (%Ld)\n",
360 s =
format(s,
"2nd polynomial(eval) : 0x%Lx (%Ld)\n",
364 s =
format(s,
" Bit mask : 0x%Lx (%Ld)\n",
366 s =
format(s,
" Validity : 0x%Lx (%Ld)\n",
374 s =
format(s,
"\nInvalid profiles start : %d Number : %d\n",
378 s =
format(s,
"\nNext time to send : %U, time_exponent:%ld\n",
382 s =
format(s,
"\nNext time to send : Immediate\n");
385 s =
format(s,
"Pkts passed : 0x%Lx (validity:0x%Lx)\n",
388 s =
format(s,
" This is Decap node. \n");
398 .path =
"show scv profile",
399 .short_help =
"show scv profile",
406 u8 renew_or_refresh = 0;
408 #define TEST_PROFILE_RENEW 1 409 #define TEST_PROFILE_REFRESH 2 411 u32 start_index = 0, num_profiles = 0;
416 if (
unformat(input,
"path-name %s start-index %d num-profiles %d",
417 &path_name, &start_index, &num_profiles))
421 else if (
unformat(input,
"refresh"))
446 (rc != 0) ?
"failed" :
"sent", (
u32) rc);
455 .path =
"test ioam profile-notification ",
457 "test ioam profile-notification path-name <string> start-index <index> num-profiles <number> <renew|refresh>",
465 u32 start_index = 0, num_profiles = 0;
469 if (
unformat(input,
"path-name %s start-index %d num-profiles %d",
470 &path_name, &start_index, &num_profiles))
471 scv_init(path_name, num_profiles, start_index);
482 .path =
"set scv-init ",
484 "set scv-init path-name <string> start-index <index> num-profiles <number>",
scv_profile * scv_profile_find(u16 id)
static void scv_profile_init(scv_profile *new, u16 id)
#define MAX_SERVICE_PROFILES
void scv_profile_cleanup(scv_profile *profile)
sll srl srl sll sra u16x4 i
void scv_init(u8 *path_name, u8 max, u8 indx)
static u64 mul64_mod(u64 a, u64 b, u64 p, double pi)
static u64 add64_mod(u64 a, u64 b, u64 p, double pi)
clib_error_t * clear_scv_profile_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u8 scv_get_max_profiles(void)
u64 scv_update_cumulative(scv_profile *profile, u64 cumulative, u64 random)
static clib_error_t * show_scv_profile_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u8 scv_validate(scv_profile *profile, u64 cumulative, u64 random)
void scv_set_validator(scv_profile *profile, u64 key)
always_inline u32 random_u32(u32 *seed)
32-bit random number generator
static u64 sc_update_cumulative(u64 cumulative, u64 random, u64 secret_share, u64 prime, u64 lpc, u64 pre_split, double prime_inv)
static clib_error_t * set_scv_init_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
always_inline uword random_default_seed(void)
Default random seed (unix/linux user-mode)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
void scv_profile_set_bit_mask(scv_profile *profile, u16 bits)
u64 scv_generate_random(scv_profile *profile)
#define vec_free(V)
Free vector's memory (no header).
void clear_scv_profiles()
#define VLIB_CLI_COMMAND(x,...)
void scv_profile_create(scv_profile *profile, u64 prime, u64 poly2, u64 lpc, u64 secret_share, u64 validity)
u16 invalid_profile_start_index
int scv_profile_renew(u8 *path_name, u8 start_index, u8 num_profiles)
int scv_profile_refresh(u8 *path_name, u8 start_index, u8 num_profiles)
u64 total_pkts_using_this_profile
static clib_error_t * test_profile_renew_refresh_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * set_scv_profile_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u8 chain_path_name[PATH_NAME_SIZE]
#define TEST_PROFILE_REFRESH
static u8 scv_is_decap(scv_profile *p)
#define TEST_PROFILE_RENEW
#define clib_error_return(e, args...)
static u8 sc_validate(u64 secret, u64 prime, double prime_inv, u64 cumulative, u64 random)
u8 number_of_invalid_profiles