diff options
| author | J08nY | 2017-09-07 16:22:22 +0200 |
|---|---|---|
| committer | J08nY | 2017-09-07 16:22:22 +0200 |
| commit | 49a9aee1b0b997f874f0fea2d45d4f6fdf1af325 (patch) | |
| tree | 30eed1d630fe3bbe27670d4403d8efbf8d3585c1 /src | |
| parent | 964395cd920883645a3f065a0fcf6785b9a85acc (diff) | |
| download | ecgen-49a9aee1b0b997f874f0fea2d45d4f6fdf1af325.tar.gz ecgen-49a9aee1b0b997f874f0fea2d45d4f6fdf1af325.tar.zst ecgen-49a9aee1b0b997f874f0fea2d45d4f6fdf1af325.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/gen/seed.c | 10 | ||||
| -rw-r--r-- | src/gen/types.h | 6 | ||||
| -rw-r--r-- | src/io/cli.c | 2 | ||||
| -rw-r--r-- | src/util/bits.c | 2 | ||||
| -rw-r--r-- | src/util/bits.h | 5 |
5 files changed, 23 insertions, 2 deletions
diff --git a/src/gen/seed.c b/src/gen/seed.c index 71b6658..628dad5 100644 --- a/src/gen/seed.c +++ b/src/gen/seed.c @@ -123,9 +123,15 @@ static void seed_hash(seed_t *seed) { } static void seed_W(seed_t *seed, const config_t *cfg) { - GEN t = utoi(cfg->bits - 1); + GEN t = utoi(cfg->bits); GEN s = floorr(rdivii(subis(t, 1), stoi(160), DEFAULTPREC)); - GEN h = subis(t, 160); + GEN h = subii(t, mulis(s, 160)); + GEN hash = binascii_btoi(seed->hash20, 20, ENDIAN_BIG); + GEN mask = subis(int2n(itos(h)), 1); + // TODO: what if I get zeros at the beginning? 0123 == 123 for PARI t_INT + // I should just convert to a t_VECSMALL of bits from the seed->hash and do everything with that. + // That's alot of custom code to handle bit strings. + GEN c0 = ibitand(hash, mask); } GENERATOR(seed_gen_random) { diff --git a/src/gen/types.h b/src/gen/types.h index a20680f..b6d488e 100644 --- a/src/gen/types.h +++ b/src/gen/types.h @@ -95,6 +95,12 @@ typedef enum { ENDIAN_BIG = 0, ENDIAN_LITTLE } endian_e; +typedef struct { + unsigned char *bits; + size_t bitlen; + size_t allocated; +} bits_t; + /** * @brief A generator function type. * @param curve A curve_t being generated diff --git a/src/io/cli.c b/src/io/cli.c index 4a75646..c37652c 100644 --- a/src/io/cli.c +++ b/src/io/cli.c @@ -201,6 +201,8 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) { cfg->from_seed = true; if (arg) { // ANSI X9.62 specifies seed as at least 160 bits in length. + // TODO: validate that it is a hex string, or what actually? It + // can be any PARI int. so 123465689 or 0xab45 or 0b1101100100 if (strlen(arg) < 40) { argp_failure( state, 1, 0, diff --git a/src/util/bits.c b/src/util/bits.c new file mode 100644 index 0000000..2e2faa2 --- /dev/null +++ b/src/util/bits.c @@ -0,0 +1,2 @@ + +#include "bits.h" diff --git a/src/util/bits.h b/src/util/bits.h new file mode 100644 index 0000000..08c06d1 --- /dev/null +++ b/src/util/bits.h @@ -0,0 +1,5 @@ + +#ifndef ECGEN_BITS_H +#define ECGEN_BITS_H + +#endif //ECGEN_BITS_H |
