Imported Upstream version 2.7.1
[platform/upstream/nettle.git] / testsuite / rsa-keygen-test.c
1 #include "testutils.h"
2
3 #include "knuth-lfib.h"
4
5 static void
6 progress(void *ctx UNUSED, int c)
7 {
8   fputc(c, stderr);
9 }
10
11 void
12 test_main(void)
13 {
14   struct rsa_public_key pub;
15   struct rsa_private_key key;
16   
17   struct knuth_lfib_ctx lfib;
18
19   mpz_t expected;
20   
21   mpz_init(expected);
22   
23   rsa_private_key_init(&key);
24   rsa_public_key_init(&pub);
25
26   /* Generate a 1024 bit key with random e */
27   knuth_lfib_init(&lfib, 13);
28
29   ASSERT (rsa_generate_keypair(&pub, &key,
30                                &lfib,
31                                (nettle_random_func *) knuth_lfib_random,
32                                NULL, verbose ? progress : NULL,
33                                1024, 50));
34
35   test_rsa_key(&pub, &key);
36
37   mpz_set_str(expected,
38               "31ee088024b66f28" "e182fa07e60f7864" "636eea21cf74c804"
39               "02a9c29ebd00933d" "8fae3ddf029d18e0" "1b5498c70a4b68fd"
40               "d3135748424e8caf" "43ee86068f250c92" "8da001d09f68c433"
41               "96f2c2a42eaed7e5" "8934a052faa38b2c" "f2ac04cc91bd0d15"
42               "4f60b16dc9045b08" "2ea1372717fd7f9c" "1e9cc383b7d5b909"
43               "72e3126df060ef79" , 16);
44
45   test_rsa_md5(&pub, &key, expected);
46
47   /* Generate a 2000 bit key with fixed e */
48   knuth_lfib_init(&lfib, 17);
49
50   mpz_set_ui(pub.e, 17);
51   ASSERT (rsa_generate_keypair(&pub, &key,
52                                &lfib,
53                                (nettle_random_func *) knuth_lfib_random,
54                                NULL, verbose ? progress : NULL,
55                                2000, 0));
56
57   test_rsa_key(&pub, &key);
58
59   mpz_set_str(expected,
60               "892ef7cda3b0b501" "85de20b93340316e" "b35ac9c193f1f5a3"
61               "9e6c1c327b9c36b8" "d4f1d41653b48fbd" "0c49e48bbdc46ced"
62               "13b3f6426e8a1780" "55b9077ba59ce748" "a325563c3b4bdf78"
63               "acdcdd556f5de3cf" "70257c3b334ba360" "5625ebda869c8058"
64               "b95b40c1e75eb91b" "776e83c0224757c6" "b61266cb1739df1a"
65               "c7fcc09194c575b5" "af4f3eb8e3aa3900" "22b72fb6e950c355"
66               "88743bab32c3a214" "ea5865e2f5c41d67" "12e745496890fc9d"
67               "7944a759f39d7b57" "e365d8d3f6ac2dd4" "052b6a2e58a6af82"
68               "b0d67e7fe09045d9" "bc965e260cf3c9a9" "3bfaa09bdd076dc2"
69               "c0ab48ce5b67105c" "cad90dcfc11cd713" "e64478d2d7ea42dd"
70               "fd040793c487588d" "6218" , 16);
71
72   test_rsa_sha1(&pub, &key, expected);
73   
74   rsa_private_key_clear(&key);
75   rsa_public_key_clear(&pub);
76   mpz_clear(expected);
77 }