/* * Add IKE alg info _with_ logic (policy): */ static void per_group_alg_info_ike_add(struct alg_info *alg_info, int ealg_id, int ek_bits, int aalg_id, int ak_bits, int modp_id) { if (ealg_id == 0) { /* use all our default enc algs */ int i; for (i=0; i != elemsof(default_ike_ealgs); i++) { per_group_alg_info_ike_add(alg_info, default_ike_ealgs[i], ek_bits, aalg_id, ak_bits, modp_id); } return; } { if (aalg_id > 0) { raw_alg_info_ike_add( (struct alg_info_ike *)alg_info, ealg_id, ek_bits, aalg_id, ak_bits, modp_id); } else { int j; for (j=0; j != elemsof(default_ike_aalgs); j++) { raw_alg_info_ike_add( (struct alg_info_ike *)alg_info, ealg_id, ek_bits, default_ike_aalgs[j], ak_bits, modp_id); } } } }
static void __alg_info_ike_add (struct alg_info_ike *alg_info , int ealg_id , unsigned ek_bits , int aalg_id , unsigned ak_bits , unsigned modp_id) { struct ike_info *ike_info=alg_info->ike; unsigned cnt=alg_info->alg_info_cnt, i; /* check for overflows */ passert(cnt < elemsof(alg_info->ike)); /* dont add duplicates */ for (i=0;i<cnt;i++) if ( ike_info[i].ike_ealg==ealg_id && (!ek_bits || ike_info[i].ike_eklen==ek_bits) && ike_info[i].ike_halg==aalg_id && (!ak_bits || ike_info[i].ike_hklen==ak_bits) && ike_info[i].ike_modp==modp_id ) return; ike_info[cnt].ike_ealg=ealg_id; ike_info[cnt].ike_eklen=ek_bits; ike_info[cnt].ike_halg=aalg_id; ike_info[cnt].ike_hklen=ak_bits; ike_info[cnt].ike_modp=modp_id; alg_info->alg_info_cnt++; DBG(DBG_CRYPT, DBG_log("__alg_info_ike_add() " "ealg=%d aalg=%d modp_id=%d, cnt=%d", ealg_id, aalg_id, modp_id, alg_info->alg_info_cnt)); }
main(int argc, char *argv[]){ int i; struct db_sa *sa1 = NULL; progname = argv[0]; leak_detective = 1; tool_init_log(); for (i = 0; i < elemsof(oakley_sadb); i++) { /* make sure that leak reports and EFence reports get * placed in the right order. */ fflush(stdout); fflush(stderr); printf("\nmain mode oakley: %u\n", i); sa_print(&oakley_sadb[i]); sa1 = sa_copy_sa_first(&oakley_sadb[i]); sa_print(sa1); free_sa(sa1); fflush(stdout); report_leaks(); } tool_close_log(); exit(0); }
/* * Raw add routine: only checks for no duplicates */ static void __alg_info_esp_add (struct alg_info_esp *alg_info , int ealg_id, unsigned ek_bits , int aalg_id, unsigned ak_bits) { struct esp_info *esp_info=alg_info->esp; unsigned cnt=alg_info->alg_info_cnt, i; /* check for overflows */ passert(cnt < elemsof(alg_info->esp)); /* dont add duplicates */ for (i=0;i<cnt;i++) if ( esp_info[i].esp_ealg_id==ealg_id && (!ek_bits || esp_info[i].esp_ealg_keylen==ek_bits) && esp_info[i].esp_aalg_id==aalg_id && (!ak_bits || esp_info[i].esp_aalg_keylen==ak_bits)) return; esp_info[cnt].esp_ealg_id=ealg_id; esp_info[cnt].esp_ealg_keylen=ek_bits; esp_info[cnt].esp_aalg_id=aalg_id; esp_info[cnt].esp_aalg_keylen=ak_bits; /* sadb values */ esp_info[cnt].encryptalg=ealg_id; esp_info[cnt].authalg=alg_info_esp_aa2sadb(aalg_id); alg_info->alg_info_cnt++; DBG(DBG_CRYPT, DBG_log("__alg_info_esp_add() " "ealg=%d aalg=%d cnt=%d", ealg_id, aalg_id, alg_info->alg_info_cnt)); }
int main(int argc, char *argv[]) { int i; struct db_sa *sa1 = NULL; struct db_sa *sa2 = NULL; progname = argv[0]; leak_detective=1; tool_init_log(); for(i=0; i < elemsof(oakley_sadb); i++) { printf("\nmain mode oakley: %u\n", i); sa_print(&oakley_sadb[i]); sa1 = sa_copy_sa(&oakley_sadb[i], 0); if(sa2 != NULL) { free_sa(sa2); } sa2 = sa_copy_sa(sa1, 0); free_sa(sa1); printf("copy 2\n"); sa_print(sa2); } for(i=0; i < elemsof(oakley_am_sadb); i++) { printf("\naggr mode oakley: %u\n", i); sa_print(&oakley_am_sadb[i]); sa1 = sa_copy_sa(&oakley_am_sadb[i], 0); if(sa2 != NULL) { free_sa(sa2); } sa2 = sa_copy_sa(sa1, 0); free_sa(sa1); printf("copy 2\n"); sa_print(sa2); } if(sa2 != NULL) free_sa(sa2); report_leaks(); tool_close_log(); exit(0); }
const struct oakley_group_desc *lookup_group(u_int16_t group) { int i; for (i = 0; i != elemsof(oakley_group); i++) if (group == oakley_group[i].group) return &oakley_group[i]; return NULL; }
/* Called to handle --interface <ifname> * Semantics: if specified, only these (real) interfaces are considered. */ bool use_interface(const char *rifn) { if (pluto_ifn_inst[0] == '\0') pluto_ifn_inst = clone_str(rifn, "genifn"); if (pluto_ifn_roof >= (int)elemsof(pluto_ifn)) { return FALSE; } else { pluto_ifn[pluto_ifn_roof++] = rifn; return TRUE; } }
main() { biglset_t a = BLEMPTY; biglset_t a2 = BLEMPTY; int i, fails=0; char out[512]; for(i=0; i< elemsof(bits1_on); i++) { biglset_t d = BLUNION(a, BLELEM(bits1_on[i])); a = d; } biglset_format(out, 512, a); if(strcmp(out, bits1_on_out)!=0) { printf("1 failure: %s <=> %s \n", out, bits1_on_out); fails++; } for(i=0; i< elemsof(bits2_off); i++) { biglset_t d = BLUNION(a2, BLELEM(bits2_off[i])); a2 = d; } biglset_format(out, 512, a2); if(strcmp(out, bits2_off_out)!=0) { printf("2 failure: %s <=> %s \n", out, bits2_off_out); fails++; } { biglset_t o = BLINTERSECT(a, a2); biglset_format(out, 512, o); if(strcmp(out, bits2_int_out)!=0) { printf("3 failure: %s <=> %s \n", out, bits2_int_out); fails++; } } exit(fails); }
int main(int argc, char *argv[]) { int i; progname = argv[0]; /* initialize list of moduli */ init_crypto(); for (i = 0; i != elemsof(oakley_group); i++) { calc_reciprocal(&oakley_group[i]); } exit(0); }
const char *AudioErrorString(const GLenum err) { static const struct Err { const GLenum err; const char *str; } tbl[] = { { AL_INVALID_NAME, "不正なネームの引数です" }, { AL_INVALID_ENUM, "不正な列挙値の引数です" }, { AL_INVALID_VALUE, "不正な引数です" }, { AL_INVALID_OPERATION, "禁止されている呼び出しです" }, { AL_OUT_OF_MEMORY, "メモリを割り当てる事が出来ません" }, { AL_NO_ERROR, "エラー番号が不正です" } }; int i; for (i = 0; i < elemsof(tbl); ++i) { if (tbl[i].err == err) break; } assert(i != elemsof(tbl)); if (i == elemsof(tbl)) --i; // エラー番号が不正だった時の対策 return tbl[i].str; }
/* * Initialize the random pool. */ void init_rnd_pool(void) { unsigned int i; unsigned int max_rnd_devices = elemsof(random_devices)+1; const char *rnd_dev; if(random_fd != -1) close(random_fd); random_fd = -1; for(i=0; random_fd == -1 && i<max_rnd_devices; i++) { DBG(DBG_CONTROL, DBG_log("opening %s", random_devices[i])); random_fd = open(random_devices[i], O_RDONLY); rnd_dev = random_devices[i]; if (random_fd == -1) { openswan_log("WARNING: open of %s failed: %s", random_devices[i] , strerror(errno)); } } if(random_fd == -1 || i == max_rnd_devices) { openswan_log("Failed to open any source of random. Unable to start any connections."); return; } openswan_log("using %s as source of random entropy", rnd_dev); fcntl(random_fd, F_SETFD, FD_CLOEXEC); get_rnd_bytes(random_pool, RANDOM_POOL_SIZE); mix_pool(); /* start of rand(3) on the right foot */ { unsigned int seed; get_rnd_bytes((void *)&seed, sizeof(seed)); srand(seed); } }
static void alg_info_ike_add(struct alg_info *alg_info, int ealg_id, int ek_bits, int aalg_id, int ak_bits, int modp_id) { if (modp_id == 0) { /* try each default group */ int i; for (i=0; i != elemsof(default_ike_groups); i++) per_group_alg_info_ike_add(alg_info, ealg_id, ek_bits, aalg_id, ak_bits, default_ike_groups[i]); } else { /* group determined by caller */ per_group_alg_info_ike_add(alg_info, ealg_id, ek_bits, aalg_id, ak_bits, modp_id); } }
/* * Add IKE alg info _with_ logic (policy): */ static void alg_info_ike_add (struct alg_info *alg_info , int ealg_id, int ek_bits , int aalg_id, int ak_bits , int modp_id, int permitmann UNUSED) { int i=0, n_groups; n_groups=elemsof(default_ike_groups); /* if specified modp_id avoid loop over default_ike_groups */ if (modp_id) { n_groups=0; goto in_loop; } for (;n_groups--;i++) { modp_id=default_ike_groups[i]; in_loop: /* Policy: default to 3DES */ if (ealg_id==0) ealg_id=OAKLEY_3DES_CBC; if (ealg_id>0) { if (aalg_id>0) __alg_info_ike_add((struct alg_info_ike *)alg_info, ealg_id, ek_bits, aalg_id, ak_bits, modp_id); else { /* Policy: default to MD5 and SHA */ __alg_info_ike_add((struct alg_info_ike *)alg_info, ealg_id, ek_bits, \ OAKLEY_MD5, ak_bits, modp_id); __alg_info_ike_add((struct alg_info_ike *)alg_info, ealg_id, ek_bits, \ OAKLEY_SHA, ak_bits, modp_id); } } } }
main(int argc, char *argv[]){ int i; struct db_sa *gsp = NULL; struct db_sa *sa1 = NULL; struct db_sa *sa2 = NULL; progname = argv[0]; leak_detective = 1; tool_init_log(); for (i = 0; i < elemsof(oakley_sadb); i++) { gsp = sa_copy_sa(&oakley_empty, 0); printf("\nmain mode oakley: %u\n", i); //sa_print(&oakley_sadb[i]); sa1 = sa_copy_sa(&oakley_sadb[i], 0); sa2 = sa_merge_proposals(gsp, sa1); printf("sa1:\n"); sa_print(sa1); printf("gsp:\n"); sa_print(gsp); printf("sa2:\n"); sa_print(sa2); free_sa(sa1); free_sa(sa2); free_sa(gsp); report_leaks(); } tool_close_log(); exit(0); }
/* ??? much of this code is the same as raw_alg_info_esp_add (same bugs!) */ static void raw_alg_info_ike_add(struct alg_info_ike *alg_info, int ealg_id, unsigned ek_bits, int aalg_id, unsigned ak_bits, unsigned int modp_id) { struct ike_info *ike_info = alg_info->ike; int cnt = alg_info->ai.alg_info_cnt; int i; /* don't add duplicates */ /* ??? why is 0 wildcard for ek_bits and ak_bits? */ for (i = 0; i < cnt; i++) { if (ike_info[i].ike_ealg == ealg_id && (ek_bits == 0 || ike_info[i].ike_eklen == ek_bits) && ike_info[i].ike_halg == aalg_id && (ak_bits == 0 || ike_info[i].ike_hklen == ak_bits) && ike_info[i].ike_modp == modp_id) { return; } } /* check for overflows */ /* ??? passert seems dangerous */ passert(cnt < (int)elemsof(alg_info->ike)); ike_info[cnt].ike_ealg = ealg_id; ike_info[cnt].ike_eklen = ek_bits; ike_info[cnt].ike_halg = aalg_id; ike_info[cnt].ike_hklen = ak_bits; ike_info[cnt].ike_modp = modp_id; alg_info->ai.alg_info_cnt++; DBG(DBG_CRYPT, DBG_log("raw_alg_info_ike_add() " "ealg_id=%d ek_bits=%d " "aalg_id=%d ak_bits=%d " "modp_id=%d, cnt=%d", ealg_id, ek_bits, aalg_id, ak_bits, modp_id, alg_info->ai.alg_info_cnt)); }
bool step(const float delta_time) { task_.step(delta_time); u_char key_inp = env_.keyinp->get(); if (key_inp != '\0') { static const u_char tbl[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e' }; int i; for (i = 0; i < elemsof(tbl); ++i) { if (tbl[i] == key_inp) break; } if (i < elemsof(tbl)) { env_.earth_texture = i; earth_.texture(env_.earth_texture); } if (key_inp == 'r') { rotate_mix_ = !rotate_mix_; env_.task->sendMsgAll(rotate_mix_ ? MSG_CONTROL_MIX : MSG_CONTROL_XY); } } // 地球のテクスチャを変更する // 問題と回答を表示するテスト if (key_inp == 'q' || key_inp == 'w') { if (key_inp == 'w') { --place_index_; if (place_index_ < 0) place_index_ = place_names_.size() - 1; } DOUT << *place_names_[place_index_] << ":" << place_index_ << "(" << place_names_.size() << ")" << std::endl; picojson::object place = places_[*place_names_[place_index_]].get<picojson::object>(); env_.cur_place = place["name"].get<std::string>(); env_.answer = place["answer"].is<std::string>(); if (env_.answer) env_.ans_place = place["answer"].get<std::string>(); env_.onetime = place["onetime"].is<bool>() ? place["onetime"].get<bool>() : false; if (key_inp == 'q') { place_index_ = (place_index_ + 1) % place_names_.size(); } { std::string& f = place["file"].get<std::string>(); std::string path = *(env_.path) + "devdata/place/" + f; place_ = std::tr1::shared_ptr<Place>(new Place(path)); std::vector<Vec2<float> > center; place_->center(center); // 各範囲の中心を求める env_.place_center.clear(); for(std::vector<Vec2<float> >::iterator it = center.begin(); it != center.end(); ++it) { Vec3<float> pos = locToPos(*it); env_.place_center.push_back(pos); } this->ansDisp(); } // 問題の正解位置を表示 env_.task->sendMsgAll(MSG_GAME_PLACEDISP_START); if (env_.answer) env_.task->sendMsgAll(MSG_GAME_PLACEDISP_ANS); env_.task->sendMsgAll(MSG_GAME_TOUCH_DISP); } else if (key_inp == 'E') { localize_.reload("en.lang"); DOUT << "Localize:en.lang" << std::endl; // 強制的に英語モード } else if (key_inp == 'J') { localize_.reload("jp.lang"); DOUT << "Localize:jp.lang" << std::endl; // 強制的に日本語モード } else if (key_inp == 'Z') { earth_.airDraw(); } else if (key_inp == 'X') { earth_.bodyDraw(); } else if (key_inp == 'C') { earth_.cloudshadowDraw(); } else if (key_inp == 'V') { earth_.cloudbodyDraw(); } else if (key_inp == 'B') { earth_.atmosbodyDraw(); } return true; }
{ OAKLEY_GROUP_MODP4096, &groupgenerator, &modp4096_modulus, BYTES_FOR_BITS(4096) }, { OAKLEY_GROUP_MODP6144, &groupgenerator, &modp6144_modulus, BYTES_FOR_BITS(6144) }, { OAKLEY_GROUP_MODP8192, &groupgenerator, &modp8192_modulus, BYTES_FOR_BITS(8192) }, { OAKLEY_GROUP_DH22, &generator_dh22, &dh22_modulus, BYTES_FOR_BITS( 1024) }, { OAKLEY_GROUP_DH23, &generator_dh23, &dh23_modulus, BYTES_FOR_BITS( 2048) }, { OAKLEY_GROUP_DH24, &generator_dh24, &dh24_modulus, BYTES_FOR_BITS( 2048) }, }; const unsigned int oakley_group_size = elemsof(oakley_group); const struct oakley_group_desc *lookup_group(u_int16_t group) { int i; for (i = 0; i != elemsof(oakley_group); i++) if (group == oakley_group[i].group) return &oakley_group[i]; return NULL; } /* Encryption Routines * * Each uses and updates the state object's st_new_iv.
static void optimizeBase(vec<Int>& seq, int carry_ins, vec<Int>& rhs, int cost, vec<int>& base, int& cost_bestfound, vec<int>& base_bestfound) { if (cost >= cost_bestfound) return; // "Base case" -- don't split further, build sorting network for current sequence: int final_cost = 0; for (int i = 0; i < seq.size(); i++){ if (seq[i] > INT_MAX) goto TooBig; #ifdef ExpensiveBigConstants final_cost += toint(seq[i]); #else int c; for (c = 1; c*c < seq[i]; c++); final_cost += c; #endif if (final_cost < 0) goto TooBig; } if (cost + final_cost < cost_bestfound){ base.copyTo(base_bestfound); cost_bestfound = cost + final_cost; } TooBig:; /**/static int depth = 0; // <<== could count 1:s here for efficiency vec<Int> new_seq; vec<Int> new_rhs; #ifdef PickSmallest int p = -1; for (int i = 0; i < seq.size(); i++) if (seq[i] > 1){ p = seq[i]; break; } if (p != -1){ #else //int upper_lim = (seq.size() == 0) ? 1 : seq.last(); // <<== Check that sqRoot is an 'int' (no truncation of 'Int') //for (int i = 0; i < (int)elemsof(primes) && primes[i] <= upper_lim; i++){ for (int i = 0; i < (int)elemsof(primes); i++){ int p = primes[i]; #endif int rest = carry_ins; // Sum of all the remainders. Int div, rem; /**/for (int n = depth; n != 0; n--) pf(" "); pf("prime=%d carry_ins=%d\n", p, carry_ins); /**/for (int n = depth; n != 0; n--) pf(" "); pf("New seq:"); for (int j = 0; j < seq.size(); j++){ rest += toint(seq[j] % Int(p)); div = seq[j] / Int(p); if (div > 0) //**/pf(" %d", div), new_seq.push(div); } /**/pf("\n"); /**/for (int n = depth; n != 0; n--) pf(" "); pf("rest=%d\n", rest); /**/for (int n = depth; n != 0; n--) pf(" "); pf("New rhs:"); #ifdef AllDigitsImportant bool digit_important = true; #else bool digit_important = false; #endif for (int j = 0; j < rhs.size(); j++){ div = rhs[j] / p; if (new_rhs.size() == 0 || div > new_rhs.last()){ rem = rhs[j] % p; /**/pf(" %d:%d", div, rem), new_rhs.push(div); if (!(rem == 0 && rest < p) && !(rem > rest)) digit_important = true; } /* <<== om 'rhs' slutar på 0:a och 'rest' inte kan overflowa, då behövs inte det sorterande nätverket för 'rest' ("always TRUE") samma sak om 'rhs' sista siffra är strikt större än 'rest' ("never TRUE") */ } /**/pf("\n\n"); base.push(p); /**/depth++; optimizeBase(new_seq, rest/p, new_rhs, cost+(digit_important ? rest : 0), base, cost_bestfound, base_bestfound); /**/depth--; base.pop(); new_seq.clear(); new_rhs.clear(); } } static void optimizeBase(vec<Int>& seq, vec<Int>& rhs, int& cost_bestfound, vec<int>& base_bestfound) { vec<int> base; cost_bestfound = INT_MAX; base_bestfound.clear(); optimizeBase(seq, 0, rhs, 0, base, cost_bestfound, base_bestfound); }
&oakley_auth_names, /* OAKLEY_AUTHENTICATION_METHOD */ &oakley_group_names, /* OAKLEY_GROUP_DESCRIPTION */ &oakley_group_type_names, /* OAKLEY_GROUP_TYPE */ NULL, /* OAKLEY_GROUP_PRIME */ NULL, /* OAKLEY_GROUP_GENERATOR_ONE */ NULL, /* OAKLEY_GROUP_GENERATOR_TWO */ NULL, /* OAKLEY_GROUP_CURVE_A */ NULL, /* OAKLEY_GROUP_CURVE_B */ &oakley_lifetime_names, /* OAKLEY_LIFE_TYPE */ NULL, /* OAKLEY_LIFE_DURATION */ &oakley_prf_names, /* OAKLEY_PRF */ NULL, /* OAKLEY_KEY_LENGTH */ NULL, /* OAKLEY_FIELD_SIZE */ NULL, /* OAKLEY_GROUP_ORDER */ }; const unsigned int oakley_attr_val_descs_size = elemsof(oakley_attr_val_descs); /* IPsec DOI attributes (RFC 2407 "IPsec DOI" section 4.5) */ static const char *const ipsec_attr_name[] = { "SA_LIFE_TYPE", "SA_LIFE_DURATION", "GROUP_DESCRIPTION", "ENCAPSULATION_MODE", "AUTH_ALGORITHM", "KEY_LENGTH", "KEY_ROUNDS", "COMPRESS_DICT_SIZE", "COMPRESS_PRIVATE_ALG", #ifdef HAVE_LABELED_IPSEC "ECN_TUNNEL",