sign.c revision ba751492fcc4f161a18b983d4f018a1a52938cb9
/*
* Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Portions copyright (c) 2008 Nominet UK. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* $Id$ */
/* signrsa [-m module] [-s $slot] [-p pin] [-t] [-n count] */
/*! \file */
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <isc/commandline.h>
#define getpassphrase(x) getpass(x)
#endif
#ifndef HAVE_CLOCK_GETTIME
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
int
{
int result;
if (result)
return (result);
return (result);
}
#endif
0x00, 0xb7, 0x9c, 0x1f, 0x05, 0xa3, 0xc2, 0x99,
0x44, 0x82, 0x20, 0x78, 0x43, 0x7f, 0x5f, 0x3b,
0x10, 0xd7, 0x9e, 0x61, 0x42, 0xd2, 0x7a, 0x90,
0x50, 0x8a, 0x99, 0x33, 0xe7, 0xca, 0xc8, 0x5f,
0x16, 0x1c, 0x56, 0xf8, 0xc1, 0x06, 0x2f, 0x96,
0xe7, 0x54, 0xf2, 0x85, 0x89, 0x41, 0x36, 0xf5,
0x4c, 0xa4, 0x0d, 0x62, 0xd3, 0x42, 0x51, 0x6b,
0x9f, 0xdc, 0x36, 0xcb, 0xad, 0x56, 0xf4, 0xbd,
0x2a, 0x60, 0x33, 0xb1, 0x7a, 0x99, 0xad, 0x08,
0x9f, 0x95, 0xe8, 0xe5, 0x14, 0xd9, 0x68, 0x79,
0xca, 0x4e, 0x72, 0xeb, 0xfb, 0x2c, 0xf1, 0x45,
0xd3, 0x33, 0x65, 0xe7, 0xc5, 0x11, 0xdd, 0xe7,
0x09, 0x83, 0x13, 0xd5, 0x17, 0x1b, 0xf4, 0xbd,
0x49, 0xdd, 0x8a, 0x3c, 0x3c, 0xf7, 0xa1, 0x5d,
0x7b, 0xb4, 0xd3, 0x80, 0x25, 0xf4, 0x05, 0x8f,
0xbc, 0x2c, 0x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
0xf6, 0x06, 0x45, 0x71, 0x4e, 0xd7, 0x90, 0x2a,
0x16, 0x52, 0x46, 0x75, 0x1a, 0xf5, 0x74, 0x8c,
0x5a, 0xa4, 0xc4, 0x66, 0x27, 0xe0, 0x96, 0x64,
0x7f
};
0x00, 0xd0, 0x1f, 0xb3, 0x47, 0x40, 0x93, 0x8b,
0x99, 0xd7, 0xb5, 0xc6, 0x09, 0x82, 0x65, 0x94,
0x9d, 0x56, 0x0a, 0x05, 0x55, 0x7d, 0x93, 0x04,
0xa4, 0x26, 0xee, 0x42, 0x86, 0xa3, 0xf1, 0xd5,
0x7a, 0x42, 0x84, 0x3c, 0x21, 0x96, 0x9a, 0xd9,
0x36, 0xd4, 0x62, 0x01, 0xb0, 0x8b, 0x77, 0xe5,
0xcc, 0x1b, 0xd2, 0x12, 0xd2, 0x9c, 0x89, 0x67,
0x0c, 0x00, 0x09, 0x56, 0x8c, 0x33, 0x57, 0xf9,
0x8c
};
int
CK_SLOT_ID slot = 0;
{
};
int error = 0;
int c, errflg = 0;
int ontoken = 0;
unsigned int count = 1000;
unsigned int i;
switch (c) {
case 'm':
break;
case 's':
break;
case 'p':
break;
case 't':
ontoken = 1;
break;
case 'n':
break;
case ':':
"Option -%c requires an operand\n",
errflg++;
break;
case '?':
default:
errflg++;
}
}
if (errflg) {
"\tsign [-m module] [-s slot] [-p pin] "
"[-t] [-n count]\n");
exit(1);
}
/* Initialize the CRYPTOKI library */
if (result != ISC_R_SUCCESS) {
exit(1);
}
/* Create the private RSA key */
if (ontoken)
goto exit_key;
}
/* Randomize the buffer */
goto exit_key;
}
perror("clock_gettime(start)");
goto exit_key;
}
for (i = 0; i < count; i++) {
/* Initialize Sign */
"C_SignInit[%u]: Error = 0x%.8lX\n",
i, rv);
error = 1;
break;
}
/* Perform Sign */
"C_Sign[%u]: Error = 0x%.8lX\n",
i, rv);
error = 1;
break;
}
}
perror("clock_gettime(end)");
goto exit_key;
}
}
printf("%u RSA signs in %ld.%09lds\n", i,
if (i > 0)
printf("%g RSA signs/s\n",
if (hKey != CK_INVALID_HANDLE) {
"C_DestroyObject: Error = 0x%.8lX\n",
rv);
}
}