Commit eef954c6 authored by Niels Möller's avatar Niels Möller

New tests.

Rev: src/nettle/testsuite/rsa2sexp-test.c:1.1
Rev: src/nettle/testsuite/sexp-format-test.c:1.1
Rev: src/nettle/testsuite/sexp2rsa-test.c:1.1
parent 7ed8cf94
#include "testutils.h"
#include "rsa.h"
#include "buffer.h"
int
test_main(void)
{
#if HAVE_LIBGMP
struct rsa_public_key pub;
struct rsa_private_key priv;
struct nettle_buffer buffer;
rsa_init_public_key(&pub);
rsa_init_private_key(&priv);
mpz_set_str(pub.n,
"085c3408989acae4faec3cbbad91c90d34c1d259cd74121a"
"36f38b0b51424a9b2be514a04377113a6cdafe79dd7d5f2e"
"cc8b5e9661189b86a7b22239907c25", 16);
mpz_set_str(pub.e, "36ad4b1d", 16);
mpz_set_str(priv.d,
"06ee6d4ff3c239e408150daf8117abfa36a40ad4455d9059"
"a86d52f33a2de07418a0a699594588c64810248c9412d554"
"f74af947c73c32007e87c92f0937ed", 16);
mpz_set_str(priv.p,
"03259879b24315e9cf14254824c7935d807cdb6990f414a0"
"f65e6065130a611f", 16);
mpz_set_str(priv.q,
"02a81ba73bad45fc73b36deffce52d1b73e0747f4d8a8264"
"8cecd310448ea63b", 16);
mpz_set_str(priv.a,
"026cbdad5dd0046e093f060ecd5b4ac918e098b0278bb752"
"b7cadd6a8944f0b9", 16);
mpz_set_str(priv.b,
"0148751e622d6d58e3bb094afd6edacf7370351d068e2ce9"
"f565c5528c4a7473", 16);
mpz_set_str(priv.c,
"f8a458ea73a018dc6fa56863e3bc6de405f364f77dee6f09"
"62679ea1a8282e", 16);
nettle_buffer_init(&buffer);
ASSERT(rsa_keypair_to_sexp(&buffer, &pub, &priv));
ASSERT(MEMEQH(buffer.size, buffer.contents,
"2831313a707269766174652d6b657928"
"333a72736128313a6e36333a085c3408"
"989acae4faec3cbbad91c90d34c1d259"
"cd74121a36f38b0b51424a9b2be514a0"
"4377113a6cdafe79dd7d5f2ecc8b5e96"
"61189b86a7b22239907c252928313a65"
"343a36ad4b1d2928313a6436333a06ee"
"6d4ff3c239e408150daf8117abfa36a4"
"0ad4455d9059a86d52f33a2de07418a0"
"a699594588c64810248c9412d554f74a"
"f947c73c32007e87c92f0937ed292831"
"3a7033323a03259879b24315e9cf1425"
"4824c7935d807cdb6990f414a0f65e60"
"65130a611f2928313a7133323a02a81b"
"a73bad45fc73b36deffce52d1b73e074"
"7f4d8a82648cecd310448ea63b292831"
"3a6133323a026cbdad5dd0046e093f06"
"0ecd5b4ac918e098b0278bb752b7cadd"
"6a8944f0b92928313a6233323a014875"
"1e622d6d58e3bb094afd6edacf737035"
"1d068e2ce9f565c5528c4a7473292831"
"3a6333313af8a458ea73a018dc6fa568"
"63e3bc6de405f364f77dee6f0962679e"
"a1a8282e292929"));
nettle_buffer_clear(&buffer);
ASSERT(rsa_keypair_to_sexp(&buffer, &pub, NULL));
ASSERT(MEMEQH(buffer.size, buffer.contents,
"2831303a7075626c69632d6b65792833"
"3a72736128313a6e36333a085c340898"
"9acae4faec3cbbad91c90d34c1d259cd"
"74121a36f38b0b51424a9b2be514a043"
"77113a6cdafe79dd7d5f2ecc8b5e9661"
"189b86a7b22239907c252928313a6534"
"3a36ad4b1d292929"));
SUCCESS();
#else /* !HAVE_LIBGMP */
SKIP();
#endif /* !HAVE_LIBGMP */
}
#include "testutils.h"
#include "sexp.h"
#include "buffer.h"
#include "bignum.h"
int
test_main(void)
{
struct nettle_buffer buffer;
const uint8_t e1[] = "(3:foo(3:bar17:xxxxxxxxxxxxxxxxx))";
nettle_buffer_init(&buffer);
ASSERT(sexp_format(&buffer, "(%s(%s%s))",
"foo", "bar", "xxxxxxxxxxxxxxxxx"));
ASSERT(buffer.size == strlen(e1));
ASSERT(MEMEQ(buffer.size, buffer.contents, e1));
nettle_buffer_clear(&buffer);
#if HAVE_LIBGMP
{
mpz_t x;
const uint8_t e2[] = "(3:foo(3:bar11:abcdefghijk))";
nettle_mpz_init_set_str_256(x, 11, "abcdefghijk");
nettle_buffer_init(&buffer);
ASSERT(sexp_format(&buffer, "(%s(%s%b))",
"foo", "bar", x));
ASSERT(buffer.size == strlen(e2));
ASSERT(MEMEQ(buffer.size, buffer.contents, e2));
nettle_buffer_clear(&buffer);
mpz_clear(x);
}
#endif /* HAVE_LIBGMP */
SUCCESS();
}
#include "testutils.h"
#include "rsa.h"
int
test_main(void)
{
#if HAVE_LIBGMP
struct rsa_public_key pub;
struct rsa_private_key priv;
rsa_init_public_key(&pub);
rsa_init_private_key(&priv);
ASSERT(rsa_keypair_from_sexp
(&pub, &priv,
HL("2831313a707269766174652d6b657928"
"333a72736128313a6e36333a085c3408"
"989acae4faec3cbbad91c90d34c1d259"
"cd74121a36f38b0b51424a9b2be514a0"
"4377113a6cdafe79dd7d5f2ecc8b5e96"
"61189b86a7b22239907c252928313a65"
"343a36ad4b1d2928313a6436333a06ee"
"6d4ff3c239e408150daf8117abfa36a4"
"0ad4455d9059a86d52f33a2de07418a0"
"a699594588c64810248c9412d554f74a"
"f947c73c32007e87c92f0937ed292831"
"3a7033323a03259879b24315e9cf1425"
"4824c7935d807cdb6990f414a0f65e60"
"65130a611f2928313a7133323a02a81b"
"a73bad45fc73b36deffce52d1b73e074"
"7f4d8a82648cecd310448ea63b292831"
"3a6133323a026cbdad5dd0046e093f06"
"0ecd5b4ac918e098b0278bb752b7cadd"
"6a8944f0b92928313a6233323a014875"
"1e622d6d58e3bb094afd6edacf737035"
"1d068e2ce9f565c5528c4a7473292831"
"3a6333313af8a458ea73a018dc6fa568"
"63e3bc6de405f364f77dee6f0962679e"
"a1a8282e292929")));
test_rsa_key(&pub, &priv);
SUCCESS();
#else /* !HAVE_LIBGMP */
SKIP();
#endif /* !HAVE_LIBGMP */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment