4 #include "knuth-lfib.h"
9 struct rsa_public_key pub
;
10 struct rsa_private_key key
;
11 struct knuth_lfib_ctx lfib
;
13 /* FIXME: How is this spelled? */
14 const uint8_t *msg
= "Squemish ossifrage";
18 unsigned decrypted_length
;
23 rsa_private_key_init(&key
);
24 rsa_public_key_init(&pub
);
27 knuth_lfib_init(&lfib
, 17);
29 test_rsa_set_key_1(&pub
, &key
);
30 msg_length
= strlen(msg
);
33 fprintf(stderr
, "msg: `%s', length = %d\n", msg
, msg_length
);
35 ASSERT(rsa_encrypt(&pub
,
36 &lfib
, (nettle_random_func
*) knuth_lfib_random
,
42 /* In which GMP version was gmp_fprintf introduced? */
43 fprintf(stderr
, "encrypted: ");
44 mpz_out_str(stderr
, 10, gibberish
);
47 decrypted
= xalloc(msg_length
+ 1);
49 knuth_lfib_random (&lfib
, msg_length
+ 1, decrypted
);
50 after
= decrypted
[msg_length
];
52 decrypted_length
= msg_length
- 1;
53 ASSERT(!rsa_decrypt(&key
, &decrypted_length
, decrypted
, gibberish
));
55 decrypted_length
= msg_length
;
56 ASSERT(rsa_decrypt(&key
, &decrypted_length
, decrypted
, gibberish
));
57 ASSERT(decrypted_length
== msg_length
);
58 ASSERT(MEMEQ(msg_length
, msg
, decrypted
));
59 ASSERT(decrypted
[msg_length
] == after
);
61 knuth_lfib_random (&lfib
, msg_length
+ 1, decrypted
);
62 after
= decrypted
[msg_length
];
64 decrypted_length
= key
.size
;
65 ASSERT(rsa_decrypt(&key
, &decrypted_length
, decrypted
, gibberish
));
66 ASSERT(decrypted_length
== msg_length
);
67 ASSERT(MEMEQ(msg_length
, msg
, decrypted
));
68 ASSERT(decrypted
[msg_length
] == after
);
70 knuth_lfib_random (&lfib
, msg_length
+ 1, decrypted
);
71 after
= decrypted
[msg_length
];
73 decrypted_length
= msg_length
;
74 ASSERT(rsa_decrypt_tr(&pub
, &key
,
75 &lfib
, (nettle_random_func
*) knuth_lfib_random
,
76 &decrypted_length
, decrypted
, gibberish
));
77 ASSERT(decrypted_length
== msg_length
);
78 ASSERT(MEMEQ(msg_length
, msg
, decrypted
));
79 ASSERT(decrypted
[msg_length
] == after
);
81 rsa_private_key_clear(&key
);
82 rsa_public_key_clear(&pub
);