summaryrefslogtreecommitdiffstats
path: root/tests/rsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/rsa.c')
-rw-r--r--tests/rsa.c77
1 files changed, 57 insertions, 20 deletions
diff --git a/tests/rsa.c b/tests/rsa.c
index 4e16769..85e1fe6 100644
--- a/tests/rsa.c
+++ b/tests/rsa.c
@@ -26,6 +26,7 @@ POSSIBILITY OF SUCH DAMAGE.
Red Hat author: Miloslav Trmač <mitr@redhat.com> */
#include <assert.h>
+#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -47,25 +48,43 @@ static const uint8_t input[] = "\x00\x01\x02\x03\x04\x05";
int
main (void)
{
+ /* This works in C because "INT" is expanded only at the point where the other
+ macros are used. */
+#define PUBLIC_INTS_COMMAS INT (modulus), INT (public_exponent)
+#define PUBLIC_INTS \
+ INT (modulus); \
+ INT (public_exponent);
+#define ALL_INTS_COMMAS \
+ INT (modulus), INT (public_exponent), INT (private_exponent), INT (prime_1), \
+ INT (prime_2), INT (exponent_1), INT (exponent_2), INT (coefficient)
+#define ALL_INTS \
+ INT (modulus); \
+ INT (public_exponent); \
+ INT (private_exponent); \
+ INT (prime_1); \
+ INT (prime_2); \
+ INT (exponent_1); \
+ INT (exponent_2); \
+ INT (coefficient);
+
struct ncr_public_key *public;
struct ncr_private_key *private;
- uint8_t dest[4096], dest2[4096];
- size_t src_size, dest_size, dest2_size;
+ uint8_t dest[4096];
+ size_t src_size, dest_size;
+#define INT(X) uint8_t export_##X[256]; size_t export_##X##_size
+ ALL_INTS;
+#undef INT
CK_RV res;
/* Test key loading. Should we test the generic version as well? */
- res = ncr_public_key_create_rsa (&public, modulus, sizeof (modulus),
- public_exponent, sizeof (public_exponent));
+#define INT(X) X, sizeof (X)
+ res = ncr_public_key_create_rsa (&public,
+ PUBLIC_INTS_COMMAS);
assert (res == CKR_OK);
- res = ncr_private_key_create_rsa (&private, modulus, sizeof (modulus),
- public_exponent, sizeof (public_exponent),
- private_exponent, sizeof (private_exponent),
- prime_1, sizeof (prime_1), prime_2,
- sizeof (prime_2), exponent_1,
- sizeof (exponent_1), exponent_2,
- sizeof (exponent_2), coefficient,
- sizeof (coefficient));
+ res = ncr_private_key_create_rsa (&private, false,
+ ALL_INTS_COMMAS);
assert (res == CKR_OK);
+#undef INT
/* Test encryption */
@@ -95,15 +114,33 @@ main (void)
sizeof (input));
assert (res != CKR_OK);
- dest_size = sizeof (dest);
- dest2_size = sizeof (dest2);
- res = ncr_public_key_export_rsa (public, dest, &dest_size, dest2,
- &dest2_size);
+#define INT(X) export_##X##_size = sizeof (export_##X);
+ PUBLIC_INTS;
+#undef INT
+#define INT(X) export_##X, &export_##X##_size
+ res = ncr_public_key_export_rsa (public, PUBLIC_INTS_COMMAS);
+#undef INT
+ assert (res == CKR_OK);
+#define INT(X) assert (export_##X##_size == sizeof (X))
+ PUBLIC_INTS;
+#undef INT
+#define INT(X) assert (memcmp (export_##X, (X), export_##X##_size) == 0);
+ PUBLIC_INTS;
+#undef INT
+
+#define INT(X) export_##X##_size = sizeof (export_##X);
+ ALL_INTS;
+#undef INT
+#define INT(X) export_##X, &export_##X##_size
+ res = ncr_private_key_export_rsa (private, ALL_INTS_COMMAS);
+#undef INT
assert (res == CKR_OK);
- assert (dest_size == sizeof (modulus));
- assert (dest2_size == sizeof (public_exponent));
- assert (memcmp (dest, modulus, dest_size) == 0);
- assert (memcmp (dest2, public_exponent, dest2_size) == 0);
+#define INT(X) assert (export_##X##_size == sizeof (X))
+ ALL_INTS;
+#undef INT
+#define INT(X) assert (memcmp (export_##X, (X), export_##X##_size) == 0);
+ ALL_INTS;
+#undef INT
res = ncr_private_key_destroy (private);
assert (res == CKR_OK);