aboutsummaryrefslogtreecommitdiff
path: root/src/gen/seed.c
diff options
context:
space:
mode:
authorJ08nY2017-09-17 00:15:24 +0200
committerJ08nY2017-09-17 00:15:24 +0200
commit77f800411c3f3968a802479ecfcf3f5c36e1727e (patch)
tree1e34debf7d5f2946b9e1371934f4e5035f0e1170 /src/gen/seed.c
parentaf443cbd827a1809f29b14065618307cb26435ff (diff)
downloadecgen-77f800411c3f3968a802479ecfcf3f5c36e1727e.tar.gz
ecgen-77f800411c3f3968a802479ecfcf3f5c36e1727e.tar.zst
ecgen-77f800411c3f3968a802479ecfcf3f5c36e1727e.zip
Diffstat (limited to 'src/gen/seed.c')
-rw-r--r--src/gen/seed.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/gen/seed.c b/src/gen/seed.c
index 1da7f2a..9d0359f 100644
--- a/src/gen/seed.c
+++ b/src/gen/seed.c
@@ -82,9 +82,39 @@ static void seed_hash(seed_t *seed) {
}
static void seed_W(seed_t *seed, const config_t *cfg) {
+ pari_sp ltop = avma;
GEN t = utoi(cfg->bits);
GEN s = floorr(rdivii(subis(t, 1), stoi(160), DEFAULTPREC));
GEN h = subii(t, mulis(s, 160));
+
+ bits_t *c0 = bits_from_raw(seed->hash20, 160);
+ bits_shortenz(c0, 160 - itos(h));
+
+ bits_t *W0 = bits_copy(c0);
+ SET_BIT(W0->bits, 0, 0);
+
+ long is = itos(s);
+ seed->W = bits_copy(W0);
+ GEN two_g = int2n(seed->seed->bitlen);
+ for (long i = 1; i <= is; ++i) {
+ pari_sp btop = avma;
+ GEN inner = bits_to_i(seed->seed);
+ inner = addis(inner, i);
+ inner = modii(inner, two_g);
+
+ bits_t *to_hash = bits_from_i(inner);
+ unsigned char hashout[20];
+ bits_sha1(to_hash, hashout);
+ bits_t *Wi = bits_from_raw(hashout, 160);
+ bits_concatz(seed->W, Wi, NULL);
+ bits_free(&to_hash);
+ bits_free(&Wi);
+ avma = btop;
+ }
+
+ bits_free(&c0);
+ bits_free(&W0);
+ avma = ltop;
}
GENERATOR(seed_gen_random) {