14 test_bignum(const char *hex
, const struct tstring
*base256
)
20 mpz_init_set_str(a
, hex
, 16);
21 nettle_mpz_init_set_str_256_s(b
, base256
->length
, base256
->data
);
23 ASSERT(mpz_cmp(a
, b
) == 0);
25 buf
= xalloc(base256
->length
+ 1);
26 memset(buf
, 17, base256
->length
+ 1);
28 nettle_mpz_get_str_256(base256
->length
, buf
, a
);
29 ASSERT(MEMEQ(base256
->length
, buf
, base256
->data
));
31 ASSERT(buf
[base256
->length
] == 17);
33 mpz_clear(a
); mpz_clear(b
);
38 test_size(long x
, unsigned size
)
42 mpz_init_set_si(t
, x
);
43 ASSERT(nettle_mpz_sizeinbase_256_s(t
) == size
);
46 #endif /* HAVE_LIBGMP */
66 test_size(- 1, 1); /* ff */
67 test_size(- 0x7f, 1); /* 81 */
68 test_size(- 0x80, 1); /* 80 */
69 test_size(- 0x81, 2); /* ff7f */
70 test_size(- 0xff, 2); /* ff01 */
71 test_size(- 0x100, 2); /* ff00 */
72 test_size(- 0x101, 2); /* feff */
73 test_size(- 0x1111, 2); /* eeef */
74 test_size(- 0x7fff, 2); /* 8001 */
75 test_size(- 0x8000, 2); /* 8000 */
76 test_size(- 0x8001, 3); /* ff7fff */
78 test_bignum("0", SHEX("00"));
79 test_bignum("010203040506", SHEX("010203040506"));
80 test_bignum("80010203040506", SHEX("0080010203040506"));
82 test_bignum( "-1", SHEX( "ff"));
83 test_bignum( "-7f", SHEX( "81"));
84 test_bignum( "-80", SHEX( "80"));
85 test_bignum( "-81", SHEX( "ff7f"));
86 test_bignum("-7fff", SHEX( "8001"));
87 test_bignum("-8000", SHEX( "8000"));
88 test_bignum("-8001", SHEX("ff7fff"));
90 #else /* !HAVE_LIBGMP */
92 #endif /* !HAVE_LIBGMP */