1
0
mirror of https://github.com/opencryptoki/opencryptoki.git synced 2026-10-24 05:39:17 +03:00
Files
opencryptoki/testcases/driver/driver.c
phreakz d0de9a0d29 Testcases improvements:
- Now testcases inside testcases/driver can be run separatedly
- ock-tests.sh now calls individual tests instead of testcases/driver/driver binary
- since all usage() were the same inside testcases/driver, this is now located at testcases/common.c. To avoid namespace conflict, the other usage() ones were renamed to <testcase_binary_name>_usage()
- skip_token_obj, no_stop and no_init are now declared in testcases/include/regress,h
2008-11-11 13:17:22 +00:00

218 lines
5.6 KiB
C
Executable File

// File: driver.c
//
//
// Test driver. In-depth regression test for PKCS #11
//
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <dlfcn.h>
#include <sys/timeb.h>
#include "pkcs11types.h"
#include "regress.h"
// these values are required when generating a PKCS DSA value. they were
// obtained by generating a DSA key pair on the 4758 with the default (random)
// values. these values are in big-endian format
//
CK_BYTE DSA_PUBL_PRIME[128] =
{
0xba, 0xa2, 0x5b, 0xd9, 0x77, 0xb3, 0xf0, 0x2d, 0xa1, 0x65, 0xf1, 0x83, 0xa7, 0xc9, 0xf0,
0x8a, 0x51, 0x3f, 0x74, 0xe8, 0xeb, 0x1f, 0xd7, 0x0a, 0xd5, 0x41, 0xfa, 0x52, 0x3c, 0x1f,
0x79, 0x15, 0x55, 0x18, 0x45, 0x41, 0x29, 0x27, 0x12, 0x4a, 0xb4, 0x32, 0xa6, 0xd2, 0xec,
0xe2, 0x82, 0x73, 0xf4, 0x30, 0x66, 0x1a, 0x31, 0x06, 0x37, 0xd2, 0xb0, 0xe4, 0x26, 0x39,
0x2a, 0x0e, 0x48, 0xf6, 0x77, 0x94, 0x47, 0xea, 0x7d, 0x99, 0x22, 0xce, 0x65, 0x61, 0x82,
0xd5, 0xe3, 0xfc, 0x15, 0x3f, 0xff, 0xff, 0xc8, 0xb9, 0x4f, 0x37, 0xbf, 0x7a, 0xa6, 0x6a,
0xbe, 0xff, 0xa9, 0xdf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, 0x4b,
0xc5, 0x18, 0xe9, 0xbc, 0xff, 0xae, 0x34, 0x7f
};
//
//
int main (int argc, char **argv)
{
CK_C_INITIALIZE_ARGS cinit_args;
int rc, i;
CK_BBOOL no_init;
SLOT_ID = 0;
skip_token_obj = TRUE;
no_init = FALSE;
no_stop = FALSE;
for (i = 1; i < argc; i++) {
if (strcmp (argv[i], "-h") == 0 || strcmp (argv[i], "--help") == 0) {
usage (argv [0]);
return 0;
}
else if (strcmp (argv[i], "-noskip") == 0)
skip_token_obj = FALSE;
else if (strcmp (argv[i], "-slot") == 0) {
SLOT_ID = atoi (argv[i+1]);
i++;
}
else if (strcmp (argv[i], "-noinit") == 0)
no_init = TRUE;
else if (strcmp (argv[i], "-nostop") == 0)
no_stop = TRUE;
else {
printf ("Invalid argument passed as option: %s\n", argv [i]);
usage (argv [0]);
return -1;
}
}
printf("Using slot #%lu...\n\n", SLOT_ID );
printf("With option: no_init: %d, noskip: %d\n", no_init, skip_token_obj);
rc = do_GetFunctionList();
if ( !rc )
return rc;
memset( &cinit_args, 0x0, sizeof(cinit_args) );
cinit_args.flags = CKF_OS_LOCKING_OK;
// SAB Add calls to ALL functions before the C_Initialize gets hit
funcs->C_Initialize( &cinit_args );
{
CK_SESSION_HANDLE hsess = 0;
rc = funcs->C_GetFunctionStatus(hsess);
if (rc != CKR_FUNCTION_NOT_PARALLEL)
return rc;
rc = funcs->C_CancelFunction(hsess);
if (rc != CKR_FUNCTION_NOT_PARALLEL)
return rc;
}
#if 0
fprintf (stderr, "\tMisc functions tests...\n");
rc = misc_functions();
if ( !rc && !no_stop)
return rc;
fprintf (stderr, "\tSession Mgmt functions tests...\n");
rc = sess_mgmt_functions();
if ( !rc && !no_stop)
return rc;
fprintf (stderr, "\tObject Mgmt functions tests...\n");
rc = obj_mgmt_functions();
if ( !rc && !no_stop)
return rc;
fprintf (stderr, "\tDES functions tests...\n");
rc = des_functions();
if ( !rc && !no_stop) {
printf("Error executing DES functions\n");
return rc;
}
fprintf (stderr, "\tDES3 functions tests...\n");
rc = des3_functions();
if ( !rc && !no_stop) {
printf("Error executing DES3 functions\n");
return rc;
}
fprintf (stderr, "\tDSA functions tests...\n");
rc = dsa_functions();
if ( !rc && !no_stop) {
printf("Error executing DSA functions\n");
return rc;
}
fprintf (stderr, "\tDES3 functions tests...\n");
rc = des3_functions();
if ( !rc && !no_stop)
return rc;
fprintf (stderr, "\tAES functions tests...\n");
rc = aes_functions();
if ( !rc && !no_stop) {
printf("Error executing AES functions\n");
return rc;
}
fprintf (stderr, "\tRijndael tests...\n");
rc = rijndael_functions();
if ( !rc && !no_stop) {
printf("Error executing Rijndael functions\n");
return rc;
}
fprintf (stderr, "\tDigest functions tests...\n");
rc = digest_functions();
if ( !rc && !no_stop) {
printf("Error executing Digest functions\n");
return rc;
}
fprintf (stderr, "\tRSA functions tests...\n");
rc = rsa_functions();
if ( !rc && !no_stop) {
printf("Error executing RSA functions\n");
return rc;
}
/* Begin code contributed by Corrent corp. */
fprintf (stderr, "\tDH functions tests...\n");
rc = dh_functions();
if ( !rc && !no_stop) {
printf("Error executing DH functions\n");
return rc;
}
/* End code contributed by Corrent corp. */
fprintf (stderr, "\tSSL3 functions tests...\n");
rc = ssl3_functions();
if ( !rc && !no_stop) {
printf("Error executing SSL3 functions\n");
return rc;
}
#endif
printf("------------------ Completed pass --------------------\n");
funcs->C_Finalize( NULL );
return 0;
}