Fix memory leaks
Indent lines git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@369 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
6e3a09fa7b
commit
50e266567a
|
@ -1,5 +1,5 @@
|
|||
#include <opensc.h>
|
||||
#include <stdio.h>
|
||||
#include <opensc.h>
|
||||
#include <sc-asn1.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
|
@ -2,30 +2,28 @@
|
|||
* All rights reserved.
|
||||
*/
|
||||
|
||||
#include "sc-test.h"
|
||||
#include "opensc.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
#include <opensc.h>
|
||||
#include "sc-test.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, c, r;
|
||||
int freq[39];
|
||||
int i, c, r, freq[39];
|
||||
struct timeval tv1, tv2;
|
||||
u8 buf[14];
|
||||
|
||||
i = sc_test_init(&argc, argv);
|
||||
|
||||
for (i = 0; i < 39; i++)
|
||||
freq[i] = 0;
|
||||
c = 0;
|
||||
while (1) {
|
||||
u8 alkiot[39];
|
||||
u8 nbuf[39];
|
||||
|
||||
for (i = 0; i < 39; i++) {
|
||||
alkiot[i] = i + 1;
|
||||
nbuf[i] = i + 1;
|
||||
}
|
||||
if (c == 0)
|
||||
gettimeofday(&tv1, NULL);
|
||||
|
@ -33,38 +31,37 @@ int main(int argc, char *argv[])
|
|||
r = sc_get_challenge(card, buf, 14);
|
||||
sc_unlock(card);
|
||||
if (r == 0) {
|
||||
int i, jaljella = 39;
|
||||
int i, left = 39;
|
||||
|
||||
printf("Lottorivi: ");
|
||||
printf("Lottery: ");
|
||||
for (i = 0; i < 7; i++) {
|
||||
unsigned short s = buf[2*i] + (buf[2*i+1] << 8);
|
||||
int lot = s % (jaljella+1);
|
||||
int num = alkiot[lot];
|
||||
|
||||
alkiot[lot] = alkiot[jaljella-1];
|
||||
jaljella--;
|
||||
|
||||
freq[num-1]++;
|
||||
unsigned short s = buf[2 * i] + (buf[2 * i + 1] << 8);
|
||||
int lot = s % (left + 1);
|
||||
int num = nbuf[lot];
|
||||
|
||||
nbuf[lot] = nbuf[left - 1];
|
||||
left--;
|
||||
freq[num - 1]++;
|
||||
printf("%3d ", num);
|
||||
}
|
||||
printf("\n");
|
||||
} else {
|
||||
fprintf(stderr, "get_random() failed: %s\n", sc_strerror(r));
|
||||
fprintf(stderr, "sc_get_challenge() failed: %s\n", sc_strerror(r));
|
||||
sc_test_cleanup();
|
||||
return 1;
|
||||
}
|
||||
c++;
|
||||
if (c == 50) {
|
||||
unsigned long long foo, foo2;
|
||||
|
||||
gettimeofday(&tv2, NULL);
|
||||
foo = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
|
||||
foo2 = tv1.tv_sec * 1000 + tv1.tv_usec / 1000;
|
||||
printf("Time per one: %lld ms\n", (foo - foo2)/50);
|
||||
printf("Time per one: %lld ms\n", (foo - foo2) / 50);
|
||||
printf("Frequencies:\n");
|
||||
for (i = 0; i < 39; i++) {
|
||||
printf("%3d: %-5d", i+1, freq[i]);
|
||||
if (((i+1) % 10) == 0)
|
||||
printf("%3d: %-5d", i + 1, freq[i]);
|
||||
if (((i + 1) % 10) == 0)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
/* Copyright (C) 2001 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
* All rights reserved.
|
||||
*
|
||||
* PKCS#15 PIN code test
|
||||
* PKCS#15 objects test
|
||||
*/
|
||||
|
||||
#include "sc-test.h"
|
||||
#include "opensc.h"
|
||||
#include "opensc-pkcs15.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <opensc.h>
|
||||
#include <opensc-pkcs15.h>
|
||||
#include "sc-test.h"
|
||||
|
||||
struct sc_pkcs15_card *p15card;
|
||||
|
||||
static int
|
||||
dump_objects(const char *what, int type)
|
||||
static int dump_objects(const char *what, int type)
|
||||
{
|
||||
struct sc_pkcs15_object **objs;
|
||||
int count, i;
|
||||
|
@ -47,11 +46,10 @@ dump_objects(const char *what, int type)
|
|||
}
|
||||
free(objs);
|
||||
sc_unlock(card);
|
||||
return (count < 0)? 1 : 0;
|
||||
return (count < 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -75,6 +73,7 @@ main(int argc, char *argv[])
|
|||
dump_objects("RSA public keys", SC_PKCS15_TYPE_PUBKEY_RSA);
|
||||
dump_objects("X.509 certificates", SC_PKCS15_TYPE_CERT_X509);
|
||||
|
||||
sc_pkcs15_unbind(p15card);
|
||||
sc_test_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
* PKCS#15 PIN code test
|
||||
*/
|
||||
|
||||
#include "sc-test.h"
|
||||
#include "opensc.h"
|
||||
#include "opensc-pkcs15.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <opensc.h>
|
||||
#include <opensc-pkcs15.h>
|
||||
#include "sc-test.h"
|
||||
|
||||
struct sc_pkcs15_card *p15card;
|
||||
|
||||
|
@ -38,7 +38,6 @@ int enum_pins(struct sc_pkcs15_object ***ret)
|
|||
return n;
|
||||
}
|
||||
|
||||
|
||||
int ask_and_verify_pin(struct sc_pkcs15_object *obj)
|
||||
{
|
||||
struct sc_pkcs15_pin_info *pin;
|
||||
|
@ -96,6 +95,7 @@ int main(int argc, char *argv[])
|
|||
sc_unlock(card);
|
||||
if (i) {
|
||||
fprintf(stderr, "failed: %s\n", sc_strerror(i));
|
||||
sc_test_cleanup();
|
||||
return 1;
|
||||
}
|
||||
printf("found.\n");
|
||||
|
@ -103,11 +103,15 @@ int main(int argc, char *argv[])
|
|||
sc_lock(card);
|
||||
count = enum_pins(&objs);
|
||||
sc_unlock(card);
|
||||
if (count < 0)
|
||||
if (count < 0) {
|
||||
sc_pkcs15_unbind(p15card);
|
||||
sc_test_cleanup();
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < count; i++) {
|
||||
ask_and_verify_pin(objs[i]);
|
||||
}
|
||||
sc_pkcs15_unbind(p15card);
|
||||
sc_test_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -4,18 +4,18 @@
|
|||
* PKCS#15 PIN code test
|
||||
*/
|
||||
|
||||
#include "sc-test.h"
|
||||
#include "opensc.h"
|
||||
#include "opensc-pkcs15.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <opensc.h>
|
||||
#include <opensc-pkcs15.h>
|
||||
#include "sc-test.h"
|
||||
|
||||
struct sc_pkcs15_card *p15card;
|
||||
|
||||
static void
|
||||
print_pin(const struct sc_pkcs15_object *obj)
|
||||
static void print_pin(const struct sc_pkcs15_object *obj)
|
||||
{
|
||||
const char *pin_flags[] = {
|
||||
const char *pin_flags[] =
|
||||
{
|
||||
"case-sensitive", "local", "change-disabled",
|
||||
"unblock-disabled", "initialized", "needs-padding",
|
||||
"unblockingPin", "soPin", "disable_allowed",
|
||||
|
@ -23,7 +23,7 @@ print_pin(const struct sc_pkcs15_object *obj)
|
|||
"exchangeRefData"
|
||||
};
|
||||
struct sc_pkcs15_pin_info *pin;
|
||||
const int pf_count = sizeof(pin_flags)/sizeof(pin_flags[0]);
|
||||
const int pf_count = sizeof(pin_flags) / sizeof(pin_flags[0]);
|
||||
int i;
|
||||
char *p;
|
||||
|
||||
|
@ -49,21 +49,22 @@ print_pin(const struct sc_pkcs15_object *obj)
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
print_prkey_rsa(const struct sc_pkcs15_object *obj)
|
||||
static void print_prkey_rsa(const struct sc_pkcs15_object *obj)
|
||||
{
|
||||
int i;
|
||||
const char *usages[] = {
|
||||
const char *usages[] =
|
||||
{
|
||||
"encrypt", "decrypt", "sign", "signRecover",
|
||||
"wrap", "unwrap", "verify", "verifyRecover",
|
||||
"derive", "nonRepudiation"
|
||||
};
|
||||
const int usage_count = sizeof(usages)/sizeof(usages[0]);
|
||||
const char *access_flags[] = {
|
||||
const int usage_count = sizeof(usages) / sizeof(usages[0]);
|
||||
const char *access_flags[] =
|
||||
{
|
||||
"sensitive", "extract", "alwaysSensitive",
|
||||
"neverExtract", "local"
|
||||
};
|
||||
const int af_count = sizeof(access_flags)/sizeof(access_flags[0]);
|
||||
const int af_count = sizeof(access_flags) / sizeof(access_flags[0]);
|
||||
struct sc_pkcs15_prkey_info *prkey;
|
||||
|
||||
prkey = (struct sc_pkcs15_prkey_info *) obj->data;
|
||||
|
@ -92,21 +93,22 @@ print_prkey_rsa(const struct sc_pkcs15_object *obj)
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
print_pubkey_rsa(const struct sc_pkcs15_object *obj)
|
||||
static void print_pubkey_rsa(const struct sc_pkcs15_object *obj)
|
||||
{
|
||||
int i;
|
||||
const char *usages[] = {
|
||||
const char *usages[] =
|
||||
{
|
||||
"encrypt", "decrypt", "sign", "signRecover",
|
||||
"wrap", "unwrap", "verify", "verifyRecover",
|
||||
"derive", "nonRepudiation"
|
||||
};
|
||||
const int usage_count = sizeof(usages)/sizeof(usages[0]);
|
||||
const char *access_flags[] = {
|
||||
const int usage_count = sizeof(usages) / sizeof(usages[0]);
|
||||
const char *access_flags[] =
|
||||
{
|
||||
"sensitive", "extract", "alwaysSensitive",
|
||||
"neverExtract", "local"
|
||||
};
|
||||
const int af_count = sizeof(access_flags)/sizeof(access_flags[0]);
|
||||
const int af_count = sizeof(access_flags) / sizeof(access_flags[0]);
|
||||
struct sc_pkcs15_pubkey_info *pubkey;
|
||||
|
||||
pubkey = (struct sc_pkcs15_pubkey_info *) obj->data;
|
||||
|
@ -135,8 +137,7 @@ print_pubkey_rsa(const struct sc_pkcs15_object *obj)
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
print_cert_x509(const struct sc_pkcs15_object *obj)
|
||||
static void print_cert_x509(const struct sc_pkcs15_object *obj)
|
||||
{
|
||||
struct sc_pkcs15_cert_info *cert;
|
||||
int i;
|
||||
|
@ -155,12 +156,10 @@ print_cert_x509(const struct sc_pkcs15_object *obj)
|
|||
* and dump the label */
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sc_test_print_object(const struct sc_pkcs15_object *obj)
|
||||
void sc_test_print_object(const struct sc_pkcs15_object *obj)
|
||||
{
|
||||
const char *kind;
|
||||
void (*printer)(const struct sc_pkcs15_object *);
|
||||
void (*printer) (const struct sc_pkcs15_object *);
|
||||
|
||||
switch (obj->type) {
|
||||
case SC_PKCS15_TYPE_AUTH_PIN:
|
||||
|
|
|
@ -4,24 +4,22 @@
|
|||
* Pseudo-random number generator test program
|
||||
*/
|
||||
|
||||
#include "sc-test.h"
|
||||
#include "opensc.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
#include <opensc.h>
|
||||
#include "sc-test.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, c;
|
||||
int freq[256];
|
||||
struct timeval tv1, tv2;
|
||||
int i, c, freq[256];
|
||||
u8 buf[8];
|
||||
|
||||
i = sc_test_init(&argc, argv);
|
||||
if (i < 0)
|
||||
return 1;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
freq[i] = 0;
|
||||
c = 0;
|
||||
|
@ -34,7 +32,7 @@ int main(int argc, char *argv[])
|
|||
gettimeofday(&tv1, NULL);
|
||||
i = sc_get_challenge(card, buf, 8);
|
||||
if (i != 0) {
|
||||
fprintf(stderr, "sc_get_random() failed: %s\n", sc_strerror(i));
|
||||
fprintf(stderr, "sc_get_challenge() failed: %s\n", sc_strerror(i));
|
||||
sc_test_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
@ -47,7 +45,7 @@ int main(int argc, char *argv[])
|
|||
foo = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
|
||||
foo2 = tv1.tv_sec * 1000 + tv1.tv_usec / 1000;
|
||||
printf("\nTime to generate 64 bits of randomness: %lld ms\n",
|
||||
(foo - foo2)/100);
|
||||
(foo - foo2) / 100);
|
||||
printf("Frequencies:\n");
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (i && (i & 0x07) == 0)
|
||||
|
|
|
@ -55,7 +55,7 @@ int sc_test_init(int *argc, char *argv[])
|
|||
printf("Connecting to card failed\n");
|
||||
return i;
|
||||
}
|
||||
printf("connected. ATR = ");
|
||||
printf("connected.\nATR = ");
|
||||
for (i = 0; i < card->atr_len; i++) {
|
||||
if (i)
|
||||
printf(":");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
#ifndef _SC_TEST_H
|
||||
#define _SC_TEST_H
|
||||
|
||||
extern struct sc_context *ctx;
|
||||
extern struct sc_card *card;
|
||||
|
|
Loading…
Reference in New Issue