rsa2sexp-test.c 2.9 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
4
5
6
7
8
9
10
11
12
#include "testutils.h"

#include "buffer.h"

int
test_main(void)
{
  struct rsa_public_key pub;
  struct rsa_private_key priv;

  struct nettle_buffer buffer;
  
13
14
  rsa_public_key_init(&pub);
  rsa_private_key_init(&priv);
Niels Möller's avatar
Niels Möller committed
15
16
17
18
19
20
21

  mpz_set_str(pub.n,
	      "085c3408989acae4faec3cbbad91c90d34c1d259cd74121a"
	      "36f38b0b51424a9b2be514a04377113a6cdafe79dd7d5f2e"
	      "cc8b5e9661189b86a7b22239907c25", 16);
  mpz_set_str(pub.e, "36ad4b1d", 16);

22
23
  ASSERT(rsa_public_key_prepare(&pub));
  
Niels Möller's avatar
Niels Möller committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  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);

49
50
  ASSERT(rsa_private_key_prepare(&priv));
  
Niels Möller's avatar
Niels Möller committed
51
  nettle_buffer_init(&buffer);
52
  ASSERT(rsa_keypair_to_sexp(&buffer, "rsa", &pub, &priv));
53
54
55
56
57
58
59

  if (verbose)
    {
      printf("private:");
      print_hex(buffer.size, buffer.contents);  
    }
  
Niels Möller's avatar
Niels Möller committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  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"
82
83
84
		"3a6333323a00f8a458ea73a018dc6fa5"
		"6863e3bc6de405f364f77dee6f096267"
		"9ea1a8282e292929"));
Niels Möller's avatar
Niels Möller committed
85
86

  nettle_buffer_clear(&buffer);
87
  ASSERT(rsa_keypair_to_sexp(&buffer, NULL, &pub, NULL));
88
89
90
91
92
93

  if (verbose)
    {
      printf("public:");
      print_hex(buffer.size, buffer.contents);  
    }
Niels Möller's avatar
Niels Möller committed
94
95
96
97
98
99
100
101
  ASSERT(MEMEQH(buffer.size, buffer.contents,
		"2831303a7075626c69632d6b65792833"
		"3a72736128313a6e36333a085c340898"
		"9acae4faec3cbbad91c90d34c1d259cd"
		"74121a36f38b0b51424a9b2be514a043"
		"77113a6cdafe79dd7d5f2ecc8b5e9661"
		"189b86a7b22239907c252928313a6534"
		"3a36ad4b1d292929"));
102
103
104

  rsa_public_key_clear(&pub);
  rsa_private_key_clear(&priv);
Niels Möller's avatar
Niels Möller committed
105
106
107
  
  SUCCESS();
}