rstatus_t server_pool_run(struct server_pool *pool) { ASSERT(array_n(&pool->server) != 0); switch (pool->dist_type) { case DIST_KETAMA: return ketama_update(pool); case DIST_VNODE: //return vnode_update(pool); break; case DIST_MODULA: return modula_update(pool); case DIST_RANDOM: return random_update(pool); case DIST_SINGLE: return DN_OK; default: NOT_REACHED(); return DN_ERROR; } return DN_OK; }
int main (int argc, char **argv) { setprogname (argv[0]); random_update (); vtime = signtime = 0; int sz = 2048; bool opt_v = false; if (argc > 1 && !strcmp (argv[1], "-v")) opt_v = true; if (argc > 2 && !(sz = atoi (argv[2]))) fatal << "bad argument\n"; for (int i = 0; i < 10; i++) { esign_priv sk = esign_keygen (opt_v ? sz : 424 + rnd.getword () % 256); test_key_sign (sk); } if (opt_v) { warn ("Signed 500 messages with %d bit key in %" U64F "u " TIME_LABEL " per signature\n", sz, signtime / 500); warn ("Verified 500 messages with %d bit key in %" U64F "u " TIME_LABEL " per verify\n", sz, vtime / 500); } return 0; }
int main (int argc, char **argv) { random_update (); bigint m, r, s1, s2; barrett b; for (int i = 120; i < 162; i++) { m = random_bigint (i); m.setbit (0, 1); b.set (m); for (int j = i - 33; j <= 2 * i; j++) { r = random_bigint (j); s1 = mod (r, m); s2 = b.reduce (r); if (s1 != s2) panic << "r = " << r << "\n" << " " << s1 << "\n != " << s2 << "\n" << " [" << strbuf ("%*s", mpz_sizeinbase (&s1, 16), bigint (abs (s1 - s2)).cstr ()) << "]\n"; } } return 0; }
int main (int argc, char **argv) { tst_vtime = tst_stime = 0; bool opt_v = false; int vsz = 1024; ptr<dsa_gen> dg; if (argc > 1 && !strcmp (argv[1], "-v")) { opt_v = true; } setprogname (argv[0]); random_update (); for (int i = 0; i < 1; i++) { dg = dsa_gen::rgen (opt_v ? vsz : 424 + rnd.getword () % 256); test_key_sign (dg->sk); } if (opt_v) { warn ("Signed 50 messages with %d bit key in %" U64F "u " TIME_LABEL " per signature\n", vsz, tst_stime / 50); warn ("Verified 50 messages with %d bit key in %" U64F "u " TIME_LABEL " per verify\n", vsz, tst_vtime / 50); } return 0; }
int main (int argc, char **argv) { int sg, rg; rs = rv = se = sc = sv = n = sg = rg = eg = 0; ptr<schnorr_gen> sgt; setprogname (argv[0]); random_update (); int m = 10; for (int i = 0; i < m; i++) { startt (); sgt = schnorr_gen::rgen (1024); sg += stopt (); startt (); rabin_priv sk = rabin_keygen (1024); rg += stopt (); test_key_encrypt (sk, sgt->csk, sgt->ssk); } /* warnx << "n: " << n << "\n" << "Rabin sign: " << rs / n << "\n" << "Rabin verify: " << rv / n << "\n" << "Schnorr Endorse: " << se / n << "\n" << "Schnorr Complete: " << sc / n << "\n" << "Schnorr Verify: " << sv / n << "\n" << "Rabin generate: " << rg / m << "\n" << "Schnorr generate: " << sg / m << "\n" << "Schnorr Ephem Gn: " << eg / n << "\n"; */ return 0; }
int main (int argc, char **argv) { setprogname (argv[0]); random_update (); esign_priv sk = get_private_key(); test_key_sign (sk); }
void random_start () { if (!initialized) { initialized = true; random_update (); arandom_fn = random_word; random_timer (); } }
void random_init () { if (initialized) random_update (); else { random_start (); while (!nupdates) acheck (); } }
int main (int argc, char **argv) { random_update (); bigint r, s1, s2; for (int i = 0; i < 1024; i++) { r = random_bigint (rnd.getword () % 2048); s1 = r * r; mpz_square (&s2, &r); if (s1 != s2) panic << "r = " << r << "\n" << " " << s1 << "\n != " << s2 << "\n" << " [" << strbuf ("%*s", int (mpz_sizeinbase (&s1, 16)), bigint (abs (s1 - s2)).cstr ()) << "]\n"; } return 0; }
int main (int argc, char **argv) { random_update (); #define HMAC(k, m) \ do { \ u_char digest[sha1::hashsize]; \ sha1_hmac (digest, k, sizeof (k) - 1, m, sizeof (m) - 1); \ warn << "k = " << k << "\nm = " << m << "\n" \ << hexdump (digest, sizeof (digest)) << "\n"; \ } while (0) #define HMAC2(k, k2, m) \ do { \ u_char digest[sha1::hashsize]; \ sha1_hmac_2 (digest, k, sizeof (k) - 1, k2, sizeof (k2) - 1, \ m, sizeof (m) - 1); \ warn << "k = " << k << "\nm = " << m << "\n" \ << hexdump (digest, sizeof (digest)) << "\n"; \ } while (0) #if 0 HMAC ("Jefe", "what do ya want for nothing?"); HMAC ("\014\014\014\014\014\014\014\014\014\014\014\014\014\014\014\014\014\014\014\014", "Test With Truncation"); //HMAC2 ("Je", "fe", "what do ya want for nothing?"); #endif bigint p ("c81698301db5fdba3c5fecfdd97ca952c1f0df3500740a567ecdb561555c8a34d0affcc99ae7a38b42d144373ae2f68b48064373b5baef7d25782fd07dc4b35f", 16); bigint q ("d32d977062a62dccfc4a37a21b03fca098973b72860002a3c05084060fbaa81b5c0fc636902a2959fb5ffd3d8a4969fbe9e15037c35477c9789da0b74ef32e3f", 16); bigint n ("a50e41c593b3b866bc4c72d0476611baab9bd54a22c62e11f536f87861ce592e7a101aea8652d3b949e66271b4497f91a861404eb5f3cba23f22b9b46fadda6cd327e3773eb23795e73ee06c16e5df18cf12e812fcd1bdbf3a4d7cca4fecd95fcbf248ac0534a3ebc67ebb06f9ca77d3ce1a5c4920da6d211b5f242e80d03661", 16); rsa_pub rsapub (n); str m ("a random string"); bigint c = rsapub.encrypt (m); rsa_priv rsapriv (p, q); m = rsapriv.decrypt (c, m.len ()); warn << "m " << m << "\n"; rsa_priv x (rsa_keygen (1024)); bigint pt (random_bigint (1019)); bigint ct, pt2; BENCH (100000, ct = x.encrypt (pt)); BENCH (1000, pt = x.decrypt (ct)); #if 0 warn << pt.getstr (10) << "\n"; ct = x.encrypt (pt); warn << ct.getstr (10) << "\n";; pt2 = x.decrypt (ct); warn << pt2.getstr (10) << "\n"; #endif rabin_priv xx (rabin_keygen (1280, 2)); str pt3 ("plaintext message"); BENCH (100000, ct = xx.encrypt (pt3)); BENCH (1000, pt3 = xx.decrypt (ct, sizeof (pt3))); #if 0 BENCH (100, ct = x.sign (pt3)); BENCH (1000, x.verify (pt3, ct)); BENCH (1000, ct = x.encrypt (pt3)); #endif return 0; }
static void saveseed () { if (seed) random_update (); }
int main (int argc, char **argv) { setprogname (argv[0]); random_update (); create_mode = false; add_mode = false; wind_mode = false; unwind_mode = false; error_check = true; window_mode = false; verbose_mode = false; id = 0; keysize = 16; chainlen = 128; window_startvers = 0; protocol = strbuf () << "sha1"; type = SFSRO_SHA1; directory = NULL; outfile = NULL; int ch; while ((ch = getopt (argc, argv, "i:k:p:d:o:l:W:cawumv")) != -1) switch (ch) { case 'i': if (!convertint (optarg, &id)) usage (); break; case 'k': if (!convertint (optarg, &keysize) || keysize < 16 || keysize > 32) usage (); break; case 'p': protocol = optarg; if (protocol == "sha1") type = SFSRO_SHA1; else if(protocol == "rabin") type = SFSRO_RABIN; else usage (); break; case 'd': directory = optarg; break; case 'o': outfile = optarg; break; case 'c': create_mode= true; break; case 'a': add_mode= true; break; case 'w': wind_mode= true; break; case 'u': unwind_mode= true; break; case 'l': if (!convertint (optarg, &chainlen)) usage (); break; case 'W': if (!convertint (optarg, &window_startvers)) usage (); break; case 'm': window_mode = true; break; case 'v': verbose_mode = true; break; default: usage (); } argc -= optind; argv += optind; if ( (argc > 0) || !directory || !id || ((create_mode + add_mode + wind_mode + unwind_mode) != 1) || !(create_mode || !window_mode)) usage (); kro = New refcounted<keyregression_owner> (directory, id, type, keysize, chainlen, create_mode, window_mode, verbose_mode); if (add_mode) { if (!kro->add (outfile, window_startvers, verbose_mode)) { warn << "kro->add failed\n"; exit (1); } } if (wind_mode) { if (!kro->wind (outfile, verbose_mode)) { warn << "kro->wind failed\n"; exit (1); } } /* if (unwind_mode) { if (!kro->unwind (outfile)) { warn << "kro->unwind failed\n"; exit (1); } } */ }
int main (int argc, char **argv) { random_update (); bigint m, m2, r, r2, ri, s1, s2; montgom b; for (int i = 120; i < 162; i++) { int res = 0; m = random_bigint (i); m.setbit (0, 1); b.set (m); m2 = m * b.getr (); for (int j = i - 33; j <= 2 * i; j++) { r = random_zn (m2); r.trunc (j); s1 = mod (r * b.getri (), m); //s2 = b.mreduce (r); b.mpz_mreduce (&s2, &r); if (s1 != s2) { res |= 1; int sz = mpz_sizeinbase (&s1, 16); panic << "mreduce failed\n" << " m = " << m << "\n" << " r = " << r << "\n" << " " << s1 << "\n != " << s2 << "\n" << " [" << strbuf ("%*s", sz, bigint (abs (s1 - s2)).cstr ()) << "]\n"; } } // r = s1; r = random_zn (m); r2 = random_zn (m); assert (r < m && r2 < m); s1 = mod (r * r2 * b.getri (), m); b.mpz_mmul (&s2, &r, &r2); if (s1 != s2) { res |= 2; int sz = mpz_sizeinbase (&s1, 16); panic << "mmul failed\n" << " m = " << m << "\n" << " r = " << r << "\n" << " " << s1 << "\n != " << s2 << "\n" << " [" << strbuf ("%*s", sz, bigint (abs (s1 - s2)).cstr ()) << "]\n"; } s1 = powm (r, r2, m); b.mpz_powm (&s2, &r, &r2); if (s1 != s2) { res |= 4; int sz = mpz_sizeinbase (&s1, 16); panic << "powm failed\n" << " m = " << m << "\n" << " r = " << r << "\n" << " " << s1 << "\n != " << s2 << "\n" << " [" << strbuf ("%*s", sz, bigint (abs (s1 - s2)).cstr ()) << "]\n"; } #if 0 warn ("%s mreduce.. %d\n", (res&1) ? "fail" : "ok", i); warn ("%s mmul.. %d\n", (res&2) ? "fail" : "ok", i); warn ("%s powm.. %d\n", (res&4) ? "fail" : "ok", i); #endif } return 0; }